ATLAS Offline Software
Loading...
Searching...
No Matches
AuxDiscoverySvc Class Reference

This class provides the interface between AthenaPoolCnvSvc and AuxStore classes. More...

#include <AuxDiscoverySvc.h>

Collaboration diagram for AuxDiscoverySvc:

Public Member Functions

 AuxDiscoverySvc ()
bool getAuxStore (void *obj, const Guid &classId, const std::string &contId)
bool setData (SG::auxid_t auxid, void *data, const RootType &type)
bool setAuxStore ()
SG::auxid_t getAuxID (const std::string &attrName, const std::string &elemName, const std::string &typeName)
SG::auxid_set_t getAuxIDs (const void *obj, const Guid &classId, const std::string &contId)
const void * getData (SG::auxid_t auxid)
const std::type_info * getType (SG::auxid_t auxid)
std::string getAttrName (SG::auxid_t auxid)
std::string getTypeName (SG::auxid_t auxid)
std::string getElemName (SG::auxid_t auxid)
StatusCode receiveStore (const IAthenaSerializeSvc *serSvc, IAthenaIPCTool *ipcTool, void *obj, int num=0)
 Receive dynamic aux store variables from streaming tool.
StatusCode sendStore (const IAthenaSerializeSvc *serSvc, IAthenaIPCTool *ipcTool, const void *obj, const Guid &classId, const std::string &contName, int num=0)
 Send dynamic aux store variables to streaming tool.

Private Attributes

const SG::IAuxStoreIOm_store
AthenaPoolAuxStorem_storeInt
SG::IAuxStoreHolderm_storeHolder

Detailed Description

This class provides the interface between AthenaPoolCnvSvc and AuxStore classes.

Definition at line 33 of file AuxDiscoverySvc.h.

Constructor & Destructor Documentation

◆ AuxDiscoverySvc()

AuxDiscoverySvc::AuxDiscoverySvc ( )
inline

Definition at line 35 of file AuxDiscoverySvc.h.

35: m_store(0), m_storeInt(0), m_storeHolder(0) {}
const SG::IAuxStoreIO * m_store
AthenaPoolAuxStore * m_storeInt
SG::IAuxStoreHolder * m_storeHolder

Member Function Documentation

◆ getAttrName()

std::string AuxDiscoverySvc::getAttrName ( SG::auxid_t auxid)

Definition at line 151 of file AuxDiscoverySvc.cxx.

151 {
153}
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.

◆ getAuxID()

SG::auxid_t AuxDiscoverySvc::getAuxID ( const std::string & attrName,
const std::string & elemName,
const std::string & typeName )

Definition at line 93 of file AuxDiscoverySvc.cxx.

93 {
94 SG::AuxTypeRegistry& registry = SG::AuxTypeRegistry::instance();
95 SG::auxid_t auxid = registry.findAuxID(attrName);
96 if (auxid == SG::null_auxid && m_storeInt != nullptr) {
97 try {
98 RootUtils::Type elemType(elemName);
99 const std::type_info* eti = elemType.getTypeInfo();
100 if (eti == nullptr) {
101 return SG::null_auxid;
102 }
103 auxid = SG::getDynamicAuxID(*eti, attrName, elemName, typeName, m_storeInt->standalone(), SG::null_auxid);
104 } catch (const std::runtime_error&) {
105 return SG::null_auxid;
106 }
107 }
108 return auxid;
109}
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
SG::auxid_t getDynamicAuxID(const std::type_info &ti, const std::string &name, const std::string &elementTypeName, const std::string &branch_type_name, bool standalone, SG::auxid_t linked_auxid)
Find the auxid for a dynamic branch.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27

◆ getAuxIDs()

SG::auxid_set_t AuxDiscoverySvc::getAuxIDs ( const void * obj,
const Guid & classId,
const std::string & contId )

Definition at line 112 of file AuxDiscoverySvc.cxx.

