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

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

Collaboration diagram for CP::AsgxAODNTupleMakerAlg::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 162 of file AsgxAODNTupleMakerAlg.h.

Member Function Documentation

◆ process()

StatusCode CP::AsgxAODNTupleMakerAlg::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 783 of file AsgxAODNTupleMakerAlg.cxx.

784  {
785 
786  // A security check.
787  if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
788  msg << MSG::FATAL << "Internal logic error detected" << endmsg;
789  return StatusCode::FAILURE;
790  }
791 
792  // Get the data out of the xAOD object.
793  //const void* auxData = ( *m_acc )( element );
794 
795  // Copy it into the output variable.
796  TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
797  m_factory->copy( m_acc->auxid(), dstiface, 0,
798  *element.container(), element.index(), 1 );
799 
800  // Return gracefully.
801  return StatusCode::SUCCESS;
802  }

◆ setup()

StatusCode CP::AsgxAODNTupleMakerAlg::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 689 of file AsgxAODNTupleMakerAlg.cxx.

691  {
692 
693  // Remember the branch name.
694  m_branchName = branchName;
695 
696  // Create the accessor.
697  m_acc.reset( new SG::AuxElement::TypelessConstAccessor( auxName ) );
698 
699  // Get a pointer to the vector factory.
701  const std::type_info* ti = reg.getType( m_acc->auxid() );
702  if( ! ti ) {
703  msg << MSG::ERROR
704  << "No std::type_info available for auxiliary variable: "
705  << auxName << endmsg;
706  return StatusCode::FAILURE;
707  }
708  m_factory = reg.getFactory( m_acc->auxid() );
709  if( ! m_factory ) {
710  msg << MSG::ERROR << "No factory found for auxiliary variable: "
711  << auxName << endmsg;
712  return StatusCode::FAILURE;
713  }
714 
715  // Create the data object.
716  m_data = m_factory->create( m_acc->auxid(), 1, 1, false );
717 
718  // Pointer to the branch, to be created.
719  TBranch* br = nullptr;
720 
721  // Decide whether we're dealing with a "primitive" or an "object" branch.
722  if( strlen( ti->name() ) == 1 ) {
723 
724  // This is a "primitive" variable...
725 
726  // Get the type identifier for it that ROOT will understand.
727  const char rType = rootType( ti->name()[ 0 ], msg );
728  if( rType == '\0' ) {
729  msg << MSG::ERROR << "Type not recognised for variable: "
730  << branchName << endmsg;
731  return StatusCode::FAILURE;
732  }
733 
734  // Construct the type description.
735  std::ostringstream typeDesc;
736  typeDesc << branchName << "/" << rType;
737 
738  // Create the primitive branch.
739  br = tree.Branch( branchName.c_str(), m_data->toPtr(),
740  typeDesc.str().c_str() );
741 
742  } else {
743 
744  // This is an "object" variable...
745 
746  // Get a proper type name for the variable.
747  const std::string typeName = SG::normalizedTypeinfoName( *ti );
748 
749  // Access the dictionary for the type.
750  TClass* cl = TClass::GetClass( *ti );
751  if( ! cl ) {
752  cl = TClass::GetClass( typeName.c_str() );
753  }
754  if( ! cl ) {
755  msg << MSG::ERROR << "Couldn't find dictionary for type: "
756  << typeName << endmsg;
757  return StatusCode::FAILURE;
758  }
759  if( ! cl->GetStreamerInfo() ) {
760  msg << MSG::ERROR << "No streamer info available for type: "
761  << cl->GetName() << endmsg;
762  return StatusCode::FAILURE;
763  }
764 
765  // Create the object branch.
766  m_dataPtr = m_data->toPtr();
767  br = tree.Branch( branchName.c_str(), cl->GetName(), &m_dataPtr );
768 
769  }
770 
771  // Check that the branch creation succeeded.
772  if( ! br ) {
773  msg << MSG::ERROR << "Failed to create branch: " << branchName
774  << endmsg;
775  return StatusCode::FAILURE;
776  }
777 
778  // Return gracefully.
779  return StatusCode::SUCCESS;
780  }

Member Data Documentation

◆ m_acc

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

Object accessing the variable in question.

Definition at line 201 of file AsgxAODNTupleMakerAlg.h.

◆ m_branchName

std::string CP::AsgxAODNTupleMakerAlg::ElementProcessor::BranchProcessor::m_branchName

Name of the branch being written.

Definition at line 199 of file AsgxAODNTupleMakerAlg.h.

◆ m_data

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

The object managing the memory of the written variable.

Definition at line 205 of file AsgxAODNTupleMakerAlg.h.

◆ m_dataPtr

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

Helper variable, pointing at the object to be written.

Definition at line 207 of file AsgxAODNTupleMakerAlg.h.

◆ m_factory

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

Pointer to the helper object that handles this variable.

Definition at line 203 of file AsgxAODNTupleMakerAlg.h.


The documentation for this class was generated from the following files:
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
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
CP::AsgxAODNTupleMakerAlg::ElementProcessor::BranchProcessor::m_data
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
Definition: AsgxAODNTupleMakerAlg.h:205
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
CP::AsgxAODNTupleMakerAlg::ElementProcessor::BranchProcessor::m_dataPtr
void * m_dataPtr
Helper variable, pointing at the object to be written.
Definition: AsgxAODNTupleMakerAlg.h:207
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.
CP::AsgxAODNTupleMakerAlg::ElementProcessor::BranchProcessor::m_branchName
std::string m_branchName
Name of the branch being written.
Definition: AsgxAODNTupleMakerAlg.h:199
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
CP::AsgxAODNTupleMakerAlg::ElementProcessor::BranchProcessor::m_acc
std::unique_ptr< SG::AuxElement::TypelessConstAccessor > m_acc
Object accessing the variable in question.
Definition: AsgxAODNTupleMakerAlg.h:201
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
CP::AsgxAODNTupleMakerAlg::ElementProcessor::BranchProcessor::m_factory
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
Definition: AsgxAODNTupleMakerAlg.h:203
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355