Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
art::FileIndex Class Reference

#include <FileIndex.h>

Classes

struct  Element
 
struct  Transients
 

Public Types

enum  EntryType { kRun, kSubRun, kEvent, kEnd }
 
enum  SortState { kNotSorted, kSorted_Run_SubRun_Event, kSorted_Run_SubRun_EventEntry }
 
using EntryNumber_t = long long
 
using const_iterator = std::vector< Element >::const_iterator
 
using iterator = std::vector< Element >::iterator
 

Public Member Functions

void addEntry (EventID const &eID, EntryNumber_t entry)
 
void addEntryOnLoad (EventID const &eID, EntryNumber_t entry)
 
void sortBy_Run_SubRun_Event ()
 
void sortBy_Run_SubRun_EventEntry ()
 
const_iterator findPosition (EventID const &eID) const
 
const_iterator findPosition (EventID const &eID, bool exact) const
 
const_iterator findPosition (SubRunID const &srID, bool exact) const
 
const_iterator findPosition (RunID const &rID, bool exact) const
 
const_iterator findSubRunOrRunPosition (SubRunID const &srID) const
 
bool contains (EventID const &id, bool exact) const
 
bool contains (SubRunID const &id, bool exact) const
 
bool contains (RunID const &id, bool exact) const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
std::vector< Element >::size_type size () const
 
bool empty () const
 
bool allEventsInEntryOrder () const
 
bool eventsUniqueAndOrdered () const
 
void print_event_list (std::ostream &os) const
 

Private Member Functions

boolallInEntryOrder () const
 
boolresultCached () const
 
SortStatesortState () const
 
const_iterator findEventForUnspecifiedSubRun (EventID const &eID, bool exact) const
 

Private Attributes

std::vector< Elemententries_ {}
 
Transient< Transientstransients_ {}
 

Friends

bool operator== (FileIndex const &, FileIndex const &)
 

Detailed Description

Definition at line 39 of file FileIndex.h.

Member Typedef Documentation

Definition at line 63 of file FileIndex.h.

using art::FileIndex::EntryNumber_t = long long

Definition at line 41 of file FileIndex.h.

Definition at line 64 of file FileIndex.h.

Member Enumeration Documentation

Enumerator
kRun 
kSubRun 
kEvent 
kEnd 

Definition at line 43 of file FileIndex.h.

43  {
44  kRun, /* 0 */
45  kSubRun, /* 1 */
46  kEvent, /* 2 */
47  kEnd /* 3 */
48  };
Enumerator
kNotSorted 
kSorted_Run_SubRun_Event 
kSorted_Run_SubRun_EventEntry 

Definition at line 66 of file FileIndex.h.

Member Function Documentation

void art::FileIndex::addEntry ( EventID const &  eID,
EntryNumber_t  entry 
)

Definition at line 134 of file FileIndex.cc.

135  {
136  entries_.emplace_back(eID, entry);
137  resultCached() = false;
138  sortState() = kNotSorted;
139  }
QList< Entry > entry
SortState & sortState() const
Definition: FileIndex.cc:110
std::vector< Element > entries_
Definition: FileIndex.h:126
bool & resultCached() const
Definition: FileIndex.cc:104
void art::FileIndex::addEntryOnLoad ( EventID const &  eID,
EntryNumber_t  entry 
)

Definition at line 142 of file FileIndex.cc.

143  {
144  entries_.emplace_back(eID, entry);
145  resultCached() = false;
146  }
QList< Entry > entry
std::vector< Element > entries_
Definition: FileIndex.h:126
bool & resultCached() const
Definition: FileIndex.cc:104
bool art::FileIndex::allEventsInEntryOrder ( ) const

Definition at line 165 of file FileIndex.cc.

166  {
167  if (!resultCached()) {
168  resultCached() = true;
170  for (auto const& e : entries_) {
171  if (e.getEntryType() == kEvent) {
172  if (e.entry < maxEntry) {
173  allInEntryOrder() = false;
174  return false;
175  }
176  maxEntry = e.entry;
177  }
178  }
179  allInEntryOrder() = true;
180  return true;
181  }
182  return allInEntryOrder();
183  }
art::FileIndex::EntryNumber_t EntryNumber_t
bool & allInEntryOrder() const
Definition: FileIndex.cc:98
const double e
static constexpr EntryNumber_t invalid
Definition: FileIndex.h:51
std::vector< Element > entries_
Definition: FileIndex.h:126
bool & resultCached() const
Definition: FileIndex.cc:104
bool & art::FileIndex::allInEntryOrder ( ) const
private

