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 expandtab :
4 
33 #include "cetlib/exempt_ptr.h"
35 
36 #include <array>
37 #include <map>
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 class TFile;
43 class TTree;
44 class TBranch;
45 
46 namespace art {
47  namespace detail {
48  void mergeAuxiliary(RunAuxiliary& left, RunAuxiliary const& right);
49  void mergeAuxiliary(SubRunAuxiliary& left, SubRunAuxiliary const& right);
50  } // namespace detail
51  class DuplicateChecker;
52  class EventRangeHandler;
53  class GroupSelectorRules;
54  class UpdateOutputCallbacks;
55  class RootInputFile {
56  private: // TYPES
57  class RootInputTree {
58  public: // TYPES
62 
63  public: // MEMBER FUNCTIONS -- Special Member Functions
64  ~RootInputTree();
66  BranchType,
67  int64_t saveMemoryObjectThreshold,
69  bool missingOK = false);
70  RootInputTree(RootInputTree const&) = delete;
71  RootInputTree(RootInputTree&&) = delete;
72  RootInputTree& operator=(RootInputTree const&) = delete;
73  RootInputTree&& operator=(RootInputTree&&) = delete;
74 
75  public: // MEMBER FUNCTIONS
76  bool isValid() const;
77  EntryNumber entries() const;
78  TTree* tree() const;
79  TTree* metaTree() const;
80  TBranch* auxBranch() const;
81  TBranch* productProvenanceBranch() const;
82  BranchMap const& branches() const;
83  void addBranch(BranchDescription const&);
84  void dropBranch(std::string const& branchName);
85 
86  private: // MEMBER DATA
87  TTree* tree_{nullptr};
88  TTree* metaTree_{nullptr};
89  TBranch* auxBranch_{nullptr};
90  TBranch* productProvenanceBranch_{nullptr};
91  EntryNumber entries_{0};
92  BranchMap branches_{};
93  };
94 
95  public: // TYPES
96  using RootInputTreePtrArray =
97  std::array<std::unique_ptr<RootInputTree>, NumBranchTypes>;
100 
101  public: // MEMBER FUNCTIONS -- Special Member Functions
102  ~RootInputFile();
103  RootInputFile(RootInputFile const&) = delete;
104  RootInputFile(RootInputFile&&) = delete;
105  RootInputFile& operator=(RootInputFile const&) = delete;
106  RootInputFile& operator=(RootInputFile&&) = delete;
107  RootInputFile(std::string const& fileName,
108  std::string const& catalogName,
109  ProcessConfiguration const& processConfiguration,
110  std::string const& logicalFileName,
111  std::unique_ptr<TFile>&& filePtr,
112  EventID const& origEventID,
113  unsigned int eventsToSkip,
114  bool compactSubRunRanges,
115  FastCloningInfoProvider const& fcip,
116  unsigned int treeCacheSize,
117  int64_t treeMaxVirtualSize,
118  int64_t saveMemoryObjectThreashold,
119  bool delayedReadEventProducts,
120  bool delayedReadSubRunProducts,
121  bool delayedReadRunProducts,
122  InputSource::ProcessingMode processingMode,
123  int forcedRunOffset,
124  bool noEventSort,
125  GroupSelectorRules const& groupSelectorRules,
126  std::shared_ptr<DuplicateChecker> duplicateChecker,
127  bool dropDescendantsOfDroppedProducts,
128  bool readIncomingParameterSets,
129  cet::exempt_ptr<RootInputFile> primaryFile,
130  std::vector<std::string> const& secondaryFileNames,
131  RootInputFileSequence* rifSequence,
132  UpdateOutputCallbacks& outputCallbacks);
133 
134  public: // MEMBER FUNCTIONS
135  void reportOpened();
136  void close(bool reallyClose);
137  std::unique_ptr<ResultsPrincipal> readResults();
138  std::unique_ptr<RunPrincipal> readRun();
139  std::unique_ptr<SubRunPrincipal> readSubRun(
141  std::unique_ptr<EventPrincipal> readEvent();
142  bool readRunForSecondaryFile(RunID);
143  bool readSubRunForSecondaryFile(SubRunID);
144  bool readEventForSecondaryFile(EventID eID);
145  std::string const& fileName() const;
146  RootInputTreePtrArray& treePointers();
147  FileFormatVersion fileFormatVersion() const;
148  bool fastClonable() const;
149  std::unique_ptr<FileBlock> createFileBlock();
150  bool setEntry_Event(EventID const& id, bool exact = true);
151  bool setEntry_SubRun(SubRunID const& id, bool exact = true);
152  bool setEntry_Run(RunID const& id, bool exact = true);
153  void rewind();
154  void setToLastEntry();
155  void nextEntry();
156  void previousEntry();
157  void advanceEntry(std::size_t n);
158  unsigned eventsToSkip() const;
159  int skipEvents(int offset);
160  int setForcedRunOffset(RunNumber_t const& forcedRunNumber);
161  FileIndex::EntryType getEntryType() const;
162  FileIndex::EntryType getNextEntryTypeWanted();
163  std::shared_ptr<FileIndex> fileIndexSharedPtr() const;
164  EventID eventIDForFileIndexPosition() const;
165  std::vector<std::string> const& secondaryFileNames() const;
166  std::vector<std::unique_ptr<RootInputFile>> const& secondaryFiles() const;
167  void openSecondaryFile(int const idx);
168  std::unique_ptr<RangeSetHandler> runRangeSetHandler();
169  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler();
170 
171  private: // MEMBER FUNCTIONS -- Implementation details
172  RootInputTree const& eventTree() const;
173  RootInputTree const& subRunTree() const;
174  RootInputTree const& runTree() const;
175  RootInputTree const& resultsTree() const;
176  RootInputTree& eventTree();
177  RootInputTree& subRunTree();
178  RootInputTree& runTree();
179  RootInputTree& resultsTree();
180  bool setIfFastClonable(FastCloningInfoProvider const& fcip) const;
181  void validateFile();
182  void fillHistory(EntryNumber const entry, History&);
183  void fillAuxiliary_Event(EntryNumber const entry);
184  void fillAuxiliary_SubRun(EntryNumber const entry);
185  void fillAuxiliary_Run(EntryNumber const entry);
186  void fillAuxiliary_Results(EntryNumber const entry);
187  std::unique_ptr<RangeSetHandler> fillAuxiliary_SubRun(
188  EntryNumbers const& entries);
189  std::unique_ptr<RangeSetHandler> fillAuxiliary_Run(
190  EntryNumbers const& entries);
191  void overrideRunNumber(RunAuxiliary&);
192  void overrideRunNumber(SubRunID& id);
193  void overrideRunNumber(EventID& id, bool isRealData);
194  void dropOnInput(GroupSelectorRules const& rules,
195  bool dropDescendants,
196  ProductTables& tables);
197  void readParentageTree(unsigned int treeCacheSize);
198  void readEventHistoryTree(unsigned int treeCacheSize);
199  void initializeDuplicateChecker();
200  std::pair<EntryNumbers, bool> getEntryNumbers(BranchType);
201  std::unique_ptr<RunPrincipal> readCurrentRun(EntryNumbers const&);
202  std::unique_ptr<SubRunPrincipal> readCurrentSubRun(
203  EntryNumbers const&,
205  std::unique_ptr<EventPrincipal> readCurrentEvent(
206  std::pair<EntryNumbers, bool> const&);
207 
208  private: // MEMBER DATA
213  std::unique_ptr<TFile> filePtr_;
214  // Start with invalid connection.
215  std::unique_ptr<cet::sqlite::Connection> sqliteDB_{nullptr};
226  std::shared_ptr<DuplicateChecker> duplicateChecker_;
228  std::vector<std::string> secondaryFileNames_;
230  FileFormatVersion fileFormatVersion_{};
231  std::shared_ptr<FileIndex> fileIndexSharedPtr_{new FileIndex};
232  FileIndex& fileIndex_{*fileIndexSharedPtr_};
233  FileIndex::const_iterator fiBegin_{fileIndex_.begin()};
234  FileIndex::const_iterator fiEnd_{fileIndex_.end()};
235  FileIndex::const_iterator fiIter_{fiBegin_};
236  bool fastClonable_{false};
237  EventAuxiliary eventAux_{};
238  SubRunAuxiliary subRunAux_{};
239  RunAuxiliary runAux_{};
240  ResultsAuxiliary resultsAux_{};
242  std::unique_ptr<BranchIDLists> branchIDLists_{};
243  TTree* eventHistoryTree_{nullptr};
244  std::vector<std::unique_ptr<RootInputFile>> secondaryFiles_{};
245  // We need to add the secondary principals to the primary
246  // principal when they are delay read, so we need to keep
247  // around a pointer to the primary. Note that these are
248  // always used in a situation where we are guaranteed that
249  // primary exists.
253  std::unique_ptr<RangeSetHandler> subRunRangeSetHandler_{nullptr};
254  std::unique_ptr<RangeSetHandler> runRangeSetHandler_{nullptr};
256  };
257 } // namespace art
258 
259 // Local Variables:
260 // mode: c++
261 // End:
262 #endif /* art_Framework_IO_Root_RootInputFile_h */
std::string const catalog_
std::vector< std::string > secondaryFileNames_
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
input::EntryNumbers EntryNumbers
Definition: RootInputFile.h:61
iterator begin()
Definition: FileIndex.cc:62
RootInputTree::EntryNumbers EntryNumbers
Definition: RootInputFile.h:99
EventNumber_t eventsToSkip_
void mergeAuxiliary(RunAuxiliary &left, RunAuxiliary const &right)
std::string string
Definition: nybbler.cc:12
std::array< std::unique_ptr< RootInputTree >, NumBranchTypes > RootInputTreePtrArray
Definition: RootInputFile.h:97
RootInputTreePtrArray treePointers_
std::shared_ptr< DuplicateChecker > duplicateChecker_
std::vector< EntryNumber > EntryNumbers
Definition: Inputfwd.h:42
std::map< ProductID, BranchInfo > BranchMap
Definition: Inputfwd.h:40
std::string const fileName_
Long64_t EntryNumber
Definition: Inputfwd.h:41
static ProductTables invalid()
cet::exempt_ptr< RootInputFile > primaryFile_
std::unique_ptr< TFile > filePtr_
bool const compactSubRunRanges_
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:96
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:75
RootInputTree::EntryNumber EntryNumber
Definition: RootInputFile.h:98
int64_t saveMemoryObjectThreshold_
InputSource::ProcessingMode processingMode_
signed __int64 int64_t
Definition: stdint.h:131
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
BranchType
Definition: BranchType.h:18
std::string const logicalFileName_
cet::exempt_ptr< RootInputFileSequence > rifSequence_
ProcessConfiguration const & processConfiguration_
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120