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 >
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 ATH_MSG_VERBOSE( "Attempting to copy " << key );
156 // Check if this meta isn't already available in output, if so, do not copy it:
157 if ( std::any_of( m_rsMetaNames.begin(), m_rsMetaNames.end(),
158 [&key](std::string &builderKey){
159 return (builderKey == key) || ((builderKey + "Aux.") == key);
160 } ) )
161 {
162 ATH_MSG_VERBOSE( "This key is already going to be built "
163 "(outputMetaNames = " << m_rsMetaNames << ")"
164 ", it will NOT be copied!" );
165 continue;
166 }
167
168 // Retrieve and record its copy in output store
169 CHECK( (copyKeyToStore<auxT, T>( key )) );
170 ATH_MSG_INFO( "Successfully copied key " << key );
171 }
172
173 return StatusCode::SUCCESS;
174
175}
176
177// =================================================================================
178template < class auxT, class T >
179StatusCode xAODRingSetConfWriter::copyKeyToStore( const std::string &key )
180{
181 typedef typename T::value_type value_type;
182 typedef typename T::base_value_type base_value_type;
183 // Retrieve container
184 const T* cont(nullptr);
185 CHECK( m_inputMetaStore->retrieve( cont, key ) );
186
187 // Create new containers:
188 auxT* contAuxCopy = new auxT;
189 T* contCopy = new T;
190 contCopy->setStore( contAuxCopy );
191
192 // Copy them:
193 contCopy->reserve( cont->size() );
194 contAuxCopy->reserve( cont->size() );
195 ATH_MSG_DEBUG("Copying object with key: " << key);
196 for ( const base_value_type* obj : *cont ) {
197 ATH_MSG_VERBOSE("Original object:");
198 // Print-out object:
199 if( msgLevel() <= MSG::VERBOSE ) {
200 std::ostringstream str;
201 obj->print( str );
202 ATH_MSG_VERBOSE( str.str() );
203 }
204 // Copy object
205 value_type objCopy = new (base_value_type)( *obj );
206 // Print-out object:
207 ATH_MSG_VERBOSE("Copied object:");
208 if( msgLevel() <= MSG::VERBOSE ) {
209 std::ostringstream str;
210 objCopy->print( str );
211 ATH_MSG_VERBOSE( str.str() );
212 }
213 // Add to container
214 contCopy->push_back( objCopy );
215 }
216
217 // And record:
218 CHECK( m_metaStore->record( contAuxCopy, key + "Aux.") );
219 CHECK( m_metaStore->record( contCopy, key) );
220
221 return StatusCode::SUCCESS;
222}
223
224
225// =================================================================================
227{
228 ATH_MSG_INFO("Retrieving " << m_crBuilderTools.size() <<
229 " reader tools for " << name() );
230
231 ATH_CHECK(m_crBuilderTools.retrieve());
232
233 return StatusCode::SUCCESS;
234}
235
236// =================================================================================
238{
239
240 for (size_t counter = 0; counter < m_rsMetaNames.size(); ++counter)
241 {
242 // Create an empty RingSetConf container:
245 rsCont->setStore( rsAux );
246 m_rsConfContVec.push_back( rsCont );
247
248 // Record the RingSet configuration metadata into output container:
249 CHECK( m_metaStore->record( rsAux, m_rsMetaNames[counter] + "Aux." ) );
250 CHECK( m_metaStore->record( rsCont, m_rsMetaNames[counter] ) );
251 }
252
253 return StatusCode::SUCCESS;
254}
255
256// =================================================================================
258{
259
260 for (size_t counter = 0; counter < m_rsConfContVec.size(); ++counter)
261 {
262 auto& crBuilder = m_crBuilderTools[counter];
263
264 // Create the xAOD configuration object (it will populate
265 // RingSetConfContainer for us):
267 crBuilder->rawConf(),
268 *m_rsConfContVec[counter]);
269
270 // Inform what we did:
271 ATH_MSG_DEBUG( "Got configuration for " << crBuilder->name() << "." );
272
273 }
274
275 return StatusCode::SUCCESS;
276
277}
278
279
280// =================================================================================
281StatusCode xAODRingSetConfWriter::execute(const EventContext& /*ctx*/)
282{
283 // Our execute don't do anything... we don't have any assyncronous change of
284 // configuration, so we don't need to keep track of what happens here.
285 // Return gracefully:
286 return StatusCode::SUCCESS;
287}
288
289// =================================================================================
291{
292 return StatusCode::SUCCESS;
293}
294
295} // namespace Ringer
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(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.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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 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.
StatusCode execute(const EventContext &ctx)
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.
Default, invalid implementation of ClassID_traits.