112 {
113 const pool::DbTypeInfo* info = pool::DbTypeInfo::create(classId); // Needed for Properties and TClass
114 if (info == nullptr) {
115 return SG::auxid_set_t();
116 }
117 if (!contId.empty() && (contId.size() < 5 || contId.substr(contId.size() - 5, 4) != "Aux.")
118 && !info->clazz().Properties().HasProperty("IAuxStore")) {
119 return SG::auxid_set_t();
120 }
121 // Detected auxStore
122 TClass* cl = info->clazz().Class();
123 if (cl == nullptr) {
124 return SG::auxid_set_t();
125 }
126 TClass* storeTC = cl->GetBaseClass("SG::IAuxStoreIO");
127 if (storeTC == nullptr) {
128 return SG::auxid_set_t();
129 }
130 m_store = reinterpret_cast<const SG::IAuxStoreIO*>((const char*)obj + cl->GetBaseClassOffset(storeTC));
131 if (m_store == nullptr) {
132 return SG::auxid_set_t();
133 }
134 return m_store->getSelectedAuxIDs();
135}
static const DbTypeInfo * create(const std::string &cl_name)
Create type information using name.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ getAuxStore()

bool AuxDiscoverySvc::getAuxStore ( void * obj,
const Guid & classId,
const std::string & contId )

Definition at line 39 of file AuxDiscoverySvc.cxx.

39 {
40 const pool::DbTypeInfo* info = pool::DbTypeInfo::create(classId); // Needed for Properties and TClass
41 if (info == nullptr) {
42 return false;
43 }
44 if (!contId.empty() && (contId.size() < 5 || contId.substr(contId.size() - 5, 4) != "Aux.")
45 && !info->clazz().Properties().HasProperty("IAuxStore")) {
46 return false;
47 }
48 TClass* cl = info->clazz().Class();
49 if (cl == nullptr) {
50 return false;
51 }
52 TClass* holderTC = cl->GetBaseClass("SG::IAuxStoreHolder");
53 if (holderTC == nullptr) {
54 return false;
55 }
56 m_storeHolder = reinterpret_cast<SG::IAuxStoreHolder*>((char*)obj + cl->GetBaseClassOffset(holderTC));
57 if (m_storeHolder == nullptr) {
58 return false;
59 }
61 m_storeInt = new AthenaPoolAuxStore(standalone);
62 return true;
63}
@ AST_ObjectStore
The store describes a single object.

◆ getData()

const void * AuxDiscoverySvc::getData ( SG::auxid_t auxid)

Definition at line 137 of file AuxDiscoverySvc.cxx.

137 {
138 if (m_store == nullptr) {
139 return nullptr;
140 }
141 return m_store->getIOData(auxid);
142}

◆ getElemName()

std::string AuxDiscoverySvc::getElemName ( SG::auxid_t auxid)

Definition at line 159 of file AuxDiscoverySvc.cxx.

159 {
161}
std::string getTypeName(SG::auxid_t auxid) const
Return the type name of an aux data item.

◆ getType()

const std::type_info * AuxDiscoverySvc::getType ( SG::auxid_t auxid)

Definition at line 144 of file AuxDiscoverySvc.cxx.

144 {
145 if (m_store == nullptr) {
146 return nullptr;
147 }
148 return m_store->getIOType(auxid);
149}

◆ getTypeName()

std::string AuxDiscoverySvc::getTypeName ( SG::auxid_t auxid)

Definition at line 155 of file AuxDiscoverySvc.cxx.

155 {
156 return SG::normalizedTypeinfoName(*(getType(auxid)));
157}
const std::type_info * getType(SG::auxid_t auxid)
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...

◆ receiveStore()

StatusCode AuxDiscoverySvc::receiveStore ( const IAthenaSerializeSvc * serSvc,
IAthenaIPCTool * ipcTool,
void * obj,
int num = 0 )

Receive dynamic aux store variables from streaming tool.

Definition at line 162 of file AuxDiscoverySvc.cxx.

