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>
52 ClassImp(AliMpMotifMap)
55 //_____________________________________________________________________________
56 AliMpMotifMap::AliMpMotifMap()
63 /// Standard constructor
65 fMotifPositions2.SetOwner(false);
68 //_____________________________________________________________________________
69 AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
73 fMotifPositions(ioCtor),
74 fMotifPositions2(ioCtor)
76 /// Root IO constructor
78 fMotifPositions2.SetOwner(false);
81 //_____________________________________________________________________________
82 AliMpMotifMap::~AliMpMotifMap()
86 // Delete all registered motifs, motif types, motif positions
93 //_____________________________________________________________________________
94 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
98 cout << motif->GetID().Data() << " "
99 << motif->GetMotifType()->GetID() << " "
100 << motif->DimensionX() << " "
101 << motif->DimensionY();
104 //_____________________________________________________________________________
105 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
107 /// Print the motif type.
109 cout << motifType->GetID().Data() << " "
110 << motifType->GetNofPadsX() << " "
111 << motifType->GetNofPadsY() << " ";
114 //_____________________________________________________________________________
115 void AliMpMotifMap::PrintMotifPosition(
116 const AliMpMotifPosition* motifPosition) const
118 /// Print the motif position.
120 cout << " ID " << motifPosition->GetID() << " "
121 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
122 << " Pos (X,Y) = (" << motifPosition->GetPositionX() << ","
123 << motifPosition->GetPositionY() << ")";
126 //_____________________________________________________________________________
127 void AliMpMotifMap::PrintMotifPosition2(
128 const AliMpMotifPosition* motifPosition) const
130 /// Print the motif position.
132 cout << setw(3) << motifPosition->GetLowLimitIx() << " "
133 << setw(3) << motifPosition->GetLowLimitIy() << " "
134 << setw(3) << motifPosition->GetHighLimitIx() << " "
135 << setw(3) << motifPosition->GetHighLimitIy() << " "
136 << motifPosition->GetID() << " ";
139 //_____________________________________________________________________________
140 void AliMpMotifMap::PrintMotifs() const
142 /// Print all the motifs and their motif types
143 /// for all motifs in the motifs map.
145 if (fMotifs.GetSize()) {
146 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
148 AliMpExMapIterator* it = fMotifs.CreateIterator();
152 while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
154 TString id = fMotifs.AliMpExMap::GetString(key);
155 cout << "Map element "
156 << setw(3) << counter++ << " "
157 << id.Data() << " " ;
166 //_____________________________________________________________________________
167 void AliMpMotifMap::PrintMotifTypes() const
169 /// Print all the the motifs types and their motif dimensions
170 /// for all motif types in the motif types map.
172 if (fMotifTypes.GetSize()) {
173 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
175 AliMpExMapIterator* it = fMotifTypes.CreateIterator();
177 AliMpMotifType* motifType;
179 while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
181 TString id = AliMpExMap::GetString(key);
182 cout << "Map element "
183 << setw(3) << counter++ << " "
184 << id.Data() << " " ;
185 PrintMotifType(motifType);
193 //_____________________________________________________________________________
195 AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
197 /// Fill the given array with all motif positions IDs (electronic card numbers)
198 /// defined in the map
200 ecn.Set(fMotifPositions.GetSize());
201 TIter next(fMotifPositions.CreateIterator());
202 AliMpMotifPosition* motifPosition;
204 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
206 ecn[i] = motifPosition->GetID();
211 //_____________________________________________________________________________
212 UInt_t AliMpMotifMap::GetNofMotifPositions() const
214 /// Return the number of all motif positions IDs (electronic card numbers)
216 return fMotifPositions.GetSize();
219 //_____________________________________________________________________________
220 AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
222 /// Return the motif position which is in the map on the index-th position
224 AliCodeTimerAuto("",0);
226 if ( index >= GetNofMotifPositions() ) {
227 AliErrorStream() << "Index " << index << " outside limits." << endl;
231 TIter next(fMotifPositions.CreateIterator());
232 while (index-- > 0) next();
233 return static_cast<AliMpMotifPosition*>(next());
236 //_____________________________________________________________________________
237 Int_t AliMpMotifMap::CalculateNofPads() const
239 /// Calculate total number of pads in the map
243 TIter next(fMotifPositions.CreateIterator());
244 AliMpMotifPosition* motifPosition;
245 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
247 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
253 //_____________________________________________________________________________
254 void AliMpMotifMap::PrintMotifPositions() const
256 /// Print all motif positions.
258 if (fMotifPositions.GetSize()) {
259 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
261 TIter next(fMotifPositions.CreateIterator());
262 AliMpMotifPosition* motifPosition;
264 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
266 cout << "Map element "
267 << setw(3) << counter++ << " ";
268 PrintMotifPosition(motifPosition);
275 //_____________________________________________________________________________
276 void AliMpMotifMap::PrintMotifPositions2() const
278 /// Print all motif positions from the second map
279 /// (by global indices)
281 if (fMotifPositions2.GetSize())
283 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
284 TIter next(fMotifPositions2.CreateIterator());
285 AliMpMotifPosition* motifPosition(0x0);
288 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
290 cout << "Map element " << setw(3) << counter++ << " ";
291 PrintMotifPosition2(motifPosition);
302 //_____________________________________________________________________________
303 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
305 /// Add the specified motif
306 /// if the motif with this ID is not yet present.
308 AliMpVMotif* found = FindMotif(motif->GetID());
310 if (warn && found == motif)
311 AliWarningStream() << "The motif is already in map." << endl;
313 if (warn && found != motif) {
315 << "Another motif with the same ID is already in map." << endl;
320 fMotifs.Add(motif->GetID(), motif);
325 //_____________________________________________________________________________
326 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
328 /// Add the specified motif type
329 /// if the motif with this ID is not yet present.
331 AliMpMotifType* found = FindMotifType(motifType->GetID());
333 if (warn && found == motifType)
334 AliWarningStream() << "The motif type is already in map." << endl;
336 if (warn && found != motifType) {
338 << "Another motif type with the same ID is already in map." << endl;
343 fMotifTypes.Add(motifType->GetID(), motifType);
348 //_____________________________________________________________________________
349 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
351 /// Add the specified motif position
352 /// if this position is not yet present.
354 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
356 if (warn && found == motifPosition) {
358 << "ID: " << motifPosition->GetID()
359 << " found: " << found
360 << " new: " << motifPosition << endl
361 << "This motif position is already in map." << endl;
364 if (warn && found != motifPosition) {
366 << "ID: " << motifPosition->GetID()
367 << " found: " << found
368 << " new: " << motifPosition << endl
369 << "Another motif position with the same ID is already in map."
376 fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
381 //_____________________________________________________________________________
382 void AliMpMotifMap::FillMotifPositionMap2()
384 /// Fill the second map (by global indices) of motif positions.
386 if (fMotifPositions2.GetSize() > 0 ) {
387 AliWarningStream() <<"Map has been already filled." << endl;
391 TIter next(fMotifPositions.CreateIterator());
392 AliMpMotifPosition* motifPosition(0x0);
393 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
395 fMotifPositions2.Add(motifPosition->GetLowLimitIx(),
396 motifPosition->GetLowLimitIy(),
401 //_____________________________________________________________________________
402 void AliMpMotifMap::Print(const char* opt) const
404 /// Print the motifs and motif types maps.
410 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
411 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
412 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
413 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
416 //_____________________________________________________________________________
417 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
419 /// Print all motif positions and their global indices.
421 ofstream out(fileName, ios::out);
423 if (fMotifPositions.GetSize()) {
424 TIter next(fMotifPositions.CreateIterator());
425 AliMpMotifPosition* motifPosition;
426 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
428 out << setw(5) << motifPosition->GetID() << " "
429 << setw(3) << motifPosition->GetLowLimitIx() << " "
430 << setw(3) << motifPosition->GetLowLimitIy()
437 //_____________________________________________________________________________
438 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
440 /// Update the motif positions global indices from the file.
442 ifstream in(fileName, ios::in);
444 Int_t motifPositionId, offx, offy;
447 in >> motifPositionId >> offx >> offy;
450 FillMotifPositionMap2();
454 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
459 << motifPosition->GetID() << " " << offx << " " << offy << endl;
461 motifPosition->SetLowIndicesLimit(offx, offy);
464 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
467 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
469 motifPosition->SetHighIndicesLimit(offx2, offy2);
473 << "Motif position " << motifPositionId << " not found" << endl;
480 //_____________________________________________________________________________
481 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
483 /// Find the motif with the specified ID.
485 //AliCodeTimerAuto("",0);
487 return (AliMpVMotif*)fMotifs.GetValue(motifID);
490 //_____________________________________________________________________________
491 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
492 const TString& motifTypeID,
493 Double_t padDimensionX,
494 Double_t padDimensionY ) const
496 /// Find the motif with the specified ID and returns it
497 /// only if its motif type and motif dimensions agree
498 /// with the given motifTypeID and motifDimensions.
499 /// Disagreement causes fatal error.
501 //AliCodeTimerAuto("",0);
503 AliMpVMotif* motif = FindMotif(motifID);
505 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
506 AliFatal("Motif has been already defined with a different type.");
510 // check pad dimension in case of a normal motif
512 dynamic_cast<AliMpMotif*>(motif) &&
513 ( motif->GetPadDimensionX(0) != padDimensionX ||
514 motif->GetPadDimensionY(0) != padDimensionY ) ) {
516 AliFatal("Motif type has been already defined with different dimensions.");
521 // check case of a special motif
523 ( padDimensionX == 0. && padDimensionY == 0.) &&
524 ! dynamic_cast<AliMpMotifSpecial*>(motif) ) {
526 AliFatal("Motif type has been already defined with different dimensions.");
534 //_____________________________________________________________________________
535 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
537 /// Find the motif type with the specified motif type ID.
539 //AliCodeTimerAuto("",0);
541 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
544 //_____________________________________________________________________________
546 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
548 /// Find the motif position with the specified motif position ID.
550 //AliCodeTimerAuto("",0);
552 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID << 16);