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 labelRawDataLikeMC,
74  bool usingGoToEvent);
75  ~RootFile();
76 
77  RootFile(RootFile const&) = delete; // Disallow copying and moving
78  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
79 
80  void reportOpened(std::string const& inputType);
81  void close();
83  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
85  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
87  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
88 
89  boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
90  boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
91  boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> rpCache);
92  boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lbCache);
93  std::string const& file() const {return file_;}
94  boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
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  boost::shared_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;
141  return *secondaryEventPrincipal_;
142  }
143 
144  private:
145  void checkReleaseVersion();
147  bool skipThisEntry();
149  void setIfFastClonable(int remainingEvents, int remainingLumis);
150  void validateFile(InputType::InputType inputType, bool usingGoToEvent);
151  void fillIndexIntoFile();
152  void fillEventAuxiliary();
153  void fillThisEventAuxiliary();
154  void fillHistory();
155  boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
156  boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
157  void overrideRunNumber(RunID& id);
159  void overrideRunNumber(EventID& id, bool isRealData);
160  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
161  void dropOnInput(ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType);
162  void readParentageTree();
164  void readEventHistoryTree();
165  bool isDuplicateEvent();
166 
167  void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
168  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
169 
170  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker() const;
171  boost::shared_ptr<BranchMapper> makeBranchMapper();
172 
173  std::string const file_;
174  std::string const logicalFile_;
177  boost::shared_ptr<InputFile> filePtr_;
178  boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
181  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
183  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
187  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
188  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
189  boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
193  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
201  boost::shared_ptr<ProductRegistry const> productRegistry_;
202  boost::shared_ptr<BranchIDListRegistry::collection_type const> branchIDLists_;
205  std::map<std::string, std::string> newBranchToOldBranch_;
206  TTree* eventHistoryTree_; // backward compatibility
207  boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
208  boost::shared_ptr<BranchListIndexes> branchListIndexes_;
209  std::unique_ptr<History> history_; // backward compatibility
210  boost::shared_ptr<BranchChildren> branchChildren_;
211  boost::shared_ptr<DuplicateChecker> duplicateChecker_;
212  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
213  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
214  mutable std::unique_ptr<EventPrincipal> secondaryEventPrincipal_;
215  mutable boost::shared_ptr<BranchMapper> eventBranchMapper_;
216  std::vector<ParentageID> parentageIDLookup_;
217  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
218  }; // class RootFile
219 
220 }
221 #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:212
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:210
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:133
boost::shared_ptr< BranchListIndexes > branchListIndexes_
Definition: RootFile.h:208
std::unique_ptr< EventPrincipal > secondaryEventPrincipal_
Definition: RootFile.h:214
boost::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:189
std::unique_ptr< History > history_
Definition: RootFile.h:209
boost::shared_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:621
RootTree const & lumiTree() const
Definition: RootFile.h:102
bool skipEvents(int &offset)
Definition: RootFile.cc:1250
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:104
RootFile & operator=(RootFile const &)=delete
bool branchListIndexesUnchanged() const
Definition: RootFile.h:107
EventPrincipal * readCurrentEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1379
bool nextEventEntry()
Definition: RootFile.h:131
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1592
ProcessConfigurationVector processConfigurations_
Definition: RootFile.h:176
unsigned int EventNumber_t
Definition: EventID.h:30
void readParentageTree()
Definition: RootFile.cc:529
int whyNotFastClonable_
Definition: RootFile.h:192
void checkReleaseVersion()
Definition: RootFile.cc:1649
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:205
IndexIntoFile::EntryType getEntryTypeWithSkipping()
Definition: RootFile.cc:701
void fillEventAuxiliary()
Definition: RootFile.cc:1143
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1584
RootTree lumiTree_
Definition: RootFile.h:197
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:213
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:203
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:186
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1229
boost::shared_ptr< BranchMapper > eventBranchMapper_
Definition: RootFile.h:215
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
EventPrincipal * readEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1356
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:179
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 labelRawDataLikeMC, bool usingGoToEvent)
Definition: RootFile.cc:122
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:652
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
EventPrincipal * clearAndReadCurrentEvent(EventPrincipal &cache, boost::shared_ptr< LuminosityBlockPrincipal > lb=boost::shared_ptr< LuminosityBlockPrincipal >())
Definition: RootFile.cc:1407
void rewind()
Definition: RootFile.h:119
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:188
void setToLastEntry()
Definition: RootFile.h:125
bool skipThisEntry()
Definition: RootFile.cc:657
IndexIntoFile::EntryType getNextEntryTypeWanted()
Definition: RootFile.cc:728
tuple InputFile
Open Root file and provide MEs ############.
FileID fid_
Definition: RootFile.h:180
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:211
std::string const logicalFile_
Definition: RootFile.h:174
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:185
bool next()
Definition: RootTree.h:79
bool noEventSort_
Definition: RootFile.h:191
bool wasLastEventJustRead() const
Definition: RootFile.cc:753
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1576
void close()
Definition: RootFile.cc:1112
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:103
bool modifiedIDs() const
Definition: RootFile.h:108
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:200
BranchIDListRegistry::collection_type const & branchIDLists()
Definition: RootFile.h:95
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:190
RootTree eventTree_
Definition: RootFile.h:196
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:106
void fillHistory()
Definition: RootFile.cc:1149
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:760
boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs_
Definition: RootFile.h:207
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:182
RootTree runTree_
Definition: RootFile.h:198
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1321
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1414
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:193
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:181
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:175
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:567
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker() const
Definition: RootFile.cc:1745
void readEntryDescriptionTree()
Definition: RootFile.cc:483
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1205
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1506
void dropOnInput(ProductRegistry &reg, GroupSelectorRules const &rules, bool dropDescendants, InputType::InputType inputType)
Definition: RootFile.cc:1680
std::string const & file() const
Definition: RootFile.h:93
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:184
EventID const & id() const
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:52
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:217
bool branchListIndexesUnchanged_
Definition: RootFile.h:194
void fillIndexIntoFile()
Definition: RootFile.cc:823
author Stefano ARGIRO author Bill Tanenbaum
EventPrincipal & secondaryEventPrincipal()
Definition: RootFile.h:140
RootTreePtrArray treePointers_
Definition: RootFile.h:199
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:201
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:183
RootTreePtrArray & treePointers()
Definition: RootFile.h:146
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1605
boost::shared_ptr< BranchMapper > makeBranchMapper()
Definition: RootFile.cc:1758
boost::shared_ptr< RunPrincipal > readRun_(boost::shared_ptr< RunPrincipal > rpCache)
Definition: RootFile.cc:1489
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:177
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1664
unsigned int RunNumber_t
Definition: EventRange.h:32
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:216
EventAuxiliary eventAux_
Definition: RootFile.h:195
void fillThisEventAuxiliary()
Definition: RootFile.cc:1124
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1568
boost::shared_ptr< BranchIDListRegistry::collection_type const > branchIDLists_
Definition: RootFile.h:202
void rewind()
Definition: RootTree.h:82
RootTree const & eventTree() const
Definition: RootFile.h:101
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:647
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:638
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:178
TTree * eventHistoryTree_
Definition: RootFile.h:206
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:94
void validateFile(InputType::InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1049
std::string const file_
Definition: RootFile.h:173
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1419
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:187
void readEventHistoryTree()
Definition: RootFile.cc:1636
int forcedRunOffset_
Definition: RootFile.h:204
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1098
boost::shared_ptr< LuminosityBlockPrincipal > readLumi(boost::shared_ptr< LuminosityBlockPrincipal > lbCache)
Definition: RootFile.cc:1550