ATLAS Offline Software
INav4MomAssocs.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // INav4MomAssocs.cxx
7 // Implementation file for class INav4MomAssocs
8 // Author: S.Binet<binet@cern.ch>
10 
11 
12 // STL includes
13 #include <algorithm>
14 
15 // NavFourMom includes
17 #include "EventKernel/IParticle.h"
19 
21 // Public methods:
23 
24 // Constructors/assignment
27 INav4MomAssocs::INav4MomAssocs( const INav4MomAssocs& rhs ) = default;
31 
33 // Const methods:
35 
36 bool
38  ConstDataVector<INavigable4MomentumCollection>& associatedElems ) const
39 {
40  if ( 0 == object ) {
41  return false;
42  }
43 
44  // do the underlying stores contain this object ?
45  bool contained = false;
46  for ( std::map<std::string, DataLink<INav4MomAssocs> >::const_iterator itr = m_assocStores.begin();
47  itr != m_assocStores.end();
48  ++itr ) {
49  if ( itr->second->assocs(object, associatedElems) ) {
50  contained = true;
51  }
52  }
53 
54  if ( !contained && !containsObject( object ) ) {
55  return false;
56  }
57 
58  associatedElems.reserve( associatedElems.size() +
59  getNumberOfAssociations(object) );
60  INav4MomAssocs::asso_iterator endAssocs = endAssociation( object );
61  for ( INav4MomAssocs::asso_iterator itr = beginAssociation( object );
62  itr != endAssocs;
63  ++itr ) {
64  associatedElems.push_back( const_cast<INavigable4Momentum*>(*itr) );
65  }
66 
67  return true;
68 }
69 
70 
71 
72 bool
74  INav4MomLinkContainer& associatedElementLinks ) const
75 {
76  if ( !objectLink.isValid() )
77  {
78  return false;
79  }
80 
81  // Get the object
82  const INavigable4Momentum* object(NULL);
83  object = (*objectLink);
84  if ( object == NULL )
85  {
86  return false;
87  }
88 
89  return getAssociations( object, associatedElementLinks );
90 }
91 
92 
93 
94 
95 bool
97  INav4MomLinkContainer& associatedElementLinks ) const
98 {
99  if ( 0 == object )
100  {
101  return false;
102  }
103 
104  // do the underlying stores contain this object ?
105  bool contained = false;
106  for ( std::map<std::string, DataLink<INav4MomAssocs> >::const_iterator itr = m_assocStores.begin();
107  itr != m_assocStores.end();
108  ++itr )
109  {
110  if ( itr->second->getAssociations( object, associatedElementLinks ) )
111  {
112  contained = true;
113  }
114  }
115 
116  if ( !contained && !containsObject( object ) )
117  {
118  return false;
119  }
120 
121  // check key
122  store_type::const_iterator mapEnd = m_associationMap.end();
123  store_type::const_iterator foundIter = mapEnd;
124  for ( store_type::const_iterator iMap = m_associationMap.begin();
125  iMap != mapEnd;
126  ++iMap )
127  {
128  // look for the address of the pointed-at object
129  // must dereference the ElementLink pointer
130  if ( &*(*(iMap->first)) == &*(object) )
131  {
132  foundIter = iMap;
133  break;
134  }
135  }
136  if ( foundIter == m_associationMap.end() )
137  {
138  return false;
139  }
140 
141  // Now, loop over all associations and fill the vector of associations
142  associatedElementLinks.reserve( associatedElementLinks.size() +
143  getNumberOfAssociations(object) );
146  for ( ; assoItr != assoItrEnd; ++assoItr )
147  {
148  const INav4MomLink assoLink = (*assoItr);
149  associatedElementLinks.push_back( assoLink );
150  }
151 
152  return true;
153 }
154 
155 
156 
158 // Non-const methods:
160 
162 {
163  const std::string& id = assocStore.dataID();
164  const std::map<std::string, DataLink<INav4MomAssocs> >::const_iterator itr = m_assocStores.find(id);
165  if ( itr != m_assocStores.end() ) {
166  m_assocStores[id] = assocStore;
167  }
168 }
169 
170 
171 std::vector<DataLink<INav4MomAssocs> > INav4MomAssocs::getAssocStores() const
172 {
173  std::vector<DataLink<INav4MomAssocs> > ret;
174  ret.reserve (m_assocStores.size());
175  for (const auto& p : m_assocStores) {
176  ret.push_back (p.second);
177  }
178  return ret;
179 }
180 
181 
182 #ifdef __APPLE__
183 // Static template members:
186 // This is only necessary for MacOSX where there's a bug in the linker that causes duplicate symbols if
187 // the static templates for the same concrete type are instantiated in two different .cxx files
188 template <class T> DataVector_detail::RegisterDVLEltBaseInit<T> DataVector_detail::DVLEltBaseInit<T>::s_regbase;
189 template class DataVector_detail::RegisterDVLEltBaseInit<IParticle> DataVector_detail::DVLEltBaseInit<IParticle>::s_regbase;
190 #endif
191 
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::containsObject
bool containsObject(const object_type *theObject) const
testing if object is in store
Definition: AssociationMap.h:143
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::endAssociation
asso_iterator endAssociation(const object_type *objectPointer) const
end iterator for associations
INav4MomAssocs::m_assocStores
std::map< std::string, INav4MomAssocsLink_t > m_assocStores
Definition: INav4MomAssocs.h:134
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::getNumberOfAssociations
size_t getNumberOfAssociations(const object_type *objectPointer) const
Definition: AssociationMap.h:195
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::beginAssociation
asso_iterator beginAssociation(const object_type *objectPointer) const
begin iterator for associations
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
IParticle.h
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
INav4MomAssocs.h
INav4MomAssocs::assocs
bool assocs(const INavigable4Momentum *object, ConstDataVector< INavigable4MomentumCollection > &assocs) const
Retrieve all the associated-to objects which have been associated to the given.
Definition: INav4MomAssocs.cxx:37
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
INav4MomAssocs
Definition: INav4MomAssocs.h:33
INav4MomAssocs::addAssocStore
void addAssocStore(const DataLink< INav4MomAssocs > &assocStore)
Retrieve all the associated-to objects which have been associated to the given.
Definition: INav4MomAssocs.cxx:161
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
INav4MomAssocs::getAssocStores
std::vector< DataLink< INav4MomAssocs > > getAssocStores() const
Return links to all other association stores.
Definition: INav4MomAssocs.cxx:171
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
INavigable4Momentum
Definition: INavigable4Momentum.h:21
ElementLinkVector::ELVIterator
Definition: AthLinks/ElementLinkVector.h:112
INav4MomAssocs::getAssociations
bool getAssociations(const INav4MomLink &objectLink, INav4MomLinkContainer &associatedElementLinks) const
Retrieve all the associated-to ElementLinks_to_objects which have been associated to the given.
Definition: INav4MomAssocs.cxx:73
pickleTool.object
object
Definition: pickleTool.py:29
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::asso_iterator
AssociationVectorIterator asso_iterator
association iterator type
Definition: AssociationMap.h:81
AssociationMap< INavigable4MomentumCollection, INavigable4MomentumCollection >::m_associationMap
store_type m_associationMap
internal store
Definition: AssociationMap.h:207
INav4MomAssocs::operator=
INav4MomAssocs & operator=(const INav4MomAssocs &rhs)
Assignment operator:
INav4MomAssocs::INav4MomAssocs
INav4MomAssocs()
Default constructor: