CMS 3D CMS Logo

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