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 BranchMapper;
37  class DaqProvenanceHelper;
38  class DuplicateChecker;
39  class EventSkipperByID;
40  class GroupSelectorRules;
41  class InputFile;
42  class ProvenanceReaderBase;
43  class ProvenanceAdaptor;
44 
46  public:
47  virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
48  };
49 
50  class RootFile {
51  public:
52  typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
53  RootFile(std::string const& fileName,
54  ProcessConfiguration const& processConfiguration,
55  std::string const& logicalFileName,
56  boost::shared_ptr<InputFile> filePtr,
57  boost::shared_ptr<EventSkipperByID> eventSkipperByID,
58  bool skipAnyEvents,
59  int remainingEvents,
60  int remainingLumis,
61  unsigned int treeCacheSize,
62  int treeMaxVirtualSize,
64  RunNumber_t const& forcedRunNumber,
65  bool noEventSort,
66  GroupSelectorRules const& groupSelectorRules,
67  InputType::InputType inputType,
68  boost::shared_ptr<DuplicateChecker> duplicateChecker,
69  bool dropDescendantsOfDroppedProducts,
70  std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
71  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
72  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
73  bool bypassVersionCheck,
74  bool labelRawDataLikeMC,
75  bool usingGoToEvent);
76  ~RootFile();
77 
78  RootFile(RootFile const&) = delete; // Disallow copying and moving
79  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
80 
81  void reportOpened(std::string const& inputType);
82  void close();
84  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
86  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
88  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
89 
90  boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
91  boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
92  boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> rpCache);
93  boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lbCache);
94  std::string const& file() const {return file_;}
95  boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
97  EventAuxiliary const& eventAux() const {return eventAux_;}
98  // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
99  // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
100  // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
101  EventID const& eventID() const {return eventAux().id();}
102  RootTree const& eventTree() const {return eventTree_;}
103  RootTree const& lumiTree() const {return lumiTree_;}
104  RootTree const& runTree() const {return runTree_;}
107  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
109  bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
110  boost::shared_ptr<FileBlock> createFileBlock() const;
112  return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
113  }
119 
120  void rewind() {
122  eventTree_.rewind();
123  lumiTree_.rewind();
124  runTree_.rewind();
125  }
126  void setToLastEntry() {
128  }
129 
130  bool skipEvents(int& offset);
131  bool goToEvent(EventID const& eventID);
132  bool nextEventEntry() {return eventTree_.next();}
134  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
136  }
137  bool wasLastEventJustRead() const;
138  bool wasFirstEventJustRead() const;
142  return *secondaryEventPrincipal_;
143  }
144 
145  private:
146  void checkReleaseVersion();
148  bool skipThisEntry();
150  void setIfFastClonable(int remainingEvents, int remainingLumis);
151  void validateFile(InputType::InputType inputType, bool usingGoToEvent);
152  void fillIndexIntoFile();
153  void fillEventAuxiliary();
154  void fillThisEventAuxiliary();
155  void fillHistory();
156  boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
157  boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
158  void overrideRunNumber(RunID& id);
160  void overrideRunNumber(EventID& id, bool isRealData);
161  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
162  void dropOnInput(ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType);
163  void readParentageTree();
165  void readEventHistoryTree();
166  bool isDuplicateEvent();
167 
168  void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
169  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
170 
171  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker() const;
172  boost::shared_ptr<BranchMapper> makeBranchMapper();
173 
174  std::string const file_;
175  std::string const logicalFile_;
178  boost::shared_ptr<InputFile> filePtr_;
179  boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
182  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
184  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
188  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
189  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
190  boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
194  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
202  boost::shared_ptr<ProductRegistry const> productRegistry_;
203  boost::shared_ptr<BranchIDListRegistry::collection_type const> branchIDLists_;
206  std::map<std::string, std::string> newBranchToOldBranch_;
207  TTree* eventHistoryTree_; // backward compatibility
208  boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
209  boost::shared_ptr<BranchListIndexes> branchListIndexes_;
210  std::unique_ptr<History> history_; // backward compatibility
211  boost::shared_ptr<BranchChildren> branchChildren_;
212  boost::shared_ptr<DuplicateChecker> duplicateChecker_;
213  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
214  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
215  mutable std::unique_ptr<EventPrincipal> secondaryEventPrincipal_;
216  mutable boost::shared_ptr<BranchMapper> eventBranchMapper_;
217  std::vector<ParentageID> parentageIDLookup_;
218  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
219  }; // class RootFile
220 
221 }
222 #endif
EventID const & eventID() const
Definition: RootFile.h:101
bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.h:111
std::unique_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:213
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:211
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:134
boost::shared_ptr< BranchListIndexes > branchListIndexes_
Definition: RootFile.h:209
std::unique_ptr< EventPrincipal > secondaryEventPrincipal_
Definition: RootFile.h:215
boost::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:190
std::unique_ptr< History > history_
Definition: RootFile.h:210
boost::shared_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:624
RootTree const & lumiTree() const
Definition: RootFile.h:103
bool skipEvents(int &offset)
Definition: RootFile.cc:1253
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:105
RootFile & operator=(RootFile const &)=delete
bool branchListIndexesUnchanged() const
Definition: RootFile.h:108
EventPrincipal * readCurrentEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1382
bool nextEventEntry()
Definition: RootFile.h:132
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1595
ProcessConfigurationVector processConfigurations_
Definition: RootFile.h:177
unsigned int EventNumber_t
Definition: EventID.h:30
void readParentageTree()
Definition: RootFile.cc:532
int whyNotFastClonable_
Definition: RootFile.h:193
void checkReleaseVersion()
Definition: RootFile.cc:1652
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:206
IndexIntoFile::EntryType getEntryTypeWithSkipping()
Definition: RootFile.cc:704
void fillEventAuxiliary()
Definition: RootFile.cc:1146
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1587
RootTree lumiTree_
Definition: RootFile.h:198
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:214
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:204
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:187
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1232
boost::shared_ptr< BranchMapper > eventBranchMapper_
Definition: RootFile.h:216
uint16_t size_type
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
long long EntryNumber_t
EventPrincipal * readEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1359
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:180
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:655
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
EventPrincipal * clearAndReadCurrentEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1410
void rewind()
Definition: RootFile.h:120
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:189
void setToLastEntry()
Definition: RootFile.h:126
bool skipThisEntry()
Definition: RootFile.cc:660
IndexIntoFile::EntryType getNextEntryTypeWanted()
Definition: RootFile.cc:731
tuple InputFile
Open Root file and provide MEs ############.
FileID fid_
Definition: RootFile.h:181
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:212
std::string const logicalFile_
Definition: RootFile.h:175
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:186
bool next()
Definition: RootTree.h:79
bool noEventSort_
Definition: RootFile.h:192
bool wasLastEventJustRead() const
Definition: RootFile.cc:756
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1579
void close()
Definition: RootFile.cc:1115
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:104
bool modifiedIDs() const
Definition: RootFile.h:109
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:201
BranchIDListRegistry::collection_type const & branchIDLists()
Definition: RootFile.h:96
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
EventAuxiliary const & eventAux() const
Definition: RootFile.h:97
int whyNotFastClonable() const
Definition: RootFile.h:106
bool skipAnyEvents_
Definition: RootFile.h:191
RootTree eventTree_
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, GroupSelectorRules const &groupSelectorRules, InputType::InputType inputType, 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 bypassVersionCheck, bool labelRawDataLikeMC, bool usingGoToEvent)
Definition: RootFile.cc:122
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:107
void fillHistory()
Definition: RootFile.cc:1152
bool isDuplicateEvent()
Definition: RootFile.cc:720
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:763
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
Definition: RootFile.h:208
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:183
RootTree runTree_
Definition: RootFile.h:199
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1324
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1417
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:194
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:182
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:176
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:570
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker() const
Definition: RootFile.cc:1748
void readEntryDescriptionTree()
Definition: RootFile.cc:486
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1208
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1509
void dropOnInput(ProductRegistry &reg, GroupSelectorRules const &rules, bool dropDescendants, InputType::InputType inputType)
Definition: RootFile.cc:1683
std::string const & file() const
Definition: RootFile.h:94
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:185
EventID const & id() const
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:52
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:218
bool branchListIndexesUnchanged_
Definition: RootFile.h:195
void fillIndexIntoFile()
Definition: RootFile.cc:826
author Stefano ARGIRO author Bill Tanenbaum
EventPrincipal & secondaryEventPrincipal()
Definition: RootFile.h:141
RootTreePtrArray treePointers_
Definition: RootFile.h:200
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:202
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:184
RootTreePtrArray & treePointers()
Definition: RootFile.h:147
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1608
boost::shared_ptr< BranchMapper > makeBranchMapper()
Definition: RootFile.cc:1761
boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > rpCache)
Definition: RootFile.cc:1492
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:178
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1667
unsigned int RunNumber_t
Definition: EventRange.h:32
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:217
EventAuxiliary eventAux_
Definition: RootFile.h:196
void fillThisEventAuxiliary()
Definition: RootFile.cc:1127
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1571
boost::shared_ptr< BranchIDListRegistry::collection_type const > branchIDLists_
Definition: RootFile.h:203
void rewind()
Definition: RootTree.h:82
RootTree const & eventTree() const
Definition: RootFile.h:102
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:650
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:641
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:179
TTree * eventHistoryTree_
Definition: RootFile.h:207
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:95
void validateFile(InputType::InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1052
std::string const file_
Definition: RootFile.h:174
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1422
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:188
void readEventHistoryTree()
Definition: RootFile.cc:1639
int forcedRunOffset_
Definition: RootFile.h:205
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1101
boost::shared_ptr< LuminosityBlockPrincipal > readLumi(boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
Definition: RootFile.cc:1553