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