Go to the documentation of this file.00001 #ifndef IOPool_Input_RootFile_h
00002 #define IOPool_Input_RootFile_h
00003
00004
00005
00006
00007
00008
00009
00010 #include "InputType.h"
00011 #include "RootTree.h"
00012 #include "DataFormats/Provenance/interface/BranchChildren.h"
00013 #include "DataFormats/Provenance/interface/BranchIDList.h"
00014 #include "DataFormats/Provenance/interface/BranchListIndex.h"
00015 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
00016 #include "DataFormats/Provenance/interface/EventProcessHistoryID.h"
00017 #include "DataFormats/Provenance/interface/EventSelectionID.h"
00018 #include "DataFormats/Provenance/interface/FileFormatVersion.h"
00019 #include "DataFormats/Provenance/interface/FileID.h"
00020 #include "DataFormats/Provenance/interface/History.h"
00021 #include "DataFormats/Provenance/interface/IndexIntoFile.h"
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/InputSource.h"
00024
00025 #include <array>
00026 #include <map>
00027 #include <memory>
00028 #include <string>
00029 #include <vector>
00030
00031 namespace edm {
00032
00033
00034
00035
00036 class BranchIDListHelper;
00037 class BranchMapper;
00038 class DaqProvenanceHelper;
00039 class DuplicateChecker;
00040 class EventSkipperByID;
00041 class ProductSelectorRules;
00042 class InputFile;
00043 class ProvenanceReaderBase;
00044 class ProvenanceAdaptor;
00045
00046 class MakeProvenanceReader {
00047 public:
00048 virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
00049 };
00050
00051 class RootFile {
00052 public:
00053 typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
00054 RootFile(std::string const& fileName,
00055 ProcessConfiguration const& processConfiguration,
00056 std::string const& logicalFileName,
00057 boost::shared_ptr<InputFile> filePtr,
00058 boost::shared_ptr<EventSkipperByID> eventSkipperByID,
00059 bool skipAnyEvents,
00060 int remainingEvents,
00061 int remainingLumis,
00062 unsigned int treeCacheSize,
00063 int treeMaxVirtualSize,
00064 InputSource::ProcessingMode processingMode,
00065 RunNumber_t const& forcedRunNumber,
00066 bool noEventSort,
00067 ProductSelectorRules const& productSelectorRules,
00068 InputType::InputType inputType,
00069 boost::shared_ptr<BranchIDListHelper> branchIDListHelper,
00070 boost::shared_ptr<DuplicateChecker> duplicateChecker,
00071 bool dropDescendantsOfDroppedProducts,
00072 std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00073 std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
00074 std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
00075 bool labelRawDataLikeMC,
00076 bool usingGoToEvent,
00077 bool enablePrefetching);
00078 ~RootFile();
00079
00080 RootFile(RootFile const&) = delete;
00081 RootFile& operator=(RootFile const&) = delete;
00082
00083 void reportOpened(std::string const& inputType);
00084 void close();
00085 EventPrincipal* readCurrentEvent(EventPrincipal& cache);
00086 EventPrincipal* readEvent(EventPrincipal& cache);
00087
00088 boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
00089 boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
00090 boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> runPrincipal);
00091 boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal);
00092 std::string const& file() const {return file_;}
00093 boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
00094 boost::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return branchIDListHelper_;}
00095 BranchIDLists const& branchIDLists() {return *branchIDLists_;}
00096 EventAuxiliary const& eventAux() const {return eventAux_;}
00097
00098
00099
00100 EventID const& eventID() const {return eventAux().id();}
00101 RootTree const& eventTree() const {return eventTree_;}
00102 RootTree const& lumiTree() const {return lumiTree_;}
00103 RootTree const& runTree() const {return runTree_;}
00104 FileFormatVersion fileFormatVersion() const {return fileFormatVersion_;}
00105 int whyNotFastClonable() const {return whyNotFastClonable_;}
00106 std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
00107 bool branchListIndexesUnchanged() const {return branchListIndexesUnchanged_;}
00108 bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
00109 std::unique_ptr<FileBlock> createFileBlock() const;
00110 bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) {
00111 return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
00112 }
00113 bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event);
00114 bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
00115 bool setEntryAtRun(RunNumber_t run);
00116 bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
00117 void setAtEventEntry(IndexIntoFile::EntryNumber_t entry);
00118
00119 void rewind() {
00120 indexIntoFileIter_ = indexIntoFileBegin_;
00121 eventTree_.rewind();
00122 lumiTree_.rewind();
00123 runTree_.rewind();
00124 }
00125 void setToLastEntry() {
00126 indexIntoFileIter_ = indexIntoFileEnd_;
00127 }
00128
00129 bool skipEvents(int& offset);
00130 bool goToEvent(EventID const& eventID);
00131 bool nextEventEntry() {return eventTree_.next();}
00132 IndexIntoFile::EntryType getNextEntryTypeWanted();
00133 boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
00134 return indexIntoFileSharedPtr_;
00135 }
00136 bool wasLastEventJustRead() const;
00137 bool wasFirstEventJustRead() const;
00138 IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const;
00139 void setPosition(IndexIntoFile::IndexIntoFileItr const& position);
00140
00141 private:
00142 void checkReleaseVersion();
00143 RootTreePtrArray& treePointers() {return treePointers_;}
00144 bool skipThisEntry();
00145 IndexIntoFile::EntryType getEntryTypeWithSkipping();
00146 void setIfFastClonable(int remainingEvents, int remainingLumis);
00147 void validateFile(InputType::InputType inputType, bool usingGoToEvent);
00148 void fillIndexIntoFile();
00149 void fillEventAuxiliary();
00150 void fillThisEventAuxiliary();
00151 void fillHistory();
00152 boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
00153 boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
00154 void overrideRunNumber(RunID& id);
00155 void overrideRunNumber(LuminosityBlockID& id);
00156 void overrideRunNumber(EventID& id, bool isRealData);
00157 std::string const& newBranchToOldBranch(std::string const& newBranch) const;
00158 void dropOnInput(ProductRegistry& reg, ProductSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType);
00159 void readParentageTree();
00160 void readEntryDescriptionTree();
00161 void readEventHistoryTree();
00162 bool isDuplicateEvent();
00163
00164 void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00165 std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
00166
00167 std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker() const;
00168 boost::shared_ptr<BranchMapper> makeBranchMapper();
00169
00170 std::string const file_;
00171 std::string const logicalFile_;
00172 ProcessConfiguration const& processConfiguration_;
00173 ProcessConfigurationVector processConfigurations_;
00174 boost::shared_ptr<InputFile> filePtr_;
00175 boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
00176 FileFormatVersion fileFormatVersion_;
00177 FileID fid_;
00178 boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
00179 IndexIntoFile& indexIntoFile_;
00180 std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
00181 IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_;
00182 IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_;
00183 IndexIntoFile::IndexIntoFileItr indexIntoFileIter_;
00184 std::vector<EventProcessHistoryID> eventProcessHistoryIDs_;
00185 std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_;
00186 boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_;
00187 bool skipAnyEvents_;
00188 bool noEventSort_;
00189 int whyNotFastClonable_;
00190 std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
00191 bool branchListIndexesUnchanged_;
00192 EventAuxiliary eventAux_;
00193 RootTree eventTree_;
00194 RootTree lumiTree_;
00195 RootTree runTree_;
00196 RootTreePtrArray treePointers_;
00197 IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_;
00198 boost::shared_ptr<ProductRegistry const> productRegistry_;
00199 boost::shared_ptr<BranchIDLists const> branchIDLists_;
00200 boost::shared_ptr<BranchIDListHelper> branchIDListHelper_;
00201 InputSource::ProcessingMode processingMode_;
00202 int forcedRunOffset_;
00203 std::map<std::string, std::string> newBranchToOldBranch_;
00204 TTree* eventHistoryTree_;
00205 boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
00206 boost::shared_ptr<BranchListIndexes> branchListIndexes_;
00207 std::unique_ptr<History> history_;
00208 boost::shared_ptr<BranchChildren> branchChildren_;
00209 boost::shared_ptr<DuplicateChecker> duplicateChecker_;
00210 std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_;
00211 std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
00212 mutable boost::shared_ptr<BranchMapper> eventBranchMapper_;
00213 std::vector<ParentageID> parentageIDLookup_;
00214 std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
00215 };
00216
00217 }
00218 #endif