LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
art::FileIndex Class Reference

#include "FileIndex.h"

Classes

class  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

 FileIndex ()=default
 
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
 
template<typename ID >
const_iterator findPosition (ID const &id, bool exact) const
 
const_iterator findSubRunOrRunPosition (SubRunID const &srID) const
 
template<typename ID >
bool contains (ID 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
 
template<>
FileIndex::const_iterator findPosition (EventID const &eID, bool exact) const
 
template<>
FileIndex::const_iterator findPosition (SubRunID const &srID, bool exact) const
 
template<>
FileIndex::const_iterator findPosition (RunID const &rID, bool exact) const
 

Private Member Functions

bool & allInEntryOrder () const
 
bool & resultCached () const
 
SortStatesortState () const
 
const_iterator findEventForUnspecifiedSubRun (EventID const &eID, bool exact) const
 

Private Attributes

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

Detailed Description

Definition at line 40 of file FileIndex.h.

Member Typedef Documentation

Definition at line 72 of file FileIndex.h.

using art::FileIndex::EntryNumber_t = long long

Definition at line 43 of file FileIndex.h.

using art::FileIndex::iterator = std::vector<Element>::iterator

Definition at line 73 of file FileIndex.h.

Member Enumeration Documentation

Enumerator
kRun 
kSubRun 
kEvent 
kEnd 

Definition at line 51 of file FileIndex.h.

Enumerator
kNotSorted 
kSorted_Run_SubRun_Event 
kSorted_Run_SubRun_EventEntry 

Definition at line 142 of file FileIndex.h.

Constructor & Destructor Documentation

art::FileIndex::FileIndex ( )
default

Member Function Documentation

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

Definition at line 29 of file FileIndex.cc.

Referenced by art::RootOutputFile::writeOne(), art::RootOutputFile::writeRun(), and art::RootOutputFile::writeSubRun().

30  {
31  entries_.emplace_back(eID, entry);
32  resultCached() = false;
34  }
bool & resultCached() const
Definition: FileIndex.h:166
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
void art::FileIndex::addEntryOnLoad ( EventID const &  eID,
EntryNumber_t  entry 
)

Definition at line 37 of file FileIndex.cc.

Referenced by art::detail::readFileIndex().

38  {
39  entries_.emplace_back(eID, entry);
40  resultCached() = false;
41  }
bool & resultCached() const
Definition: FileIndex.h:166
std::vector< Element > entries_
Definition: FileIndex.h:179
bool art::FileIndex::allEventsInEntryOrder ( ) const

Definition at line 60 of file FileIndex.cc.

References e.

Referenced by empty().

61  {
62  if (!resultCached()) {
63  resultCached() = true;
65  for (auto const& e : entries_) {
66  if (e.getEntryType() == kEvent) {
67  if (e.entry_ < maxEntry) {
68  allInEntryOrder() = false;
69  return false;
70  }
71  maxEntry = e.entry_;
72  }
73  }
74  allInEntryOrder() = true;
75  return true;
76  }
77  return allInEntryOrder();
78  }
bool & resultCached() const
Definition: FileIndex.h:166
static EntryNumber_t constexpr invalidEntry
Definition: FileIndex.h:55
art::FileIndex::EntryNumber_t EntryNumber_t
bool & allInEntryOrder() const
Definition: FileIndex.h:161
Float_t e
Definition: plot.C:34
std::vector< Element > entries_
Definition: FileIndex.h:179
bool& art::FileIndex::allInEntryOrder ( ) const
inlineprivate

Definition at line 161 of file FileIndex.h.

References transients_.

162  {
163  return transients_.get().allInEntryOrder_;
164  }
Transient< Transients > transients_
Definition: FileIndex.h:180
iterator art::FileIndex::begin ( )
inline

Definition at line 93 of file FileIndex.h.

References entries_.

94  {
95  return entries_.begin();
96  }
std::vector< Element > entries_
Definition: FileIndex.h:179
const_iterator art::FileIndex::begin ( ) const
inline

Definition at line 98 of file FileIndex.h.

References entries_.

99  {
100  return entries_.begin();
101  }
std::vector< Element > entries_
Definition: FileIndex.h:179
const_iterator art::FileIndex::cbegin ( ) const
inline

Definition at line 103 of file FileIndex.h.

References entries_.

Referenced by art::detail::InfoDumperInputFile::print_range_sets().

104  {
105  return entries_.begin();
106  }
std::vector< Element > entries_
Definition: FileIndex.h:179
const_iterator art::FileIndex::cend ( ) const
inline

Definition at line 119 of file FileIndex.h.

References entries_.

Referenced by art::MixHelper::mixAndPut(), and art::detail::InfoDumperInputFile::print_range_sets().

120  {
121  return entries_.end();
122  }
std::vector< Element > entries_
Definition: FileIndex.h:179
template<typename ID >
bool art::FileIndex::contains ( ID const &  id,
bool  exact 
) const
inline

Definition at line 87 of file FileIndex.h.

References entries_, and findPosition().

88  {
89  return findPosition(id, exact) != entries_.end();
90  }
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
std::vector< Element > entries_
Definition: FileIndex.h:179
bool art::FileIndex::empty ( void  ) const
inline

Definition at line 131 of file FileIndex.h.

References allEventsInEntryOrder(), entries_, eventsUniqueAndOrdered(), and print_event_list().

132  {
133  return entries_.empty();
134  }
std::vector< Element > entries_
Definition: FileIndex.h:179
iterator art::FileIndex::end ( void  )
inline

Definition at line 109 of file FileIndex.h.

References entries_.

110  {
111  return entries_.end();
112  }
std::vector< Element > entries_
Definition: FileIndex.h:179
const_iterator art::FileIndex::end ( void  ) const
inline

Definition at line 114 of file FileIndex.h.

References entries_.

115  {
116  return entries_.end();
117  }
std::vector< Element > entries_
Definition: FileIndex.h:179
bool art::FileIndex::eventsUniqueAndOrdered ( ) const

Definition at line 81 of file FileIndex.cc.

Referenced by empty(), and art::DuplicateChecker::init().

82  {
83 
84  auto it = cbegin();
85  auto itEnd = cend();
86 
87  // Set up the iterators to point to first two events
88  // (In the trivial case where there is zero or one event,
89  // the set is unique and ordered by construction).
90 
91  if (it == itEnd)
92  return true;
93 
94  // Step to first event
95  while (it->getEntryType() != kEvent) {
96  ++it;
97  if (it == itEnd)
98  return true;
99  }
100  auto itPrevious = it;
101 
102  // Step to second event
103  ++it;
104  if (it == itEnd)
105  return true;
106  while (it->getEntryType() != kEvent) {
107  ++it;
108  if (it == itEnd)
109  return true;
110  }
111 
112  for (; it != itEnd; ++it) {
113  if (it->getEntryType() == kEvent) {
114  if (it->eventID_ <= itPrevious->eventID_)
115  return false;
116  itPrevious = it;
117  }
118  }
119  return true; // finished and found no duplicates
120  }
const_iterator cbegin() const
Definition: FileIndex.h:103
const_iterator cend() const
Definition: FileIndex.h:119
FileIndex::const_iterator art::FileIndex::findEventForUnspecifiedSubRun ( EventID const &  eID,
bool  exact 
) const
private

Definition at line 305 of file FileIndex.cc.

References art::EventID::event(), art::SubRunID::isValid(), art::SubRunID::next(), and art::EventID::runID().

Referenced by sortState().

306  {
307 
308  RunID const& runID = eID.runID();
309  EventNumber_t event = eID.event();
310  SubRunID last_subRunID;
311 
312  // Try to find the event.
313  auto const firstEvent =
315  const_iterator it = firstEvent;
316  const_iterator const itEnd = entries_.end();
317  if (it == itEnd)
318  return it;
319 
320  // Starting with it, jump to the first event of each subrun until
321  // we find either:
322  //
323  // 1. The next run.
324  // 2. An event number higher than we want.
325  // 3. The end of the file index.
326  while ((it != itEnd) && (it->eventID_.runID() == runID) &&
327  (it->eventID_.event() < event)) {
328  last_subRunID = it->eventID_.subRunID();
329  // Get the first event in the next subrun.
330  it = findPosition(EventID::firstEvent(it->eventID_.subRunID().next()),
331  false);
332  }
333 
334  const_iterator result = itEnd;
335  if ((it != itEnd) && (it->eventID_.runID() == runID) &&
336  (it->eventID_.event() == event)) {
337  // We started on the correct event.
338  result = it;
339  } else if (last_subRunID.isValid()) {
340  // Find the event in the last subrun.
341  result = findPosition(EventID(last_subRunID, event), exact);
342  }
343  if (result == itEnd) {
344  // Did not find anything.
345  mf::LogWarning("FileIndex")
346  << "Could not find incompletely specified event " << eID
347  << " with smart algorithm:\n"
348  << "Assuming pathological file structure (event selection?) and\n"
349  << "trying again (inefficient).\n"
350  << "NOTE: this will find only the event with matching event number "
351  << "and the\n"
352  << " lowest subrun number: any others are inaccessible via this "
353  << "method.";
354  SubRunID trySubRun{SubRunID::firstSubRun(runID)};
355  // Try to find the highest subrun number in this run.
356  const_iterator findIt(firstEvent);
357  SubRunID lastSubRunInRun{trySubRun};
358  for (; findIt != itEnd && findIt->eventID_.runID() == runID;
359  findIt =
360  findPosition(EventID::firstEvent(lastSubRunInRun.next()), false)) {
361  lastSubRunInRun = findIt->eventID_.subRunID();
362  }
363  // Now loop through each subrun looking for an exact match to our event.
364  while ((findIt = findPosition(EventID(trySubRun, event), true)) ==
365  itEnd &&
366  trySubRun < lastSubRunInRun) {
367  trySubRun = trySubRun.next();
368  }
369  result = findIt;
370  }
371  return result;
372  }
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
static SubRunID firstSubRun()
Definition: SubRunID.h:152
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
static EventID firstEvent()
Definition: EventID.h:191
std::vector< Element > entries_
Definition: FileIndex.h:179
Event finding and building.
FileIndex::const_iterator art::FileIndex::findPosition ( EventID const &  eID) const

Definition at line 123 of file FileIndex.cc.

Referenced by contains(), art::MixHelper::mixAndPut(), and art::RootInputFile::setEntry().

124  {
125 
126  assert(sortState() == kSorted_Run_SubRun_Event);
127 
128  Element el{eID};
129  return lower_bound_all(entries_, el);
130  }
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
template<typename ID >
const_iterator art::FileIndex::findPosition ( ID const &  id,
bool  exact 
) const
template<>
FileIndex::const_iterator art::FileIndex::findPosition ( EventID const &  eID,
bool  exact 
) const

Definition at line 134 of file FileIndex.cc.

135  {
136 
137  assert(sortState() == kSorted_Run_SubRun_Event);
138 
139  if (subRunUnspecified(eID)) {
140  return findEventForUnspecifiedSubRun(eID, exact);
141  }
142 
143  const_iterator it = findPosition(eID);
144  const_iterator itEnd = entries_.end();
145  while (it != itEnd && it->getEntryType() != FileIndex::kEvent) {
146  ++it;
147  }
148  if (it == itEnd)
149  return itEnd;
150  if (exact && (*it != eID))
151  return itEnd;
152  return it;
153  }
const_iterator findEventForUnspecifiedSubRun(EventID const &eID, bool exact) const
Definition: FileIndex.cc:305
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
template<>
FileIndex::const_iterator art::FileIndex::findPosition ( SubRunID const &  srID,
bool  exact 
) const

Definition at line 157 of file FileIndex.cc.

158  {
159  assert(sortState() != kNotSorted);
160  const_iterator it;
161  auto const invID = EventID::invalidEvent(srID);
163  Element const el{invID};
164  it = lower_bound_all(entries_, el, Compare_Run_SubRun_EventEntry());
165  } else {
166  it = findPosition(invID);
167  }
168  auto const itEnd = entries_.cend();
169  while (it != itEnd && it->getEntryType() != FileIndex::kSubRun) {
170  ++it;
171  }
172  if (it == itEnd)
173  return itEnd;
174  if (exact && (it->eventID_.subRunID() != srID))
175  return itEnd;
176  return it;
177  }
static constexpr EventID invalidEvent()
Definition: EventID.h:203
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
template<>
FileIndex::const_iterator art::FileIndex::findPosition ( RunID const &  rID,
bool  exact 
) const

