6 // Class describing the motif map container, where motifs are
7 // mapped to their string IDs.
8 // Included in AliRoot: 2003/05/02
9 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
11 #include <Riostream.h>
14 #include "AliMpMotifMap.h"
15 #include "AliMpVMotif.h"
16 #include "AliMpMotif.h"
17 #include "AliMpMotifSpecial.h"
18 #include "AliMpMotifType.h"
19 #include "AliMpMotifPosition.h"
21 ClassImp(AliMpMotifMap)
24 const Int_t AliMpMotifMap::fgkSeparator = 100;
27 //_____________________________________________________________________________
28 AliMpMotifMap::AliMpMotifMap()
34 //_____________________________________________________________________________
35 AliMpMotifMap::~AliMpMotifMap() {
38 // Delete all registered motifs, motif types, motif positions
41 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
45 for (MotifTypeMapIterator it=fMotifTypes.begin();
46 it != fMotifTypes.end(); it++) {
50 for (MotifPositionMapIterator ip=fMotifPositions.begin();
51 ip != fMotifPositions.end(); ip++) {
57 MotifMapIterator im(&fMotifs);
59 while ( im.Next(mkey, mvalue) ) delete (AliMpMotif*)mvalue;
61 MotifMapIterator it(&fMotifTypes);
63 while ( it.Next(tkey, tvalue) ) delete (AliMpMotifType*)tvalue;
65 MotifMapIterator ip(&fMotifPositions);
67 while ( it.Next(pkey, pvalue) ) delete (AliMpMotifPosition*)pvalue;
76 //_____________________________________________________________________________
77 Int_t AliMpMotifMap::GetIndex(const TString& s) const
79 // Converts the TString to integer.
83 Fatal("GetIndex", "String too long.");
88 for (Int_t i=s.Length(); i>=0; --i) index = index*100 + int(s(i));
92 //______________________________________________________________________________
93 Int_t AliMpMotifMap::GetIndex(const AliMpIntPair& pair) const
95 // Converts the pair of integers to integer.
98 if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator)
99 Fatal("GetIndex", "Index out of limit.");
101 return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1;
104 //_____________________________________________________________________________
105 TString AliMpMotifMap::GetString(Int_t index) const
107 // Converts the integer index to the string.
112 Char_t c = index%100;
119 //______________________________________________________________________________
120 AliMpIntPair AliMpMotifMap::GetPair(Int_t index) const
122 // Converts the integer index to the pair of integers.
125 return AliMpIntPair((index-1)/fgkSeparator, (index-1)%fgkSeparator);
129 //_____________________________________________________________________________
130 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
135 cout << motif->GetID().Data() << " "
136 << motif->GetMotifType()->GetID() << " "
137 << motif->Dimensions().X() << " "
138 << motif->Dimensions().Y();
141 //_____________________________________________________________________________
142 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
144 // Prints the motif type.
147 cout << motifType->GetID().Data() << " "
148 << motifType->GetNofPadsX() << " "
149 << motifType->GetNofPadsY() << " ";
152 //_____________________________________________________________________________
153 void AliMpMotifMap::PrintMotifPosition(
154 const AliMpMotifPosition* motifPosition) const
156 // Prints the motif position.
159 cout << motifPosition->GetID() << " "
160 << motifPosition->GetMotif()->GetID() << " "
161 << motifPosition->Position().X() << " "
162 << motifPosition->Position().Y() << " ";
165 //_____________________________________________________________________________
166 void AliMpMotifMap::PrintMotifPosition2(
167 const AliMpMotifPosition* motifPosition) const
169 // Prints the motif position.
172 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
173 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
174 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
175 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
176 << motifPosition->GetID() << " ";
179 //_____________________________________________________________________________
180 void AliMpMotifMap::PrintMotifs() const
182 // Prints all the motifs and their motif types
183 // for all motifs in the motifs map.
187 if (fMotifs.size()) {
188 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
190 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
191 const TString& id = (*i).first;
192 cout << "Map element "
193 << setw(3) << counter++ << " "
194 << id.Data() << " " ;
195 PrintMotif((*i).second);
203 if (fMotifs.GetSize()) {
204 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
206 MotifMapIterator i(&fMotifs);
208 while ( i.Next(key, value) ) {
209 TString id = GetString(key);
210 AliMpVMotif* motif = (AliMpVMotif*)value;
211 cout << "Map element "
212 << setw(3) << counter++ << " "
213 << id.Data() << " " ;
222 //_____________________________________________________________________________
223 void AliMpMotifMap::PrintMotifTypes() const
225 // Prints all the the motifs types and their motif dimensions
226 // for all motif types in the motif types map.
230 if (fMotifTypes.size()) {
231 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
233 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
234 const TString& id = (*i).first;
235 cout << "Map element "
236 << setw(3) << counter++ << " "
238 PrintMotifType((*i).second);
246 if (fMotifTypes.GetSize()) {
247 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
249 MotifTypeMapIterator i(&fMotifTypes);
251 while ( i.Next(key, value) ) {
252 TString id = GetString(key);
253 AliMpMotifType* motifType = (AliMpMotifType*)value;
254 cout << "Map element "
255 << setw(3) << counter++ << " "
256 << id.Data() << " " ;
257 PrintMotifType(motifType);
265 //_____________________________________________________________________________
266 void AliMpMotifMap::PrintMotifPositions() const
268 // Prints all the the motifs positions.
272 if (fMotifPositions.size()) {
273 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
275 for (MotifPositionMapIterator i=fMotifPositions.begin();
276 i != fMotifPositions.end(); i++) {
278 cout << "Map element "
279 << setw(3) << counter++ << " ";
280 PrintMotifPosition((*i).second);
288 if (fMotifPositions.GetSize()) {
289 cout << "Dump of Motif Type Map - " << fMotifPositions.GetSize() << " entries:" << endl;
291 MotifPositionMapIterator i(&fMotifPositions);
293 while ( i.Next(key, value) ) {
294 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
295 cout << "Map element "
296 << setw(3) << counter++ << " ";
297 PrintMotifPosition(motifPosition);
305 //_____________________________________________________________________________
306 void AliMpMotifMap::PrintMotifPositions2() const
308 // Prints all the the motifs positions from the second map
309 // (by global indices)
313 if (fMotifPositions2.size()) {
314 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
316 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
317 i != fMotifPositions2.end(); i++) {
319 cout << "Map element "
320 << setw(3) << counter++ << " ";
321 PrintMotifPosition2((*i).second);
329 if (fMotifPositions2.GetSize()) {
330 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
332 MotifPositionMapIterator i(&fMotifPositions2);
334 while ( i.Next(key, value) ) {
335 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
336 cout << "Map element "
337 << setw(3) << counter++ << " ";
338 PrintMotifPosition2(motifPosition);
350 //_____________________________________________________________________________
351 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
353 // Adds the specified motif
354 // if the motif with this ID is not yet present.
357 AliMpVMotif* found = FindMotif(motif->GetID());
359 if (warn && found == motif)
360 Warning("AddMotif", "The motif is already in map.");
361 if (warn && found != motif)
362 Warning("AddMotif", "Another motif with the same ID is already in map.");
367 fMotifs[motif->GetID()] = motif;
371 fMotifs.Add(GetIndex(motif->GetID()), (Long_t)motif);
377 //_____________________________________________________________________________
378 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
380 // Adds the specified motif type
381 // if the motif with this ID is not yet present.
384 AliMpMotifType* found = FindMotifType(motifType->GetID());
386 if (warn && found == motifType)
387 Warning("AddMotifType", "The motif type is already in map.");
388 if (warn && found != motifType)
389 Warning("AddMotifType",
390 "Another motif type with the same ID is already in map.");
395 fMotifTypes[motifType->GetID()] = motifType;
399 fMotifTypes.Add(GetIndex(motifType->GetID()), (Long_t)motifType);
405 //_____________________________________________________________________________
406 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
408 // Adds the specified motif position
409 // if this position is not yet present.
412 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
414 if (warn && found == motifPosition) {
415 cerr << "ID: " << motifPosition->GetID()
416 << " found: " << found
417 << " new: " << motifPosition << endl;
418 Warning("AddMotifPosition", "This motif position is already in map.");
420 if (warn && found != motifPosition) {
421 cerr << "ID: " << motifPosition->GetID()
422 << " found: " << found
423 << " new: " << motifPosition << endl;
424 Warning("AddMotifposition",
425 "Another motif position with the same ID is already in map.");
431 fMotifPositions[motifPosition->GetID()] = motifPosition;
435 fMotifPositions.Add(motifPosition->GetID(), (Long_t)motifPosition);
441 //_____________________________________________________________________________
442 void AliMpMotifMap::FillMotifPositionMap2()
444 // Fills the second map (by global indices) of motif positions.
448 if (fMotifPositions2.size() > 0 ) {
449 Warning("FillMotifPositionMap2", "Map has been already filled.");
453 for (MotifPositionMapIterator ip=fMotifPositions.begin();
454 ip != fMotifPositions.end(); ip++) {
456 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
461 if (fMotifPositions2.GetSize() > 0 ) {
462 Warning("FillMotifPositionMap2", "Map has been already filled.");
466 MotifPositionMapIterator i(&fMotifPositions);
468 while ( i.Next(key, value) ) {
469 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
470 fMotifPositions2.Add(GetIndex(motifPosition->GetLowIndicesLimit()),
471 (Long_t)motifPosition);
477 //_____________________________________________________________________________
478 void AliMpMotifMap::Print(const char* /*option*/) const
480 // Prints the motifs and motif types maps.
485 PrintMotifPositions();
486 PrintMotifPositions2();
489 //_____________________________________________________________________________
490 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
492 // Prints all the motifs positions and their global indices.
495 ofstream out(fileName, ios::out);
498 if (fMotifPositions.size()) {
499 for (MotifPositionMapIterator i=fMotifPositions.begin();
500 i != fMotifPositions.end(); i++) {
502 AliMpMotifPosition* motifPosition = (*i).second;
503 out << setw(5) << motifPosition->GetID() << " "
504 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
505 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
513 if (fMotifPositions.GetSize()) {
514 MotifPositionMapIterator i(&fMotifPositions);
516 while ( i.Next(key, value) ) {
517 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
518 out << setw(5) << motifPosition->GetID() << " "
519 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
520 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
528 //_____________________________________________________________________________
529 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
531 // Updates the motifs positions global indices
535 ifstream in(fileName, ios::in);
537 Int_t motifPositionId, offx, offy;
540 in >> motifPositionId >> offx >> offy;
543 FillMotifPositionMap2();
547 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
550 cout << "Processing "
551 << motifPosition->GetID() << " " << offx << " " << offy << endl;
553 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
556 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
559 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
561 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
564 cerr <<"Motif position " << motifPositionId << endl;
565 Warning("UpdateGlobalIndices", "Motif position not found !!!");
572 //_____________________________________________________________________________
573 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
575 // Finds the motif with the specified ID.
579 MotifMapIterator i = fMotifs.find(motifID);
580 if (i != fMotifs.end())
587 Long_t value = fMotifs.GetValue(GetIndex(motifID));
589 return (AliMpVMotif*)value;
595 //_____________________________________________________________________________
596 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
597 const TString& motifTypeID,
598 const TVector2& padDimensions ) const
600 // Finds the motif with the specified ID and returns it
601 // only if its motif type and motif dimensions agree
602 // with the given motifTypeID and motifDimensions.
603 // Disagreement causes fatal error.
606 AliMpVMotif* motif = FindMotif(motifID);
608 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
610 "Motif has been already defined with a different type.");
614 // check pad dimension in case of a normal motif
616 dynamic_cast<AliMpMotif*>(motif) &&
617 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
618 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
620 Fatal("FindMotifType",
621 "Motif type has been already defined with different dimensions.");
626 // check case of a special motif
628 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
629 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
631 Fatal("FindMotifType",
632 "Motif type has been already defined with different dimensions.");
640 //_____________________________________________________________________________
641 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
643 // Finds the motif type with the specified motif type ID.
647 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
648 if (i != fMotifTypes.end())
655 Long_t value = fMotifTypes.GetValue(GetIndex(motifTypeID));
657 return (AliMpMotifType*)value;
663 //_____________________________________________________________________________
665 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
667 // Finds the motif position with the specified motif position ID.
671 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
672 if (i != fMotifPositions.end())
679 Long_t value = fMotifPositions.GetValue(motifPositionID);
681 return (AliMpMotifPosition*)value;
688 //_____________________________________________________________________________
690 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
692 // Finds the last motif position which has the global indices (low limit)
693 // less then the indices specified.
697 MotifPositionMap2Iterator found
698 = fMotifPositions2.lower_bound(indices);
700 if (found == fMotifPositions2.end()) found--;
702 MotifPositionMap2Iterator i=found;
704 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
705 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
707 if ( indices.GetFirst() >= low.GetFirst() &&
708 indices.GetSecond() >= low.GetSecond() &&
709 indices.GetFirst() <= up.GetFirst() &&
710 indices.GetSecond() <= up.GetSecond())
714 while ( i-- != fMotifPositions2.begin());
720 // HOW TO DO THIS WITH ROOT ????
721 // Fortunately it seems not to be used anywhere
722 Fatal("FindMotifPosition", "Difficult in Root to do this.");