00001 #ifndef PSANA_DATASOURCE_H 00002 #define PSANA_DATASOURCE_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: DataSource.h 10732 2015-09-23 22:07:46Z davidsch@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class DataSource. 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 00023 //------------------------------- 00024 // Collaborating Class Headers -- 00025 //------------------------------- 00026 #include "psana/EventIter.h" 00027 #include "psana/EventLoop.h" 00028 #include "psana/RunIter.h" 00029 #include "psana/StepIter.h" 00030 #include "PSEnv/Env.h" 00031 00032 //------------------------------------ 00033 // Collaborating Class Declarations -- 00034 //------------------------------------ 00035 namespace psana { 00036 class InputModule; 00037 class Module; 00038 } 00039 00040 00041 // --------------------- 00042 // -- Class Interface -- 00043 // --------------------- 00044 00045 namespace psana { 00046 00047 /// @addtogroup psana 00048 00049 /** 00050 * @ingroup psana 00051 * 00052 * @brief Class representing a data source for psana framework. 00053 * 00054 * Class encapsulates input data in the form of input module and 00055 * provides different ways to iterator over those data. 00056 * 00057 * This software was developed for the LCLS project. If you use all or 00058 * part of it, please give an appropriate acknowledgment. 00059 * 00060 * @version $Id: DataSource.h 10732 2015-09-23 22:07:46Z davidsch@SLAC.STANFORD.EDU $ 00061 * 00062 * @author Andy Salnikov 00063 */ 00064 00065 class DataSource { 00066 public: 00067 00068 /** 00069 * @brief Default constructor makes "null" data source 00070 */ 00071 DataSource(); 00072 00073 /** 00074 * @brief Make an instance of data source. 00075 * 00076 * Constructor takes instance of input module, and a list of 00077 * user modules. 00078 */ 00079 DataSource(const boost::shared_ptr<InputModule>& inputModule, 00080 const std::vector<boost::shared_ptr<Module> >& modules, 00081 const boost::shared_ptr<PSEnv::Env>& env); 00082 00083 // Destructor 00084 ~DataSource(); 00085 00086 /** 00087 * Returns true if data source has no data ("null" source) 00088 */ 00089 bool empty() const { return not m_evtLoop; } 00090 00091 /// Get environment object, cannot be called for "null" source 00092 PSEnv::Env& env() const; 00093 00094 /// Returns iterator for events 00095 EventIter events() { return EventIter(m_evtLoop, EventLoop::None); } 00096 00097 /// Returns iterator for steps 00098 StepIter steps() { return StepIter(m_evtLoop, EventLoop::None); } 00099 00100 /// Returns iterator for runs 00101 RunIter runs() { return RunIter(m_evtLoop); } 00102 00103 // Add PSANA module to list of modules in eventloop 00104 void addmodule(boost::shared_ptr<Module> module){ m_evtLoop->addmodule(module);} 00105 00106 // Returns True if live mode and the available events > numEvents arg 00107 // Used to skip events and catch up with latest for live data. 00108 // Calculation of available events is approximate 00109 bool liveAvail(int numEvents); 00110 00111 protected: 00112 00113 private: 00114 00115 // Data members 00116 boost::shared_ptr<EventLoop> m_evtLoop; 00117 }; 00118 00119 } // namespace psana 00120 00121 #endif // PSANA_DATASOURCE_H