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.9 2005/09/26 16:11:20 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"
37 ClassImp(AliMpMotifMap)
39 //_____________________________________________________________________________
40 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/)
45 fMotifPositions(true),
46 fMotifPositions2(true)
49 /// Standard constructor
51 //fMotifPositions2.SetOwner(false);
54 //_____________________________________________________________________________
55 AliMpMotifMap::AliMpMotifMap()
62 /// Default constructor
65 //_____________________________________________________________________________
66 AliMpMotifMap::~AliMpMotifMap()
70 // Delete all registered motifs, motif types, motif positions
73 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
77 for (MotifTypeMapIterator it=fMotifTypes.begin();
78 it != fMotifTypes.end(); it++) {
82 for (MotifPositionMapIterator ip=fMotifPositions.begin();
83 ip != fMotifPositions.end(); ip++) {
93 //_____________________________________________________________________________
94 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
99 cout << motif->GetID().Data() << " "
100 << motif->GetMotifType()->GetID() << " "
101 << motif->Dimensions().X() << " "
102 << motif->Dimensions().Y();
105 //_____________________________________________________________________________
106 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
108 /// Print the motif type.
110 cout << motifType->GetID().Data() << " "
111 << motifType->GetNofPadsX() << " "
112 << motifType->GetNofPadsY() << " ";
115 //_____________________________________________________________________________
116 void AliMpMotifMap::PrintMotifPosition(
117 const AliMpMotifPosition* motifPosition) const
119 /// Print the motif position.
121 cout << motifPosition->GetID() << " "
122 << motifPosition->GetMotif()->GetID() << " "
123 << motifPosition->Position().X() << " "
124 << motifPosition->Position().Y() << " ";
127 //_____________________________________________________________________________
128 void AliMpMotifMap::PrintMotifPosition2(
129 const AliMpMotifPosition* motifPosition) const
131 /// Print the motif position.
133 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
134 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
135 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
136 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
137 << motifPosition->GetID() << " ";
140 //_____________________________________________________________________________
141 void AliMpMotifMap::PrintMotifs() const
143 /// Print all the motifs and their motif types
144 /// for all motifs in the motifs map.
147 if (fMotifs.size()) {
148 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
150 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
151 const TString& id = (*i).first;
152 cout << "Map element "
153 << setw(3) << counter++ << " "
154 << id.Data() << " " ;
155 PrintMotif((*i).second);
163 if (fMotifs.GetSize()) {
164 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
166 TExMapIter i = fMotifs.GetIterator();
168 while ( i.Next(key, value) ) {
169 TString id = fMotifs.AliMpExMap::GetString(key);
170 AliMpVMotif* motif = (AliMpVMotif*)value;
171 cout << "Map element "
172 << setw(3) << counter++ << " "
173 << id.Data() << " " ;
182 //_____________________________________________________________________________
183 void AliMpMotifMap::PrintMotifTypes() const
185 /// Print all the the motifs types and their motif dimensions
186 /// for all motif types in the motif types map.
189 if (fMotifTypes.size()) {
190 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
192 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
193 const TString& id = (*i).first;
194 cout << "Map element "
195 << setw(3) << counter++ << " "
197 PrintMotifType((*i).second);
205 if (fMotifTypes.GetSize()) {
206 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
208 TExMapIter i = fMotifTypes.GetIterator();
210 while ( i.Next(key, value) ) {
211 TString id = AliMpExMap::GetString(key);
212 AliMpMotifType* motifType = (AliMpMotifType*)value;
213 cout << "Map element "
214 << setw(3) << counter++ << " "
215 << id.Data() << " " ;
216 PrintMotifType(motifType);
224 //_____________________________________________________________________________
225 void AliMpMotifMap::PrintMotifPositions() const
227 /// Print all the the motifs positions.
230 if (fMotifPositions.size()) {
231 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
233 for (MotifPositionMapIterator i=fMotifPositions.begin();
234 i != fMotifPositions.end(); i++) {
236 cout << "Map element "
237 << setw(3) << counter++ << " ";
238 PrintMotifPosition((*i).second);
246 if (fMotifPositions.GetSize()) {
247 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
249 TExMapIter i = fMotifPositions.GetIterator();
251 while ( i.Next(key, value) ) {
252 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
253 cout << "Map element "
254 << setw(3) << counter++ << " ";
255 PrintMotifPosition(motifPosition);
263 //_____________________________________________________________________________
264 void AliMpMotifMap::PrintMotifPositions2() const
266 /// Print all the the motifs positions from the second map
267 /// (by global indices)
270 if (fMotifPositions2.size()) {
271 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
273 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
274 i != fMotifPositions2.end(); i++) {
276 cout << "Map element "
277 << setw(3) << counter++ << " ";
278 PrintMotifPosition2((*i).second);
286 if (fMotifPositions2.GetSize()) {
287 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
289 TExMapIter i = fMotifPositions2.GetIterator();
291 while ( i.Next(key, value) ) {
292 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
293 cout << "Map element "
294 << setw(3) << counter++ << " ";
295 PrintMotifPosition2(motifPosition);
307 //_____________________________________________________________________________
308 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
310 /// Add the specified motif
311 /// if the motif with this ID is not yet present.
313 AliMpVMotif* found = FindMotif(motif->GetID());
315 if (warn && found == motif)
316 Warning("AddMotif", "The motif is already in map.");
317 if (warn && found != motif)
318 Warning("AddMotif", "Another motif with the same ID is already in map.");
323 fMotifs[motif->GetID()] = motif;
327 fMotifs.Add(motif->GetID(), motif);
333 //_____________________________________________________________________________
334 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
336 /// Add the specified motif type
337 /// if the motif with this ID is not yet present.
339 AliMpMotifType* found = FindMotifType(motifType->GetID());
341 if (warn && found == motifType)
342 Warning("AddMotifType", "The motif type is already in map.");
343 if (warn && found != motifType)
344 Warning("AddMotifType",
345 "Another motif type with the same ID is already in map.");
350 fMotifTypes[motifType->GetID()] = motifType;
354 fMotifTypes.Add(motifType->GetID(), motifType);
360 //_____________________________________________________________________________
361 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
363 /// Add the specified motif position
364 /// if this position is not yet present.
366 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
368 if (warn && found == motifPosition) {
369 cerr << "ID: " << motifPosition->GetID()
370 << " found: " << found
371 << " new: " << motifPosition << endl;
372 Warning("AddMotifPosition", "This motif position is already in map.");
374 if (warn && found != motifPosition) {
375 cerr << "ID: " << motifPosition->GetID()
376 << " found: " << found
377 << " new: " << motifPosition << endl;
378 Warning("AddMotifposition",
379 "Another motif position with the same ID is already in map.");
385 fMotifPositions[motifPosition->GetID()] = motifPosition;
389 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
395 //_____________________________________________________________________________
396 void AliMpMotifMap::FillMotifPositionMap2()
398 /// Fill the second map (by global indices) of motif positions.
401 if (fMotifPositions2.size() > 0 ) {
402 Warning("FillMotifPositionMap2", "Map has been already filled.");
406 for (MotifPositionMapIterator ip=fMotifPositions.begin();
407 ip != fMotifPositions.end(); ip++) {
409 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
414 if (fMotifPositions2.GetSize() > 0 ) {
415 Warning("FillMotifPositionMap2", "Map has been already filled.");
419 TExMapIter i = fMotifPositions.GetIterator();
421 while ( i.Next(key, value) ) {
422 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
423 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
429 //_____________________________________________________________________________
430 void AliMpMotifMap::Print(const char* /*option*/) const
432 /// Print the motifs and motif types maps.
436 PrintMotifPositions();
437 PrintMotifPositions2();
440 //_____________________________________________________________________________
441 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
443 /// Print all the motifs positions and their global indices.
445 ofstream out(fileName, ios::out);
448 if (fMotifPositions.size()) {
449 for (MotifPositionMapIterator i=fMotifPositions.begin();
450 i != fMotifPositions.end(); i++) {
452 AliMpMotifPosition* motifPosition = (*i).second;
453 out << setw(5) << motifPosition->GetID() << " "
454 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
455 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
463 if (fMotifPositions.GetSize()) {
464 TExMapIter i = fMotifPositions.GetIterator();
466 while ( i.Next(key, value) ) {
467 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
468 out << setw(5) << motifPosition->GetID() << " "
469 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
470 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
478 //_____________________________________________________________________________
479 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
481 /// Updates the motifs positions global indices
484 ifstream in(fileName, ios::in);
486 Int_t motifPositionId, offx, offy;
489 in >> motifPositionId >> offx >> offy;
492 FillMotifPositionMap2();
496 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
499 cout << "Processing "
500 << motifPosition->GetID() << " " << offx << " " << offy << endl;
502 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
505 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
508 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
510 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
513 cerr <<"Motif position " << motifPositionId << endl;
514 Warning("UpdateGlobalIndices", "Motif position not found !!!");
521 //_____________________________________________________________________________
522 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
524 /// Finds the motif with the specified ID.
527 MotifMapIterator i = fMotifs.find(motifID);
528 if (i != fMotifs.end())
535 return (AliMpVMotif*)fMotifs.GetValue(motifID);
539 //_____________________________________________________________________________
540 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
541 const TString& motifTypeID,
542 const TVector2& padDimensions ) const
544 /// Finds the motif with the specified ID and returns it
545 /// only if its motif type and motif dimensions agree
546 /// with the given motifTypeID and motifDimensions.
547 /// Disagreement causes fatal error.
549 AliMpVMotif* motif = FindMotif(motifID);
551 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
553 "Motif has been already defined with a different type.");
557 // check pad dimension in case of a normal motif
559 dynamic_cast<AliMpMotif*>(motif) &&
560 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
561 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
563 Fatal("FindMotifType",
564 "Motif type has been already defined with different dimensions.");
569 // check case of a special motif
571 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
572 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
574 Fatal("FindMotifType",
575 "Motif type has been already defined with different dimensions.");
583 //_____________________________________________________________________________
584 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
586 /// Find the motif type with the specified motif type ID.
589 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
590 if (i != fMotifTypes.end())
597 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
601 //_____________________________________________________________________________
603 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
605 /// Find the motif position with the specified motif position ID.
608 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
609 if (i != fMotifPositions.end())
616 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
621 //_____________________________________________________________________________
623 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
625 /// Find the last motif position which has the global indices (low limit)
626 /// less then the indices specified.
629 MotifPositionMap2Iterator found
630 = fMotifPositions2.lower_bound(indices);
632 if (found == fMotifPositions2.end()) found--;
634 MotifPositionMap2Iterator i=found;
636 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
637 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
639 if ( indices.GetFirst() >= low.GetFirst() &&
640 indices.GetSecond() >= low.GetSecond() &&
641 indices.GetFirst() <= up.GetFirst() &&
642 indices.GetSecond() <= up.GetSecond())
646 while ( i-- != fMotifPositions2.begin());
652 // HOW TO DO THIS WITH ROOT ????
653 // Fortunately it seems not to be used anywhere
654 Fatal("FindMotifPosition", "Difficult in Root to do this.");