162 {
163 void* buffer = nullptr;
164 size_t nbytes = 0;
165 StatusCode sc = ipcTool->getObject(&buffer, nbytes, num);
166 while (sc.isRecoverable() && nbytes > 0) {
167 sc = ipcTool->getObject(&buffer, nbytes, num);
168 }
169 if (!sc.isSuccess() || nbytes == 0) { // No dynamic attributes
170 return(StatusCode::SUCCESS);
171 }
172 Guid classId;
173 classId.fromString(static_cast<const char*>(buffer));
174 if (!ipcTool->getObject(&buffer, nbytes, num).isSuccess() || nbytes == 0) {
175 return(StatusCode::FAILURE);
176 }
177 const std::string contName = std::string(static_cast<const char*>(buffer));
178 if (classId != Guid::null() && this->getAuxStore(obj, classId, contName)) {
179 void* nameData = nullptr;
180 // StreamingTool owns buffer, will stay around until last dynamic attribute is copied
181 while (ipcTool->getObject(&nameData, nbytes, num).isSuccess() && nbytes > 0) {
182 const char* del1 = static_cast<const char*>(memchr(nameData, '\n', nbytes));
183 const char* del2 = static_cast<const char*>(memchr(del1 + 1, '\n', nbytes - (del1 - static_cast<const char*>(nameData) - 1)));
184 const std::string dataStr(static_cast<const char*>(nameData));
185 const std::string& attrName = dataStr.substr(0, del1 - static_cast<const char*>(nameData));
186 const std::string& typeName = dataStr.substr(del1 - static_cast<const char*>(nameData) + 1, del2 - del1 - 1);
187 const std::string& elemName = dataStr.substr(del2 - static_cast<const char*>(nameData) + 1);
188 if (ipcTool->getObject(&buffer, nbytes, num).isSuccess()) {
189 SG::auxid_t auxid = this->getAuxID(attrName, elemName, typeName);
190 if (auxid != SG::null_auxid) {
191 const RootType type(typeName);
192 void* dynAttr = nullptr;
193 if (type.IsFundamental()) {
194 dynAttr = new char[nbytes];
195 std::memcpy(dynAttr, buffer, nbytes); buffer = nullptr;
196 } else {
197 dynAttr = serSvc->deserialize(buffer, nbytes, type); buffer = nullptr;
198 }
199 this->setData(auxid, dynAttr, type);
200 }
201 }
202 }
203 this->setAuxStore();
204 }
205 return(StatusCode::SUCCESS);
206}
static Double_t sc
TTypeAdapter RootType
Definition RootType.h:211
bool getAuxStore(void *obj, const Guid &classId, const std::string &contId)
bool setData(SG::auxid_t auxid, void *data, const RootType &type)
SG::auxid_t getAuxID(const std::string &attrName, const std::string &elemName, const std::string &typeName)
constexpr void fromString(std::string_view s)
Automatic conversion from string representation.
Definition Guid.h:143
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition Guid.cxx:14
virtual StatusCode getObject(void **target, size_t &nbytes, int num=0)=0
virtual void * deserialize(void *buffer, size_t &nbytes, const std::string &name) const =0
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ sendStore()

StatusCode AuxDiscoverySvc::sendStore ( const IAthenaSerializeSvc * serSvc,
IAthenaIPCTool * ipcTool,
const void * obj,
const Guid & classId,
const std::string & contName,
int num = 0 )

Send dynamic aux store variables to streaming tool.

Definition at line 208 of file AuxDiscoverySvc.cxx.