Definition at line 181 of file FileIndex.cc.

182  {
183  assert(sortState() != kNotSorted);
184  const_iterator it;
185  auto const invID = EventID::invalidEvent(rID);
187  Element const el{invID};
188  it = lower_bound_all(entries_, el, Compare_Run_SubRun_EventEntry());
189  } else {
190  it = findPosition(invID);
191  }
192  auto const itEnd = entries_.cend();
193  while (it != itEnd && it->getEntryType() != FileIndex::kRun) {
194  ++it;
195  }
196  if (it == itEnd)
197  return itEnd;
198  if (exact && (it->eventID_.runID() != rID))
199  return itEnd;
200  return it;
201  }
static constexpr EventID invalidEvent()
Definition: EventID.h:203
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
FileIndex::const_iterator art::FileIndex::findSubRunOrRunPosition ( SubRunID const &  srID) const

Definition at line 204 of file FileIndex.cc.

205  {
206  assert(sortState() != kNotSorted);
207  const_iterator it;
209  Element el{EventID::invalidEvent(srID)};
210  it = lower_bound_all(entries_, el, Compare_Run_SubRun_EventEntry());
211  } else {
213  }
214  auto const itEnd = entries_.cend();
215  while (it != itEnd && it->getEntryType() != FileIndex::kSubRun &&
216  it->getEntryType() != FileIndex::kRun) {
217  ++it;
218  }
219  return it;
220  }
static constexpr EventID invalidEvent()
Definition: EventID.h:203
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
void art::FileIndex::print_event_list ( std::ostream &  os) const

