FileIndex.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_FileIndex_h
2 #define canvas_Persistency_Provenance_FileIndex_h
3 
4 ////////////////////////////////////////////////////////////////////////
5 //
6 // This intra-file indexing system has known issues and will be going
7 // away at the earliest possible opportunity. In the meantime however,
8 // there are some things of which the user of this class should be
9 // aware:
10 //
11 // 1. This class is *not* intended for use outside ART. It should
12 // probably be put into the detail namespace.
13 //
14 // 2. This class depends implicitly on an invalid value of the run,
15 // subrun or event in an EventID sorting *before* a valid one. This
16 // should be enforced in the comparison operations of the EventID and
17 // related classes.
18 //
19 // 3. Due to user requirements, it *is* possible to findEventPosition()
20 // using an EventID which is invalid in one particular way: the run
21 // and event numbers are valid, but the subrun number is not. HOWEVER,
22 // this only makes sense in an environment where the run number and
23 // event number specify the event uniquely. No check is made that an
24 // answer returned by findEventPosition() in these circumstances is
25 // in any way unique.
26 //
27 ////////////////////////////////////////////////////////////////////////
28 
33 #include <iosfwd>
34 #include <vector>
35 
36 namespace art {
37  class FileIndex;
38 }
39 
41 
42 public:
43  using EntryNumber_t = long long;
44 
45  FileIndex() = default; // Necessary for ROOT
46 
47  void addEntry(EventID const& eID, EntryNumber_t entry);
48 
49  void addEntryOnLoad(EventID const& eID, EntryNumber_t entry);
50 
52 
53  class Element {
54  public:
55  static EntryNumber_t constexpr invalidEntry{-1};
56  Element() = default;
57  Element(EventID const& eID) : Element(eID, invalidEntry) {}
58  Element(EventID const& eID, EntryNumber_t const entry)
59  : entry_{entry}, eventID_{eID}
60  {}
61  EntryType
62  getEntryType() const
63  {
64  return eventID_.isValid() ?
65  kEvent :
67  }
68  // WARNING: The order of these two data members is important!
69  // The padding rules mean that in this order each element
70  // is 8 + 12 = 20 bytes. If they are reversed it becomes
71  // 12 + (4 padding) + 8 = 24 bytes.
74  };
75 
76  using const_iterator = std::vector<Element>::const_iterator;
77  using iterator = std::vector<Element>::iterator;
78 
81 
82  const_iterator findPosition(EventID const& eID) const;
83 
84  template <typename ID>
85  const_iterator findPosition(ID const& id, bool exact) const;
86 
88 
89  template <typename ID>
90  bool
91  contains(ID const& id, bool exact) const
92  {
93  return findPosition(id, exact) != entries_.end();
94  }
95 
96  iterator
98  {
99  return entries_.begin();
100  }
102  begin() const
103  {
104  return entries_.begin();
105  }
107  cbegin() const
108  {
109  return entries_.begin();
110  }
111 
112  iterator
113  end()
114  {
115  return entries_.end();
116  }
118  end() const
119  {
120  return entries_.end();
121  }
123  cend() const
124  {
125  return entries_.end();
126  }
127 
129  size() const
130  {
131  return entries_.size();
132  }
133 
134  bool
135  empty() const
136  {
137  return entries_.empty();
138  }
139 
140  bool allEventsInEntryOrder() const;
141 
142  bool eventsUniqueAndOrdered() const;
143 
144  void print_event_list(std::ostream& os) const;
145 
146  enum SortState {
150  };
151  struct Transients {
152  bool allInEntryOrder_{false};
153  bool resultCached_{false};
154  // The default value for sortState_ reflects the fact that
155  // the index is always sorted using Run, SubRun, and Event
156  // number by the RootOutput before being written out.
157  // In the other case when we create a new FileIndex, the
158  // vector is empty, which is consistent with it having been
159  // sorted.
161  };
162 
163 private:
164  bool&
166  {
167  return transients_.get().allInEntryOrder_;
168  }
169  bool&
170  resultCached() const
171  {
172  return transients_.get().resultCached_;
173  }
174  SortState&
175  sortState() const
176  {
177  return transients_.get().sortState_;
178  }
179 
181  bool exact) const;
182 
183  std::vector<Element> entries_{};
185 };
186 
187 namespace art {
188  bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
189 
190  inline bool
192  {
193  return rh < lh;
194  }
195 
196  inline bool
198  {
199  return !(lh < rh);
200  }
201 
202  inline bool
204  {
205  return !(rh < lh);
206  }
207 
208  inline bool
210  {
211  return !(lh < rh || rh < lh);
212  }
213 
214  inline bool
216  {
217  return lh < rh || rh < lh;
218  }
219 
221  public:
222  bool operator()(FileIndex::Element const& lh, FileIndex::Element const& rh);
223  };
224 
225  std::ostream& operator<<(std::ostream& os, FileIndex::Element const& el);
226 
227  std::ostream& operator<<(std::ostream& os, FileIndex const& fileIndex);
228 }
229 
230 #endif /* canvas_Persistency_Provenance_FileIndex_h */
231 
232 // Local Variables:
233 // mode: c++
234 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
bool operator<=(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:130
void addEntryOnLoad(EventID const &eID, EntryNumber_t entry)
Transient< Transients > transients_
Definition: FileIndex.h:184
bool & resultCached() const
Definition: FileIndex.h:170
std::vector< Element >::iterator iterator
Definition: FileIndex.h:77
TH2 * rh
Definition: drawXsec.C:5
const_iterator cbegin() const
Definition: FileIndex.h:107
static EntryNumber_t constexpr invalidEntry
Definition: FileIndex.h:55
const_iterator begin() const
Definition: FileIndex.h:102
FileIndex()=default
bool allEventsInEntryOrder() const
Element(EventID const &eID, EntryNumber_t const entry)
Definition: FileIndex.h:58
bool isValid() const
Definition: EventID.h:122
Element(EventID const &eID)
Definition: FileIndex.h:57
bool operator>=(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:142
const_iterator findPosition(EventID const &eID) const
void sortBy_Run_SubRun_EventEntry()
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
long long EntryNumber_t
Definition: FileIndex.h:43
bool empty() const
Definition: FileIndex.h:135
bool operator>(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:136
bool isValid() const
Definition: SubRunID.h:95
iterator end()
Definition: FileIndex.h:113
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.h:44
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
const_iterator findEventForUnspecifiedSubRun(EventID const &eID, bool exact) const
void print_event_list(std::ostream &os) const
SubRunID const & subRunID() const
Definition: EventID.h:104
void sortBy_Run_SubRun_Event()
const_iterator cend() const
Definition: FileIndex.h:123
bool & allInEntryOrder() const
Definition: FileIndex.h:165
void addEntry(EventID const &eID, EntryNumber_t entry)
bool eventsUniqueAndOrdered() const
const_iterator findSubRunOrRunPosition(SubRunID const &srID) const
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:76
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
iterator begin()
Definition: FileIndex.h:97
const_iterator end() const
Definition: FileIndex.h:118
bool contains(ID const &id, bool exact) const
Definition: FileIndex.h:91
EntryNumber_t entry_
Definition: FileIndex.h:72
bool operator==(Provenance const &a, Provenance const &b)
Definition: Provenance.h:168
std::vector< Element > entries_
Definition: FileIndex.h:183
std::vector< Element >::size_type size() const
Definition: FileIndex.h:129
def entry(str)
Definition: HTMLTools.py:26
EntryType getEntryType() const
Definition: FileIndex.h:62
SortState & sortState() const
Definition: FileIndex.h:175