CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TFWLiteSelectorBasic Class Referenceabstract

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

Inheritance diagram for TFWLiteSelectorBasic:
TFWLiteSelector< TWorker > TFWLiteSelector< __class__Worker > TFWLiteSelector< ThingsWorker > tfwliteselectortest::ThingsTSelector __class__< T > tfwliteselectortest::ThingsTSelector2

Public Member Functions

virtual void begin (TList *&in)=0
 
virtual void postProcessing (TList &out)=0
 
virtual void preProcessing (const TList *in, TList &out)=0
 
virtual void process (const edm::Event &event)=0
 
virtual void terminate (TList &out)=0
 
 TFWLiteSelectorBasic ()
 
 ~TFWLiteSelectorBasic () override
 

Private Member Functions

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

Private Attributes

bool everythingOK_
 
edm::propagate_const< std::shared_ptr< edm::root::TFWLiteSelectorMembers > > m_
 

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 42 of file TFWLiteSelectorBasic.h.

Constructor & Destructor Documentation

◆ TFWLiteSelectorBasic() [1/2]

TFWLiteSelectorBasic::TFWLiteSelectorBasic ( )

Definition at line 213 of file TFWLiteSelectorBasic.cc.

edm::propagate_const< std::shared_ptr< edm::root::TFWLiteSelectorMembers > > m_

◆ ~TFWLiteSelectorBasic()

TFWLiteSelectorBasic::~TFWLiteSelectorBasic ( )
override

Definition at line 220 of file TFWLiteSelectorBasic.cc.

220 {}

◆ TFWLiteSelectorBasic() [2/2]

TFWLiteSelectorBasic::TFWLiteSelectorBasic ( const TFWLiteSelectorBasic )
private

Member Function Documentation

◆ begin()

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

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

Parameters
inan 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 __class__< T >, tfwliteselectortest::ThingsTSelector2, and tfwliteselectortest::ThingsTSelector.

Referenced by Begin().

◆ Begin()

void TFWLiteSelectorBasic::Begin ( TTree *  iTree)
overrideprivate

Definition at line 237 of file TFWLiteSelectorBasic.cc.

References begin(), and Init().

237  {
238  Init(iTree);
239  begin(fInput);
240 }
void Init(TTree *) override
virtual void begin(TList *&in)=0

◆ Init()

void TFWLiteSelectorBasic::Init ( TTree *  iTree)
overrideprivate

Definition at line 247 of file TFWLiteSelectorBasic.cc.

References m_.

Referenced by Begin(), and SlaveBegin().

247  {
248  if (iTree == nullptr)
249  return;
250  m_->setTree(iTree);
251 }
edm::propagate_const< std::shared_ptr< edm::root::TFWLiteSelectorMembers > > m_

◆ Notify()

Bool_t TFWLiteSelectorBasic::Notify ( )
overrideprivate

Definition at line 253 of file TFWLiteSelectorBasic.cc.

References gather_cfg::cout, everythingOK_, geometryDiff::file, m_, and setupNewFile().

253  {
254  //std::cout << "Notify start" << std::endl;
255  //we have switched to a new file
256  //get new file from Tree
257  if (nullptr == m_->tree_) {
258  std::cout << "No tree" << std::endl;
259  return kFALSE;
260  }
261  TFile* file = m_->tree_->GetCurrentFile();
262  if (nullptr == file) {
263  //When in Rome, do as the Romans
264  TChain* chain = dynamic_cast<TChain*>(m_->tree());
265  if (nullptr == chain) {
266  std::cout << "No file" << std::endl;
267  return kFALSE;
268  }
269  file = chain->GetFile();
270  if (nullptr == file) {
271  std::cout << "No file" << std::endl;
272  return kFALSE;
273  }
274  }
275  setupNewFile(*file);
276  return everythingOK_ ? kTRUE : kFALSE;
277 }
edm::propagate_const< std::shared_ptr< edm::root::TFWLiteSelectorMembers > > m_

◆ operator=()

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

◆ postProcessing()

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

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