Definition at line 98 of file FileIndex.cc.

99  {
100  return transients_.get().allInEntryOrder;
101  }
Transient< Transients > transients_
Definition: FileIndex.h:127
FileIndex::iterator art::FileIndex::begin ( )

Definition at line 50 of file FileIndex.cc.

51  {
52  return entries_.begin();
53  }
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::begin ( ) const

Definition at line 56 of file FileIndex.cc.

57  {
58  return entries_.begin();
59  }
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::cbegin ( ) const

Definition at line 62 of file FileIndex.cc.

63  {
64  return entries_.begin();
65  }
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::cend ( ) const

Definition at line 80 of file FileIndex.cc.

81  {
82  return entries_.end();
83  }
std::vector< Element > entries_
Definition: FileIndex.h:126
bool art::FileIndex::contains ( EventID const &  id,
bool  exact 
) const

Definition at line 116 of file FileIndex.cc.

117  {
118  return findPosition(id, exact) != entries_.end();
119  }
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
std::vector< Element > entries_
Definition: FileIndex.h:126
bool art::FileIndex::contains ( SubRunID const &  id,
bool  exact 
) const

Definition at line 122 of file FileIndex.cc.

123  {
124  return findPosition(id, exact) != entries_.end();
125  }
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
std::vector< Element > entries_
Definition: FileIndex.h:126
bool art::FileIndex::contains ( RunID const &  id,
bool  exact 
) const

Definition at line 128 of file FileIndex.cc.

129  {
130  return findPosition(id, exact) != entries_.end();
131  }
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
std::vector< Element > entries_
Definition: FileIndex.h:126
bool art::FileIndex::empty ( ) const

Definition at line 92 of file FileIndex.cc.

93  {
94  return entries_.empty();
95  }
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::iterator art::FileIndex::end ( )

Definition at line 68 of file FileIndex.cc.

69  {
70  return entries_.end();
71  }
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::end ( ) const

Definition at line 74 of file FileIndex.cc.

75  {
76  return entries_.end();
77  }
std::vector< Element > entries_
Definition: FileIndex.h:126
bool art::FileIndex::eventsUniqueAndOrdered ( ) const

Definition at line 186 of file FileIndex.cc.

187  {
188  auto it = cbegin();
189  auto itEnd = cend();
190  // Set up the iterators to point to first two events
191  // (In the trivial case where there is zero or one event,
192  // the set is unique and ordered by construction).
193  if (it == itEnd) {
194  return true;
195  }
196  // Step to first event
197  while (it->getEntryType() != kEvent) {
198  ++it;
199  if (it == itEnd) {
200  return true;
201  }
202  }
203  auto itPrevious = it;
204  // Step to second event
205  ++it;
206  if (it == itEnd) {
207  return true;
208  }
209  while (it->getEntryType() != kEvent) {
210  ++it;
211  if (it == itEnd) {
212  return true;
213  }
214  }
215  for (; it != itEnd; ++it) {
216  if (it->getEntryType() == kEvent) {
217  if (it->eventID <= itPrevious->eventID) {
218  return false;
219  }
220  itPrevious = it;
221  }
222  }
223  return true; // finished and found no duplicates
224  }
const_iterator cbegin() const
Definition: FileIndex.cc:62
const_iterator cend() const
Definition: FileIndex.cc:80
FileIndex::const_iterator art::FileIndex::findEventForUnspecifiedSubRun ( EventID const &  eID,
bool  exact 
) const
private

Definition at line 347 of file FileIndex.cc.

