ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor Class Reference

Class writing one variable from an xAOD object into a branch. More...

Collaboration diagram for CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor:

Public Member Functions

StatusCode setup (TTree &tree, const std::string &auxName, const std::string &branchName, MsgStream &msg)
 Function setting up the object, and the branch. More...
 
StatusCode process (const SG::AuxElement &element, MsgStream &msg)
 Function processing the object, filling the variable. More...
 

Public Attributes

std::string m_branchName
 Name of the branch being written. More...
 
std::unique_ptr< SG::AuxElement::TypelessConstAccessorm_acc
 Object accessing the variable in question. More...
 
const SG::IAuxTypeVectorFactorym_factory = nullptr
 Pointer to the helper object that handles this variable. More...
 
std::unique_ptr< SG::IAuxTypeVectorm_data
 The object managing the memory of the written variable. More...
 
void * m_dataPtr = nullptr
 Helper variable, pointing at the object to be written. More...
 

Detailed Description

Class writing one variable from an xAOD object into a branch.

It is used for both setting up the branch in the outut TTree during the setup of the tree, and then to fill the "output variable" with the right payload during the event processing.

Note that since we may have a lot of such objects, I didn't want to make it inherit from asg::AsgMessaging. Which means that all of the class's functions need to receive its parent's message stream object to be able to log error messages "nicely".

Also note that since this is very much an internal class, all of its members are public. Since the owner of such objects should know perfectly well how they behave.

Definition at line 138 of file AsgxAODMetNTupleMakerAlg.h.

Member Function Documentation

◆ process()

StatusCode CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::process ( const SG::AuxElement element,
MsgStream &  msg 
)

Function processing the object, filling the variable.

This function is called by ElementProcessor, to extract one variable from the standalone object, and move its payload into the memory address from which the output tree is writing its branch.

Parameters
elementThe standalone object to get the auxiliary variable from
msgReference to the parent's MsgStream object
Returns
The usual StatusCode values

Definition at line 529 of file AsgxAODMetNTupleMakerAlg.cxx.

530  {
531 
532  // A security check.
533  if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
534  msg << MSG::FATAL << "Internal logic error detected" << endmsg;
535  return StatusCode::FAILURE;
536  }
537 
538  // Get the data out of the xAOD object.
539  //const void* auxData = ( *m_acc )( element );
540 
541  // Copy it into the output variable.
542  TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
543  m_factory->copy( m_acc->auxid(), dstiface, 0,
544  *element.container(), element.index(), 1 );
545 
546  // Return gracefully.
547  return StatusCode::SUCCESS;
548  }

◆ setup()

StatusCode CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::setup ( TTree &  tree,
const std::string &  auxName,
const std::string &  branchName,
MsgStream &  msg 
)

Function setting up the object, and the branch.

This is pretty much the constructor of the class. I just decided to implement it as a regular function and not a "real" constructor, to be able to return a StatusCode value from the call. Since the setup of the object may very well fail.

Parameters
treeThe tree to set up the new branch in
auxNameThe name of the auxiliary variable to create a branch from
branchNameName of the branch to create in the tree
msgReference to the parent's MsgStream object
Returns
The usual StatusCode values

Definition at line 435 of file AsgxAODMetNTupleMakerAlg.cxx.

