ATLAS Offline Software
Loading...
Searching...
No Matches
AthCommonDataStore.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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 hndArr.setOwner(this);
265 m_vhka.push_back(&hndArr);
266
267 Gaudi::Details::PropertyBase* p = PBASE::declareProperty(name, hndArr, doc);
268 if (p != 0) {
269 p->declareUpdateHandler(&AthCommonDataStore<PBASE>::updateVHKA, this);
270 } else {
271 ATH_MSG_ERROR("unable to call declareProperty on VarHandleKeyArray {}", name);
272 }
273
274 return p;
275
276 }
277
278
279/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
280
281 // Since the contents of the VarHandleKeyArrays have not been read
282 // in from the configurables by the time that declareProperty is
283 // executed, we must cache them and loop through them later to
284 // register the data dependencies.
285 //
286 // However, we cannot actually call declare() on the key instances
287 // until we know that the vector cannot change size anymore --- otherwise,
288 // the pointers given to declare() may become invalid. That basically means
289 // that we can't call declare() until the derived class's initialize()
290 // completes. So instead of doing it here (which would be too early),
291 // we override sysInitialize() and do it at the end of that. But,
292 // Algorithm::sysInitialize() wants to have the handle lists after initialize()
293 // completes in order to do dependency analysis. It gets these lists
294 // solely by calling inputHandles() and outputHandles(), so we can get this
295 // to work by overriding those methods and adding in the current contents
296 // of the arrays.
297
298 void updateVHKA(Gaudi::Details::PropertyBase& /*p*/) {
299 for (auto &a : m_vhka) {
300 std::vector<SG::VarHandleKey*> keys = a->keys();
301 for (auto k : keys) {
302 k->setOwner(this);
303 }
304 }
305 }
306
307/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
308
309
320 template <class T>
321 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
322 T& property,
323 const std::string& doc,
324 const SG::NotHandleType&)
325 {
326 return PBASE::declareProperty(name, property, doc);
327 }
328
329
339 template <class T>
340 Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
341 T& property,
342 const std::string& doc="none")
343 {
344 typedef typename SG::HandleClassifier<T>::type htype;
345 return declareProperty (name, property, doc, htype());
346 }
347
348
349
350protected:
352 void renounceArray( SG::VarHandleKeyArray& handlesArray ) {
353 handlesArray.renounce();
354 }
355
356
357 // renounce() from the Gaudi base class.
358 // But if the handle class also declares a renounce(), then call that first.
359 // For safety, allow this only if the argument derives from Gaudi::DataHandle
360 // and (to prevent confusion with the above method) it is not
361 // a VarHandleKeyArray.
362 using PBASE::renounce;
363 template <class T>
364 std::enable_if_t<std::is_void_v<std::result_of_t<decltype(&T::renounce)(T)> > &&
365 !std::is_base_of_v<SG::VarHandleKeyArray, T> &&
366 std::is_base_of_v<Gaudi::DataHandle, T>,
367 void>
369 {
370 h.renounce();
371 PBASE::renounce (h);
372 }
373
374
375private:
379
382
383
384private:
385 // to keep track of VarHandleKeyArrays for data dep registration
386 std::vector<SG::VarHandleKeyArray*> m_vhka;
388
389
390protected:
398 void extraDeps_update_handler( Gaudi::Details::PropertyBase& ExtraDeps );
399
400
401};
402
403#include "AthCommonDataStore.icc"
404
405#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