348  {
349  RunID const& runID = eID.runID();
350  EventNumber_t event = eID.event();
351  SubRunID last_subRunID;
352  // Try to find the event.
353  auto const firstEvent =
355  const_iterator it = firstEvent;
356  const_iterator const itEnd = entries_.end();
357  if (it == itEnd) {
358  return it;
359  }
360 
361  // Starting with it, jump to the first event of each subrun until
362  // we find either:
363  //
364  // 1. The next run.
365  // 2. An event number higher than we want.
366  // 3. The end of the file index.
367  while ((it != itEnd) && (it->eventID.runID() == runID) &&
368  (it->eventID.event() < event)) {
369  last_subRunID = it->eventID.subRunID();
370  // Get the first event in the next subrun.
371  it =
372  findPosition(EventID::firstEvent(it->eventID.subRunID().next()), false);
373  }
374  const_iterator result = itEnd;
375  if ((it != itEnd) && (it->eventID.runID() == runID) &&
376  (it->eventID.event() == event)) {
377  // We started on the correct event.
378  result = it;
379  } else if (last_subRunID.isValid()) {
380  // Find the event in the last subrun.
381  result = findPosition(EventID(last_subRunID, event), exact);
382  }
383  if (result == itEnd) {
384  // Did not find anything.
385  mf::LogWarning("FileIndex")
386  << "Could not find incompletely specified event " << eID
387  << " with smart algorithm:\n"
388  << "Assuming pathological file structure (event selection?) and\n"
389  << "trying again (inefficient).\n"
390  << "NOTE: this will find only the event with matching event number "
391  << "and the\n"
392  << " lowest subrun number: any others are inaccessible via this "
393  << "method.";
394  SubRunID trySubRun{SubRunID::firstSubRun(runID)};
395  // Try to find the highest subrun number in this run.
396  const_iterator findIt(firstEvent);
397  SubRunID lastSubRunInRun{trySubRun};
398  for (; findIt != itEnd && findIt->eventID.runID() == runID;
399  findIt =
400  findPosition(EventID::firstEvent(lastSubRunInRun.next()), false)) {
401  lastSubRunInRun = findIt->eventID.subRunID();
402  }
403  // Now loop through each subrun looking for an exact match to our event.
404  while ((findIt = findPosition(EventID(trySubRun, event), true)) ==
405  itEnd &&
406  trySubRun < lastSubRunInRun) {
407  trySubRun = trySubRun.next();
408  }
409  result = findIt;
410  }
411  return result;
412  }
static QCString result
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
static SubRunID firstSubRun()
Definition: SubRunID.h:153
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
static EventID firstEvent()
Definition: EventID.h:190
std::vector< Element > entries_
Definition: FileIndex.h:126
Event finding and building.
FileIndex::const_iterator art::FileIndex::findPosition ( EventID const &  eID) const

Definition at line 227 of file FileIndex.cc.

228  {
229  assert(sortState() == kSorted_Run_SubRun_Event);
230  Element el{eID};
231  return lower_bound_all(entries_, el);
232  }
auto lower_bound_all(FwdCont &, Datum const &)
SortState & sortState() const
Definition: FileIndex.cc:110
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::findPosition ( EventID const &  eID,
bool  exact 
) const

Definition at line 235 of file FileIndex.cc.

236  {
237  assert(sortState() == kSorted_Run_SubRun_Event);
238  if (subRunUnspecified(eID)) {
239  return findEventForUnspecifiedSubRun(eID, exact);
240  }
241  const_iterator it = findPosition(eID);
242  const_iterator itEnd = entries_.end();
243  while (it != itEnd && it->getEntryType() != FileIndex::kEvent) {
244  ++it;
245  }
246  if (it == itEnd) {
247  return itEnd;
248  }
249  if (exact && (*it != eID)) {
250  return itEnd;
251  }
252  return it;
253  }
SortState & sortState() const
Definition: FileIndex.cc:110
const_iterator findEventForUnspecifiedSubRun(EventID const &eID, bool exact) const
Definition: FileIndex.cc:347
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::findPosition ( SubRunID const &  srID,
bool  exact 
) const

Definition at line 256 of file FileIndex.cc.

257  {
258  assert(sortState() != kNotSorted);
259  const_iterator it;
260  auto const invID = EventID::invalidEvent(srID);
262  Element const el{invID};
263  it = lower_bound_all(entries_, el, Compare_Run_SubRun_EventEntry());
264  } else {
265  it = findPosition(invID);
266  }
267  auto const itEnd = entries_.cend();
268  while (it != itEnd && it->getEntryType() != FileIndex::kSubRun) {
269  ++it;
270  }
271  if (it == itEnd) {
272  return itEnd;
273  }
274  if (exact && (it->eventID.subRunID() != srID)) {
275  return itEnd;
276  }
277  return it;
278  }
auto lower_bound_all(FwdCont &, Datum const &)
SortState & sortState() const
Definition: FileIndex.cc:110
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
static constexpr EventID invalidEvent() noexcept
Definition: EventID.h:202
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::findPosition ( RunID const &  rID,
bool  exact 
) const

Definition at line 281 of file FileIndex.cc.

282  {
283  assert(sortState() != kNotSorted);
284  const_iterator it;
285  auto const invID = EventID::invalidEvent(rID);
287  Element const el{invID};
288  it = lower_bound_all(entries_, el, Compare_Run_SubRun_EventEntry());
289  } else {
290  it = findPosition(invID);
291  }
292  auto const itEnd = entries_.cend();
293  while (it != itEnd && it->getEntryType() != FileIndex::kRun) {
294  ++it;
295  }
296  if (it == itEnd) {
297  return itEnd;
298  }
299  if (exact && (it->eventID.runID() != rID)) {
300  return itEnd;
301  }
302  return it;
303  }
auto lower_bound_all(FwdCont &, Datum const &)
SortState & sortState() const
Definition: FileIndex.cc:110
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
static constexpr EventID invalidEvent() noexcept
Definition: EventID.h:202
std::vector< Element > entries_
Definition: FileIndex.h:126
FileIndex::const_iterator art::FileIndex::findSubRunOrRunPosition ( SubRunID const &  srID) const

