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.10 2006/03/02 16:32:38 ivana Exp $
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
230 ecn.Set(fMotifPositions.size());
232 MotifPositionMapIterator it;
233 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
234 AliMpMotifPosition* motifPosition = (*it).second;
235 ecn[i++] = motifPosition->GetID();
240 ecn.Set(fMotifPositions.GetSize());
241 TExMapIter it = fMotifPositions.GetIterator();
245 while ( it.Next(key, value) )
247 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
248 ecn[i] = motifPosition->GetID();
255 //_____________________________________________________________________________
256 void AliMpMotifMap::PrintMotifPositions() const
258 /// Print all the the motifs positions.
261 if (fMotifPositions.size()) {
262 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
264 for (MotifPositionMapIterator i=fMotifPositions.begin();
265 i != fMotifPositions.end(); i++) {
267 cout << "Map element "
268 << setw(3) << counter++ << " ";
269 PrintMotifPosition((*i).second);
277 if (fMotifPositions.GetSize()) {
278 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
280 TExMapIter i = fMotifPositions.GetIterator();
282 while ( i.Next(key, value) ) {
283 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
284 cout << "Map element "
285 << setw(3) << counter++ << " ";
286 PrintMotifPosition(motifPosition);
294 //_____________________________________________________________________________
295 void AliMpMotifMap::PrintMotifPositions2() const
297 /// Print all the the motifs positions from the second map
298 /// (by global indices)
301 if (fMotifPositions2.size()) {
302 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
304 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
305 i != fMotifPositions2.end(); i++) {
307 cout << "Map element "
308 << setw(3) << counter++ << " ";
309 PrintMotifPosition2((*i).second);
317 if (fMotifPositions2.GetSize()) {
318 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
320 TExMapIter i = fMotifPositions2.GetIterator();
322 while ( i.Next(key, value) ) {
323 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
324 cout << "Map element "
325 << setw(3) << counter++ << " ";
326 PrintMotifPosition2(motifPosition);
338 //_____________________________________________________________________________
339 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
341 /// Add the specified motif
342 /// if the motif with this ID is not yet present.
344 AliMpVMotif* found = FindMotif(motif->GetID());
346 if (warn && found == motif)
347 Warning("AddMotif", "The motif is already in map.");
348 if (warn && found != motif)
349 Warning("AddMotif", "Another motif with the same ID is already in map.");
354 fMotifs[motif->GetID()] = motif;
358 fMotifs.Add(motif->GetID(), motif);
364 //_____________________________________________________________________________
365 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
367 /// Add the specified motif type
368 /// if the motif with this ID is not yet present.
370 AliMpMotifType* found = FindMotifType(motifType->GetID());
372 if (warn && found == motifType)
373 Warning("AddMotifType", "The motif type is already in map.");
374 if (warn && found != motifType)
375 Warning("AddMotifType",
376 "Another motif type with the same ID is already in map.");
381 fMotifTypes[motifType->GetID()] = motifType;
385 fMotifTypes.Add(motifType->GetID(), motifType);
391 //_____________________________________________________________________________
392 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
394 /// Add the specified motif position
395 /// if this position is not yet present.
397 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
399 if (warn && found == motifPosition) {
400 cerr << "ID: " << motifPosition->GetID()
401 << " found: " << found
402 << " new: " << motifPosition << endl;
403 Warning("AddMotifPosition", "This motif position is already in map.");
405 if (warn && found != motifPosition) {
406 cerr << "ID: " << motifPosition->GetID()
407 << " found: " << found
408 << " new: " << motifPosition << endl;
409 Warning("AddMotifposition",
410 "Another motif position with the same ID is already in map.");
416 fMotifPositions[motifPosition->GetID()] = motifPosition;
420 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
426 //_____________________________________________________________________________
427 void AliMpMotifMap::FillMotifPositionMap2()
429 /// Fill the second map (by global indices) of motif positions.
432 if (fMotifPositions2.size() > 0 ) {
433 Warning("FillMotifPositionMap2", "Map has been already filled.");
437 for (MotifPositionMapIterator ip=fMotifPositions.begin();
438 ip != fMotifPositions.end(); ip++) {
440 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
445 if (fMotifPositions2.GetSize() > 0 ) {
446 Warning("FillMotifPositionMap2", "Map has been already filled.");
450 TExMapIter i = fMotifPositions.GetIterator();
452 while ( i.Next(key, value) ) {
453 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
454 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
460 //_____________________________________________________________________________
461 void AliMpMotifMap::Print(const char* opt) const
463 /// Print the motifs and motif types maps.
469 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
470 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
471 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
472 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
475 //_____________________________________________________________________________
476 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
478 /// Print all the motifs positions and their global indices.
480 ofstream out(fileName, ios::out);
483 if (fMotifPositions.size()) {
484 for (MotifPositionMapIterator i=fMotifPositions.begin();
485 i != fMotifPositions.end(); i++) {
487 AliMpMotifPosition* motifPosition = (*i).second;
488 out << setw(5) << motifPosition->GetID() << " "
489 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
490 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
498 if (fMotifPositions.GetSize()) {
499 TExMapIter i = fMotifPositions.GetIterator();
501 while ( i.Next(key, value) ) {
502 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
503 out << setw(5) << motifPosition->GetID() << " "
504 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
505 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
513 //_____________________________________________________________________________
514 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
516 /// Updates the motifs positions global indices
519 ifstream in(fileName, ios::in);
521 Int_t motifPositionId, offx, offy;
524 in >> motifPositionId >> offx >> offy;
527 FillMotifPositionMap2();
531 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
534 cout << "Processing "
535 << motifPosition->GetID() << " " << offx << " " << offy << endl;
537 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
540 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
543 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
545 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
548 cerr <<"Motif position " << motifPositionId << endl;
549 Warning("UpdateGlobalIndices", "Motif position not found !!!");
556 //_____________________________________________________________________________
557 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
559 /// Finds the motif with the specified ID.
562 MotifMapIterator i = fMotifs.find(motifID);
563 if (i != fMotifs.end())
570 return (AliMpVMotif*)fMotifs.GetValue(motifID);
574 //_____________________________________________________________________________
575 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
576 const TString& motifTypeID,
577 const TVector2& padDimensions ) const
579 /// Finds the motif with the specified ID and returns it
580 /// only if its motif type and motif dimensions agree
581 /// with the given motifTypeID and motifDimensions.
582 /// Disagreement causes fatal error.
584 AliMpVMotif* motif = FindMotif(motifID);
586 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
588 "Motif has been already defined with a different type.");
592 // check pad dimension in case of a normal motif
594 dynamic_cast<AliMpMotif*>(motif) &&
595 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
596 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
598 Fatal("FindMotifType",
599 "Motif type has been already defined with different dimensions.");
604 // check case of a special motif
606 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
607 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
609 Fatal("FindMotifType",
610 "Motif type has been already defined with different dimensions.");
618 //_____________________________________________________________________________
619 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
621 /// Find the motif type with the specified motif type ID.
624 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
625 if (i != fMotifTypes.end())
632 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
636 //_____________________________________________________________________________
638 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
640 /// Find the motif position with the specified motif position ID.
643 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
644 if (i != fMotifPositions.end())
651 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
656 //_____________________________________________________________________________
658 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
660 /// Find the last motif position which has the global indices (low limit)
661 /// less then the indices specified.
664 MotifPositionMap2Iterator found
665 = fMotifPositions2.lower_bound(indices);
667 if (found == fMotifPositions2.end()) found--;
669 MotifPositionMap2Iterator i=found;
671 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
672 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
674 if ( indices.GetFirst() >= low.GetFirst() &&
675 indices.GetSecond() >= low.GetSecond() &&
676 indices.GetFirst() <= up.GetFirst() &&
677 indices.GetSecond() <= up.GetSecond())
681 while ( i-- != fMotifPositions2.begin());
687 // HOW TO DO THIS WITH ROOT ????
688 // Fortunately it seems not to be used anywhere
689 Fatal("FindMotifPosition", "Difficult in Root to do this.");