00001 #ifndef SIO_LCIORandomAccessMgr_H 00002 #define SIO_LCIORandomAccessMgr_H 1 00003 00004 #include "LCIORandomAccess.h" 00005 #include "RunEventMap.h" 00006 00007 #include <iostream> 00008 #include <map> 00009 #include <list> 00010 00011 class SIO_stream ; 00012 00013 namespace SIO { 00014 00015 class LCIORandomAccessMgr ; 00016 class SIOIndexHandler ; 00017 class SIORandomAccessHandler ; 00018 00019 std::ostream & operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ) ; 00020 00038 class LCIORandomAccessMgr { 00039 00040 friend class SIOIndexHandler ; 00041 friend class SIORandomAccessHandler ; 00042 friend std::ostream & operator<<(std::ostream& os, const LCIORandomAccessMgr& ra ) ; 00043 00044 public: 00045 00046 LCIORandomAccessMgr() ; 00047 00049 LCIORandomAccessMgr(const LCIORandomAccessMgr&) = delete ; 00051 LCIORandomAccessMgr& operator=(const LCIORandomAccessMgr&) = delete ; 00052 00053 virtual ~LCIORandomAccessMgr() ; 00054 00058 long64 getPosition(const RunEvent& re ) { 00059 return _runEvtMap.getPosition( re ) ; 00060 } 00061 00064 void add(const RunEvent& re, long64 pos ) { 00065 _runEvtMap.add( re , pos ) ; 00066 } 00067 00071 bool createEventMap(SIO_stream* s) ; 00072 00075 const RunEventMap& getEventMap() { return _runEvtMap ; } 00076 00080 bool initAppend( SIO_stream* s) ; 00081 00082 00085 void writeRandomAccessRecords(SIO_stream* stream) ; 00086 00088 void clear() ; 00089 00090 protected: 00091 00093 LCIORandomAccess* createFromEventMap() ; 00094 00096 void addLCIORandomAccess( LCIORandomAccess* ra ) ; 00097 00099 bool readLCIORandomAccessAt( SIO_stream* stream , long64 pos) ; 00100 00102 bool readLCIOIndexAt( SIO_stream* stream , long64 pos) ; 00103 00105 bool recreateEventMap(SIO_stream*) ; 00106 00108 bool readLCIORandomAccess( SIO_stream* stream ) ; 00109 00111 bool readLCIOIndex( SIO_stream* stream ) ; 00112 00113 00115 void createFileRecord() ; 00116 00118 const LCIORandomAccess* lastLCIORandomAccess() { 00119 return (_list.empty() ? 0 : _list.back() ) ; 00120 } 00121 00122 // ----- map with RunHeader and EventHeader record positions 00123 RunEventMap _runEvtMap{} ; 00124 00125 // ----- list of LCIORandomAccess objects 00126 std::list< LCIORandomAccess* > _list{} ; 00127 00128 LCIORandomAccess* _fileRecord ; 00129 00130 }; // class 00131 00132 00133 } // namespace 00134 #endif