Parameters
outthe 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 >, TFWLiteSelector< ThingsWorker >, TFWLiteSelector< __class__Worker >, and tfwliteselectortest::ThingsTSelector.

Referenced by SlaveTerminate().

◆ preProcessing()

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

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

Parameters
ina pointer to the list of objects created in 'begin()'. The pointer can be 0
outa 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 >, TFWLiteSelector< ThingsWorker >, TFWLiteSelector< __class__Worker >, and tfwliteselectortest::ThingsTSelector.

Referenced by SlaveBegin().

◆ process()

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

Call each time the 'slave' gets a new Event

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

Implemented in TFWLiteSelector< TWorker >, TFWLiteSelector< ThingsWorker >, TFWLiteSelector< __class__Worker >, and tfwliteselectortest::ThingsTSelector.

Referenced by Process().

◆ Process()

Bool_t TFWLiteSelectorBasic::Process ( Long64_t  iEntry)
overrideprivate

Definition at line 290 of file TFWLiteSelectorBasic.cc.

References printConversionInfo::aux, MicroEventContent_cff::branch, edm::poolNames::branchListIndexesBranchName(), edm::BranchTypeToAuxiliaryBranchName(), gather_cfg::cout, edmPickEvents::event, edm::poolNames::eventSelectionsBranchName(), everythingOK_, cppFunctionSkipper::exception, Exception, edm::errors::FatalRootError, edm::propagate_const< T >::get(), edm::InEvent, m_, eostools::move(), and process().

290  {
291  //std::cout << "Process start" << std::endl;
292  if (everythingOK_) {
293  std::unique_ptr<edm::EventAuxiliary> eaux = std::make_unique<edm::EventAuxiliary>();
294  edm::EventAuxiliary& aux = *eaux;
295  edm::EventAuxiliary* pAux = eaux.get();
296  TBranch* branch = m_->tree_->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InEvent).c_str());
297 
298  branch->SetAddress(&pAux);
299  branch->GetEntry(iEntry);
300 
301  //NEW m_->processNames_ = aux.processHistory();
302 
303  // std::cout << "ProcessNames\n";
304  // for(auto const& name : m_->processNames_) {
305  // std::cout << " " << name << std::endl;
306  // }
307 
308  edm::EventSelectionIDVector eventSelectionIDs;
309  edm::EventSelectionIDVector* pEventSelectionIDVector = &eventSelectionIDs;
310  TBranch* eventSelectionsBranch = m_->tree_->GetBranch(edm::poolNames::eventSelectionsBranchName().c_str());
311  if (!eventSelectionsBranch) {
312  throw edm::Exception(edm::errors::FatalRootError) << "Failed to find event Selections branch in event tree";
313  }
314  eventSelectionsBranch->SetAddress(&pEventSelectionIDVector);
315  eventSelectionsBranch->GetEntry(iEntry);
316 
317  edm::BranchListIndexes branchListIndexes;
318  edm::BranchListIndexes* pBranchListIndexes = &branchListIndexes;
319  TBranch* branchListIndexBranch = m_->tree_->GetBranch(edm::poolNames::branchListIndexesBranchName().c_str());
320  if (!branchListIndexBranch) {
321  throw edm::Exception(edm::errors::FatalRootError) << "Failed to find branch list index branch in event tree";
322  }
323  branchListIndexBranch->SetAddress(&pBranchListIndexes);
324  branchListIndexBranch->GetEntry(iEntry);
325  m_->branchIDListHelper_->fixBranchListIndexes(branchListIndexes);
326  edm::EventToProcessBlockIndexes dummyEventToProcessBlockIndexes;
327 
328  try {
329  m_->reader_->setEntry(iEntry);
330  auto runAux = std::make_shared<edm::RunAuxiliary>(aux.run(), aux.time(), aux.time());
331  auto rp = std::make_shared<edm::RunPrincipal>(runAux, m_->reg(), m_->pc_, nullptr, 0);
332  auto lbp = std::make_shared<edm::LuminosityBlockPrincipal>(m_->reg(), m_->pc_, nullptr, 0);
333  lbp->setAux(edm::LuminosityBlockAuxiliary(rp->run(), 1, aux.time(), aux.time()));
334  auto history = m_->phreg_->getMapped(eaux->processHistoryID());
335  m_->ep_->fillEventPrincipal(*eaux,
336  history,
337  std::move(eventSelectionIDs),
338  std::move(branchListIndexes),
339  dummyEventToProcessBlockIndexes,
340  *(m_->provRetriever_),
341  m_->reader_.get());
342  lbp->setRunPrincipal(rp);
343  m_->ep_->setLuminosityBlockPrincipal(lbp.get());
344  m_->processNames_ = m_->ep_->processHistory();
345 
346  edm::Event event(*m_->ep_, m_->md_, nullptr);
347 
348  //Make the event principal accessible to edm::Ref's
349  Operate sentry(m_->ep_->prodGetter());
350  process(event);
351  } catch (std::exception const& iEx) {
352  std::cout << "While processing entry " << iEntry << " the following exception was caught \n"
353  << iEx.what() << std::endl;
354  } catch (...) {
355  std::cout << "While processing entry " << iEntry << " an unknown exception was caught" << std::endl;
356  }
357  }
358  return everythingOK_ ? kTRUE : kFALSE;
359 }
edm::propagate_const< std::shared_ptr< edm::root::TFWLiteSelectorMembers > > m_
virtual void process(const edm::Event &event)=0
std::vector< EventSelectionID > EventSelectionIDVector
constexpr element_type const * get() const
std::vector< BranchListIndex > BranchListIndexes
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:210
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:212
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:116
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1

