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 $
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifMap
22 // -------------------
23 // Class describing the motif map container, where motifs are
24 // mapped to their string IDs.
25 // Included in AliRoot: 2003/05/02
26 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
27 //-----------------------------------------------------------------------------
29 #include "AliMpMotifMap.h"
30 #include "AliMpVMotif.h"
31 #include "AliMpMotif.h"
32 #include "AliMpMotifSpecial.h"
33 #include "AliMpMotifType.h"
34 #include "AliMpMotifPosition.h"
38 #include <Riostream.h>
43 ClassImp(AliMpMotifMap)
46 //_____________________________________________________________________________
47 AliMpMotifMap::AliMpMotifMap(Bool_t /*standardConstructor*/)
52 fMotifPositions(true),
53 fMotifPositions2(true)
56 /// Standard constructor
58 //fMotifPositions2.SetOwner(false);
61 //_____________________________________________________________________________
62 AliMpMotifMap::AliMpMotifMap()
69 /// Default constructor
72 //_____________________________________________________________________________
73 AliMpMotifMap::~AliMpMotifMap()
77 // Delete all registered motifs, motif types, motif positions
80 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
84 for (MotifTypeMapIterator it=fMotifTypes.begin();
85 it != fMotifTypes.end(); it++) {
89 for (MotifPositionMapIterator ip=fMotifPositions.begin();
90 ip != fMotifPositions.end(); ip++) {
100 //_____________________________________________________________________________
101 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
105 cout << motif->GetID().Data() << " "
106 << motif->GetMotifType()->GetID() << " "
107 << motif->Dimensions().X() << " "
108 << motif->Dimensions().Y();
111 //_____________________________________________________________________________
112 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
114 /// Print the motif type.
116 cout << motifType->GetID().Data() << " "
117 << motifType->GetNofPadsX() << " "
118 << motifType->GetNofPadsY() << " ";
121 //_____________________________________________________________________________
122 void AliMpMotifMap::PrintMotifPosition(
123 const AliMpMotifPosition* motifPosition) const
125 /// Print the motif position.
127 cout << " ID " << motifPosition->GetID() << " "
128 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
129 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
130 << motifPosition->Position().Y() << ")";
133 //_____________________________________________________________________________
134 void AliMpMotifMap::PrintMotifPosition2(
135 const AliMpMotifPosition* motifPosition) const
137 /// Print the motif position.
139 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
140 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
141 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
142 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
143 << motifPosition->GetID() << " ";
146 //_____________________________________________________________________________
147 void AliMpMotifMap::PrintMotifs() const
149 /// Print all the motifs and their motif types
150 /// for all motifs in the motifs map.
153 if (fMotifs.size()) {
154 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
156 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
157 const TString& id = (*i).first;
158 cout << "Map element "
159 << setw(3) << counter++ << " "
160 << id.Data() << " " ;
161 PrintMotif((*i).second);
169 if (fMotifs.GetSize()) {
170 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
172 TExMapIter i = fMotifs.GetIterator();
174 while ( i.Next(key, value) ) {
175 TString id = fMotifs.AliMpExMap::GetString(key);
176 AliMpVMotif* motif = (AliMpVMotif*)value;
177 cout << "Map element "
178 << setw(3) << counter++ << " "
179 << id.Data() << " " ;
188 //_____________________________________________________________________________
189 void AliMpMotifMap::PrintMotifTypes() const
191 /// Print all the the motifs types and their motif dimensions
192 /// for all motif types in the motif types map.
195 if (fMotifTypes.size()) {
196 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
198 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
199 const TString& id = (*i).first;
200 cout << "Map element "
201 << setw(3) << counter++ << " "
203 PrintMotifType((*i).second);
211 if (fMotifTypes.GetSize()) {
212 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
214 TExMapIter i = fMotifTypes.GetIterator();
216 while ( i.Next(key, value) ) {
217 TString id = AliMpExMap::GetString(key);
218 AliMpMotifType* motifType = (AliMpMotifType*)value;
219 cout << "Map element "
220 << setw(3) << counter++ << " "
221 << id.Data() << " " ;
222 PrintMotifType(motifType);
230 //_____________________________________________________________________________
232 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
234 /// Fill the given array with all motif positions IDs (electronic card numbers)
235 /// defined in the map
238 ecn.Set(fMotifPositions.size());
240 MotifPositionMapIterator it;
241 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
242 AliMpMotifPosition* motifPosition = (*it).second;
243 ecn[i++] = motifPosition->GetID();
248 ecn.Set(fMotifPositions.GetSize());
249 TExMapIter it = fMotifPositions.GetIterator();
253 while ( it.Next(key, value) )
255 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
256 ecn[i] = motifPosition->GetID();
263 //_____________________________________________________________________________
264 UInt_t AliMpMotifMap::GetNofMotifPositions() const
266 /// Return the number of all motif positions IDs (electronic card numbers)
269 return fMotifPositions.size();
273 return fMotifPositions.GetSize();
277 //_____________________________________________________________________________
278 AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
280 /// Return the motif position which is in the map on the index-th position
282 if ( index >= GetNofMotifPositions() ) {
283 AliErrorStream() << "Index " << index << " outside limits." << endl;
288 MotifPositionMapIterator it = fMotifPositions.begin();
289 std::advance(it, index);
294 return (AliMpMotifPosition*)fMotifPositions.GetObject(index);
298 //_____________________________________________________________________________
299 Int_t AliMpMotifMap::CalculateNofPads() const
301 /// Calculate total number of pads in the map
306 MotifPositionMapIterator it;
307 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
308 AliMpMotifPosition* motifPosition = (*it).second;
309 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
314 TExMapIter it = fMotifPositions.GetIterator();
317 while ( it.Next(key, value) ) {
318 AliMpMotifPosition* motifPosition = reinterpret_cast<AliMpMotifPosition*>(value);
319 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
326 //_____________________________________________________________________________
327 void AliMpMotifMap::PrintMotifPositions() const
329 /// Print all motif positions.
332 if (fMotifPositions.size()) {
333 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
335 for (MotifPositionMapIterator i=fMotifPositions.begin();
336 i != fMotifPositions.end(); i++) {
338 cout << "Map element "
339 << setw(3) << counter++ << " ";
340 PrintMotifPosition((*i).second);
348 if (fMotifPositions.GetSize()) {
349 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
351 TExMapIter i = fMotifPositions.GetIterator();
353 while ( i.Next(key, value) ) {
354 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
355 cout << "Map element "
356 << setw(3) << counter++ << " ";
357 PrintMotifPosition(motifPosition);
365 //_____________________________________________________________________________
366 void AliMpMotifMap::PrintMotifPositions2() const
368 /// Print all motif positions from the second map
369 /// (by global indices)
372 if (fMotifPositions2.size()) {
373 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
375 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
376 i != fMotifPositions2.end(); i++) {
378 cout << "Map element "
379 << setw(3) << counter++ << " ";
380 PrintMotifPosition2((*i).second);
388 if (fMotifPositions2.GetSize()) {
389 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
391 TExMapIter i = fMotifPositions2.GetIterator();
393 while ( i.Next(key, value) ) {
394 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
395 cout << "Map element "
396 << setw(3) << counter++ << " ";
397 PrintMotifPosition2(motifPosition);
409 //_____________________________________________________________________________
410 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
412 /// Add the specified motif
413 /// if the motif with this ID is not yet present.
415 AliMpVMotif* found = FindMotif(motif->GetID());
417 if (warn && found == motif)
418 AliWarningStream() << "The motif is already in map." << endl;
420 if (warn && found != motif) {
422 << "Another motif with the same ID is already in map." << endl;
428 fMotifs[motif->GetID()] = motif;
432 fMotifs.Add(motif->GetID(), motif);
438 //_____________________________________________________________________________
439 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
441 /// Add the specified motif type
442 /// if the motif with this ID is not yet present.
444 AliMpMotifType* found = FindMotifType(motifType->GetID());
446 if (warn && found == motifType)
447 AliWarningStream() << "The motif type is already in map." << endl;
449 if (warn && found != motifType) {
451 << "Another motif type with the same ID is already in map." << endl;
457 fMotifTypes[motifType->GetID()] = motifType;
461 fMotifTypes.Add(motifType->GetID(), motifType);
467 //_____________________________________________________________________________
468 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
470 /// Add the specified motif position
471 /// if this position is not yet present.
473 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
475 if (warn && found == motifPosition) {
477 << "ID: " << motifPosition->GetID()
478 << " found: " << found
479 << " new: " << motifPosition << endl
480 << "This motif position is already in map." << endl;
483 if (warn && found != motifPosition) {
485 << "ID: " << motifPosition->GetID()
486 << " found: " << found
487 << " new: " << motifPosition << endl
488 << "Another motif position with the same ID is already in map."
496 fMotifPositions[motifPosition->GetID()] = motifPosition;
500 fMotifPositions.Add(motifPosition->GetID(), motifPosition);
506 //_____________________________________________________________________________
507 void AliMpMotifMap::FillMotifPositionMap2()
509 /// Fill the second map (by global indices) of motif positions.
512 if (fMotifPositions2.size() > 0 ) {
513 AliWarningStream() << "Map has been already filled." << endl;
517 for (MotifPositionMapIterator ip=fMotifPositions.begin();
518 ip != fMotifPositions.end(); ip++) {
520 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
525 if (fMotifPositions2.GetSize() > 0 ) {
526 AliWarningStream() <<"Map has been already filled." << endl;
530 TExMapIter i = fMotifPositions.GetIterator();
532 while ( i.Next(key, value) ) {
533 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
534 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
540 //_____________________________________________________________________________
541 void AliMpMotifMap::Print(const char* opt) const
543 /// Print the motifs and motif types maps.
549 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
550 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
551 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
552 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
555 //_____________________________________________________________________________
556 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
558 /// Print all motif positions and their global indices.
560 ofstream out(fileName, ios::out);
563 if (fMotifPositions.size()) {
564 for (MotifPositionMapIterator i=fMotifPositions.begin();
565 i != fMotifPositions.end(); i++) {
567 AliMpMotifPosition* motifPosition = (*i).second;
568 out << setw(5) << motifPosition->GetID() << " "
569 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
570 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
578 if (fMotifPositions.GetSize()) {
579 TExMapIter i = fMotifPositions.GetIterator();
581 while ( i.Next(key, value) ) {
582 AliMpMotifPosition* motifPosition = (AliMpMotifPosition*)value;
583 out << setw(5) << motifPosition->GetID() << " "
584 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
585 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
593 //_____________________________________________________________________________
594 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
596 /// Update the motif positions global indices from the file.
598 ifstream in(fileName, ios::in);
600 Int_t motifPositionId, offx, offy;
603 in >> motifPositionId >> offx >> offy;
606 FillMotifPositionMap2();
610 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
615 << motifPosition->GetID() << " " << offx << " " << offy << endl;
617 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
620 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
623 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
625 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
629 << "Motif position " << motifPositionId << " not found" << endl;
636 //_____________________________________________________________________________
637 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
639 /// Find the motif with the specified ID.
642 MotifMapIterator i = fMotifs.find(motifID);
643 if (i != fMotifs.end())
650 return (AliMpVMotif*)fMotifs.GetValue(motifID);
654 //_____________________________________________________________________________
655 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
656 const TString& motifTypeID,
657 const TVector2& padDimensions ) const
659 /// Find the motif with the specified ID and returns it
660 /// only if its motif type and motif dimensions agree
661 /// with the given motifTypeID and motifDimensions.
662 /// Disagreement causes fatal error.
664 AliMpVMotif* motif = FindMotif(motifID);
666 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
668 "Motif has been already defined with a different type.");
672 // check pad dimension in case of a normal motif
674 dynamic_cast<AliMpMotif*>(motif) &&
675 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
676 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
678 Fatal("FindMotifType",
679 "Motif type has been already defined with different dimensions.");
684 // check case of a special motif
686 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
687 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
689 Fatal("FindMotifType",
690 "Motif type has been already defined with different dimensions.");
698 //_____________________________________________________________________________
699 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
701 /// Find the motif type with the specified motif type ID.
704 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
705 if (i != fMotifTypes.end())
712 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
716 //_____________________________________________________________________________
718 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
720 /// Find the motif position with the specified motif position ID.
723 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
724 if (i != fMotifPositions.end())
731 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID);
736 //_____________________________________________________________________________
738 AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
740 /// Find the last motif position which has the global indices (low limit)
741 /// less then the indices specified.
744 MotifPositionMap2Iterator found
745 = fMotifPositions2.lower_bound(indices);
747 if (found == fMotifPositions2.end()) found--;
749 MotifPositionMap2Iterator i=found;
751 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
752 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
754 if ( indices.GetFirst() >= low.GetFirst() &&
755 indices.GetSecond() >= low.GetSecond() &&
756 indices.GetFirst() <= up.GetFirst() &&
757 indices.GetSecond() <= up.GetSecond())
761 while ( i-- != fMotifPositions2.begin());
767 // HOW TO DO THIS WITH ROOT ????
768 // Fortunately it seems not to be used anywhere
769 Fatal("FindMotifPosition", "Difficult in Root to do this.");