CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/FWCore/FWLite/src/BranchMapReader.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     FWLite
00004 // Class  :     BranchMapReader
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Dan Riley
00010 //         Created:  Tue May 20 10:31:32 EDT 2008
00011 //
00012 
00013 // system include files
00014 
00015 // user include files
00016 #include "FWCore/FWLite/interface/BranchMapReader.h"
00017 
00018 #include "DataFormats/Provenance/interface/BranchIDList.h"
00019 #include "DataFormats/Provenance/interface/BranchListIndex.h"
00020 #include "DataFormats/Provenance/interface/BranchType.h"
00021 #include "DataFormats/Provenance/interface/EventEntryInfo.h"
00022 #include "DataFormats/Provenance/interface/EventSelectionID.h"
00023 #include "DataFormats/Provenance/interface/FileFormatVersion.h"
00024 #include "DataFormats/Provenance/interface/History.h"
00025 #include "DataFormats/Provenance/interface/ProductIDToBranchID.h"
00026 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00027 #include "FWCore/Utilities/interface/EDMException.h"
00028 
00029 #include "TBranch.h"
00030 #include "TFile.h"
00031 #include "TTree.h"
00032 
00033 namespace fwlite {
00034   namespace internal {
00035 
00036     static const edm::BranchDescription kDefaultBranchDescription;
00037 
00038     BMRStrategy::BMRStrategy(TFile* file, int fileVersion)
00039       : currentFile_(file), eventTree_(0), luminosityBlockTree_(0), runTree_(0),
00040         eventEntry_(-1), luminosityBlockEntry_(-1), runEntry_(-1), fileVersion_(fileVersion) {
00041       // do in derived obects
00042       // updateFile(file);
00043     }
00044 
00045     BMRStrategy::~BMRStrategy() {
00046     }
00047 
00048     class Strategy : public BMRStrategy {
00049     public:
00050       typedef std::map<edm::BranchID, edm::BranchDescription> bidToDesc;
00051 
00052       Strategy(TFile* file, int fileVersion);
00053       virtual ~Strategy();
00054       virtual bool updateFile(TFile* file);
00055       virtual bool updateEvent(Long_t eventEntry) { eventEntry_ = eventEntry; return true; }
00056       virtual bool updateLuminosityBlock(Long_t luminosityBlockEntry) {
00057         luminosityBlockEntry_ = luminosityBlockEntry;
00058         return true;
00059       }
00060       virtual bool updateRun(Long_t runEntry) {
00061         runEntry_ = runEntry;
00062         return true;
00063       }
00064       virtual bool updateMap() { return true; }
00065       virtual edm::BranchID productToBranchID(edm::ProductID const& pid);
00066       virtual edm::BranchDescription const& productToBranch(edm::ProductID const& pid);
00067       virtual std::vector<edm::BranchDescription> const& getBranchDescriptions();
00068 
00069       TBranch* getBranchRegistry(edm::ProductRegistry** pReg);
00070 
00071       bidToDesc branchDescriptionMap_;
00072       std::vector<edm::BranchDescription> bDesc_;
00073       bool mapperFilled_;
00074     };
00075 
00076     Strategy::Strategy(TFile* file, int fileVersion)
00077       : BMRStrategy(file, fileVersion), mapperFilled_(false) {
00078       // do in derived obects
00079       // updateFile(file);
00080     }
00081 
00082     Strategy::~Strategy() {
00083       // probably need to clean up something here...
00084     }
00085 
00086     bool Strategy::updateFile(TFile* file) {
00087       currentFile_ = file;
00088       eventTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventTreeName().c_str()));
00089       luminosityBlockTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::luminosityBlockTreeName().c_str()));
00090       runTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::runTreeName().c_str()));
00091       fileUUID_ = currentFile_->GetUUID();
00092       branchDescriptionMap_.clear();
00093       bDesc_.clear();
00094       return 0 != eventTree_;
00095     }
00096 
00097     TBranch* Strategy::getBranchRegistry(edm::ProductRegistry** ppReg) {
00098       TBranch* bReg(0);
00099 
00100       TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
00101       if(0 != metaDataTree) {
00102         bReg = metaDataTree->GetBranch(edm::poolNames::productDescriptionBranchName().c_str());
00103         bReg->SetAddress(ppReg);
00104         bReg->GetEntry(0);
00105         (*ppReg)->setFrozen(false);
00106       }
00107       return bReg;
00108     }
00109 
00110     std::vector<edm::BranchDescription> const&
00111     Strategy::getBranchDescriptions() {
00112       if(bDesc_.empty()) {
00113         for(bidToDesc::const_iterator i = branchDescriptionMap_.begin(); i != branchDescriptionMap_.end(); ++i) {
00114           bDesc_.push_back(i->second);
00115         }
00116       }
00117       return bDesc_;
00118     }
00119 
00120     edm::BranchID
00121     Strategy::productToBranchID(edm::ProductID const&) {
00122       throw edm::Exception(edm::errors::UnimplementedFeature) << "Unsupported EDM file version";
00123     }
00124 
00125     edm::BranchDescription const &
00126     Strategy::productToBranch(edm::ProductID const& pid) {
00127       edm::BranchID bid = productToBranchID(pid);
00128       bidToDesc::const_iterator bdi = branchDescriptionMap_.find(bid);
00129       if(branchDescriptionMap_.end() == bdi) {
00130         return kDefaultBranchDescription;
00131       }
00132       return bdi->second;
00133     }
00134 
00135     class BranchMapReaderStrategyV1 : public Strategy {
00136     public:
00137       BranchMapReaderStrategyV1(TFile* file, int fileVersion);
00138       virtual bool updateFile(TFile* file);
00139       virtual bool updateMap();
00140       virtual edm::BranchListIndexes const& branchListIndexes() const {return dummyBranchListIndexes_;}
00141     private:
00142       edm::BranchListIndexes dummyBranchListIndexes_;
00143     };
00144 
00145     BranchMapReaderStrategyV1::BranchMapReaderStrategyV1(TFile* file, int fileVersion)
00146       : Strategy(file, fileVersion) {
00147       updateFile(file);
00148     }
00149 
00150     bool BranchMapReaderStrategyV1::updateFile(TFile* file) {
00151       if(Strategy::updateFile(file)) {
00152         mapperFilled_ = false;
00153         return true;
00154       }
00155       return false;
00156     }
00157 
00158     bool BranchMapReaderStrategyV1::updateMap() {
00159       if(mapperFilled_) {
00160         return true;
00161       }
00162 
00163       branchDescriptionMap_.clear();
00164       bDesc_.clear();
00165 
00166       edm::ProductRegistry reg;
00167       edm::ProductRegistry* pReg = &reg;
00168       TBranch* br = getBranchRegistry(&pReg);
00169 
00170       if(0 != br) {
00171         edm::ProductRegistry::ProductList const& prodList = reg.productList();
00172 
00173         for(edm::ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd; ++it) {
00174           if(edm::InEvent == it->second.branchType()) {
00175             // call to regenerate branchName
00176             it->second.init();
00177             branchDescriptionMap_.insert(bidToDesc::value_type(it->second.branchID(), it->second));
00178           }
00179         }
00180         mapperFilled_ = true;
00181       }
00182       return 0 != br;
00183     }
00184 
00185     // v7 has differences in product status that are not implemented in BranchMapReader yet
00186     class BranchMapReaderStrategyV7 : public BranchMapReaderStrategyV1 {
00187     public:
00188       BranchMapReaderStrategyV7(TFile* file, int fileVersion);
00189       virtual edm::BranchListIndexes const& branchListIndexes() const {return dummyBranchListIndexes_;}
00190     private:
00191       edm::BranchListIndexes dummyBranchListIndexes_;
00192     };
00193 
00194     BranchMapReaderStrategyV7::BranchMapReaderStrategyV7(TFile* file, int fileVersion)
00195     : BranchMapReaderStrategyV1(file, fileVersion) {
00196       updateFile(file);
00197     }
00198 
00199     class BranchMapReaderStrategyV8 : public Strategy {
00200     public:
00201       BranchMapReaderStrategyV8(TFile* file, int fileVersion);
00202       virtual bool updateFile(TFile* file);
00203       virtual bool updateEvent(Long_t eventEntry);
00204       virtual bool updateLuminosityBlock(Long_t luminosityBlockEntry);
00205       virtual bool updateRun(Long_t runEntry);
00206       virtual bool updateMap();
00207       virtual edm::BranchListIndexes const& branchListIndexes() const {return dummyBranchListIndexes_;}
00208     private:
00209       TBranch* entryInfoBranch_;
00210       edm::EventEntryInfoVector  eventEntryInfoVector_;
00211       edm::EventEntryInfoVector* pEventEntryInfoVector_;
00212       edm::BranchListIndexes dummyBranchListIndexes_;
00213     };
00214 
00215     BranchMapReaderStrategyV8::BranchMapReaderStrategyV8(TFile* file, int fileVersion)
00216     : Strategy(file, fileVersion),
00217       eventEntryInfoVector_(), pEventEntryInfoVector_(&eventEntryInfoVector_) {
00218       updateFile(file);
00219     }
00220 
00221     bool BranchMapReaderStrategyV8::updateEvent(Long_t newevent) {
00222       // std::cout << "v8 updateevent " << newevent << std::endl;
00223       if(newevent != eventEntry_) {
00224         eventEntry_ = newevent;
00225         mapperFilled_ = false;
00226       }
00227       return true;
00228     }
00229 
00230     bool BranchMapReaderStrategyV8::updateLuminosityBlock(Long_t newLumi) {
00231       if(newLumi != luminosityBlockEntry_) {
00232         luminosityBlockEntry_ = newLumi;
00233         mapperFilled_ = false;
00234       }
00235       return true;
00236     }
00237 
00238     bool BranchMapReaderStrategyV8::updateRun(Long_t newRun) {
00239       if(newRun != runEntry_) {
00240         runEntry_ = newRun;
00241         mapperFilled_ = false;
00242       }
00243       return true;
00244     }
00245 
00246     bool BranchMapReaderStrategyV8::updateFile(TFile* file) {
00247       Strategy::updateFile(file);
00248       mapperFilled_ = false;
00249       entryInfoBranch_ = 0;
00250       TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventMetaDataTreeName().c_str()));
00251       if(0 != metaDataTree) {
00252         entryInfoBranch_ = metaDataTree->GetBranch(BranchTypeToBranchEntryInfoBranchName(edm::InEvent).c_str());
00253 //         std::cout << "entryInfoBranch for " << BranchTypeToBranchEntryInfoBranchName(edm::InEvent) << " " << entryInfoBranch_ << std::endl;
00254       } else {
00255         return false;
00256       }
00257       pEventEntryInfoVector_ = &eventEntryInfoVector_;
00258       entryInfoBranch_->SetAddress(&pEventEntryInfoVector_);
00259 
00260       branchDescriptionMap_.clear();
00261       bDesc_.clear();
00262 
00263       edm::ProductRegistry reg;
00264       edm::ProductRegistry* pReg = &reg;
00265       TBranch *br = getBranchRegistry(&pReg);
00266 
00267       if(0 != br) {
00268         edm::ProductRegistry::ProductList const& prodList = reg.productList();
00269 
00270         for(edm::ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd; ++it) {
00271           if(edm::InEvent == it->second.branchType()) {
00272             // call to regenerate branchName
00273             it->second.init();
00274             branchDescriptionMap_.insert(bidToDesc::value_type(it->second.branchID(), it->second));
00275           }
00276         }
00277       }
00278       return 0 != br;
00279     }
00280 
00281     bool BranchMapReaderStrategyV8::updateMap() {
00282       if(mapperFilled_) {
00283         return true;
00284       }
00285 
00286       assert(entryInfoBranch_);
00287 
00288       entryInfoBranch_->GetEntry(eventEntry_);
00289 
00290       for(std::vector<edm::EventEntryInfo>::const_iterator it = pEventEntryInfoVector_->begin(),
00291            itEnd = pEventEntryInfoVector_->end();
00292            it != itEnd; ++it) {
00293 //         eventInfoMap_.insert(*it);
00294       }
00295       mapperFilled_ = true;
00296       return true;
00297     }
00298 
00299     class BranchMapReaderStrategyV11 : public Strategy {
00300     public:
00301       BranchMapReaderStrategyV11(TFile* file, int fileVersion);
00302       virtual bool updateFile(TFile* file);
00303       virtual bool updateEvent(Long_t eventEntry);
00304       virtual bool updateLuminosityBlock(Long_t luminosityBlockEntry);
00305       virtual bool updateRun(Long_t runEntry);
00306       virtual bool updateMap();
00307       virtual edm::BranchID productToBranchID(edm::ProductID const& pid);
00308       virtual edm::BranchListIndexes const& branchListIndexes() const {return history_.branchListIndexes();}
00309     private:
00310       std::auto_ptr<edm::BranchIDLists> branchIDLists_;
00311       TTree* eventHistoryTree_;
00312       edm::History history_;
00313       edm::History* pHistory_;
00314     };
00315 
00316     BranchMapReaderStrategyV11::BranchMapReaderStrategyV11(TFile* file, int fileVersion)
00317     : Strategy(file, fileVersion), eventHistoryTree_(0), pHistory_(&history_) {
00318       updateFile(file);
00319     }
00320 
00321     bool BranchMapReaderStrategyV11::updateEvent(Long_t newevent) {
00322 //      std::cout << "v11 updateevent " << newevent << std::endl;
00323       if(newevent != eventEntry_) {
00324         eventEntry_ = newevent;
00325         mapperFilled_ = false;
00326       }
00327       return true;
00328     }
00329 
00330     bool BranchMapReaderStrategyV11::updateLuminosityBlock(Long_t newlumi) {
00331       if(newlumi != luminosityBlockEntry_) {
00332         luminosityBlockEntry_ = newlumi;
00333         mapperFilled_ = false;
00334       }
00335       return true;
00336     }
00337 
00338     bool BranchMapReaderStrategyV11::updateRun(Long_t newRun) {
00339       if(newRun != runEntry_) {
00340         runEntry_ = newRun;
00341         mapperFilled_ = false;
00342       }
00343       return true;
00344     }
00345 
00346     bool BranchMapReaderStrategyV11::updateFile(TFile* file) {
00347       Strategy::updateFile(file);
00348       mapperFilled_ = false;
00349       TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
00350 
00351       if(0 == metaDataTree) {
00352          throw edm::Exception(edm::errors::EventCorruption)
00353            <<"No "<<edm::poolNames::metaDataTreeName()<<" TTree in file";
00354       }
00355       branchIDLists_.reset(new edm::BranchIDLists);
00356       edm::BranchIDLists* branchIDListsPtr = branchIDLists_.get();
00357       if(metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != 0) {
00358         TBranch* b = metaDataTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str());
00359         b->SetAddress(&branchIDListsPtr);
00360         b->GetEntry(0);
00361 //         std::cout << "--> " << branchIDLists_->size() << std::endl;
00362       } else {
00363         throw edm::Exception(edm::errors::EventCorruption)
00364           << "FindBranch of branchIDList failed";
00365         return false;
00366       }
00367 
00368       eventHistoryTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventHistoryTreeName().c_str()));
00369 
00370       branchDescriptionMap_.clear();
00371       bDesc_.clear();
00372 
00373       edm::ProductRegistry reg;
00374       edm::ProductRegistry* pReg = &reg;
00375       TBranch *br = getBranchRegistry(&pReg);
00376 
00377       if(0 != br) {
00378         edm::ProductRegistry::ProductList const& prodList = reg.productList();
00379 
00380         for(edm::ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd; ++it) {
00381           if(edm::InEvent == it->second.branchType()) {
00382             // call to regenerate branchName
00383             it->second.init();
00384             branchDescriptionMap_.insert(bidToDesc::value_type(it->second.branchID(), it->second));
00385 //             std::cout << "v11 updatefile " << it->second.branchID() << std::endl;
00386                 }
00387               }
00388       }
00389       return 0 != br;
00390     }
00391 
00392     bool BranchMapReaderStrategyV11::updateMap() {
00393       if(!mapperFilled_) {
00394         TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
00395         if(!eventHistoryBranch) {
00396           throw edm::Exception(edm::errors::EventCorruption)
00397             << "Failed to find history branch in event history tree";
00398           return false;
00399         }
00400         // yes, SetAddress really does need to be called every time...
00401         eventHistoryBranch->SetAddress(&pHistory_);
00402         eventHistoryTree_->GetEntry(eventEntry_);
00403         mapperFilled_ = true;
00404       }
00405       return true;
00406     }
00407 
00408     edm::BranchID
00409     BranchMapReaderStrategyV11::productToBranchID(edm::ProductID const& pid) {
00410       updateMap();
00411       return edm::productIDToBranchID(pid, *branchIDLists_, history_.branchListIndexes());
00412     }
00413 
00414     class BranchMapReaderStrategyV17 : public Strategy {
00415     public:
00416       BranchMapReaderStrategyV17(TFile* file, int fileVersion);
00417       virtual bool updateFile(TFile* file);
00418       virtual bool updateEvent(Long_t eventEntry);
00419       virtual bool updateLuminosityBlock(Long_t luminosityBlockEntry);
00420       virtual bool updateRun(Long_t runEntry);
00421       virtual bool updateMap();
00422       virtual edm::BranchID productToBranchID(edm::ProductID const& pid);
00423       virtual edm::BranchListIndexes const& branchListIndexes() const {return branchListIndexes_;}
00424     private:
00425       std::auto_ptr<edm::BranchIDLists> branchIDLists_;
00426       TTree* eventsTree_;
00427       edm::BranchListIndexes branchListIndexes_;
00428       edm::BranchListIndexes* pBranchListIndexes_;
00429     };
00430 
00431     BranchMapReaderStrategyV17::BranchMapReaderStrategyV17(TFile* file, int fileVersion)
00432     : Strategy(file, fileVersion), eventsTree_(0), pBranchListIndexes_(&branchListIndexes_) {
00433       updateFile(file);
00434     }
00435 
00436     bool BranchMapReaderStrategyV17::updateEvent(Long_t newevent) {
00437 //      std::cout << "v11 updateevent " << newevent << std::endl;
00438       if(newevent != eventEntry_) {
00439         eventEntry_ = newevent;
00440         mapperFilled_ = false;
00441       }
00442       return true;
00443     }
00444 
00445     bool BranchMapReaderStrategyV17::updateLuminosityBlock(Long_t newlumi) {
00446       if(newlumi != luminosityBlockEntry_) {
00447         luminosityBlockEntry_ = newlumi;
00448         mapperFilled_ = false;
00449       }
00450       return true;
00451     }
00452 
00453     bool BranchMapReaderStrategyV17::updateRun(Long_t newRun) {
00454       if(newRun != runEntry_) {
00455         runEntry_ = newRun;
00456         mapperFilled_ = false;
00457       }
00458       return true;
00459     }
00460 
00461     bool BranchMapReaderStrategyV17::updateFile(TFile* file) {
00462       Strategy::updateFile(file);
00463       mapperFilled_ = false;
00464       TTree* metaDataTree = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::metaDataTreeName().c_str()));
00465       if(0==metaDataTree) {
00466          throw edm::Exception(edm::errors::EventCorruption) <<"No "<<edm::poolNames::metaDataTreeName()<<" TTree in file";
00467       }
00468       branchIDLists_.reset(new edm::BranchIDLists);
00469       edm::BranchIDLists* branchIDListsPtr = branchIDLists_.get();
00470       if(metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != 0) {
00471         TBranch* b = metaDataTree->GetBranch(edm::poolNames::branchIDListBranchName().c_str());
00472         b->SetAddress(&branchIDListsPtr);
00473         b->GetEntry(0);
00474 //         std::cout << "--> " << branchIDLists_->size() << std::endl;
00475       } else {
00476         throw edm::Exception(edm::errors::EventCorruption)
00477           << "FindBranch of branchIDList failed";
00478         return false;
00479       }
00480 
00481       eventsTree_ = dynamic_cast<TTree*>(currentFile_->Get(edm::poolNames::eventTreeName().c_str()));
00482 
00483       branchDescriptionMap_.clear();
00484       bDesc_.clear();
00485 
00486       edm::ProductRegistry reg;
00487       edm::ProductRegistry* pReg = &reg;
00488       TBranch *br = getBranchRegistry(&pReg);
00489 
00490       if(0 != br) {
00491         edm::ProductRegistry::ProductList const& prodList = reg.productList();
00492 
00493         for(edm::ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end(); it != itEnd; ++it) {
00494           if(edm::InEvent == it->second.branchType()) {
00495             // call to regenerate branchName
00496             it->second.init();
00497             branchDescriptionMap_.insert(bidToDesc::value_type(it->second.branchID(), it->second));
00498 //             std::cout << "v11 updatefile " << it->second.branchID() << std::endl;
00499                 }
00500               }
00501       }
00502       return 0 != br;
00503     }
00504 
00505     bool BranchMapReaderStrategyV17::updateMap() {
00506       if(!mapperFilled_) {
00507         TBranch* branchListIndexesBranch = eventsTree_->GetBranch(edm::poolNames::branchListIndexesBranchName().c_str());
00508         if(!branchListIndexesBranch) {
00509           throw edm::Exception(edm::errors::EventCorruption)
00510             << "Failed to find branch list indexes branch in event tree";
00511           return false;
00512         }
00513         // yes, SetAddress really does need to be called every time...
00514         branchListIndexesBranch->SetAddress(&pBranchListIndexes_);
00515         branchListIndexesBranch->GetEntry(eventEntry_);
00516         mapperFilled_ = true;
00517       }
00518       return true;
00519     }
00520 
00521     edm::BranchID
00522     BranchMapReaderStrategyV17::productToBranchID(edm::ProductID const& pid) {
00523       updateMap();
00524       return edm::productIDToBranchID(pid, *branchIDLists_, branchListIndexes_);
00525     }
00526   }
00527 
00528 //
00529 // constants, enums and typedefs
00530 //
00531 
00532 //
00533 // static data member definitions
00534 //
00535 
00536 //
00537 // constructors and destructor
00538 //
00539 
00540 BranchMapReader::BranchMapReader(TFile* file) :
00541     fileVersion_(-1) {
00542   if(0==file) {
00543      throw cms::Exception("NoFile")<<"The TFile pointer is null";
00544   }
00545   strategy_ = newStrategy(file, getFileVersion(file));
00546 }
00547 
00548 //
00549 // member functions
00550 //
00551 
00552 int BranchMapReader::getFileVersion(TFile* file) {
00553   TTree* metaDataTree = dynamic_cast<TTree*>(file->Get(edm::poolNames::metaDataTreeName().c_str()));
00554   if(0==metaDataTree) {
00555     return 0;
00556   }
00557 
00558   edm::FileFormatVersion v;
00559   edm::FileFormatVersion* pV=&v;
00560   TBranch* bVer = metaDataTree->GetBranch(edm::poolNames::fileFormatVersionBranchName().c_str());
00561   bVer->SetAddress(&pV);
00562   bVer->GetEntry(0);
00563   fileVersion_ = v.value();
00564   return v.value();
00565 }
00566 
00567 bool BranchMapReader::updateEvent(Long_t newevent) {
00568   return strategy_->updateEvent(newevent);
00569 }
00570 
00571 bool BranchMapReader::updateLuminosityBlock(Long_t newlumi) {
00572   return strategy_->updateLuminosityBlock(newlumi);
00573 }
00574 
00575 bool BranchMapReader::updateRun(Long_t newRun) {
00576   return strategy_->updateRun(newRun);
00577 }
00578 
00579 bool BranchMapReader::updateFile(TFile* file) {
00580   if(0 == strategy_.get()) {
00581     strategy_ = newStrategy(file, getFileVersion(file));
00582     return true;
00583   }
00584 
00585   TFile* currentFile(strategy_->currentFile_);
00586   bool isNew(file != currentFile);
00587 
00588   if(!isNew) {
00589     //could still have a new TFile which just happens to share the same memory address as the previous file
00590     //will assume that if the Event tree's address and UUID are the same as before then we do not have
00591     // to treat this like a new file
00592     TTree* eventTreeTemp = dynamic_cast<TTree*>(currentFile->Get(edm::poolNames::eventTreeName().c_str()));
00593     isNew = eventTreeTemp != strategy_->eventTree_ || strategy_->fileUUID_ != currentFile->GetUUID();
00594   }
00595   if(isNew) {
00596     int fileVersion = getFileVersion(file);
00597     if(fileVersion != strategy_->fileVersion_) {
00598       strategy_ = newStrategy(file, fileVersion);
00599     } else {
00600       strategy_->updateFile(file);
00601     }
00602   }
00603   return isNew;
00604 }
00605 
00606 edm::BranchDescription const &
00607 BranchMapReader::productToBranch(edm::ProductID const& pid) {
00608   return strategy_->productToBranch(pid);
00609 }
00610 
00611 std::vector<edm::BranchDescription> const&
00612 BranchMapReader::getBranchDescriptions() {
00613   return strategy_->getBranchDescriptions();
00614 }
00615 
00616 
00617 std::auto_ptr<internal::BMRStrategy>
00618 BranchMapReader::newStrategy(TFile* file, int fileVersion) {
00619   std::auto_ptr<internal::BMRStrategy> s;
00620 
00621   if(fileVersion >= 17) {
00622     s = std::auto_ptr<internal::BMRStrategy>(new internal::BranchMapReaderStrategyV17(file, fileVersion));
00623   } else if(fileVersion >= 11) {
00624     s = std::auto_ptr<internal::BMRStrategy>(new internal::BranchMapReaderStrategyV11(file, fileVersion));
00625   } else if(fileVersion >= 8) {
00626     s = std::auto_ptr<internal::BMRStrategy>(new internal::BranchMapReaderStrategyV8(file, fileVersion));
00627   } else if(fileVersion >= 7) {
00628     s = std::auto_ptr<internal::BMRStrategy>(new internal::BranchMapReaderStrategyV7(file, fileVersion));
00629   } else {
00630     s = std::auto_ptr<internal::BMRStrategy>(new internal::BranchMapReaderStrategyV1(file, fileVersion));
00631   }
00632   return s;
00633 }
00634 }