00001 #ifndef PSXTCINPUT_XTCINPUTMODULEBASE_H 00002 #define PSXTCINPUT_XTCINPUTMODULEBASE_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: XtcInputModuleBase.h 10730 2015-09-23 22:06:21Z davidsch@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class XtcInputModuleBase. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 #include <vector> 00017 #include <boost/shared_ptr.hpp> 00018 00019 //---------------------- 00020 // Base Class Headers -- 00021 //---------------------- 00022 #include "psana/InputModule.h" 00023 00024 //------------------------------- 00025 // Collaborating Class Headers -- 00026 //------------------------------- 00027 #include "PSXtcInput/DamagePolicy.h" 00028 #include "PSXtcInput/IDatagramSource.h" 00029 #include "psddl_pds2psana/XtcConverter.h" 00030 #include "pdsdata/xtc/TransitionId.hh" 00031 #include "pdsdata/xtc/ClockTime.hh" 00032 00033 //------------------------------------ 00034 // Collaborating Class Declarations -- 00035 //------------------------------------ 00036 00037 // --------------------- 00038 // -- Class Interface -- 00039 // --------------------- 00040 00041 namespace PSXtcInput { 00042 00043 /** 00044 * @ingroup PSXtcInput 00045 * 00046 * @brief Psana input module for reading XTC files. 00047 * 00048 * This software was developed for the LCLS project. If you use all or 00049 * part of it, please give an appropriate acknowledgment. 00050 * 00051 * @version $Id: XtcInputModuleBase.h 10730 2015-09-23 22:06:21Z davidsch@SLAC.STANFORD.EDU $ 00052 * 00053 * @author Andrei Salnikov 00054 */ 00055 00056 class XtcInputModuleBase : public InputModule { 00057 public: 00058 00059 /** 00060 * @brief Constructor takes the name of the module and instance of datagram source. 00061 * 00062 * If noSkip parameter is set to true then psana parameters "skip-events", "events", 00063 * "skip-epics" and "l3t-accept-only" are ignored. This is intended for use with 00064 * slave worker process in multi-process mode where all skipping is done on master 00065 * side. 00066 * 00067 */ 00068 XtcInputModuleBase (const std::string& name, 00069 const boost::shared_ptr<IDatagramSource>& dgsource, 00070 bool noSkip = false); 00071 00072 // Destructor 00073 virtual ~XtcInputModuleBase () ; 00074 00075 /// Method which is called once at the beginning of the job 00076 virtual void beginJob(Event& evt, Env& env); 00077 00078 /// Method which is called with event data 00079 virtual Status event(Event& evt, Env& env); 00080 00081 /// Method which is called once at the end of the job 00082 virtual void endJob(Event& evt, Env& env); 00083 00084 /// Returns True if live mode and the available events > numEvents arg 00085 virtual bool liveAvail(int numEvents); 00086 00087 protected: 00088 00089 /** 00090 * @brief Fill event from list of datagrams. 00091 * 00092 * Datagrams should be sorted with DAQ streams first, Control streams last. If transition is 00093 * Configure or BeginCalibCycle, uses first DAQ stream (skips others) and all control streams. 00094 * For all other transitions all Dgrams are processed. 00095 */ 00096 void fillEvent(const std::vector<XtcInput::Dgram>& dgList, Event& evt, Env& env); 00097 00098 /// Fill event with datagram contents 00099 void fillEvent(const XtcInput::Dgram& dg, Event& evt, Env& env); 00100 00101 /// Fill event with EventId information 00102 void fillEventId(const XtcInput::Dgram& dg, Event& evt); 00103 00104 /// Fill event with Datagram list 00105 void fillEventDgList(const std::vector<XtcInput::Dgram>& dgList, Event& evt); 00106 00107 /** 00108 * @brief Fill env from list of datagrams. 00109 * 00110 * Datagrams should be sorted with DAQ streams first, Control streams last. If transition is 00111 * Configure or BeginCalibCycle, uses first DAQ stream (skips others) and all control streams. 00112 * For all other transitions all Dgrams are processed. 00113 */ 00114 void fillEnv(const std::vector<XtcInput::Dgram> &dgList, Env &env); 00115 00116 /// Fill environment with datagram contents 00117 void fillEnv(const XtcInput::Dgram& dg, Env& env); 00118 00119 /// Protected since the Indexing input module needs access to it. 00120 boost::shared_ptr<IDatagramSource> m_dgsource; ///< Datagram source instance 00121 00122 /// Protected to allow specific input modules to ignore settings they 00123 /// don't support 00124 void skipEvents(unsigned long nskip) {m_skipEvents = nskip;} 00125 void maxEvents(unsigned long nmax) {m_maxEvents = nmax;} 00126 void skipEpics(bool skip) {m_skipEpics = skip;} 00127 void l3tAcceptOnly(bool l3tAccept) {m_l3tAcceptOnly = l3tAccept;} 00128 unsigned long skipEvents() const {return m_skipEvents;} 00129 unsigned long maxEvents() const {return m_maxEvents;} 00130 bool skipEpics() const {return m_skipEpics;} 00131 bool l3tAcceptOnly() const {return m_l3tAcceptOnly;} 00132 00133 private: 00134 00135 DamagePolicy m_damagePolicy; ///< Policy instance for damage data 00136 std::vector<XtcInput::Dgram> m_putBack; ///< Buffer for put-back datagrams 00137 psddl_pds2psana::XtcConverter m_cvt; ///< Data converter object 00138 Pds::ClockTime m_transitions[Pds::TransitionId::NumberOf]; ///< Timestamps of the observed transitions 00139 unsigned long m_skipEvents; ///< Number of events (L1Accept transitions) to skip 00140 unsigned long m_maxEvents; ///< Number of events (L1Accept transitions) to process 00141 bool m_skipEpics; ///< If true then skip EPICS-only events 00142 bool m_l3tAcceptOnly; ///< If true then pass only events accepted by L3T 00143 int m_firstControlStream; ///< Starting index of control streams 00144 unsigned long m_l1Count; ///< Number of events (L1Accept transitions) seen so far 00145 long m_eventTagEpicsStore; ///< counter to pass to epicsStore 00146 int m_simulateEOR; ///< if non-zero then simulate endRun/stop 00147 int m_run; ///< Run number that comes from BeginRun transition (or -1) 00148 bool m_liveMode; ///< true if live mode specified in psana files option 00149 unsigned m_liveTimeOut; ///< live timeout value from config 00150 }; 00151 00152 } // namespace PSXtcInput 00153 00154 #endif // PSXTCINPUT_XTCINPUTMODULEBASE_H