ATLAS Offline Software
Loading...
Searching...
No Matches
INav4MomAssocsCnv_p1.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7// INav4MomAssocsCnv_p1.cxx
8// Implementation file for class INav4MomAssocsCnv_p1
9// Author: S.Binet<binet@cern.ch>
11
12
13// STL includes
14
15// Framework includes
16#include "GaudiKernel/MsgStream.h"
18
19// NavFourMom includes
21
22// EventCommonTPCnv includes
24
25
26void
28 INav4MomAssocs* transObj,
29 MsgStream &log ) const
30{
31 *transObj = INav4MomAssocs();
32
33 log << MSG::DEBUG
34 << "Loading INav4MomAssocs from persistent state..."
35 << endmsg;
36 if ( 0 == m_storeGate ) {
37 log << MSG::ERROR
38 << "NULL pointer to StoreGateSvc !!" << endmsg
39 << "Cannot do anything !!" <<endmsg;
40 throw std::runtime_error("NULL pointer to StoreGateSvc !!");
41 }
42
43 // retrieve underlying association stores
44 for ( std::vector<std::string>::const_iterator itr = persObj->m_assocStores.begin();
45 itr != persObj->m_assocStores.end();
46 ++itr ) {
47 DataLink<INav4MomAssocs> link( *itr );
48 if ( !link.isValid() ) {
49 log << MSG::WARNING
50 << "Could not build DataLink<INav4MomAssocs> from ["
51 << *itr
52 << "] !!"
53 << endmsg;
54 } else {
55 transObj->addAssocStore (link);
56 }
57 }
58
59 std::map<std::string,const INavigable4MomentumCollection*> collections;
60
61 for ( INav4MomAssocs_p1::ElemLinkVect_t::const_iterator asso = persObj->m_assocs.begin();
62 asso != persObj->m_assocs.end();
63 ++asso ) {
64
65 const std::pair<std::string,unsigned int>& objLink = asso->first;
66 const std::pair<std::string,unsigned int>& assLink = asso->second;
67
68 const std::string& objKey = objLink.first;
69 const std::string& assKey = assLink.first;
70
71 log << MSG::DEBUG << "\tobjLink=" << objKey << ", " << objLink.second << endmsg;
72 log << MSG::DEBUG << "\tassLink=" << assKey << ", " << assLink.second << endmsg;
73
74 if ( collections.find(objKey) == collections.end() ) {
75 const INavigable4MomentumCollection* coll = nullptr;
76 collections[objKey] = 0;
77 if ( m_storeGate->retrieve( coll, objKey ).isFailure() ||
78 nullptr == coll ) {
79 log << MSG::ERROR
80 << "Could not retrieve INavigable4MomentumCollection at : "
81 << objKey
82 << endmsg;
83 throw std::runtime_error("Could not retrieve an INavigable4MomentumCollection");
84 } else {
85 log << MSG::DEBUG
86 << "Successfully retrieve INav4MomCollection at : "
87 << objKey
88 << endmsg;
89 }
90 collections[objKey] = coll;
91 }
92
93 if ( collections.find(assKey) == collections.end() ) {
94 const INavigable4MomentumCollection* coll = nullptr;
95 if ( m_storeGate->retrieve( coll, assKey ).isFailure() ||
96 nullptr == coll ) {
97 log << MSG::ERROR
98 << "Could not retrieve INavigable4MomentumCollection at : "
99 << assKey
100 << endmsg;
101 throw std::runtime_error("Could not retrieve an INavigable4MomentumCollection");
102 } else {
103 log << MSG::DEBUG
104 << "Successfully retrieve INav4MomCollection at : "
105 << assKey
106 << endmsg;
107 }
108 collections[assKey] = coll;
109 }
110
111 transObj->addAssociation( collections[objKey], objLink.second,
112 collections[assKey], assLink.second );
113
114 }
115
116 log << MSG::DEBUG
117 << "Loaded INav4MomAssocs from persistent state [OK]"
118 << endmsg;
119 return;
120}
121
122void
124 INav4MomAssocs_p1* persObj,
125 MsgStream &log ) const
126{
127 log << MSG::DEBUG
128 << "Creating persistent state of INav4MomAssocs..."
129 << endmsg;
130
131 // first store the underlying association stores
132 for (const DataLink<INav4MomAssocs>& l : transObj->getAssocStores()) {
133 persObj->m_assocStores.push_back( l.dataID() );
134 }
135
136 INav4MomAssocs::object_iterator begObj = transObj->beginObject();
137 INav4MomAssocs::object_iterator endObj = transObj->endObject();
138 for (; begObj != endObj; ++begObj)
139 {
140 const INav4MomAssocs::object_link& key = begObj.getObjectLink();
141 INav4MomAssocs_p1::Elem_t keyElem (key.dataID(), key.index());
142 INav4MomAssocs::asso_iterator begAsso = begObj.getFirstAssociation();
143 INav4MomAssocs::asso_iterator endAsso = begObj.getLastAssociation();
144 for (; begAsso != endAsso; ++begAsso) {
145 const INav4MomAssocs::asso_link asso = begAsso.getLink();
146 INav4MomAssocs_p1::Elem_t assoElem (asso.dataID(), asso.index());
147 const INav4MomAssocs_p1::ElemLink_t association( keyElem, assoElem );
148 persObj->m_assocs.emplace_back( keyElem, assoElem );
149 }
150 }
151
152 log << MSG::DEBUG
153 << "Created persistent state of INav4MomAssocs [OK]"
154 << endmsg;
155 return;
156}
#define endmsg
INav4MomAssocs
DataVector< INavigable4Momentum > INavigable4MomentumCollection
object_iterator endObject() const
end iterator for objects
void addAssociation(const object_container_type *objectContainer, const object_index_type &objectIndex, const asso_container_type *assoContainer, const asso_index_type &assoIndex)
object_iterator beginObject() const
begin iterator for objects
virtual void transToPers(const INav4MomAssocs *transObj, INav4MomAssocs_p1 *persObj, MsgStream &log) const override
Method creating the persistent representation INav4MomAssocs_p1 from its transient representation INa...
StoreGateSvc * m_storeGate
Pointer to the StoreGateSvc: we need this as we'll have to fetch the INav4MomAssocs which is the pare...
virtual void persToTrans(const INav4MomAssocs_p1 *persObj, INav4MomAssocs *transObj, MsgStream &log) const override
Method creating the transient representation of INav4MomAssocs from its persistent representation INa...
std::pair< Elem_t, Elem_t > ElemLink_t
ElemLinkVect_t m_assocs
INav4MomStores_t m_assocStores
std::pair< std::string, unsigned int > Elem_t
void addAssocStore(const DataLink< INav4MomAssocs > &assocStore)
Retrieve all the associated-to objects which have been associated to the given.
std::vector< DataLink< INav4MomAssocs > > getAssocStores() const
Return links to all other association stores.