CMS 3D CMS Logo

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