psana/src/EventIter.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: EventIter.cpp 3781 2012-06-11 01:01:41Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class EventIter...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "psana/EventIter.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 EventIter::EventIter ()
00040   : m_evtLoop()
00041   , m_stopType(EventLoop::None)
00042 {
00043 }
00044 
00045 EventIter::EventIter (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 EventIter::~EventIter ()
00055 {
00056 }
00057 
00058 /// get next event, returns zero pointer when done
00059 boost::shared_ptr<PSEvt::Event>
00060 EventIter::next()
00061 {
00062   boost::shared_ptr<PSEvt::Event> result;
00063   if (m_stopType == EventLoop::Event) {
00064     // means iteration already finished
00065     return result;
00066   }
00067 
00068   while (true) {
00069     EventLoop::value_type nxt = m_evtLoop->next();
00070     if (nxt.first == EventLoop::None) {
00071       // no events left
00072       m_stopType = EventLoop::Event;
00073       break;
00074     } else if (nxt.first == m_stopType) {
00075       // we stop here, return event back to the stream, someone else
00076       // may be interested in it
00077       m_evtLoop->putback(nxt);
00078       m_stopType = EventLoop::Event;
00079       break;
00080     } else if (nxt.first == EventLoop::Event) {
00081       // found event
00082       result = nxt.second;
00083       break;
00084     }
00085   }
00086   return result;
00087 }
00088 
00089 } // namespace psana

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7