Definition at line 256 of file FileIndex.cc.

References e.

Referenced by empty(), and art::detail::InfoDumperInputFile::print_event_list().

257  {
258  os << "\nPrinting the list of Runs, SubRuns, and Events stored in the root "
259  "file.\n\n";
260  os << setw(15) << "Run" << setw(15) << "SubRun" << setw(15) << "Event"
261  << "\n";
262  for (auto const& e : entries_) {
263  if (e.getEntryType() == FileIndex::kEvent) {
264  os << setw(15) << e.eventID_.run() << setw(15) << e.eventID_.subRun()
265  << setw(15) << e.eventID_.event() << "\n";
266  } else if (e.getEntryType() == FileIndex::kSubRun) {
267  os << setw(15) << e.eventID_.run() << setw(15) << e.eventID_.subRun()
268  << setw(15) << " "
269  << "\n";
270  } else if (e.getEntryType() == FileIndex::kRun) {
271  os << setw(15) << e.eventID_.run() << setw(15) << " " << setw(15) << " "
272  << "\n";
273  }
274  }
275  }
Float_t e
Definition: plot.C:34
std::vector< Element > entries_
Definition: FileIndex.h:179
bool& art::FileIndex::resultCached ( ) const
inlineprivate

Definition at line 166 of file FileIndex.h.

