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 labelRawDataLikeMC,
82  bool usingGoToEvent,
83  bool enablePrefetching);
84  ~RootFile();
85 
86  RootFile(RootFile const&) = delete; // Disallow copying and moving
87  RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
88 
89  void reportOpened(std::string const& inputType);
90  void close();
91  bool readCurrentEvent(EventPrincipal& cache);
92  void readEvent(EventPrincipal& cache);
93 
94  boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
95  boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
96  void readRun_(RunPrincipal& runPrincipal);
98  std::string const& file() const {return file_;}
99  boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
100  boost::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return branchIDListHelper_;}
102  EventAuxiliary const& eventAux() const {return eventAux_;}
103  // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
104  // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
105  // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
106  EventID const& eventID() const {return eventAux().id();}
107  RootTree const& eventTree() const {return eventTree_;}
108  RootTree const& lumiTree() const {return lumiTree_;}
109  RootTree const& runTree() const {return runTree_;}
112  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
114  bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
115  std::unique_ptr<FileBlock> createFileBlock() const;
117  return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
118  }
125 
126  void rewind() {
128  eventTree_.rewind();
129  lumiTree_.rewind();
130  runTree_.rewind();
131  }
132  void setToLastEntry() {
134  }
135 
136  bool skipEvents(int& offset);
137  bool goToEvent(EventID const& eventID);
138  bool nextEventEntry() {return eventTree_.next();}
140  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
142  }
143  bool wasLastEventJustRead() const;
144  bool wasFirstEventJustRead() const;
147 
148  private:
150  bool skipThisEntry();
151  void setIfFastClonable(int remainingEvents, int remainingLumis);
152  void validateFile(InputType inputType, bool usingGoToEvent);
153  void fillIndexIntoFile();
155  void fillThisEventAuxiliary();
156  void fillEventHistory();
157  boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
158  boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
159  void overrideRunNumber(RunID& id);
161  void overrideRunNumber(EventID& id, bool isRealData);
162  std::string const& newBranchToOldBranch(std::string const& newBranch) const;
163  void dropOnInput(ProductRegistry& reg, ProductSelectorRules const& rules, bool dropDescendants, InputType inputType);
164  void readParentageTree(InputType inputType);
165  void readEntryDescriptionTree(EntryDescriptionMap& entryDescriptionMap, InputType inputType); // backward compatibility
166  void readEventHistoryTree();
167  bool isDuplicateEvent();
168 
169  void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
170  std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
171 
172  std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker(InputType inputType);
173  boost::shared_ptr<ProductProvenanceRetriever> makeProductProvenanceRetriever();
174 
179  boost::shared_ptr<InputFile> filePtr_;
180  boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
183  boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
185  std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
189  std::vector<EventProcessHistoryID> eventProcessHistoryIDs_; // backward compatibility
190  std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
191  boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
195  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
203  boost::shared_ptr<ProductRegistry const> productRegistry_;
204  boost::shared_ptr<BranchIDLists const> branchIDLists_;
205  boost::shared_ptr<BranchIDListHelper> branchIDListHelper_;
208  std::map<std::string, std::string> newBranchToOldBranch_;
209  TTree* eventHistoryTree_; // backward compatibility
212  std::unique_ptr<History> history_; // backward compatibility
213  boost::shared_ptr<BranchChildren> branchChildren_;
214  boost::shared_ptr<DuplicateChecker> duplicateChecker_;
215  std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
216  std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
217  mutable boost::shared_ptr<ProductProvenanceRetriever> eventProductProvenanceRetriever_;
218  std::vector<ParentageID> parentageIDLookup_;
219  std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
220  }; // class RootFile
221 
222 }
223 #endif
void dropOnInput(ProductRegistry &reg, ProductSelectorRules const &rules, bool dropDescendants, InputType inputType)
Definition: RootFile.cc:1663
EventID const & eventID() const
Definition: RootFile.h:106
bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.h:116
std::unique_ptr< ProvenanceAdaptor > provenanceAdaptor_
Definition: RootFile.h:215
boost::shared_ptr< BranchChildren > branchChildren_
Definition: RootFile.h:213
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr() const
Definition: RootFile.h:140
boost::shared_ptr< RunAuxiliary > savedRunAuxiliary_
Definition: RootFile.h:191
std::unique_ptr< History > history_
Definition: RootFile.h:212
InputType
Definition: InputType.h:5
boost::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: RootFile.h:100
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
RootTree const & lumiTree() const
Definition: RootFile.h:108
bool skipEvents(int &offset)
Definition: RootFile.cc:1271
FileFormatVersion fileFormatVersion() const
Definition: RootFile.h:110
RootFile & operator=(RootFile const &)=delete
void readEntryDescriptionTree(EntryDescriptionMap &entryDescriptionMap, InputType inputType)
Definition: RootFile.cc:495
bool branchListIndexesUnchanged() const
Definition: RootFile.h:113
bool nextEventEntry()
Definition: RootFile.h:138
bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1590
unsigned int EventNumber_t
Definition: EventID.h:30
int whyNotFastClonable_
Definition: RootFile.h:194
tuple lumi
Definition: fjr2json.py:35
std::map< std::string, std::string > newBranchToOldBranch_
Definition: RootFile.h:208
BranchIDLists const & branchIDLists()
Definition: RootFile.h:101
bool setEntryAtRun(RunNumber_t run)
Definition: RootFile.cc:1582
void readRun_(RunPrincipal &runPrincipal)
Definition: RootFile.cc:1493
RootTree lumiTree_
Definition: RootFile.h:199
std::unique_ptr< MakeProvenanceReader > provenanceReaderMaker_
Definition: RootFile.h:216
processConfiguration
Definition: Schedule.cc:362
boost::shared_ptr< BranchIDLists const > branchIDLists_
Definition: RootFile.h:204
InputSource::ProcessingMode processingMode_
Definition: RootFile.h:206
IndexIntoFile::IndexIntoFileItr indexIntoFileIter_
Definition: RootFile.h:188
boost::shared_ptr< RunAuxiliary > fillRunAuxiliary()
Definition: RootFile.cc:1250
std::unique_ptr< FileBlock > createFileBlock() const
Definition: RootFile.cc:631
bool readCurrentEvent(EventPrincipal &cache)
Definition: RootFile.cc:1396
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:1160
std::vector< EventSelectionID > EventSelectionIDVector
FileFormatVersion fileFormatVersion_
Definition: RootFile.h:181
void setPosition(IndexIntoFile::IndexIntoFileItr const &position)
Definition: RootFile.cc:663
void rewind()
Definition: RootFile.h:126
std::vector< EventProcessHistoryID >::const_iterator eventProcessHistoryIter_
Definition: RootFile.h:190
void setToLastEntry()
Definition: RootFile.h:132
bool skipThisEntry()
Definition: RootFile.cc:668
tuple InputFile
Open Root file and provide MEs ############.
FileID fid_
Definition: RootFile.h:182
boost::shared_ptr< DuplicateChecker > duplicateChecker_
Definition: RootFile.h:214
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: RootFile.cc:723
std::string const logicalFile_
Definition: RootFile.h:176
std::vector< BranchListIndex > BranchListIndexes
IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_
Definition: RootFile.h:187
void readParentageTree(InputType inputType)
Definition: RootFile.cc:541
bool next()
Definition: RootTree.h:85
bool noEventSort_
Definition: RootFile.h:193
bool wasLastEventJustRead() const
Definition: RootFile.cc:773
bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi)
Definition: RootFile.cc:1574
void close()
Definition: RootFile.cc:1129
virtual std::unique_ptr< ProvenanceReaderBase > makeReader(RootTree &eventTree, DaqProvenanceHelper const *daqProvenanceHelper) const =0
RootTree const & runTree() const
Definition: RootFile.h:109
boost::shared_ptr< BranchIDListHelper > branchIDListHelper_
Definition: RootFile.h:205
bool modifiedIDs() const
Definition: RootFile.h:114
IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_
Definition: RootFile.h:202
EventAuxiliary const & eventAux() const
Definition: RootFile.h:102
EventSelectionIDVector eventSelectionIDs_
Definition: RootFile.h:210
int whyNotFastClonable() const
Definition: RootFile.h:111
bool skipAnyEvents_
Definition: RootFile.h:192
RootTree eventTree_
Definition: RootFile.h:198
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: RootFile.h:112
IndexIntoFile::EntryType getNextItemType(RunNumber_t &run, LuminosityBlockNumber_t &lumi, EventNumber_t &event)
Definition: RootFile.cc:728
BranchListIndexes branchListIndexes_
Definition: RootFile.h:211
bool isDuplicateEvent()
Definition: RootFile.cc:712
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:780
IndexIntoFile & indexIntoFile_
Definition: RootFile.h:184
boost::shared_ptr< ProductProvenanceRetriever > eventProductProvenanceRetriever_
Definition: RootFile.h:217
void readEvent(EventPrincipal &cache)
Definition: RootFile.cc:1373
RootTree runTree_
Definition: RootFile.h:200
bool goToEvent(EventID const &eventID)
Definition: RootFile.cc:1339
void setAtEventEntry(IndexIntoFile::EntryNumber_t entry)
Definition: RootFile.cc:1424
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: RootFile.h:195
boost::shared_ptr< IndexIntoFile > indexIntoFileSharedPtr_
Definition: RootFile.h:183
ProcessConfiguration const & processConfiguration_
Definition: RootFile.h:177
boost::shared_ptr< ProductProvenanceRetriever > makeProductProvenanceRetriever()
Definition: RootFile.cc:1744
void setIfFastClonable(int remainingEvents, int remainingLumis)
Definition: RootFile.cc:577
std::map< EntryDescriptionID, EventEntryDescription > EntryDescriptionMap
Definition: RootFile.h:47
boost::shared_ptr< LuminosityBlockAuxiliary > fillLumiAuxiliary()
Definition: RootFile.cc:1226
boost::shared_ptr< LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
Definition: RootFile.cc:1510
void fillEventHistory()
Definition: RootFile.cc:1170
std::string const & file() const
Definition: RootFile.h:98
IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_
Definition: RootFile.h:186
EventID const & id() const
std::array< RootTree *, NumBranchTypes > RootTreePtrArray
Definition: RootFile.h:57
std::unique_ptr< DaqProvenanceHelper > daqProvenanceHelper_
Definition: RootFile.h:219
bool branchListIndexesUnchanged_
Definition: RootFile.h:196
void fillIndexIntoFile()
Definition: RootFile.cc:842
void readLuminosityBlock_(LuminosityBlockPrincipal &lumiPrincipal)
Definition: RootFile.cc:1548
RootTreePtrArray treePointers_
Definition: RootFile.h:201
boost::shared_ptr< ProductRegistry const > productRegistry_
Definition: RootFile.h:203
std::vector< ProcessHistoryID > & orderedProcessHistoryIDs_
Definition: RootFile.h:185
RootTreePtrArray & treePointers()
Definition: RootFile.h:149
void overrideRunNumber(RunID &id)
Definition: RootFile.cc:1603
std::unique_ptr< MakeProvenanceReader > makeProvenanceReaderMaker(InputType inputType)
Definition: RootFile.cc:1727
boost::shared_ptr< InputFile > filePtr_
Definition: RootFile.h:179
void initializeDuplicateChecker(std::vector< boost::shared_ptr< IndexIntoFile > > const &indexesIntoFiles, std::vector< boost::shared_ptr< IndexIntoFile > >::size_type currentIndexIntoFile)
Definition: RootFile.cc:1647
unsigned int RunNumber_t
Definition: EventRange.h:32
std::vector< ParentageID > parentageIDLookup_
Definition: RootFile.h:218
EventAuxiliary eventAux_
Definition: RootFile.h:197
void fillThisEventAuxiliary()
Definition: RootFile.cc:1141
bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
Definition: RootFile.cc:1566
ProcessHistoryRegistry * processHistoryRegistry_
Definition: RootFile.h:178
void rewind()
Definition: RootTree.h:89
RootTree const & eventTree() const
Definition: RootFile.h:107
void validateFile(InputType inputType, bool usingGoToEvent)
Definition: RootFile.cc:1068
IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const
Definition: RootFile.cc:658
std::string const & newBranchToOldBranch(std::string const &newBranch) const
Definition: RootFile.cc:649
boost::shared_ptr< EventSkipperByID > eventSkipperByID_
Definition: RootFile.h:180
TTree * eventHistoryTree_
Definition: RootFile.h:209
boost::shared_ptr< ProductRegistry const > productRegistry() const
Definition: RootFile.h:99
std::string const file_
Definition: RootFile.h:175
boost::shared_ptr< RunAuxiliary > readRunAuxiliary_()
Definition: RootFile.cc:1429
std::vector< EventProcessHistoryID > eventProcessHistoryIDs_
Definition: RootFile.h:189
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 labelRawDataLikeMC, bool usingGoToEvent, bool enablePrefetching)
Definition: RootFile.cc:136
void readEventHistoryTree()
Definition: RootFile.cc:1634
int forcedRunOffset_
Definition: RootFile.h:207
void reportOpened(std::string const &inputType)
Definition: RootFile.cc:1115