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.16 2006/05/24 13:58:41 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>
41 ClassImp(AliMpMotifMap)
44 //_____________________________________________________________________________
45 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/)
50 fMotifPositions(true),
51 fMotifPositions2(true)
54 /// Standard constructor
56 //fMotifPositions2.SetOwner(false);
59 //_____________________________________________________________________________
60 AliMpMotifMap::AliMpMotifMap()
67 /// Default constructor
70 //_____________________________________________________________________________
71 AliMpMotifMap::~AliMpMotifMap()
75 // Delete all registered motifs, motif types, motif positions
78 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
82 for (MotifTypeMapIterator it=fMotifTypes.begin();
83 it != fMotifTypes.end(); it++) {
87 for (MotifPositionMapIterator ip=fMotifPositions.begin();
88 ip != fMotifPositions.end(); ip++) {
98 //_____________________________________________________________________________
99 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
103 cout << motif->GetID().Data() << " "
104 << motif->GetMotifType()->GetID() << " "
105 << motif->Dimensions().X() << " "
106 << motif->Dimensions().Y();
109 //_____________________________________________________________________________
110 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
112 /// Print the motif type.
114 cout << motifType->GetID().Data() << " "
115 << motifType->GetNofPadsX() << " "
116 << motifType->GetNofPadsY() << " ";
119 //_____________________________________________________________________________
120 void AliMpMotifMap::PrintMotifPosition(
121 const AliMpMotifPosition* motifPosition) const
123 /// Print the motif position.
125 cout << " ID " << motifPosition->GetID() << " "
126 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
127 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
128 << motifPosition->Position().Y() << ")";
131 //_____________________________________________________________________________
132 void AliMpMotifMap::PrintMotifPosition2(
133 const AliMpMotifPosition* motifPosition) const
135 /// Print the motif position.
137 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
138 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
139 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
140 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
141 << motifPosition->GetID() << " ";
144 //_____________________________________________________________________________
145 void AliMpMotifMap::PrintMotifs() const
147 /// Print all the motifs and their motif types
148 /// for all motifs in the motifs map.
151 if (fMotifs.size()) {
152 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
154 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
155 const TString& id = (*i).first;
156 cout << "Map element "
157 << setw(3) << counter++ << " "
158 << id.Data() << " " ;
159 PrintMotif((*i).second);
167 if (fMotifs.GetSize()) {
168 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
170 TExMapIter i = fMotifs.GetIterator();
172 while ( i.Next(key, value) ) {
173 TString id = fMotifs.AliMpExMap::GetString(key);
174 AliMpVMotif* motif = (AliMpVMotif*)value;
175 cout << "Map element "
176 << setw(3) << counter++ << " "
177 << id.Data() << " " ;
186 //_____________________________________________________________________________
187 void AliMpMotifMap::PrintMotifTypes() const
189 /// Print all the the motifs types and their motif dimensions
190 /// for all motif types in the motif types map.
193 if (fMotifTypes.size()) {
194 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
196 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
197 const TString& id = (*i).first;
198 cout << "Map element "
199 << setw(3) << counter++ << " "
201 PrintMotifType((*i).second);
209 if (fMotifTypes.GetSize()) {
210 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
212 TExMapIter i = fMotifTypes.GetIterator();
214 while ( i.Next(key, value) ) {
215 TString id = AliMpExMap::GetString(key);
216 AliMpMotifType* motifType = (AliMpMotifType*)value;
217 cout << "Map element "
218 << setw(3) << counter++ << " "
219 << id.Data() << " " ;
220 PrintMotifType(motifType);
228 //_____________________________________________________________________________
230 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
232 /// Fill the given array with all motif positions IDs (electronic card numbers)
233 /// defined in the map
236 ecn.Set(fMotifPositions.size());
238 MotifPositionMapIterator it;
239 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
240 AliMpMotifPosition* motifPosition = (*it).second;
241 ecn[i++] = motifPosition->GetID();
246 ecn.Set(fMotifPositions.GetSize());
247 TExMapIter it = fMotifPositions.GetIterator();
251 while ( it.Next(key, value) )
253 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
254 ecn[i] = motifPosition->GetID();
261 //_____________________________________________________________________________
262 UInt_t AliMpMotifMap::GetNofMotifPositions() const
264 /// Return the number of all motif positions IDs (electronic card numbers)
267 return fMotifPositions.size();
271 return fMotifPositions.GetSize();
275 //_____________________________________________________________________________
276 AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
278 /// Return the motif position which is in the map on the index-th position
280 if ( index >= GetNofMotifPositions() ) {
281 AliErrorStream() << "Index " << index << " outside limits." << endl;
286 MotifPositionMapIterator it = fMotifPositions.begin();
287 std::advance(it, index);
292 return (AliMpMotifPosition*)fMotifPositions.GetObject(index);
296 //_____________________________________________________________________________
297 Int_t AliMpMotifMap::CalculateNofPads() const
299 /// Calculate total number of pads in the map
304 MotifPositionMapIterator it;
305 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
306 AliMpMotifPosition* motifPosition = (*it).second;
307 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
312 TExMapIter it = fMotifPositions.GetIterator();
315 while ( it.Next(key, value) ) {
316 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
317 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
324 //_____________________________________________________________________________
325 void AliMpMotifMap::PrintMotifPositions() const
327 /// Print all motif positions.
330 if (fMotifPositions.size()) {
331 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
333 for (MotifPositionMapIterator i=fMotifPositions.begin();
334 i != fMotifPositions.end(); i++) {
336 cout << "Map element "
337 << setw(3) << counter++ << " ";
338 PrintMotifPosition((*i).second);
346 if (fMotifPositions.GetSize()) {
347 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
349 TExMapIter i = fMotifPositions.GetIterator();
351 while ( i.Next(key, value) ) {
352 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
353 cout << "Map element "
354 << setw(3) << counter++ << " ";
355 PrintMotifPosition(motifPosition);
363 //_____________________________________________________________________________
364 void AliMpMotifMap::PrintMotifPositions2() const
366 /// Print all motif positions from the second map
367 /// (by global indices)
370 if (fMotifPositions2.size()) {
371 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
373 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
374 i != fMotifPositions2.end(); i++) {
376 cout << "Map element "
377 << setw(3) << counter++ << " ";
378 PrintMotifPosition2((*i).second);
386 if (fMotifPositions2.GetSize()) {
387 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
389 TExMapIter i = fMotifPositions2.GetIterator();
391 while ( i.Next(key, value) ) {
392 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
393 cout << "Map element "
394 << setw(3) << counter++ << " ";
395 PrintMotifPosition2(motifPosition);
407 //_____________________________________________________________________________
408 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
410 /// Add the specified motif
411 /// if the motif with this ID is not yet present.
413 AliMpVMotif* found = FindMotif(motif->GetID());
415 if (warn && found == motif)
416 AliWarningStream() << "The motif is already in map." << endl;
418 if (warn && found != motif) {
420 << "Another motif with the same ID is already in map." << endl;
426 fMotifs[motif->GetID()] = motif;
430 fMotifs.Add(motif->GetID(), motif);
436 //_____________________________________________________________________________
437 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
439 /// Add the specified motif type
440 /// if the motif with this ID is not yet present.
442 AliMpMotifType* found = FindMotifType(motifType->GetID());
444 if (warn && found == motifType)
445 AliWarningStream() << "The motif type is already in map." << endl;
447 if (warn && found != motifType) {
449 << "Another motif type with the same ID is already in map." << endl;
455 fMotifTypes[motifType->GetID()] = motifType;
459 fMotifTypes.Add(motifType->GetID(), motifType);
465 //_____________________________________________________________________________
466 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
468 /// Add the specified motif position
469 /// if this position is not yet present.
471 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
473 if (warn && found == motifPosition) {
475 << "ID: " << motifPosition->GetID()
476 << " found: " << found
477 << " new: " << motifPosition << endl
478 << "This motif position is already in map." << endl;
481 if (warn && found != motifPosition) {
483 << "ID: " << motifPosition->GetID()
484 << " found: " << found
485 << " new: " << motifPosition << endl
486 << "Another motif position with the same ID is already in map."
494 fMotifPositions[motifPosition->GetID()] = motifPosition;
498 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
504 //_____________________________________________________________________________
505 void AliMpMotifMap::FillMotifPositionMap2()
507 /// Fill the second map (by global indices) of motif positions.
510 if (fMotifPositions2.size() > 0 ) {
511 AliWarningStream() << "Map has been already filled." << endl;
515 for (MotifPositionMapIterator ip=fMotifPositions.begin();
516 ip != fMotifPositions.end(); ip++) {
518 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
523 if (fMotifPositions2.GetSize() > 0 ) {
524 AliWarningStream() <<"Map has been already filled." << endl;
528 TExMapIter i = fMotifPositions.GetIterator();
530 while ( i.Next(key, value) ) {
531 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
532 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
538 //_____________________________________________________________________________
539 void AliMpMotifMap::Print(const char* opt) const
541 /// Print the motifs and motif types maps.
547 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
548 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
549 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
550 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
553 //_____________________________________________________________________________
554 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
556 /// Print all motif positions and their global indices.
558 ofstream out(fileName, ios::out);
561 if (fMotifPositions.size()) {
562 for (MotifPositionMapIterator i=fMotifPositions.begin();
563 i != fMotifPositions.end(); i++) {
565 AliMpMotifPosition* motifPosition = (*i).second;
566 out << setw(5) << motifPosition->GetID() << " "
567 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
568 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
576 if (fMotifPositions.GetSize()) {
577 TExMapIter i = fMotifPositions.GetIterator();
579 while ( i.Next(key, value) ) {
580 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
581 out << setw(5) << motifPosition->GetID() << " "
582 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
583 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
591 //_____________________________________________________________________________
592 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
594 /// Update the motif positions global indices from the file.
596 ifstream in(fileName, ios::in);
598 Int_t motifPositionId, offx, offy;
601 in >> motifPositionId >> offx >> offy;
604 FillMotifPositionMap2();
608 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
613 << motifPosition->GetID() << " " << offx << " " << offy << endl;
615 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
618 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
621 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
623 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
627 << "Motif position " << motifPositionId << " not found" << endl;
634 //_____________________________________________________________________________
635 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
637 /// Find the motif with the specified ID.
640 MotifMapIterator i = fMotifs.find(motifID);
641 if (i != fMotifs.end())
648 return (AliMpVMotif*)fMotifs.GetValue(motifID);
652 //_____________________________________________________________________________
653 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
654 const TString& motifTypeID,
655 const TVector2& padDimensions ) const
657 /// Find the motif with the specified ID and returns it
658 /// only if its motif type and motif dimensions agree
659 /// with the given motifTypeID and motifDimensions.
660 /// Disagreement causes fatal error.
662 AliMpVMotif* motif = FindMotif(motifID);
664 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
666 "Motif has been already defined with a different type.");
670 // check pad dimension in case of a normal motif
672 dynamic_cast<AliMpMotif*>(motif) &&
673 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
674 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
676 Fatal("FindMotifType",
677 "Motif type has been already defined with different dimensions.");
682 // check case of a special motif
684 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
685 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
687 Fatal("FindMotifType",
688 "Motif type has been already defined with different dimensions.");
696 //_____________________________________________________________________________
697 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
699 /// Find the motif type with the specified motif type ID.
702 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
703 if (i != fMotifTypes.end())
710 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
714 //_____________________________________________________________________________
716 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
718 /// Find the motif position with the specified motif position ID.
721 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
722 if (i != fMotifPositions.end())
729 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
734 //_____________________________________________________________________________
736 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
738 /// Find the last motif position which has the global indices (low limit)
739 /// less then the indices specified.
742 MotifPositionMap2Iterator found
743 = fMotifPositions2.lower_bound(indices);
745 if (found == fMotifPositions2.end()) found--;
747 MotifPositionMap2Iterator i=found;
749 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
750 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
752 if ( indices.GetFirst() >= low.GetFirst() &&
753 indices.GetSecond() >= low.GetSecond() &&
754 indices.GetFirst() <= up.GetFirst() &&
755 indices.GetSecond() <= up.GetSecond())
759 while ( i-- != fMotifPositions2.begin());
765 // HOW TO DO THIS WITH ROOT ????
766 // Fortunately it seems not to be used anywhere
767 Fatal("FindMotifPosition", "Difficult in Root to do this.");