psana/src/StepIter.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //     $Id: StepIter.cpp 8825 2014-08-28 01:16:10Z davidsch@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //     Class StepIter...
00007 //
00008 // Author List:
00009 //     Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "psana/StepIter.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 
00026 //-----------------------------------------------------------------------
00027 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00028 //-----------------------------------------------------------------------
00029 
00030 //             ----------------------------------------
00031 //             -- Public Function Member Definitions --
00032 //             ----------------------------------------
00033 
00034 namespace psana {
00035 
00036 //----------------
00037 // Constructors --
00038 //----------------
00039 StepIter::StepIter ()
00040   : m_evtLoop()
00041 {
00042 }
00043 
00044 /// Constructor takes event loop instance.
00045 StepIter::StepIter (const boost::shared_ptr<EventLoop>& evtLoop, EventLoop::EventType stopType)
00046   : m_evtLoop(evtLoop)
00047   , m_stopType(stopType)
00048 {
00049 }
00050 
00051 //--------------
00052 // Destructor --
00053 //--------------
00054 StepIter::~StepIter ()
00055 {
00056 }
00057 
00058 /// get next Step and corresponding event.
00059 //  when done returns object which is convertible to "false"
00060 std::pair<StepIter::value_type, boost::shared_ptr<PSEvt::Event> >
00061 StepIter::nextWithEvent()
00062 {
00063   std::pair<StepIter::value_type, boost::shared_ptr<PSEvt::Event> > result;
00064   if (m_stopType == EventLoop::Event) {
00065     // means iteration already finished
00066     return result;
00067   }
00068   
00069   while (true) {
00070     EventLoop::value_type nxt = m_evtLoop->next();
00071     if (nxt.first == EventLoop::None) {
00072       // no events left
00073       m_stopType = EventLoop::Event;
00074       break;
00075     } else if (nxt.first == m_stopType) {
00076       // we stop here, return event back to the stream, someone else
00077       // may be interested in it
00078       m_evtLoop->putback(nxt);
00079       m_stopType = EventLoop::Event;
00080       break;
00081     } else if (nxt.first == EventLoop::BeginCalibCycle) {
00082       // found it
00083       result = std::pair<StepIter::value_type, 
00084         boost::shared_ptr<PSEvt::Event> >(StepIter::value_type(m_evtLoop), nxt.second);
00085       break;
00086     }
00087   }
00088   return result;
00089 }
00090 
00091 /// get next Step, when done returns object which is convertible to "false"
00092 StepIter::value_type
00093 StepIter::next()
00094 {
00095   return nextWithEvent().first;
00096 }
00097 
00098 } // namespace psana

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7