CMS 3D CMS Logo

TFWLiteSelectorBasic Class Reference

Description: A ROOT TSelector which accesses data using an edm::Event. More...

#include <FWCore/FWLite/interface/TFWLiteSelectorBasic.h>

Inheritance diagram for TFWLiteSelectorBasic:

TFWLiteSelector< TWorker > TFWLiteSelector< examples::TrackAnalysisAlgorithm > TFWLiteSelector< tfwliteselectortest::ThingsWorker > TFWLiteSelector< tselnameWorker > tfwliteselectortest::ThingsTSelector examples::TrackTSelector tfwliteselectortest::ThingsTSelector2 tselname

List of all members.

Public Member Functions

virtual void begin (TList *&in)=0
 Called each time the 'client' begins processing (remote 'slaves' do not see this message).
virtual void postProcessing (TList &out)=0
 Called each time the 'slave' has seen all the events.
virtual void preProcessing (const TList *in, TList &out)=0
 Called each time the 'slave' is about to start processing.
virtual void process (const edm::Event &event)=0
 Call each time the 'slave' gets a new Event.
virtual void terminate (TList &out)=0
 Called each time the 'client' has finished processing.
 TFWLiteSelectorBasic ()
virtual ~TFWLiteSelectorBasic ()

Private Member Functions

virtual void Begin (TTree *)
virtual void Init (TTree *)
virtual Bool_t Notify ()
const TFWLiteSelectorBasicoperator= (const TFWLiteSelectorBasic &)
virtual Bool_t Process (Long64_t)
void setupNewFile (TFile &)
virtual void SlaveBegin (TTree *)
virtual void SlaveTerminate ()
virtual void Terminate ()
 TFWLiteSelectorBasic (const TFWLiteSelectorBasic &)
virtual Int_t Version () const

Private Attributes

bool everythingOK_
edm::root::TFWLiteSelectorMembersm_


Detailed Description

Description: A ROOT TSelector which accesses data using an edm::Event.

Usage: By inheriting from this class one can make a TSelector for ROOT which works with PROOF and which allows you to access data using an edm::Event.

Definition at line 41 of file TFWLiteSelectorBasic.h.


Constructor & Destructor Documentation

TFWLiteSelectorBasic::TFWLiteSelectorBasic (  ) 

Definition at line 176 of file TFWLiteSelectorBasic.cc.

00176                                            : m_(new edm::root::TFWLiteSelectorMembers),
00177                                      everythingOK_(false)
00178 {
00179 }

TFWLiteSelectorBasic::~TFWLiteSelectorBasic (  )  [virtual]

Definition at line 186 of file TFWLiteSelectorBasic.cc.

References m_.

00187 {
00188   delete m_;
00189 }

TFWLiteSelectorBasic::TFWLiteSelectorBasic ( const TFWLiteSelectorBasic  )  [private]


Member Function Documentation

void TFWLiteSelectorBasic::Begin ( TTree *  iTree  )  [private, virtual]

Definition at line 207 of file TFWLiteSelectorBasic.cc.

References begin(), and Init().

00207                                          { 
00208   Init(iTree);
00209   begin(fInput);
00210 }

virtual void TFWLiteSelectorBasic::begin ( TList *&  in  )  [pure virtual]

Called each time the 'client' begins processing (remote 'slaves' do not see this message).

Parameters:
in an assignable pointer to a list of objects you want passed to 'preProcessing'. This list is used to communicate with remote slaves. NOTE: you are responsible for deleting this TList and its content once you are done with it.

Implemented in tselname, tfwliteselectortest::ThingsTSelector, tfwliteselectortest::ThingsTSelector2, and examples::TrackTSelector.

Referenced by Begin().

void TFWLiteSelectorBasic::Init ( TTree *  iTree  )  [private, virtual]

Definition at line 219 of file TFWLiteSelectorBasic.cc.

References m_, and edm::root::TFWLiteSelectorMembers::setTree().

Referenced by Begin(), and SlaveBegin().

00219                                        { 
00220   if(iTree==0) return;
00221   m_->setTree(iTree);
00222 }

Bool_t TFWLiteSelectorBasic::Notify (  )  [private, virtual]

