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
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
const_iterator findLumiOrRunPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:150
const_iterator findRunPosition(RunNumber_t run) const
Definition: FileIndex.cc:135
ForwardSequence::const_iterator lower_bound_all(ForwardSequence const &s, Datum const &d)
wrappers for std::lower_bound
Definition: Algorithms.h:69
const_iterator end() const
Definition: FileIndex.h:87
bool operator()(FileIndex::Element const &lh, FileIndex::Element const &rh)
Definition: FileIndex.cc:195
bool & resultCached() const
Definition: FileIndex.h:117
unsigned long long EventNumber_t
bool allEventsInEntryOrder() const
Definition: FileIndex.cc:46
bool int lh
Definition: SIMDVec.h:20
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: FileIndex.cc:91
assert(be >=bs)
unsigned int LuminosityBlockNumber_t
void sortBy_Run_Lumi_EventEntry()
Definition: FileIndex.cc:40
EntryNumber_t entry_
Definition: FileIndex.h:46
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:49
const_iterator findEventEntryPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry) const
Definition: FileIndex.cc:159
static EntryNumber_t const invalidEntry
Definition: FileIndex.h:34
long long EntryNumber_t
Definition: FileIndex.h:23
LuminosityBlockNumber_t lumi_
Definition: FileIndex.h:44
const_iterator begin() const
Definition: FileIndex.h:85
std::vector< Element > entries_
Definition: FileIndex.h:120
void sortBy_Run_Lumi_Event()
Definition: FileIndex.cc:34
void addEntry(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
Definition: FileIndex.cc:28
const_iterator findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:120
HLT enums.
unsigned int RunNumber_t
bool & allInEntryOrder() const
Definition: FileIndex.h:116
const_iterator findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
Definition: FileIndex.cc:66
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger table.
EventNumber_t event_
Definition: FileIndex.h:45
SortState & sortState() const
Definition: FileIndex.h:118
Definition: event.py:1