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
102 cout << motif->GetID().Data() << " "
103 << motif->GetMotifType()->GetID() << " "
104 << motif->Dimensions().X() << " "
105 << motif->Dimensions().Y();
108 //_____________________________________________________________________________
109 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
111 /// Print the motif type.
113 cout << motifType->GetID().Data() << " "
114 << motifType->GetNofPadsX() << " "
115 << motifType->GetNofPadsY() << " ";
118 //_____________________________________________________________________________
119 void AliMpMotifMap::PrintMotifPosition(
120 const AliMpMotifPosition* motifPosition) const
122 /// Print the motif position.
124 cout << " ID " << motifPosition->GetID() << " "
125 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
126 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
127 << motifPosition->Position().Y() << ")";
130 //_____________________________________________________________________________
131 void AliMpMotifMap::PrintMotifPosition2(
132 const AliMpMotifPosition* motifPosition) const
134 /// Print the motif position.
136 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
137 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
138 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
139 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
140 << motifPosition->GetID() << " ";
143 //_____________________________________________________________________________
144 void AliMpMotifMap::PrintMotifs() const
146 /// Print all the motifs and their motif types
147 /// for all motifs in the motifs map.
150 if (fMotifs.size()) {
151 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
153 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
154 const TString& id = (*i).first;
155 cout << "Map element "
156 << setw(3) << counter++ << " "
157 << id.Data() << " " ;
158 PrintMotif((*i).second);
166 if (fMotifs.GetSize()) {
167 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
169 TExMapIter i = fMotifs.GetIterator();
171 while ( i.Next(key, value) ) {
172 TString id = fMotifs.AliMpExMap::GetString(key);
173 AliMpVMotif* motif = (AliMpVMotif*)value;
174 cout << "Map element "
175 << setw(3) << counter++ << " "
176 << id.Data() << " " ;
185 //_____________________________________________________________________________
186 void AliMpMotifMap::PrintMotifTypes() const
188 /// Print all the the motifs types and their motif dimensions
189 /// for all motif types in the motif types map.
192 if (fMotifTypes.size()) {
193 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
195 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
196 const TString& id = (*i).first;
197 cout << "Map element "
198 << setw(3) << counter++ << " "
200 PrintMotifType((*i).second);
208 if (fMotifTypes.GetSize()) {
209 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
211 TExMapIter i = fMotifTypes.GetIterator();
213 while ( i.Next(key, value) ) {
214 TString id = AliMpExMap::GetString(key);
215 AliMpMotifType* motifType = (AliMpMotifType*)value;
216 cout << "Map element "
217 << setw(3) << counter++ << " "
218 << id.Data() << " " ;
219 PrintMotifType(motifType);
227 //_____________________________________________________________________________
229 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
231 /// Fill the given array with all motif positions IDs (electronic card numbers)
232 /// defined in the map
235 ecn.Set(fMotifPositions.size());
237 MotifPositionMapIterator it;
238 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
239 AliMpMotifPosition* motifPosition = (*it).second;
240 ecn[i++] = motifPosition->GetID();
245 ecn.Set(fMotifPositions.GetSize());
246 TExMapIter it = fMotifPositions.GetIterator();
250 while ( it.Next(key, value) )
252 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
253 ecn[i] = motifPosition->GetID();
260 //_____________________________________________________________________________
261 Int_t AliMpMotifMap::CalculateNofPads() const
266 MotifPositionMapIterator it;
267 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
268 AliMpMotifPosition* motifPosition = (*it).second;
269 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
274 TExMapIter it = fMotifPositions.GetIterator();
277 while ( it.Next(key, value) ) {
278 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
279 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
286 //_____________________________________________________________________________
287 void AliMpMotifMap::PrintMotifPositions() const
289 /// Print all the the motifs positions.
292 if (fMotifPositions.size()) {
293 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
295 for (MotifPositionMapIterator i=fMotifPositions.begin();
296 i != fMotifPositions.end(); i++) {
298 cout << "Map element "
299 << setw(3) << counter++ << " ";
300 PrintMotifPosition((*i).second);
308 if (fMotifPositions.GetSize()) {
309 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
311 TExMapIter i = fMotifPositions.GetIterator();
313 while ( i.Next(key, value) ) {
314 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
315 cout << "Map element "
316 << setw(3) << counter++ << " ";
317 PrintMotifPosition(motifPosition);
325 //_____________________________________________________________________________
326 void AliMpMotifMap::PrintMotifPositions2() const
328 /// Print all the the motifs positions from the second map
329 /// (by global indices)
332 if (fMotifPositions2.size()) {
333 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
335 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
336 i != fMotifPositions2.end(); i++) {
338 cout << "Map element "
339 << setw(3) << counter++ << " ";
340 PrintMotifPosition2((*i).second);
348 if (fMotifPositions2.GetSize()) {
349 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
351 TExMapIter i = fMotifPositions2.GetIterator();
353 while ( i.Next(key, value) ) {
354 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
355 cout << "Map element "
356 << setw(3) << counter++ << " ";
357 PrintMotifPosition2(motifPosition);
369 //_____________________________________________________________________________
370 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
372 /// Add the specified motif
373 /// if the motif with this ID is not yet present.
375 AliMpVMotif* found = FindMotif(motif->GetID());
377 if (warn && found == motif)
378 AliWarningStream() << "The motif is already in map." << endl;
380 if (warn && found != motif) {
382 << "Another motif with the same ID is already in map." << endl;
388 fMotifs[motif->GetID()] = motif;
392 fMotifs.Add(motif->GetID(), motif);
398 //_____________________________________________________________________________
399 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
401 /// Add the specified motif type
402 /// if the motif with this ID is not yet present.
404 AliMpMotifType* found = FindMotifType(motifType->GetID());
406 if (warn && found == motifType)
407 AliWarningStream() << "The motif type is already in map." << endl;
409 if (warn && found != motifType) {
411 << "Another motif type with the same ID is already in map." << endl;
417 fMotifTypes[motifType->GetID()] = motifType;
421 fMotifTypes.Add(motifType->GetID(), motifType);
427 //_____________________________________________________________________________
428 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
430 /// Add the specified motif position
431 /// if this position is not yet present.
433 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
435 if (warn && found == motifPosition) {
437 << "ID: " << motifPosition->GetID()
438 << " found: " << found
439 << " new: " << motifPosition << endl
440 << "This motif position is already in map." << endl;
443 if (warn && found != motifPosition) {
445 << "ID: " << motifPosition->GetID()
446 << " found: " << found
447 << " new: " << motifPosition << endl
448 << "Another motif position with the same ID is already in map."
456 fMotifPositions[motifPosition->GetID()] = motifPosition;
460 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
466 //_____________________________________________________________________________
467 void AliMpMotifMap::FillMotifPositionMap2()
469 /// Fill the second map (by global indices) of motif positions.
472 if (fMotifPositions2.size() > 0 ) {
473 AliWarningStream() << "Map has been already filled." << endl;
477 for (MotifPositionMapIterator ip=fMotifPositions.begin();
478 ip != fMotifPositions.end(); ip++) {
480 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
485 if (fMotifPositions2.GetSize() > 0 ) {
486 AliWarningStream() <<"Map has been already filled." << endl;
490 TExMapIter i = fMotifPositions.GetIterator();
492 while ( i.Next(key, value) ) {
493 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
494 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
500 //_____________________________________________________________________________
501 void AliMpMotifMap::Print(const char* opt) const
503 /// Print the motifs and motif types maps.
509 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
510 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
511 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
512 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
515 //_____________________________________________________________________________
516 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
518 /// Print all the motifs positions and their global indices.
520 ofstream out(fileName, ios::out);
523 if (fMotifPositions.size()) {
524 for (MotifPositionMapIterator i=fMotifPositions.begin();
525 i != fMotifPositions.end(); i++) {
527 AliMpMotifPosition* motifPosition = (*i).second;
528 out << setw(5) << motifPosition->GetID() << " "
529 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
530 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
538 if (fMotifPositions.GetSize()) {
539 TExMapIter i = fMotifPositions.GetIterator();
541 while ( i.Next(key, value) ) {
542 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
543 out << setw(5) << motifPosition->GetID() << " "
544 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
545 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
553 //_____________________________________________________________________________
554 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
556 /// Updates the motifs positions global indices
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 /// Finds 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 /// Finds 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.");