ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CP::AsgxAODNTupleMakerAlg::ContainerProcessor Class Reference

Class writing all variables from one DataVector container. More...

Inheritance diagram for CP::AsgxAODNTupleMakerAlg::ContainerProcessor:
Collaboration diagram for CP::AsgxAODNTupleMakerAlg::ContainerProcessor:

Classes

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

Public Member Functions

 ContainerProcessor ()
 Default constructor. More...
 
StatusCode process (const SG::AuxVectorBase &container, const TClass &cl)
 Process the container. More...
 
StatusCode addBranch (TTree &tree, const std::string &auxName, const std::string &branchName, bool allowMissing, bool &created)
 Add one branch to the output tree. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::list< BranchProcessorm_branches
 List of branch processors set up for this xAOD object. More...
 
TVirtualCollectionProxy * m_collProxy = nullptr
 Collection proxy used for iterating over the container. More...
 
int m_auxElementOffset = -1
 Offset of the element type to SG::AuxElement. More...
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging) More...
 

Detailed Description

Class writing all variables from one DataVector container.

It is designed to work with any DataVector<SG::AuxElement> type, it doesn't have to be an xAOD::IParticleContainer. But of course that is the main use case for it...

It expects an SG::AuxVectorBase object from the caller, iterates over the elements of that container using the ROOT dictionary of the type, and writes individual variables from the elements of the container using the same machinery that ElementProcessor employs.

Definition at line 235 of file AsgxAODNTupleMakerAlg.h.

Constructor & Destructor Documentation

◆ ContainerProcessor()

CP::AsgxAODNTupleMakerAlg::ContainerProcessor::ContainerProcessor ( )

Default constructor.

We have to have a default constructor to initialise the asg::AsgMessaging base class correctly. Members of this class would not need an explicit constructor themselves.

Definition at line 804 of file AsgxAODNTupleMakerAlg.cxx.

805  : asg::AsgMessaging( "CP::AsgxAODNTupleMakerAlg::ContainerProcessor" ) {
806 
807  }

Member Function Documentation

◆ addBranch()

StatusCode CP::AsgxAODNTupleMakerAlg::ContainerProcessor::addBranch ( TTree &  tree,
const std::string &  auxName,
const std::string &  branchName,
bool  allowMissing,
bool &  created 
)

Add one branch to the output tree.

This function is used during the setup of the output tree to create one branch in it, from one specific auxiliary variable. The type of the variable is figured out at runtime using the auxiliary store infrastructure.

Parameters
treeThe tree to create the branch in
auxNameName of the auxiliary variable to create the branch from
branchNameThe name of the branch to create in the tree
allowMissingSet to true to print an error message in case of a failure
createdUsed to store if the branch was actually created
Returns
The usual StatusCode values

Helper class for finding an already existing branch processor.

Type of the predicate's argument

Constructor with key/name

Operator evaluating whether this is the branch we're looking for

< Name of the branch

Definition at line 873 of file AsgxAODNTupleMakerAlg.cxx.

877  {
878 
880  class BranchFinder {
881  public:
883  typedef const BranchProcessor& argument_type;
885  BranchFinder( const std::string& branchName ) : m_name( branchName ) {}
887  bool operator()( argument_type bp ) const {
888  return ( bp.m_branchName == m_name );
889  }
890  private:
891  std::string m_name;
892  }; // class BranchFinder
893 
894  // Check if the corresponding aux item exists
895  bool validAuxItem = auxItemExists( auxName );
896  if( ! validAuxItem ) {
897  if( allowMissing ) {
898  // Return gracefully.
899  ATH_MSG_DEBUG( "Aux item \"" << auxName
900  << "\" not readable for branch \""
901  << branchName << "\"" );
902  return StatusCode::SUCCESS;
903  } else {
904  // Return gracefully.
905  ATH_MSG_ERROR( "Aux item \"" << auxName
906  << "\" not readable for branch \""
907  << branchName << "\"" );
908  return StatusCode::FAILURE;
909  }
910  }
911 
912  // Check whether this branch is already set up:
913  auto itr = std::find_if( m_branches.begin(), m_branches.end(),
914  BranchFinder( branchName ) );
915  if( itr != m_branches.end() ) {
916  ATH_MSG_WARNING( "Duplicate setup received for branch: " << branchName );
917  return StatusCode::SUCCESS;
918  }
919 
920  created = true;
921 
922  // Set up the new branch.
923  m_branches.emplace_back();
924  ATH_CHECK( m_branches.back().setup( tree, auxName, branchName, msg() ) );
925 
926  // Return gracefully.
927  return StatusCode::SUCCESS;
928  }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49  {
50 #ifndef XAOD_STANDALONE
52 #else // not XAOD_STANDALONE
53  return m_msg;
54 #endif // not XAOD_STANDALONE
55  }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level  lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57  {
58 #ifndef XAOD_STANDALONE
60 #else // not XAOD_STANDALONE
61  m_msg << lvl;
62  return m_msg;
63 #endif // not XAOD_STANDALONE
64  }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level  lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41  {
42 #ifndef XAOD_STANDALONE
43  return ::AthMessaging::msgLvl( lvl );
44 #else // not XAOD_STANDALONE
45  return m_msg.msgLevel( lvl );
46 #endif // not XAOD_STANDALONE
47  }

