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 "InputType.h"
11 #include "RootTree.h"
16 #include "DataFormats/Provenance/interface/EventProcessHistoryID.h" // backward compatibility
24 
25 #include <array>
26 #include <map>
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 namespace edm {
32 
33  //------------------------------------------------------------
34  // Class RootFile: supports file reading.
35 
36  class BranchIDListHelper;
37  class BranchMapper;
38  class DaqProvenanceHelper;
39  class DuplicateChecker;
40  class EventSkipperByID;
41  class ProductSelectorRules;
42  class InputFile;
43  class ProvenanceReaderBase;
44  class ProvenanceAdaptor;
45 
47  public:
48  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
49  };
50 
51  class RootFile {
52  public:
53  typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
55  ProcessConfiguration const& processConfiguration,
56  std::string const& logicalFileName,
57  boost::shared_ptr<InputFile> filePtr,
58  boost::shared_ptr<EventSkipperByID> eventSkipperByID,
59  bool skipAnyEvents,
60  int remainingEvents,
61  int remainingLumis,
62  unsigned int treeCacheSize,
63  int treeMaxVirtualSize,
65  RunNumber_t const& forcedRunNumber,
66  bool noEventSort,
67  ProductSelectorRules const& productSelectorRules,
68  InputType::InputType inputType,
69  boost::shared_ptr<BranchIDListHelper> branchIDListHelper,
70  boost::shared_ptr<DuplicateChecker> duplicateChecker,
71  bool dropDescendantsOfDroppedProducts,
72  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
73  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
74  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
75  bool labelRawDataLikeMC,
76  bool usingGoToEvent,
77  bool enablePrefetching);
78  ~RootFile();
79 
80  RootFile(RootFile const&) = delete; // Disallow copying and moving
81  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
82 
83  void reportOpened(std::string const& inputType);
84  void close();
87 
88  boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
89  boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
90  boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> runPrincipal);
91  boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal);
92  std::string const& file() const {return file_;}
93  boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
94  boost::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return branchIDListHelper_;}
96  EventAuxiliary const& eventAux() const {return eventAux_;}
97  // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
98  // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
99  // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
100  EventID const& eventID() const {return eventAux().id();}
101  RootTree const& eventTree() const {return eventTree_;}
102  RootTree const& lumiTree() const {return lumiTree_;}
103  RootTree const& runTree() const {return runTree_;}
106  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
108  bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
109  std::unique_ptr<FileBlock> createFileBlock() const;
111  return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
112  }
118 
119  void rewind() {
121  eventTree_.rewind();
122  lumiTree_.rewind();
123  runTree_.rewind();
124  }
125  void setToLastEntry() {
127  }
128 
129  bool skipEvents(int& offset);
130  bool goToEvent(EventID const& eventID);
131  bool nextEventEntry() {return eventTree_.next();}
133  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
135  }
136  bool wasLastEventJustRead() const;
137  bool wasFirstEventJustRead() const;
140 
141  private:
142  void checkReleaseVersion();
144  bool skipThisEntry();
146  void setIfFastClonable(int remainingEvents, int remainingLumis);
147  void validateFile(InputType::InputType inputType, bool usingGoToEvent);
148  void fillIndexIntoFile();
149  void fillEventAuxiliary();
150  void fillThisEventAuxiliary();
151  void fillHistory();
152  boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
153  boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
154  void overrideRunNumber(RunID& id);
156  void overrideRunNumber(EventID& id, bool isRealData);
157  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
158  void dropOnInput(ProductRegistry& reg, ProductSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType);
159  void readParentageTree();
161  void readEventHistoryTree();
162  bool isDuplicateEvent();
163 
164  void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
165  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
166 
167  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker() const;
168  boost::shared_ptr<BranchMapper> makeBranchMapper();
169 
174  boost::shared_ptr<InputFile> filePtr_;
175  boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
178  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
180  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
184  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
185  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
186  boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
190  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
198  boost::shared_ptr<ProductRegistry const> productRegistry_;
199  boost::shared_ptr<BranchIDLists const> branchIDLists_;
200  boost::shared_ptr<BranchIDListHelper> branchIDListHelper_;
203  std::map<std::string, std::string> newBranchToOldBranch_;
204  TTree* eventHistoryTree_; // backward compatibility
205  boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
206  boost::shared_ptr<BranchListIndexes> branchListIndexes_;
207  std::unique_ptr<History> history_; // backward compatibility
208  boost::shared_ptr<BranchChildren> branchChildren_;
209  boost::shared_ptr<DuplicateChecker> duplicateChecker_;
210  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
211  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
212  mutable boost::shared_ptr<BranchMapper> eventBranchMapper_;
213  std::vector<ParentageID> parentageIDLookup_;
214  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
215  }; // class RootFile
216 
217 }
218 #endif
EventID const & eventID() const
Definition: RootFile.h:100
bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.h:110
std::unique_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:210
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:208
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:133
boost::shared_ptr< BranchListIndexes > branchListIndexes_
Definition: RootFile.h:206
boost::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:186
std::unique_ptr< History > history_
Definition: RootFile.h:207
boost::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: RootFile.h:94
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
RootTree const & lumiTree() const
Definition: RootFile.h:102
bool skipEvents(int &offset)
Definition: RootFile.cc:1242
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:104
RootFile & operator=(RootFile const &)=delete
bool branchListIndexesUnchanged() const
Definition: RootFile.h:107
bool nextEventEntry()
Definition: RootFile.h:131
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1575
ProcessConfigurationVector processConfigurations_
Definition: RootFile.h:173
unsigned int EventNumber_t
Definition: EventID.h:30
void readParentageTree()
Definition: RootFile.cc:522
int whyNotFastClonable_
Definition: RootFile.h:189
void checkReleaseVersion()
Definition: RootFile.cc:1632
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:203
IndexIntoFile::EntryType getEntryTypeWithSkipping()
Definition: RootFile.cc:695
void fillEventAuxiliary()
Definition: RootFile.cc:1135
BranchIDLists const & branchIDLists()
Definition: RootFile.h:95
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1567
RootTree lumiTree_
Definition: RootFile.h:194
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:211
boost::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:199
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:201
boost::shared_ptr< LuminosityBlockPrincipal > readLumi(boost::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal)
Definition: RootFile.cc:1533
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:183
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1221
boost::shared_ptr< BranchMapper > eventBranchMapper_
Definition: RootFile.h:212
std::unique_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:614
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
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:176
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:646
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
void rewind()
Definition: RootFile.h:119
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:185
void setToLastEntry()
Definition: RootFile.h:125
bool skipThisEntry()
Definition: RootFile.cc:651
IndexIntoFile::EntryType getNextEntryTypeWanted()
Definition: RootFile.cc:722
tuple InputFile
Open Root file and provide MEs ############.
FileID fid_
Definition: RootFile.h:177
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:209
std::string const logicalFile_
Definition: RootFile.h:171
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:182
bool next()
Definition: RootTree.h:81
bool noEventSort_
Definition: RootFile.h:188
bool wasLastEventJustRead() const
Definition: RootFile.cc:747
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1559
void close()
Definition: RootFile.cc:1104
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:103
boost::shared_ptr< BranchIDListHelper > branchIDListHelper_
Definition: RootFile.h:200
bool modifiedIDs() const
Definition: RootFile.h:108
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:197
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 treeCacheSize, int treeMaxVirtualSize, InputSource::ProcessingMode processingMode, RunNumber_t const &forcedRunNumber, bool noEventSort, ProductSelectorRules const &productSelectorRules, InputType::InputType inputType, boost::shared_ptr< BranchIDListHelper > branchIDListHelper, boost::shared_ptr< DuplicateChecker > duplicateChecker, bool dropDescendantsOfDroppedProducts, std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile, std::vector< ProcessHistoryID > &orderedProcessHistoryIDs, bool labelRawDataLikeMC, bool usingGoToEvent, bool enablePrefetching)
Definition: RootFile.cc:121
EventPrincipal * readEvent(EventPrincipal &cache)
Definition: RootFile.cc:1348
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
EventAuxiliary const & eventAux() const
Definition: RootFile.h:96
int whyNotFastClonable() const
Definition: RootFile.h:105
bool skipAnyEvents_
Definition: RootFile.h:187
RootTree eventTree_
Definition: RootFile.h:193
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:106
void fillHistory()
Definition: RootFile.cc:1141
bool isDuplicateEvent()
Definition: RootFile.cc:711
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:754
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
Definition: RootFile.h:205
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:179
RootTree runTree_
Definition: RootFile.h:195
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1313
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1397
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:190
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:178
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:172
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:560
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker() const
Definition: RootFile.cc:1726
void readEntryDescriptionTree()
Definition: RootFile.cc:476
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1197
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1489
std::string const & file() const
Definition: RootFile.h:92
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:181
boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > runPrincipal)
Definition: RootFile.cc:1472
EventID const & id() const
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:53
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:214
bool branchListIndexesUnchanged_
Definition: RootFile.h:191
void fillIndexIntoFile()
Definition: RootFile.cc:817
RootTreePtrArray treePointers_
Definition: RootFile.h:196
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:198
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:180
RootTreePtrArray & treePointers()
Definition: RootFile.h:143
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1588
boost::shared_ptr< BranchMapper > makeBranchMapper()
Definition: RootFile.cc:1739
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:174
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1646
unsigned int RunNumber_t
Definition: EventRange.h:32
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:213
EventAuxiliary eventAux_
Definition: RootFile.h:192
void fillThisEventAuxiliary()
Definition: RootFile.cc:1116
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1551
EventPrincipal * readCurrentEvent(EventPrincipal &cache)
Definition: RootFile.cc:1371
void rewind()
Definition: RootTree.h:84
RootTree const & eventTree() const
Definition: RootFile.h:101
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:641
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:632
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:175
TTree * eventHistoryTree_
Definition: RootFile.h:204
void dropOnInput(ProductRegistry &reg, ProductSelectorRules const &rules, bool dropDescendants, InputType::InputType inputType)
Definition: RootFile.cc:1662
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:93
void validateFile(InputType::InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1043
std::string const file_
Definition: RootFile.h:170
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1402
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:184
void readEventHistoryTree()
Definition: RootFile.cc:1619
int forcedRunOffset_
Definition: RootFile.h:202
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1090