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.14 2006/03/17 11:38:06 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>
40 ClassImp(AliMpMotifMap)
42 //_____________________________________________________________________________
43 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/)
48 fMotifPositions(true),
49 fMotifPositions2(true)
52 /// Standard constructor
54 //fMotifPositions2.SetOwner(false);
57 //_____________________________________________________________________________
58 AliMpMotifMap::AliMpMotifMap()
65 /// Default constructor
68 //_____________________________________________________________________________
69 AliMpMotifMap::~AliMpMotifMap()
73 // Delete all registered motifs, motif types, motif positions
76 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
80 for (MotifTypeMapIterator it=fMotifTypes.begin();
81 it != fMotifTypes.end(); it++) {
85 for (MotifPositionMapIterator ip=fMotifPositions.begin();
86 ip != fMotifPositions.end(); ip++) {
96 //_____________________________________________________________________________
97 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
101 cout << motif->GetID().Data() << " "
102 << motif->GetMotifType()->GetID() << " "
103 << motif->Dimensions().X() << " "
104 << motif->Dimensions().Y();
107 //_____________________________________________________________________________
108 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
110 /// Print the motif type.
112 cout << motifType->GetID().Data() << " "
113 << motifType->GetNofPadsX() << " "
114 << motifType->GetNofPadsY() << " ";
117 //_____________________________________________________________________________
118 void AliMpMotifMap::PrintMotifPosition(
119 const AliMpMotifPosition* motifPosition) const
121 /// Print the motif position.
123 cout << " ID " << motifPosition->GetID() << " "
124 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
125 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
126 << motifPosition->Position().Y() << ")";
129 //_____________________________________________________________________________
130 void AliMpMotifMap::PrintMotifPosition2(
131 const AliMpMotifPosition* motifPosition) const
133 /// Print the motif position.
135 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
136 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
137 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
138 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
139 << motifPosition->GetID() << " ";
142 //_____________________________________________________________________________
143 void AliMpMotifMap::PrintMotifs() const
145 /// Print all the motifs and their motif types
146 /// for all motifs in the motifs map.
149 if (fMotifs.size()) {
150 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
152 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
153 const TString& id = (*i).first;
154 cout << "Map element "
155 << setw(3) << counter++ << " "
156 << id.Data() << " " ;
157 PrintMotif((*i).second);
165 if (fMotifs.GetSize()) {
166 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
168 TExMapIter i = fMotifs.GetIterator();
170 while ( i.Next(key, value) ) {
171 TString id = fMotifs.AliMpExMap::GetString(key);
172 AliMpVMotif* motif = (AliMpVMotif*)value;
173 cout << "Map element "
174 << setw(3) << counter++ << " "
175 << id.Data() << " " ;
184 //_____________________________________________________________________________
185 void AliMpMotifMap::PrintMotifTypes() const
187 /// Print all the the motifs types and their motif dimensions
188 /// for all motif types in the motif types map.
191 if (fMotifTypes.size()) {
192 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
194 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
195 const TString& id = (*i).first;
196 cout << "Map element "
197 << setw(3) << counter++ << " "
199 PrintMotifType((*i).second);
207 if (fMotifTypes.GetSize()) {
208 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
210 TExMapIter i = fMotifTypes.GetIterator();
212 while ( i.Next(key, value) ) {
213 TString id = AliMpExMap::GetString(key);
214 AliMpMotifType* motifType = (AliMpMotifType*)value;
215 cout << "Map element "
216 << setw(3) << counter++ << " "
217 << id.Data() << " " ;
218 PrintMotifType(motifType);
226 //_____________________________________________________________________________
228 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
230 /// Fill the given array with all motif positions IDs (electronic card numbers)
231 /// defined in the map
234 ecn.Set(fMotifPositions.size());
236 MotifPositionMapIterator it;
237 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
238 AliMpMotifPosition* motifPosition = (*it).second;
239 ecn[i++] = motifPosition->GetID();
244 ecn.Set(fMotifPositions.GetSize());
245 TExMapIter it = fMotifPositions.GetIterator();
249 while ( it.Next(key, value) )
251 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
252 ecn[i] = motifPosition->GetID();
259 //_____________________________________________________________________________
260 Int_t AliMpMotifMap::CalculateNofPads() const
262 /// Calculate total number of pads in the map
267 MotifPositionMapIterator it;
268 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
269 AliMpMotifPosition* motifPosition = (*it).second;
270 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
275 TExMapIter it = fMotifPositions.GetIterator();
278 while ( it.Next(key, value) ) {
279 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
280 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
287 //_____________________________________________________________________________
288 void AliMpMotifMap::PrintMotifPositions() const
290 /// Print all motif positions.
293 if (fMotifPositions.size()) {
294 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
296 for (MotifPositionMapIterator i=fMotifPositions.begin();
297 i != fMotifPositions.end(); i++) {
299 cout << "Map element "
300 << setw(3) << counter++ << " ";
301 PrintMotifPosition((*i).second);
309 if (fMotifPositions.GetSize()) {
310 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
312 TExMapIter i = fMotifPositions.GetIterator();
314 while ( i.Next(key, value) ) {
315 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
316 cout << "Map element "
317 << setw(3) << counter++ << " ";
318 PrintMotifPosition(motifPosition);
326 //_____________________________________________________________________________
327 void AliMpMotifMap::PrintMotifPositions2() const
329 /// Print all motif positions from the second map
330 /// (by global indices)
333 if (fMotifPositions2.size()) {
334 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
336 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
337 i != fMotifPositions2.end(); i++) {
339 cout << "Map element "
340 << setw(3) << counter++ << " ";
341 PrintMotifPosition2((*i).second);
349 if (fMotifPositions2.GetSize()) {
350 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
352 TExMapIter i = fMotifPositions2.GetIterator();
354 while ( i.Next(key, value) ) {
355 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
356 cout << "Map element "
357 << setw(3) << counter++ << " ";
358 PrintMotifPosition2(motifPosition);
370 //_____________________________________________________________________________
371 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
373 /// Add the specified motif
374 /// if the motif with this ID is not yet present.
376 AliMpVMotif* found = FindMotif(motif->GetID());
378 if (warn && found == motif)
379 AliWarningStream() << "The motif is already in map." << endl;
381 if (warn && found != motif) {
383 << "Another motif with the same ID is already in map." << endl;
389 fMotifs[motif->GetID()] = motif;
393 fMotifs.Add(motif->GetID(), motif);
399 //_____________________________________________________________________________
400 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
402 /// Add the specified motif type
403 /// if the motif with this ID is not yet present.
405 AliMpMotifType* found = FindMotifType(motifType->GetID());
407 if (warn && found == motifType)
408 AliWarningStream() << "The motif type is already in map." << endl;
410 if (warn && found != motifType) {
412 << "Another motif type with the same ID is already in map." << endl;
418 fMotifTypes[motifType->GetID()] = motifType;
422 fMotifTypes.Add(motifType->GetID(), motifType);
428 //_____________________________________________________________________________
429 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
431 /// Add the specified motif position
432 /// if this position is not yet present.
434 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
436 if (warn && found == motifPosition) {
438 << "ID: " << motifPosition->GetID()
439 << " found: " << found
440 << " new: " << motifPosition << endl
441 << "This motif position is already in map." << endl;
444 if (warn && found != motifPosition) {
446 << "ID: " << motifPosition->GetID()
447 << " found: " << found
448 << " new: " << motifPosition << endl
449 << "Another motif position with the same ID is already in map."
457 fMotifPositions[motifPosition->GetID()] = motifPosition;
461 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
467 //_____________________________________________________________________________
468 void AliMpMotifMap::FillMotifPositionMap2()
470 /// Fill the second map (by global indices) of motif positions.
473 if (fMotifPositions2.size() > 0 ) {
474 AliWarningStream() << "Map has been already filled." << endl;
478 for (MotifPositionMapIterator ip=fMotifPositions.begin();
479 ip != fMotifPositions.end(); ip++) {
481 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
486 if (fMotifPositions2.GetSize() > 0 ) {
487 AliWarningStream() <<"Map has been already filled." << endl;
491 TExMapIter i = fMotifPositions.GetIterator();
493 while ( i.Next(key, value) ) {
494 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
495 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
501 //_____________________________________________________________________________
502 void AliMpMotifMap::Print(const char* opt) const
504 /// Print the motifs and motif types maps.
510 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
511 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
512 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
513 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
516 //_____________________________________________________________________________
517 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
519 /// Print all motif positions and their global indices.
521 ofstream out(fileName, ios::out);
524 if (fMotifPositions.size()) {
525 for (MotifPositionMapIterator i=fMotifPositions.begin();
526 i != fMotifPositions.end(); i++) {
528 AliMpMotifPosition* motifPosition = (*i).second;
529 out << setw(5) << motifPosition->GetID() << " "
530 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
531 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
539 if (fMotifPositions.GetSize()) {
540 TExMapIter i = fMotifPositions.GetIterator();
542 while ( i.Next(key, value) ) {
543 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
544 out << setw(5) << motifPosition->GetID() << " "
545 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
546 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
554 //_____________________________________________________________________________
555 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
557 /// Update the motif positions global indices from the file.
559 ifstream in(fileName, ios::in);
561 Int_t motifPositionId, offx, offy;
564 in >> motifPositionId >> offx >> offy;
567 FillMotifPositionMap2();
571 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
576 << motifPosition->GetID() << " " << offx << " " << offy << endl;
578 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
581 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
584 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
586 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
590 << "Motif position " << motifPositionId << " not found" << endl;
597 //_____________________________________________________________________________
598 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
600 /// Find the motif with the specified ID.
603 MotifMapIterator i = fMotifs.find(motifID);
604 if (i != fMotifs.end())
611 return (AliMpVMotif*)fMotifs.GetValue(motifID);
615 //_____________________________________________________________________________
616 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
617 const TString& motifTypeID,
618 const TVector2& padDimensions ) const
620 /// Find the motif with the specified ID and returns it
621 /// only if its motif type and motif dimensions agree
622 /// with the given motifTypeID and motifDimensions.
623 /// Disagreement causes fatal error.
625 AliMpVMotif* motif = FindMotif(motifID);
627 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
629 "Motif has been already defined with a different type.");
633 // check pad dimension in case of a normal motif
635 dynamic_cast<AliMpMotif*>(motif) &&
636 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
637 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
639 Fatal("FindMotifType",
640 "Motif type has been already defined with different dimensions.");
645 // check case of a special motif
647 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
648 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
650 Fatal("FindMotifType",
651 "Motif type has been already defined with different dimensions.");
659 //_____________________________________________________________________________
660 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
662 /// Find the motif type with the specified motif type ID.
665 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
666 if (i != fMotifTypes.end())
673 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
677 //_____________________________________________________________________________
679 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
681 /// Find the motif position with the specified motif position ID.
684 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
685 if (i != fMotifPositions.end())
692 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
697 //_____________________________________________________________________________
699 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
701 /// Find the last motif position which has the global indices (low limit)
702 /// less then the indices specified.
705 MotifPositionMap2Iterator found
706 = fMotifPositions2.lower_bound(indices);
708 if (found == fMotifPositions2.end()) found--;
710 MotifPositionMap2Iterator i=found;
712 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
713 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
715 if ( indices.GetFirst() >= low.GetFirst() &&
716 indices.GetSecond() >= low.GetSecond() &&
717 indices.GetFirst() <= up.GetFirst() &&
718 indices.GetSecond() <= up.GetSecond())
722 while ( i-- != fMotifPositions2.begin());
728 // HOW TO DO THIS WITH ROOT ????
729 // Fortunately it seems not to be used anywhere
730 Fatal("FindMotifPosition", "Difficult in Root to do this.");