ATLAS Offline Software
AssociationMap.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATHLINKS_ASSOCIATIONMAP_H
6 #define ATHLINKS_ASSOCIATIONMAP_H
7 
8 #define ASSOCIATION_CONTEXT
9 #define ASSOCIATIONMAP_CONTEXT
10 
29 #include "AthLinks/ElementLink.h"
30 #include "AthLinks/ElementLinkVector.h"
32 
33 #include <map>
34 #include <list>
35 #include <algorithm>
36 
37 template<class OBJCONT,class ASSCONT>
39 {
40  public:
41 
44  typedef OBJCONT object_container_type;
46  typedef
47  typename
51  typedef typename std::list<const object_type*> object_list;
52 
53  typedef ASSCONT asso_container_type;
55  typedef
56  typename
59  typedef typename std::list<const asso_type*> asso_list;
63  typedef typename std::map<object_link,asso_store> store_type;
67  // Dummy to allow defining an end iterator for an empty map.
69 
73  virtual ~AssociationMap();
81  typedef AssociationVectorIterator asso_iterator;
97  void addAssociation(const object_container_type* objectContainer,
98  const object_index_type& objectIndex,
99  const asso_container_type* assoContainer,
100  const asso_index_type& assoIndex);
101  void addAssociation(const object_container_type* objectContainer,
102  const object_type* objectPointer,
103  const asso_container_type* assoContainer,
104  const asso_type* assoPointer);
105  void addAssociation(const object_link& objectLink,
106  const asso_link& assoLink);
121 
123  asso_iterator beginAssociation(const object_type* objectPointer) const;
126  asso_iterator endAssociation(const object_type* objectPointer) const;
127  asso_iterator endAssociation(const object_iterator& objectIter) const;
130 
132 
133 
135  const object_type* getObject(const object_iterator& objectIter) const
136  { return (*objectIter).getObject(); }
137 
139  object_iterator findObject(const object_type* theObject) const
140  { return object_iterator(m_associationMap).find(theObject); }
141 
143  bool containsObject(const object_type* theObject) const
144  { return this->findObject(theObject) != this->endObject(); }
145 
147  size_t getNumberOfObjects() const { return this->size(); }
148 
152 
153 
154  const asso_type* getAssociation(asso_iterator assoIter) const
155  { return *assoIter; }
156 
159  const asso_type* assoPointer) const
160  { return objectIter.findAssociation(assoPointer); }
162  const asso_type* assoPointer) const;
163 
165  bool containsAssociation(const object_iterator& objectIter,
166  const asso_type* assoPointer) const
167  { return objectIter.containsAssociation(assoPointer); }
168 
169  bool containsAssociation(const object_type* objectPointer,
170  const asso_type* assoPointer) const;
171  bool containsAssociation(const asso_type* assoPointer) const;
172 
174  bool getObjects(const asso_type* assoPointer, object_list& theObjects) const;
175 
177  bool getObjects(const asso_iterator& assoIter, object_list& theObjects) const
178  { return this->getObjects(*assoIter,theObjects); }
179 
181  bool getAssociations(const object_type* objPointer, asso_list& assocs) const;
182 
184  bool getAssociations(const object_iterator& objIter, asso_list& assocs) const
185  { return this->getAssociations(objIter.getObject(),assocs); }
186 
188  size_t size() { return m_associationMap.size(); }
189 
191  size_t size() const { return m_associationMap.size(); }
192 
193  size_t size(const object_type* objectPointer) const;
194 
195  size_t getNumberOfAssociations(const object_type* objectPointer) const
196  { return this->size(objectPointer); }
197 
198  size_t size(const object_iterator& objectIter) const
199  { return objectIter.getNumberOfAssociations(); }
200 
201  size_t getNumberOfAssociations(const object_iterator& objectIter) const
202  { return this->size(objectIter); }
203 
204  protected:
205 
208 
211  const asso_link& assoLink)
212  {
213  // check key
214  store_iterator_type mapEnd = m_associationMap.end();
215  store_iterator_type foundIter = mapEnd;
216  for ( store_iterator_type iMap = m_associationMap.begin();
217  iMap != mapEnd;
218  ++iMap ) {
219  // look for the address of the pointed-at object
220  // must dereference the ElementLink pointer
221  if ( iMap->first.cptr() == objectLink.cptr() ) {
222  foundIter = iMap;
223  break;
224  }
225  }
226 
227  if ( foundIter == m_associationMap.end() ) { return foundIter; }
228  // check data
229  if ( std::find((foundIter->second).begin(),
230  (foundIter->second).end(),
231  assoLink) !=
232  (foundIter->second).end() )
233  { return foundIter; }
234  // not found at all
235  return m_associationMap.end();
236  }
237 
239  bool addToStore(const object_link& objectLink, const asso_link& assoLink);
240 
241 };
242 
244 
245 #undef ASSOCIATION_CONTEXT
246 #undef ASSOCIATIONMAP_CONTEXT
247 #endif
AssociationMap::store_iterator_type
store_type::iterator store_iterator_type
Definition: AssociationMap.h:64
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AssociationMap::containsObject
bool containsObject(const object_type *theObject) const
testing if object is in store
Definition: AssociationMap.h:143
AssociationMap::size
size_t size() const
get number of associations
Definition: AssociationMap.h:191
AssociationMap::getAssociations
bool getAssociations(const object_type *objPointer, asso_list &assocs) const
get all associations for a given object
AssociationMap::addToStore
bool addToStore(const object_link &objectLink, const asso_link &assoLink)
internally used function to add links to store
AssociationMap::endAssociation
asso_iterator endAssociation(const object_type *objectPointer) const
end iterator for associations
AssociationMap::addAssociation
void addAssociation(const object_container_type *objectContainer, const object_type *objectPointer, const asso_container_type *assoContainer, const asso_type *assoPointer)
AssociationMap::~AssociationMap
virtual ~AssociationMap()
AssociationMap::getNumberOfAssociations
size_t getNumberOfAssociations(const object_type *objectPointer) const
Definition: AssociationMap.h:195
AssociationMap.icc
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AssociationMap::beginObject
object_iterator beginObject() const
begin iterator for objects
AssociationMap::beginAssociation
asso_iterator beginAssociation(const object_type *objectPointer) const
begin iterator for associations
AssociationMap::object_type
object_container_type::base_value_type object_type
Definition: AssociationMap.h:45
AssociationMap::AssociationMap
AssociationMap()
AssociationMap::containsAssociation
bool containsAssociation(const object_type *objectPointer, const asso_type *assoPointer) const
ElementLinkVector
ElementLinkVector implementation for standalone ROOT.
Definition: AthLinks/ElementLinkVector.h:65
AssociationMap
templated base class for a look-up map for associations
Definition: AssociationMap.h:39
AssociationMap::getAssociation
const asso_type * getAssociation(asso_iterator assoIter) const
associations iterator access
Definition: AssociationMap.h:154
AssociationMap::beginAssociation
asso_iterator beginAssociation(const object_iterator &objectIter) const
AssociationMap::asso_store_iterator
asso_store::const_iterator asso_store_iterator
Definition: AssociationMap.h:62
AssociationMap::object_link
ElementLink< object_container_type > object_link
Definition: AssociationMap.h:50
AssociationMap::s_dum_asso_store
static const asso_store s_dum_asso_store
Definition: AssociationMap.h:68
DataVector::base_value_type
T base_value_type
The T value used as the template parameter.
Definition: DataVector.h:824
AssociationMap::getObjects
bool getObjects(const asso_iterator &assoIter, object_list &theObjects) const
get all objects for a given association
Definition: AssociationMap.h:177
AssociationMap::asso_store
ElementLinkVector< asso_container_type > asso_store
Definition: AssociationMap.h:61
AssociationObjectIterator
object iterator for association maps (internal use only!)
AssociationMap::findAssociation
asso_iterator findAssociation(const object_iterator &objectIter, const asso_type *assoPointer) const
find association
Definition: AssociationMap.h:158
GenerateIndexingPolicy.h
AssociationMap::asso_list
std::list< const asso_type * > asso_list
Definition: AssociationMap.h:59
AssociationMap::addAssociation
void addAssociation(const object_link &objectLink, const asso_link &assoLink)
AssociationMap::object_iterator
AssociationObjectIterator object_iterator
object iterator type
Definition: AssociationMap.h:84
AssociationMap::endObject
object_iterator endObject() const
end iterator for objects
AssociationMap::asso_index_type
SG::GenerateIndexingPolicy< asso_container_type >::type::index_type asso_index_type
Definition: AssociationMap.h:58
AssociationMap::size
size_t size(const object_iterator &objectIter) const
Definition: AssociationMap.h:198
AssociationMap::getNumberOfObjects
size_t getNumberOfObjects() const
retrieve number of objects in store
Definition: AssociationMap.h:147
AssociationMap::asso_link
ElementLink< asso_container_type > asso_link
Definition: AssociationMap.h:60
AssociationMap::containsAssociation
bool containsAssociation(const asso_type *assoPointer) const
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
AssociationMap::findAssociation
asso_iterator findAssociation(const object_type *objectPointer, const asso_type *assoPointer) const
Rec::TrackParticleContainer
Definition: Reconstruction/Particle/Particle/TrackParticleContainer.h:33
AssociationMap::endAssociation
asso_iterator endAssociation(const object_iterator &objectIter) const
AssociationObjectIterator.h
AssociationMap::containsAssociation
bool containsAssociation(const object_iterator &objectIter, const asso_type *assoPointer) const
containment check
Definition: AssociationMap.h:165
AssociationVectorIterator.h
AssociationMap::getObject
const object_type * getObject(const object_iterator &objectIter) const
get association iterators by object iterator
Definition: AssociationMap.h:135
AssociationMap::asso_container_type
ASSCONT asso_container_type
Definition: AssociationMap.h:53
AssociationMap::addAssociation
void addAssociation(const object_container_type *objectContainer, const object_index_type &objectIndex, const asso_container_type *assoContainer, const asso_index_type &assoIndex)
AssociationMap::size
size_t size()
get number of associations
Definition: AssociationMap.h:188
ElementLinkVector::ELVIterator
Definition: AthLinks/ElementLinkVector.h:112
AssociationMap::findObject
object_iterator findObject(const object_type *theObject) const
finding an object with allocation
Definition: AssociationMap.h:139
AssociationMap::getObjects
bool getObjects(const asso_type *assoPointer, object_list &theObjects) const
get all objects for a given association
AssociationMap::internalFind
store_iterator_type internalFind(const object_link &objectLink, const asso_link &assoLink)
internally used find method
Definition: AssociationMap.h:210
AssociationMap::getNumberOfAssociations
size_t getNumberOfAssociations(const object_iterator &objectIter) const
Definition: AssociationMap.h:201
SG::GenerateIndexingPolicy
Definition: GenerateIndexingPolicy.h:30
AssociationMap::asso_iterator
AssociationVectorIterator asso_iterator
association iterator type
Definition: AssociationMap.h:81
AssociationMap::object_index_type
SG::GenerateIndexingPolicy< object_container_type >::type::index_type object_index_type
Definition: AssociationMap.h:49
AssociationMap::m_associationMap
store_type m_associationMap
internal store
Definition: AssociationMap.h:207
AssociationMap::getAssociations
bool getAssociations(const object_iterator &objIter, asso_list &assocs) const
get all associations for a given object
Definition: AssociationMap.h:184
AssociationMap::store_type
std::map< object_link, asso_store > store_type
Definition: AssociationMap.h:63
AssociationMap::asso_type
asso_container_type::base_value_type asso_type
Definition: AssociationMap.h:54
AssociationMap::size
size_t size(const object_type *objectPointer) const
AssociationMap::object_list
std::list< const object_type * > object_list
Definition: AssociationMap.h:51
AssociationMap::object_container_type
OBJCONT object_container_type
Definition: AssociationMap.h:44