1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // $MpId: AliMpMotifMap.cxx,v 1.16 2006/05/24 13:58:41 ivana Exp $
19 // -------------------
20 // Class AliMpMotifMap
21 // -------------------
22 // Class describing the motif map container, where motifs are
23 // mapped to their string IDs.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 #include "AliMpMotifMap.h"
28 #include "AliMpVMotif.h"
29 #include "AliMpMotif.h"
30 #include "AliMpMotifSpecial.h"
31 #include "AliMpMotifType.h"
32 #include "AliMpMotifPosition.h"
36 #include <Riostream.h>
41 ClassImp(AliMpMotifMap)
44 //_____________________________________________________________________________
45 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/)
50 fMotifPositions(true),
51 fMotifPositions2(true)
54 /// Standard constructor
56 //fMotifPositions2.SetOwner(false);
59 //_____________________________________________________________________________
60 AliMpMotifMap::AliMpMotifMap()
67 /// Default constructor
70 //_____________________________________________________________________________
71 AliMpMotifMap::~AliMpMotifMap()
75 // Delete all registered motifs, motif types, motif positions
78 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
82 for (MotifTypeMapIterator it=fMotifTypes.begin();
83 it != fMotifTypes.end(); it++) {
87 for (MotifPositionMapIterator ip=fMotifPositions.begin();
88 ip != fMotifPositions.end(); ip++) {
98 //_____________________________________________________________________________
99 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
103 cout << motif->GetID().Data() << " "
104 << motif->GetMotifType()->GetID() << " "
105 << motif->Dimensions().X() << " "
106 << motif->Dimensions().Y();
109 //_____________________________________________________________________________
110 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
112 /// Print the motif type.
114 cout << motifType->GetID().Data() << " "
115 << motifType->GetNofPadsX() << " "
116 << motifType->GetNofPadsY() << " ";
119 //_____________________________________________________________________________
120 void AliMpMotifMap::PrintMotifPosition(
121 const AliMpMotifPosition* motifPosition) const
123 /// Print the motif position.
125 cout << " ID " << motifPosition->GetID() << " "
126 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
127 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
128 << motifPosition->Position().Y() << ")";
131 //_____________________________________________________________________________
132 void AliMpMotifMap::PrintMotifPosition2(
133 const AliMpMotifPosition* motifPosition) const
135 /// Print the motif position.
137 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
138 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
139 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
140 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
141 << motifPosition->GetID() << " ";
144 //_____________________________________________________________________________
145 void AliMpMotifMap::PrintMotifs() const
147 /// Print all the motifs and their motif types
148 /// for all motifs in the motifs map.
151 if (fMotifs.size()) {
152 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
154 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
155 const TString& id = (*i).first;
156 cout << "Map element "
157 << setw(3) << counter++ << " "
158 << id.Data() << " " ;
159 PrintMotif((*i).second);
167 if (fMotifs.GetSize()) {
168 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
170 TExMapIter i = fMotifs.GetIterator();
172 while ( i.Next(key, value) ) {
173 TString id = fMotifs.AliMpExMap::GetString(key);
174 AliMpVMotif* motif = (AliMpVMotif*)value;
175 cout << "Map element "
176 << setw(3) << counter++ << " "
177 << id.Data() << " " ;
186 //_____________________________________________________________________________
187 void AliMpMotifMap::PrintMotifTypes() const
189 /// Print all the the motifs types and their motif dimensions
190 /// for all motif types in the motif types map.
193 if (fMotifTypes.size()) {
194 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
196 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
197 const TString& id = (*i).first;
198 cout << "Map element "
199 << setw(3) << counter++ << " "
201 PrintMotifType((*i).second);
209 if (fMotifTypes.GetSize()) {
210 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
212 TExMapIter i = fMotifTypes.GetIterator();
214 while ( i.Next(key, value) ) {
215 TString id = AliMpExMap::GetString(key);
216 AliMpMotifType* motifType = (AliMpMotifType*)value;
217 cout << "Map element "
218 << setw(3) << counter++ << " "
219 << id.Data() << " " ;
220 PrintMotifType(motifType);
228 //_____________________________________________________________________________
230 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
232 /// Fill the given array with all motif positions IDs (electronic card numbers)
233 /// defined in the map
236 ecn.Set(fMotifPositions.size());
238 MotifPositionMapIterator it;
239 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
240 AliMpMotifPosition* motifPosition = (*it).second;
241 ecn[i++] = motifPosition->GetID();
246 ecn.Set(fMotifPositions.GetSize());
247 TExMapIter it = fMotifPositions.GetIterator();
251 while ( it.Next(key, value) )
253 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
254 ecn[i] = motifPosition->GetID();
261 //_____________________________________________________________________________
262 Int_t AliMpMotifMap::CalculateNofPads() const
264 /// Calculate total number of pads in the map
269 MotifPositionMapIterator it;
270 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
271 AliMpMotifPosition* motifPosition = (*it).second;
272 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
277 TExMapIter it = fMotifPositions.GetIterator();
280 while ( it.Next(key, value) ) {
281 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
282 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
289 //_____________________________________________________________________________
290 void AliMpMotifMap::PrintMotifPositions() const
292 /// Print all motif positions.
295 if (fMotifPositions.size()) {
296 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
298 for (MotifPositionMapIterator i=fMotifPositions.begin();
299 i != fMotifPositions.end(); i++) {
301 cout << "Map element "
302 << setw(3) << counter++ << " ";
303 PrintMotifPosition((*i).second);
311 if (fMotifPositions.GetSize()) {
312 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
314 TExMapIter i = fMotifPositions.GetIterator();
316 while ( i.Next(key, value) ) {
317 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
318 cout << "Map element "
319 << setw(3) << counter++ << " ";
320 PrintMotifPosition(motifPosition);
328 //_____________________________________________________________________________
329 void AliMpMotifMap::PrintMotifPositions2() const
331 /// Print all motif positions from the second map
332 /// (by global indices)
335 if (fMotifPositions2.size()) {
336 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
338 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
339 i != fMotifPositions2.end(); i++) {
341 cout << "Map element "
342 << setw(3) << counter++ << " ";
343 PrintMotifPosition2((*i).second);
351 if (fMotifPositions2.GetSize()) {
352 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
354 TExMapIter i = fMotifPositions2.GetIterator();
356 while ( i.Next(key, value) ) {
357 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
358 cout << "Map element "
359 << setw(3) << counter++ << " ";
360 PrintMotifPosition2(motifPosition);
372 //_____________________________________________________________________________
373 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
375 /// Add the specified motif
376 /// if the motif with this ID is not yet present.
378 AliMpVMotif* found = FindMotif(motif->GetID());
380 if (warn && found == motif)
381 AliWarningStream() << "The motif is already in map." << endl;
383 if (warn && found != motif) {
385 << "Another motif with the same ID is already in map." << endl;
391 fMotifs[motif->GetID()] = motif;
395 fMotifs.Add(motif->GetID(), motif);
401 //_____________________________________________________________________________
402 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
404 /// Add the specified motif type
405 /// if the motif with this ID is not yet present.
407 AliMpMotifType* found = FindMotifType(motifType->GetID());
409 if (warn && found == motifType)
410 AliWarningStream() << "The motif type is already in map." << endl;
412 if (warn && found != motifType) {
414 << "Another motif type with the same ID is already in map." << endl;
420 fMotifTypes[motifType->GetID()] = motifType;
424 fMotifTypes.Add(motifType->GetID(), motifType);
430 //_____________________________________________________________________________
431 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
433 /// Add the specified motif position
434 /// if this position is not yet present.
436 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
438 if (warn && found == motifPosition) {
440 << "ID: " << motifPosition->GetID()
441 << " found: " << found
442 << " new: " << motifPosition << endl
443 << "This motif position is already in map." << endl;
446 if (warn && found != motifPosition) {
448 << "ID: " << motifPosition->GetID()
449 << " found: " << found
450 << " new: " << motifPosition << endl
451 << "Another motif position with the same ID is already in map."
459 fMotifPositions[motifPosition->GetID()] = motifPosition;
463 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
469 //_____________________________________________________________________________
470 void AliMpMotifMap::FillMotifPositionMap2()
472 /// Fill the second map (by global indices) of motif positions.
475 if (fMotifPositions2.size() > 0 ) {
476 AliWarningStream() << "Map has been already filled." << endl;
480 for (MotifPositionMapIterator ip=fMotifPositions.begin();
481 ip != fMotifPositions.end(); ip++) {
483 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
488 if (fMotifPositions2.GetSize() > 0 ) {
489 AliWarningStream() <<"Map has been already filled." << endl;
493 TExMapIter i = fMotifPositions.GetIterator();
495 while ( i.Next(key, value) ) {
496 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
497 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
503 //_____________________________________________________________________________
504 void AliMpMotifMap::Print(const char* opt) const
506 /// Print the motifs and motif types maps.
512 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
513 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
514 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
515 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
518 //_____________________________________________________________________________
519 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
521 /// Print all motif positions and their global indices.
523 ofstream out(fileName, ios::out);
526 if (fMotifPositions.size()) {
527 for (MotifPositionMapIterator i=fMotifPositions.begin();
528 i != fMotifPositions.end(); i++) {
530 AliMpMotifPosition* motifPosition = (*i).second;
531 out << setw(5) << motifPosition->GetID() << " "
532 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
533 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
541 if (fMotifPositions.GetSize()) {
542 TExMapIter i = fMotifPositions.GetIterator();
544 while ( i.Next(key, value) ) {
545 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
546 out << setw(5) << motifPosition->GetID() << " "
547 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
548 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
556 //_____________________________________________________________________________
557 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
559 /// Update the motif positions global indices from the file.
561 ifstream in(fileName, ios::in);
563 Int_t motifPositionId, offx, offy;
566 in >> motifPositionId >> offx >> offy;
569 FillMotifPositionMap2();
573 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
578 << motifPosition->GetID() << " " << offx << " " << offy << endl;
580 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
583 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
586 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
588 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
592 << "Motif position " << motifPositionId << " not found" << endl;
599 //_____________________________________________________________________________
600 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
602 /// Find the motif with the specified ID.
605 MotifMapIterator i = fMotifs.find(motifID);
606 if (i != fMotifs.end())
613 return (AliMpVMotif*)fMotifs.GetValue(motifID);
617 //_____________________________________________________________________________
618 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
619 const TString& motifTypeID,
620 const TVector2& padDimensions ) const
622 /// Find the motif with the specified ID and returns it
623 /// only if its motif type and motif dimensions agree
624 /// with the given motifTypeID and motifDimensions.
625 /// Disagreement causes fatal error.
627 AliMpVMotif* motif = FindMotif(motifID);
629 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
631 "Motif has been already defined with a different type.");
635 // check pad dimension in case of a normal motif
637 dynamic_cast<AliMpMotif*>(motif) &&
638 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
639 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
641 Fatal("FindMotifType",
642 "Motif type has been already defined with different dimensions.");
647 // check case of a special motif
649 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
650 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
652 Fatal("FindMotifType",
653 "Motif type has been already defined with different dimensions.");
661 //_____________________________________________________________________________
662 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
664 /// Find the motif type with the specified motif type ID.
667 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
668 if (i != fMotifTypes.end())
675 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
679 //_____________________________________________________________________________
681 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
683 /// Find the motif position with the specified motif position ID.
686 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
687 if (i != fMotifPositions.end())
694 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
699 //_____________________________________________________________________________
701 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
703 /// Find the last motif position which has the global indices (low limit)
704 /// less then the indices specified.
707 MotifPositionMap2Iterator found
708 = fMotifPositions2.lower_bound(indices);
710 if (found == fMotifPositions2.end()) found--;
712 MotifPositionMap2Iterator i=found;
714 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
715 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
717 if ( indices.GetFirst() >= low.GetFirst() &&
718 indices.GetSecond() >= low.GetSecond() &&
719 indices.GetFirst() <= up.GetFirst() &&
720 indices.GetSecond() <= up.GetSecond())
724 while ( i-- != fMotifPositions2.begin());
730 // HOW TO DO THIS WITH ROOT ????
731 // Fortunately it seems not to be used anywhere
732 Fatal("FindMotifPosition", "Difficult in Root to do this.");