ATLAS Offline Software
INav4MomAssocsCnv_p1.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2019 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"
17 #include "StoreGate/StoreGateSvc.h"
18 
19 // NavFourMom includes
21 
22 // EventCommonTPCnv includes
24 
25 
26 void
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 
122 void
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.push_back( association );
149  }
150  }
151 
152  log << MSG::DEBUG
153  << "Created persistent state of INav4MomAssocs [OK]"
154  << endmsg;
155  return;
156 }
INav4MomAssocs
INav4MomAssocs
Definition: EventCommonTPCnv.cxx:32
INav4MomAssocs_p1::m_assocs
ElemLinkVect_t m_assocs
Definition: INav4MomAssocs_p1.h:70
AssociationMap::beginObject
object_iterator beginObject() const
begin iterator for objects
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
INav4MomAssocs.h
INav4MomAssocs_p1
Definition: INav4MomAssocs_p1.h:24
AssociationObjectIterator
object iterator for association maps (internal use only!)
AssociationMap::endObject
object_iterator endObject() const
end iterator for objects
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
INav4MomAssocs_p1::ElemLink_t
std::pair< Elem_t, Elem_t > ElemLink_t
Definition: INav4MomAssocs_p1.h:39
Trk::association
@ association
Definition: TrackingGeometry.h:46
INav4MomAssocsCnv_p1::m_storeGate
StoreGateSvc * m_storeGate
Pointer to the StoreGateSvc: we need this as we'll have to fetch the INav4MomAssocs which is the pare...
Definition: INav4MomAssocsCnv_p1.h:76
INav4MomAssocs
Definition: INav4MomAssocs.h:33
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
INav4MomAssocsCnv_p1::transToPers
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...
Definition: INav4MomAssocsCnv_p1.cxx:123
INav4MomAssocs::addAssocStore
void addAssocStore(const DataLink< INav4MomAssocs > &assocStore)
Retrieve all the associated-to objects which have been associated to the given.
Definition: INav4MomAssocs.cxx:178
INav4MomAssocs::getAssocStores
std::vector< DataLink< INav4MomAssocs > > getAssocStores() const
Return links to all other association stores.
Definition: INav4MomAssocs.cxx:188
AssociationMap::addAssociation
void addAssociation(const object_container_type *objectContainer, const object_index_type &objectIndex, const asso_container_type *assoContainer, const asso_index_type &assoIndex)
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
INav4MomAssocs_p1::m_assocStores
INav4MomStores_t m_assocStores
Definition: INav4MomAssocs_p1.h:71
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::asso_iterator
AssociationVectorIterator asso_iterator
association iterator type
Definition: AssociationMap.h:81
INav4MomAssocs_p1::Elem_t
std::pair< std::string, unsigned int > Elem_t
Definition: INav4MomAssocs_p1.h:38
StoreGateSvc.h
INav4MomAssocsCnv_p1::persToTrans
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...
Definition: INav4MomAssocsCnv_p1.cxx:27
INav4MomAssocsCnv_p1.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37