ATLAS Offline Software
xAODRingSetConfWriter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // STL include(s)
6 #include <algorithm>
7 #include <sstream>
8 
9 // Gaudi/Athena include(s):
11 
12 // Tool interface includes:
14 
15 // EDM include(s):
16 #include "xAODCore/AuxInfoBase.h"
18 
19 // Local include(s):
20 #include "xAODRingSetConfWriter.h"
21 
22 namespace Ringer {
23 
24 
25 // =================================================================================
27  ::ISvcLocator* svcLoc ) :
28  ::AthAlgorithm( name, svcLoc ),
29  m_metaStore( "MetaDataStore", name ),
30  m_inputMetaStore( "StoreGateSvc/InputMetaDataStore", name )
31 {
32 
33  declareProperty( "MetaDataStore", m_metaStore,
34  "The metadata Storage ServiceHandle. If empty, it will use "
35  "MetaDataStore service with same name as this algorithm.");
36 
37  declareProperty( "CaloRingsBuilderTools", m_crBuilderTools ,
38  "The CaloRingsBuilder tools handles array.");
39 
40  declareProperty( "RingSetConfContainerNames", m_rsMetaNames,
41  "The metadata RingSet Configuration container keys to write." );
42 
43 }
44 
45 // =================================================================================
47 
48  // Greet the user:
49  ATH_MSG_INFO( "Initialising" );
50 
51  // Make sure that configuration param are equivalent in size:
52  if ( m_crBuilderTools.size() != m_rsMetaNames.size() )
53  {
54 
55  ATH_MSG_ERROR("Configuration error: every CaloRingsBuilder should "
56  "have its own RingSet/CaloRings names "
57  "set via the RingSetConfMetaNames "
58  "python configurable.");
59 
60  ATH_MSG_ERROR("The retrieven m_RingSet names are: " << m_rsMetaNames );
61  ATH_MSG_ERROR("The retrieven m_crBuilderTools names are: "
62  << [this]()
63  {
64  std::vector<std::string> names;
65  for ( const auto& tool : m_crBuilderTools )
66  {
67  names.push_back( tool.name() );
68  }
69  return names;
70  }()
71  );
72 
73  return StatusCode::FAILURE;
74  }
75 
76  // Display the configuration:
77  ATH_MSG_DEBUG( "RingSetConfMetaNames = " << m_rsMetaNames );
78  if ( msg().level() <= MSG::DEBUG ){ // Display
79  std::vector<std::string> toolNames;
80  toolNames.reserve( m_crBuilderTools.size() );
81  for ( const auto &tool : m_crBuilderTools ){
82  toolNames.push_back( tool.name() );
83  }
84  ATH_MSG_DEBUG( "CaloRingsBuilderTools = " << toolNames );
85  }
86 
87  ATH_MSG_VERBOSE( "inputMetaStore = " << m_inputMetaStore->dump() );
88 
89  // Retrieve the necessary service(s):
90  CHECK( m_metaStore.retrieve() );
91  CHECK( m_inputMetaStore.retrieve() );
92 
93  // Now work to set xAOD RingSet/CaloRings configuration metadata available on
94  // the output meta store:
98 
99  // NOTE: This must be called after fillConfigurations, otherwise it will
100  // attempt to fill those configurations retrieven from the builders.
102 
103  // Print-out configurations:
104  ATH_MSG_DEBUG("There are available a total of " << m_rsConfContVec.size() << " RingSetConfContainer(s).");
105  for ( const auto* c : m_rsConfContVec ) {
106  if ( nullptr != c ) {
107  if ( msg().level() <= MSG::VERBOSE ) {
108  for ( const auto *const r : *c ){
109  std::ostringstream str;
110  r->print( str );
111  ATH_MSG_VERBOSE( str.str() );
112  }
113  }
114  } else {
115  ATH_MSG_WARNING("Container " << c << "is empty!");
116  }
117  }
118 
119  ATH_MSG_DEBUG("Obtained configuration succesfully.");
120 
121  ATH_MSG_VERBOSE( "outputMetaStore = " << m_metaStore->dump() );
122 
123  // Return gracefully:
124  return StatusCode::SUCCESS;
125 }
126 
127 // =================================================================================
129 {
130  ATH_MSG_DEBUG("Checking if it is needed to copy RingSetConf "
131  "MetaData on input file.");
132 
133  CHECK( searchAndCopyCLID< xAOD::RingSetConfAuxContainer >(
135 
136  return StatusCode::SUCCESS;
137 }
138 
139 // =================================================================================
140 template< class auxT, class T >
142  const ClassID_traits< T >& classID )
143 {
144  std::vector< std::string > ringConfKeys;
145 
146  // Retrieve our container keys:
147  m_inputMetaStore->keys( classID.ID() , ringConfKeys);
148 
149  ATH_MSG_DEBUG( "Available keys with type(" << classID.typeName() << ") are: "
150  << ringConfKeys );
151 
152  // Now loop retrieving them and recording on the outputContainer:
153  for ( const auto &key : ringConfKeys )
154  {
155  if (key[0] == ';' && key[3] == ';') continue; // ignore versioned keys
156  ATH_MSG_VERBOSE( "Attempting to copy " << key );
157 
158  // Check if this meta isn't already available in output, if so, do not copy it:
159  if ( std::any_of( m_rsMetaNames.begin(), m_rsMetaNames.end(),
160  [&key](std::string &builderKey){
161  return (builderKey == key) || ((builderKey + "Aux.") == key);
162  } ) )
163  {
164  ATH_MSG_VERBOSE( "This key is already going to be built "
165  "(outputMetaNames = " << m_rsMetaNames << ")"
166  ", it will NOT be copied!" );
167  continue;
168  }
169 
170  // Retrieve and record its copy in output store
171  CHECK( (copyKeyToStore<auxT, T>( key )) );
172  ATH_MSG_INFO( "Successfully copied key " << key );
173  }
174 
175  return StatusCode::SUCCESS;
176 
177 }
178 
179 // =================================================================================
180 template < class auxT, class T >
182 {
183  typedef typename T::value_type value_type;
184  typedef typename T::base_value_type base_value_type;
185  // Retrieve container
186  const T* cont(nullptr);
187  CHECK( m_inputMetaStore->retrieve( cont, key ) );
188 
189  // Create new containers:
190  auxT* contAuxCopy = new auxT;
191  T* contCopy = new T;
192  contCopy->setStore( contAuxCopy );
193 
194  // Copy them:
195  contCopy->reserve( cont->size() );
196  contAuxCopy->reserve( cont->size() );
197  ATH_MSG_DEBUG("Copying object with key: " << key);
198  for ( const base_value_type* obj : *cont ) {
199  ATH_MSG_VERBOSE("Original object:");
200  // Print-out object:
201  if( msgLevel() <= MSG::VERBOSE ) {
202  std::ostringstream str;
203  obj->print( str );
204  ATH_MSG_VERBOSE( str.str() );
205  }
206  // Copy object
207  value_type objCopy = new (base_value_type)( *obj );
208  // Print-out object:
209  ATH_MSG_VERBOSE("Copied object:");
210  if( msgLevel() <= MSG::VERBOSE ) {
211  std::ostringstream str;
212  objCopy->print( str );
213  ATH_MSG_VERBOSE( str.str() );
214  }
215  // Add to container
216  contCopy->push_back( objCopy );
217  }
218 
219  // And record:
220  CHECK( m_metaStore->record( contAuxCopy, key + "Aux.") );
221  CHECK( m_metaStore->record( contCopy, key) );
222 
223  return StatusCode::SUCCESS;
224 }
225 
226 
227 // =================================================================================
229 {
230  ATH_MSG_INFO("Retrieving " << m_crBuilderTools.size() <<
231  " reader tools for " << name() );
232 
233  ATH_CHECK(m_crBuilderTools.retrieve());
234 
235  return StatusCode::SUCCESS;
236 }
237 
238 // =================================================================================
240 {
241 
242  for (size_t counter = 0; counter < m_rsMetaNames.size(); ++counter)
243  {
244  // Create an empty RingSetConf container:
247  rsCont->setStore( rsAux );
248  m_rsConfContVec.push_back( rsCont );
249 
250  // Record the RingSet configuration metadata into output container:
251  CHECK( m_metaStore->record( rsAux, m_rsMetaNames[counter] + "Aux." ) );
252  CHECK( m_metaStore->record( rsCont, m_rsMetaNames[counter] ) );
253  }
254 
255  return StatusCode::SUCCESS;
256 }
257 
258 // =================================================================================
260 {
261 
262  for (size_t counter = 0; counter < m_rsConfContVec.size(); ++counter)
263  {
264  auto& crBuilder = m_crBuilderTools[counter];
265  auto& rsCont = m_rsConfContVec[counter];
266 
267  // Create the xAOD configuration object (it will populate
268  // RingSetConfContainer for us):
270  crBuilder->rawConf(),
271  rsCont);
272 
273  // Inform what we did:
274  ATH_MSG_DEBUG( "Got configuration for " << crBuilder->name() << "." );
275 
276  }
277 
278  return StatusCode::SUCCESS;
279 
280 }
281 
282 
283 // =================================================================================
285 {
286  // Our execute don't do anything... we don't have any assyncronous change of
287  // configuration, so we don't need to keep track of what happens here.
288  // Return gracefully:
289  return StatusCode::SUCCESS;
290 }
291 
292 // =================================================================================
294 {
295  return StatusCode::SUCCESS;
296 }
297 
298 } // namespace Ringer
RingSetConfAuxContainer.h
ICaloRingsBuilder.h
beamspotman.r
def r
Definition: beamspotman.py:676
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Ringer::xAODRingSetConfWriter::initialize
StatusCode initialize()
Method initialising the algorithm.
Definition: xAODRingSetConfWriter.cxx:46
Ringer::xAODRingSetConfWriter::execute
StatusCode execute()
Method executing the algorithm.
Definition: xAODRingSetConfWriter.cxx:284
Ringer::xAODRingSetConfWriter::allocateContainers
StatusCode allocateContainers()
Prepare containers to retrieve configurations.
Definition: xAODRingSetConfWriter.cxx:239
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Ringer::xAODRingSetConfWriter::finalize
StatusCode finalize()
Method executing the algorithm.
Definition: xAODRingSetConfWriter.cxx:293
AuxInfoBase.h
Ringer::xAODRingSetConfWriter::searchAndCopyCLID
StatusCode searchAndCopyCLID(const ClassID_traits< T > &classID)
Auxiliary method called by copyInputMetaStore.
Definition: xAODRingSetConfWriter.cxx:141
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Ringer::xAODRingSetConfWriter::retrieveCaloRingsBuilders
StatusCode retrieveCaloRingsBuilders()
Retrieve CaloRingsBuilder tools.
Definition: xAODRingSetConfWriter.cxx:228
Ringer::xAODRingSetConfWriter::m_rsConfContVec
std::vector< xAOD::RingSetConfContainer * > m_rsConfContVec
Private properties (non python configurables):The CaloRings configuration container.
Definition: xAODRingSetConfWriter.h:79
xAODRingSetConfWriter.h
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
ClassID_traits::typeName
static const std::string & typeName()
the demangled type name of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:56
Ringer::xAODRingSetConfWriter::m_rsMetaNames
std::vector< std::string > m_rsMetaNames
StoreGate keys for the RingSet configurations.
Definition: xAODRingSetConfWriter.h:73
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::RingSetConfContainer
RingSetConfContainer_v1 RingSetConfContainer
Definition of the current "RingSetConf container version".
Definition: RingSetConfContainer.h:21
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
python.subdetectors.mmg.names
names
Definition: mmg.py:8
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::RingSetConfAuxContainer_v1
Auxiliary store for xAOD::RingSetConfContainer.
Definition: RingSetConfAuxContainer_v1.h:17
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
Ringer::xAODRingSetConfWriter::fillConfigurations
StatusCode fillConfigurations()
Fill the containers with each CaloRingsBuilder tool configuration.
Definition: xAODRingSetConfWriter.cxx:259
Ringer::xAODRingSetConfWriter::m_metaStore
ServiceHandle< StoreGateSvc > m_metaStore
Private properties (python configurables):Connection to the (output)metadata store.
Definition: xAODRingSetConfWriter.h:67
Ringer::xAODRingSetConfWriter::copyKeyToStore
StatusCode copyKeyToStore(const std::string &key)
Retrieve a key and returns a copy of it to outputmeta.
Definition: xAODRingSetConfWriter.cxx:181
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Ringer::xAODRingSetConfWriter::m_inputMetaStore
ServiceHandle< StoreGateSvc > m_inputMetaStore
Connection to the inputMetadata store.
Definition: xAODRingSetConfWriter.h:69
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
xAOD::RingSetConfAuxContainer
RingSetConfAuxContainer_v1 RingSetConfAuxContainer
Definition of the current RingSetConf auxiliary container.
Definition: RingSetConfAuxContainer.h:20
Ringer::xAODRingSetConfWriter::m_crBuilderTools
ToolHandleArray< Ringer::ICaloRingsBuilder > m_crBuilderTools
Connection to the trigger configuration service.
Definition: xAODRingSetConfWriter.h:71
str
Definition: BTagTrackIpAccessor.cxx:11
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
test_pyathena.counter
counter
Definition: test_pyathena.py:15
python.PyAthena.obj
obj
Definition: PyAthena.py:135
value_type
Definition: EDM_MasterSearch.h:11
Ringer::xAODRingSetConfWriter::xAODRingSetConfWriter
xAODRingSetConfWriter(const std::string &name, ::ISvcLocator *svcLoc)
Regular Algorithm constructor.
Definition: xAODRingSetConfWriter.cxx:26
python.compressB64.c
def c
Definition: compressB64.py:93
xAOD::RingSetConf_v1::fillRingSetConfContainer
static void fillRingSetConfContainer(const RawConfCollection &rawConfCol, RingSetConfContainer_v1 *container)
Creates RingSetConfContainer from RawConfCollection.
Definition: RingSetConf_v1.cxx:360
Ringer::xAODRingSetConfWriter::copyInputMetaStore
StatusCode copyInputMetaStore()
Private methods:
Definition: xAODRingSetConfWriter.cxx:128
Ringer
Namespace dedicated for Ringer utilities.
Definition: CaloRingsDefs.h:9
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37