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>
46 ClassImp(AliMpMotifMap)
49 //_____________________________________________________________________________
50 AliMpMotifMap::AliMpMotifMap()
57 /// Standard constructor
59 fMotifPositions2.SetOwner(false);
62 //_____________________________________________________________________________
63 AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
67 fMotifPositions(ioCtor),
68 fMotifPositions2(ioCtor)
70 /// Root IO constructor
72 fMotifPositions2.SetOwner(false);
75 //_____________________________________________________________________________
76 AliMpMotifMap::~AliMpMotifMap()
80 // Delete all registered motifs, motif types, motif positions
87 //_____________________________________________________________________________
88 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
92 cout << motif->GetID().Data() << " "
93 << motif->GetMotifType()->GetID() << " "
94 << motif->DimensionX() << " "
95 << motif->DimensionY();
98 //_____________________________________________________________________________
99 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
101 /// Print the motif type.
103 cout << motifType->GetID().Data() << " "
104 << motifType->GetNofPadsX() << " "
105 << motifType->GetNofPadsY() << " ";
108 //_____________________________________________________________________________
109 void AliMpMotifMap::PrintMotifPosition(
110 const AliMpMotifPosition* motifPosition) const
112 /// Print the motif position.
114 cout << " ID " << motifPosition->GetID() << " "
115 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
116 << " Pos (X,Y) = (" << motifPosition->GetPositionX() << ","
117 << motifPosition->GetPositionY() << ")";
120 //_____________________________________________________________________________
121 void AliMpMotifMap::PrintMotifPosition2(
122 const AliMpMotifPosition* motifPosition) const
124 /// Print the motif position.
126 cout << setw(3) << motifPosition->GetLowLimitIx() << " "
127 << setw(3) << motifPosition->GetLowLimitIy() << " "
128 << setw(3) << motifPosition->GetHighLimitIx() << " "
129 << setw(3) << motifPosition->GetHighLimitIy() << " "
130 << motifPosition->GetID() << " ";
133 //_____________________________________________________________________________
134 void AliMpMotifMap::PrintMotifs() const
136 /// Print all the motifs and their motif types
137 /// for all motifs in the motifs map.
139 if (fMotifs.GetSize()) {
140 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
142 AliMpExMapIterator* it = fMotifs.CreateIterator();
146 while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
148 TString id = fMotifs.AliMpExMap::GetString(key);
149 cout << "Map element "
150 << setw(3) << counter++ << " "
151 << id.Data() << " " ;
160 //_____________________________________________________________________________
161 void AliMpMotifMap::PrintMotifTypes() const
163 /// Print all the the motifs types and their motif dimensions
164 /// for all motif types in the motif types map.
166 if (fMotifTypes.GetSize()) {
167 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
169 AliMpExMapIterator* it = fMotifTypes.CreateIterator();
171 AliMpMotifType* motifType;
173 while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
175 TString id = AliMpExMap::GetString(key);
176 cout << "Map element "
177 << setw(3) << counter++ << " "
178 << id.Data() << " " ;
179 PrintMotifType(motifType);
187 //_____________________________________________________________________________
189 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
191 /// Fill the given array with all motif positions IDs (electronic card numbers)
192 /// defined in the map
194 ecn.Set(fMotifPositions.GetSize());
195 TIter next(fMotifPositions.CreateIterator());
196 AliMpMotifPosition* motifPosition;
198 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
200 ecn[i] = motifPosition->GetID();
205 //_____________________________________________________________________________
206 UInt_t AliMpMotifMap::GetNofMotifPositions() const
208 /// Return the number of all motif positions IDs (electronic card numbers)
210 return fMotifPositions.GetSize();
213 //_____________________________________________________________________________
214 AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
216 /// Return the motif position which is in the map on the index-th position
218 AliCodeTimerAuto("");
220 if ( index >= GetNofMotifPositions() ) {
221 AliErrorStream() << "Index " << index << " outside limits." << endl;
225 TIter next(fMotifPositions.CreateIterator());
226 while (index-- > 0) next();
227 return static_cast<AliMpMotifPosition*>(next());
230 //_____________________________________________________________________________
231 Int_t AliMpMotifMap::CalculateNofPads() const
233 /// Calculate total number of pads in the map
237 TIter next(fMotifPositions.CreateIterator());
238 AliMpMotifPosition* motifPosition;
239 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
241 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
247 //_____________________________________________________________________________
248 void AliMpMotifMap::PrintMotifPositions() const
250 /// Print all motif positions.
252 if (fMotifPositions.GetSize()) {
253 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
255 TIter next(fMotifPositions.CreateIterator());
256 AliMpMotifPosition* motifPosition;
258 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
260 cout << "Map element "
261 << setw(3) << counter++ << " ";
262 PrintMotifPosition(motifPosition);
269 //_____________________________________________________________________________
270 void AliMpMotifMap::PrintMotifPositions2() const
272 /// Print all motif positions from the second map
273 /// (by global indices)
275 if (fMotifPositions2.GetSize())
277 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
278 TIter next(fMotifPositions2.CreateIterator());
279 AliMpMotifPosition* motifPosition(0x0);
282 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
284 cout << "Map element " << setw(3) << counter++ << " ";
285 PrintMotifPosition2(motifPosition);
296 //_____________________________________________________________________________
297 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
299 /// Add the specified motif
300 /// if the motif with this ID is not yet present.
302 AliMpVMotif* found = FindMotif(motif->GetID());
304 if (warn && found == motif)
305 AliWarningStream() << "The motif is already in map." << endl;
307 if (warn && found != motif) {
309 << "Another motif with the same ID is already in map." << endl;
314 fMotifs.Add(motif->GetID(), motif);
319 //_____________________________________________________________________________
320 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
322 /// Add the specified motif type
323 /// if the motif with this ID is not yet present.
325 AliMpMotifType* found = FindMotifType(motifType->GetID());
327 if (warn && found == motifType)
328 AliWarningStream() << "The motif type is already in map." << endl;
330 if (warn && found != motifType) {
332 << "Another motif type with the same ID is already in map." << endl;
337 fMotifTypes.Add(motifType->GetID(), motifType);
342 //_____________________________________________________________________________
343 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
345 /// Add the specified motif position
346 /// if this position is not yet present.
348 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
350 if (warn && found == motifPosition) {
352 << "ID: " << motifPosition->GetID()
353 << " found: " << found
354 << " new: " << motifPosition << endl
355 << "This motif position is already in map." << endl;
358 if (warn && found != motifPosition) {
360 << "ID: " << motifPosition->GetID()
361 << " found: " << found
362 << " new: " << motifPosition << endl
363 << "Another motif position with the same ID is already in map."
370 fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
375 //_____________________________________________________________________________
376 void AliMpMotifMap::FillMotifPositionMap2()
378 /// Fill the second map (by global indices) of motif positions.
380 if (fMotifPositions2.GetSize() > 0 ) {
381 AliWarningStream() <<"Map has been already filled." << endl;
385 TIter next(fMotifPositions.CreateIterator());
386 AliMpMotifPosition* motifPosition(0x0);
387 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
389 fMotifPositions2.Add(motifPosition->GetLowLimitIx(),
390 motifPosition->GetLowLimitIy(),
395 //_____________________________________________________________________________
396 void AliMpMotifMap::Print(const char* opt) const
398 /// Print the motifs and motif types maps.
404 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
405 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
406 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
407 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
410 //_____________________________________________________________________________
411 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
413 /// Print all motif positions and their global indices.
415 ofstream out(fileName, ios::out);
417 if (fMotifPositions.GetSize()) {
418 TIter next(fMotifPositions.CreateIterator());
419 AliMpMotifPosition* motifPosition;
420 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
422 out << setw(5) << motifPosition->GetID() << " "
423 << setw(3) << motifPosition->GetLowLimitIx() << " "
424 << setw(3) << motifPosition->GetLowLimitIy()
431 //_____________________________________________________________________________
432 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
434 /// Update the motif positions global indices from the file.
436 ifstream in(fileName, ios::in);
438 Int_t motifPositionId, offx, offy;
441 in >> motifPositionId >> offx >> offy;
444 FillMotifPositionMap2();
448 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
453 << motifPosition->GetID() << " " << offx << " " << offy << endl;
455 motifPosition->SetLowIndicesLimit(offx, offy);
458 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
461 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
463 motifPosition->SetHighIndicesLimit(offx2, offy2);
467 << "Motif position " << motifPositionId << " not found" << endl;
474 //_____________________________________________________________________________
475 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
477 /// Find the motif with the specified ID.
479 //AliCodeTimerAuto("");
481 return (AliMpVMotif*)fMotifs.GetValue(motifID);
484 //_____________________________________________________________________________
485 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
486 const TString& motifTypeID,
487 Double_t padDimensionX,
488 Double_t padDimensionY ) 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->GetPadDimensionX(0) != padDimensionX ||
508 motif->GetPadDimensionY(0) != padDimensionY ) ) {
510 AliFatal("Motif type has been already defined with different dimensions.");
515 // check case of a special motif
517 ( padDimensionX == 0. && padDimensionY == 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);