◆ setupNewFile()

void TFWLiteSelectorBasic::setupNewFile ( TFile &  iFile)
private

Definition at line 365 of file TFWLiteSelectorBasic.cc.

References edm::poolNames::branchIDListBranchName(), gather_cfg::cout, mps_splice::entry, everythingOK_, Exception, edm::poolNames::fileFormatVersionBranchName(), edm::errors::FileReadError, edm::friendlyname::friendlyName(), mps_fire::i, edm::poolNames::idToParameterSetBlobsBranchName(), edm::InEvent, edm::pset::Registry::insertMapped(), edm::pset::Registry::instance(), B2GTnPMonitor_cfi::item, m_, edm::poolNames::metaDataTreeName(), AlCaHLTBitMon_ParallelJobs::p, edm::poolNames::parameterSetMapBranchName(), edm::poolNames::parameterSetsTreeName(), edm::poolNames::processConfigurationBranchName(), edm::poolNames::processHistoryBranchName(), dumpMFGeometry_cfg::prod, edm::poolNames::productDescriptionBranchName(), muonDTDigis_cfi::pset, edm::setIsMergeable(), AlCaHLTBitMon_QueryRunRegistry::string, groupFilesInBlocks::temp, edm::errors::UnimplementedFeature, and edm::BranchDescription::updateFriendlyClassName().

Referenced by Notify().

