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

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

#include <AuxDiscoverySvc.h>

Inheritance diagram for AuxDiscoverySvc:
Collaboration diagram for AuxDiscoverySvc:

Public Member Functions

 AuxDiscoverySvc (const IAthenaSerializeSvc *serSvc, IAthenaIPCTool *ipcTool)
 ~AuxDiscoverySvc ()
StatusCode receiveStore (TClass *cl, void *obj, int num=0)
 Receive dynamic aux store variables from streaming tool.
StatusCode sendStore (TClass *cl, const void *obj, const std::string &classId, const std::string &contName, int num=0)
 Send dynamic aux store variables to streaming tool.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

const IAthenaSerializeSvcm_serSvc {}
IAthenaIPCToolm_ipcTool {}
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

This class provides the interface between AthenaPoolCnvSvc and AuxStore classes.

Definition at line 22 of file AuxDiscoverySvc.h.

Constructor & Destructor Documentation

◆ AuxDiscoverySvc()

AuxDiscoverySvc::AuxDiscoverySvc ( const IAthenaSerializeSvc * serSvc,
IAthenaIPCTool * ipcTool )

Definition at line 33 of file AuxDiscoverySvc.cxx.

33 : AthMessaging("AuxDiscoverySvc"), m_serSvc(serSvc), m_ipcTool(ipcTool) {
34}
AthMessaging()
Default constructor:
const IAthenaSerializeSvc * m_serSvc
IAthenaIPCTool * m_ipcTool

◆ ~AuxDiscoverySvc()

AuxDiscoverySvc::~AuxDiscoverySvc ( )

Definition at line 36 of file AuxDiscoverySvc.cxx.

36 {
37}

Member Function Documentation

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ receiveStore()

StatusCode AuxDiscoverySvc::receiveStore ( TClass * cl,
void * obj,
int num = 0 )
virtual

Receive dynamic aux store variables from streaming tool.

Implements RootAuxDynIO::IAuxDynShare.

Definition at line 39 of file AuxDiscoverySvc.cxx.

39 {
40 TClass* holderTC = cl->GetBaseClass("SG::IAuxStoreHolder");
41 if (holderTC == nullptr) {
42 return(StatusCode::FAILURE);
43 }
44 SG::IAuxStoreHolder* storeHolder = reinterpret_cast<SG::IAuxStoreHolder*>((char*)obj + cl->GetBaseClassOffset(holderTC));
45 if (storeHolder == nullptr) {
46 return(StatusCode::FAILURE);
47 }
49 std::unique_ptr<AthenaPoolAuxStore> storeInt = std::make_unique<AthenaPoolAuxStore>(standalone);
50
51 void* nameData = nullptr;
52 // StreamingTool owns buffer, will stay around until last dynamic attribute is copied
53 size_t nbytes = 0;
54 while (m_ipcTool->getObject(&nameData, nbytes, num).isSuccess() && nbytes > 0) {
55 const char* del1 = static_cast<const char*>(std::memchr(nameData, '\n', nbytes));
56 if (del1 == nullptr) continue;
57 const char* del2 = static_cast<const char*>(std::memchr(del1 + 1, '\n', nbytes - (del1 - static_cast<const char*>(nameData) + 1)));
58 if (del2 == nullptr) continue;
59 const std::string dataStr(static_cast<const char*>(nameData));
60 const std::string& attrName = dataStr.substr(0, del1 - static_cast<const char*>(nameData));
61 const std::string& typeName = dataStr.substr(del1 - static_cast<const char*>(nameData) + 1, del2 - del1 - 1);
62 const std::string& elemName = dataStr.substr(del2 - static_cast<const char*>(nameData) + 1, nbytes - (del2 - static_cast<const char*>(nameData) + 1));
63 void* buffer = nullptr;
64 if (m_ipcTool->getObject(&buffer, nbytes, num).isSuccess()) {
65 SG::AuxTypeRegistry& registry = SG::AuxTypeRegistry::instance();
66 SG::auxid_t auxid = registry.findAuxID(attrName);
67 if (auxid == SG::null_auxid) {
68 try {
69 RootUtils::Type elemType(elemName);
70 const std::type_info* eti = elemType.getTypeInfo();
71 if (eti != nullptr) {
72 auxid = SG::getDynamicAuxID(*eti, attrName, elemName, typeName, storeInt->standalone(), SG::null_auxid);
73 }
74 } catch (const std::runtime_error&) {
76 }
77 }
78 if (auxid != SG::null_auxid) {
79 const RootType type(typeName);
80 void* dynAttr = nullptr;
81 if (type.IsFundamental()) {
82 dynAttr = new char[nbytes];
83 std::memcpy(dynAttr, buffer, nbytes); buffer = nullptr;
84 } else {
85 dynAttr = m_serSvc->deserialize(buffer, nbytes, type); buffer = nullptr;
86 }
87 if (storeInt->standalone()) {
88 (void)storeInt->getData(auxid, 1, 1);
89 registry.copy(auxid,
90 SG::AuxVectorInterface(*storeInt), 0,
91 SG::AuxVectorInterface(auxid, 1, const_cast<const void*>(dynAttr)), 0, 1);
92 if (type.IsFundamental()) {
93 delete [] (char*)dynAttr; dynAttr = nullptr;
94 } else {
95 type.Destruct(dynAttr); dynAttr = nullptr;
96 }
97 } else {
98 // Move the data to the dynamic store.
99 std::unique_ptr<SG::IAuxTypeVector> vec(registry.makeVectorFromData(auxid, dynAttr, nullptr, false, true));
100 storeInt->addVector(std::move(vec), false);
101 }
102 }
103 }
104 }
105 storeHolder->setStore(storeInt.release());
106 return(StatusCode::SUCCESS);
107}
std::vector< size_t > vec
TTypeAdapter RootType
Definition RootType.h:211
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
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.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
@ AST_ObjectStore
The store describes a single object.
virtual AuxStoreType getStoreType() const =0
Return the type of the store object.
virtual void setStore(IAuxStore *store)=0
Give an auxiliary store object to the holder object.
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
SG::auxid_t auxid() const
Return the aux id for this variable.
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
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ sendStore()

StatusCode AuxDiscoverySvc::sendStore ( TClass * cl,
const void * obj,
const std::string & classId,
const std::string & contName,
int num = 0 )
virtual

Send dynamic aux store variables to streaming tool.

Implements RootAuxDynIO::IAuxDynShare.

Definition at line 109 of file AuxDiscoverySvc.cxx.

113 {
114 TClass* storeTC = cl->GetBaseClass("SG::IAuxStoreIO");
115 if (storeTC == nullptr) {
116 return(StatusCode::SUCCESS);
117 }
118 const SG::IAuxStoreIO* store = reinterpret_cast<const SG::IAuxStoreIO*>((const char*)obj + cl->GetBaseClassOffset(storeTC));
119 if (store == nullptr) {
120 return(StatusCode::FAILURE);
121 }
122 const SG::auxid_set_t& auxIDs = store->getSelectedAuxIDs();
123 if (!auxIDs.empty()) {
124 if (!m_ipcTool->putObject(classId.c_str(), classId.size() + 1, num).isSuccess()) {
125 return(StatusCode::FAILURE);
126 }
127 if (!m_ipcTool->putObject(contName.c_str(), contName.size() + 1, num).isSuccess()) {
128 return(StatusCode::FAILURE);
129 }
130 }
131 for (SG::auxid_t auxid : auxIDs) {
132 const std::type_info* typePtr = store->getIOType(auxid);
133 if (typePtr == nullptr) continue;
134 const std::string& dataStr = SG::AuxTypeRegistry::instance().getName(auxid) + "\n" + SG::normalizedTypeinfoName(*typePtr) + "\n" + SG::AuxTypeRegistry::instance().getTypeName(auxid);
135 if (!m_ipcTool->putObject(dataStr.c_str(), dataStr.size() + 1, num).isSuccess()) {
136 return(StatusCode::FAILURE);
137 }
138 const std::type_info* tip = store->getIOType(auxid);
139 if (tip == nullptr) {
140 return(StatusCode::FAILURE);
141 }
142 RootType type(*tip);
143 StatusCode sc = StatusCode::FAILURE;
144 if (type.IsFundamental()) {
145 sc = m_ipcTool->putObject(store->getIOData(auxid), type.SizeOf(), num);
146 } else {
147 size_t nbytes = 0;
148 void* buffer = m_serSvc->serialize(store->getIOData(auxid), type, nbytes);
149 sc = m_ipcTool->putObject(buffer, nbytes, num);
150 delete [] static_cast<char*>(buffer); buffer = nullptr;
151 }
152 if (!sc.isSuccess()) {
153 return(StatusCode::FAILURE);
154 }
155 }
156 return(StatusCode::SUCCESS);
157}
static Double_t sc
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
std::string getTypeName(SG::auxid_t auxid) const
Return the type name of an aux data item.
::StatusCode StatusCode
StatusCode definition for legacy code.
TestStore store
Definition TestStore.cxx:23
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...

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_ipcTool

IAthenaIPCTool* AuxDiscoverySvc::m_ipcTool {}
private

Definition at line 38 of file AuxDiscoverySvc.h.

38{};

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_serSvc

const IAthenaSerializeSvc* AuxDiscoverySvc::m_serSvc {}
private

Definition at line 37 of file AuxDiscoverySvc.h.

37{};

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