ATLAS Offline Software
AltDataBucket.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHENASERVICES_ALTDATABUCKET_H
6 #define ATHENASERVICES_ALTDATABUCKET_H
7 
8 #include <cstdlib> // std::abort
9 #include <memory> // std::unique_ptr, std::make_unique
10 #include <string> // std::string
11 #include <typeinfo> // std::type_info
12 
13 // Framework include files
16 #include "GaudiKernel/ClassID.h"
17 #include "SGTools/DataProxy.h"
19 
20 namespace {
42  class AltDataBucket
43  : public DataBucketBase
44  {
45  public:
46  AltDataBucket (void* ptr, CLID clid, const std::type_info& tinfo,
47  const SG::DataProxy& proxy)
48  : m_proxy(this, makeTransientAddress(clid, proxy).release()),
49  m_ptr (ptr), m_clid (clid), m_tinfo (tinfo)
50  {
51  addRef();
52  }
53  // Extra constructor to create a temporary proxy without aliases, for objects in MetaContainers
54  AltDataBucket(void* ptr, CLID clid, const std::type_info& tinfo, const std::string& name) :
55  m_proxy(this, new SG::TransientAddress(clid, name) ),
56  m_ptr(ptr), m_clid(clid), m_tinfo(tinfo)
57  {
58  addRef();
59  }
60 
61  virtual const CLID& clID() const override { return m_clid; }
62  virtual void* object() override { return m_ptr; }
63  virtual const std::type_info& tinfo() const override { return m_tinfo; }
65  virtual void* cast (CLID /*clid*/,
66  SG::IRegisterTransient* /*irt*/ = nullptr,
67  bool /*isConst*/ = true) override
68  { std::abort(); }
69  virtual void* cast (const std::type_info& tinfo,
70  SG::IRegisterTransient* /*irt*/ = nullptr,
71  bool /*isConst*/ = true) override
72  { if (tinfo == m_tinfo)
73  return m_ptr;
74  return nullptr;
75  }
76  virtual void relinquish() override {}
77  virtual void lock() override {}
78 
79 
80  private:
81  static
82  std::unique_ptr<SG::TransientAddress>
83  makeTransientAddress (CLID clid, const SG::DataProxy& oldProxy);
84 
85  SG::DataProxy m_proxy;
86  void* m_ptr;
87  CLID m_clid;
88  const std::type_info& m_tinfo;
89  };
90 
91 
92  std::unique_ptr<SG::TransientAddress>
93  AltDataBucket::makeTransientAddress (CLID clid, const SG::DataProxy& oldProxy)
94  {
95  auto newTad = std::make_unique<SG::TransientAddress>
96  (clid, oldProxy.name());
97  newTad->setAlias (oldProxy.alias());
98  for (CLID tclid : oldProxy.transientID()) {
99  // Note: this will include derived CLIDs.
100  // Strictly speaking, that's not right; however, filtering them
101  // out can break ElementLinks (for example those used by
102  // ShallowAuxContainer). One will not actually be able to get
103  // a pointer of the derived type, as the conversions in StorableConversion
104  // only support derived->base, not the other way around.
105  newTad->setTransientID (tclid);
106  }
107  return newTad;
108  }
109 
110 } // anonymous namespace
111 
112 #endif
SG::IRegisterTransient
Interface for registering a transient object in t2p map.
Definition: IRegisterTransient.h:28
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:407
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
DataBucketBase::lock
virtual void lock()=0
If the held object derives from ILockable, call lock() on it.
DataBucketBase
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
Definition: DataBucketBase.h:24
DataBucketBase.h
DataBucketBase::object
virtual void * object()=0
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
DataBucketBase::cast
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
SG::DataProxy::alias
AliasCont_t alias() const
access set of proxy aliases Returns a COPY of the alias set.
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
SG::DataProxy::name
virtual const name_type & name() const override final
Retrieve data object key == string.
SG::DataProxy::transientID
bool transientID(CLID id) const
return the list of transient IDs (primary or symLinked):
TransientAddress.h
DataBucketBase::relinquish
virtual void relinquish()=0
Give up ownership of the DataBucket contents.
IRegisterTransient.h
Interface for registering a transient object in t2p map.
DataBucketBase::tinfo
virtual const std::type_info & tinfo() const =0
Return the type_info for the stored object.
SG::DataProxy
Definition: DataProxy.h:45
DataProxy.h