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
26 
27 #include <array>
28 #include <map>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 
33 namespace edm {
34 
35  //------------------------------------------------------------
36  // Class RootFile: supports file reading.
37 
38  class BranchID;
39  class BranchIDListHelper;
40  class ProductProvenanceRetriever;
41  class DaqProvenanceHelper;
42  class DuplicateChecker;
43  class EventSkipperByID;
44  class ProcessHistoryRegistry;
45  class ProductSelectorRules;
46  class InputFile;
47  class ProvenanceReaderBase;
48  class ProvenanceAdaptor;
50 
51  typedef std::map<EntryDescriptionID, EventEntryDescription> EntryDescriptionMap;
52 
54  public:
55  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
56  };
57 
58  class RootFile {
59  public:
60  typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
63  std::string const& logicalFileName,
64  std::shared_ptr<InputFile> filePtr,
65  std::shared_ptr<EventSkipperByID> eventSkipperByID,
66  bool skipAnyEvents,
67  int remainingEvents,
68  int remainingLumis,
69  unsigned int nStreams,
70  unsigned int treeCacheSize,
71  int treeMaxVirtualSize,
73  RunNumber_t const& forcedRunNumber,
74  bool noEventSort,
75  ProductSelectorRules const& productSelectorRules,
76  InputType inputType,
77  std::shared_ptr<BranchIDListHelper> branchIDListHelper,
78  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
79  std::vector<BranchID> const& associationsFromSecondary,
80  std::shared_ptr<DuplicateChecker> duplicateChecker,
81  bool dropDescendantsOfDroppedProducts,
82  ProcessHistoryRegistry& processHistoryRegistry,
83  std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
84  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
85  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
86  bool bypassVersionCheck,
87  bool labelRawDataLikeMC,
88  bool usingGoToEvent,
89  bool enablePrefetching);
90  ~RootFile();
91 
92  RootFile(RootFile const&) = delete; // Disallow copying and moving
93  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
94 
95  void reportOpened(std::string const& inputType);
96  void close();
97  bool readCurrentEvent(EventPrincipal& cache);
98  void readEvent(EventPrincipal& cache);
99 
100  std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
101  std::shared_ptr<RunAuxiliary> readRunAuxiliary_();
102  void readRun_(RunPrincipal& runPrincipal);
103  void readLuminosityBlock_(LuminosityBlockPrincipal& lumiPrincipal);
104  std::string const& file() const {return file_;}
105  std::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
106  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return branchIDListHelper_;}
107  EventAuxiliary const& eventAux() const {return eventAux_;}
108  // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
109  // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
110  // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
111  EventID const& eventID() const {return eventAux().id();}
112  RootTree const& eventTree() const {return eventTree_;}
113  RootTree const& lumiTree() const {return lumiTree_;}
114  RootTree const& runTree() const {return runTree_;}
117  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
119  bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
120  std::unique_ptr<FileBlock> createFileBlock() const;
122  return (event != 0) ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
123  }
130 
131  void rewind() {
133  eventTree_.rewind();
134  lumiTree_.rewind();
135  runTree_.rewind();
136  }
137  void setToLastEntry() {
139  }
140 
141  bool skipEvents(int& offset);
142  bool goToEvent(EventID const& eventID);
143  bool nextEventEntry() {return eventTree_.next();}
145  std::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
147  }
148  bool wasLastEventJustRead() const;
149  bool wasFirstEventJustRead() const;
152  void initAssociationsFromSecondary(std::vector<BranchID> const&);
153 
154  private:
156  bool skipThisEntry();
157  void setIfFastClonable(int remainingEvents, int remainingLumis);
158  void validateFile(InputType inputType, bool usingGoToEvent);
159  void fillIndexIntoFile();
161  void fillThisEventAuxiliary();
162  void fillEventHistory();
163  std::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
164  std::shared_ptr<RunAuxiliary> fillRunAuxiliary();
165  void overrideRunNumber(RunID& id);
167  void overrideRunNumber(EventID& id, bool isRealData);
168  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
169  void markBranchToBeDropped(bool dropDescendants, BranchID const& branchID, std::set<BranchID>& branchesToDrop) const;
170  void dropOnInput(ProductRegistry& reg, ProductSelectorRules const& rules, bool dropDescendants, InputType inputType);
171  void readParentageTree(InputType inputType);
172  void readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType); // backward compatibility
173  void readEventHistoryTree();
174  bool isDuplicateEvent();
175 
176  void initializeDuplicateChecker(std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
177  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
178 
179  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker(InputType inputType);
180  std::shared_ptr<ProductProvenanceRetriever> makeProductProvenanceRetriever(unsigned int iStreamIndex);
181 
186  std::shared_ptr<InputFile> filePtr_;
187  std::shared_ptr<EventSkipperByID> eventSkipperByID_;
190  std::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
192  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
196  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
197  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
198  std::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
202  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
210  std::shared_ptr<ProductRegistry const> productRegistry_;
211  std::shared_ptr<BranchIDLists const> branchIDLists_;
212  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
213  std::unique_ptr<ThinnedAssociationsHelper> fileThinnedAssociationsHelper_;
214  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
217  std::map<std::string, std::string> newBranchToOldBranch_;
218  TTree* eventHistoryTree_; // backward compatibility
221  std::unique_ptr<History> history_; // backward compatibility
222  std::shared_ptr<BranchChildren> branchChildren_;
223  std::shared_ptr<DuplicateChecker> duplicateChecker_;
224  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
225  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
226  mutable std::vector<std::shared_ptr<ProductProvenanceRetriever>> eventProductProvenanceRetrievers_;
227  std::vector<ParentageID> parentageIDLookup_;
228  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
230  }; // class RootFile
231 
232 }
233 #endif
void dropOnInput(ProductRegistry &reg, ProductSelectorRules const &rules, bool dropDescendants, InputType inputType)
Definition: RootFile.cc:1707
EventID const & eventID() const
Definition: RootFile.h:111
bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.h:121
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
Definition: RootFile.h:214
std::unique_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:224
std::unique_ptr< History > history_
Definition: RootFile.h:221
InputType
Definition: InputType.h:5
RootTree const & lumiTree() const
Definition: RootFile.h:113
std::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:211
bool skipEvents(int &offset)
Definition: RootFile.cc:1306
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: RootFile.h:106
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:115
std::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1261
RootFile & operator=(RootFile const &)=delete
void readEntryDescriptionTree(EntryDescriptionMap &entryDescriptionMap, InputType inputType)
Definition: RootFile.cc:526
bool branchListIndexesUnchanged() const
Definition: RootFile.h:118
bool nextEventEntry()
Definition: RootFile.h:143
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1625
int whyNotFastClonable_
Definition: RootFile.h:201
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:217
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1617
void readRun_(RunPrincipal &runPrincipal)
Definition: RootFile.cc:1528
RootTree lumiTree_
Definition: RootFile.h:206
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:225
unsigned long long EventNumber_t
processConfiguration
Definition: Schedule.cc:370
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:215
TClass * edProductClass_
Definition: RootFile.h:229
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:195
std::unique_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:662
bool readCurrentEvent(EventPrincipal &cache)
Definition: RootFile.cc:1431
std::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:105
uint16_t size_type
unsigned int LuminosityBlockNumber_t
long long EntryNumber_t
bool fillEventAuxiliary(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1195
std::vector< EventSelectionID > EventSelectionIDVector
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:188
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:693
void rewind()
Definition: RootFile.h:131
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:197
void setToLastEntry()
Definition: RootFile.h:137
bool skipThisEntry()
Definition: RootFile.cc:703
FileID fid_
Definition: RootFile.h:189
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: RootFile.cc:758
std::string const logicalFile_
Definition: RootFile.h:183
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:194
void readParentageTree(InputType inputType)
Definition: RootFile.cc:572
std::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:145
bool next()
Definition: RootTree.h:87
bool noEventSort_
Definition: RootFile.h:200
bool wasLastEventJustRead() const
Definition: RootFile.cc:808
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1609
void close()
Definition: RootFile.cc:1164
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:114
bool modifiedIDs() const
Definition: RootFile.h:119
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:209
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
Definition: RootFile.h:212
std::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1464
EventAuxiliary const & eventAux() const
Definition: RootFile.h:107
EventSelectionIDVector eventSelectionIDs_
Definition: RootFile.h:219
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1545
int whyNotFastClonable() const
Definition: RootFile.h:116
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, std::shared_ptr< InputFile > filePtr, std::shared_ptr< EventSkipperByID > eventSkipperByID, bool skipAnyEvents, int remainingEvents, int remainingLumis, unsigned int nStreams, unsigned int treeCacheSize, int treeMaxVirtualSize, InputSource::ProcessingMode processingMode, RunNumber_t const &forcedRunNumber, bool noEventSort, ProductSelectorRules const &productSelectorRules, InputType inputType, std::shared_ptr< BranchIDListHelper > branchIDListHelper, std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper, std::vector< BranchID > const &associationsFromSecondary, std::shared_ptr< DuplicateChecker > duplicateChecker, 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 usingGoToEvent, bool enablePrefetching)
Definition: RootFile.cc:139
std::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1285
bool skipAnyEvents_
Definition: RootFile.h:199
std::vector< std::shared_ptr< ProductProvenanceRetriever > > eventProductProvenanceRetrievers_
Definition: RootFile.h:226
RootTree eventTree_
Definition: RootFile.h:205
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:117
IndexIntoFile::EntryType getNextItemType(RunNumber_t &run, LuminosityBlockNumber_t &lumi, EventNumber_t &event)
Definition: RootFile.cc:763
BranchListIndexes branchListIndexes_
Definition: RootFile.h:220
bool isDuplicateEvent()
Definition: RootFile.cc:747
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool wasFirstEventJustRead() const
Definition: RootFile.cc:815
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:191
std::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:186
void readEvent(EventPrincipal &cache)
Definition: RootFile.cc:1408
RootTree runTree_
Definition: RootFile.h:207
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1374
std::unique_ptr< ThinnedAssociationsHelper > fileThinnedAssociationsHelper_
Definition: RootFile.h:213
std::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:187
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1459
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:202
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:184
std::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:210
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:608
std::map< EntryDescriptionID, EventEntryDescription > EntryDescriptionMap
Definition: RootFile.h:49
std::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:222
void fillEventHistory()
Definition: RootFile.cc:1205
std::shared_ptr< ProductProvenanceRetriever > makeProductProvenanceRetriever(unsigned int iStreamIndex)
Definition: RootFile.cc:1838
std::string const & file() const
Definition: RootFile.h:104
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:193
EventID const & id() const
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:60
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:228
bool branchListIndexesUnchanged_
Definition: RootFile.h:203
void fillIndexIntoFile()
Definition: RootFile.cc:877
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: RootFile.cc:1583
RootTreePtrArray treePointers_
Definition: RootFile.h:208
static int position[264][3]
Definition: ReadPGInfo.cc:509
void initializeDuplicateChecker(std::vector< std::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< std::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1682
std::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:223
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:192
void initAssociationsFromSecondary(std::vector< BranchID > const &)
Definition: RootFile.cc:698
RootTreePtrArray & treePointers()
Definition: RootFile.h:155
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1638
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker(InputType inputType)
Definition: RootFile.cc:1821
unsigned int RunNumber_t
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:227
EventAuxiliary eventAux_
Definition: RootFile.h:204
void fillThisEventAuxiliary()
Definition: RootFile.cc:1176
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1601
ProcessHistoryRegistry * processHistoryRegistry_
Definition: RootFile.h:185
void markBranchToBeDropped(bool dropDescendants, BranchID const &branchID, std::set< BranchID > &branchesToDrop) const
Definition: RootFile.cc:1698
void rewind()
Definition: RootTree.h:91
RootTree const & eventTree() const
Definition: RootFile.h:112
void validateFile(InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1103
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:688
std::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:190
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:679
TTree * eventHistoryTree_
Definition: RootFile.h:218
std::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:198
std::string const file_
Definition: RootFile.h:182
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:196
void readEventHistoryTree()
Definition: RootFile.cc:1669
int forcedRunOffset_
Definition: RootFile.h:216
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1150