ATLAS Offline Software
Loading...
Searching...
No Matches
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
20namespace {
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
uint32_t CLID
The Class ID type.
Interface for registering a transient object in t2p map.
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
virtual const name_type & name() const override final
Retrieve data object key == string.
AliasCont_t alias() const
access set of proxy aliases Returns a COPY of the alias set.
bool transientID(CLID id) const
return the list of transient IDs (primary or symLinked):
static std::string release
Definition computils.h:50
void * ptr(T *p)
Definition SGImplSvc.cxx:74