CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/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 
00008 ----------------------------------------------------------------------*/
00009 
00010 #include <vector>
00011 #include <cassert>
00012 #include "DataFormats/Provenance/interface/RunID.h"
00013 #include "DataFormats/Provenance/interface/EventID.h"
00014 #include "DataFormats/Provenance/interface/Transient.h"
00015 
00016 #include <iosfwd>
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       struct Transients {
00119         Transients();
00120         bool allInEntryOrder_;
00121         bool resultCached_;
00122         SortState sortState_;
00123       };
00124 
00125     private:
00126 
00127       bool& allInEntryOrder() const {return transients_.get().allInEntryOrder_;}
00128       bool& resultCached() const {return transients_.get().resultCached_;}
00129       SortState& sortState() const {return transients_.get().sortState_;}
00130 
00131       std::vector<Element> entries_;
00132       mutable Transient<Transients> transients_;
00133   };
00134 
00135   bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
00136 
00137   inline
00138   bool operator>(FileIndex::Element const& lh, FileIndex::Element const& rh) {return rh < lh;}
00139 
00140   inline
00141   bool operator>=(FileIndex::Element const& lh, FileIndex::Element const& rh) {return !(lh < rh);}
00142 
00143   inline
00144   bool operator<=(FileIndex::Element const& lh, FileIndex::Element const& rh) {return !(rh < lh);}
00145 
00146   inline
00147   bool operator==(FileIndex::Element const& lh, FileIndex::Element const& rh) {return !(lh < rh || rh < lh);}
00148 
00149   inline
00150   bool operator!=(FileIndex::Element const& lh, FileIndex::Element const& rh) {return lh < rh || rh < lh;}
00151 
00152   class Compare_Run_Lumi_EventEntry {
00153   public:
00154     bool operator()(FileIndex::Element const& lh, FileIndex::Element const& rh);
00155   };
00156 
00157   std::ostream&
00158   operator<<(std::ostream& os, FileIndex const& fileIndex);
00159 }
00160 
00161 #endif