CMS 3D CMS Logo

FileIndex.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 #include <iomanip>
6 #include <ostream>
7 
8 namespace edm {
9 
10  FileIndex::FileIndex() : entries_(), transient_() {}
11 
12  // The default value for sortState_ reflects the fact that
13  // the index is always sorted using Run, Lumi, and Event
14  // number by the PoolOutputModule before being written out.
15  // In the other case when we create a new FileIndex, the
16  // vector is empty, which is consistent with it having been
17  // sorted.
18 
20  : allInEntryOrder_(false), resultCached_(false), sortState_(kSorted_Run_Lumi_Event) {}
21 
23  allInEntryOrder_ = false;
24  resultCached_ = false;
25  sortState_ = kSorted_Run_Lumi_Event;
26  }
27 
29  entries_.emplace_back(run, lumi, event, entry);
30  resultCached() = false;
32  }
33 
36  resultCached() = false;
38  }
39 
42  resultCached() = false;
44  }
45 
47  if (!resultCached()) {
48  resultCached() = true;
50  for (std::vector<FileIndex::Element>::const_iterator it = entries_.begin(), itEnd = entries_.end(); it != itEnd;
51  ++it) {
52  if (it->getEntryType() == kEvent) {
53  if (it->entry_ < maxEntry) {
54  allInEntryOrder() = false;
55  return false;
56  }
57  maxEntry = it->entry_;
58  }
59  }
60  allInEntryOrder() = true;
61  return true;
62  }
63  return allInEntryOrder();
64  }
65 
68  EventNumber_t event) const {
70 
71  const_iterator itEnd = entries_.end();
72  const_iterator it;
73  Element el(run, lumi, event);
75  it = lower_bound_all(entries_, el);
76  bool lumiMissing = (lumi == 0 && event != 0);
77  if (lumiMissing) {
78  while (it != itEnd && it->run_ < run) {
79  ++it;
80  }
81  while (it != itEnd && (it->run_ == run && it->event_ < event)) {
82  ++it;
83  }
84  }
85  } else {
87  }
88  return it;
89  }
90 
93  EventNumber_t event) const {
95  const_iterator itEnd = entries_.end();
96  while (it != itEnd && it->getEntryType() != FileIndex::kEvent) {
97  ++it;
98  }
99  if (it == itEnd) {
100  return itEnd;
101  }
102  if (lumi == 0) {
103  lumi = it->lumi_;
104  }
105  if (it->run_ != run || it->lumi_ != lumi || it->event_ != event) {
107  return itEnd;
108  }
109  // not sorted by event, so we need to do a linear search
110  while (it != itEnd && it->run_ == run && it->lumi_ == lumi && it->event_ != event) {
111  ++it;
112  }
113  if (it->run_ != run || it->lumi_ != lumi || it->event_ != event) {
114  return itEnd;
115  }
116  }
117  return it;
118  }
119 
122  const_iterator itEnd = entries_.end();
123  while (it != itEnd && it->getEntryType() != FileIndex::kLumi) {
124  ++it;
125  }
126  if (it == itEnd) {
127  return itEnd;
128  }
129  if (it->run_ != run || it->lumi_ != lumi) {
130  return itEnd;
131  }
132  return it;
133  }
134 
136  const_iterator it = findPosition(run, 0U, 0U);
137  const_iterator itEnd = entries_.end();
138  while (it != itEnd && it->getEntryType() != FileIndex::kRun) {
139  ++it;
140  }
141  if (it == itEnd) {
142  return itEnd;
143  }
144  if (it->run_ != run) {
145  return itEnd;
146  }
147  return it;
148  }
149 
152  const_iterator itEnd = entries_.end();
153  while (it != itEnd && it->getEntryType() != FileIndex::kLumi && it->getEntryType() != FileIndex::kRun) {
154  ++it;
155  }
156  return it;
157  }
158 
162  EntryNumber_t entry) const {
164  const_iterator it;
165  const_iterator itEnd = entries_.end();
167  assert(lumi != 0U);
168  Element el(run, lumi, event, entry);
170  } else {
172  while (it != itEnd && it->entry_ != entry && it->event_ == event) {
173  ++it;
174  }
175  }
176  if (it == itEnd)
177  return itEnd;
178  if (lumi == 0)
179  lumi = it->lumi_;
180  if (it->run_ != run || it->lumi_ != lumi || it->event_ != event || it->entry_ != entry)
181  return itEnd;
182  return it;
183  }
184 
186  if (lh.run_ == rh.run_) {
187  if (lh.lumi_ == rh.lumi_) {
188  return lh.event_ < rh.event_;
189  }
190  return lh.lumi_ < rh.lumi_;
191  }
192  return lh.run_ < rh.run_;
193  }
194 
196  if (lh.run_ == rh.run_) {
197  if (lh.lumi_ == rh.lumi_) {
198  if (lh.event_ == 0U && rh.event_ == 0U) {
199  return false;
200  } else if (lh.event_ == 0U) {
201  return true;
202  } else if (rh.event_ == 0U) {
203  return false;
204  } else {
205  return lh.entry_ < rh.entry_;
206  }
207  }
208  return lh.lumi_ < rh.lumi_;
209  }
210  return lh.run_ < rh.run_;
211  }
212 
213  std::ostream& operator<<(std::ostream& os, FileIndex const& fileIndex) {
214  os << "\nPrinting FileIndex contents. This includes a list of all Runs, LuminosityBlocks\n"
215  << "and Events stored in the root file.\n\n";
216  os << std::setw(15) << "Run" << std::setw(15) << "Lumi" << std::setw(15) << "Event" << std::setw(15)
217  << "TTree Entry"
218  << "\n";
219  for (std::vector<FileIndex::Element>::const_iterator it = fileIndex.begin(), itEnd = fileIndex.end(); it != itEnd;
220  ++it) {
221  if (it->getEntryType() == FileIndex::kEvent) {
222  os << std::setw(15) << it->run_ << std::setw(15) << it->lumi_ << std::setw(15) << it->event_ << std::setw(15)
223  << it->entry_ << "\n";
224  } else if (it->getEntryType() == FileIndex::kLumi) {
225  os << std::setw(15) << it->run_ << std::setw(15) << it->lumi_ << std::setw(15) << " " << std::setw(15)
226  << it->entry_ << " (LuminosityBlock)"
227  << "\n";
228  } else if (it->getEntryType() == FileIndex::kRun) {
229  os << std::setw(15) << it->run_ << std::setw(15) << " " << std::setw(15) << " " << std::setw(15) << it->entry_
230  << " (Run)"
231  << "\n";
232  }
233  }
234  return os;
235  }
236 } // namespace edm
edm::FileIndex::sortState
SortState & sortState() const
Definition: FileIndex.h:118
edm::FileIndex
Definition: FileIndex.h:21
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
edm::FileIndex::findLumiPosition
const_iterator findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:120
edm::FileIndex::Element::event_
EventNumber_t event_
Definition: FileIndex.h:45
funct::false
false
Definition: Factorize.h:34
edm::FileIndex::kRun
Definition: FileIndex.h:30
edm::FileIndex::findEventPosition
const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: FileIndex.cc:91
edm::FileIndex::resultCached
bool & resultCached() const
Definition: FileIndex.h:117
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_splice.entry
entry
Definition: mps_splice.py:68
edm::FileIndex::entries_
std::vector< Element > entries_
Definition: FileIndex.h:120
edm::FileIndex::kNotSorted
Definition: FileIndex.h:103
Algorithms.h
cms::cuda::assert
assert(be >=bs)
mathSSE::lh
bool int lh
Definition: SIMDVec.h:20
edm::FileIndex::findLumiOrRunPosition
const_iterator findLumiOrRunPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:150
edm::Compare_Run_Lumi_EventEntry
Definition: FileIndex.h:137
edm::FileIndex::kSorted_Run_Lumi_EventEntry
Definition: FileIndex.h:103
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
edm::FileIndex::begin
const_iterator begin() const
Definition: FileIndex.h:85
edm::operator<<
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
Definition: HLTGlobalStatus.h:106
edm::FileIndex::Transients::reset
void reset()
Definition: FileIndex.cc:22
edm::FileIndex::FileIndex
FileIndex()
Definition: FileIndex.cc:10
edm::FileIndex::Transients::Transients
Transients()
Definition: FileIndex.cc:19
edm::Compare_Run_Lumi_EventEntry::operator()
bool operator()(FileIndex::Element const &lh, FileIndex::Element const &rh)
Definition: FileIndex.cc:195
edm::operator<
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
edm::FileIndex::EntryNumber_t
long long EntryNumber_t
Definition: FileIndex.h:23
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
edm::FileIndex::Element::entry_
EntryNumber_t entry_
Definition: FileIndex.h:46
edm::FileIndex::end
const_iterator end() const
Definition: FileIndex.h:87
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::FileIndex::const_iterator
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:49
edm::FileIndex::addEntry
void addEntry(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
Definition: FileIndex.cc:28
edm::FileIndex::kLumi
Definition: FileIndex.h:30
edm::FileIndex::sortBy_Run_Lumi_EventEntry
void sortBy_Run_Lumi_EventEntry()
Definition: FileIndex.cc:40
FileIndex.h
edm::FileIndex::allInEntryOrder
bool & allInEntryOrder() const
Definition: FileIndex.h:116
edm::FileIndex::findPosition
const_iterator findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
Definition: FileIndex.cc:66
edm::lower_bound_all
ForwardSequence::const_iterator lower_bound_all(ForwardSequence const &s, Datum const &d)
wrappers for std::lower_bound
Definition: Algorithms.h:69
edm::FileIndex::Element::invalidEntry
static const EntryNumber_t invalidEntry
Definition: FileIndex.h:34
edm::FileIndex::allEventsInEntryOrder
bool allEventsInEntryOrder() const
Definition: FileIndex.cc:46
edm::FileIndex::Element::lumi_
LuminosityBlockNumber_t lumi_
Definition: FileIndex.h:44
edm::FileIndex::Element::run_
RunNumber_t run_
Definition: FileIndex.h:43
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::FileIndex::kSorted_Run_Lumi_Event
Definition: FileIndex.h:103
edm::FileIndex::sortBy_Run_Lumi_Event
void sortBy_Run_Lumi_Event()
Definition: FileIndex.cc:34
edm::FileIndex::findRunPosition
const_iterator findRunPosition(RunNumber_t run) const
Definition: FileIndex.cc:135
edm::FileIndex::kEvent
Definition: FileIndex.h:30
edm::FileIndex::findEventEntryPosition
const_iterator findEventEntryPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry) const
Definition: FileIndex.cc:159
edm::stable_sort_all
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
event
Definition: event.py:1
lumi
Definition: LumiSectionData.h:20
edm::FileIndex::Element
Definition: FileIndex.h:32