CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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 <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 BranchMapper;
00037   class DaqProvenanceHelper;
00038   class DuplicateChecker;
00039   class EventSkipperByID;
00040   class GroupSelectorRules;
00041   class InputFile;
00042   class ProvenanceReaderBase;
00043   class ProvenanceAdaptor;
00044 
00045   class MakeProvenanceReader {
00046   public:
00047     virtual std::unique_ptr<ProvenanceReaderBase> makeReader(RootTree& eventTree, DaqProvenanceHelper const* daqProvenanceHelper) const = 0;
00048   };
00049 
00050   class RootFile {
00051   public:
00052     typedef std::array<RootTree*, NumBranchTypes> RootTreePtrArray;
00053     RootFile(std::string const& fileName,
00054              ProcessConfiguration const& processConfiguration,
00055              std::string const& logicalFileName,
00056              boost::shared_ptr<InputFile> filePtr,
00057              boost::shared_ptr<EventSkipperByID> eventSkipperByID,
00058              bool skipAnyEvents,
00059              int remainingEvents,
00060              int remainingLumis,
00061              unsigned int treeCacheSize,
00062              int treeMaxVirtualSize,
00063              InputSource::ProcessingMode processingMode,
00064              RunNumber_t const& forcedRunNumber,
00065              bool noEventSort,
00066              GroupSelectorRules const& groupSelectorRules,
00067              InputType::InputType inputType,
00068              boost::shared_ptr<DuplicateChecker> duplicateChecker,
00069              bool dropDescendantsOfDroppedProducts,
00070              std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00071              std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile,
00072              std::vector<ProcessHistoryID>& orderedProcessHistoryIDs,
00073              bool labelRawDataLikeMC,
00074              bool usingGoToEvent);
00075     ~RootFile();
00076 
00077     RootFile(RootFile const&) = delete; // Disallow copying and moving
00078     RootFile& operator=(RootFile const&) = delete; // Disallow copying and moving
00079 
00080     void reportOpened(std::string const& inputType);
00081     void close();
00082     EventPrincipal* clearAndReadCurrentEvent(EventPrincipal& cache,
00083                  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
00084     EventPrincipal* readCurrentEvent(EventPrincipal& cache,
00085                  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
00086     EventPrincipal* readEvent(EventPrincipal& cache,
00087                  boost::shared_ptr<LuminosityBlockPrincipal> lb = boost::shared_ptr<LuminosityBlockPrincipal>());
00088 
00089     boost::shared_ptr<LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_();
00090     boost::shared_ptr<RunAuxiliary> readRunAuxiliary_();
00091     boost::shared_ptr<RunPrincipal> readRun_(boost::shared_ptr<RunPrincipal> rpCache);
00092     boost::shared_ptr<LuminosityBlockPrincipal> readLumi(boost::shared_ptr<LuminosityBlockPrincipal> lbCache);
00093     std::string const& file() const {return file_;}
00094     boost::shared_ptr<ProductRegistry const> productRegistry() const {return productRegistry_;}
00095     BranchIDListRegistry::collection_type const& branchIDLists() {return *branchIDLists_;}
00096     EventAuxiliary const& eventAux() const {return eventAux_;}
00097     // IndexIntoFile::EntryNumber_t const& entryNumber() const {return indexIntoFileIter().entry();}
00098     // LuminosityBlockNumber_t const& luminosityBlockNumber() const {return indexIntoFileIter().lumi();}
00099     // RunNumber_t const& runNumber() const {return indexIntoFileIter().run();}
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     boost::shared_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     EventPrincipal& secondaryEventPrincipal() {
00141       return *secondaryEventPrincipal_;
00142     }
00143 
00144   private:
00145     void checkReleaseVersion();
00146     RootTreePtrArray& treePointers() {return treePointers_;}
00147     bool skipThisEntry();
00148     IndexIntoFile::EntryType getEntryTypeWithSkipping();
00149     void setIfFastClonable(int remainingEvents, int remainingLumis);
00150     void validateFile(InputType::InputType inputType, bool usingGoToEvent);
00151     void fillIndexIntoFile();
00152     void fillEventAuxiliary();
00153     void fillThisEventAuxiliary();
00154     void fillHistory();
00155     boost::shared_ptr<LuminosityBlockAuxiliary> fillLumiAuxiliary();
00156     boost::shared_ptr<RunAuxiliary> fillRunAuxiliary();
00157     void overrideRunNumber(RunID& id);
00158     void overrideRunNumber(LuminosityBlockID& id);
00159     void overrideRunNumber(EventID& id, bool isRealData);
00160     std::string const& newBranchToOldBranch(std::string const& newBranch) const;
00161     void dropOnInput(ProductRegistry& reg, GroupSelectorRules const& rules, bool dropDescendants, InputType::InputType inputType);
00162     void readParentageTree();
00163     void readEntryDescriptionTree();
00164     void readEventHistoryTree();
00165     bool isDuplicateEvent();
00166 
00167     void initializeDuplicateChecker(std::vector<boost::shared_ptr<IndexIntoFile> > const& indexesIntoFiles,
00168                                     std::vector<boost::shared_ptr<IndexIntoFile> >::size_type currentIndexIntoFile);
00169 
00170     std::unique_ptr<MakeProvenanceReader> makeProvenanceReaderMaker() const;
00171     boost::shared_ptr<BranchMapper> makeBranchMapper();
00172 
00173     std::string const file_;
00174     std::string const logicalFile_;
00175     ProcessConfiguration const& processConfiguration_;
00176     ProcessConfigurationVector processConfigurations_;
00177     boost::shared_ptr<InputFile> filePtr_;
00178     boost::shared_ptr<EventSkipperByID> eventSkipperByID_;
00179     FileFormatVersion fileFormatVersion_;
00180     FileID fid_;
00181     boost::shared_ptr<IndexIntoFile> indexIntoFileSharedPtr_;
00182     IndexIntoFile& indexIntoFile_;
00183     std::vector<ProcessHistoryID>& orderedProcessHistoryIDs_;
00184     IndexIntoFile::IndexIntoFileItr indexIntoFileBegin_;
00185     IndexIntoFile::IndexIntoFileItr indexIntoFileEnd_;
00186     IndexIntoFile::IndexIntoFileItr indexIntoFileIter_;
00187     std::vector<EventProcessHistoryID> eventProcessHistoryIDs_;  // backward compatibility
00188     std::vector<EventProcessHistoryID>::const_iterator eventProcessHistoryIter_; // backward compatibility
00189     boost::shared_ptr<RunAuxiliary> savedRunAuxiliary_; // backward compatibility
00190     bool skipAnyEvents_;
00191     bool noEventSort_;
00192     int whyNotFastClonable_;
00193     std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
00194     bool branchListIndexesUnchanged_;
00195     EventAuxiliary eventAux_;
00196     RootTree eventTree_;
00197     RootTree lumiTree_;
00198     RootTree runTree_;
00199     RootTreePtrArray treePointers_;
00200     IndexIntoFile::EntryNumber_t lastEventEntryNumberRead_;
00201     boost::shared_ptr<ProductRegistry const> productRegistry_;
00202     boost::shared_ptr<BranchIDListRegistry::collection_type const> branchIDLists_;
00203     InputSource::ProcessingMode processingMode_;
00204     int forcedRunOffset_;
00205     std::map<std::string, std::string> newBranchToOldBranch_;
00206     TTree* eventHistoryTree_;                   // backward compatibility
00207     boost::shared_ptr<EventSelectionIDVector> eventSelectionIDs_;
00208     boost::shared_ptr<BranchListIndexes> branchListIndexes_;
00209     std::unique_ptr<History> history_; // backward compatibility
00210     boost::shared_ptr<BranchChildren> branchChildren_;
00211     boost::shared_ptr<DuplicateChecker> duplicateChecker_;
00212     std::unique_ptr<ProvenanceAdaptor> provenanceAdaptor_; // backward comatibility
00213     std::unique_ptr<MakeProvenanceReader> provenanceReaderMaker_;
00214     mutable std::unique_ptr<EventPrincipal> secondaryEventPrincipal_;
00215     mutable boost::shared_ptr<BranchMapper> eventBranchMapper_;
00216     std::vector<ParentageID> parentageIDLookup_;
00217     std::unique_ptr<DaqProvenanceHelper> daqProvenanceHelper_;
00218   }; // class RootFile
00219 
00220 }
00221 #endif