Definition at line 226 of file TFWLiteSelectorBasic.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), everythingOK_, file, m_, setupNewFile(), and edm::root::TFWLiteSelectorMembers::tree_.

00226                              { 
00227    //std::cout <<"Notify start"<<std::endl;
00228   //we have switched to a new file  
00229   //get new file from Tree
00230   if(0==m_->tree_) {
00231     std::cout <<"No tree"<<std::endl;
00232     return kFALSE;
00233   }
00234   TFile* file = m_->tree_->GetCurrentFile();
00235   if(0 == file) {
00236      //When in Rome, do as the Romans
00237      TChain* chain = dynamic_cast<TChain*>(m_->tree_);
00238      if(0 == chain) {
00239         std::cout <<"No file"<<std::endl;
00240         return kFALSE;
00241      }
00242      file = chain->GetFile();
00243      if(0==file) {
00244         std::cout <<"No file"<<std::endl;
00245         return kFALSE;
00246      }
00247   }
00248   setupNewFile(*file);
00249   return everythingOK_ ? kTRUE: kFALSE; 
00250 }

const TFWLiteSelectorBasic& TFWLiteSelectorBasic::operator= ( const TFWLiteSelectorBasic  )  [private]

virtual void TFWLiteSelectorBasic::postProcessing ( TList &  out  )  [pure virtual]

Called each time the 'slave' has seen all the events.

Parameters:
out the list of objects that will be sent to 'terminate'. You can Add() additional objects to 'out' at this point as well.

Implemented in TFWLiteSelector< TWorker >, tfwliteselectortest::ThingsTSelector, TFWLiteSelector< tselnameWorker >, TFWLiteSelector< tfwliteselectortest::ThingsWorker >, and TFWLiteSelector< examples::TrackAnalysisAlgorithm >.

Referenced by SlaveTerminate().

virtual void TFWLiteSelectorBasic::preProcessing ( const TList *  in,
TList &  out 
) [pure virtual]

Called each time the 'slave' is about to start processing.

Parameters:
in a pointer to the list of objects created in 'begin()'. The pointer can be 0
out a list of objects that are the result of processing (e.g. histograms). You should call 'Add()' for each object you want sent to the 'terminate' method.

Implemented in TFWLiteSelector< TWorker >, tfwliteselectortest::ThingsTSelector, TFWLiteSelector< tselnameWorker >, TFWLiteSelector< tfwliteselectortest::ThingsWorker >, and TFWLiteSelector< examples::TrackAnalysisAlgorithm >.

Referenced by SlaveBegin().

Bool_t TFWLiteSelectorBasic::Process ( Long64_t  iEntry  )  [private, virtual]

Definition at line 253 of file TFWLiteSelectorBasic.cc.

References edm::aux, edm::BranchTypeToAuxiliaryBranchName(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), event(), edm::poolNames::eventHistoryBranchName(), edm::root::TFWLiteSelectorMembers::eventHistoryTree_, everythingOK_, exception, edm::errors::FatalRootError, edm::root::TFWLiteSelectorMembers::fileFormatVersion_, edm::InEvent, edm::lumiAux, m_, process(), edm::EventAuxiliary::processHistoryID(), edm::History::processHistoryID(), edm::EventAuxiliary::processHistoryID_, edm::root::TFWLiteSelectorMembers::processNames_, edm::root::TFWLiteSelectorMembers::productMap_, edm::root::TFWLiteSelectorMembers::reader_, edm::root::TFWLiteSelectorMembers::reg_, edm::EventAuxiliary::run(), edm::runAux, edm::EventAuxiliary::time(), edm::root::TFWLiteSelectorMembers::tree_, and edm::FileFormatVersion::value_.

