psana/src/RunIter.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //     $Id: RunIter.cpp 8825 2014-08-28 01:16:10Z davidsch@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //     Class RunIter...
00007 //
00008 // Author List:
00009 //     Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "psana/RunIter.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "PSEvt/EventId.h"
00026 #include "psana/Exceptions.h"
00027 
00028 //-----------------------------------------------------------------------
00029 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00030 //-----------------------------------------------------------------------
00031 
00032 //             ----------------------------------------
00033 //             -- Public Function Member Definitions --
00034 //             ----------------------------------------
00035 
00036 namespace psana {
00037 
00038 //----------------
00039 // Constructors --
00040 //----------------
00041 RunIter::RunIter ()
00042   : m_evtLoop()
00043 {
00044 }
00045 
00046 /// Constructor takes event loop instance.
00047 RunIter::RunIter (const boost::shared_ptr<EventLoop>& evtLoop)
00048   : m_evtLoop(evtLoop)
00049 {
00050   try {
00051     _runIter = m_evtLoop->index().runs().begin();
00052   }
00053   catch (ExceptionAbort e) {
00054   }
00055 }
00056 
00057 //--------------
00058 // Destructor --
00059 //--------------
00060 RunIter::~RunIter ()
00061 {
00062 }
00063 
00064 /// get next run, when done returns object which is convertible to "false"
00065 std::pair<RunIter::value_type, boost::shared_ptr<PSEvt::Event> > 
00066 RunIter::nextWithEvent()
00067 {
00068   std::pair<RunIter::value_type, boost::shared_ptr<PSEvt::Event> > result;
00069 
00070   try {
00071     if (_runIter == m_evtLoop->index().runs().end()) return result;
00072     m_evtLoop->index().setrun(*_runIter);
00073     _runIter++;
00074   }
00075   catch (ExceptionAbort e) {
00076   }
00077 
00078   // Go to a BeginRun transition
00079   while (true) {
00080     EventLoop::value_type nxt = m_evtLoop->next();
00081     if (nxt.first == EventLoop::None) {
00082       // nothing left there
00083       break;
00084     } else if (nxt.first == EventLoop::BeginRun) {
00085       // found it, try to get run number from current event
00086       boost::shared_ptr<PSEvt::EventId> eid = nxt.second->get();
00087       int run = eid ? eid->run() : -1 ;
00088       result = std::pair<RunIter::value_type, 
00089         boost::shared_ptr<PSEvt::Event> >(RunIter::value_type(m_evtLoop, run), nxt.second);
00090       break;
00091     }
00092   }
00093 
00094   return result;
00095 }
00096 
00097 RunIter::value_type
00098 RunIter::next()
00099 {
00100   return nextWithEvent().first;
00101 }
00102 
00103 } // namespace psana

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7