LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FileIndex.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_FileIndex_h
2 #define canvas_Persistency_Provenance_FileIndex_h
3 // vim: set sw=2 expandtab :
4 
6 //
7 // This intra-file indexing system has known issues and will be going
8 // away at the earliest possible opportunity. In the meantime however,
9 // there are some things of which the user of this class should be
10 // aware:
11 //
12 // 1. This class is *not* intended for use outside ART. It should
13 // probably be put into the detail namespace.
14 //
15 // 2. This class depends implicitly on an invalid value of the run,
16 // subrun or event in an EventID sorting *before* a valid one. This
17 // should be enforced in the comparison operations of the EventID and
18 // related classes.
19 //
20 // 3. Due to user requirements, it *is* possible to findEventPosition()
21 // using an EventID which is invalid in one particular way: the run
22 // and event numbers are valid, but the subrun number is not. HOWEVER,
23 // this only makes sense in an environment where the run number and
24 // event number specify the event uniquely. No check is made that an
25 // answer returned by findEventPosition() in these circumstances is
26 // in any way unique.
27 //
29 
33 
34 #include <iosfwd>
35 #include <vector>
36 
37 namespace art {
38 
39  class FileIndex {
40  public:
41  using EntryNumber_t = long long;
42 
43  enum EntryType {
44  kRun, /* 0 */
45  kSubRun, /* 1 */
46  kEvent, /* 2 */
47  kEnd /* 3 */
48  };
49 
50  struct Element {
51  static constexpr EntryNumber_t invalid{-1};
52 
53  Element() = default;
54  Element(EventID const& eID);
55  Element(EventID const& eID, EntryNumber_t const entry);
56 
57  EntryType getEntryType() const;
58 
61  };
62 
65 
66  enum SortState {
67  kNotSorted, /* 0 */
70  };
71 
72  struct Transients {
73  bool allInEntryOrder{false};
74  bool resultCached{false};
75 
76  // The default value for sortState_ reflects the fact that the
77  // index is always sorted using Run, SubRun, and Event number by
78  // the RootOutput before being written out. In the other case
79  // when we create a new FileIndex, the vector is empty, which is
80  // consistent with it having been sorted.
82  };
83 
84  void addEntry(EventID const& eID, EntryNumber_t entry);
85  void addEntryOnLoad(EventID const& eID, EntryNumber_t entry);
88 
89  const_iterator findPosition(EventID const& eID) const;
90  const_iterator findPosition(EventID const& eID, bool exact) const;
91  const_iterator findPosition(SubRunID const& srID, bool exact) const;
92  const_iterator findPosition(RunID const& rID, bool exact) const;
93 
95 
96  bool contains(EventID const& id, bool exact) const;
97  bool contains(SubRunID const& id, bool exact) const;
98  bool contains(RunID const& id, bool exact) const;
99 
100  iterator begin();
101  const_iterator begin() const;
102  const_iterator cbegin() const;
103 
104  iterator end();
105  const_iterator end() const;
106  const_iterator cend() const;
107 
108  std::vector<Element>::size_type size() const;
109 
110  bool empty() const;
111 
112  bool allEventsInEntryOrder() const;
113  bool eventsUniqueAndOrdered() const;
114 
115  void print_event_list(std::ostream& os) const;
116 
117  friend bool operator==(FileIndex const&, FileIndex const&);
118 
119  private:
120  bool& allInEntryOrder() const;
121  bool& resultCached() const;
122  SortState& sortState() const;
124  bool exact) const;
125 
126  std::vector<Element> entries_{};
128  };
129 
130  bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
131  bool operator>(FileIndex::Element const& lh, FileIndex::Element const& rh);
132  bool operator>=(FileIndex::Element const& lh, FileIndex::Element const& rh);
133  bool operator<=(FileIndex::Element const& lh, FileIndex::Element const& rh);
134  bool operator==(FileIndex::Element const& lh, FileIndex::Element const& rh);
135  bool operator!=(FileIndex::Element const& lh, FileIndex::Element const& rh);
136 
137  bool operator==(FileIndex const& lh, FileIndex const& rh);
138  bool operator!=(FileIndex const& lh, FileIndex const& rh);
139 
141  bool operator()(FileIndex::Element const& lh, FileIndex::Element const& rh);
142  };
143 
144  std::ostream& operator<<(std::ostream& os, FileIndex::Element const& el);
145  std::ostream& operator<<(std::ostream& os, FileIndex const& fileIndex);
146 
147 } // namespace art
148 
149 #endif /* canvas_Persistency_Provenance_FileIndex_h */
150 
151 // Local Variables:
152 // mode: c++
153 // End:
intermediate_table::iterator iterator
void addEntryOnLoad(EventID const &eID, EntryNumber_t entry)
Definition: FileIndex.cc:142
Transient< Transients > transients_
Definition: FileIndex.h:127
std::vector< Element >::iterator iterator
Definition: FileIndex.h:64
iterator begin()
Definition: FileIndex.cc:50
bool operator>(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:53
const_iterator findSubRunOrRunPosition(SubRunID const &srID) const
Definition: FileIndex.cc:306
friend bool operator==(FileIndex const &, FileIndex const &)
Definition: FileIndex.cc:451
bool allEventsInEntryOrder() const
Definition: FileIndex.cc:165
SortState & sortState() const
Definition: FileIndex.cc:110
intermediate_table::const_iterator const_iterator
void sortBy_Run_SubRun_EventEntry()
Definition: FileIndex.cc:157
bool & allInEntryOrder() const
Definition: FileIndex.cc:98
bool operator!=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:41
long long EntryNumber_t
Definition: FileIndex.h:41
bool empty() const
Definition: FileIndex.cc:92
std::vector< Element >::size_type size() const
Definition: FileIndex.cc:86
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.cc:51
bool operator<=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:47
void print_event_list(std::ostream &os) const
Definition: FileIndex.cc:325
const_iterator findEventForUnspecifiedSubRun(EventID const &eID, bool exact) const
Definition: FileIndex.cc:347
const_iterator cbegin() const
Definition: FileIndex.cc:62
void sortBy_Run_SubRun_Event()
Definition: FileIndex.cc:149
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:227
void addEntry(EventID const &eID, EntryNumber_t entry)
Definition: FileIndex.cc:134
bool eventsUniqueAndOrdered() const
Definition: FileIndex.cc:186
EntryType getEntryType() const
Definition: FileIndex.cc:43
iterator end()
Definition: FileIndex.cc:68
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:63
bool contains(EventID const &id, bool exact) const
Definition: FileIndex.cc:116
static constexpr EntryNumber_t invalid
Definition: FileIndex.h:51
Definition: MVAAlg.h:12
bool operator>=(ScheduleID const left, ScheduleID const right) noexcept
Definition: ScheduleID.cc:59
const_iterator cend() const
Definition: FileIndex.cc:80
std::vector< Element > entries_
Definition: FileIndex.h:126
EntryNumber_t entry
Definition: FileIndex.h:60
bool & resultCached() const
Definition: FileIndex.cc:104