psana/include/InputIter.h

Go to the documentation of this file.
00001 #ifndef PSANA_INPUTITER_H
00002 #define PSANA_INPUTITER_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: InputIter.h 7529 2014-01-13 21:45:29Z salnikov@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class InputIter.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 #include <boost/shared_ptr.hpp>
00017 #include <boost/utility.hpp>
00018 #include <deque>
00019 #include <utility>
00020 #include <iosfwd>
00021 
00022 //----------------------
00023 // Base Class Headers --
00024 //----------------------
00025 
00026 //-------------------------------
00027 // Collaborating Class Headers --
00028 //-------------------------------
00029 #include "PSEvt/AliasMap.h"
00030 #include "PSEnv/Env.h"
00031 #include "PSEvt/Event.h"
00032 
00033 //------------------------------------
00034 // Collaborating Class Declarations --
00035 //------------------------------------
00036 namespace psana {
00037 class InputModule;
00038 }
00039 
00040 //              ---------------------
00041 //              -- Class Interface --
00042 //              ---------------------
00043 
00044 namespace psana {
00045 
00046 /// @addtogroup psana
00047 
00048 /**
00049  *  @ingroup psana
00050  *
00051  *  @brief Implementation of the iterator for input events.
00052  *
00053  *  The purpose of this class is to provide iteration over "events"
00054  *  in psana framework with well-defined properties. Event in this
00055  *  context means not only regular events but also transitions
00056  *  like BeginRun, EndRun, etc. Instance of this class acts like
00057  *  iterator which returns two items for each iteration -
00058  *  event type and event contents (PSEvt::Event object). It guarantees
00059  *  correct nesting of transitions and events, so that regular events
00060  *  happen only inside BeginCalibCycle/EndCalibCycle, which in turn
00061  *  happen only inside BeginRun/EndRun.
00062  *
00063  *  This software was developed for the LCLS project.  If you use all or 
00064  *  part of it, please give an appropriate acknowledgment.
00065  *
00066  *  @version $Id: InputIter.h 7529 2014-01-13 21:45:29Z salnikov@SLAC.STANFORD.EDU $
00067  *
00068  *  @author Andy Salnikov
00069  */
00070 
00071 class InputIter : boost::noncopyable {
00072 public:
00073 
00074   /// State order must not change, state machine depends on ordering
00075   enum State {StateNone=0, StateConfigured=1, StateRunning=2, StateScanning=3, NumStates=4};
00076 
00077   /// Enumeration for the event types returned by iterator
00078   enum EventType {
00079     BeginJob,         ///< Returned at the begin of job
00080     BeginRun,         ///< Returned at the begin of run
00081     BeginCalibCycle,  ///< Returned at the begin of calib cycle
00082     Event,            ///< Returned for regular event
00083     EndCalibCycle,    ///< Returned at the end of calib cycle
00084     EndRun,           ///< Returned at the end of run
00085     EndJob,           ///< Returned at the end of job
00086     None,             ///< Returned if there are no more events
00087     NumEventTypes,    ///< Total number off event types
00088   };
00089 
00090   typedef boost::shared_ptr<PSEvt::Event> EventPtr;
00091   typedef std::pair<EventType, EventPtr> value_type;
00092 
00093   /**
00094    *  @brief Constructor takes instance of input module and environment object.
00095    */
00096   InputIter(const boost::shared_ptr<InputModule>& inputModule,
00097             const boost::shared_ptr<PSEnv::Env>& env);
00098 
00099   // DEstructor
00100   ~InputIter();
00101   
00102   /// Get environment object
00103   PSEnv::Env& env() const { return *m_env; }
00104 
00105   /**
00106    *  Method that runs one iteration and returns event type,
00107    *  and event object.
00108    */
00109   value_type next();
00110 
00111   /**
00112    *  Prepare to stop iteration, instructs iterator to stop reading
00113    *  data from input module and produce standard EndCalibCycle/EndRun/EndJob
00114    *  sequence on the following calls to next().
00115    */
00116   void finish();
00117 
00118 protected:
00119 
00120 private:
00121 
00122   void newState(State state, const EventPtr& evt);
00123   void closeState(const EventPtr& evt);
00124   void unwind(State newState, const EventPtr& evt);
00125 
00126   boost::shared_ptr<InputModule> m_inputModule;
00127   boost::shared_ptr<PSEnv::Env> m_env;
00128   bool m_finished;
00129   State m_state;
00130   EventType m_newStateEventType[NumStates];
00131   EventType m_closeStateEventType[NumStates];
00132   std::deque<value_type> m_values;
00133   boost::shared_ptr<PSEvt::AliasMap> m_aliasMap;
00134 };
00135 
00136 /// formatting for InputIter::EventType enum
00137 std::ostream&
00138 operator<<(std::ostream& out, InputIter::EventType type);
00139 
00140 /// formatting for InputIter::State enum
00141 std::ostream&
00142 operator<<(std::ostream& out, InputIter::State state);
00143 
00144 } // namespace psana
00145 
00146 #endif // PSANA_INPUTITER_H

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7