437  {
438 
439  // Remember the branch name.
440  m_branchName = branchName;
441 
442  // Create the accessor.
443  m_acc.reset( new SG::AuxElement::TypelessConstAccessor( auxName ) );
444 
445  // Get a pointer to the vector factory.
447  const std::type_info* ti = reg.getType( m_acc->auxid() );
448  if( ! ti ) {
449  msg << MSG::ERROR
450  << "No std::type_info available for auxiliary variable: "
451  << auxName << endmsg;
452  return StatusCode::FAILURE;
453  }
454  m_factory = reg.getFactory( m_acc->auxid() );
455  if( ! m_factory ) {
456  msg << MSG::ERROR << "No factory found for auxiliary variable: "
457  << auxName << endmsg;
458  return StatusCode::FAILURE;
459  }
460 
461  // Create the data object.
462  m_data = m_factory->create( m_acc->auxid(), 1, 1, false );
463 
464  // Pointer to the branch, to be created.
465  TBranch* br = nullptr;
466 
467  // Decide whether we're dealing with a "primitive" or an "object" branch.
468  if( strlen( ti->name() ) == 1 ) {
469 
470  // This is a "primitive" variable...
471 
472  // Get the type identifier for it that ROOT will understand.
473  const char rType = rootType( ti->name()[ 0 ], msg );
474  if( rType == '\0' ) {
475  msg << MSG::ERROR << "Type not recognised for variable: "
476  << branchName << endmsg;
477  return StatusCode::FAILURE;
478  }
479 
480  // Construct the type description.
481  std::ostringstream typeDesc;
482  typeDesc << branchName << "/" << rType;
483 
484  // Create the primitive branch.
485  br = tree.Branch( branchName.c_str(), m_data->toPtr(),
486  typeDesc.str().c_str() );
487 
488  } else {
489 
490  // This is an "object" variable...
491 
492  // Get a proper type name for the variable.
493  const std::string typeName = SG::normalizedTypeinfoName( *ti );
494 
495  // Access the dictionary for the type.
496  TClass* cl = TClass::GetClass( *ti );
497  if( ! cl ) {
498  cl = TClass::GetClass( typeName.c_str() );
499  }
500  if( ! cl ) {
501  msg << MSG::ERROR << "Couldn't find dictionary for type: "
502  << typeName << endmsg;
503  return StatusCode::FAILURE;
504  }
505  if( ! cl->GetStreamerInfo() ) {
506  msg << MSG::ERROR << "No streamer info available for type: "
507  << cl->GetName() << endmsg;
508  return StatusCode::FAILURE;
509  }
510 
511  // Create the object branch.
512  m_dataPtr = m_data->toPtr();
513  br = tree.Branch( branchName.c_str(), cl->GetName(), &m_dataPtr );
514 
515  }
516 
517  // Check that the branch creation succeeded.
518  if( ! br ) {
519  msg << MSG::ERROR << "Failed to create branch: " << branchName
520  << endmsg;
521  return StatusCode::FAILURE;
522  }
523 
524  // Return gracefully.
525  return StatusCode::SUCCESS;
526  }

Member Data Documentation

◆ m_acc

std::unique_ptr< SG::AuxElement::TypelessConstAccessor > CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_acc

Object accessing the variable in question.

Definition at line 177 of file AsgxAODMetNTupleMakerAlg.h.

◆ m_branchName

std::string CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_branchName

Name of the branch being written.

Definition at line 175 of file AsgxAODMetNTupleMakerAlg.h.

◆ m_data

std::unique_ptr< SG::IAuxTypeVector > CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_data

The object managing the memory of the written variable.

Definition at line 181 of file AsgxAODMetNTupleMakerAlg.h.

◆ m_dataPtr

void* CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_dataPtr = nullptr

Helper variable, pointing at the object to be written.

Definition at line 183 of file AsgxAODMetNTupleMakerAlg.h.

◆ m_factory

const SG::IAuxTypeVectorFactory* CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_factory = nullptr

Pointer to the helper object that handles this variable.

Definition at line 179 of file AsgxAODMetNTupleMakerAlg.h.


The documentation for this class was generated from the following files:
CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_acc
std::unique_ptr< SG::AuxElement::TypelessConstAccessor > m_acc
Object accessing the variable in question.
Definition: AsgxAODMetNTupleMakerAlg.h:177
CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_data
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
Definition: AsgxAODMetNTupleMakerAlg.h:181
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_factory
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
Definition: AsgxAODMetNTupleMakerAlg.h:179
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
SG::normalizedTypeinfoName
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
Definition: normalizedTypeinfoName.cxx:120
SG::IAuxTypeVectorFactory::create
virtual std::unique_ptr< IAuxTypeVector > create(SG::auxid_t auxid, size_t size, size_t capacity, bool isLinked) const =0
Create a vector object of this type.
SG::TypelessConstAccessor
Helper class to provide const generic access to aux data.
Definition: TypelessConstAccessor.h:44
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:62
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
SG::IAuxTypeVectorFactory::copy
virtual void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const =0
Copy elements between vectors.
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_dataPtr
void * m_dataPtr
Helper variable, pointing at the object to be written.
Definition: AsgxAODMetNTupleMakerAlg.h:183
CP::AsgxAODMetNTupleMakerAlg::ElementProcessor::BranchProcessor::m_branchName
std::string m_branchName
Name of the branch being written.
Definition: AsgxAODMetNTupleMakerAlg.h:175
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
xAOD::Utils::rootType
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
Definition: Control/xAODRootAccess/Root/Utils.cxx:226
AthHistogramming::tree
TTree * tree(const std::string &treeName, const std::string &tDir="", const std::string &stream="")
Simplify the retrieval of registered TTrees.
Definition: AthHistogramming.cxx:378
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355