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"
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 BranchChildren;
45  class DuplicateChecker;
46  class EventRangeHandler;
47  class GroupSelectorRules;
48  class MasterProductRegistry;
49 
50  class RootInputFile {
51 
52  public: // TYPES
53  using RootInputTreePtrArray =
54  std::array<std::unique_ptr<RootInputTree>, NumBranchTypes>;
57 
58  public: // MEMBER FUNCTIONS
59  RootInputFile(RootInputFile const&) = delete;
60 
61  RootInputFile& operator=(RootInputFile const&) = delete;
62 
64  std::string const& catalogName,
65  ProcessConfiguration const& processConfiguration,
66  std::string const& logicalFileName,
67  std::unique_ptr<TFile>&& filePtr,
68  EventID const& origEventID,
69  unsigned int eventsToSkip,
70  bool compactSubRunRanges,
71  FastCloningInfoProvider const& fcip,
72  unsigned int treeCacheSize,
73  int64_t treeMaxVirtualSize,
74  int64_t saveMemoryObjectThreashold,
75  bool delayedReadEventProducts,
76  bool delayedReadSubRunProducts,
77  bool delayedReadRunProducts,
78  InputSource::ProcessingMode processingMode,
79  int forcedRunOffset,
80  bool noEventSort,
81  GroupSelectorRules const& groupSelectorRules,
82  std::shared_ptr<DuplicateChecker> duplicateChecker,
83  bool dropDescendantsOfDroppedProducts,
84  bool readIncomingParameterSets,
86  std::vector<std::string> const& secondaryFileNames,
87  RootInputFileSequence* rifSequence,
89  bool const parentageEnabled,
90  bool const rangesEnabled);
91 
92  void reportOpened();
93 
94  void close(bool reallyClose);
95 
96  std::unique_ptr<ResultsPrincipal> readResults();
97  std::unique_ptr<RunPrincipal> readRun();
98  std::unique_ptr<SubRunPrincipal> readSubRun(cet::exempt_ptr<RunPrincipal>);
99  std::unique_ptr<EventPrincipal> readEvent();
100 
104 
105  std::string const&
106  fileName() const
107  {
108  return fileName_;
109  }
110 
111  RunAuxiliary&
113  {
114  return std::get<RunAuxiliary>(auxiliaries_);
115  }
118  {
119  return std::get<ResultsAuxiliary>(auxiliaries_);
120  }
123  {
124  return std::get<SubRunAuxiliary>(auxiliaries_);
125  }
128  {
129  return std::get<EventAuxiliary>(auxiliaries_);
130  }
131 
134  {
135  return fileFormatVersion_;
136  }
137 
138  bool
139  fastClonable() const
140  {
141  return fastClonable_;
142  }
143 
144  std::unique_ptr<FileBlock> createFileBlock();
145 
146  template <BranchType BT>
147  void
149  {
150  treePointers_[BT]->setEntryNumber(entry);
151  }
152 
153  template <BranchType BT, typename ID>
154  bool
155  setEntry(ID const& id, bool exact = true)
156  {
157  fiIter_ = fileIndex_.findPosition(id, exact);
158  if (fiIter_ == fiEnd_) {
159  return false;
160  }
161  setEntry<BT>(fiIter_->entry_);
162  return true;
163  }
164 
165  void
167  {
168  fiIter_ = fiBegin_;
169  // FIXME: Rewinding the trees is suspicious!
170  // FIXME: They should be positioned based on the new iter pos.
171  eventTree().rewind();
172  subRunTree().rewind();
173  runTree().rewind();
174  }
175 
176  void
178  {
179  fiIter_ = fiEnd_;
180  }
181  void
183  {
184  ++fiIter_;
185  }
186  void
188  {
189  --fiIter_;
190  }
191  void
192  advanceEntry(std::size_t n)
193  {
194  while (n-- != 0)
195  nextEntry();
196  }
197 
198  unsigned int
199  eventsToSkip() const
200  {
201  return eventsToSkip_;
202  }
203  int skipEvents(int offset);
204  int setForcedRunOffset(RunNumber_t const& forcedRunNumber);
205 
206  bool
208  {
209  return eventTree().next();
210  }
211 
214 
215  std::shared_ptr<FileIndex>
217  {
218  return fileIndexSharedPtr_;
219  }
220 
222 
223  auto const&
225  {
226  return secondaryFileNames_;
227  }
228  auto const&
230  {
231  return secondaryFiles_;
232  }
233 
234  void openSecondaryFile(int const idx);
235 
236  std::unique_ptr<RangeSetHandler> runRangeSetHandler();
237  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler();
238 
239  private:
240  // const versions
241  RootInputTree const&
242  eventTree() const
243  {
244  return *treePointers_[InEvent];
245  }
246  RootInputTree const&
247  subRunTree() const
248  {
249  return *treePointers_[InSubRun];
250  }
251  RootInputTree const&
252  runTree() const
253  {
254  return *treePointers_[InRun];
255  }
256  RootInputTree const&
257  resultsTree() const
258  {
259  return *treePointers_[InResults];
260  }
261 
262  // non-const versions
265  {
266  return *treePointers_[InEvent];
267  }
270  {
271  return *treePointers_[InSubRun];
272  }
275  {
276  return *treePointers_[InRun];
277  }
280  {
281  return *treePointers_[InResults];
282  }
283 
284  bool setIfFastClonable(FastCloningInfoProvider const& fcip) const;
285 
286  void validateFile();
287 
288  void fillHistory();
289  std::array<AvailableProducts_t, NumBranchTypes>
291 
292  template <BranchType BT>
293  void
295  {
296  using AUX = std::tuple_element_t<BT, decltype(auxiliaries_)>;
297  auto& aux = std::get<BT>(auxiliaries_);
298  aux = treePointers_[BT]->getAux<AUX>(entry);
299  }
300 
301  template <BranchType BT>
302  std::unique_ptr<RangeSetHandler>
303  fillAuxiliary(EntryNumbers const& entries)
304  {
305  using AUX = std::tuple_element_t<BT, decltype(auxiliaries_)>;
306  auto& aux = std::get<BT>(auxiliaries_);
307  return treePointers_[BT]->fillAux<AUX>(
309  }
310 
311  void overrideRunNumber(RunID& id);
312  void overrideRunNumber(SubRunID& id);
313  void overrideRunNumber(EventID& id, bool isRealData);
314 
315  void dropOnInput(GroupSelectorRules const& rules,
316  BranchChildren const& children,
317  bool dropDescendants,
318  ProductList& branchDescriptions);
319 
320  void readParentageTree(unsigned int treeCacheSize);
321  void readEventHistoryTree(unsigned int treeCacheSize);
322 
324 
325  std::pair<EntryNumbers, bool> getEntryNumbers(BranchType);
326 
327  std::unique_ptr<RunPrincipal> readCurrentRun(EntryNumbers const&);
328  std::unique_ptr<SubRunPrincipal> readCurrentSubRun(
329  EntryNumbers const&,
331  std::unique_ptr<EventPrincipal> readCurrentEvent(
332  std::pair<EntryNumbers, bool> const&);
333 
338  std::unique_ptr<TFile> filePtr_;
339  cet::sqlite::Connection sqliteDB_{}; // Start with invalid connection.
350  std::shared_ptr<DuplicateChecker> duplicateChecker_;
352  std::vector<std::string> secondaryFileNames_;
354 
356  std::shared_ptr<FileIndex> fileIndexSharedPtr_{new FileIndex};
361  bool fastClonable_{false};
362  std::tuple<EventAuxiliary, SubRunAuxiliary, RunAuxiliary, ResultsAuxiliary>
363  auxiliaries_{}; // Must be in same order as treePointers_ !
364 
365  // The holder is necessary since references of its contents are
366  // passed to the RootDelayedReader.
369  std::unique_ptr<BranchIDLists> branchIDLists_{
370  nullptr}; // Only used for maintaining backwards compatibility
371 
372  TTree* eventHistoryTree_{nullptr};
373  std::shared_ptr<History> history_{std::make_shared<History>()};
374  std::vector<std::unique_ptr<RootInputFile>> secondaryFiles_{};
375  // We need to add the secondary principals to the primary
376  // principal when they are delay read, so we need to keep around a
377  // pointer to the primary. Note that these are always used in a
378  // situation where we are guaranteed that primary exists.
382  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler_{nullptr};
383  std::unique_ptr<RangeSetHandler> runRangeSetHandler_{nullptr};
384  bool const parentageEnabled_{true};
385  bool const rangesEnabled_{true};
386  };
387 
388 } // namespace art
389 
390 // Local Variables:
391 // mode: c++
392 // End:
393 #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< SubRunPrincipal > readSubRun(cet::exempt_ptr< RunPrincipal >)
std::unique_ptr< EventPrincipal > readCurrentEvent(std::pair< EntryNumbers, bool > const &)
RootInputTree const & resultsTree() const
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler_
RootInputTree::EntryNumbers EntryNumbers
Definition: RootInputFile.h:56
EventNumber_t eventsToSkip_
auto const & secondaryFiles() const
std::unique_ptr< FileBlock > createFileBlock()
void readEventHistoryTree(unsigned int treeCacheSize)
std::tuple< EventAuxiliary, SubRunAuxiliary, RunAuxiliary, ResultsAuxiliary > auxiliaries_
std::array< std::unique_ptr< RootInputTree >, NumBranchTypes > RootInputTreePtrArray
Definition: RootInputFile.h:54
std::unique_ptr< RunPrincipal > readRun()
ResultsAuxiliary & resultsAux()
bool setEntry(ID const &id, bool exact=true)
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductList.h:15
FileIndex & fileIndex_
const_iterator findPosition(EventID const &eID) const
RootInputTree const & eventTree() const
void overrideRunNumber(RunID &id)
std::unique_ptr< RangeSetHandler > fillAuxiliary(EntryNumbers const &entries)
void dropOnInput(GroupSelectorRules const &rules, BranchChildren const &children, bool dropDescendants, ProductList &branchDescriptions)
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)
RootInputFile & operator=(RootInputFile const &)=delete
EventID eventIDForFileIndexPosition() const
bool setIfFastClonable(FastCloningInfoProvider const &fcip) const
std::unique_ptr< ResultsPrincipal > readResults()
RootInputTree & subRunTree()
iterator end()
Definition: FileIndex.h:113
std::unique_ptr< RunPrincipal > readCurrentRun(EntryNumbers const &)
RootInputTreePtrArray treePointers_
std::shared_ptr< DuplicateChecker > duplicateChecker_
int setForcedRunOffset(RunNumber_t const &forcedRunNumber)
std::unique_ptr< RangeSetHandler > runRangeSetHandler()
ProductRegistry productListHolder_
void initializeDuplicateChecker()
RootInputTree & eventTree()
auto const & secondaryFileNames() const
FileFormatVersion fileFormatVersion_
std::array< AvailableProducts_t, NumBranchTypes > fillPerBranchTypePresenceFlags(ProductList const &)
EventAuxiliary & eventAux()
bool readEventForSecondaryFile(EventID eID)
RootInputFile(RootInputFile const &)=delete
std::shared_ptr< FileIndex > fileIndexSharedPtr() const
FileIndex::const_iterator fiBegin_
static ProductTables invalid()
unsigned int eventsToSkip() const
RootInputTree const & runTree() const
std::unique_ptr< RangeSetHandler > runRangeSetHandler_
int skipEvents(int offset)
std::string const fileName_
std::unique_ptr< EventPrincipal > readEvent()
cet::exempt_ptr< EventPrincipal > primaryEP_
std::pair< EntryNumbers, bool > getEntryNumbers(BranchType)
cet::sqlite::Connection sqliteDB_
input::EntryNumber EntryNumber
Definition: RootInputTree.h:77
bool readRunForSecondaryFile(RunID)
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_
bool fastClonable() const
RootInputTree & resultsTree()
FileIndex::const_iterator fiEnd_
FileIndex::EntryType getEntryType() const
std::unique_ptr< RangeSetHandler > subRunRangeSetHandler()
std::shared_ptr< FileIndex > fileIndexSharedPtr_
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:76
RootInputTree & runTree()
FileFormatVersion fileFormatVersion() const
RootInputTree::EntryNumber EntryNumber
Definition: RootInputFile.h:55
InputSource::ProcessingMode processingMode_
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
BranchType
Definition: BranchType.h:18
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
iterator begin()
Definition: FileIndex.h:97
std::unique_ptr< SubRunPrincipal > readCurrentSubRun(EntryNumbers const &, cet::exempt_ptr< RunPrincipal >)
void advanceEntry(std::size_t n)
std::string const logicalFileName_
ProductTables presentProducts_
cet::exempt_ptr< RunPrincipal > primaryRP_
RootInputTree const & subRunTree() const
def entry(str)
Definition: HTMLTools.py:26
cet::exempt_ptr< RootInputFileSequence > rifSequence_
SubRunAuxiliary & subRunAux()
bool const rangesEnabled_
ProcessConfiguration const & processConfiguration_
bool const parentageEnabled_
void openSecondaryFile(int const idx)
cet::exempt_ptr< SubRunPrincipal > primarySRP_
void close(bool reallyClose)
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119
enum BeamMode string