00253                                              { 
00254    //std::cout <<"Process start"<<std::endl;
00255    if(everythingOK_) {
00256       edm::EventAuxiliary aux;
00257       edm::EventAuxiliary* pAux= &aux;
00258       TBranch* branch = m_->tree_->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InEvent).c_str());
00259 
00260       branch->SetAddress(&pAux);
00261       //provBranch->SetAddress(&pProv);
00262       branch->GetEntry(iEntry);
00263       //provBranch->GetEntry(iEntry);
00264       //CDJ turn off reading meta tree until we fix handling of provenance
00265       //m_->metaTree_->GetEntry(iEntry);
00266 
00267 //NEW      m_->processNames_ = aux.processHistory();
00268 
00269 //      std::cout <<"ProcessNames\n";
00270 //      for(edm::ProcessNameList::const_iterator itName = m_->processNames_.begin(),
00271 //        itNameEnd = m_->processNames_.end();
00272 //        itName != itNameEnd;
00273 //        ++itName) {
00274 //       std::cout <<"  "<<*itName<< std::endl;
00275       //     }
00276 
00277       edm::History history;
00278       if (m_->fileFormatVersion_.value_ >= 7) {
00279          edm::History* pHistory = &history;
00280          TBranch* eventHistoryBranch = m_->eventHistoryTree_->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
00281          if (!eventHistoryBranch)
00282             throw edm::Exception(edm::errors::FatalRootError)
00283             << "Failed to find history branch in event history tree";
00284          eventHistoryBranch->SetAddress(&pHistory);
00285          m_->eventHistoryTree_->GetEntry(iEntry);
00286          aux.processHistoryID_ = history.processHistoryID();
00287       }
00288       try {
00289          m_->reader_->setEntry(iEntry);
00290          edm::ProcessConfiguration pc;
00291          boost::shared_ptr<edm::ProductRegistry const> reg(m_->reg_);
00292          edm::RunAuxiliary runAux(aux.run(), aux.time(), aux.time());
00293          boost::shared_ptr<edm::RunPrincipal> rp(new edm::RunPrincipal(runAux, reg, pc));
00294          edm::LuminosityBlockAuxiliary lumiAux(rp->run(), 1, aux.time(), aux.time());
00295          boost::shared_ptr<edm::LuminosityBlockPrincipal>lbp(
00296             new edm::LuminosityBlockPrincipal(lumiAux, reg, pc));
00297          lbp->setRunPrincipal(rp);
00298          boost::shared_ptr<edm::BranchMapper> mapper(new edm::BranchMapper);
00299          edm::EventPrincipal ep(aux, reg, pc, aux.processHistoryID(), mapper, m_->reader_);
00300          ep.setLuminosityBlockPrincipal(lbp);
00301          ep.setHistory(history);
00302          m_->processNames_ = ep.processHistory();
00303 
00304          using namespace edm;
00305          std::map<ProductID, BranchDescription>::iterator pit = m_->productMap_.begin();
00306          std::map<ProductID, BranchDescription>::iterator pitEnd = m_->productMap_.end();
00307          for (; pit != pitEnd; ++pit) {
00308             BranchDescription &product = pit->second;
00309             if (not product.oldProductID().isValid()) continue;
00310             ep.addGroup(edm::ConstBranchDescription(product));
00311          }
00312 
00313          edm::ModuleDescription md;
00314          edm::Event event(ep,md);
00315          
00316          //Make the event principal accessible to edm::Ref's
00317          edm::EDProductGetter::Operate sentry(ep.prodGetter());
00318          process(event);
00319       } catch( const std::exception& iEx ) {
00320          std::cout <<"While processing entry "<<iEntry<<" the following exception was caught \n"
00321                    <<iEx.what()<<std::endl;
00322       } catch(...) {
00323          std::cout <<"While processing entry "<<iEntry<<" an unknown exception was caught" << std::endl;
00324       }
00325    }
00326    //std::cout <<"Process end"<<std::endl;
00327   return kFALSE; 
00328 }

virtual void TFWLiteSelectorBasic::process ( const edm::Event event  )  [pure virtual]

Call each time the 'slave' gets a new Event.

Parameters:
event a standard edm::Event which works just like it does in cmsRun

Implemented in TFWLiteSelector< TWorker >, tfwliteselectortest::ThingsTSelector, TFWLiteSelector< tselnameWorker >, TFWLiteSelector< tfwliteselectortest::ThingsWorker >, and TFWLiteSelector< examples::TrackAnalysisAlgorithm >.

Referenced by Process().

void TFWLiteSelectorBasic::setupNewFile ( TFile &  iFile  )  [private]

Definition at line 341 of file TFWLiteSelectorBasic.cc.

