2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 template<class OBJCONT,class ASSCONT>
6 const typename AssociationMap<OBJCONT,ASSCONT>::asso_store
7 AssociationMap<OBJCONT,ASSCONT>::s_dum_asso_store;
9 /////////////////////////////////
10 // Constructors and Destructor //
11 /////////////////////////////////
13 template<class OBJCONT,class ASSCONT>
14 AssociationMap<OBJCONT,ASSCONT>::AssociationMap()
17 template<class OBJCONT,class ASSCONT>
18 AssociationMap<OBJCONT,ASSCONT>::~AssociationMap()
20 m_associationMap.clear();
23 ////////////////////////////////////
24 // Add Association Implementation //
25 ////////////////////////////////////
28 template<class OBJCONT,class ASSCONT>
30 AssociationMap<OBJCONT,ASSCONT>::addAssociation(const object_container_type*
32 const object_index_type&
34 const asso_container_type*
36 const asso_index_type&
40 object_link objectLink( *objectContainer, objectIndex );
41 objectLink.setElement( (*objectContainer)[objectIndex] );
44 asso_link assoLink( *assoContainer, assoIndex );
45 assoLink.setElement( (*assoContainer)[assoIndex]);
48 this->addToStore(objectLink,assoLink);
52 template<class OBJCONT,class ASSCONT>
54 AssociationMap<OBJCONT,ASSCONT>::addAssociation(const object_container_type*
58 const asso_container_type*
64 this->addToStore( object_link( objectPointer, *objectContainer ),
65 asso_link ( assoPointer, *assoContainer ) );
69 template<class OBJCONT,class ASSCONT>
71 AssociationMap<OBJCONT,ASSCONT>::addAssociation(const object_link&
77 this->addToStore( objectLink, assoLink );
85 template<class OBJCONT,class ASSCONT>
86 inline typename AssociationMap<OBJCONT,ASSCONT>::object_iterator
87 AssociationMap<OBJCONT,ASSCONT>::beginObject() const
89 return object_iterator(m_associationMap).begin();
93 template<class OBJCONT,class ASSCONT>
94 inline typename AssociationMap<OBJCONT,ASSCONT>::object_iterator
95 AssociationMap<OBJCONT,ASSCONT>::endObject() const
97 return object_iterator(m_associationMap).end();
100 template<class OBJCONT,class ASSCONT>
101 inline typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
102 AssociationMap<OBJCONT,ASSCONT>::beginAssociation(const object_iterator&
105 return this->beginAssociation(objectIter.getObject());
108 template<class OBJCONT,class ASSCONT>
109 inline typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
110 AssociationMap<OBJCONT,ASSCONT>::endAssociation(const object_iterator&
113 return this->endAssociation(objectIter.getObject());
116 // association begin iterator
117 template<class OBJCONT,class ASSCONT>
118 typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
119 AssociationMap<OBJCONT,ASSCONT>::beginAssociation(const object_type*
123 object_iterator foundIter = this->findObject(objectPointer);
126 if ( foundIter != this->endObject() )
128 return foundIter.getFirstAssociation();
133 return asso_iterator (s_dum_asso_store, s_dum_asso_store.end());
137 // association end iterator
138 template<class OBJCONT,class ASSCONT>
139 typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
140 AssociationMap<OBJCONT,ASSCONT>::endAssociation(const object_type*
144 object_iterator foundIter = this->findObject(objectPointer);
147 if ( foundIter != this->endObject() )
149 return foundIter.getLastAssociation();
154 return asso_iterator (s_dum_asso_store, s_dum_asso_store.end());
158 ////////////////////////////
159 // Store Parameter Access //
160 ////////////////////////////
162 template<class OBJCONT,class ASSCONT>
164 AssociationMap<OBJCONT,ASSCONT>::size(const object_type* objectPointer) const
166 object_iterator foundIter = this->findObject(objectPointer);
167 if ( foundIter != this->endObject() )
169 return this->size(foundIter);
179 // find association for given object
180 template<class OBJCONT,class ASSCONT>
181 typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
182 AssociationMap<OBJCONT,ASSCONT>::findAssociation(const object_type* objectPointer,
183 const asso_type* assoPointer)
187 object_iterator foundIter = object_iterator(m_associationMap).find(objectPointer);
188 if ( foundIter == this->endObject() )
190 return asso_iterator (s_dum_asso_store, s_dum_asso_store.end());
193 return (foundIter.second()).find(assoPointer);
196 // check on association for a given object
197 template<class OBJCONT,class ASSCONT>
199 AssociationMap<OBJCONT,ASSCONT>::containsAssociation(const object_type* objectPointer,
200 const asso_type* assoPointer) const
202 const object_iterator obj = this->findObject( objectPointer );
203 if ( obj != endObject() ) {
204 return obj.containsAssociation(assoPointer);
210 // find if it contains association anywhere
211 template<class OBJCONT,class ASSCONT>
213 AssociationMap<OBJCONT,ASSCONT>::containsAssociation(const asso_type*
217 const object_iterator lastObj = this->endObject();
218 for ( object_iterator objItr = this->beginObject();
221 asso_iterator lastAsso = this->endAssociation( objItr );
222 for ( asso_iterator assItr = this->beginAssociation(objItr);
225 if ( *assItr == assoPointer ) {
228 }//> end loop over associated objects
229 }//> end loop over objects
234 // retrieve all objects for a given association
235 template<class OBJCONT,class ASSCONT>
237 AssociationMap<OBJCONT,ASSCONT>::getObjects(const asso_type* assoPointer,
238 object_list& theObjects) const
240 const object_iterator objEnd = this->endObject();
241 for ( object_iterator objItr = this->beginObject();
244 const object_type* pObj = objItr.getObject();
245 if ( this->containsAssociation(pObj,assoPointer) ) {
246 theObjects.push_back(pObj);
249 return theObjects.size() > 0;
252 // retrieve all associated-objects for a given object
253 template<class OBJCONT,class ASSCONT>
255 AssociationMap<OBJCONT,ASSCONT>::getAssociations(const object_type* objPointer,
256 asso_list& assocs) const
258 const size_t origSize = assocs.size();
259 const asso_iterator assocEnd = this->endAssociation(objPointer);
260 for ( asso_iterator assocItr = this->beginAssociation(objPointer);
261 assocItr != assocEnd;
263 assocs.push_back( *assocItr );
265 return assocs.size() > origSize;
268 ///////////////////////////////////////////////////////////////////
269 /// Protected methods:
270 ///////////////////////////////////////////////////////////////////
272 template<class OBJCONT,class ASSCONT>
274 AssociationMap<OBJCONT,ASSCONT>::addToStore(const object_link& objectLink,
275 const asso_link& assoLink)
277 // check if already in (no association to be stored twice)
278 if ( this->internalFind(objectLink,assoLink) != m_associationMap.end() ) {
282 m_associationMap[objectLink].push_back(assoLink);