365  {
366  //look up meta-data
367  //get product registry
368 
369  //std::vector<edm::EventProcessHistoryID> eventProcessHistoryIDs_;
370  TTree* metaDataTree = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::metaDataTreeName().c_str()));
371  if (!metaDataTree) {
372  std::cout << "could not find TTree " << edm::poolNames::metaDataTreeName() << std::endl;
373  everythingOK_ = false;
374  return;
375  }
376  edm::FileFormatVersion* fftPtr = &(m_->fileFormatVersion_);
377  if (metaDataTree->FindBranch(edm::poolNames::fileFormatVersionBranchName().c_str()) != nullptr) {
378  metaDataTree->SetBranchAddress(edm::poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
379  }
380 
381  edm::ProductRegistry* pReg = &(*m_->reg_);
382  metaDataTree->SetBranchAddress(edm::poolNames::productDescriptionBranchName().c_str(), &(pReg));
383 
384  typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> PsetMap;
385  PsetMap psetMap;
386  PsetMap* psetMapPtr = &psetMap;
387  if (metaDataTree->FindBranch(edm::poolNames::parameterSetMapBranchName().c_str()) != nullptr) {
388  metaDataTree->SetBranchAddress(edm::poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
389  } else {
390  TTree* psetTree = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::parameterSetsTreeName().c_str()));
391  if (nullptr == psetTree) {
393  << "Could not find tree " << edm::poolNames::parameterSetsTreeName() << " in the input file.\n";
394  }
395  typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
396  IdToBlobs idToBlob;
397  IdToBlobs* pIdToBlob = &idToBlob;
398  psetTree->SetBranchAddress(edm::poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
399  for (long long i = 0; i != psetTree->GetEntries(); ++i) {
400  psetTree->GetEntry(i);
401  psetMap.insert(idToBlob);
402  }
403  }
404 
406  edm::ProcessHistoryRegistry::vector_type* pHistVectorPtr = &pHistVector;
407  if (metaDataTree->FindBranch(edm::poolNames::processHistoryBranchName().c_str()) != nullptr) {
408  metaDataTree->SetBranchAddress(edm::poolNames::processHistoryBranchName().c_str(), &pHistVectorPtr);
409  }
410 
411  edm::ProcessConfigurationVector procConfigVector;
412  edm::ProcessConfigurationVector* procConfigVectorPtr = &procConfigVector;
413  if (metaDataTree->FindBranch(edm::poolNames::processConfigurationBranchName().c_str()) != nullptr) {
414  metaDataTree->SetBranchAddress(edm::poolNames::processConfigurationBranchName().c_str(), &procConfigVectorPtr);
415  }
416 
417  auto branchIDListsHelper = std::make_shared<edm::BranchIDListHelper>();
418  edm::BranchIDLists const* branchIDListsPtr = &branchIDListsHelper->branchIDLists();
419  if (metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != nullptr) {
420  metaDataTree->SetBranchAddress(edm::poolNames::branchIDListBranchName().c_str(), &branchIDListsPtr);
421  }
422 
423  metaDataTree->GetEntry(0);
424 
425  for (auto& prod : m_->reg_->productListUpdator()) {
426  prod.second.init();
427  setIsMergeable(prod.second);
428  }
429 
430  // Merge into the registries. For now, we do NOT merge the product registry.
432  for (auto const& entry : psetMap) {
433  edm::ParameterSet pset(entry.second.pset());
434  pset.setID(entry.first);
435  psetRegistry.insertMapped(pset);
436  }
437 
438  for (auto const& ph : pHistVector) {
439  m_->phreg_->registerProcessHistory(ph);
440  }
441 
442  m_->pointerToBranchBuffer_.erase(m_->pointerToBranchBuffer_.begin(), m_->pointerToBranchBuffer_.end());
443 
444  std::unique_ptr<edm::ProductRegistry> newReg = std::make_unique<edm::ProductRegistry>();
445 
446  edm::ProductRegistry::ProductList& prodList = m_->reg_->productListUpdator();
447  {
448  for (auto& item : prodList) {
449  edm::BranchDescription& prod = item.second;
450  //std::cout << "productname = " << item.second << " end " << std::endl;
451  std::string newFriendlyName = edm::friendlyname::friendlyName(prod.className());
452  if (newFriendlyName == prod.friendlyClassName()) {
453  newReg->copyProduct(prod);
454  } else {
455  if (m_->fileFormatVersion_.splitProductIDs()) {
457  << "Cannot change friendly class name algorithm without more development work\n"
458  << "to update BranchIDLists. Contact the framework group.\n";
459  }
461  newBD.updateFriendlyClassName();
462  newReg->copyProduct(newBD);
463  }
464  prod.init();
465  }
466 
467  m_->reg().reset(newReg.release());
468  }
469 
470  edm::ProductRegistry::ProductList& prodList2 = m_->reg_->productListUpdator();
471  std::vector<edm::EventEntryDescription> temp(prodList2.size(), edm::EventEntryDescription());
472  m_->prov_.swap(temp);
473  m_->pointerToBranchBuffer_.reserve(prodList2.size());
474 
475  for (auto& item : prodList2) {
476  edm::BranchDescription& prod = item.second;
477  if (prod.branchType() == edm::InEvent) {
478  prod.init();
479  //NEED to do this and check to see if branch exists
480  if (m_->tree_->GetBranch(prod.branchName().c_str()) == nullptr) {
481  prod.setDropped(true);
482  }
483  prod.setOnDemand(true);
484 
485  //std::cout << "id " << it->first << " branch " << it->second << std::endl;
486  //m_->pointerToBranchBuffer_.push_back(&(*itB));
487  //void* tmp = &(m_->pointerToBranchBuffer_.back());
488  //edm::EventEntryDescription* tmp = &(*itB);
489  //CDJ need to fix provenance and be backwards compatible, for now just don't read the branch
490  //m_->metaTree_->SetBranchAddress(prod.branchName().c_str(), tmp);
491  }
492  }
493  m_->branchIDListHelper_->updateFromInput(*branchIDListsPtr);
494  m_->reg_->setFrozen();
495  m_->bidToDesc_->clear();
496  for (auto const& p : m_->reg_->productList()) {
497  m_->bidToDesc_->emplace(p.second.branchID().id(), &p.second);
498  }
499  m_->ep_ = std::make_shared<edm::EventPrincipal>(
500  m_->reg(), m_->branchIDListHelper(), m_->thinnedAssociationsHelper(), m_->pc_, nullptr);
501  everythingOK_ = true;
502 }
std::vector< ProcessConfiguration > ProcessConfigurationVector
std::string const & metaDataTreeName()
Definition: BranchType.cc:159
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
edm::propagate_const< std::shared_ptr< edm::root::TFWLiteSelectorMembers > > m_
std::map< BranchKey, BranchDescription > ProductList
std::string const & processHistoryBranchName()
Definition: BranchType.cc:177
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:168
std::string const & fileFormatVersionBranchName()
Definition: BranchType.cc:189
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:162
std::string const & branchIDListBranchName()
Definition: BranchType.cc:183
std::string friendlyName(std::string const &iFullName)
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:216
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:218
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:180
void setIsMergeable(BranchDescription &)
static Registry * instance()
Definition: Registry.cc:12