References edm::BranchDescription::branchType(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), edm::root::TFWLiteSelectorMembers::eventHistoryTree_, edm::poolNames::eventHistoryTreeName(), edm::poolNames::eventMetaDataTreeName(), everythingOK_, edm::root::TFWLiteSelectorMembers::fileFormatVersion_, edm::poolNames::fileFormatVersionBranchName(), i, edm::InEvent, edm::BranchDescription::init(), edm::detail::ThreadSafeRegistry< KEY, T, E >::insertMapped(), edm::detail::ThreadSafeRegistry< KEY, T, E >::instance(), it, j, k, m_, edm::metaDataTree, edm::poolNames::metaDataTreeName(), edm::root::TFWLiteSelectorMembers::metaTree_, edm::poolNames::moduleDescriptionMapBranchName(), edm::poolNames::parameterSetMapBranchName(), edm::root::TFWLiteSelectorMembers::pointerToBranchBuffer_, edm::poolNames::processHistoryMapBranchName(), edm::poolNames::productDescriptionBranchName(), edm::ProductRegistry::productList(), edm::root::TFWLiteSelectorMembers::productMap_, edm::root::TFWLiteSelectorMembers::prov_, edm::root::TFWLiteSelectorMembers::reg_, pyDBSRunClass::temp, tmp, and edm::FileFormatVersion::value_.

Referenced by Notify().

00341                                                { 
00342   //look up meta-data
00343   //get product registry
00344   edm::ProductRegistry* pReg = &(*m_->reg_);
00345   typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> PsetMap;
00346   PsetMap psetMap;
00347   edm::ProcessHistoryMap pHistMap;
00348   edm::ModuleDescriptionMap mdMap;
00349   PsetMap *psetMapPtr = &psetMap;
00350   edm::ProcessHistoryMap *pHistMapPtr = &pHistMap;
00351   edm::ModuleDescriptionMap *mdMapPtr = &mdMap;
00352   edm::FileFormatVersion* fftPtr = &(m_->fileFormatVersion_);
00353    
00354   TTree* metaDataTree = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::metaDataTreeName().c_str()) );
00355   if ( 0 != metaDataTree) {
00356     metaDataTree->SetBranchAddress(edm::poolNames::productDescriptionBranchName().c_str(), &(pReg) );
00357     metaDataTree->SetBranchAddress(edm::poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
00358     metaDataTree->SetBranchAddress(edm::poolNames::processHistoryMapBranchName().c_str(), &pHistMapPtr);
00359     metaDataTree->SetBranchAddress(edm::poolNames::moduleDescriptionMapBranchName().c_str(), &mdMapPtr);
00360      metaDataTree->SetBranchAddress(edm::poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
00361     metaDataTree->GetEntry(0);
00362     m_->reg_->setFrozen();
00363   } else {
00364     std::cout <<"could not find TTree "<<edm::poolNames::metaDataTreeName() <<std::endl;
00365     everythingOK_ = false;
00366     return;
00367   }
00368   m_->metaTree_ = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::eventMetaDataTreeName().c_str()));
00369   if( 0 == m_->metaTree_) {
00370     std::cout <<"could not find TTree "<<edm::poolNames::eventMetaDataTreeName() <<std::endl;
00371     everythingOK_ = false;
00372     return;
00373   }
00374 
00375   // Merge into the registries. For now, we do NOT merge the product registry.
00376   edm::pset::Registry& psetRegistry = *edm::pset::Registry::instance();
00377   for (PsetMap::const_iterator i = psetMap.begin(), iEnd = psetMap.end();
00378       i != iEnd; ++i) {
00379     psetRegistry.insertMapped(edm::ParameterSet(i->second.pset_));
00380   } 
00381   edm::ProcessHistoryRegistry & processNameListRegistry = *edm::ProcessHistoryRegistry::instance();
00382   for (edm::ProcessHistoryMap::const_iterator j = pHistMap.begin(), jEnd = pHistMap.end();
00383       j != jEnd; ++j) {
00384     processNameListRegistry.insertMapped(j->second);
00385   } 
00386   edm::ModuleDescriptionRegistry & moduleDescriptionRegistry = *edm::ModuleDescriptionRegistry::instance();
00387   for (edm::ModuleDescriptionMap::const_iterator k = mdMap.begin(), kEnd = mdMap.end();
00388       k != kEnd; ++k) {
00389     moduleDescriptionRegistry.insertMapped(k->second);
00390   } 
00391   
00392   m_->productMap_.erase(m_->productMap_.begin(),m_->productMap_.end());
00393   m_->pointerToBranchBuffer_.erase(m_->pointerToBranchBuffer_.begin(),
00394                                    m_->pointerToBranchBuffer_.end());
00395   edm::ProductRegistry::ProductList const& prodList = pReg->productList();
00396   std::vector<edm::EventEntryDescription> temp( prodList.size(), edm::EventEntryDescription() );
00397   m_->prov_.swap( temp);
00398   std::vector<edm::EventEntryDescription>::iterator itB = m_->prov_.begin();
00399   m_->pointerToBranchBuffer_.reserve(prodList.size());
00400   for (edm::ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
00401        it != itEnd; ++it, ++itB) {
00402     edm::BranchDescription const& prod = it->second;
00403     if( prod.branchType() == edm::InEvent) {
00404       prod.init();
00405       //NEED to do this and check to see if branch exists
00406       //prod.present_ = (branch != 0);
00407       m_->productMap_.insert(std::make_pair(it->second.oldProductID(), it->second));
00408       //std::cout <<"id "<<it->second.oldProductID()<<" branch "<<it->second.branchName()<<std::endl;
00409       m_->pointerToBranchBuffer_.push_back( & (*itB));
00410       void* tmp = &(m_->pointerToBranchBuffer_.back());
00411       //edm::EventEntryDescription* tmp = & (*itB);
00412       //CDJ need to fix provenance and be backwards compatible, for now just don't read the branch
00413       //m_->metaTree_->SetBranchAddress( prod.branchName().c_str(), tmp);
00414     }
00415   }  
00416   //std::cout <<"Notify end"<<std::endl;
00417    
00418    if (m_->fileFormatVersion_.value_ >= 7) {
00419       m_->eventHistoryTree_ = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::eventHistoryTreeName().c_str()));
00420       if(0==m_->eventHistoryTree_) {
00421          std::cout <<"could not find TTree "<<edm::poolNames::eventHistoryTreeName() <<std::endl;
00422          everythingOK_ = false;
00423          return;
00424       }
00425    }
00426   everythingOK_ = true;
00427 }

