ATLAS Offline Software
Loading...
Searching...
No Matches
AthCommonDataStore.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
14
15#ifndef ATHENABASECOMPS_ATHCOMMONDATASTORE_H
16#define ATHENABASECOMPS_ATHCOMMONDATASTORE_H
17
18#include <string>
19#include <type_traits>
20
21// Need to do this very early so parser for VarHandleKey picked up
22#include "GaudiKernel/StatusCode.h"
23namespace SG {
24 class VarHandleKey;
26 class VarHandleBase;
27}
28namespace Gaudi {
29 namespace Parsers {
30 StatusCode parse(SG::VarHandleKey& v, const std::string& s);
31 StatusCode parse(SG::VarHandleKeyArray& v, const std::string& s);
32 StatusCode parse(SG::VarHandleBase& v, const std::string& s);
33 }
34}
35
39
40#include "GaudiKernel/ServiceHandle.h"
48
49
50
51template <class PBASE>
52class AthCommonDataStore : public PBASE {
53public:
54 template <typename... T>
55 AthCommonDataStore(const std::string& name, T... args)
56 : PBASE(name, std::move(args)...),
57 m_evtStore ( "StoreGateSvc/StoreGateSvc", name ),
58 m_detStore ( "StoreGateSvc/DetectorStore", name ),
60 {
61
62 this->declareProperty( "EvtStore",
63 m_evtStore = StoreGateSvc_t ("StoreGateSvc", name),
64 "Handle to a StoreGateSvc instance: it will be used to "
65 "retrieve data during the course of the job" );
66
67 this->declareProperty( "DetStore",
68 m_detStore = StoreGateSvc_t ("StoreGateSvc/DetectorStore", name),
69 "Handle to a StoreGateSvc/DetectorStore instance: it will be used to "
70 "retrieve data during the course of the job" );
71
72 auto props = this->getProperties();
73 for( Gaudi::Details::PropertyBase* prop : props ) {
74 if (prop->name() == "ExtraOutputs" || prop->name() == "ExtraInputs") {
75 prop->declareUpdateHandler
77 }
78 }
79 }
80
81
86
91
96
97
105 virtual StatusCode sysInitialize() override;
106
113 virtual StatusCode sysStart() override;
114
122 virtual std::vector<Gaudi::DataHandle*> inputHandles() const override;
123
124
132 virtual std::vector<Gaudi::DataHandle*> outputHandles() const override;
133
134
135
136 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
137 public:
139 //
141 // style properties in AthAlgorithms
142 //
143
144 template <class T, class V, class H>
145 Gaudi::Details::PropertyBase& declareProperty(Gaudi::Property<T,V,H> &t) {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
149
150 private:
155 template <class T, class V, class H>
156 Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T,V,H> &hndl,
158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }
164
169 template <class T, class V, class H>
170 Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T,V,H> &hndl,
172 {
174 hndl.value(),
175 hndl.documentation());
176
177 }
178
183 template <class T, class V, class H>
184 Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T,V,H> &hndl,
185 const SG::VarHandleType&)
186 {
188 hndl.value(),
189 hndl.documentation());
190 }
191
192
198 template <class T, class V, class H>
199 Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T,V,H> &t, const SG::NotHandleType&)
200 {
201 return PBASE::declareProperty(t);
202 }
203
204
206 //
208 //
209
210public:
221 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
222 SG::VarHandleKey& hndl,
223 const std::string& doc,
225 {
226 this->declare(hndl);
227 hndl.setOwner(this);
228
229 return PBASE::declareProperty(name,hndl,doc);
230 }
231
232
233/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
234
245 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
246 SG::VarHandleBase& hndl,
247 const std::string& doc,
248 const SG::VarHandleType&)
249 {
250 this->declare(hndl.vhKey());
251 hndl.vhKey().setOwner(this);
252
253 return PBASE::declareProperty(name,hndl,doc);
254 }
255
256
257/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
258
259 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
260 SG::VarHandleKeyArray& hndArr,
261 const std::string& doc,
263 {
264
265 // std::ostringstream ost;
266 // ost << Algorithm::name() << " VHKA declareProp: " << name
267 // << " size: " << hndArr.keys().size()
268 // << " mode: " << hndArr.mode()
269 // << " vhka size: " << m_vhka.size()
270 // << "\n";
271 // debug() << ost.str() << endmsg;
272
273 hndArr.setOwner(this);
274 m_vhka.push_back(&hndArr);
275
276 Gaudi::Details::PropertyBase* p = PBASE::declareProperty(name, hndArr, doc);
277 if (p != 0) {
278 p->declareUpdateHandler(&AthCommonDataStore<PBASE>::updateVHKA, this);
279 } else {
280 ATH_MSG_ERROR("unable to call declareProperty on VarHandleKeyArray "
281 << name);
282 }
283
284 return p;
285
286 }
287
288
289/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
290
291 // Since the contents of the VarHandleKeyArrays have not been read
292 // in from the configurables by the time that declareProperty is
293 // executed, we must cache them and loop through them later to
294 // register the data dependencies.
295 //
296 // However, we cannot actually call declare() on the key instances
297 // until we know that the vector cannot change size anymore --- otherwise,
298 // the pointers given to declare() may become invalid. That basically means
299 // that we can't call declare() until the derived class's initialize()
300 // completes. So instead of doing it here (which would be too early),
301 // we override sysInitialize() and do it at the end of that. But,
302 // Algorithm::sysInitialize() wants to have the handle lists after initialize()
303 // completes in order to do dependency analysis. It gets these lists
304 // solely by calling inputHandles() and outputHandles(), so we can get this
305 // to work by overriding those methods and adding in the current contents
306 // of the arrays.
307
308 void updateVHKA(Gaudi::Details::PropertyBase& /*p*/) {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
312 std::vector<SG::VarHandleKey*> keys = a->keys();
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
318
319/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
320
321
332 template <class T>
333 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
334 T& property,
335 const std::string& doc,
336 const SG::NotHandleType&)
337 {
338 return PBASE::declareProperty(name, property, doc);
339 }
340
341
351 template <class T>
352 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
353 T& property,
354 const std::string& doc="none")
355 {
356 typedef typename SG::HandleClassifier<T>::type htype;
357 return declareProperty (name, property, doc, htype());
358 }
359
360
361
362protected:
364 void renounceArray( SG::VarHandleKeyArray& handlesArray ) {
365 handlesArray.renounce();
366 }
367
368
369 // renounce() from the Gaudi base class.
370 // But if the handle class also declares a renounce(), then call that first.
371 // For safety, allow this only if the argument derives from Gaudi::DataHandle
372 // and (to prevent confusion with the above method) it is not
373 // a VarHandleKeyArray.
374 using PBASE::renounce;
375 template <class T>
376 std::enable_if_t<std::is_void_v<std::result_of_t<decltype(&T::renounce)(T)> > &&
377 !std::is_base_of_v<SG::VarHandleKeyArray, T> &&
378 std::is_base_of_v<Gaudi::DataHandle, T>,
379 void>
381 {
382 h.renounce();
383 PBASE::renounce (h);
384 }
385
386
387private:
391
394
395
396private:
397 // to keep track of VarHandleKeyArrays for data dep registration
398 std::vector<SG::VarHandleKeyArray*> m_vhka;
400
401
402protected:
410 void extraDeps_update_handler( Gaudi::Details::PropertyBase& ExtraDeps );
411
412
413};
414
415#include "AthCommonDataStore.icc"
416
417#endif
#define ATH_MSG_ERROR(x)
Helper to classify the type of a handle property.
static Double_t a
Base class for VarHandle classes.
Base class for VarHandleKeyArray for reading from StoreGate.
A property holding a SG store/key/clid from which a VarHandle is made.
class to handle Properties for VarHandleKeyArray
Handle Gaudi property setting for VarHandleKey.
virtual std::vector< Gaudi::DataHandle * > inputHandles() const override
Return this algorithm's input handles.
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
AthCommonDataStore(const std::string &name, T... args)
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &t, const SG::NotHandleType &)
specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHa...
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, SG::VarHandleKey &hndl, const std::string &doc, const SG::VarHandleKeyType &)
Declare a new Gaudi property.
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
Return this algorithm's output handles.
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, SG::VarHandleKeyArray &hndArr, const std::string &doc, const SG::VarHandleKeyArrayType &)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::vector< SG::VarHandleKeyArray * > m_vhka
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyArrayType &)
specialization for handling Gaudi::Property<SG::VarHandleKeyArray>
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, SG::VarHandleBase &hndl, const std::string &doc, const SG::VarHandleType &)
Declare a new Gaudi property.
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysStart() override
Handle START transition.
const ServiceHandle< StoreGateSvc > & evtStore() const
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
void extraDeps_update_handler(Gaudi::Details::PropertyBase &ExtraDeps)
Add StoreName to extra input/output deps as needed.
virtual StatusCode sysInitialize() override
Perform system initialization for an algorithm.
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleType &)
specialization for handling Gaudi::Property<SG::VarHandleBase>
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>
void updateVHKA(Gaudi::Details::PropertyBase &)
void renounceArray(SG::VarHandleKeyArray &handlesArray)
remove all handles from I/O resolution
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, T &property, const std::string &doc, const SG::NotHandleType &)
Declare a new Gaudi property.
ServiceHandle< StoreGateSvc > StoreGateSvc_t
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, T &property, const std::string &doc="none")
Declare a new Gaudi property.
Header file for AthHistogramAlgorithm.
Base class for VarHandle types.
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
virtual void setOwner(IDataHandleHolder *o)=0
virtual void renounce()=0
A property holding a SG store/key/clid from which a VarHandle is made.
::StatusCode StatusCode
StatusCode definition for legacy code.
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
=============================================================================
Forward declaration.
STL namespace.
std::conditional< std::is_base_of< SG::VarHandleKeyArray, T >::value, VarHandleKeyArrayType, type2 >::type type