LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
RootInputFile.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Root_RootInputFile_h
2 #define art_Framework_IO_Root_RootInputFile_h
3 // vim: set sw=2:
4 
15 #include "canvas/Persistency/Provenance/Compatibility/BranchIDList.h"
31 #include "cetlib/exempt_ptr.h"
32 #include "cetlib/sqlite/Connection.h"
33 
34 #include <array>
35 #include <map>
36 #include <memory>
37 #include <string>
38 #include <vector>
39 
40 #include "TFile.h"
41 
42 namespace art {
43 
44  class DuplicateChecker;
45  class EventRangeHandler;
46  class GroupSelectorRules;
47  class MasterProductRegistry;
48 
49  class RootInputFile {
50 
51  public: // TYPES
52  using RootInputTreePtrArray =
53  std::array<std::unique_ptr<RootInputTree>, NumBranchTypes>;
56 
57  public: // MEMBER FUNCTIONS
58  RootInputFile(RootInputFile const&) = delete;
59 
60  RootInputFile& operator=(RootInputFile const&) = delete;
61 
62  RootInputFile(std::string const& fileName,
63  std::string const& catalogName,
64  ProcessConfiguration const& processConfiguration,
65  std::string const& logicalFileName,
66  std::unique_ptr<TFile>&& filePtr,
67  EventID const& origEventID,
68  unsigned int eventsToSkip,
69  bool compactSubRunRanges,
70  FastCloningInfoProvider const& fcip,
71  unsigned int treeCacheSize,
72  int64_t treeMaxVirtualSize,
73  int64_t saveMemoryObjectThreashold,
74  bool delayedReadEventProducts,
75  bool delayedReadSubRunProducts,
76  bool delayedReadRunProducts,
77  InputSource::ProcessingMode processingMode,
78  int forcedRunOffset,
79  bool noEventSort,
80  GroupSelectorRules const& groupSelectorRules,
81  std::shared_ptr<DuplicateChecker> duplicateChecker,
82  bool dropDescendantsOfDroppedProducts,
83  bool readIncomingParameterSets,
84  cet::exempt_ptr<RootInputFile> primaryFile,
85  std::vector<std::string> const& secondaryFileNames,
86  RootInputFileSequence* rifSequence,
88 
89  void reportOpened();
90 
91  void close(bool reallyClose);
92 
93  std::unique_ptr<ResultsPrincipal> readResults();
94  std::unique_ptr<RunPrincipal> readRun();
95  std::unique_ptr<SubRunPrincipal> readSubRun(cet::exempt_ptr<RunPrincipal>);
96  std::unique_ptr<EventPrincipal> readEvent();
97 
101 
102  std::string const&
103  fileName() const
104  {
105  return fileName_;
106  }
107 
108  RunAuxiliary&
110  {
111  return std::get<RunAuxiliary>(auxiliaries_);
112  }
115  {
116  return std::get<ResultsAuxiliary>(auxiliaries_);
117  }
120  {
121  return std::get<SubRunAuxiliary>(auxiliaries_);
122  }
125  {
126  return std::get<EventAuxiliary>(auxiliaries_);
127  }
128 
131  {
132  return fileFormatVersion_;
133  }
134 
135  bool
136  fastClonable() const
137  {
138  return fastClonable_;
139  }
140 
141  std::unique_ptr<FileBlock> createFileBlock();
142 
143  template <BranchType BT>
144  void
146  {
147  treePointers_[BT]->setEntryNumber(entry);
148  }
149 
150  template <BranchType BT, typename ID>
151  bool
152  setEntry(ID const& id, bool exact = true)
153  {
154  fiIter_ = fileIndex_.findPosition(id, exact);
155  if (fiIter_ == fiEnd_) {
156  return false;
157  }
158  setEntry<BT>(fiIter_->entry_);
159  return true;
160  }
161 
162  void
164  {
165  fiIter_ = fiBegin_;
166  // FIXME: Rewinding the trees is suspicious!
167  // FIXME: They should be positioned based on the new iter pos.
168  eventTree().rewind();
169  subRunTree().rewind();
170  runTree().rewind();
171  }
172 
173  void
175  {
176  fiIter_ = fiEnd_;
177  }
178  void
180  {
181  ++fiIter_;
182  }
183  void
185  {
186  --fiIter_;
187  }
188  void
189  advanceEntry(std::size_t n)
190  {
191  while (n-- != 0)
192  nextEntry();
193  }
194 
195  unsigned int
196  eventsToSkip() const
197  {
198  return eventsToSkip_;
199  }
200  int skipEvents(int offset);
201  int setForcedRunOffset(RunNumber_t const& forcedRunNumber);
202 
203  bool
205  {
206  return eventTree().next();
207  }
208 
211 
212  std::shared_ptr<FileIndex>
214  {
215  return fileIndexSharedPtr_;
216  }
217 
219 
220  auto const&
222  {
223  return secondaryFileNames_;
224  }
225  auto const&
227  {
228  return secondaryFiles_;
229  }
230 
231  void openSecondaryFile(int const idx);
232 
233  std::unique_ptr<RangeSetHandler> runRangeSetHandler();
234  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler();
235 
236  private:
237  // const versions
238  RootInputTree const&
239  eventTree() const
240  {
241  return *treePointers_[InEvent];
242  }
243  RootInputTree const&
244  subRunTree() const
245  {
246  return *treePointers_[InSubRun];
247  }
248  RootInputTree const&
249  runTree() const
250  {
251  return *treePointers_[InRun];
252  }
253  RootInputTree const&
254  resultsTree() const
255  {
256  return *treePointers_[InResults];
257  }
258 
259  // non-const versions
262  {
263  return *treePointers_[InEvent];
264  }
267  {
268  return *treePointers_[InSubRun];
269  }
272  {
273  return *treePointers_[InRun];
274  }
277  {
278  return *treePointers_[InResults];
279  }
280 
281  bool setIfFastClonable(FastCloningInfoProvider const& fcip) const;
282 
283  void validateFile();
284 
285  void fillHistory();
286  std::array<AvailableProducts_t, NumBranchTypes>
288 
289  template <BranchType BT>
290  void
292  {
293  using AUX = std::tuple_element_t<BT, decltype(auxiliaries_)>;
294  auto& aux = std::get<BT>(auxiliaries_);
295  aux = treePointers_[BT]->getAux<AUX>(entry);
296  }
297 
298  template <BranchType BT>
299  std::unique_ptr<RangeSetHandler>
300  fillAuxiliary(EntryNumbers const& entries)
301  {
302  using AUX = std::tuple_element_t<BT, decltype(auxiliaries_)>;
303  auto& aux = std::get<BT>(auxiliaries_);
304  return treePointers_[BT]->fillAux<AUX>(
306  }
307 
308  void overrideRunNumber(RunID& id);
309  void overrideRunNumber(SubRunID& id);
310  void overrideRunNumber(EventID& id, bool isRealData);
311 
312  void dropOnInput(GroupSelectorRules const& rules,
313  bool dropDescendants,
314  ProductList& branchDescriptions);
315 
316  void readParentageTree(unsigned int treeCacheSize);
317  void readEventHistoryTree(unsigned int treeCacheSize);
318 
320 
321  std::pair<EntryNumbers, bool> getEntryNumbers(BranchType);
322 
323  std::unique_ptr<RunPrincipal> readCurrentRun(EntryNumbers const&);
324  std::unique_ptr<SubRunPrincipal> readCurrentSubRun(
325  EntryNumbers const&,
326  cet::exempt_ptr<RunPrincipal>);
327  std::unique_ptr<EventPrincipal> readCurrentEvent(
328  std::pair<EntryNumbers, bool> const&);
329 
330  std::string const fileName_;
331  std::string const catalog_;
333  std::string const logicalFileName_;
334  std::unique_ptr<TFile> filePtr_;
335  cet::sqlite::Connection sqliteDB_{}; // Start with invalid connection.
346  std::shared_ptr<DuplicateChecker> duplicateChecker_;
347  cet::exempt_ptr<RootInputFile> primaryFile_;
348  std::vector<std::string> secondaryFileNames_;
349  cet::exempt_ptr<RootInputFileSequence> rifSequence_;
350 
352  std::shared_ptr<FileIndex> fileIndexSharedPtr_{new FileIndex};
357  bool fastClonable_{false};
358  std::tuple<EventAuxiliary, SubRunAuxiliary, RunAuxiliary, ResultsAuxiliary>
359  auxiliaries_{}; // Must be in same order as treePointers_ !
360 
361  // The holder is necessary since references of its contents are
362  // passed to the RootDelayedReader.
365  std::unique_ptr<BranchIDLists> branchIDLists_{
366  nullptr}; // Only used for maintaining backwards compatibility
367 
368  TTree* eventHistoryTree_{nullptr};
369  std::shared_ptr<History> history_{std::make_shared<History>()};
370  std::vector<std::unique_ptr<RootInputFile>> secondaryFiles_{};
371  // We need to add the secondary principals to the primary
372  // principal when they are delay read, so we need to keep around a
373  // pointer to the primary. Note that these are always used in a
374  // situation where we are guaranteed that primary exists.
375  cet::exempt_ptr<EventPrincipal> primaryEP_{};
376  cet::exempt_ptr<RunPrincipal> primaryRP_{};
377  cet::exempt_ptr<SubRunPrincipal> primarySRP_{};
378  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler_{nullptr};
379  std::unique_ptr<RangeSetHandler> runRangeSetHandler_{nullptr};
380  };
381 
382 } // namespace art
383 
384 // Local Variables:
385 // mode: c++
386 // End:
387 #endif /* art_Framework_IO_Root_RootInputFile_h */
RunAuxiliary & runAux()
std::shared_ptr< History > history_
void fillAuxiliary(EntryNumber const entry)
std::string const catalog_
FileIndex::EntryType getNextEntryTypeWanted()
std::vector< std::string > secondaryFileNames_
std::unique_ptr< RunPrincipal > readCurrentRun(EntryNumbers const &)
RootInputTree const & resultsTree() const
std::unique_ptr< SubRunPrincipal > readCurrentSubRun(EntryNumbers const &, cet::exempt_ptr< RunPrincipal >)
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler_
RootInputTree::EntryNumbers EntryNumbers
Definition: RootInputFile.h:55
EventNumber_t eventsToSkip_
auto const & secondaryFiles() const
void readEventHistoryTree(unsigned int treeCacheSize)
std::tuple< EventAuxiliary, SubRunAuxiliary, RunAuxiliary, ResultsAuxiliary > auxiliaries_
std::array< std::unique_ptr< RootInputTree >, NumBranchTypes > RootInputTreePtrArray
Definition: RootInputFile.h:53
void dropOnInput(GroupSelectorRules const &rules, bool dropDescendants, ProductList &branchDescriptions)
ResultsAuxiliary & resultsAux()
bool setEntry(ID const &id, bool exact=true)
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductList.h:15
FileIndex & fileIndex_
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler()
RootInputTree const & eventTree() const
void overrideRunNumber(RunID &id)
std::unique_ptr< RangeSetHandler > fillAuxiliary(EntryNumbers const &entries)
input::EntryNumbers EntryNumbers
Definition: RootInputTree.h:78
long long EntryNumber_t
Definition: FileIndex.h:43
FileIndex::const_iterator fiIter_
bool readSubRunForSecondaryFile(SubRunID)
std::string const & fileName() const
void readParentageTree(unsigned int treeCacheSize)
void setEntry(FileIndex::EntryNumber_t entry)
std::unique_ptr< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal >)
std::pair< EntryNumbers, bool > getEntryNumbers(BranchType)
RootInputFile & operator=(RootInputFile const &)=delete
std::unique_ptr< FileBlock > createFileBlock()
EventID eventIDForFileIndexPosition() const
bool setIfFastClonable(FastCloningInfoProvider const &fcip) const
RootInputTree & subRunTree()
iterator end()
Definition: FileIndex.h:109
std::array< AvailableProducts_t, NumBranchTypes > fillPerBranchTypePresenceFlags(ProductList const &)
RootInputTreePtrArray treePointers_
std::shared_ptr< DuplicateChecker > duplicateChecker_
int setForcedRunOffset(RunNumber_t const &forcedRunNumber)
std::unique_ptr< EventPrincipal > readEvent()
ProductRegistry productListHolder_
void initializeDuplicateChecker()
RootInputTree & eventTree()
auto const & secondaryFileNames() const
FileFormatVersion fileFormatVersion_
EventAuxiliary & eventAux()
std::unique_ptr< RangeSetHandler > runRangeSetHandler()
bool readEventForSecondaryFile(EventID eID)
RootInputFile(RootInputFile const &)=delete
std::shared_ptr< FileIndex > fileIndexSharedPtr() const
FileIndex::const_iterator fiBegin_
const_iterator findPosition(EventID const &eID) const
Definition: FileIndex.cc:123
unsigned int eventsToSkip() const
RootInputTree const & runTree() const
std::unique_ptr< RangeSetHandler > runRangeSetHandler_
int skipEvents(int offset)
std::string const fileName_
cet::exempt_ptr< EventPrincipal > primaryEP_
cet::sqlite::Connection sqliteDB_
input::EntryNumber EntryNumber
Definition: RootInputTree.h:77
std::unique_ptr< EventPrincipal > readCurrentEvent(std::pair< EntryNumbers, bool > const &)
bool readRunForSecondaryFile(RunID)
static ProductTables invalid()
std::unique_ptr< BranchIDLists > branchIDLists_
std::vector< std::unique_ptr< RootInputFile > > secondaryFiles_
cet::exempt_ptr< RootInputFile > primaryFile_
std::unique_ptr< TFile > filePtr_
bool const compactSubRunRanges_
std::unique_ptr< ResultsPrincipal > readResults()
bool fastClonable() const
RootInputTree & resultsTree()
FileIndex::const_iterator fiEnd_
FileIndex::EntryType getEntryType() const
std::shared_ptr< FileIndex > fileIndexSharedPtr_
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:72
RootInputTree & runTree()
FileFormatVersion fileFormatVersion() const
RootInputTree::EntryNumber EntryNumber
Definition: RootInputFile.h:54
InputSource::ProcessingMode processingMode_
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
BranchType
Definition: BranchType.h:18
HLT enums.
iterator begin()
Definition: FileIndex.h:93
Char_t n[5]
void advanceEntry(std::size_t n)
std::unique_ptr< RunPrincipal > readRun()
std::string const logicalFileName_
ProductTables presentProducts_
cet::exempt_ptr< RunPrincipal > primaryRP_
RootInputTree const & subRunTree() const
cet::exempt_ptr< RootInputFileSequence > rifSequence_
SubRunAuxiliary & subRunAux()
ProcessConfiguration const & processConfiguration_
void openSecondaryFile(int const idx)
cet::exempt_ptr< SubRunPrincipal > primarySRP_
void close(bool reallyClose)
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119