void TFWLiteSelectorBasic::SlaveBegin ( TTree *  iTree  )  [private, virtual]

Definition at line 213 of file TFWLiteSelectorBasic.cc.

References Init(), and preProcessing().

00213                                              { 
00214   Init(iTree);
00215   preProcessing(fInput,*fOutput);
00216 }

void TFWLiteSelectorBasic::SlaveTerminate (  )  [private, virtual]

Definition at line 331 of file TFWLiteSelectorBasic.cc.

References postProcessing().

00331                                      { 
00332   postProcessing(*fOutput);
00333 }

void TFWLiteSelectorBasic::Terminate (  )  [private, virtual]

Definition at line 336 of file TFWLiteSelectorBasic.cc.

References terminate().

00336                                 {
00337   terminate(*fOutput);
00338 }

virtual void TFWLiteSelectorBasic::terminate ( TList &  out  )  [pure virtual]

Called each time the 'client' has finished processing.

Parameters:
out contains the accumulated output of all slaves.

Implemented in tselname, tfwliteselectortest::ThingsTSelector, tfwliteselectortest::ThingsTSelector2, and examples::TrackTSelector.

Referenced by Terminate().

virtual Int_t TFWLiteSelectorBasic::Version (  )  const [inline, private, virtual]

Definition at line 95 of file TFWLiteSelectorBasic.h.

00095 { return 1; }


Member Data Documentation

bool TFWLiteSelectorBasic::everythingOK_ [private]

Definition at line 100 of file TFWLiteSelectorBasic.h.

Referenced by Notify(), Process(), and setupNewFile().

edm::root::TFWLiteSelectorMembers* TFWLiteSelectorBasic::m_ [private]

Definition at line 99 of file TFWLiteSelectorBasic.h.

Referenced by Init(), Notify(), Process(), setupNewFile(), and ~TFWLiteSelectorBasic().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:33:24 2009 for CMSSW by  doxygen 1.5.4