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.13 2006/03/15 10:04:36 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 <Riostream.h>
30 #include "AliMpMotifMap.h"
31 #include "AliMpVMotif.h"
32 #include "AliMpMotif.h"
33 #include "AliMpMotifSpecial.h"
34 #include "AliMpMotifType.h"
35 #include "AliMpMotifPosition.h"
38 ClassImp(AliMpMotifMap)
40 //_____________________________________________________________________________
41 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/)
46 fMotifPositions(true),
47 fMotifPositions2(true)
50 /// Standard constructor
52 //fMotifPositions2.SetOwner(false);
55 //_____________________________________________________________________________
56 AliMpMotifMap::AliMpMotifMap()
63 /// Default constructor
66 //_____________________________________________________________________________
67 AliMpMotifMap::~AliMpMotifMap()
71 // Delete all registered motifs, motif types, motif positions
74 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
78 for (MotifTypeMapIterator it=fMotifTypes.begin();
79 it != fMotifTypes.end(); it++) {
83 for (MotifPositionMapIterator ip=fMotifPositions.begin();
84 ip != fMotifPositions.end(); ip++) {
94 //_____________________________________________________________________________
95 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
100 cout << motif->GetID().Data() << " "
101 << motif->GetMotifType()->GetID() << " "
102 << motif->Dimensions().X() << " "
103 << motif->Dimensions().Y();
106 //_____________________________________________________________________________
107 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
109 /// Print the motif type.
111 cout << motifType->GetID().Data() << " "
112 << motifType->GetNofPadsX() << " "
113 << motifType->GetNofPadsY() << " ";
116 //_____________________________________________________________________________
117 void AliMpMotifMap::PrintMotifPosition(
118 const AliMpMotifPosition* motifPosition) const
120 /// Print the motif position.
122 cout << " ID " << motifPosition->GetID() << " "
123 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
124 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
125 << motifPosition->Position().Y() << ")";
128 //_____________________________________________________________________________
129 void AliMpMotifMap::PrintMotifPosition2(
130 const AliMpMotifPosition* motifPosition) const
132 /// Print the motif position.
134 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
135 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
136 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
137 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
138 << motifPosition->GetID() << " ";
141 //_____________________________________________________________________________
142 void AliMpMotifMap::PrintMotifs() const
144 /// Print all the motifs and their motif types
145 /// for all motifs in the motifs map.
148 if (fMotifs.size()) {
149 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
151 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
152 const TString& id = (*i).first;
153 cout << "Map element "
154 << setw(3) << counter++ << " "
155 << id.Data() << " " ;
156 PrintMotif((*i).second);
164 if (fMotifs.GetSize()) {
165 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
167 TExMapIter i = fMotifs.GetIterator();
169 while ( i.Next(key, value) ) {
170 TString id = fMotifs.AliMpExMap::GetString(key);
171 AliMpVMotif* motif = (AliMpVMotif*)value;
172 cout << "Map element "
173 << setw(3) << counter++ << " "
174 << id.Data() << " " ;
183 //_____________________________________________________________________________
184 void AliMpMotifMap::PrintMotifTypes() const
186 /// Print all the the motifs types and their motif dimensions
187 /// for all motif types in the motif types map.
190 if (fMotifTypes.size()) {
191 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
193 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
194 const TString& id = (*i).first;
195 cout << "Map element "
196 << setw(3) << counter++ << " "
198 PrintMotifType((*i).second);
206 if (fMotifTypes.GetSize()) {
207 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
209 TExMapIter i = fMotifTypes.GetIterator();
211 while ( i.Next(key, value) ) {
212 TString id = AliMpExMap::GetString(key);
213 AliMpMotifType* motifType = (AliMpMotifType*)value;
214 cout << "Map element "
215 << setw(3) << counter++ << " "
216 << id.Data() << " " ;
217 PrintMotifType(motifType);
225 //_____________________________________________________________________________
227 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
229 /// Fill the given array with all motif positions IDs (electronic card numbers)
230 /// defined in the map
233 ecn.Set(fMotifPositions.size());
235 MotifPositionMapIterator it;
236 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
237 AliMpMotifPosition* motifPosition = (*it).second;
238 ecn[i++] = motifPosition->GetID();
243 ecn.Set(fMotifPositions.GetSize());
244 TExMapIter it = fMotifPositions.GetIterator();
248 while ( it.Next(key, value) )
250 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
251 ecn[i] = motifPosition->GetID();
258 //_____________________________________________________________________________
259 Int_t AliMpMotifMap::CalculateNofPads() const
264 MotifPositionMapIterator it;
265 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
266 AliMpMotifPosition* motifPosition = (*it).second;
267 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
272 TExMapIter it = fMotifPositions.GetIterator();
275 while ( it.Next(key, value) ) {
276 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
277 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
284 //_____________________________________________________________________________
285 void AliMpMotifMap::PrintMotifPositions() const
287 /// Print all the the motifs positions.
290 if (fMotifPositions.size()) {
291 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
293 for (MotifPositionMapIterator i=fMotifPositions.begin();
294 i != fMotifPositions.end(); i++) {
296 cout << "Map element "
297 << setw(3) << counter++ << " ";
298 PrintMotifPosition((*i).second);
306 if (fMotifPositions.GetSize()) {
307 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
309 TExMapIter i = fMotifPositions.GetIterator();
311 while ( i.Next(key, value) ) {
312 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
313 cout << "Map element "
314 << setw(3) << counter++ << " ";
315 PrintMotifPosition(motifPosition);
323 //_____________________________________________________________________________
324 void AliMpMotifMap::PrintMotifPositions2() const
326 /// Print all the the motifs positions from the second map
327 /// (by global indices)
330 if (fMotifPositions2.size()) {
331 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
333 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
334 i != fMotifPositions2.end(); i++) {
336 cout << "Map element "
337 << setw(3) << counter++ << " ";
338 PrintMotifPosition2((*i).second);
346 if (fMotifPositions2.GetSize()) {
347 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
349 TExMapIter i = fMotifPositions2.GetIterator();
351 while ( i.Next(key, value) ) {
352 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
353 cout << "Map element "
354 << setw(3) << counter++ << " ";
355 PrintMotifPosition2(motifPosition);
367 //_____________________________________________________________________________
368 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
370 /// Add the specified motif
371 /// if the motif with this ID is not yet present.
373 AliMpVMotif* found = FindMotif(motif->GetID());
375 if (warn && found == motif)
376 Warning("AddMotif", "The motif is already in map.");
377 if (warn && found != motif)
378 Warning("AddMotif", "Another motif with the same ID is already in map.");
383 fMotifs[motif->GetID()] = motif;
387 fMotifs.Add(motif->GetID(), motif);
393 //_____________________________________________________________________________
394 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
396 /// Add the specified motif type
397 /// if the motif with this ID is not yet present.
399 AliMpMotifType* found = FindMotifType(motifType->GetID());
401 if (warn && found == motifType)
402 Warning("AddMotifType", "The motif type is already in map.");
403 if (warn && found != motifType)
404 Warning("AddMotifType",
405 "Another motif type with the same ID is already in map.");
410 fMotifTypes[motifType->GetID()] = motifType;
414 fMotifTypes.Add(motifType->GetID(), motifType);
420 //_____________________________________________________________________________
421 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
423 /// Add the specified motif position
424 /// if this position is not yet present.
426 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
428 if (warn && found == motifPosition) {
429 cerr << "ID: " << motifPosition->GetID()
430 << " found: " << found
431 << " new: " << motifPosition << endl;
432 Warning("AddMotifPosition", "This motif position is already in map.");
434 if (warn && found != motifPosition) {
435 cerr << "ID: " << motifPosition->GetID()
436 << " found: " << found
437 << " new: " << motifPosition << endl;
438 Warning("AddMotifposition",
439 "Another motif position with the same ID is already in map.");
445 fMotifPositions[motifPosition->GetID()] = motifPosition;
449 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
455 //_____________________________________________________________________________
456 void AliMpMotifMap::FillMotifPositionMap2()
458 /// Fill the second map (by global indices) of motif positions.
461 if (fMotifPositions2.size() > 0 ) {
462 Warning("FillMotifPositionMap2", "Map has been already filled.");
466 for (MotifPositionMapIterator ip=fMotifPositions.begin();
467 ip != fMotifPositions.end(); ip++) {
469 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
474 if (fMotifPositions2.GetSize() > 0 ) {
475 Warning("FillMotifPositionMap2", "Map has been already filled.");
479 TExMapIter i = fMotifPositions.GetIterator();
481 while ( i.Next(key, value) ) {
482 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
483 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
489 //_____________________________________________________________________________
490 void AliMpMotifMap::Print(const char* opt) const
492 /// Print the motifs and motif types maps.
498 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
499 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
500 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
501 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
504 //_____________________________________________________________________________
505 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
507 /// Print all the motifs positions and their global indices.
509 ofstream out(fileName, ios::out);
512 if (fMotifPositions.size()) {
513 for (MotifPositionMapIterator i=fMotifPositions.begin();
514 i != fMotifPositions.end(); i++) {
516 AliMpMotifPosition* motifPosition = (*i).second;
517 out << setw(5) << motifPosition->GetID() << " "
518 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
519 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
527 if (fMotifPositions.GetSize()) {
528 TExMapIter i = fMotifPositions.GetIterator();
530 while ( i.Next(key, value) ) {
531 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
532 out << setw(5) << motifPosition->GetID() << " "
533 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
534 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
542 //_____________________________________________________________________________
543 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
545 /// Updates the motifs positions global indices
548 ifstream in(fileName, ios::in);
550 Int_t motifPositionId, offx, offy;
553 in >> motifPositionId >> offx >> offy;
556 FillMotifPositionMap2();
560 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
563 cout << "Processing "
564 << motifPosition->GetID() << " " << offx << " " << offy << endl;
566 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
569 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
572 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
574 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
577 cerr <<"Motif position " << motifPositionId << endl;
578 Warning("UpdateGlobalIndices", "Motif position not found !!!");
585 //_____________________________________________________________________________
586 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
588 /// Finds the motif with the specified ID.
591 MotifMapIterator i = fMotifs.find(motifID);
592 if (i != fMotifs.end())
599 return (AliMpVMotif*)fMotifs.GetValue(motifID);
603 //_____________________________________________________________________________
604 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
605 const TString& motifTypeID,
606 const TVector2& padDimensions ) const
608 /// Finds the motif with the specified ID and returns it
609 /// only if its motif type and motif dimensions agree
610 /// with the given motifTypeID and motifDimensions.
611 /// Disagreement causes fatal error.
613 AliMpVMotif* motif = FindMotif(motifID);
615 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
617 "Motif has been already defined with a different type.");
621 // check pad dimension in case of a normal motif
623 dynamic_cast<AliMpMotif*>(motif) &&
624 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
625 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
627 Fatal("FindMotifType",
628 "Motif type has been already defined with different dimensions.");
633 // check case of a special motif
635 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
636 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
638 Fatal("FindMotifType",
639 "Motif type has been already defined with different dimensions.");
647 //_____________________________________________________________________________
648 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
650 /// Find the motif type with the specified motif type ID.
653 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
654 if (i != fMotifTypes.end())
661 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
665 //_____________________________________________________________________________
667 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
669 /// Find the motif position with the specified motif position ID.
672 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
673 if (i != fMotifPositions.end())
680 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
685 //_____________________________________________________________________________
687 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
689 /// Find the last motif position which has the global indices (low limit)
690 /// less then the indices specified.
693 MotifPositionMap2Iterator found
694 = fMotifPositions2.lower_bound(indices);
696 if (found == fMotifPositions2.end()) found--;
698 MotifPositionMap2Iterator i=found;
700 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
701 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
703 if ( indices.GetFirst() >= low.GetFirst() &&
704 indices.GetSecond() >= low.GetSecond() &&
705 indices.GetFirst() <= up.GetFirst() &&
706 indices.GetSecond() <= up.GetSecond())
710 while ( i-- != fMotifPositions2.begin());
716 // HOW TO DO THIS WITH ROOT ????
717 // Fortunately it seems not to be used anywhere
718 Fatal("FindMotifPosition", "Difficult in Root to do this.");