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