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  boost::shared_ptr<InputFile> filePtr,
62  boost::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  boost::shared_ptr<BranchIDListHelper> branchIDListHelper,
75  boost::shared_ptr<DuplicateChecker> duplicateChecker,
76  bool dropDescendantsOfDroppedProducts,
77  ProcessHistoryRegistry& processHistoryRegistry,
78  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
79  std::vector<boost::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  boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
96  boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
97  void readRun_(RunPrincipal& runPrincipal);
99  std::string const& file() const {return file_;}
100  boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
101  boost::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  boost::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  boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
159  boost::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<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
171  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
172 
173  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker(InputType inputType);
174  boost::shared_ptr<ProductProvenanceRetriever> makeProductProvenanceRetriever(unsigned int iStreamIndex);
175 
180  boost::shared_ptr<InputFile> filePtr_;
181  boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
184  boost::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  boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
196  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
204  boost::shared_ptr<ProductRegistry const> productRegistry_;
205  boost::shared_ptr<BranchIDLists const> branchIDLists_;
206  boost::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  boost::shared_ptr<BranchChildren> branchChildren_;
215  boost::shared_ptr<DuplicateChecker> duplicateChecker_;
216  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
217  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
218  mutable std::vector<boost::shared_ptr<ProductProvenanceRetriever>> eventProductProvenanceRetrievers_;
219  std::vector<ParentageID> parentageIDLookup_;
220  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
221  }; // class RootFile
222 
223 }
224 #endif
void dropOnInput(ProductRegistry &reg, ProductSelectorRules const &rules, bool dropDescendants, InputType inputType)
Definition: RootFile.cc:1667
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
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:214
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:141
boost::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:192
std::unique_ptr< History > history_
Definition: RootFile.h:213
InputType
Definition: InputType.h:5
boost::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: RootFile.h:101
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
RootTree const & lumiTree() const
Definition: RootFile.h:109
bool skipEvents(int &offset)
Definition: RootFile.cc:1275
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:111
RootFile & operator=(RootFile const &)=delete
void readEntryDescriptionTree(EntryDescriptionMap &entryDescriptionMap, InputType inputType)
Definition: RootFile.cc:500
bool branchListIndexesUnchanged() const
Definition: RootFile.h:114
bool nextEventEntry()
Definition: RootFile.h:139
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1594
unsigned int EventNumber_t
Definition: EventID.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:1586
void readRun_(RunPrincipal &runPrincipal)
Definition: RootFile.cc:1497
RootTree lumiTree_
Definition: RootFile.h:200
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:217
processConfiguration
Definition: Schedule.cc:369
boost::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:205
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:207
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:189
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1254
std::unique_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:636
bool readCurrentEvent(EventPrincipal &cache)
Definition: RootFile.cc:1400
uint16_t size_type
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
long long EntryNumber_t
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
bool fillEventAuxiliary(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1164
std::vector< EventSelectionID > EventSelectionIDVector
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:182
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:667
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:672
FileID fid_
Definition: RootFile.h:183
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:215
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: RootFile.cc:727
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:546
bool next()
Definition: RootTree.h:85
bool noEventSort_
Definition: RootFile.h:194
bool wasLastEventJustRead() const
Definition: RootFile.cc:777
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1578
void close()
Definition: RootFile.cc:1133
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:110
boost::shared_ptr< BranchIDListHelper > branchIDListHelper_
Definition: RootFile.h:206
bool modifiedIDs() const
Definition: RootFile.h:115
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:203
EventAuxiliary const & eventAux() const
Definition: RootFile.h:103
EventSelectionIDVector eventSelectionIDs_
Definition: RootFile.h:211
int whyNotFastClonable() const
Definition: RootFile.h:112
bool skipAnyEvents_
Definition: RootFile.h:193
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:732
BranchListIndexes branchListIndexes_
Definition: RootFile.h:212
bool isDuplicateEvent()
Definition: RootFile.cc:716
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
std::vector< boost::shared_ptr< ProductProvenanceRetriever > > eventProductProvenanceRetrievers_
Definition: RootFile.h:218
bool wasFirstEventJustRead() const
Definition: RootFile.cc:784
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:185
void readEvent(EventPrincipal &cache)
Definition: RootFile.cc:1377
RootTree runTree_
Definition: RootFile.h:201
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1343
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1428
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:196
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:184
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:178
RootFile(std::string const &fileName, ProcessConfiguration const &processConfiguration, std::string const &logicalFileName, boost::shared_ptr< InputFile > filePtr, boost::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, boost::shared_ptr< BranchIDListHelper > branchIDListHelper, boost::shared_ptr< DuplicateChecker > duplicateChecker, bool dropDescendantsOfDroppedProducts, ProcessHistoryRegistry &processHistoryRegistry, std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool bypassVersionCheck, bool labelRawDataLikeMC, bool usingGoToEvent, bool enablePrefetching)
Definition: RootFile.cc:138
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:582
std::map< EntryDescriptionID, EventEntryDescription > EntryDescriptionMap
Definition: RootFile.h:47
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1230
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1514
void fillEventHistory()
Definition: RootFile.cc:1174
boost::shared_ptr< ProductProvenanceRetriever > makeProductProvenanceRetriever(unsigned int iStreamIndex)
Definition: RootFile.cc:1748
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:846
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: RootFile.cc:1552
RootTreePtrArray treePointers_
Definition: RootFile.h:202
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:204
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:186
RootTreePtrArray & treePointers()
Definition: RootFile.h:150
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1607
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker(InputType inputType)
Definition: RootFile.cc:1731
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:180
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1651
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:1145
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1570
ProcessHistoryRegistry * processHistoryRegistry_
Definition: RootFile.h:179
void rewind()
Definition: RootTree.h:89
RootTree const & eventTree() const
Definition: RootFile.h:108
void validateFile(InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1072
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:662
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:653
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:181
TTree * eventHistoryTree_
Definition: RootFile.h:210
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:100
std::string const file_
Definition: RootFile.h:176
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1433
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:190
void readEventHistoryTree()
Definition: RootFile.cc:1638
int forcedRunOffset_
Definition: RootFile.h:208
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1119