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[ "TrigOperationalInfo" ] = "TrigOperationalInfoCollection_tlp1";
70 m_oldEDMmap[ "TrigInDetTrackCollection" ] = "TrigInDetTrackCollection_tlp1";
71 m_oldEDMmap[ "MuonFeature" ] = "MuonFeatureContainer_tlp1";
72 m_oldEDMmap[ "IsoMuonFeature" ] = "IsoMuonFeatureContainer_tlp1";
73 m_oldEDMmap[ "CombinedMuonFeature" ] = "CombinedMuonFeatureContainer_tlp1";
74 m_oldEDMmap[ "TileMuFeature" ] = "TileMuFeatureContainer_tlp1";
75 m_oldEDMmap[ "TileTrackMuFeature" ] = "TileTrackMuFeatureContainer_tlp1";
76 m_oldEDMmap[ "TrigEMCluster" ] = "TrigEMClusterContainer_tlp1";
77 //m_oldEDMmap[ "TrigEMCluster" ] = "TrigEMClusterContainer_tlp2";
78 m_oldEDMmap[ "RingerRings" ] = "RingerRingsContainer_tlp1";
79 m_oldEDMmap[ "TrigTauCluster" ] = "TrigTauClusterContainer_tlp1";
80 m_oldEDMmap[ "TrigTauClusterDetails" ] = "TrigTauClusterDetailsContainer_tlp1";
81 m_oldEDMmap[ "TrigTauTracksInfo" ] = "TrigTauTracksInfoCollection_tlp1";
82 m_oldEDMmap[ "TrigElectronContainer" ] = "TrigElectronContainer_tlp2";
83 m_oldEDMmap[ "TrigPhotonContainer" ] = "TrigPhotonContainer_tlp2";
84 m_oldEDMmap[ "TrigMissingET" ] = "TrigMissingETContainer_tlp1";
85 m_oldEDMmap[ "TrigT2MbtsBits" ] = "TrigT2MbtsBitsContainer_tlp1";
86 m_oldEDMmap[ "TrigSpacePointCounts" ] = "TrigSpacePointCountsCollection_tlp1";
87 m_oldEDMmap[ "TrigTrtHitCounts" ] = "TrigTrtHitCountsCollection_tlp1";
88 m_oldEDMmap[ "CosmicMuonCollection" ] = "CosmicMuonCollection_tlp1";
89 m_oldEDMmap[ "MdtTrackSegmentCollection" ] = "MdtTrackSegmentCollection_tlp1";
90 m_oldEDMmap[ "TrigVertexCollection" ] = "TrigVertexCollection_tlp1";
91 m_oldEDMmap[ "JetCollection" ] = "JetCollection_tlp2";
92 m_oldEDMmap[ "CaloClusterContainer" ] = "CaloClusterContainer_p4";
93 m_oldEDMmap[ "CaloShowerContainer" ] = "CaloShowerContainer_p2";
94 //m_oldEDMmap[ "CaloTowerContainer" ] = "CaloTowerContainer_p1";
95 m_oldEDMmap[ "TrigMuonEFContainer" ] = "TrigMuonEFContainer_tlp1";
96 m_oldEDMmap[ "TrigMuonEFInfoContainer" ] = "TrigMuonEFInfoContainer_tlp1";
97 m_oldEDMmap[ "egDetailContainer" ] = "egDetailContainer_p1";
98 m_oldEDMmap[ "egammaContainer" ] = "egammaContainer_p1";
99 m_oldEDMmap[ "Analysis::TauJetContainer" ] = "TauJetContainer_p3";
100 m_oldEDMmap[ "TrigTrackCounts" ] = "TrigTrackCountsCollection_tlp1";
101 m_oldEDMmap[ "TrackCollection" ] = "Trk::TrackCollection_tlp2";
102 m_oldEDMmap[ "Rec::TrackParticleContainer" ] = "Rec::TrackParticleContainer_tlp1";
103 m_oldEDMmap[ "Analysis::TauDetailsContainer" ] ="TauDetailsContainer_tlp1";
104 m_oldEDMmap[ "VxContainer" ] = "";
105 m_oldEDMmap[ "CaloCellContainer" ] = "CaloCompactCellContainer";
106
107
108 return StatusCode::SUCCESS;
109}
110
111StatusCode TrigSerializeConvHelper::createObj(const std::string &clname, IOpaqueAddress* iAddr, void *&ptr, bool isxAOD){
112 ptr = 0;
113 ATH_MSG_DEBUG("in TrigSerializeConvHelper::createObj for clname " << clname << " is xAOD? " << (isxAOD?"yes":"no"));
114
115 //could alse get DATA (perhaps as std::any) from the IOA
116 TrigStreamAddress *addr = dynamic_cast<TrigStreamAddress*>(iAddr);
117 if (!addr) {
118 ATH_MSG_WARNING("createObj cast failed");
119 return StatusCode::FAILURE;
120 }
121
122 ITrigSerializerToolBase* serializer = m_serializerTool.operator->();
123 serializer->reset();
124
125 std::vector<uint32_t> v = addr->get();
126
127 //we need to find the name of the ob
128 std::string cl = clname;
129
130 if (m_doTP and !isxAOD)
131 cl = m_TPTool->persClassName(clname);
132
133 uint32_t guid[4];
134
135 bool versionChange = false;
136
137 if (cl!=""){
138 StatusCode scid;
139 scid = serializer->peekCLID(v, guid);
140 if (scid.isFailure()){
141 //BS has no hint on the pers class - use the original table
142 ATH_MSG_DEBUG("BS does not hint on payload object " << cl);
143 if (m_oldEDMmap.find(clname)!=m_oldEDMmap.end()){
144 if (cl!=m_oldEDMmap[clname]){
145 ATH_MSG_DEBUG("Using backward compatibility map with " << m_oldEDMmap[clname]
146 << " instead of " << cl);
147 cl = m_oldEDMmap[clname];
148 }
149 }
150 } else {
151 //get the pers version from the BS
152 std::string nclass = cl;
153 StatusCode ai = m_guidTool->IntsToClassName(guid, nclass);
154 if (ai.isFailure()) {
155 //better do not decode
156 return StatusCode::FAILURE;
157 }
158 if (cl != nclass){
159 cl = nclass;
160 ATH_MSG_DEBUG("Got hint of " << cl << " different persistent class from the BS payload. Name from GUID: " << nclass);
161
162 if(isxAOD){
163 ATH_MSG_DEBUG("This is an xAOD so probably the BS version is an older version of the xAOD type.");
164 }
165 versionChange = true;
166 }
167 }
168
169 // Many variables in this class were changed from double to float.
170 // However, we wrote data in the past which contained values
171 // that were valid doubles but which were out of range for floats.
172 // So we can get FPEs when we read them.
173 // Disable FPEs when we're reading an instance of this class.
174 CxxUtils::FPControl fpcontrol;
175 if (cl == "xAOD::BTaggingTrigAuxContainer_v1") {
176 fpcontrol.holdExceptions();
177 }
178
179 ptr = serializer->deserialize(cl, v);
180
181 ATH_MSG_DEBUG(cl << " deserialized to " << ptr << " version change detected: " << (versionChange ? "yes":"no"));
182 }
183
184 // T/P separation
185 bool isViewVector = cl.substr(0, 11) == "ViewVector<";
186 if (m_doTP and (!isxAOD or versionChange) and !isViewVector){
187 std::string transclass;
188
189 ATH_MSG_DEBUG("converting with pername " << cl);
190
191 void *transObj = m_TPTool->convertPT(cl,ptr, transclass);
192
193 ATH_MSG_DEBUG("was converted to " << transclass << " at " << transObj);
194
195 //persistent object not needed anymore
196 RootType persClObj(cl);
197 persClObj.Destruct(ptr);
198
199 ptr = transObj;
200 }
201
202 return StatusCode::SUCCESS;
203}
204
205
206
207StatusCode TrigSerializeConvHelper::createRep(const std::string &clname,
208 void *ptr, std::vector<uint32_t> &out, bool isxAOD){
209
210 StatusCode sc(StatusCode::SUCCESS);
211
212 ATH_MSG_DEBUG("in TrigSerializeConvHelper::createRep for clname" << clname << " is xAOD? " << (isxAOD?"yes":"no"));
213
214 std::string cl = clname;
215 void *pObj = ptr;
216
217 // T/P separation
218 if (m_doTP and !isxAOD){
219 std::string persclass("");
220 pObj = m_TPTool->convertTP(clname,ptr, persclass);
221 cl = std::move(persclass);
222 }
223
224 ATH_MSG_DEBUG("convertTP: " << pObj << " of " << cl);
225
226 //void *serptr(0);
227 //
228 ITrigSerializerToolBase* serializer = m_serializerTool.operator->();
229 serializer->reset();
230
231 ATH_MSG_VERBOSE("About to get GUID for " << cl);
232
233 //opposite from string to class
234 uint32_t irep[4];
235 StatusCode ai = m_guidTool->ClassNameToInts(cl, irep);
236 if (ai.isFailure()){
237 ATH_MSG_WARNING("Cannot store class identification for " << cl << " to BS");
238 }
239
240 ATH_MSG_VERBOSE("got GUID: " << irep[0] << "-" << irep[1] << "-" << irep[2] << "-" << irep[3]);
241
242 if (cl != "" && pObj){
243 serializer->setCLID(irep);
244 serializer->serialize(cl, pObj, out);
245 } else {
246 ATH_MSG_WARNING("did not serialize " << ptr << " of " << clname);
247 }
248
249 if (m_doTP and !isxAOD){
250 //we don't need the persistent object anymore
251 RootType persClObj(cl);
252 persClObj.Destruct(pObj);
253 }
254
255 ATH_MSG_DEBUG("pObj: " << pObj << " of " << cl << " payload: " << out.size());
256
257 return sc;
258}
#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