ATLAS Offline Software
Loading...
Searching...
No Matches
xAODRingSetConfWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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):
18
19// Local include(s):
21
22namespace Ringer {
23
24
25// =================================================================================
27 ::ISvcLocator* svcLoc ) :
28 ::AthAlgorithm( name, svcLoc ),
29 m_metaStore( "StoreGateSvc/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
135
136 return StatusCode::SUCCESS;
137}
138
139// =================================================================================
140template< 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// =================================================================================
180template < class auxT, class T >
181StatusCode xAODRingSetConfWriter::copyKeyToStore( const std::string &key )
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
266 // Create the xAOD configuration object (it will populate
267 // RingSetConfContainer for us):
269 crBuilder->rawConf(),
270 *m_rsConfContVec[counter]);
271
272 // Inform what we did:
273 ATH_MSG_DEBUG( "Got configuration for " << crBuilder->name() << "." );
274
275 }
276
277 return StatusCode::SUCCESS;
278
279}
280
281
282// =================================================================================
284{
285 // Our execute don't do anything... we don't have any assyncronous change of
286 // configuration, so we don't need to keep track of what happens here.
287 // Return gracefully:
288 return StatusCode::SUCCESS;
289}
290
291// =================================================================================
293{
294 return StatusCode::SUCCESS;
295}
296
297} // namespace Ringer
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
MsgStream & msg() const
ServiceHandle< StoreGateSvc > m_metaStore
Private properties (python configurables):Connection to the (output)metadata store.
StatusCode allocateContainers()
Prepare containers to retrieve configurations.
std::vector< std::string > m_rsMetaNames
StoreGate keys for the RingSet configurations.
StatusCode execute()
Method executing the algorithm.
StatusCode copyKeyToStore(const std::string &key)
Retrieve a key and returns a copy of it to outputmeta.
StatusCode copyInputMetaStore()
Private methods:
StatusCode searchAndCopyCLID(const ClassID_traits< T > &classID)
Auxiliary method called by copyInputMetaStore.
StatusCode fillConfigurations()
Fill the containers with each CaloRingsBuilder tool configuration.
std::vector< xAOD::RingSetConfContainer * > m_rsConfContVec
Private properties (non python configurables):The CaloRings configuration container.
StatusCode initialize()
Method initialising the algorithm.
StatusCode retrieveCaloRingsBuilders()
Retrieve CaloRingsBuilder tools.
ServiceHandle< StoreGateSvc > m_inputMetaStore
Connection to the inputMetadata store.
ToolHandleArray< Ringer::ICaloRingsBuilder > m_crBuilderTools
Connection to the trigger configuration service.
xAODRingSetConfWriter(const std::string &name, ::ISvcLocator *svcLoc)
Regular Algorithm constructor.
StatusCode finalize()
Method executing the algorithm.
static void fillRingSetConfContainer(const RawConfCollection &rawConfCol, RingSetConfContainer_v1 &container)
Creates RingSetConfContainer from RawConfCollection.
int r
Definition globals.cxx:22
Namespace dedicated for Ringer utilities.
RingSetConfContainer_v1 RingSetConfContainer
Definition of the current "RingSetConf container version".
RingSetConfAuxContainer_v1 RingSetConfAuxContainer
Definition of the current RingSetConf auxiliary container.
This specialization is used for classes deriving from DataObject.
static const std::string & typeName()
the demangled type name of T
Default, invalid implementation of ClassID_traits.