00001 #ifndef IOPool_Input_RootTree_h 00002 #define IOPool_Input_RootTree_h 00003 00004 /*---------------------------------------------------------------------- 00005 00006 RootTree.h // used by ROOT input sources 00007 00008 ----------------------------------------------------------------------*/ 00009 00010 #include <memory> 00011 #include <string> 00012 #include <vector> 00013 00014 #include "boost/shared_ptr.hpp" 00015 #include "boost/utility.hpp" 00016 00017 #include "Inputfwd.h" 00018 #include "FWCore/Framework/interface/Frameworkfwd.h" 00019 #include "DataFormats/Provenance/interface/ProvenanceFwd.h" 00020 #include "DataFormats/Provenance/interface/EventEntryInfo.h" 00021 #include "DataFormats/Provenance/interface/BranchKey.h" 00022 #include "IOPool/Input/src/BranchMapperWithReader.h" 00023 #include "TBranch.h" 00024 #include "TTree.h" 00025 class TFile; 00026 00027 namespace edm { 00028 00029 class RootTree : private boost::noncopyable { 00030 public: 00031 typedef input::BranchMap BranchMap; 00032 typedef input::EntryNumber EntryNumber; 00033 RootTree(boost::shared_ptr<TFile> filePtr, BranchType const& branchType); 00034 ~RootTree() {} 00035 00036 bool isValid() const; 00037 void addBranch(BranchKey const& key, 00038 BranchDescription const& prod, 00039 std::string const& oldBranchName); 00040 void dropBranch(std::string const& oldBranchName); 00041 void setPresence(BranchDescription const& prod); 00042 bool next() {return ++entryNumber_ < entries_;} 00043 bool previous() {return --entryNumber_ >= 0;} 00044 bool current() {return entryNumber_ < entries_ && entryNumber_ >= 0;} 00045 void rewind() {entryNumber_ = 0;} 00046 EntryNumber const& entryNumber() const {return entryNumber_;} 00047 EntryNumber const& entries() const {return entries_;} 00048 void setEntryNumber(EntryNumber theEntryNumber); 00049 std::vector<std::string> const& branchNames() const {return branchNames_;} 00050 template <typename T> 00051 void fillGroups(T& item); 00052 boost::shared_ptr<DelayedReader> makeDelayedReader() const; 00053 template <typename T> 00054 boost::shared_ptr<BranchMapper> makeBranchMapper() const; 00055 //TBranch *auxBranch() {return auxBranch_;} 00056 template <typename T> 00057 void fillAux(T *& pAux) const { 00058 auxBranch_->SetAddress(&pAux); 00059 input::getEntry(auxBranch_, entryNumber_); 00060 } 00061 TTree const* tree() const {return tree_;} 00062 TTree const* metaTree() const {return metaTree_;} 00063 void setCacheSize(unsigned int cacheSize) const; 00064 void setTreeMaxVirtualSize(int treeMaxVirtualSize); 00065 BranchMap const& branches() const {return *branches_;} 00066 std::vector<ProductStatus> const& productStatuses() const {return productStatuses_;} 00067 00068 // below for backward compatibility 00069 void fillStatus() { 00070 statusBranch_->SetAddress(&pProductStatuses_); 00071 input::getEntry(statusBranch_, entryNumber_); 00072 } 00073 00074 private: 00075 boost::shared_ptr<TFile> filePtr_; 00076 // We use bare pointers for pointers to some ROOT entities. 00077 // Root owns them and uses bare pointers internally. 00078 // Therefore,using smart pointers here will do no good. 00079 TTree *const tree_; 00080 TTree *const metaTree_; 00081 BranchType branchType_; 00082 TBranch *const auxBranch_; 00083 TBranch *const branchEntryInfoBranch_; 00084 EntryNumber entries_; 00085 EntryNumber entryNumber_; 00086 std::vector<std::string> branchNames_; 00087 boost::shared_ptr<BranchMap> branches_; 00088 00089 // below for backward compatibility 00090 std::vector<ProductStatus> productStatuses_; 00091 std::vector<ProductStatus>* pProductStatuses_; 00092 TTree *const infoTree_; 00093 TBranch *const statusBranch_; 00094 }; 00095 00096 template <typename T> 00097 void 00098 RootTree::fillGroups(T& item) { 00099 if (metaTree_ == 0 || metaTree_->GetNbranches() == 0) return; 00100 // Loop over provenance 00101 for (BranchMap::const_iterator pit = branches_->begin(), pitEnd = branches_->end(); pit != pitEnd; ++pit) { 00102 item.addGroup(pit->second.branchDescription_); 00103 } 00104 } 00105 00106 template <typename T> 00107 boost::shared_ptr<BranchMapper> 00108 RootTree::makeBranchMapper() const { 00109 assert (branchEntryInfoBranch_); 00110 boost::shared_ptr<BranchMapper> mapper(new BranchMapperWithReader<T>(branchEntryInfoBranch_, entryNumber_)); 00111 return mapper; 00112 } 00113 00114 } 00115 #endif