Definition at line 306 of file FileIndex.cc.

307  {
308  assert(sortState() != kNotSorted);
309  const_iterator it;
311  Element el{EventID::invalidEvent(srID)};
312  it = lower_bound_all(entries_, el, Compare_Run_SubRun_EventEntry());
313  } else {
315  }
316  auto const itEnd = entries_.cend();
317  while (it != itEnd && it->getEntryType() != FileIndex::kSubRun &&
318  it->getEntryType() != FileIndex::kRun) {
319  ++it;
320  }
321  return it;
322  }
auto lower_bound_all(FwdCont &, Datum const &)
SortState & sortState() const
Definition: FileIndex.cc:110
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
static constexpr EventID invalidEvent() noexcept
Definition: EventID.h:202
std::vector< Element > entries_
Definition: FileIndex.h:126
void art::FileIndex::print_event_list ( std::ostream &  os) const

Definition at line 325 of file FileIndex.cc.

326  {
327  os << "\nPrinting the list of Runs, SubRuns, and Events stored in the root "
328  "file.\n\n";
329  os << setw(15) << "Run" << setw(15) << "SubRun" << setw(15) << "Event"
330  << "\n";
331  for (auto const& e : entries_) {
332  if (e.getEntryType() == FileIndex::kEvent) {
333  os << setw(15) << e.eventID.run() << setw(15) << e.eventID.subRun()
334  << setw(15) << e.eventID.event() << "\n";
335  } else if (e.getEntryType() == FileIndex::kSubRun) {
336  os << setw(15) << e.eventID.run() << setw(15) << e.eventID.subRun()
337  << setw(15) << " "
338  << "\n";
339  } else if (e.getEntryType() == FileIndex::kRun) {
340  os << setw(15) << e.eventID.run() << setw(15) << " " << setw(15) << " "
341  << "\n";
342  }
343  }
344  }
const double e
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::vector< Element > entries_
Definition: FileIndex.h:126
bool & art::FileIndex::resultCached ( ) const
private

Definition at line 104 of file FileIndex.cc.

105  {
106  return transients_.get().resultCached;
107  }
Transient< Transients > transients_
Definition: FileIndex.h:127
std::vector< FileIndex::Element >::size_type art::FileIndex::size ( ) const

Definition at line 86 of file FileIndex.cc.

87  {
88  return entries_.size();
89  }
std::vector< Element > entries_
Definition: FileIndex.h:126
void art::FileIndex::sortBy_Run_SubRun_Event ( )

Definition at line 149 of file FileIndex.cc.

150  {
152  resultCached() = false;
154  }
void stable_sort_all(RandCont &)
SortState & sortState() const
Definition: FileIndex.cc:110
std::vector< Element > entries_
Definition: FileIndex.h:126
bool & resultCached() const
Definition: FileIndex.cc:104
void art::FileIndex::sortBy_Run_SubRun_EventEntry ( )

Definition at line 157 of file FileIndex.cc.

158  {
159  stable_sort_all(entries_, Compare_Run_SubRun_EventEntry());
160  resultCached() = false;
162  }
void stable_sort_all(RandCont &)
SortState & sortState() const
Definition: FileIndex.cc:110
std::vector< Element > entries_
Definition: FileIndex.h:126
bool & resultCached() const
Definition: FileIndex.cc:104
FileIndex::SortState & art::FileIndex::sortState ( ) const
private

Definition at line 110 of file FileIndex.cc.

111  {
112  return transients_.get().sortState;
113  }
Transient< Transients > transients_
Definition: FileIndex.h:127

Friends And Related Function Documentation

bool operator== ( FileIndex const &  ,
FileIndex const &   
)
friend

Definition at line 451 of file FileIndex.cc.

452  {
453  return lh.entries_ == rh.entries_;
454  }

Member Data Documentation

std::vector<Element> art::FileIndex::entries_ {}
private

Definition at line 126 of file FileIndex.h.

Transient<Transients> art::FileIndex::transients_ {}
mutableprivate

Definition at line 127 of file FileIndex.h.


The documentation for this class was generated from the following files: