ATLAS Offline Software
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 
14 namespace xAODMaker {
15 
16  // Helper typedef:
18 
20  : asg::AsgMetadataTool( name ),
21  m_truthMeta(), m_truthMetaAux() {
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:
49  if( ! inputMetaStore()->contains< Cont_t >( m_inputKey ) ) {
50  return StatusCode::SUCCESS;
51  }
52 
53  // Retrieve the input container:
54  const Cont_t* input = nullptr;
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.
106  if( outputMetaStore()->contains< Cont_t >( m_outputKey ) ) {
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
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::TruthMetaDataContainer
TruthMetaDataContainer_v1 TruthMetaDataContainer
Declare the latest version of the truth vertex container.
Definition: TruthMetaDataContainer.h:17
xAODMaker::TruthMetaDataTool::beginInputFile
virtual StatusCode beginInputFile()
Function collecting the configuration metadata from the input file.
Definition: TruthMetaDataTool.cxx:45
asg
Definition: DataHandleTestTool.h:28
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
asg::AsgMetadataTool::inputMetaStore
MetaStorePtr_t inputMetaStore() const
Accessor for the input metadata store.
Definition: AsgMetadataTool.cxx:88
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAODMaker::TruthMetaDataTool::m_truthMetaAux
std::unique_ptr< xAOD::TruthMetaDataAuxContainer > m_truthMetaAux
The merged trigger menu auxiliary container.
Definition: TruthMetaDataTool.h:91
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAODMaker
Definition: StoreGateSvc.h:72
xAOD::TruthMetaData
TruthMetaData_v1 TruthMetaData
Typedef to implementation.
Definition: TruthMetaData.h:15
xAODMaker::TruthMetaDataTool::m_truthMeta
std::unique_ptr< xAOD::TruthMetaDataContainer > m_truthMeta
The merged trigger menu container.
Definition: TruthMetaDataTool.h:89
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODMaker::TruthMetaDataTool::initialize
virtual StatusCode initialize()
Function initialising the tool.
Definition: TruthMetaDataTool.cxx:31
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::TruthMetaData_v1
Class describing meta data for truth records.
Definition: TruthMetaData_v1.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAODMaker::TruthMetaDataTool::m_outputKey
std::string m_outputKey
The key of the truth metadata for the output file.
Definition: TruthMetaDataTool.h:81
asg::AsgMetadataTool::outputMetaStore
MetaStorePtr_t outputMetaStore() const
Accessor for the output metadata store.
Definition: AsgMetadataTool.cxx:97
xAODMaker::TruthMetaDataTool::m_inputKey
std::string m_inputKey
The key of the truth metadata in the input file.
Definition: TruthMetaDataTool.h:79
TruthMetaDataTool.h
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
xAODMaker::TruthMetaDataTool::endInputFile
virtual StatusCode endInputFile()
Function called when the currently open input file got completely processed.
Definition: TruthMetaDataTool.cxx:97
xAODMaker::TruthMetaDataTool::metaDataStop
virtual StatusCode metaDataStop()
Function writing out the collected metadata.
Definition: TruthMetaDataTool.cxx:101
xAODMaker::TruthMetaDataTool::TruthMetaDataTool
TruthMetaDataTool(const std::string &name="TruthMetaDataTool")
Declare the correct constructor for Athena.
Definition: TruthMetaDataTool.cxx:19