PSShmemInput/src/ShmemMonitorClient.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: ShmemMonitorClient.cpp 9721 2015-03-04 01:29:09Z davidsch@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class ShmemMonitorClient...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "PSShmemInput/ShmemMonitorClient.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <boost/thread.hpp>
00022 
00023 //-------------------------------
00024 // Collaborating Class Headers --
00025 //-------------------------------
00026 #include "MsgLogger/MsgLogger.h"
00027 #include "pdsdata/xtc/Dgram.hh"
00028 #include "XtcInput/Dgram.h"
00029 #include "XtcInput/DgramQueue.h"
00030 
00031 //-----------------------------------------------------------------------
00032 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00033 //-----------------------------------------------------------------------
00034 
00035 namespace {
00036 
00037   const char logger[] = "PSShmemInput.ShmemMonitorClient";
00038 
00039 }
00040 
00041 //              ----------------------------------------
00042 //              -- Public Function Member Definitions --
00043 //              ----------------------------------------
00044 
00045 namespace PSShmemInput {
00046 
00047 //----------------
00048 // Constructors --
00049 //----------------
00050 ShmemMonitorClient::ShmemMonitorClient (const std::string& tag, int index,
00051     XtcInput::DgramQueue& queue, Pds::TransitionId::Value stopTr)
00052   : Pds::XtcMonitorClient()
00053   , m_tag(tag)
00054   , m_index(index)
00055   , m_queue(queue)
00056   , m_stopTr(stopTr)
00057 {
00058 }
00059 
00060 // this is the "run" method used by the Boost.thread
00061 void
00062 ShmemMonitorClient::operator()()
00063 {
00064   this->run(m_tag.c_str(), m_index);
00065 }
00066 
00067 // overriding base class method
00068 int
00069 ShmemMonitorClient::processDgram(Pds::Dgram* dg)
00070 {
00071   Pds::TransitionId::Value tr = dg->seq.service();
00072   MsgLog(logger, debug, "received transition " << Pds::TransitionId::name(tr));
00073 
00074   // skip some datagrams that base class does not expect
00075   if (tr != Pds::TransitionId::Map and tr != Pds::TransitionId::Unmap) {
00076     // copy datagram
00077     const unsigned size = sizeof(Pds::Dgram) + dg->xtc.sizeofPayload();
00078     const char* src = (const char*)dg;
00079     char* dst = new char[size];
00080     std::copy(src, src+size, dst);
00081 
00082     // wrap into object and push into queue
00083     // need to create a large run number so shmem analysis can pick
00084     // up the latest calibration constants.
00085     XtcInput::Dgram dgobj(XtcInput::Dgram::make_ptr((Pds::Dgram*)dst), XtcInput::XtcFileName("<ShMem>",0,std::numeric_limits<short>::max()-1,0,0,false));
00086     m_queue.push(dgobj);
00087   }
00088 
00089   // check if we should stop now
00090   bool stop = false;
00091   switch (tr) {
00092   case Pds::TransitionId::Unmap:
00093     stop = m_stopTr == Pds::TransitionId::Unmap or
00094            m_stopTr == Pds::TransitionId::Unconfigure or
00095            m_stopTr == Pds::TransitionId::EndRun or
00096            m_stopTr == Pds::TransitionId::EndCalibCycle;
00097     break;
00098   case Pds::TransitionId::Unconfigure:
00099     stop = m_stopTr == Pds::TransitionId::Unconfigure or
00100            m_stopTr == Pds::TransitionId::EndRun or
00101            m_stopTr == Pds::TransitionId::EndCalibCycle;
00102     break;
00103   case Pds::TransitionId::EndRun:
00104     stop = m_stopTr == Pds::TransitionId::EndRun or
00105            m_stopTr == Pds::TransitionId::EndCalibCycle;
00106     break;
00107   case Pds::TransitionId::EndCalibCycle:
00108     stop = m_stopTr == Pds::TransitionId::EndCalibCycle;
00109     break;
00110   default:
00111     break;
00112   }
00113 
00114   // if signalled try to stop gracefully
00115   if (stop) {
00116     MsgLog(logger, debug, "stop transition reached");
00117     m_queue.push(XtcInput::Dgram());
00118     return 1;
00119   } else if (boost::this_thread::interruption_requested()) {
00120     MsgLog(logger, debug, "interrupted, stopping");
00121     m_queue.push(XtcInput::Dgram());
00122     return -1;
00123   } else {
00124     return 0;
00125   }
00126 }
00127 
00128 } // namespace PSShmemInput

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7