References transients_.

167  {
168  return transients_.get().resultCached_;
169  }
Transient< Transients > transients_
Definition: FileIndex.h:180
std::vector<Element>::size_type art::FileIndex::size ( void  ) const
inline

Definition at line 125 of file FileIndex.h.

References entries_.

126  {
127  return entries_.size();
128  }
std::vector< Element > entries_
Definition: FileIndex.h:179
void art::FileIndex::sortBy_Run_SubRun_Event ( )

Definition at line 44 of file FileIndex.cc.

Referenced by art::RootOutputFile::writeFileIndex().

45  {
46  stable_sort_all(entries_);
47  resultCached() = false;
49  }
bool & resultCached() const
Definition: FileIndex.h:166
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
void art::FileIndex::sortBy_Run_SubRun_EventEntry ( )

Definition at line 52 of file FileIndex.cc.

53  {
54  stable_sort_all(entries_, Compare_Run_SubRun_EventEntry());
55  resultCached() = false;
57  }
bool & resultCached() const
Definition: FileIndex.h:166
std::vector< Element > entries_
Definition: FileIndex.h:179
SortState & sortState() const
Definition: FileIndex.h:171
SortState& art::FileIndex::sortState ( ) const
inlineprivate

Definition at line 171 of file FileIndex.h.

References findEventForUnspecifiedSubRun(), and transients_.

172  {
173  return transients_.get().sortState_;
174  }
Transient< Transients > transients_
Definition: FileIndex.h:180

Member Data Documentation

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

Definition at line 179 of file FileIndex.h.

Referenced by begin(), cbegin(), cend(), contains(), empty(), end(), and size().

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

Definition at line 180 of file FileIndex.h.

Referenced by allInEntryOrder(), resultCached(), and sortState().


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