CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KalmanAlignmentMetricsCalculator.cc
Go to the documentation of this file.
2 #include <limits.h>
3 
5 
6 
8 
9 
10 void KalmanAlignmentMetricsCalculator::updateDistances( const std::vector< Alignable* >& alignables )
11 {
12  // List of the distances of the current alignables.
13  FullDistancesList currentDistances;
14 
15  // Updated list of the distances of the current alignables.
16  FullDistancesList updatedDistances;
17 
18  // List of distances between the current and all other alignables that changed due to the update of the list
19  // of the current alignables. This information has to be propagated to the lists of all other alignables.
20  FullDistancesList propagatedDistances;
21 
22  // Iterate over current alignables and set the distances between them to 1 - save pointers to
23  // their distances-lists for further manipulation.
24  std::vector< Alignable* >::const_iterator itA;
25  for ( itA = alignables.begin(); itA != alignables.end(); ++itA )
26  {
27  FullDistancesList::iterator itD = theDistances.find( *itA );
28 
29  if ( itD != theDistances.end() )
30  {
31  currentDistances[*itA] = itD->second;
32 
33  std::vector< Alignable* >::const_iterator itA2;
34  for ( itA2 = alignables.begin(); itA2 != alignables.end(); ++itA2 ) (*itD->second)[*itA2] = ( *itA == *itA2 ) ? 0 : 1;
35  }
36  else
37  {
39  theDistances[*itA] = newEntry;
40  currentDistances[*itA] = newEntry;
41 
42  std::vector< Alignable* >::const_iterator itA2;
43  for ( itA2 = alignables.begin(); itA2 != alignables.end(); ++itA2 ) (*newEntry)[*itA2] = ( *itA == *itA2 ) ? 0 : 1;
44  }
45  }
46 
47  // Iterate over the current alignables' distances-lists and compute updates.
48  FullDistancesList::iterator itC1;
49  FullDistancesList::iterator itC2;
50  for ( itC1 = currentDistances.begin(); itC1 != currentDistances.end(); ++itC1 )
51  {
52  SingleDistancesList* updatedList = new SingleDistancesList( *itC1->second );
53 
54  for ( itC2 = currentDistances.begin(); itC2 != currentDistances.end(); ++itC2 )
55  {
56  if ( itC1->first != itC2->first ) updateList( updatedList, itC2->second );
57  }
58 
59  extractPropagatedDistances( propagatedDistances, itC1->first, itC1->second, updatedList );
60  updatedDistances[itC1->first] = updatedList;
61  }
62 
63  // Insert the updated distances-lists.
64  insertUpdatedDistances( updatedDistances );
65 
66  // Insert the propagated distances-lists.
67  insertPropagatedDistances( propagatedDistances );
68 
69  // Used only temporary - clear it to deallocate its memory.
70  clearDistances( propagatedDistances );
71 }
72 
73 
76 {
77  FullDistancesList::const_iterator itD = theDistances.find( i );
78  if ( itD == theDistances.end() ) return theDefaultReturnList;
79  return *itD->second;
80 }
81 
82 
84 {
85  if ( i == j ) return 0;
86 
87  FullDistancesList::const_iterator itD = theDistances.find( i );
88  if ( itD == theDistances.end() ) return -1;
89 
90  SingleDistancesList::const_iterator itL = itD->second->find( j );
91  if ( itL == itD->second->end() ) return -1;
92 
93  return itL->second;
94 }
95 
96 
98 {
99  unsigned int nod = 0;
100 
101  FullDistancesList::const_iterator itD;
102  for ( itD = theDistances.begin(); itD != theDistances.end(); ++itD ) nod += itD->second->size();
103 
104  return nod;
105 }
106 
107 
109 {
111 }
112 
113 
114 const std::vector< Alignable* > KalmanAlignmentMetricsCalculator::alignables( void ) const
115 {
116  std::vector< Alignable* > alignables;
117  alignables.reserve( theDistances.size() );
118 
119  for ( FullDistancesList::const_iterator itL = theDistances.begin(); itL != theDistances.end(); ++itL )
120  alignables.push_back( itL->first );
121 
122  return alignables;
123 }
124 
125 
127 {
128  FullDistancesList::iterator itD;
129  for ( itD = dist.begin(); itD != dist.end(); ++itD ) delete itD->second;
130  dist.clear();
131 }
132 
133 
135  SingleDistancesList* otherList )
136 {
137  SingleDistancesList::iterator itThis;
138  SingleDistancesList::iterator itOther;
139 
140  // Iterate through the ordered entries (via "<") of thisList and otherList.
141  for ( itThis = thisList->begin(), itOther = otherList->begin(); itOther != otherList->end(); ++itOther )
142  {
143  // Irrelevant information.
144  if ( itOther->second >= theMaxDistance ) continue;
145 
146  // Skip these elements of thisList - no new information available for them in otherList.
147  while ( itThis != thisList->end() && itThis->first < itOther->first ) ++itThis;
148 
149  // Insert new element ...
150  if ( itThis == thisList->end() || itThis->first > itOther->first ) {
151  (*thisList)[itOther->first] = itOther->second + 1;
152  // ... or write smaller distance for existing element.
153  } else if ( itThis->second > itOther->second ) {
154  itThis->second = itOther->second + 1;
155  }
156 
157  }
158 }
159 
160 
162 {
163  FullDistancesList::iterator itOld;
164  FullDistancesList::iterator itNew;
165 
166  for ( itNew = updated.begin(); itNew != updated.end(); ++itNew )
167  {
168  itOld = theDistances.find( itNew->first );
169  delete itOld->second;
170  itOld->second = itNew->second;
171  }
172 }
173 
174 
176 {
177  FullDistancesList::iterator itOld;
178  FullDistancesList::iterator itNew;
179 
180  for ( itNew = propagated.begin(); itNew != propagated.end(); ++itNew )
181  {
182  itOld = theDistances.find( itNew->first );
183  SingleDistancesList::iterator itL;
184  for ( itL = itNew->second->begin(); itL != itNew->second->end(); ++itL )
185  insertDistance( itOld->second, itL->first, itL->second );
186  }
187 }
188 
189 
191  Alignable* alignable,
193  SingleDistancesList* newList )
194 {
195  SingleDistancesList::iterator itOld;
196  SingleDistancesList::iterator itNew;
197 
198  SingleDistancesList newConnections;
199 
200  // Distances-list newList has at least entries for the same indices as distances-list
201  // oldList. For this reason 'newList->begin()->first <= oldList->begin()->first' and
202  // hence 'itNew->first <= itOld->first' is always true in the loop below.
203  for ( itOld = oldList->begin(), itNew = newList->begin(); itNew != newList->end(); ++itNew )
204  {
205  // No entry associated to index itNew->first present in oldList. --> This is indeed a change.
206  if ( itOld == oldList->end() || itNew->first < itOld->first )
207  {
208  insertDistance( changes, itNew->first, alignable, itNew->second );
209  newConnections[itNew->first] = itNew->second;
210  // Entry associated to index itNew->first present in oldList. --> Check if it has changed.
211  } else if ( itNew->first == itOld->first ) {
212  if ( itNew->second != itOld->second ) insertDistance( changes, itNew->first, alignable, itNew->second );
213  ++itOld;
214  }
215  }
216 
217  SingleDistancesList::iterator it;
218  for ( it = newConnections.begin(); it != newConnections.end(); ++it )
219  connect( changes, newList, it->first, it->second );
220 }
221 
222 
224  Alignable* alignable, short int value )
225 {
226  SingleDistancesList::iterator itL;
227  for ( itL = connection->begin(); itL != connection->end(); ++itL )
228  {
229  if ( itL->first != alignable ) insertDistance( changes, alignable, itL->first, value + itL->second );
230  }
231 
232 }
233 
234 
236 {
237  FullDistancesList::iterator itD = dist.find( i );
238  if ( itD != dist.end() ) // Found distances-list for index i.
239  {
240  insertDistance( itD->second, j, value );
241  }
242  else // No distances-list found for value i.
243  {
245  (*newList)[j] = value;
246  dist[i] = newList;
247  }
248 }
249 
250 
252 {
253  SingleDistancesList::iterator itL = distList->find( j );
254  if ( itL != distList->end() ) { // Entry associated to index j found.
255  if ( itL->second > value ) itL->second = value;
256  } else { // No entry associated to index j found. -> Insert new entry.
257  (*distList)[j] = value;
258  }
259 }
260 
261 
263 {
264 
265 }
266 
267 
269 {
270 
271 }
272 
273 
275 {
276 
277 }
278 
279 
281 {
282 
283 }
284 
int i
Definition: DBlmapReader.cc:9
const std::vector< Alignable * > alignables(void) const
Return all known alignables.
void connect(FullDistancesList &changes, SingleDistancesList *connection, Alignable *alignable, short int value)
void insertPropagatedDistances(FullDistancesList &propagated)
Insert the &#39;propagated distances&#39; into the lists of the remaining alignables.
void insertDistance(FullDistancesList &dist, Alignable *i, Alignable *j, short int value)
void updateList(SingleDistancesList *thisList, SingleDistancesList *otherList)
short int operator()(Alignable *i, Alignable *j) const
int j
Definition: DBlmapReader.cc:9
unsigned int nDistances(void) const
Number of stored distances.
void insertUpdatedDistances(FullDistancesList &updated)
Insert changes due to the update of the lists of the current alignables.
void updateDistances(const std::vector< Alignable * > &alignables)
Update list of distances with a set Alignables.
void extractPropagatedDistances(FullDistancesList &changes, Alignable *alignable, SingleDistancesList *oldList, SingleDistancesList *newList)
Extract entries from the updated lists that need to be further propagated.
tuple filename
Definition: lut2db_cfg.py:20
const SingleDistancesList & getDistances(Alignable *i) const
void clear(void)
Clear stored distances.
std::map< Alignable *, SingleDistancesList * > FullDistancesList
std::map< Alignable *, short int > SingleDistancesList