ATLAS Offline Software
Loading...
Searching...
No Matches
TruthMetaDataTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Local include(s):
6#include <memory>
7
8
9
12
13
14namespace xAODMaker {
15
16 // Helper typedef:
18
19 TruthMetaDataTool::TruthMetaDataTool( const std::string& name )
20 : asg::AsgMetadataTool( name ),
22
23 declareProperty( "InputKey", m_inputKey = "TruthMetaData" );
24 declareProperty( "OutputKey", m_outputKey = "TruthMetaData" );
25
26#ifndef XAOD_STANDALONE
27 declareInterface< ::IMetaDataTool >( this );
28#endif // XAOD_STANDALONE
29 }
30
32
33 // Greet the user:
34 ATH_MSG_DEBUG( "Initialising TruthMetaDataTool" );
35 ATH_MSG_DEBUG( " InputKey = " << m_inputKey );
36 ATH_MSG_DEBUG( " OutputKey = " << m_outputKey );
37
38 // Reset the internal variable(s):
39 m_truthMeta.reset(); m_truthMetaAux.reset();
40
41 // Retrun gracefully:
42 return StatusCode::SUCCESS;
43 }
44
46
47 // If the input file doesn't have any trigger configuration metadata,
48 // then finish right away:
50 return StatusCode::SUCCESS;
51 }
52
53 // Retrieve the input container:
54 const Cont_t* input = nullptr;
55 ATH_CHECK( inputMetaStore()->retrieve( input, m_inputKey ) );
56
57 // Create an output container if it doesn't exist yet:
58 if( ( ! m_truthMeta ) && ( ! m_truthMetaAux ) ) {
59 ATH_MSG_DEBUG( "Creating output container" );
60 m_truthMeta = std::make_unique<xAOD::TruthMetaDataContainer>( );
61 m_truthMetaAux = std::make_unique<xAOD::TruthMetaDataAuxContainer>( );
62 m_truthMeta->setStore( m_truthMetaAux.get() );
63 }
64
65 // Loop over the configurations of the input file:
66 for( const xAOD::TruthMetaData* meta : *input ) {
67
68 // Check if this configuration is already in the output container:
69 bool exists = false;
70 for( const xAOD::TruthMetaData* existing : *m_truthMeta ) {
71 if( existing->mcChannelNumber() == meta->mcChannelNumber() ){
72 static const SG::ConstAccessor<std::string> generatorsAcc ("generators");
73 if (!generatorsAcc.isAvailable (*existing) ||
74 !generatorsAcc.isAvailable (*meta) ||
75 existing->generators() == meta->generators() ) {
76 exists = true;
77 break;
78 }
79 }
80 }
81 if( exists ) {
82 continue;
83 }
84
85 // If it's a new configuration, put it into the output container:
86 ATH_MSG_VERBOSE( "Copying configuration with ChannelID: "
87 << meta->mcChannelNumber() );
89 m_truthMeta->push_back( out );
90 *out = *meta;
91 }
92
93 // Return gracefully:
94 return StatusCode::SUCCESS;
95 }
96
98 return StatusCode::SUCCESS;
99 }
100
102
103 // The output may already have trigger configuration metadata in it.
104 // For instance from TrigConf::xAODMenuWriter. In this case let that
105 // object take precedence.
107 ATH_MSG_DEBUG( "xAOD::TruthMetaDataContainer already in the output" );
108 return StatusCode::SUCCESS;
109 }
110
111 // Record the truth metadata, if any was found in the processed input files.
112 if( m_truthMeta.get() && m_truthMetaAux.get() ) {
113 ATH_MSG_DEBUG( "Recording truth metadata" );
114 ATH_CHECK( outputMetaStore()->record( m_truthMeta.release(),
115 m_outputKey ) );
116 ATH_CHECK( outputMetaStore()->record( m_truthMetaAux.release(),
117 m_outputKey + "Aux." ) );
118 }
119
120 // Return gracefully:
121 return StatusCode::SUCCESS;
122 }
123
124} // namespace xAODMaker
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Helper class to provide constant type-safe access to aux data.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
MetaStorePtr_t outputMetaStore() const
Accessor for the output metadata store.
AsgMetadataTool(const std::string &name)
Normal ASG tool constructor with a name.
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
virtual StatusCode endInputFile()
Function called when the currently open input file got completely processed.
std::unique_ptr< xAOD::TruthMetaDataAuxContainer > m_truthMetaAux
The merged trigger menu auxiliary container.
virtual StatusCode initialize()
Function initialising the tool.
TruthMetaDataTool(const std::string &name="TruthMetaDataTool")
Declare the correct constructor for Athena.
std::unique_ptr< xAOD::TruthMetaDataContainer > m_truthMeta
The merged trigger menu container.
virtual StatusCode beginInputFile()
Function collecting the configuration metadata from the input file.
std::string m_outputKey
The key of the truth metadata for the output file.
std::string m_inputKey
The key of the truth metadata in the input file.
virtual StatusCode metaDataStop()
Function writing out the collected metadata.
bool exists(const std::string &filename)
does a file exist
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
-diff
xAOD::TruthMetaDataContainer Cont_t
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
TruthMetaData_v1 TruthMetaData
Typedef to implementation.