6 // Class describing the motif map container, where motifs are
7 // mapped to their string IDs.
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
11 #include <Riostream.h>
13 #include "AliMpMotifMap.h"
14 #include "AliMpVMotif.h"
15 #include "AliMpMotif.h"
16 #include "AliMpMotifSpecial.h"
17 #include "AliMpMotifType.h"
18 #include "AliMpMotifPosition.h"
20 ClassImp(AliMpMotifMap)
22 //_____________________________________________________________________________
23 AliMpMotifMap::AliMpMotifMap()
29 //_____________________________________________________________________________
30 AliMpMotifMap::~AliMpMotifMap() {
33 // Delete all registered motifs, motif types, motif positions
35 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
39 for (MotifTypeMapIterator it=fMotifTypes.begin();
40 it != fMotifTypes.end(); it++) {
44 for (MotifPositionMapIterator ip=fMotifPositions.begin();
45 ip != fMotifPositions.end(); ip++) {
54 //_____________________________________________________________________________
55 void AliMpMotifMap::PrintMotifs() const
57 // Prints all the motifs and their motif types
58 // for all motifs in the motifs map.
62 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
64 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
65 const TString& id = (*i).first;
66 AliMpVMotif* motif = (*i).second;
67 cout << "Map element "
68 << setw(3) << counter++ << " "
70 << motif->GetID().Data() << " "
71 << motif->GetMotifType()->GetID() << " "
72 << motif->Dimensions().X() << " "
73 << motif->Dimensions().Y()
80 //_____________________________________________________________________________
81 void AliMpMotifMap::PrintMotifTypes() const
83 // Prints all the the motifs types and their motif dimensions
84 // for all motif types in the motif types map.
87 if (fMotifTypes.size()) {
88 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
90 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
91 const TString& id = (*i).first;
92 AliMpMotifType* motifType = (*i).second;
93 cout << "Map element "
94 << setw(3) << counter++ << " "
96 << motifType->GetID().Data() << " "
97 << motifType->GetNofPadsX() << " "
98 << motifType->GetNofPadsY() << " "
105 //_____________________________________________________________________________
106 void AliMpMotifMap::PrintMotifPositions() const
108 // Prints all the the motifs positions.
111 if (fMotifPositions.size()) {
112 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
114 for (MotifPositionMapIterator i=fMotifPositions.begin();
115 i != fMotifPositions.end(); i++) {
117 AliMpMotifPosition* motifPosition = (*i).second;
118 cout << "Map element "
119 << setw(3) << counter++ << " "
120 << motifPosition->GetID() << " "
121 << motifPosition->GetMotif()->GetID() << " "
122 << motifPosition->Position().X() << " "
123 << motifPosition->Position().Y() << " "
130 //_____________________________________________________________________________
131 void AliMpMotifMap::PrintMotifPositions2() const
133 // Prints all the the motifs positions from the second map
134 // (by global indices)
137 if (fMotifPositions2.size()) {
138 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
140 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
141 i != fMotifPositions2.end(); i++) {
143 AliMpMotifPosition* motifPosition = (*i).second;
144 cout << "Map element "
145 << setw(3) << counter++ << " "
146 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
147 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
148 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
149 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
150 << motifPosition->GetID() << " "
161 //_____________________________________________________________________________
162 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
164 // Adds the specified motif
165 // if the motif with this ID is not yet present.
168 AliMpVMotif* found = FindMotif(motif->GetID());
170 if (warn && found == motif)
171 Warning("AddMotif", "The motif is already in map.");
172 if (warn && found != motif)
173 Warning("AddMotif", "Another motif with the same ID is already in map.");
177 fMotifs[motif->GetID()] = motif;
181 //_____________________________________________________________________________
182 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
184 // Adds the specified motif type
185 // if the motif with this ID is not yet present.
188 AliMpMotifType* found = FindMotifType(motifType->GetID());
190 if (warn && found == motifType)
191 Warning("AddMotifType", "The motif type is already in map.");
192 if (warn && found != motifType)
193 Warning("AddMotifType",
194 "Another motif type with the same ID is already in map.");
198 fMotifTypes[motifType->GetID()] = motifType;
202 //_____________________________________________________________________________
203 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
205 // Adds the specified motif position
206 // if this position is not yet present.
209 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
211 if (warn && found == motifPosition)
212 Warning("AddMotifPosition", "This motif position is already in map.");
213 if (warn && found != motifPosition)
214 Warning("AddMotifposition",
215 "Another motif position with the same ID is already in map.");
219 fMotifPositions[motifPosition->GetID()] = motifPosition;
223 //_____________________________________________________________________________
224 void AliMpMotifMap::FillMotifPositionMap2()
226 // Fills the second map (by global indices) of motif positions.
229 if (fMotifPositions2.size() > 0 ) {
230 Warning("FillMotifPositionMap2", "Map has been already filled.");
234 for (MotifPositionMapIterator ip=fMotifPositions.begin();
235 ip != fMotifPositions.end(); ip++) {
237 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
242 //_____________________________________________________________________________
243 void AliMpMotifMap::Print() const
245 // Prints the motifs and motif types maps.
250 PrintMotifPositions();
251 PrintMotifPositions2();
254 //_____________________________________________________________________________
255 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
257 // Prints all the motifs positions and their global indices.
260 ofstream out(fileName, ios::out);
262 if (fMotifPositions.size()) {
263 for (MotifPositionMapIterator i=fMotifPositions.begin();
264 i != fMotifPositions.end(); i++) {
266 AliMpMotifPosition* motifPosition = (*i).second;
267 out << setw(5) << motifPosition->GetID() << " "
268 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
269 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
276 //_____________________________________________________________________________
277 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
279 // Updates the motifs positions global indices
283 ifstream in(fileName, ios::in);
285 Int_t motifPositionId, offx, offy;
288 in >> motifPositionId >> offx >> offy;
291 FillMotifPositionMap2();
295 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
298 cout << "Processing "
299 << motifPosition->GetID() << " " << offx << " " << offy << endl;
301 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
304 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
307 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
309 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
312 cerr <<"Motif position " << motifPositionId << endl;
313 Warning("UpdateGlobalIndices", "Motif position not found !!!");
320 //_____________________________________________________________________________
321 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
323 // Finds the motif with the specified ID.
326 MotifMapIterator i = fMotifs.find(motifID);
328 if (i != fMotifs.end())
334 //_____________________________________________________________________________
335 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
336 const TString& motifTypeID,
337 TVector2 padDimensions ) const
339 // Finds the motif with the specified ID and returns it
340 // only if its motif type and motif dimensions agree
341 // with the given motifTypeID and motifDimensions.
342 // Disagreement causes fatal error.
345 AliMpVMotif* motif = FindMotif(motifID);
347 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
349 "Motif has been already defined with a different type.");
353 // check pad dimension in case of a normal motif
355 dynamic_cast<AliMpMotif*>(motif) &&
356 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
357 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
359 Fatal("FindMotifType",
360 "Motif type has been already defined with different dimensions.");
365 // check case of a special motif
367 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
368 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
370 Fatal("FindMotifType",
371 "Motif type has been already defined with different dimensions.");
379 //_____________________________________________________________________________
380 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
382 // Finds the motif type with the specified motif type ID.
385 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
387 if (i != fMotifTypes.end())
393 //_____________________________________________________________________________
394 AliMpMotifPosition* AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
396 // Finds the motif position with the specified motif position ID.
399 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
401 if (i != fMotifPositions.end())
407 //_____________________________________________________________________________
408 AliMpMotifPosition* AliMpMotifMap::FindMotifPosition(AliMpIntPair indices) const
410 // Finds the last motif position which has the global indices (low limit)
411 // less then the indices specified.
414 MotifPositionMap2Iterator found
415 = fMotifPositions2.lower_bound(indices);
417 if (found == fMotifPositions2.end()) found--;
419 MotifPositionMap2Iterator i=found;
421 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
422 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
424 if ( indices.GetFirst() >= low.GetFirst() &&
425 indices.GetSecond() >= low.GetSecond() &&
426 indices.GetFirst() <= up.GetFirst() &&
427 indices.GetSecond() <= up.GetSecond())
431 while ( i-- != fMotifPositions2.begin());