◆ process()

StatusCode CP::AsgxAODNTupleMakerAlg::ContainerProcessor::process ( const SG::AuxVectorBase container,
const TClass &  cl 
)

Process the container.

This function is called during the event processing to extract all configured variables from an xAOD container into the output variables set up using ContainerProcessor::addBranch.

Parameters
containerThe xAOD (interface) container to process
cltype of container
Returns
The usual StatusCode values

Definition at line 809 of file AsgxAODNTupleMakerAlg.cxx.

810  {
811 
812  // Get the collection proxy for the type if it's not available yet.
813  if( ! m_collProxy ) {
814 
815  // Get the collection proxy from the dictionary.
816  m_collProxy = cl.GetCollectionProxy();
817  if( ! m_collProxy ) {
818  ATH_MSG_ERROR( "No collection proxy provided by type: "
819  << cl.GetName() );
820  return StatusCode::FAILURE;
821  }
822 
823  // Get the offset that one needs to use to get from the element
824  // pointers to SG::AuxElement pointers.
825  static const TClass* const auxElementClass =
826  TClass::GetClass( typeid( SG::AuxElement ) );
828  m_collProxy->GetValueClass()->GetBaseClassOffset( auxElementClass );
829  if( m_auxElementOffset < 0 ) {
830  ATH_MSG_ERROR( "Vector element type \""
831  << m_collProxy->GetValueClass()->GetName()
832  << "\" doesn't seem to inherit from \""
833  << auxElementClass->GetName() << "\"" );
834  return StatusCode::FAILURE;
835  }
836  }
837 
838  // Set up the iteration over the elements of the container. In a really
839  // low level / ugly way...
840  void* cPtr =
841  const_cast< void* >( static_cast< const void* >( &container ) );
842  TVirtualCollectionProxy::TPushPop helper( m_collProxy, cPtr );
843  const UInt_t cSize = m_collProxy->Size();
844 
845  // Tell all branch processors to resize their variables.
846  for( BranchProcessor& p : m_branches ) {
847  ATH_CHECK( p.resize( cSize, msg() ) );
848  }
849 
850  // Now iterate over the container.
851  for( UInt_t i = 0; i < cSize; ++i ) {
852 
853  // Get the element.
854  char* elPtr = static_cast< char* >( m_collProxy->At( i ) );
855  if( ! elPtr ) {
856  ATH_MSG_ERROR( "Failed to get element " << i << " from container" );
857  return StatusCode::FAILURE;
858  }
859  const SG::AuxElement* element =
860  reinterpret_cast< const SG::AuxElement* >( elPtr +
862 
863  // Execute all branch processors on this element.
864  for( BranchProcessor& p : m_branches ) {
865  ATH_CHECK( p.process( *element, i, msg() ) );
866  }
867  }
868 
869  // Return gracefully.
870  return StatusCode::SUCCESS;
871  }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_auxElementOffset

int CP::AsgxAODNTupleMakerAlg::ContainerProcessor::m_auxElementOffset = -1
private

Offset of the element type to SG::AuxElement.

Definition at line 340 of file AsgxAODNTupleMakerAlg.h.

◆ m_branches

std::list< BranchProcessor > CP::AsgxAODNTupleMakerAlg::ContainerProcessor::m_branches
private

List of branch processors set up for this xAOD object.

Note that when we set up a branch, we tell TTree to remember a physical address in memory. To make sure that the address of the object held by the branch processors are not moved in memory after their construction, we have to use an std::list container here. std::vector would not work. (As it can relocate objects when increasing the size of the container.)

Definition at line 336 of file AsgxAODNTupleMakerAlg.h.

◆ m_collProxy

TVirtualCollectionProxy* CP::AsgxAODNTupleMakerAlg::ContainerProcessor::m_collProxy = nullptr
private

Collection proxy used for iterating over the container.

Definition at line 338 of file AsgxAODNTupleMakerAlg.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.


The documentation for this class was generated from the following files:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:472
CP::AsgxAODNTupleMakerAlg::ContainerProcessor::m_collProxy
TVirtualCollectionProxy * m_collProxy
Collection proxy used for iterating over the container.
Definition: AsgxAODNTupleMakerAlg.h:338
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
CP::AsgxAODNTupleMakerAlg::ContainerProcessor::m_branches
std::list< BranchProcessor > m_branches
List of branch processors set up for this xAOD object.
Definition: AsgxAODNTupleMakerAlg.h:336
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
AthHistogramming::m_name
std::string m_name
Instance name.
Definition: AthHistogramming.h:245
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
CP::AsgxAODNTupleMakerAlg::ContainerProcessor::m_auxElementOffset
int m_auxElementOffset
Offset of the element type to SG::AuxElement.
Definition: AsgxAODNTupleMakerAlg.h:340
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