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 
19  FileIndex::Transients::Transients() : allInEntryOrder_(false), resultCached_(false), sortState_(kSorted_Run_Lumi_Event) {}
20 
21  void
23  allInEntryOrder_ = false;
24  resultCached_ = false;
26  }
27 
28  void
30  entries_.emplace_back(run, lumi, event, entry);
31  resultCached() = false;
33  }
34 
37  resultCached() = false;
39  }
40 
43  resultCached() = false;
45  }
46 
48  if(!resultCached()) {
49  resultCached() = true;
51  for(std::vector<FileIndex::Element>::const_iterator it = entries_.begin(), itEnd = entries_.end(); it != itEnd; ++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  assert(sortState() != kNotSorted);
69 
70  const_iterator itEnd = entries_.end();
71  const_iterator it;
72  Element el(run, lumi, event);
74  it = lower_bound_all(entries_, el);
75  bool lumiMissing = (lumi == 0 && event != 0);
76  if(lumiMissing) {
77  while(it != itEnd && it->run_ < run) {
78  ++it;
79  }
80  while(it != itEnd && (it->run_ == run && it->event_ < event)) {
81  ++it;
82  }
83  }
84  } else {
86  }
87  return it;
88  }
89 
92 
93  const_iterator it = findPosition(run, lumi, event);
94  const_iterator itEnd = entries_.end();
95  while(it != itEnd && it->getEntryType() != FileIndex::kEvent) {
96  ++it;
97  }
98  if(it == itEnd) {
99  return itEnd;
100  }
101  if(lumi == 0) {
102  lumi = it->lumi_;
103  }
104  if(it->run_ != run || it->lumi_ != lumi || it->event_ != event) {
106  return itEnd;
107  }
108  // not sorted by event, so we need to do a linear search
109  while (it != itEnd && it->run_ == run && it->lumi_ == lumi && it->event_ != event) {
110  ++it;
111  }
112  if(it->run_ != run || it->lumi_ != lumi || it->event_ != event) {
113  return itEnd;
114  }
115  }
116  return it;
117  }
118 
121  const_iterator it = findPosition(run, lumi, 0U);
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 
137  const_iterator it = findPosition(run, 0U, 0U);
138  const_iterator itEnd = entries_.end();
139  while(it != itEnd && it->getEntryType() != FileIndex::kRun) {
140  ++it;
141  }
142  if(it == itEnd) {
143  return itEnd;
144  }
145  if(it->run_ != run) {
146  return itEnd;
147  }
148  return it;
149  }
150 
153  const_iterator it = findPosition(run, lumi, 0U);
154  const_iterator itEnd = entries_.end();
155  while(it != itEnd && it->getEntryType() != FileIndex::kLumi && it->getEntryType() != FileIndex::kRun) {
156  ++it;
157  }
158  return it;
159  }
160 
163  assert(sortState() != kNotSorted);
164  const_iterator it;
165  const_iterator itEnd = entries_.end();
167  assert(lumi != 0U);
168  Element el(run, lumi, event, entry);
170  } else {
171  it = findEventPosition(run, lumi, event);
172  while(it != itEnd && it->entry_ != entry && it->event_ == event) {
173  ++it;
174  }
175  }
176  if(it == itEnd) return itEnd;
177  if(lumi == 0) lumi = it->lumi_;
178  if(it->run_ != run || it->lumi_ != lumi || it->event_ != event || it->entry_ != entry) return itEnd;
179  return it;
180  }
181 
183  if(lh.run_ == rh.run_) {
184  if(lh.lumi_ == rh.lumi_) {
185  return lh.event_ < rh.event_;
186  }
187  return lh.lumi_ < rh.lumi_;
188  }
189  return lh.run_ < rh.run_;
190  }
191 
193  if(lh.run_ == rh.run_) {
194  if(lh.lumi_ == rh.lumi_) {
195  if(lh.event_ == 0U && rh.event_ == 0U) {
196  return false;
197  } else if(lh.event_ == 0U) {
198  return true;
199  } else if(rh.event_ == 0U) {
200  return false;
201  } else {
202  return lh.entry_ < rh.entry_;
203  }
204  }
205  return lh.lumi_ < rh.lumi_;
206  }
207  return lh.run_ < rh.run_;
208  }
209 
210  std::ostream&
211  operator<<(std::ostream& os, FileIndex const& fileIndex) {
212 
213  os << "\nPrinting FileIndex contents. This includes a list of all Runs, LuminosityBlocks\n"
214  << "and Events stored in the root file.\n\n";
215  os << std::setw(15) << "Run"
216  << std::setw(15) << "Lumi"
217  << std::setw(15) << "Event"
218  << std::setw(15) << "TTree Entry"
219  << "\n";
220  for(std::vector<FileIndex::Element>::const_iterator it = fileIndex.begin(), itEnd = fileIndex.end(); it != itEnd; ++it) {
221  if(it->getEntryType() == FileIndex::kEvent) {
222  os << std::setw(15) << it->run_
223  << std::setw(15) << it ->lumi_
224  << std::setw(15) << it->event_
225  << std::setw(15) << it->entry_
226  << "\n";
227  }
228  else if(it->getEntryType() == FileIndex::kLumi) {
229  os << std::setw(15) << it->run_
230  << std::setw(15) << it ->lumi_
231  << std::setw(15) << " "
232  << std::setw(15) << it->entry_ << " (LuminosityBlock)"
233  << "\n";
234  }
235  else if(it->getEntryType() == FileIndex::kRun) {
236  os << std::setw(15) << it->run_
237  << std::setw(15) << " "
238  << std::setw(15) << " "
239  << std::setw(15) << it->entry_ << " (Run)"
240  << "\n";
241  }
242  }
243  return os;
244  }
245 }
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
const_iterator findEventEntryPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry) const
Definition: FileIndex.cc:162
ForwardSequence::const_iterator lower_bound_all(ForwardSequence const &s, Datum const &d)
wrappers for std::lower_bound
Definition: Algorithms.h:91
bool & allInEntryOrder() const
Definition: FileIndex.h:130
bool operator()(FileIndex::Element const &lh, FileIndex::Element const &rh)
Definition: FileIndex.cc:192
SortState & sortState() const
Definition: FileIndex.h:132
unsigned long long EventNumber_t
bool int lh
Definition: SIMDVec.h:21
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:135
unsigned int LuminosityBlockNumber_t
void sortBy_Run_Lumi_EventEntry()
Definition: FileIndex.cc:41
EntryNumber_t entry_
Definition: FileIndex.h:50
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:53
bool allEventsInEntryOrder() const
Definition: FileIndex.cc:47
static EntryNumber_t const invalidEntry
Definition: FileIndex.h:34
long long EntryNumber_t
Definition: FileIndex.h:23
const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: FileIndex.cc:91
const_iterator findRunPosition(RunNumber_t run) const
Definition: FileIndex.cc:136
const_iterator end() const
Definition: FileIndex.h:100
const_iterator findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:120
LuminosityBlockNumber_t lumi_
Definition: FileIndex.h:48
const_iterator findLumiOrRunPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:152
std::vector< Element > entries_
Definition: FileIndex.h:134
void sortBy_Run_Lumi_Event()
Definition: FileIndex.cc:35
void addEntry(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
Definition: FileIndex.cc:29
HLT enums.
const_iterator findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
Definition: FileIndex.cc:67
bool & resultCached() const
Definition: FileIndex.h:131
const_iterator begin() const
Definition: FileIndex.h:98
unsigned int RunNumber_t
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
EventNumber_t event_
Definition: FileIndex.h:49
Definition: event.py:1