LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
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 //
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  : eventID_{eID}, entry_{entry}
60  {}
61  EntryType
62  getEntryType() const
63  {
64  return eventID_.isValid() ?
65  kEvent :
67  }
70  };
71 
74 
77 
78  const_iterator findPosition(EventID const& eID) const;
79 
80  template <typename ID>
81  const_iterator findPosition(ID const& id, bool exact) const;
82 
84 
85  template <typename ID>
86  bool
87  contains(ID const& id, bool exact) const
88  {
89  return findPosition(id, exact) != entries_.end();
90  }
91 
92  iterator
94  {
95  return entries_.begin();
96  }
98  begin() const
99  {
100  return entries_.begin();
101  }
103  cbegin() const
104  {
105  return entries_.begin();
106  }
107 
108  iterator
109  end()
110  {
111  return entries_.end();
112  }
114  end() const
115  {
116  return entries_.end();
117  }
119  cend() const
120  {
121  return entries_.end();
122  }
123 
124  std::vector<Element>::size_type
125  size() const
126  {
127  return entries_.size();
128  }
129 
130  bool
131  empty() const
132  {
133  return entries_.empty();
134  }
135 
136  bool allEventsInEntryOrder() const;
137 
138  bool eventsUniqueAndOrdered() const;
139 
140  void print_event_list(std::ostream& os) const;
141 
142  enum SortState {
146  };
147  struct Transients {
148  bool allInEntryOrder_{false};
149  bool resultCached_{false};
150  // The default value for sortState_ reflects the fact that
151  // the index is always sorted using Run, SubRun, and Event
152  // number by the RootOutput before being written out.
153  // In the other case when we create a new FileIndex, the
154  // vector is empty, which is consistent with it having been
155  // sorted.
157  };
158 
159 private:
160  bool&
162  {
163  return transients_.get().allInEntryOrder_;
164  }
165  bool&
166  resultCached() const
167  {
168  return transients_.get().resultCached_;
169  }
170  SortState&
171  sortState() const
172  {
173  return transients_.get().sortState_;
174  }
175 
177  bool exact) const;
178 
179  std::vector<Element> entries_{};
181 };
182 
183 namespace art {
184  bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
185 
186  inline bool
188  {
189  return rh < lh;
190  }
191 
192  inline bool
194  {
195  return !(lh < rh);
196  }
197 
198  inline bool
200  {
201  return !(rh < lh);
202  }
203 
204  inline bool
206  {
207  return !(lh < rh || rh < lh);
208  }
209 
210  inline bool
212  {
213  return lh < rh || rh < lh;
214  }
215 
217  public:
218  bool operator()(FileIndex::Element const& lh, FileIndex::Element const& rh);
219  };
220 
221  std::ostream& operator<<(std::ostream& os, FileIndex::Element const& el);
222 
223  std::ostream& operator<<(std::ostream& os, FileIndex const& fileIndex);
224 }
225 
226 #endif /* canvas_Persistency_Provenance_FileIndex_h */
227 
228 // Local Variables:
229 // mode: c++
230 // End:
bool isValid() const
Definition: EventID.h:123
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
SubRunID const & subRunID() const
Definition: EventID.h:105
bool operator<=(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:130
void addEntryOnLoad(EventID const &eID, EntryNumber_t entry)
Definition: FileIndex.cc:37
Transient< Transients > transients_
Definition: FileIndex.h:180
bool & resultCached() const
Definition: FileIndex.h:166
std::vector< Element >::iterator iterator
Definition: FileIndex.h:73
const_iterator findSubRunOrRunPosition(SubRunID const &srID) const
Definition: FileIndex.cc:204
const_iterator cbegin() const
Definition: FileIndex.h:103
static EntryNumber_t constexpr invalidEntry
Definition: FileIndex.h:55
intermediate_table::iterator iterator
const_iterator begin() const
Definition: FileIndex.h:98
FileIndex()=default
bool allEventsInEntryOrder() const
Definition: FileIndex.cc:60
Element(EventID const &eID, EntryNumber_t const entry)
Definition: FileIndex.h:58
Element(EventID const &eID)
Definition: FileIndex.h:57
bool operator>=(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:142
void sortBy_Run_SubRun_EventEntry()
Definition: FileIndex.cc:52
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
long long EntryNumber_t
Definition: FileIndex.h:43
bool empty() const
Definition: FileIndex.h:131
bool operator>(ScheduleID left, ScheduleID right)
Definition: ScheduleID.h:136
bool isValid() const
Definition: SubRunID.h:96
iterator end()
Definition: FileIndex.h:109
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.h:44
intermediate_table::const_iterator const_iterator
void print_event_list(std::ostream &os) const
Definition: FileIndex.cc:256
const_iterator findEventForUnspecifiedSubRun(EventID const &eID, bool exact) const
Definition: FileIndex.cc:305
void sortBy_Run_SubRun_Event()
Definition: FileIndex.cc:44
const_iterator cend() const
Definition: FileIndex.h:119
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
bool & allInEntryOrder() const
Definition: FileIndex.h:161
void addEntry(EventID const &eID, EntryNumber_t entry)
Definition: FileIndex.cc:29
bool eventsUniqueAndOrdered() const
Definition: FileIndex.cc:81
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:72
HLT enums.
iterator begin()
Definition: FileIndex.h:93
const_iterator end() const
Definition: FileIndex.h:114
bool contains(ID const &id, bool exact) const
Definition: FileIndex.h:87
EntryNumber_t entry_
Definition: FileIndex.h:69
bool operator==(Provenance const &a, Provenance const &b)
Definition: Provenance.h:168
std::vector< Element > entries_
Definition: FileIndex.h:179
std::vector< Element >::size_type size() const
Definition: FileIndex.h:125
EntryType getEntryType() const
Definition: FileIndex.h:62
SortState & sortState() const
Definition: FileIndex.h:171