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 BranchIDListHelper;
39  class ProductProvenanceRetriever;
40  class DaqProvenanceHelper;
41  class DuplicateChecker;
42  class EventSkipperByID;
43  class ProcessHistoryRegistry;
44  class ProductSelectorRules;
45  class InputFile;
46  class ProvenanceReaderBase;
48  typedef std::map<EntryDescriptionID, EventEntryDescription> EntryDescriptionMap;
49 
51  public:
52  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
53  };
54 
55  class RootFile {
56  public:
57  typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
60  std::string const& logicalFileName,
61  std::shared_ptr<InputFile> filePtr,
62  std::shared_ptr<EventSkipperByID> eventSkipperByID,
63  bool skipAnyEvents,
64  int remainingEvents,
65  int remainingLumis,
66  unsigned int nStreams,
67  unsigned int treeCacheSize,
68  int treeMaxVirtualSize,
70  RunNumber_t const& forcedRunNumber,
71  bool noEventSort,
72  ProductSelectorRules const& productSelectorRules,
73  InputType inputType,
74  std::shared_ptr<BranchIDListHelper> branchIDListHelper,
75  std::shared_ptr<DuplicateChecker> duplicateChecker,
76  bool dropDescendantsOfDroppedProducts,
77  ProcessHistoryRegistry& processHistoryRegistry,
78  std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
79  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
80  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
81  bool bypassVersionCheck,
82  bool labelRawDataLikeMC,
83  bool usingGoToEvent,
84  bool enablePrefetching);
85  ~RootFile();
86 
87  RootFile(RootFile const&) = delete; // Disallow copying and moving
88  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
89 
90  void reportOpened(std::string const& inputType);
91  void close();
92  bool readCurrentEvent(EventPrincipal& cache);
93  void readEvent(EventPrincipal& cache);
94 
95  std::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
96  std::shared_ptr<RunAuxiliary> readRunAuxiliary_();
97  void readRun_(RunPrincipal& runPrincipal);
99  std::string const& file() const {return file_;}
100  std::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
101  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return branchIDListHelper_;}
103  EventAuxiliary const& eventAux() const {return eventAux_;}
104  // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
105  // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
106  // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
107  EventID const& eventID() const {return eventAux().id();}
108  RootTree const& eventTree() const {return eventTree_;}
109  RootTree const& lumiTree() const {return lumiTree_;}
110  RootTree const& runTree() const {return runTree_;}
113  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
115  bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
116  std::unique_ptr<FileBlock> createFileBlock() const;
118  return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
119  }
126 
127  void rewind() {
129  eventTree_.rewind();
130  lumiTree_.rewind();
131  runTree_.rewind();
132  }
133  void setToLastEntry() {
135  }
136 
137  bool skipEvents(int& offset);
138  bool goToEvent(EventID const& eventID);
139  bool nextEventEntry() {return eventTree_.next();}
141  std::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
143  }
144  bool wasLastEventJustRead() const;
145  bool wasFirstEventJustRead() const;
148 
149  private:
151  bool skipThisEntry();
152  void setIfFastClonable(int remainingEvents, int remainingLumis);
153  void validateFile(InputType inputType, bool usingGoToEvent);
154  void fillIndexIntoFile();
156  void fillThisEventAuxiliary();
157  void fillEventHistory();
158  std::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
159  std::shared_ptr<RunAuxiliary> fillRunAuxiliary();
160  void overrideRunNumber(RunID& id);
162  void overrideRunNumber(EventID& id, bool isRealData);
163  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
164  void dropOnInput(ProductRegistry& reg, ProductSelectorRules const& rules, bool dropDescendants, InputType inputType);
165  void readParentageTree(InputType inputType);
166  void readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType); // backward compatibility
167  void readEventHistoryTree();
168  bool isDuplicateEvent();
169 
170  void initializeDuplicateChecker(std::vector<std::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
171  std::vector<std::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
172 
173  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker(InputType inputType);
174  std::shared_ptr<ProductProvenanceRetriever> makeProductProvenanceRetriever(unsigned int iStreamIndex);
175 
180  std::shared_ptr<InputFile> filePtr_;
181  std::shared_ptr<EventSkipperByID> eventSkipperByID_;
184  std::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
186  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
190  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
191  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
192  std::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
196  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
204  std::shared_ptr<ProductRegistry const> productRegistry_;
205  std::shared_ptr<BranchIDLists const> branchIDLists_;
206  std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
209  std::map<std::string, std::string> newBranchToOldBranch_;
210  TTree* eventHistoryTree_; // backward compatibility
213  std::unique_ptr<History> history_; // backward compatibility
214  std::shared_ptr<BranchChildren> branchChildren_;
215  std::shared_ptr<DuplicateChecker> duplicateChecker_;
216  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
217  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
218  mutable std::vector<std::shared_ptr<ProductProvenanceRetriever>> eventProductProvenanceRetrievers_;
219  std::vector<ParentageID> parentageIDLookup_;
220  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
222  }; // class RootFile
223 
224 }
225 #endif
void dropOnInput(ProductRegistry &reg, ProductSelectorRules const &rules, bool dropDescendants, InputType inputType)
Definition: RootFile.cc:1668
EventID const & eventID() const
Definition: RootFile.h:107
bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.h:117
std::unique_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:216
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< 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:138
std::unique_ptr< History > history_
Definition: RootFile.h:213
InputType
Definition: InputType.h:5
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
RootTree const & lumiTree() const
Definition: RootFile.h:109
std::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:205
bool skipEvents(int &offset)
Definition: RootFile.cc:1276
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: RootFile.h:101
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:111
std::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1231
RootFile & operator=(RootFile const &)=delete
void readEntryDescriptionTree(EntryDescriptionMap &entryDescriptionMap, InputType inputType)
Definition: RootFile.cc:501
bool branchListIndexesUnchanged() const
Definition: RootFile.h:114
bool nextEventEntry()
Definition: RootFile.h:139
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1595
unsigned int EventNumber_t
Definition: EventRange.h:30
int whyNotFastClonable_
Definition: RootFile.h:195
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:209
BranchIDLists const & branchIDLists()
Definition: RootFile.h:102
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1587
void readRun_(RunPrincipal &runPrincipal)
Definition: RootFile.cc:1498
RootTree lumiTree_
Definition: RootFile.h:200
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:217
processConfiguration
Definition: Schedule.cc:368
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:207
TClass * edProductClass_
Definition: RootFile.h:221
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:189
std::unique_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:637
bool readCurrentEvent(EventPrincipal &cache)
Definition: RootFile.cc:1401
std::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:100
uint16_t size_type
unsigned int LuminosityBlockNumber_t
long long EntryNumber_t
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
bool fillEventAuxiliary(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1165
std::vector< EventSelectionID > EventSelectionIDVector
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:182
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:668
void rewind()
Definition: RootFile.h:127
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:191
void setToLastEntry()
Definition: RootFile.h:133
bool skipThisEntry()
Definition: RootFile.cc:673
FileID fid_
Definition: RootFile.h:183
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: RootFile.cc:728
std::string const logicalFile_
Definition: RootFile.h:177
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:188
void readParentageTree(InputType inputType)
Definition: RootFile.cc:547
std::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:141
bool next()
Definition: RootTree.h:87
bool noEventSort_
Definition: RootFile.h:194
bool wasLastEventJustRead() const
Definition: RootFile.cc:778
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1579
void close()
Definition: RootFile.cc:1134
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:110
bool modifiedIDs() const
Definition: RootFile.h:115
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:203
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
Definition: RootFile.h:206
std::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1434
EventAuxiliary const & eventAux() const
Definition: RootFile.h:103
EventSelectionIDVector eventSelectionIDs_
Definition: RootFile.h:211
std::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1515
int whyNotFastClonable() const
Definition: RootFile.h:112
std::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1255
bool skipAnyEvents_
Definition: RootFile.h:193
std::vector< std::shared_ptr< ProductProvenanceRetriever > > eventProductProvenanceRetrievers_
Definition: RootFile.h:218
RootTree eventTree_
Definition: RootFile.h:199
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:113
IndexIntoFile::EntryType getNextItemType(RunNumber_t &run, LuminosityBlockNumber_t &lumi, EventNumber_t &event)
Definition: RootFile.cc:733
BranchListIndexes branchListIndexes_
Definition: RootFile.h:212
bool isDuplicateEvent()
Definition: RootFile.cc:717
unsigned int offset(bool)
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:785
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:185
std::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:180
void readEvent(EventPrincipal &cache)
Definition: RootFile.cc:1378
RootTree runTree_
Definition: RootFile.h:201
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1344
std::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:181
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1429
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:196
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:178
std::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:204
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:583
std::map< EntryDescriptionID, EventEntryDescription > EntryDescriptionMap
Definition: RootFile.h:47
std::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:214
void fillEventHistory()
Definition: RootFile.cc:1175
std::shared_ptr< ProductProvenanceRetriever > makeProductProvenanceRetriever(unsigned int iStreamIndex)
Definition: RootFile.cc:1751
std::string const & file() const
Definition: RootFile.h:99
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:187
EventID const & id() const
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:57
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:220
bool branchListIndexesUnchanged_
Definition: RootFile.h:197
void fillIndexIntoFile()
Definition: RootFile.cc:847
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: RootFile.cc:1553
RootTreePtrArray treePointers_
Definition: RootFile.h:202
void initializeDuplicateChecker(std::vector< std::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< std::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1652
std::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:215
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:186
RootTreePtrArray & treePointers()
Definition: RootFile.h:150
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1608
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker(InputType inputType)
Definition: RootFile.cc:1734
unsigned int RunNumber_t
Definition: EventRange.h:32
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:219
EventAuxiliary eventAux_
Definition: RootFile.h:198
void fillThisEventAuxiliary()
Definition: RootFile.cc:1146
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1571
ProcessHistoryRegistry * processHistoryRegistry_
Definition: RootFile.h:179
void rewind()
Definition: RootTree.h:91
RootTree const & eventTree() const
Definition: RootFile.h:108
void validateFile(InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1073
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:663
std::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:184
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:654
TTree * eventHistoryTree_
Definition: RootFile.h:210
std::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:192
std::string const file_
Definition: RootFile.h:176
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:190
void readEventHistoryTree()
Definition: RootFile.cc:1639
int forcedRunOffset_
Definition: RootFile.h:208
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1120