CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/IOPool/Input/src/RootFile.h

Go to the documentation of this file.
00001 #ifndef IOPool_Input_RootFile_h
00002 #define IOPool_Input_RootFile_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 RootFile.h // used by ROOT input sources
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" // backward compatibility
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   // Class RootFile: supports file reading.
00035 
00036   class BranchIDListHelper;
00037   class BranchMapper;
00038   class DaqProvenanceHelper;
00039   class DuplicateChecker;
00040   class EventSkipperByID;
00041   class GroupSelectorRules;
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              GroupSelectorRules const& groupSelectorRules,
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; // Disallow copying and moving
00081     RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
00082 
00083     void reportOpened(std::string const& inputType);
00084     void close();
00085     EventPrincipal* clearAndReadCurrentEvent(EventPrincipal& cache);
00086     EventPrincipal* readCurrentEvent(EventPrincipal& cache);
00087     EventPrincipal* readEvent(EventPrincipal& cache);
00088 
00089     boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
00090     boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
00091     boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> runPrincipal);
00092     boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lumiPrincipal);
00093     std::string const& file() const {return file_;}
00094     boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
00095     boost::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return branchIDListHelper_;}
00096     BranchIDLists const& branchIDLists() {return *branchIDLists_;}
00097     EventAuxiliary const& eventAux() const {return eventAux_;}
00098     // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
00099     // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
00100     // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
00101     EventID const& eventID() const {return eventAux().id();}
00102     RootTree const& eventTree() const {return eventTree_;}
00103     RootTree const& lumiTree() const {return lumiTree_;}
00104     RootTree const& runTree() const {return runTree_;}
00105     FileFormatVersion fileFormatVersion() const {return fileFormatVersion_;}
00106     int whyNotFastClonable() const {return whyNotFastClonable_;}
00107     std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
00108     bool branchListIndexesUnchanged() const {return branchListIndexesUnchanged_;}
00109     bool modifiedIDs() const {return daqProvenanceHelper_.get() != 0;}
00110     boost::shared_ptr<FileBlock> createFileBlock() const;
00111     bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) {
00112       return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
00113     }
00114     bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event);
00115     bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
00116     bool setEntryAtRun(RunNumber_t run);
00117     bool setEntryAtNextEventInLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
00118     void setAtEventEntry(IndexIntoFile::EntryNumber_t entry);
00119 
00120     void rewind() {
00121       indexIntoFileIter_ = indexIntoFileBegin_;
00122       eventTree_.rewind();
00123       lumiTree_.rewind();
00124       runTree_.rewind();
00125     }
00126     void setToLastEntry() {
00127       indexIntoFileIter_ = indexIntoFileEnd_;
00128     }
00129 
00130     bool skipEvents(int& offset);
00131     bool goToEvent(EventID const& eventID);
00132     bool nextEventEntry() {return eventTree_.next();}
00133     IndexIntoFile::EntryType getNextEntryTypeWanted();
00134     boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
00135       return indexIntoFileSharedPtr_;
00136     }
00137     bool wasLastEventJustRead() const;
00138     bool wasFirstEventJustRead() const;
00139     IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const;
00140     void setPosition(IndexIntoFile::IndexIntoFileItr const& position);
00141     EventPrincipal& secondaryEventPrincipal() {
00142       return *secondaryEventPrincipal_;
00143     }
00144 
00145   private:
00146     void checkReleaseVersion();
00147     RootTreePtrArray& treePointers() {return treePointers_;}
00148     bool skipThisEntry();
00149     IndexIntoFile::EntryType getEntryTypeWithSkipping();
00150     void setIfFastClonable(int remainingEvents, int remainingLumis);
00151     void validateFile(InputType::InputType inputType, bool usingGoToEvent);
00152     void fillIndexIntoFile();
00153     void fillEventAuxiliary();
00154     void fillThisEventAuxiliary();
00155     void fillHistory();
00156     boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
00157     boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
00158     void overrideRunNumber(RunID& id);
00159     void overrideRunNumber(LuminosityBlockID& id);
00160     void overrideRunNumber(EventID& id, bool isRealData);
00161     std::string const& newBranchToOldBranch(std::string const& newBranch) const;
00162     void dropOnInput(ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType);
00163     void readParentageTree();
00164     void readEntryDescriptionTree();
00165     void readEventHistoryTree();
00166     bool isDuplicateEvent();
00167 
00168     void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00169                                     std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
00170 
00171     std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker() const;
00172     boost::shared_ptr<BranchMapper> makeBranchMapper();
00173 
00174     std::string const file_;
00175     std::string const logicalFile_;
00176     ProcessConfiguration const& processConfiguration_;
00177     ProcessConfigurationVector processConfigurations_;
00178     boost::shared_ptr<InputFile> filePtr_;
00179     boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
00180     FileFormatVersion fileFormatVersion_;
00181     FileID fid_;
00182     boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
00183     IndexIntoFile& indexIntoFile_;
00184     std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
00185     IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_;
00186     IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_;
00187     IndexIntoFile::IndexIntoFileItr indexIntoFileIter_;
00188     std::vector<EventProcessHistoryID> eventProcessHistoryIDs_;  // backward compatibility
00189     std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
00190     boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
00191     bool skipAnyEvents_;
00192     bool noEventSort_;
00193     int whyNotFastClonable_;
00194     std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
00195     bool branchListIndexesUnchanged_;
00196     EventAuxiliary eventAux_;
00197     RootTree eventTree_;
00198     RootTree lumiTree_;
00199     RootTree runTree_;
00200     RootTreePtrArray treePointers_;
00201     IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_;
00202     boost::shared_ptr<ProductRegistry const> productRegistry_;
00203     boost::shared_ptr<BranchIDLists const> branchIDLists_;
00204     boost::shared_ptr<BranchIDListHelper> branchIDListHelper_;
00205     InputSource::ProcessingMode processingMode_;
00206     int forcedRunOffset_;
00207     std::map<std::string, std::string> newBranchToOldBranch_;
00208     TTree* eventHistoryTree_;                   // backward compatibility
00209     boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
00210     boost::shared_ptr<BranchListIndexes> branchListIndexes_;
00211     std::unique_ptr<History> history_; // backward compatibility
00212     boost::shared_ptr<BranchChildren> branchChildren_;
00213     boost::shared_ptr<DuplicateChecker> duplicateChecker_;
00214     std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
00215     std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
00216     mutable std::unique_ptr<EventPrincipal> secondaryEventPrincipal_;
00217     mutable boost::shared_ptr<BranchMapper> eventBranchMapper_;
00218     std::vector<ParentageID> parentageIDLookup_;
00219     std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
00220   }; // class RootFile
00221 
00222 }
00223 #endif