00001 #ifndef FWLite_BranchMapReader_h 00002 #define FWLite_BranchMapReader_h 00003 // -*- C++ -*- 00004 // 00005 // Package: FWLite 00006 // Class : BranchMapReader 00007 // 00016 // 00017 // Original Author: Dan Riley 00018 // Created: Tue May 20 10:31:32 EDT 2008 00019 // 00020 00021 // system include files 00022 #include <memory> 00023 #include "TUUID.h" 00024 00025 // user include files 00026 #include "DataFormats/Provenance/interface/BranchDescription.h" 00027 #include "DataFormats/Provenance/interface/BranchListIndex.h" 00028 00029 // forward declarations 00030 class TFile; 00031 class TTree; 00032 class TBranch; 00033 00034 namespace fwlite { 00035 namespace internal { 00036 class BMRStrategy { 00037 public: 00038 BMRStrategy(TFile* file, int fileVersion); 00039 virtual ~BMRStrategy(); 00040 00041 virtual bool updateFile(TFile* file) = 0; 00042 virtual bool updateEvent(Long_t eventEntry) = 0; 00043 virtual bool updateLuminosityBlock(Long_t luminosityBlockEntry) = 0; 00044 virtual bool updateRun(Long_t runEntry) = 0; 00045 virtual bool updateMap() = 0; 00046 virtual edm::BranchID productToBranchID(const edm::ProductID& pid) = 0; 00047 virtual const edm::BranchDescription& productToBranch(const edm::ProductID& pid) = 0; 00048 virtual const std::vector<edm::BranchDescription>& getBranchDescriptions() = 0; 00049 virtual const edm::BranchListIndexes& branchListIndexes() const = 0; 00050 00051 TFile* currentFile_; 00052 TTree* eventTree_; 00053 TTree* luminosityBlockTree_; 00054 TTree* runTree_; 00055 TUUID fileUUID_; 00056 Long_t eventEntry_; 00057 Long_t luminosityBlockEntry_; 00058 Long_t runEntry_; 00059 int fileVersion_; 00060 }; 00061 } 00062 00063 class BranchMapReader { 00064 public: 00065 BranchMapReader(TFile* file); 00066 BranchMapReader() : strategy_(0),fileVersion_(0) {} 00067 00068 // ---------- const member functions --------------------- 00069 00070 // ---------- static member functions -------------------- 00071 00072 // ---------- member functions --------------------------- 00073 bool updateFile(TFile* file); 00074 bool updateEvent(Long_t eventEntry); 00075 bool updateLuminosityBlock(Long_t luminosityBlockEntry); 00076 bool updateRun(Long_t runEntry); 00077 const edm::BranchDescription& productToBranch(const edm::ProductID& pid); 00078 int getFileVersion(TFile* file); 00079 int getFileVersion() const { return fileVersion_;} 00080 00081 TFile* getFile() const { return strategy_->currentFile_; } 00082 TTree* getEventTree() const { return strategy_->eventTree_; } 00083 TTree* getLuminosityBlockTree() const { return strategy_->luminosityBlockTree_; } 00084 TTree* getRunTree() const { return strategy_->runTree_; } 00085 TUUID getFileUUID() const { return strategy_->fileUUID_; } 00086 Long_t getEventEntry() const { return strategy_->eventEntry_; } 00087 Long_t getLuminosityBlockEntry() const { return strategy_->luminosityBlockEntry_; } 00088 Long_t getRunEntry() const { return strategy_->runEntry_; } 00089 const std::vector<edm::BranchDescription>& getBranchDescriptions(); 00090 const edm::BranchListIndexes& branchListIndexes() const { strategy_->updateMap(); return strategy_->branchListIndexes(); } 00091 00092 // ---------- member data -------------------------------- 00093 private: 00094 std::auto_ptr<internal::BMRStrategy> newStrategy(TFile* file, int fileVersion); 00095 std::auto_ptr<internal::BMRStrategy> strategy_; 00096 int fileVersion_; 00097 }; 00098 } 00099 00100 #endif