CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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 <map>
00011 #include <memory>
00012 #include <string>
00013 #include <vector>
00014 
00015 #include "boost/shared_ptr.hpp"
00016 #include "boost/utility.hpp"
00017 #include "boost/array.hpp"
00018 
00019 #include "RootTree.h"
00020 #include "FWCore/Framework/interface/Frameworkfwd.h"
00021 #include "FWCore/Framework/interface/InputSource.h"
00022 #include "DataFormats/Provenance/interface/BranchChildren.h"
00023 #include "DataFormats/Provenance/interface/BranchIDListRegistry.h"
00024 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
00025 #include "DataFormats/Provenance/interface/FileFormatVersion.h"
00026 #include "DataFormats/Provenance/interface/FileID.h"
00027 #include "DataFormats/Provenance/interface/EventSelectionID.h"
00028 #include "DataFormats/Provenance/interface/History.h"
00029 #include "DataFormats/Provenance/interface/BranchListIndex.h"
00030 #include "DataFormats/Provenance/interface/IndexIntoFile.h"
00031 #include "DataFormats/Provenance/interface/EventProcessHistoryID.h" // backward compatibility
00032 
00033 namespace edm {
00034 
00035   //------------------------------------------------------------
00036   // Class RootFile: supports file reading.
00037 
00038   class DuplicateChecker;
00039   class ProvenanceAdaptor;
00040   class GroupSelectorRules;
00041   class EventSkipperByID;
00042   class InputFile;
00043 
00044   class RootFile : private boost::noncopyable {
00045   public:
00046     typedef boost::array<RootTree*, NumBranchTypes> RootTreePtrArray;
00047     RootFile(std::string const& fileName,
00048              ProcessConfiguration const& processConfiguration,
00049              std::string const& logicalFileName,
00050              boost::shared_ptr<InputFile> filePtr,
00051              boost::shared_ptr<EventSkipperByID> eventSkipperByID,
00052              bool skipAnyEvents,
00053              int remainingEvents,
00054              int remainingLumis,
00055              unsigned int treeCacheSize,
00056              int treeMaxVirtualSize,
00057              InputSource::ProcessingMode processingMode,
00058              RunNumber_t const& forcedRunNumber,
00059              bool noEventSort,
00060              GroupSelectorRules const& groupSelectorRules,
00061              bool secondaryFile,
00062              boost::shared_ptr<DuplicateChecker> duplicateChecker,
00063              bool dropDescendantsOfDroppedProducts,
00064              std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00065              std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
00066              std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
00067              bool usingGoToEvent);
00068     ~RootFile();
00069     void reportOpened(std::string const& inputType);
00070     void close();
00071     EventPrincipal* readCurrentEvent(EventPrincipal& cache,
00072                  boost::shared_ptr<RootFile> rootFilePtr,
00073                  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
00074     EventPrincipal* readEvent(EventPrincipal& cache,
00075                  boost::shared_ptr<RootFile> rootFilePtr,
00076                  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
00077 
00078     boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
00079     boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
00080     boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> rpCache);
00081     boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lbCache);
00082     std::string const& file() const {return file_;}
00083     boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
00084     BranchIDListRegistry::collection_type const& branchIDLists() {return *branchIDLists_;}
00085     EventAuxiliary const& eventAux() const {return eventAux_;}
00086     // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
00087     // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
00088     // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
00089     EventID const& eventID() const {return eventAux().id();}
00090     RootTree const& eventTree() const {return eventTree_;}
00091     RootTree const& lumiTree() const {return lumiTree_;}
00092     RootTree const& runTree() const {return runTree_;}
00093     FileFormatVersion fileFormatVersion() const {return fileFormatVersion_;}
00094     int whyNotFastClonable() const {return whyNotFastClonable_;}
00095     boost::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
00096     bool branchListIndexesUnchanged() const {return branchListIndexesUnchanged_;}
00097     boost::shared_ptr<FileBlock> createFileBlock() const;
00098     bool setEntryAtItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) {
00099       return event ? setEntryAtEvent(run, lumi, event) : (lumi ? setEntryAtLumi(run, lumi) : setEntryAtRun(run));
00100     }
00101     bool setEntryAtEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event);
00102     bool setEntryAtLumi(RunNumber_t run, LuminosityBlockNumber_t lumi);
00103     bool setEntryAtRun(RunNumber_t run);
00104     void setAtEventEntry(IndexIntoFile::EntryNumber_t entry);
00105 
00106     void rewind() {
00107       indexIntoFileIter_ = indexIntoFileBegin_;
00108       eventTree_.rewind();
00109       lumiTree_.rewind();
00110       runTree_.rewind();
00111     }
00112     void setToLastEntry() {
00113       indexIntoFileIter_ = indexIntoFileEnd_;
00114     }
00115 
00116     bool skipEvents(int& offset);
00117     bool goToEvent(EventID const& eventID);
00118     bool nextEventEntry() {return eventTree_.next();}
00119     IndexIntoFile::EntryType getNextEntryTypeWanted();
00120     boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr() const {
00121       return indexIntoFileSharedPtr_;
00122     }
00123     bool wasLastEventJustRead() const;
00124     bool wasFirstEventJustRead() const;
00125     IndexIntoFile::IndexIntoFileItr indexIntoFileIter() const;
00126     void setPosition(IndexIntoFile::IndexIntoFileItr const& position);
00127 
00128   private:
00129     RootTreePtrArray& treePointers() {return treePointers_;}
00130     bool skipThisEntry();
00131     IndexIntoFile::EntryType getEntryTypeWithSkipping();
00132     void setIfFastClonable(int remainingEvents, int remainingLumis);
00133     void validateFile(bool secondaryFile, bool usingGoToEvent);
00134     void fillIndexIntoFile();
00135     void fillEventAuxiliary();
00136     void fillThisEventAuxiliary();
00137     void fillHistory();
00138     boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
00139     boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
00140     void overrideRunNumber(RunID& id);
00141     void overrideRunNumber(LuminosityBlockID& id);
00142     void overrideRunNumber(EventID& id, bool isRealData);
00143     std::string const& newBranchToOldBranch(std::string const& newBranch) const;
00144     void dropOnInput(ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, bool secondaryFile);
00145     void readParentageTree();
00146     void readEntryDescriptionTree();
00147     void readEventHistoryTree();
00148     bool isDuplicateEvent();
00149 
00150     void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00151                                     std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
00152 
00153     boost::shared_ptr<BranchMapper> makeBranchMapper(RootTree& rootTree, BranchType const& type) const;
00154 
00155     std::string const file_;
00156     std::string const logicalFile_;
00157     ProcessConfiguration const& processConfiguration_;
00158     boost::shared_ptr<InputFile> filePtr_;
00159     boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
00160     FileFormatVersion fileFormatVersion_;
00161     FileID fid_;
00162     boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
00163     IndexIntoFile& indexIntoFile_;
00164     std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
00165     IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_;
00166     IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_;
00167     IndexIntoFile::IndexIntoFileItr indexIntoFileIter_;
00168     std::vector<EventProcessHistoryID> eventProcessHistoryIDs_;  // backward compatibility
00169     std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
00170     bool skipAnyEvents_;
00171     bool noEventSort_;
00172     int whyNotFastClonable_;
00173     boost::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
00174     bool branchListIndexesUnchanged_;
00175     EventAuxiliary eventAux_;
00176     RootTree eventTree_;
00177     RootTree lumiTree_;
00178     RootTree runTree_;
00179     RootTreePtrArray treePointers_;
00180     IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_;
00181     boost::shared_ptr<ProductRegistry const> productRegistry_;
00182     boost::shared_ptr<BranchIDListRegistry::collection_type const> branchIDLists_;
00183     InputSource::ProcessingMode processingMode_;
00184     int forcedRunOffset_;
00185     std::map<std::string, std::string> newBranchToOldBranch_;
00186     TTree* eventHistoryTree_;
00187     boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
00188     boost::shared_ptr<BranchListIndexes> branchListIndexes_;
00189     boost::shared_ptr<History> history_;
00190     boost::shared_ptr<BranchChildren> branchChildren_;
00191     boost::shared_ptr<DuplicateChecker> duplicateChecker_;
00192     boost::shared_ptr<ProvenanceAdaptor> provenanceAdaptor_;
00193   }; // class RootFile
00194 
00195 }
00196 #endif