Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:31

0001 #ifndef FWLite_BranchMapReader_h
0002 #define FWLite_BranchMapReader_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     BranchMapReader
0007 //
0008 /**\class BranchMapReader BranchMapReader.h FWCore/FWLite/interface/BranchMapReader.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Dan Riley
0018 //         Created:  Tue May 20 10:31:32 EDT 2008
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include "TUUID.h"
0024 
0025 // user include files
0026 #include "DataFormats/Provenance/interface/BranchDescription.h"
0027 #include "DataFormats/Provenance/interface/BranchListIndex.h"
0028 #include "FWCore/Utilities/interface/propagate_const.h"
0029 
0030 // forward declarations
0031 class TFile;
0032 class TTree;
0033 class TBranch;
0034 
0035 namespace edm {
0036   class ThinnedAssociationsHelper;
0037 }
0038 
0039 namespace fwlite {
0040   namespace internal {
0041     class BMRStrategy {
0042     public:
0043       BMRStrategy(TFile* file, int fileVersion);
0044       virtual ~BMRStrategy();
0045 
0046       virtual bool updateFile(TFile* file) = 0;
0047       virtual bool updateEvent(Long_t eventEntry) = 0;
0048       virtual bool updateLuminosityBlock(Long_t luminosityBlockEntry) = 0;
0049       virtual bool updateRun(Long_t runEntry) = 0;
0050       virtual bool updateMap() = 0;
0051       virtual edm::BranchID productToBranchID(const edm::ProductID& pid) = 0;
0052       virtual const edm::BranchDescription& productToBranch(const edm::ProductID& pid) = 0;
0053       virtual const edm::BranchDescription& branchIDToBranch(const edm::BranchID& bid) const = 0;
0054       virtual const std::vector<edm::BranchDescription>& getBranchDescriptions() = 0;
0055       virtual const edm::BranchListIndexes& branchListIndexes() const = 0;
0056       virtual const edm::ThinnedAssociationsHelper& thinnedAssociationsHelper() const = 0;
0057 
0058       edm::propagate_const<TFile*> currentFile_;
0059       edm::propagate_const<TTree*> eventTree_;
0060       edm::propagate_const<TTree*> luminosityBlockTree_;
0061       edm::propagate_const<TTree*> runTree_;
0062       TUUID fileUUID_;
0063       Long_t eventEntry_;
0064       Long_t luminosityBlockEntry_;
0065       Long_t runEntry_;
0066       int fileVersion_;
0067     };
0068   }  // namespace internal
0069 
0070   class BranchMapReader {
0071   public:
0072     BranchMapReader(TFile* file);
0073     BranchMapReader() : strategy_(nullptr), fileVersion_(0) {}
0074 
0075     // ---------- const member functions ---------------------
0076 
0077     // ---------- static member functions --------------------
0078 
0079     // ---------- member functions ---------------------------
0080     bool updateFile(TFile* file);
0081     bool updateEvent(Long_t eventEntry);
0082     bool updateLuminosityBlock(Long_t luminosityBlockEntry);
0083     bool updateRun(Long_t runEntry);
0084     edm::BranchID productToBranchID(const edm::ProductID& pid) { return strategy_->productToBranchID(pid); }
0085     const edm::BranchDescription& productToBranch(const edm::ProductID& pid);
0086     const edm::BranchDescription& branchIDToBranch(const edm::BranchID& bid) const {
0087       return strategy_->branchIDToBranch(bid);
0088     }
0089     int getFileVersion(TFile* file);
0090     int getFileVersion() const { return fileVersion_; }
0091 
0092     TFile const* getFile() const { return strategy_->currentFile_; }
0093     TFile* getFile() { return strategy_->currentFile_; }
0094     TTree const* getEventTree() const { return strategy_->eventTree_; }
0095     TTree* getEventTree() { return strategy_->eventTree_; }
0096     TTree const* getLuminosityBlockTree() const { return strategy_->luminosityBlockTree_; }
0097     TTree* getLuminosityBlockTree() { return strategy_->luminosityBlockTree_; }
0098     TTree const* getRunTree() const { return strategy_->runTree_; }
0099     TTree* getRunTree() { return strategy_->runTree_; }
0100     TUUID getFileUUID() const { return strategy_->fileUUID_; }
0101     Long_t getEventEntry() const { return strategy_->eventEntry_; }
0102     Long_t getLuminosityBlockEntry() const { return strategy_->luminosityBlockEntry_; }
0103     Long_t getRunEntry() const { return strategy_->runEntry_; }
0104     const std::vector<edm::BranchDescription>& getBranchDescriptions();
0105     const edm::BranchListIndexes& branchListIndexes() const {
0106       strategy_->updateMap();
0107       return strategy_->branchListIndexes();
0108     }
0109     const edm::ThinnedAssociationsHelper& thinnedAssociationsHelper() const {
0110       return strategy_->thinnedAssociationsHelper();
0111     }
0112 
0113     // ---------- member data --------------------------------
0114   private:
0115     std::unique_ptr<internal::BMRStrategy> newStrategy(TFile* file, int fileVersion);
0116     std::unique_ptr<internal::BMRStrategy> strategy_;  // Contains caches, so we do not propagate_const
0117     int fileVersion_;
0118   };
0119 }  // namespace fwlite
0120 
0121 #endif