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"
31 #include "AliCodeTimer.h"
32 #include "AliMpExMapIterator.h"
33 #include "AliMpVMotif.h"
34 #include "AliMpMotif.h"
35 #include "AliMpMotifSpecial.h"
36 #include "AliMpMotifType.h"
37 #include "AliMpMotifPosition.h"
38 #include "AliMpEncodePair.h"
42 #include <Riostream.h>
47 ClassImp(AliMpMotifMap)
50 //_____________________________________________________________________________
51 AliMpMotifMap::AliMpMotifMap()
58 /// Standard constructor
60 fMotifPositions2.SetOwner(false);
63 //_____________________________________________________________________________
64 AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
68 fMotifPositions(ioCtor),
69 fMotifPositions2(ioCtor)
71 /// Root IO constructor
73 fMotifPositions2.SetOwner(false);
76 //_____________________________________________________________________________
77 AliMpMotifMap::~AliMpMotifMap()
81 // Delete all registered motifs, motif types, motif positions
88 //_____________________________________________________________________________
89 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
93 cout << motif->GetID().Data() << " "
94 << motif->GetMotifType()->GetID() << " "
95 << motif->Dimensions().X() << " "
96 << motif->Dimensions().Y();
99 //_____________________________________________________________________________
100 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
102 /// Print the motif type.
104 cout << motifType->GetID().Data() << " "
105 << motifType->GetNofPadsX() << " "
106 << motifType->GetNofPadsY() << " ";
109 //_____________________________________________________________________________
110 void AliMpMotifMap::PrintMotifPosition(
111 const AliMpMotifPosition* motifPosition) const
113 /// Print the motif position.
115 cout << " ID " << motifPosition->GetID() << " "
116 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
117 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
118 << motifPosition->Position().Y() << ")";
121 //_____________________________________________________________________________
122 void AliMpMotifMap::PrintMotifPosition2(
123 const AliMpMotifPosition* motifPosition) const
125 /// Print the motif position.
127 cout << setw(3) << motifPosition->GetLowLimitIx() << " "
128 << setw(3) << motifPosition->GetLowLimitIy() << " "
129 << setw(3) << motifPosition->GetHighLimitIx() << " "
130 << setw(3) << motifPosition->GetHighLimitIy() << " "
131 << motifPosition->GetID() << " ";
134 //_____________________________________________________________________________
135 void AliMpMotifMap::PrintMotifs() const
137 /// Print all the motifs and their motif types
138 /// for all motifs in the motifs map.
140 if (fMotifs.GetSize()) {
141 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
143 AliMpExMapIterator* it = fMotifs.CreateIterator();
147 while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
149 TString id = fMotifs.AliMpExMap::GetString(key);
150 cout << "Map element "
151 << setw(3) << counter++ << " "
152 << id.Data() << " " ;
161 //_____________________________________________________________________________
162 void AliMpMotifMap::PrintMotifTypes() const
164 /// Print all the the motifs types and their motif dimensions
165 /// for all motif types in the motif types map.
167 if (fMotifTypes.GetSize()) {
168 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
170 AliMpExMapIterator* it = fMotifTypes.CreateIterator();
172 AliMpMotifType* motifType;
174 while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
176 TString id = AliMpExMap::GetString(key);
177 cout << "Map element "
178 << setw(3) << counter++ << " "
179 << id.Data() << " " ;
180 PrintMotifType(motifType);
188 //_____________________________________________________________________________
190 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
192 /// Fill the given array with all motif positions IDs (electronic card numbers)
193 /// defined in the map
195 ecn.Set(fMotifPositions.GetSize());
196 TIter next(fMotifPositions.CreateIterator());
197 AliMpMotifPosition* motifPosition;
199 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
201 ecn[i] = motifPosition->GetID();
206 //_____________________________________________________________________________
207 UInt_t AliMpMotifMap::GetNofMotifPositions() const
209 /// Return the number of all motif positions IDs (electronic card numbers)
211 return fMotifPositions.GetSize();
214 //_____________________________________________________________________________
215 AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
217 /// Return the motif position which is in the map on the index-th position
219 AliCodeTimerAuto("");
221 if ( index >= GetNofMotifPositions() ) {
222 AliErrorStream() << "Index " << index << " outside limits." << endl;
226 TIter next(fMotifPositions.CreateIterator());
227 while (index-- > 0) next();
228 return static_cast<AliMpMotifPosition*>(next());
231 //_____________________________________________________________________________
232 Int_t AliMpMotifMap::CalculateNofPads() const
234 /// Calculate total number of pads in the map
238 TIter next(fMotifPositions.CreateIterator());
239 AliMpMotifPosition* motifPosition;
240 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
242 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
248 //_____________________________________________________________________________
249 void AliMpMotifMap::PrintMotifPositions() const
251 /// Print all motif positions.
253 if (fMotifPositions.GetSize()) {
254 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
256 TIter next(fMotifPositions.CreateIterator());
257 AliMpMotifPosition* motifPosition;
259 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
261 cout << "Map element "
262 << setw(3) << counter++ << " ";
263 PrintMotifPosition(motifPosition);
270 //_____________________________________________________________________________
271 void AliMpMotifMap::PrintMotifPositions2() const
273 /// Print all motif positions from the second map
274 /// (by global indices)
276 if (fMotifPositions2.GetSize())
278 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
279 TIter next(fMotifPositions2.CreateIterator());
280 AliMpMotifPosition* motifPosition(0x0);
283 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
285 cout << "Map element " << setw(3) << counter++ << " ";
286 PrintMotifPosition2(motifPosition);
297 //_____________________________________________________________________________
298 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
300 /// Add the specified motif
301 /// if the motif with this ID is not yet present.
303 AliMpVMotif* found = FindMotif(motif->GetID());
305 if (warn && found == motif)
306 AliWarningStream() << "The motif is already in map." << endl;
308 if (warn && found != motif) {
310 << "Another motif with the same ID is already in map." << endl;
315 fMotifs.Add(motif->GetID(), motif);
320 //_____________________________________________________________________________
321 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
323 /// Add the specified motif type
324 /// if the motif with this ID is not yet present.
326 AliMpMotifType* found = FindMotifType(motifType->GetID());
328 if (warn && found == motifType)
329 AliWarningStream() << "The motif type is already in map." << endl;
331 if (warn && found != motifType) {
333 << "Another motif type with the same ID is already in map." << endl;
338 fMotifTypes.Add(motifType->GetID(), motifType);
343 //_____________________________________________________________________________
344 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
346 /// Add the specified motif position
347 /// if this position is not yet present.
349 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
351 if (warn && found == motifPosition) {
353 << "ID: " << motifPosition->GetID()
354 << " found: " << found
355 << " new: " << motifPosition << endl
356 << "This motif position is already in map." << endl;
359 if (warn && found != motifPosition) {
361 << "ID: " << motifPosition->GetID()
362 << " found: " << found
363 << " new: " << motifPosition << endl
364 << "Another motif position with the same ID is already in map."
371 fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
376 //_____________________________________________________________________________
377 void AliMpMotifMap::FillMotifPositionMap2()
379 /// Fill the second map (by global indices) of motif positions.
381 if (fMotifPositions2.GetSize() > 0 ) {
382 AliWarningStream() <<"Map has been already filled." << endl;
386 TIter next(fMotifPositions.CreateIterator());
387 AliMpMotifPosition* motifPosition(0x0);
388 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
390 fMotifPositions2.Add(motifPosition->GetLowLimitIx(),
391 motifPosition->GetLowLimitIy(),
396 //_____________________________________________________________________________
397 void AliMpMotifMap::Print(const char* opt) const
399 /// Print the motifs and motif types maps.
405 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
406 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
407 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
408 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
411 //_____________________________________________________________________________
412 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
414 /// Print all motif positions and their global indices.
416 ofstream out(fileName, ios::out);
418 if (fMotifPositions.GetSize()) {
419 TIter next(fMotifPositions.CreateIterator());
420 AliMpMotifPosition* motifPosition;
421 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
423 out << setw(5) << motifPosition->GetID() << " "
424 << setw(3) << motifPosition->GetLowLimitIx() << " "
425 << setw(3) << motifPosition->GetLowLimitIy()
432 //_____________________________________________________________________________
433 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
435 /// Update the motif positions global indices from the file.
437 ifstream in(fileName, ios::in);
439 Int_t motifPositionId, offx, offy;
442 in >> motifPositionId >> offx >> offy;
445 FillMotifPositionMap2();
449 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
454 << motifPosition->GetID() << " " << offx << " " << offy << endl;
456 motifPosition->SetLowIndicesLimit(offx, offy);
459 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
462 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
464 motifPosition->SetHighIndicesLimit(offx2, offy2);
468 << "Motif position " << motifPositionId << " not found" << endl;
475 //_____________________________________________________________________________
476 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
478 /// Find the motif with the specified ID.
480 //AliCodeTimerAuto("");
482 return (AliMpVMotif*)fMotifs.GetValue(motifID);
485 //_____________________________________________________________________________
486 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
487 const TString& motifTypeID,
488 const TVector2& padDimensions ) const
490 /// Find the motif with the specified ID and returns it
491 /// only if its motif type and motif dimensions agree
492 /// with the given motifTypeID and motifDimensions.
493 /// Disagreement causes fatal error.
495 //AliCodeTimerAuto("");
497 AliMpVMotif* motif = FindMotif(motifID);
499 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
500 AliFatal("Motif has been already defined with a different type.");
504 // check pad dimension in case of a normal motif
506 dynamic_cast<AliMpMotif*>(motif) &&
507 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
508 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
510 AliFatal("Motif type has been already defined with different dimensions.");
515 // check case of a special motif
517 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
518 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
520 AliFatal("Motif type has been already defined with different dimensions.");
528 //_____________________________________________________________________________
529 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
531 /// Find the motif type with the specified motif type ID.
533 //AliCodeTimerAuto("");
535 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
538 //_____________________________________________________________________________
540 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
542 /// Find the motif position with the specified motif position ID.
544 //AliCodeTimerAuto("");
546 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID << 16);