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 // $Id: BranchMapReader.h,v 1.5 2008/09/24 15:25:31 dsr Exp $ 00020 // 00021 00022 // system include files 00023 #include <map> 00024 //#include "boost/shared_ptr.hpp" 00025 #include "TUUID.h" 00026 00027 // user include files 00028 #include "DataFormats/Provenance/interface/BranchMapper.h" 00029 #include "DataFormats/Provenance/interface/BranchDescription.h" 00030 #include "DataFormats/Provenance/interface/EventEntryInfo.h" 00031 00032 // forward declarations 00033 class TFile; 00034 class TTree; 00035 class TBranch; 00036 00037 namespace fwlite { 00038 00039 class BranchMapReader { 00040 public: 00041 typedef edm::BranchMapper eeiMap; 00042 typedef std::map<edm::BranchID, edm::BranchDescription> bidToDesc; 00043 00044 BranchMapReader(TFile* file); 00045 BranchMapReader() : strategy_(0) {} 00046 00047 class Strategy { 00048 public: 00049 Strategy(TFile* file, int fileVersion, eeiMap& eventInfoMap, bidToDesc& branchDescriptionMap); 00050 virtual ~Strategy(); 00051 virtual bool updateFile(TFile* file); 00052 virtual bool updateEvent(Long_t eventEntry) { eventEntry_ = eventEntry; return true; } 00053 virtual bool updateMap() { return true; } 00054 00055 TBranch* getBranchRegistry(edm::ProductRegistry** pReg); 00056 00057 TFile* currentFile_; 00058 TTree* eventTree_; 00059 TUUID fileUUID_; 00060 int fileVersion_; 00061 Long_t eventEntry_; 00062 eeiMap& eventInfoMap_; 00063 bidToDesc& branchDescriptionMap_; 00064 bool mapperFilled_; 00065 }; 00066 00067 // ---------- const member functions --------------------- 00068 00069 // ---------- static member functions -------------------- 00070 00071 // ---------- member functions --------------------------- 00072 bool updateFile(TFile* file); 00073 bool updateEvent(Long_t eventEntry); 00074 const edm::BranchDescription productToBranch(const edm::ProductID& pid) const { 00075 strategy_->updateMap(); 00076 edm::BranchID bid = eventInfoMap_.productToBranch(pid); 00077 bidToDesc::const_iterator bdi = branchDescriptionMap_.find(bid); 00078 if (branchDescriptionMap_.end() == bdi) { 00079 return edm::BranchDescription(); 00080 } 00081 return bdi->second; 00082 } 00083 int getFileVersion(TFile* file) const; 00084 00085 TFile* getFile() const { return strategy_->currentFile_; } 00086 TTree* getEventTree() const { return strategy_->eventTree_; } 00087 TUUID getFileUUID() const { return strategy_->fileUUID_; } 00088 Long_t getEventEntry() const { return strategy_->eventEntry_; } 00089 const std::vector<edm::BranchDescription>& getBranchDescriptions(); 00090 00091 // ---------- member data -------------------------------- 00092 private: 00093 std::auto_ptr<Strategy> newStrategy(TFile* file, int fileVersion); 00094 00095 std::auto_ptr<Strategy> strategy_; 00096 eeiMap eventInfoMap_; 00097 bidToDesc branchDescriptionMap_; 00098 std::vector<edm::BranchDescription> bDesc_; 00099 }; 00100 } 00101 00102 #endif