213 {
214 const SG::auxid_set_t& auxIDs = this->getAuxIDs(obj, classId, contName);
215 if (!auxIDs.empty()) {
216 const std::string& classIdStr = classId.toString();
217 if (!ipcTool->putObject(classIdStr.c_str(), classIdStr.size() + 1, num).isSuccess()) {
218 return(StatusCode::FAILURE);
219 }
220 if (!ipcTool->putObject(contName.c_str(), contName.size() + 1, num).isSuccess()) {
221 return(StatusCode::FAILURE);
222 }
223 }
224 for (SG::auxid_t auxid : auxIDs) {
225 const std::string& dataStr = this->getAttrName(auxid) + "\n" + this->getTypeName(auxid) + "\n" + this->getElemName(auxid);
226 if (!ipcTool->putObject(dataStr.c_str(), dataStr.size() + 1, num).isSuccess()) {
227 return(StatusCode::FAILURE);
228 }
229 const std::type_info* tip = this->getType(auxid);
230 if (tip == nullptr) {
231 return(StatusCode::FAILURE);
232 }
233 RootType type(*tip);
234 StatusCode sc = StatusCode::FAILURE;
235 if (type.IsFundamental()) {
236 sc = ipcTool->putObject(this->getData(auxid), type.SizeOf(), num);
237 } else {
238 size_t nbytes = 0;
239 void* buffer = serSvc->serialize(this->getData(auxid), type, nbytes);
240 sc = ipcTool->putObject(buffer, nbytes, num);
241 delete [] static_cast<char*>(buffer); buffer = nullptr;
242 }
243 if (!sc.isSuccess()) {
244 return(StatusCode::FAILURE);
245 }
246 }
247 return(StatusCode::SUCCESS);
248}
std::string getElemName(SG::auxid_t auxid)
SG::auxid_set_t getAuxIDs(const void *obj, const Guid &classId, const std::string &contId)
std::string getTypeName(SG::auxid_t auxid)
const void * getData(SG::auxid_t auxid)
std::string getAttrName(SG::auxid_t auxid)
bool empty() const
Return true if there are no 1 bits in the set.
constexpr void toString(std::span< char, StrLen > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
virtual StatusCode putObject(const void *source, size_t nbytes, int num=0)=0
virtual void * serialize(const void *object, const std::string &name, size_t &nbytes) const =0

◆ setAuxStore()

bool AuxDiscoverySvc::setAuxStore ( )

Definition at line 85 of file AuxDiscoverySvc.cxx.

85 {
86 if (m_storeHolder == nullptr) {
87 return false;
88 }
89 m_storeHolder->setStore(m_storeInt);
90 return true;
91}

◆ setData()

bool AuxDiscoverySvc::setData ( SG::auxid_t auxid,
void * data,
const RootType & type )

Definition at line 65 of file AuxDiscoverySvc.cxx.

65 {
66 SG::AuxTypeRegistry& registry = SG::AuxTypeRegistry::instance();
67 if (m_storeInt->standalone()) {
68 (void)m_storeInt->getData(auxid, 1, 1);
69 registry.copy(auxid,
70 SG::AuxVectorInterface (*m_storeInt), 0,
71 SG::AuxVectorInterface (auxid, 1, const_cast<const void*>(data)), 0, 1);
72 if (type.IsFundamental()) {
73 delete [] (char*)data; data = nullptr;
74 } else {
75 type.Destruct(data); data = nullptr;
76 }
77 } else {
78 // Move the data to the dynamic store.
79 std::unique_ptr<SG::IAuxTypeVector> vec(registry.makeVectorFromData(auxid, data, nullptr, false, true));
80 m_storeInt->addVector(std::move(vec), false);
81 }
82 return true;
83}
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::unique_ptr< IAuxTypeVector > makeVectorFromData(SG::auxid_t auxid, void *data, IAuxTypeVector *linkedVector, bool isPacked, bool ownFlag) const
Construct an IAuxTypeVector object from a vector.
void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const
Copy elements between vectors.

Member Data Documentation

◆ m_store

const SG::IAuxStoreIO* AuxDiscoverySvc::m_store
private

Definition at line 69 of file AuxDiscoverySvc.h.

◆ m_storeHolder

SG::IAuxStoreHolder* AuxDiscoverySvc::m_storeHolder
private

Definition at line 71 of file AuxDiscoverySvc.h.

◆ m_storeInt

AthenaPoolAuxStore* AuxDiscoverySvc::m_storeInt
private

Definition at line 70 of file AuxDiscoverySvc.h.


The documentation for this class was generated from the following files: