ATLAS Offline Software
Loading...
Searching...
No Matches
TrigSerializeConvHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/ClassID.h"
8
13
15#include "CxxUtils/FPControl.h"
16
17
18TrigSerializeConvHelper::TrigSerializeConvHelper(const std::string& toolname, const std::string& type, const IInterface* parent) :
19 AthAlgTool(toolname, type, parent),
20 m_serializerTool("TrigTSerializer/TrigTSerializer"),
21 m_TPTool("TrigSerTPTool/TrigSerTPTool"),
22 m_guidTool("TrigSerializeGuidHelper/TrigSerializeGuidHelper"),
23 m_doTP(true)
24{
25 declareInterface<ITrigSerializeConvHelper>( this );
26 declareProperty("doTP", m_doTP, "allows to serialize/deserialize transient classes");
27}
28
31
33
34 StatusCode sc = m_serializerTool.retrieve();
35
36 if (!sc.isSuccess()){
37 ATH_MSG_DEBUG("m_serializer not retrieved");
38 return sc;
39 } else {
40 ATH_MSG_DEBUG("m_serializer retrieved");
41 /*
42 if (m_serializerTool->initialize().isSuccess()){
43 ATH_MSG_DEBUG( "serializer initialized" );
44 }
45 */
46 }
47
48 StatusCode sctp = m_TPTool.retrieve();
49 if (!sctp.isSuccess()){
50 ATH_MSG_DEBUG( "m_TPTool not retrieved" );
51 return sctp;
52 } else {
53 ATH_MSG_DEBUG( "m_TPTool retrieved" );
54 /*
55 if (m_TPTool->initialize().isSuccess())
56 ATH_MSG_DEBUG( "m_TPTool initialized" );
57 */
58 }
59
60 StatusCode scg = m_guidTool.retrieve();
61 if (!scg.isSuccess()){
62 ATH_MSG_DEBUG( m_guidTool << " not retrieved" );
63 return scg;
64 } else {
65 ATH_MSG_DEBUG( m_guidTool << "retrieved" );
66 }
67
68 m_oldEDMmap[ "TrigRoiDescriptor" ] = "TrigRoiDescriptorCollection_tlp1";
69 m_oldEDMmap[ "TrigInDetTrackCollection" ] = "TrigInDetTrackCollection_tlp1";
70 m_oldEDMmap[ "TrigVertexCollection" ] = "TrigVertexCollection_tlp1";
71 m_oldEDMmap[ "CaloCellContainer" ] = "CaloCompactCellContainer";
72 m_oldEDMmap[ "CaloClusterContainer" ] = "CaloClusterContainer_p4";
73 m_oldEDMmap[ "CaloShowerContainer" ] = "CaloShowerContainer_p2";
74 m_oldEDMmap[ "TrackCollection" ] = "Trk::TrackCollection_tlp2";
75 m_oldEDMmap[ "Rec::TrackParticleContainer" ] = "Rec::TrackParticleContainer_tlp1";
76 m_oldEDMmap[ "VxContainer" ] = "";
77
78 return StatusCode::SUCCESS;
79}
80
81StatusCode TrigSerializeConvHelper::createObj(const std::string &clname, IOpaqueAddress* iAddr, void *&ptr, bool isxAOD){
82 ptr = 0;
83 ATH_MSG_DEBUG("in TrigSerializeConvHelper::createObj for clname " << clname << " is xAOD? " << (isxAOD?"yes":"no"));
84
85 //could alse get DATA (perhaps as std::any) from the IOA
86 TrigStreamAddress *addr = dynamic_cast<TrigStreamAddress*>(iAddr);
87 if (!addr) {
88 ATH_MSG_WARNING("createObj cast failed");
89 return StatusCode::FAILURE;
90 }
91
92 ITrigSerializerToolBase* serializer = m_serializerTool.operator->();
93 serializer->reset();
94
95 std::vector<uint32_t> v = addr->get();
96
97 //we need to find the name of the ob
98 std::string cl = clname;
99
100 if (m_doTP and !isxAOD)
101 cl = m_TPTool->persClassName(clname);
102
103 uint32_t guid[4];
104
105 bool versionChange = false;
106
107 if (cl!=""){
108 StatusCode scid;
109 scid = serializer->peekCLID(v, guid);
110 if (scid.isFailure()){
111 //BS has no hint on the pers class - use the original table
112 ATH_MSG_DEBUG("BS does not hint on payload object " << cl);
113 if (m_oldEDMmap.find(clname)!=m_oldEDMmap.end()){
114 if (cl!=m_oldEDMmap[clname]){
115 ATH_MSG_DEBUG("Using backward compatibility map with " << m_oldEDMmap[clname]
116 << " instead of " << cl);
117 cl = m_oldEDMmap[clname];
118 }
119 }
120 } else {
121 //get the pers version from the BS
122 std::string nclass = cl;
123 StatusCode ai = m_guidTool->IntsToClassName(guid, nclass);
124 if (ai.isFailure()) {
125 //better do not decode
126 return StatusCode::FAILURE;
127 }
128 if (cl != nclass){
129 cl = nclass;
130 ATH_MSG_DEBUG("Got hint of " << cl << " different persistent class from the BS payload. Name from GUID: " << nclass);
131
132 if(isxAOD){
133 ATH_MSG_DEBUG("This is an xAOD so probably the BS version is an older version of the xAOD type.");
134 }
135 versionChange = true;
136 }
137 }
138
139 // Many variables in this class were changed from double to float.
140 // However, we wrote data in the past which contained values
141 // that were valid doubles but which were out of range for floats.
142 // So we can get FPEs when we read them.
143 // Disable FPEs when we're reading an instance of this class.
144 CxxUtils::FPControl fpcontrol;
145 if (cl == "xAOD::BTaggingTrigAuxContainer_v1") {
146 fpcontrol.holdExceptions();
147 }
148
149 ptr = serializer->deserialize(cl, v);
150
151 ATH_MSG_DEBUG(cl << " deserialized to " << ptr << " version change detected: " << (versionChange ? "yes":"no"));
152 }
153
154 // T/P separation
155 bool isViewVector = cl.substr(0, 11) == "ViewVector<";
156 if (m_doTP and (!isxAOD or versionChange) and !isViewVector){
157 std::string transclass;
158
159 ATH_MSG_DEBUG("converting with pername " << cl);
160
161 void *transObj = m_TPTool->convertPT(cl,ptr, transclass);
162
163 ATH_MSG_DEBUG("was converted to " << transclass << " at " << transObj);
164
165 //persistent object not needed anymore
166 RootType persClObj(cl);
167 persClObj.Destruct(ptr);
168
169 ptr = transObj;
170 }
171
172 return StatusCode::SUCCESS;
173}
174
175
176
177StatusCode TrigSerializeConvHelper::createRep(const std::string &clname,
178 void *ptr, std::vector<uint32_t> &out, bool isxAOD){
179
180 StatusCode sc(StatusCode::SUCCESS);
181
182 ATH_MSG_DEBUG("in TrigSerializeConvHelper::createRep for clname" << clname << " is xAOD? " << (isxAOD?"yes":"no"));
183
184 std::string cl = clname;
185 void *pObj = ptr;
186
187 // T/P separation
188 if (m_doTP and !isxAOD){
189 std::string persclass("");
190 pObj = m_TPTool->convertTP(clname,ptr, persclass);
191 cl = std::move(persclass);
192 }
193
194 ATH_MSG_DEBUG("convertTP: " << pObj << " of " << cl);
195
196 //void *serptr(0);
197 //
198 ITrigSerializerToolBase* serializer = m_serializerTool.operator->();
199 serializer->reset();
200
201 ATH_MSG_VERBOSE("About to get GUID for " << cl);
202
203 //opposite from string to class
204 uint32_t irep[4];
205 StatusCode ai = m_guidTool->ClassNameToInts(cl, irep);
206 if (ai.isFailure()){
207 ATH_MSG_WARNING("Cannot store class identification for " << cl << " to BS");
208 }
209
210 ATH_MSG_VERBOSE("got GUID: " << irep[0] << "-" << irep[1] << "-" << irep[2] << "-" << irep[3]);
211
212 if (cl != "" && pObj){
213 serializer->setCLID(irep);
214 serializer->serialize(cl, pObj, out);
215 } else {
216 ATH_MSG_WARNING("did not serialize " << ptr << " of " << clname);
217 }
218
219 if (m_doTP and !isxAOD){
220 //we don't need the persistent object anymore
221 RootType persClObj(cl);
222 persClObj.Destruct(pObj);
223 }
224
225 ATH_MSG_DEBUG("pObj: " << pObj << " of " << cl << " payload: " << out.size());
226
227 return sc;
228}
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
Helper to control FP exceptions.
static Double_t sc
TTypeAdapter RootType
Definition RootType.h:211
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
AlgTool interface of a serializer implementation.
virtual StatusCode peekCLID(const std::vector< uint32_t > &v, uint32_t *guid) const =0
access clid of the payload (stored in BS)
virtual void reset()=0
clean internal serializer state.
virtual void serialize(const std::string &nameOfClass, const void *instance, std::vector< uint32_t > &v)=0
serializes an object of a class nameOfClass pointed to by instance and recursively also other objects...
virtual void * deserialize(const std::string &nameOfClass, const std::vector< uint32_t > &v)=0
deserializes an object of a class nameOfClass (and recursively other objects) found in std::vector<ui...
virtual void setCLID(const uint32_t *guid)=0
access clid of the payload virtual CLID getCLID() const = 0;
void Destruct(void *place) const
Definition RootType.cxx:675
TrigSerializeConvHelper(const std::string &name, const std::string &type, const IInterface *parent)
std::map< std::string, std::string > m_oldEDMmap
ToolHandle< TrigSerTPTool > m_TPTool
ToolHandle< ITrigSerializeGuidHelper > m_guidTool
ToolHandle< ITrigSerializerToolBase > m_serializerTool
StatusCode createObj(const std::string &clname, IOpaqueAddress *iAddr, void *&ptr, bool isxAOD=false)
StatusCode createRep(const std::string &clname, void *ptr, std::vector< uint32_t > &out, bool isxAOD=false)
IOpaqueAddress for TrigSerializenCnvSvc.
const std::vector< uint32_t > & get() const