CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DataFormats/Provenance/interface/FileIndex.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Provenance_FileIndex_h
00002 #define DataFormats_Provenance_FileIndex_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 FileIndex.h
00007 // Obsolete: For Backward compatibility only.
00008 
00009 ----------------------------------------------------------------------*/
00010 
00011 #include "DataFormats/Provenance/interface/RunID.h"
00012 #include "DataFormats/Provenance/interface/EventID.h"
00013 
00014 #include <cassert>
00015 #include <iosfwd>
00016 #include <vector>
00017 
00018 namespace edm {
00019 
00020   class FileIndex {
00021 
00022     public:
00023       typedef long long EntryNumber_t;
00024 
00025       FileIndex();
00026       ~FileIndex() {}
00027 
00028       void addEntry(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry);
00029 
00030       enum EntryType {kRun, kLumi, kEvent, kEnd};
00031 
00032       class Element {
00033         public:
00034           static EntryNumber_t const invalidEntry = -1LL;
00035           Element() : run_(0U), lumi_(0U), event_(0U), entry_(invalidEntry) {
00036           }
00037           Element(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, long long entry) :
00038             run_(run), lumi_(lumi),
00039           event_(event), entry_(entry) {
00040             assert(lumi_ != 0U || event_ == 0U);
00041           }
00042           Element(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) :
00043             run_(run), lumi_(lumi), event_(event), entry_(invalidEntry) {}
00044           EntryType getEntryType() const {
00045             return lumi_ == 0U ? kRun : (event_ == 0U ? kLumi : kEvent);
00046           }
00047           RunNumber_t run_;
00048           LuminosityBlockNumber_t lumi_;
00049           EventNumber_t event_;
00050           EntryNumber_t entry_;
00051       };
00052 
00053       typedef std::vector<Element>::const_iterator const_iterator;
00054 
00055       typedef std::vector<Element>::iterator iterator;
00056 
00057       void sortBy_Run_Lumi_Event();
00058       void sortBy_Run_Lumi_EventEntry();
00059 
00060       const_iterator
00061       findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi = 0U, EventNumber_t event = 0U) const;
00062 
00063       const_iterator
00064       findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
00065 
00066       const_iterator
00067       findEventEntryPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry) const;
00068 
00069       const_iterator
00070       findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const;
00071 
00072       const_iterator
00073       findRunPosition(RunNumber_t run) const;
00074 
00075       const_iterator
00076       findLumiOrRunPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const;
00077 
00078       bool
00079       containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
00080         return event ? containsEvent(run, lumi, event) : (lumi ? containsLumi(run, lumi) : containsRun(run));
00081       }
00082 
00083       bool
00084       containsEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
00085         return findEventPosition(run, lumi, event) != entries_.end();
00086       }
00087 
00088       bool
00089       containsLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) const {
00090         return findLumiPosition(run, lumi) != entries_.end();
00091       }
00092 
00093       bool
00094       containsRun(RunNumber_t run) const {
00095         return findRunPosition(run) != entries_.end();
00096       }
00097 
00098       const_iterator begin() const {return entries_.begin();}
00099 
00100       const_iterator end() const {return entries_.end();}
00101 
00102       iterator begin() {return entries_.begin();}
00103 
00104       iterator end() {return entries_.end();}
00105 
00106       iterator erase(iterator pos) {return entries_.erase(pos);}
00107 
00108       iterator erase(iterator begin, iterator end) {return entries_.erase(begin, end);}
00109 
00110       std::vector<Element>::size_type size() const {return entries_.size();}
00111 
00112       bool empty() const {return entries_.empty();}
00113 
00114       bool allEventsInEntryOrder() const;
00115 
00116       enum SortState {kNotSorted, kSorted_Run_Lumi_Event, kSorted_Run_Lumi_EventEntry};
00117 
00118       void initializeTransients() const {transient_.reset();}
00119 
00120       struct Transients {
00121         Transients();
00122         void reset();
00123         bool allInEntryOrder_;
00124         bool resultCached_;
00125         SortState sortState_;
00126       };
00127 
00128     private:
00129 
00130       bool& allInEntryOrder() const {return transient_.allInEntryOrder_;}
00131       bool& resultCached() const {return transient_.resultCached_;}
00132       SortState& sortState() const {return transient_.sortState_;}
00133 
00134       std::vector<Element> entries_;
00135       mutable Transients transient_;
00136   };
00137 
00138   bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
00139 
00140   inline
00141   bool operator>(FileIndex::Element const& lh, FileIndex::Element const& rh) {return rh < lh;}
00142 
00143   inline
00144   bool operator>=(FileIndex::Element const& lh, FileIndex::Element const& rh) {return !(lh < rh);}
00145 
00146   inline
00147   bool operator<=(FileIndex::Element const& lh, FileIndex::Element const& rh) {return !(rh < lh);}
00148 
00149   inline
00150   bool operator==(FileIndex::Element const& lh, FileIndex::Element const& rh) {return !(lh < rh || rh < lh);}
00151 
00152   inline
00153   bool operator!=(FileIndex::Element const& lh, FileIndex::Element const& rh) {return lh < rh || rh < lh;}
00154 
00155   class Compare_Run_Lumi_EventEntry {
00156   public:
00157     bool operator()(FileIndex::Element const& lh, FileIndex::Element const& rh);
00158   };
00159 
00160   std::ostream&
00161   operator<<(std::ostream& os, FileIndex const& fileIndex);
00162 }
00163 
00164 #endif