◆ SlaveBegin()

void TFWLiteSelectorBasic::SlaveBegin ( TTree *  iTree)
overrideprivate

Definition at line 242 of file TFWLiteSelectorBasic.cc.

References Init(), and preProcessing().

242  {
243  Init(iTree);
244  preProcessing(fInput, *fOutput);
245 }
virtual void preProcessing(const TList *in, TList &out)=0
void Init(TTree *) override

◆ SlaveTerminate()

void TFWLiteSelectorBasic::SlaveTerminate ( )
overrideprivate

Definition at line 361 of file TFWLiteSelectorBasic.cc.

References postProcessing().

361 { postProcessing(*fOutput); }
virtual void postProcessing(TList &out)=0

◆ terminate()

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

Called each time the 'client' has finished processing.

Parameters
outcontains the accumulated output of all slaves.

Implemented in __class__< T >, tfwliteselectortest::ThingsTSelector2, and tfwliteselectortest::ThingsTSelector.

Referenced by Terminate().

◆ Terminate()

void TFWLiteSelectorBasic::Terminate ( )
overrideprivate

Definition at line 363 of file TFWLiteSelectorBasic.cc.

References terminate().

363 { terminate(*fOutput); }
virtual void terminate(TList &out)=0

◆ Version()

Int_t TFWLiteSelectorBasic::Version ( ) const
inlineoverrideprivate

Definition at line 94 of file TFWLiteSelectorBasic.h.

94 { return 1; }

Member Data Documentation

◆ everythingOK_

bool TFWLiteSelectorBasic::everythingOK_
private

Definition at line 99 of file TFWLiteSelectorBasic.h.

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

◆ m_

edm::propagate_const<std::shared_ptr<edm::root::TFWLiteSelectorMembers> > TFWLiteSelectorBasic::m_
private

Definition at line 98 of file TFWLiteSelectorBasic.h.

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