ATLAS Offline Software
AthCommonDataStore.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
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"
23 namespace SG {
24  class VarHandleKey;
25  class VarHandleKeyArray;
26  class VarHandleBase;
27 }
28 namespace 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"
41 #include "StoreGate/StoreGateSvc.h"
44 #include "StoreGate/VarHandleKey.h"
48 
49 
50 
51 template <class PBASE>
52 class AthCommonDataStore : public PBASE {
53 public:
54  template <typename... T>
55  AthCommonDataStore(const std::string& name, T... args)
56  : PBASE(name, 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 
90  const ServiceHandle<StoreGateSvc>& evtStore() const { return m_evtStore; }
91 
95  const ServiceHandle<StoreGateSvc>& detStore() const { return m_detStore; }
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>
145  Gaudi::Details::PropertyBase& declareProperty(Gaudi::Property<T> &t) {
146  typedef typename SG::HandleClassifier<T>::type htype;
148  }
149 
150  private:
155  template <class T>
156  Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T> &hndl,
157  const SG::VarHandleKeyType&)
158  {
159  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
160  hndl.value(),
161  hndl.documentation());
162 
163  }
164 
169  template <class T>
170  Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T> &hndl,
172  {
173  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
174  hndl.value(),
175  hndl.documentation());
176 
177  }
178 
183  template <class T>
184  Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T> &hndl,
185  const SG::VarHandleType&)
186  {
187  return *AthCommonDataStore<PBASE>::declareProperty(hndl.name(),
188  hndl.value(),
189  hndl.documentation());
190  }
191 
192 
198  template <class T>
199  Gaudi::Details::PropertyBase& declareGaudiProperty(Gaudi::Property<T> &t, const SG::NotHandleType&)
200  {
201  return PBASE::declareProperty(t);
202  }
203 
204 
206  //
208  //
209 
210 public:
221  Gaudi::Details::PropertyBase* declareProperty(const std::string& name,
222  SG::VarHandleKey& hndl,
223  const std::string& doc,
224  const SG::VarHandleKeyType&)
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 
362 protected:
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 
387 private:
391 
394 
395 
396 private:
397  // to keep track of VarHandleKeyArrays for data dep registration
398  std::vector<SG::VarHandleKeyArray*> m_vhka;
400 
401 
402 protected:
410  void extraDeps_update_handler( Gaudi::Details::PropertyBase& ExtraDeps );
411 
412 
413 };
414 
415 #include "AthCommonDataStore.icc"
416 
417 #endif
VarHandleBase.h
Base class for VarHandle classes.
AthCommonDataStore::extraDeps_update_handler
void extraDeps_update_handler(Gaudi::Details::PropertyBase &ExtraDeps)
Add StoreName to extra input/output deps as needed.
AthCommonDataStore::sysStart
virtual StatusCode sysStart() override
Handle START transition.
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
beamspotPlotBcids.k
k
Definition: beamspotPlotBcids.py:524
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
VarHandleKeyProperty.h
Handle Gaudi property setting for VarHandleKey.
VarHandleKey.h
A property holding a SG store/key/clid from which a VarHandle is made.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
AthCommonDataStore::AthCommonDataStore
AthCommonDataStore(const std::string &name, T... args)
Definition: AthCommonDataStore.h:55
Gaudi::Parsers::parse
StatusCode parse(std::tuple< Tup... > &tup, const Gaudi::Parsers::InputData &input)
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:284
AthCheckMacros.h
AthCommonDataStore::m_varHandleArraysDeclared
bool m_varHandleArraysDeclared
Definition: AthCommonDataStore.h:399
AthMsgStreamMacros.h
SG::VarHandleType
Definition: HandleClassifier.h:28
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, T &property, const std::string &doc="none")
Declare a new Gaudi property.
Definition: AthCommonDataStore.h:352
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase
Base class for VarHandle types.
Definition: StoreGate/StoreGate/VarHandleBase.h:83
AthCommonDataStore::renounce
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)
Definition: AthCommonDataStore.h:380
AthCommonDataStore::m_evtStore
StoreGateSvc_t m_evtStore
Pointer to StoreGate (event store by default)
Definition: AthCommonDataStore.h:390
AthCommonDataStore::m_vhka
std::vector< SG::VarHandleKeyArray * > m_vhka
Definition: AthCommonDataStore.h:398
VarHandleKeyArray.h
Base class for VarHandleKeyArray for reading from StoreGate.
AthCommonDataStore::renounceArray
void renounceArray(SG::VarHandleKeyArray &handlesArray)
remove all handles from I/O resolution
Definition: AthCommonDataStore.h:364
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
VarHandleProperty.h
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, SG::VarHandleKeyArray &hndArr, const std::string &doc, const SG::VarHandleKeyArrayType &)
Definition: AthCommonDataStore.h:259
AthCommonDataStore::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
SG::VarHandleKeyArray::setOwner
virtual void setOwner(IDataHandleHolder *o)=0
VarHandleKeyArrayProperty.h
class to handle Properties for VarHandleKeyArray
AthCommonDataStore::inputHandles
virtual std::vector< Gaudi::DataHandle * > inputHandles() const override
Return this algorithm's input handles.
AthCommonDataStore::StoreGateSvc_t
ServiceHandle< StoreGateSvc > StoreGateSvc_t
Definition: AthCommonDataStore.h:388
AthCommonDataStore::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AthCommonDataStore.icc
AthCommonDataStore
Definition: AthCommonDataStore.h:52
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthCommonDataStore::outputHandles
virtual std::vector< Gaudi::DataHandle * > outputHandles() const override
Return this algorithm's output handles.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HandleClassifier.h
Helper to classify the type of a handle property.
SG::NotHandleType
Definition: HandleClassifier.h:31
AthCommonDataStore::declareGaudiProperty
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleType &)
specialization for handling Gaudi::Property<SG::VarHandleBase>
Definition: AthCommonDataStore.h:184
AthCommonDataStore::m_detStore
StoreGateSvc_t m_detStore
Pointer to StoreGate (detector store by default)
Definition: AthCommonDataStore.h:393
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, T &property, const std::string &doc, const SG::NotHandleType &)
Declare a new Gaudi property.
Definition: AthCommonDataStore.h:333
SG::VarHandleKeyArray::renounce
virtual void renounce()=0
SG::HandleClassifier::type
std::conditional< std::is_base_of< SG::VarHandleKeyArray, T >::value, VarHandleKeyArrayType, type2 >::type type
Definition: HandleClassifier.h:54
SG::VarHandleKeyType
Definition: HandleClassifier.h:29
merge_scale_histograms.doc
string doc
Definition: merge_scale_histograms.py:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AthCommonDataStore::sysInitialize
virtual StatusCode sysInitialize() override
Perform system initialization for an algorithm.
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, SG::VarHandleBase &hndl, const std::string &doc, const SG::VarHandleType &)
Declare a new Gaudi property.
Definition: AthCommonDataStore.h:245
AthCommonDataStore::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, SG::VarHandleKey &hndl, const std::string &doc, const SG::VarHandleKeyType &)
Declare a new Gaudi property.
Definition: AthCommonDataStore.h:221
AthCommonDataStore::declareGaudiProperty
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &t, const SG::NotHandleType &)
specialization for handling everything that's not a Gaudi::Property<SG::VarHandleKey> or a <SG::VarHa...
Definition: AthCommonDataStore.h:199
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
python.PyAthena.v
v
Definition: PyAthena.py:157
python.KeyStore.getProperties
def getProperties(self)
Definition: KeyStore.py:247
a
TList * a
Definition: liststreamerinfos.cxx:10
h
AthCommonDataStore::updateVHKA
void updateVHKA(Gaudi::Details::PropertyBase &)
Definition: AthCommonDataStore.h:308
SG::VarHandleBase::vhKey
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
Definition: StoreGate/src/VarHandleBase.cxx:616
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
StoreGateSvc.h
AthCommonDataStore::declareGaudiProperty
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>
Definition: AthCommonDataStore.h:156
SG::VarHandleKeyArray
Definition: StoreGate/StoreGate/VarHandleKeyArray.h:28
AthCommonDataStore::declareGaudiProperty
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T > &hndl, const SG::VarHandleKeyArrayType &)
specialization for handling Gaudi::Property<SG::VarHandleKeyArray>
Definition: AthCommonDataStore.h:170
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
SG::VarHandleKeyArrayType
Definition: HandleClassifier.h:30
AthCommonDataStore::evtStore
const ServiceHandle< StoreGateSvc > & evtStore() const
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:90
ServiceHandle< StoreGateSvc >