2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5template<class OBJCONT,class ASSCONT>
6const typename AssociationMap<OBJCONT,ASSCONT>::asso_store
7 AssociationMap<OBJCONT,ASSCONT>::s_dum_asso_store;
9/////////////////////////////////
10// Constructors and Destructor //
11/////////////////////////////////
13template<class OBJCONT,class ASSCONT>
14AssociationMap<OBJCONT,ASSCONT>::AssociationMap()
17template<class OBJCONT,class ASSCONT>
18AssociationMap<OBJCONT,ASSCONT>::~AssociationMap()
20 m_associationMap.clear();
23////////////////////////////////////
24// Add Association Implementation //
25////////////////////////////////////
28template<class OBJCONT,class ASSCONT>
30AssociationMap<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);
52template<class OBJCONT,class ASSCONT>
54AssociationMap<OBJCONT,ASSCONT>::addAssociation(const object_container_type*
58 const asso_container_type*
64 this->addToStore( object_link( objectPointer, *objectContainer ),
65 asso_link ( assoPointer, *assoContainer ) );
69template<class OBJCONT,class ASSCONT>
71AssociationMap<OBJCONT,ASSCONT>::addAssociation(const object_link&
77 this->addToStore( objectLink, assoLink );
85template<class OBJCONT,class ASSCONT>
86inline typename AssociationMap<OBJCONT,ASSCONT>::object_iterator
87AssociationMap<OBJCONT,ASSCONT>::beginObject() const
89 return object_iterator(m_associationMap).begin();
93template<class OBJCONT,class ASSCONT>
94inline typename AssociationMap<OBJCONT,ASSCONT>::object_iterator
95AssociationMap<OBJCONT,ASSCONT>::endObject() const
97 return object_iterator(m_associationMap).end();
100template<class OBJCONT,class ASSCONT>
101inline typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
102AssociationMap<OBJCONT,ASSCONT>::beginAssociation(const object_iterator&
105 return this->beginAssociation(objectIter.getObject());
108template<class OBJCONT,class ASSCONT>
109inline typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
110AssociationMap<OBJCONT,ASSCONT>::endAssociation(const object_iterator&
113 return this->endAssociation(objectIter.getObject());
116// association begin iterator
117template<class OBJCONT,class ASSCONT>
118typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
119AssociationMap<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
138template<class OBJCONT,class ASSCONT>
139typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
140AssociationMap<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////////////////////////////
162template<class OBJCONT,class ASSCONT>
164AssociationMap<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
180template<class OBJCONT,class ASSCONT>
181typename AssociationMap<OBJCONT,ASSCONT>::asso_iterator
182AssociationMap<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
197template<class OBJCONT,class ASSCONT>
199AssociationMap<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
211template<class OBJCONT,class ASSCONT>
213AssociationMap<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
235template<class OBJCONT,class ASSCONT>
237AssociationMap<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
253template<class OBJCONT,class ASSCONT>
255AssociationMap<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///////////////////////////////////////////////////////////////////
272template<class OBJCONT,class ASSCONT>
274AssociationMap<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);