CMS 3D CMS Logo

RootFile.h
Go to the documentation of this file.
1 #ifndef IOPool_Input_RootFile_h
2 #define IOPool_Input_RootFile_h
3 
4 /*----------------------------------------------------------------------
5 
6 RootFile.h // used by ROOT input sources
7 
8 ----------------------------------------------------------------------*/
9 
10 #include "RootTree.h"
14 #include "DataFormats/Provenance/interface/EntryDescriptionID.h" // backward compatibility
16 #include "DataFormats/Provenance/interface/EventEntryDescription.h" // backward compatibility
17 #include "DataFormats/Provenance/interface/EventProcessHistoryID.h" // backward compatibility
27 
28 #include <array>
29 #include <map>
30 #include <memory>
31 #include <string>
32 #include <vector>
33 
34 namespace edm {
35 
36  //------------------------------------------------------------
37  // Class RootFile: supports file reading.
38 
39  class BranchID;
40  class BranchIDListHelper;
41  class ProductProvenanceRetriever;
42  struct DaqProvenanceHelper;
43  class DuplicateChecker;
44  class EventSkipperByID;
45  class ProcessHistoryRegistry;
46  class ProductSelectorRules;
47  class InputFile;
48  class ProvenanceReaderBase;
49  class ProvenanceAdaptor;
50  class RunHelperBase;
52 
53  typedef std::map<EntryDescriptionID, EventEntryDescription> EntryDescriptionMap;
54 
56  public:
57  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
58  virtual ~MakeProvenanceReader() = default;
59  };
60 
61  class RootFile {
62  public:
63  typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
65  ProcessConfiguration const& processConfiguration,
66  std::string const& logicalFileName,
67  std::shared_ptr<InputFile> filePtr,
68  std::shared_ptr<EventSkipperByID> eventSkipperByID,
69  bool skipAnyEvents,
70  int remainingEvents,
71  int remainingLumis,
72  unsigned int nStreams,
73  unsigned int treeCacheSize,
74  int treeMaxVirtualSize,
75  InputSource::ProcessingMode processingMode,
76  RunHelperBase* runHelper,
77  bool noEventSort,
78  ProductSelectorRules const& productSelectorRules,
79  InputType inputType,
80  std::shared_ptr<BranchIDListHelper> branchIDListHelper,
81  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
82  std::vector<BranchID> const* associationsFromSecondary,
83  std::shared_ptr<DuplicateChecker> duplicateChecker,
84  bool dropDescendantsOfDroppedProducts,
85  ProcessHistoryRegistry& processHistoryRegistry,
86  std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
87  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
88  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
89  bool bypassVersionCheck,
90  bool labelRawDataLikeMC,
91  bool usingGoToEvent,
92  bool enablePrefetching,
93  bool enforceGUIDInFileName);
94 
96  ProcessConfiguration const& processConfiguration,
97  std::string const& logicalFileName,
98  std::shared_ptr<InputFile> filePtr,
99  unsigned int nStreams,
100  int treeMaxVirtualSize,
101  InputSource::ProcessingMode processingMode,
102  RunHelperBase* runHelper,
103  ProductSelectorRules const& productSelectorRules,
104  InputType inputType,
105  std::shared_ptr<BranchIDListHelper> branchIDListHelper,
106  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
107  std::vector<BranchID> const* associationsFromSecondary,
108  bool dropDescendantsOfDroppedProducts,
109  ProcessHistoryRegistry& processHistoryRegistry,
110  std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
111  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
112  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
113  bool bypassVersionCheck,
114  bool labelRawDataLikeMC,
115  bool enablePrefetching,
116  bool enforceGUIDInFileName) : RootFile(
117  fileName, processConfiguration, logicalFileName, filePtr,
118  nullptr, false, -1, -1, nStreams, 0U, treeMaxVirtualSize,
119  processingMode, runHelper,
120  false, productSelectorRules, inputType, branchIDListHelper,
121  thinnedAssociationsHelper, associationsFromSecondary,
122  nullptr, dropDescendantsOfDroppedProducts, processHistoryRegistry,
123  indexesIntoFiles, currentIndexIntoFile, orderedProcessHistoryIDs,
124  bypassVersionCheck, labelRawDataLikeMC,
125  false, enablePrefetching, enforceGUIDInFileName) {}
126 
128  ProcessConfiguration const& processConfiguration,
129  std::string const& logicalFileName,
130  std::shared_ptr<InputFile> filePtr,
131  unsigned int nStreams,
132  unsigned int treeCacheSize,
133  int treeMaxVirtualSize,
134  RunHelperBase* runHelper,
135  ProductSelectorRules const& productSelectorRules,
136  InputType inputType,
137  ProcessHistoryRegistry& processHistoryRegistry,
138  std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
139  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
140  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
141  bool bypassVersionCheck,
142  bool enablePrefetching,
143  bool enforceGUIDInFileName) : RootFile(
144  fileName, processConfiguration, logicalFileName, filePtr,
145  nullptr, false, -1, -1, nStreams, treeCacheSize, treeMaxVirtualSize,
146  InputSource::RunsLumisAndEvents, runHelper,
147  false, productSelectorRules, inputType, nullptr, nullptr,
148  nullptr, nullptr, false, processHistoryRegistry,
149  indexesIntoFiles, currentIndexIntoFile, orderedProcessHistoryIDs,
150  bypassVersionCheck, false,
151  false, enablePrefetching, enforceGUIDInFileName) {}
152 
153  ~RootFile();
154 
155  RootFile(RootFile const&) = delete; // Disallow copying and moving
156  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
157 
158  void reportOpened(std::string const& inputType);
159  void close();
160  bool readCurrentEvent(EventPrincipal& cache);
161  void readEvent(EventPrincipal& cache);
162 
163  std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
164  std::shared_ptr<RunAuxiliary> readRunAuxiliary_();
165  std::shared_ptr<RunAuxiliary> readFakeRunAuxiliary_();
166  void readRun_(RunPrincipal& runPrincipal);
167  void readFakeRun_(RunPrincipal& runPrincipal);
168  void readLuminosityBlock_(LuminosityBlockPrincipal& lumiPrincipal);
169  std::string const& file() const {return file_;}
170  std::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
171  EventAuxiliary const& eventAux() const {return eventAux_;}
172  // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
173  // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
174  // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
175  EventID const& eventID() const {return eventAux().id();}
176  RootTree const& eventTree() const {return eventTree_;}
177  RootTree const& lumiTree() const {return lumiTree_;}
178  RootTree const& runTree() const {return runTree_;}
179  FileFormatVersion fileFormatVersion() const {return fileFormatVersion_;}
180  int whyNotFastClonable() const {return whyNotFastClonable_;}
181  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
182  bool branchListIndexesUnchanged() const {return branchListIndexesUnchanged_;}
183  bool modifiedIDs() const {return daqProvenanceHelper_.get() != nullptr;}
184  std::unique_ptr<FileBlock> createFileBlock() const;
186  return (event != 0) ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
187  }
188  bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
189  bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event);
190  bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
191  bool setEntryAtRun(RunNumber_t run);
192  bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
193  void setAtEventEntry(IndexIntoFile::EntryNumber_t entry);
194 
195  void rewind() {
196  indexIntoFileIter_ = indexIntoFileBegin_;
197  eventTree_.rewind();
198  lumiTree_.rewind();
199  runTree_.rewind();
200  }
201  void setToLastEntry() {
202  indexIntoFileIter_ = indexIntoFileEnd_;
203  }
204 
205  bool skipEntries(unsigned int& offset) {return eventTree_.skipEntries(offset);}
206  bool skipEvents(int& offset);
207  bool goToEvent(EventID const& eventID);
208  bool nextEventEntry() {return eventTree_.nextWithCache();}
209  IndexIntoFile::EntryType getNextItemType(RunNumber_t& run, LuminosityBlockNumber_t& lumi, EventNumber_t& event);
210  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return get_underlying_safe(branchIDListHelper_);}
211  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() {return get_underlying_safe(branchIDListHelper_);}
212  std::shared_ptr<IndexIntoFile const> indexIntoFileSharedPtr() const {return get_underlying_safe(indexIntoFileSharedPtr_);}
213  std::shared_ptr<IndexIntoFile>& indexIntoFileSharedPtr() {return get_underlying_safe(indexIntoFileSharedPtr_);}
214  bool wasLastEventJustRead() const;
215  bool wasFirstEventJustRead() const;
216  IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const;
217  void setPosition(IndexIntoFile::IndexIntoFileItr const& position);
218  void initAssociationsFromSecondary(std::vector<BranchID> const&);
219 
220  void setSignals(signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadSource,
221  signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource);
222  private:
223  RootTreePtrArray& treePointers() {return treePointers_;}
224  bool skipThisEntry();
225  void setIfFastClonable(int remainingEvents, int remainingLumis);
226  void validateFile(InputType inputType, bool usingGoToEvent);
227  void fillIndexIntoFile();
228  bool fillEventAuxiliary(IndexIntoFile::EntryNumber_t entry);
229  void fillThisEventAuxiliary();
230  void fillEventHistory();
231  std::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
232  std::shared_ptr<RunAuxiliary> fillRunAuxiliary();
233  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
234  void markBranchToBeDropped(bool dropDescendants, BranchDescription const& branch, std::set<BranchID>& branchesToDrop, std::map<BranchID, BranchID> const& droppedToKeptAlias) const;
235  void dropOnInput(ProductRegistry& reg, ProductSelectorRules const& rules, bool dropDescendants, InputType inputType);
236  void readParentageTree(InputType inputType);
237  void readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType); // backward compatibility
238  void readEventHistoryTree();
239  bool isDuplicateEvent();
240 
241  void initializeDuplicateChecker(std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
242  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
243 
244  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker(InputType inputType);
245  std::shared_ptr<ProductProvenanceRetriever> makeProductProvenanceRetriever(unsigned int iStreamIndex);
246 
247  std::shared_ptr<RunAuxiliary const> savedRunAuxiliary() const {return get_underlying_safe(savedRunAuxiliary_);}
248  std::shared_ptr<RunAuxiliary>& savedRunAuxiliary() {return get_underlying_safe(savedRunAuxiliary_);}
249 
250  std::shared_ptr<BranchChildren const> branchChildren() const {return get_underlying_safe(branchChildren_);}
251  std::shared_ptr<BranchChildren>& branchChildren() {return get_underlying_safe(branchChildren_);}
252 
253  std::shared_ptr<ProductProvenanceRetriever const> eventProductProvenanceRetriever(size_t index) const {return get_underlying_safe(eventProductProvenanceRetrievers_[index]);}
254  std::shared_ptr<ProductProvenanceRetriever>& eventProductProvenanceRetriever(size_t index) {return get_underlying_safe(eventProductProvenanceRetrievers_[index]);}
255 
266  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
270  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
271  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
277  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
283  RootTreePtrArray treePointers_;
285  std::shared_ptr<ProductRegistry const> productRegistry_;
286  std::shared_ptr<BranchIDLists const> branchIDLists_;
292  std::map<std::string, std::string> newBranchToOldBranch_;
301  std::vector<edm::propagate_const<std::shared_ptr<ProductProvenanceRetriever>>> eventProductProvenanceRetrievers_;
302  std::vector<ParentageID> parentageIDLookup_;
305  }; // class RootFile
306 
307 }
308 #endif
EventID const & eventID() const
Definition: RootFile.h:175
bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.h:185
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > fileThinnedAssociationsHelper_
Definition: RootFile.h:288
InputType
Definition: InputType.h:5
RootTree const & lumiTree() const
Definition: RootFile.h:177
std::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:286
edm::propagate_const< std::shared_ptr< DuplicateChecker > > duplicateChecker_
Definition: RootFile.h:298
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: RootFile.h:210
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:179
virtual ~MakeProvenanceReader()=default
bool branchListIndexesUnchanged() const
Definition: RootFile.h:182
bool nextEventEntry()
Definition: RootFile.h:208
bool enforceGUIDInFileName_
Definition: RootFile.h:275
int whyNotFastClonable_
Definition: RootFile.h:276
edm::propagate_const< std::shared_ptr< EventSkipperByID > > eventSkipperByID_
Definition: RootFile.h:261
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: RootFile.h:289
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:292
edm::propagate_const< std::shared_ptr< IndexIntoFile > > indexIntoFileSharedPtr_
Definition: RootFile.h:264
RootTree lumiTree_
Definition: RootFile.h:281
edm::propagate_const< ProcessHistoryRegistry * > processHistoryRegistry_
Definition: RootFile.h:259
edm::propagate_const< std::unique_ptr< DaqProvenanceHelper > > daqProvenanceHelper_
Definition: RootFile.h:303
edm::propagate_const< std::shared_ptr< RunAuxiliary > > savedRunAuxiliary_
Definition: RootFile.h:272
unsigned long long EventNumber_t
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:290
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:269
std::shared_ptr< ProductProvenanceRetriever const > eventProductProvenanceRetriever(size_t index) const
Definition: RootFile.h:253
bool skipEntries(unsigned int &offset)
Definition: RootFile.h:205
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, std::shared_ptr< InputFile > filePtr, unsigned int nStreams, int treeMaxVirtualSize, InputSource::ProcessingMode processingMode, RunHelperBase *runHelper, ProductSelectorRules const &productSelectorRules, InputType inputType, std::shared_ptr< BranchIDListHelper > branchIDListHelper, std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper, std::vector< BranchID > const *associationsFromSecondary, bool dropDescendantsOfDroppedProducts, ProcessHistoryRegistry &processHistoryRegistry, std::vector< std::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< std::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool bypassVersionCheck, bool labelRawDataLikeMC, bool enablePrefetching, bool enforceGUIDInFileName)
Definition: RootFile.h:95
#define nullptr
std::shared_ptr< IndexIntoFile > & indexIntoFileSharedPtr()
Definition: RootFile.h:213
std::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:170
uint16_t size_type
unsigned int LuminosityBlockNumber_t
std::vector< EventSelectionID > EventSelectionIDVector
edm::propagate_const< TClass * > edProductClass_
Definition: RootFile.h:304
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:262
void rewind()
Definition: RootFile.h:195
std::vector< edm::propagate_const< std::shared_ptr< ProductProvenanceRetriever > > > eventProductProvenanceRetrievers_
Definition: RootFile.h:301
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:271
void setToLastEntry()
Definition: RootFile.h:201
FileID fid_
Definition: RootFile.h:263
long long EntryNumber_t
std::string const logicalFile_
Definition: RootFile.h:257
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:268
bool noEventSort_
Definition: RootFile.h:274
RootTree const & runTree() const
Definition: RootFile.h:178
bool modifiedIDs() const
Definition: RootFile.h:183
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:284
EventAuxiliary const & eventAux() const
Definition: RootFile.h:171
EventSelectionIDVector eventSelectionIDs_
Definition: RootFile.h:294
int whyNotFastClonable() const
Definition: RootFile.h:180
edm::propagate_const< std::unique_ptr< ProvenanceAdaptor > > provenanceAdaptor_
Definition: RootFile.h:299
std::shared_ptr< ProductProvenanceRetriever > & eventProductProvenanceRetriever(size_t index)
Definition: RootFile.h:254
bool skipAnyEvents_
Definition: RootFile.h:273
RootTree eventTree_
Definition: RootFile.h:280
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:181
BranchListIndexes branchListIndexes_
Definition: RootFile.h:295
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
def cache(function)
edm::propagate_const< std::unique_ptr< History > > history_
Definition: RootFile.h:296
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:265
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
Definition: RootFile.h:211
RootTree runTree_
Definition: RootFile.h:282
edm::propagate_const< std::unique_ptr< MakeProvenanceReader > > provenanceReaderMaker_
Definition: RootFile.h:300
std::shared_ptr< RunAuxiliary const > savedRunAuxiliary() const
Definition: RootFile.h:247
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:277
std::shared_ptr< RunAuxiliary > & savedRunAuxiliary()
Definition: RootFile.h:248
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:258
std::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:285
std::map< EntryDescriptionID, EventEntryDescription > EntryDescriptionMap
Definition: RootFile.h:51
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, std::shared_ptr< InputFile > filePtr, unsigned int nStreams, unsigned int treeCacheSize, int treeMaxVirtualSize, RunHelperBase *runHelper, ProductSelectorRules const &productSelectorRules, InputType inputType, ProcessHistoryRegistry &processHistoryRegistry, std::vector< std::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< std::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool bypassVersionCheck, bool enablePrefetching, bool enforceGUIDInFileName)
Definition: RootFile.h:127
edm::propagate_const< std::shared_ptr< BranchChildren > > branchChildren_
Definition: RootFile.h:297
edm::propagate_const< std::shared_ptr< InputFile > > filePtr_
Definition: RootFile.h:260
std::shared_ptr< BranchChildren const > branchChildren() const
Definition: RootFile.h:250
std::shared_ptr< BranchChildren > & branchChildren()
Definition: RootFile.h:251
std::string const & file() const
Definition: RootFile.h:169
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:267
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:63
edm::propagate_const< RunHelperBase * > runHelper_
Definition: RootFile.h:291
bool branchListIndexesUnchanged_
Definition: RootFile.h:278
HLT enums.
edm::propagate_const< TTree * > eventHistoryTree_
Definition: RootFile.h:293
RootTreePtrArray treePointers_
Definition: RootFile.h:283
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:266
RootTreePtrArray & treePointers()
Definition: RootFile.h:223
std::shared_ptr< IndexIntoFile const > indexIntoFileSharedPtr() const
Definition: RootFile.h:212
unsigned int RunNumber_t
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:302
EventAuxiliary eventAux_
Definition: RootFile.h:279
RootTree const & eventTree() const
Definition: RootFile.h:176
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: RootFile.h:287
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
std::string const file_
Definition: RootFile.h:256
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:270
Definition: event.py:1