AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpMotifMap.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
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  **************************************************************************/
15 
16 // $Id$
17 // $MpId: AliMpMotifMap.cxx,v 1.16 2006/05/24 13:58:41 ivana Exp $
18 // Category: motif
19 
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 //-----------------------------------------------------------------------------
28 
29 #include "AliMpMotifMap.h"
30 
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"
39 
40 #include "AliLog.h"
41 
42 #include <Riostream.h>
43 #include <TArrayI.h>
44 
45 using std::cout;
46 using std::endl;
47 using std::setw;
48 using std::ofstream;
49 using std::ios;
50 using std::ifstream;
54 
55 //_____________________________________________________________________________
57  : TObject(),
58  fMotifs(),
59  fMotifTypes(),
60  fMotifPositions(),
61  fMotifPositions2()
62 {
64 
65  fMotifPositions2.SetOwner(false);
66 }
67 
68 //_____________________________________________________________________________
69 AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
70  : TObject(),
71  fMotifs(ioCtor),
72  fMotifTypes(ioCtor),
73  fMotifPositions(ioCtor),
74  fMotifPositions2(ioCtor)
75 {
77 
79 }
80 
81 //_____________________________________________________________________________
83 {
85 
86  // Delete all registered motifs, motif types, motif positions
87 }
88 
89 //
90 // private methods
91 //
92 
93 //_____________________________________________________________________________
94 void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
95 {
97 
98  cout << motif->GetID().Data() << " "
99  << motif->GetMotifType()->GetID() << " "
100  << motif->DimensionX() << " "
101  << motif->DimensionY();
102 }
103 
104 //_____________________________________________________________________________
105 void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
106 {
108 
109  cout << motifType->GetID().Data() << " "
110  << motifType->GetNofPadsX() << " "
111  << motifType->GetNofPadsY() << " ";
112 }
113 
114 //_____________________________________________________________________________
116  const AliMpMotifPosition* motifPosition) const
117 {
119 
120  cout << " ID " << motifPosition->GetID() << " "
121  << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
122  << " Pos (X,Y) = (" << motifPosition->GetPositionX() << ","
123  << motifPosition->GetPositionY() << ")";
124 }
125 
126 //_____________________________________________________________________________
128  const AliMpMotifPosition* motifPosition) const
129 {
131 
132  cout << setw(3) << motifPosition->GetLowLimitIx() << " "
133  << setw(3) << motifPosition->GetLowLimitIy() << " "
134  << setw(3) << motifPosition->GetHighLimitIx() << " "
135  << setw(3) << motifPosition->GetHighLimitIy() << " "
136  << motifPosition->GetID() << " ";
137 }
138 
139 //_____________________________________________________________________________
141 {
144 
145  if (fMotifs.GetSize()) {
146  cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
147  Int_t counter = 0;
149  Int_t key;
150  AliMpVMotif* motif;
151 
152  while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
153  {
154  TString id = fMotifs.AliMpExMap::GetString(key);
155  cout << "Map element "
156  << setw(3) << counter++ << " "
157  << id.Data() << " " ;
158  PrintMotif(motif);
159  cout << endl;
160  }
161  cout << endl;
162  delete it;
163  }
164 }
165 
166 //_____________________________________________________________________________
168 {
171 
172  if (fMotifTypes.GetSize()) {
173  cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
174  Int_t counter = 0;
176  Int_t key;
177  AliMpMotifType* motifType;
178 
179  while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
180  {
181  TString id = AliMpExMap::GetString(key);
182  cout << "Map element "
183  << setw(3) << counter++ << " "
184  << id.Data() << " " ;
185  PrintMotifType(motifType);
186  cout << endl;
187  }
188  cout << endl;
189  delete it;
190  }
191 }
192 
193 //_____________________________________________________________________________
194 void
196 {
199 
200  ecn.Set(fMotifPositions.GetSize());
201  TIter next(fMotifPositions.CreateIterator());
202  AliMpMotifPosition* motifPosition;
203  Int_t i(0);
204  while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
205  {
206  ecn[i] = motifPosition->GetID();
207  ++i;
208  }
209 }
210 
211 //_____________________________________________________________________________
213 {
215 
216  return fMotifPositions.GetSize();
217 }
218 
219 //_____________________________________________________________________________
221 {
223 
224  AliCodeTimerAuto("",0);
225 
226  if ( index >= GetNofMotifPositions() ) {
227  AliErrorStream() << "Index " << index << " outside limits." << endl;
228  return 0;
229  }
230 
231  TIter next(fMotifPositions.CreateIterator());
232  while (index-- > 0) next();
233  return static_cast<AliMpMotifPosition*>(next());
234 }
235 
236 //_____________________________________________________________________________
238 {
240 
241  Int_t nofPads = 0;
242 
243  TIter next(fMotifPositions.CreateIterator());
244  AliMpMotifPosition* motifPosition;
245  while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
246  {
247  nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
248  }
249 
250  return nofPads;
251 }
252 
253 //_____________________________________________________________________________
255 {
257 
258  if (fMotifPositions.GetSize()) {
259  cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
260  Int_t counter = 0;
261  TIter next(fMotifPositions.CreateIterator());
262  AliMpMotifPosition* motifPosition;
263 
264  while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
265  {
266  cout << "Map element "
267  << setw(3) << counter++ << " ";
268  PrintMotifPosition(motifPosition);
269  cout << endl;
270  }
271  cout << endl;
272  }
273 }
274 
275 //_____________________________________________________________________________
277 {
280 
281  if (fMotifPositions2.GetSize())
282  {
283  cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
284  TIter next(fMotifPositions2.CreateIterator());
285  AliMpMotifPosition* motifPosition(0x0);
286  Int_t counter = 0;
287 
288  while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
289  {
290  cout << "Map element " << setw(3) << counter++ << " ";
291  PrintMotifPosition2(motifPosition);
292  cout << endl;
293  }
294  cout << endl;
295  }
296 }
297 
298 //
299 // public methods
300 //
301 
302 //_____________________________________________________________________________
303 Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
304 {
307 
308  AliMpVMotif* found = FindMotif(motif->GetID());
309  if (found) {
310  if (warn && found == motif)
311  AliWarningStream() << "The motif is already in map." << endl;
312 
313  if (warn && found != motif) {
314  AliWarningStream()
315  << "Another motif with the same ID is already in map." << endl;
316  }
317  return false;
318  }
319 
320  fMotifs.Add(motif->GetID(), motif);
321 
322  return true;
323 }
324 
325 //_____________________________________________________________________________
326 Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
327 {
330 
331  AliMpMotifType* found = FindMotifType(motifType->GetID());
332  if (found) {
333  if (warn && found == motifType)
334  AliWarningStream() << "The motif type is already in map." << endl;
335 
336  if (warn && found != motifType) {
337  AliWarningStream()
338  << "Another motif type with the same ID is already in map." << endl;
339  }
340  return false;
341  }
342 
343  fMotifTypes.Add(motifType->GetID(), motifType);
344 
345  return true;
346 }
347 
348 //_____________________________________________________________________________
349 Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
350 {
353 
354  AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
355  if (found) {
356  if (warn && found == motifPosition) {
357  AliWarningStream()
358  << "ID: " << motifPosition->GetID()
359  << " found: " << found
360  << " new: " << motifPosition << endl
361  << "This motif position is already in map." << endl;
362  }
363 
364  if (warn && found != motifPosition) {
365  AliWarningStream()
366  << "ID: " << motifPosition->GetID()
367  << " found: " << found
368  << " new: " << motifPosition << endl
369  << "Another motif position with the same ID is already in map."
370  << endl;
371  }
372 
373  return false;
374  }
375 
376  fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
377 
378  return true;
379 }
380 
381 //_____________________________________________________________________________
383 {
385 
386  if (fMotifPositions2.GetSize() > 0 ) {
387  AliWarningStream() <<"Map has been already filled." << endl;
388  return;
389  }
390 
391  TIter next(fMotifPositions.CreateIterator());
392  AliMpMotifPosition* motifPosition(0x0);
393  while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
394  {
395  fMotifPositions2.Add(motifPosition->GetLowLimitIx(),
396  motifPosition->GetLowLimitIy(),
397  motifPosition);
398  }
399 }
400 
401 //_____________________________________________________________________________
402 void AliMpMotifMap::Print(const char* opt) const
403 {
405 
406  TString sopt(opt);
407 
408  sopt.ToUpper();
409 
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();
414 }
415 
416 //_____________________________________________________________________________
417 void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
418 {
420 
421  ofstream out(fileName, ios::out);
422 
423  if (fMotifPositions.GetSize()) {
424  TIter next(fMotifPositions.CreateIterator());
425  AliMpMotifPosition* motifPosition;
426  while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
427  {
428  out << setw(5) << motifPosition->GetID() << " "
429  << setw(3) << motifPosition->GetLowLimitIx() << " "
430  << setw(3) << motifPosition->GetLowLimitIy()
431  << endl;
432  }
433  out << endl;
434  }
435 }
436 
437 //_____________________________________________________________________________
438 void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
439 {
441 
442  ifstream in(fileName, ios::in);
443 
444  Int_t motifPositionId, offx, offy;
445 
446  do {
447  in >> motifPositionId >> offx >> offy;
448 
449  if (in.eof()) {
451  return;
452  }
453 
454  AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
455 
456  if (motifPosition) {
457  AliDebugStream(1)
458  << "Processing "
459  << motifPosition->GetID() << " " << offx << " " << offy << endl;
460 
461  motifPosition->SetLowIndicesLimit(offx, offy);
462 
463  Int_t offx2
464  = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
465 
466  Int_t offy2
467  = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
468 
469  motifPosition->SetHighIndicesLimit(offx2, offy2);
470  }
471  else {
472  AliWarningStream()
473  << "Motif position " << motifPositionId << " not found" << endl;
474  }
475  }
476  while (!in.eof());
477 }
478 
479 
480 //_____________________________________________________________________________
481 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
482 {
484 
485  //AliCodeTimerAuto("",0);
486 
487  return (AliMpVMotif*)fMotifs.GetValue(motifID);
488 }
489 
490 //_____________________________________________________________________________
491 AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
492  const TString& motifTypeID,
493  Double_t padDimensionX,
494  Double_t padDimensionY ) const
495 {
500 
501  //AliCodeTimerAuto("",0);
502 
503  AliMpVMotif* motif = FindMotif(motifID);
504 
505  if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
506  AliFatal("Motif has been already defined with a different type.");
507  return 0;
508  }
509 
510  // check pad dimension in case of a normal motif
511  if ( motif &&
512  dynamic_cast<AliMpMotif*>(motif) &&
513  ( motif->GetPadDimensionX(0) != padDimensionX ||
514  motif->GetPadDimensionY(0) != padDimensionY ) ) {
515 
516  AliFatal("Motif type has been already defined with different dimensions.");
517  return 0;
518 
519  }
520 
521  // check case of a special motif
522  if ( motif &&
523  ( padDimensionX == 0. && padDimensionY == 0.) &&
524  ! dynamic_cast<AliMpMotifSpecial*>(motif) ) {
525 
526  AliFatal("Motif type has been already defined with different dimensions.");
527  return 0;
528 
529  }
530 
531  return motif;
532 }
533 
534 //_____________________________________________________________________________
535 AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
536 {
538 
539  //AliCodeTimerAuto("",0);
540 
541  return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
542 }
543 
544 //_____________________________________________________________________________
546 AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
547 {
549 
550  //AliCodeTimerAuto("",0);
551 
552  return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID << 16);
553 }
Double_t GetPositionY() const
Return y position.
void PrintMotifPosition2(const AliMpMotifPosition *motifPosition) const
void SetLowIndicesLimit(MpPair_t limit, Bool_t valid=true)
void PrintMotifs() const
Bool_t AddMotifPosition(AliMpMotifPosition *motifType, Bool_t warn=true)
AliMpExMap fMotifTypes
motifs types map
Definition: AliMpMotifMap.h:83
void FillMotifPositionMap2()
AliMpExMap fMotifPositions2
motifs positions map
Definition: AliMpMotifMap.h:85
Int_t GetLowLimitIx() const
virtual Double_t GetPadDimensionY(Int_t i) const =0
Return the i-th pad y dimension.
void PrintMotifPositions2() const
void PrintMotif(const AliMpVMotif *motif) const
Int_t CalculateNofPads() const
Calculate total number of pads defined in the map.
virtual Double_t DimensionY() const =0
Return y dimensions.
void UpdateGlobalIndices(const char *fileName)
void PrintMotifType(const AliMpMotifType *motifType) const
UInt_t GetNofMotifPositions() const
AliMpExMap fMotifs
motifs map
Definition: AliMpMotifMap.h:82
Int_t GetLowLimitIy() const
Int_t GetHighLimitIy() const
void PrintMotifPosition(const AliMpMotifPosition *motifPosition) const
AliMpVMotif * FindMotif(const TString &motifID) const
AliMpMotifType * GetMotifType() const
Return the motif type.
Definition: AliMpVMotif.h:87
virtual void Print(const char *option="ALL") const
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t GetSize() const
Definition: AliMpExMap.cxx:339
void PrintMotifPositions() const
void SetHighIndicesLimit(MpPair_t limit, Bool_t valid=true)
virtual TObject * Next()
The returned object must not be deleted by the user.
Int_t GetID() const
Return motif position ID = manu id.
TString GetID() const
Return the motif identifier.
Definition: AliMpVMotif.h:90
A placed motif.
Int_t GetNofPadsX() const
Return number of pads in x direction.
Int_t GetNofPadsY() const
Return number of pads in y direction.
Motif map containers.
Definition: AliMpMotifMap.h:34
Bool_t AddMotif(AliMpVMotif *motif, Bool_t warn=true)
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
Definition: AliMpExMap.cxx:364
AliMpVMotif * GetMotif() const
Return motif.
AliMpMotifType * FindMotifType(const TString &motifTypeID) const
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
Definition: AliMpExMap.cxx:291
virtual Double_t DimensionX() const =0
Return x dimensions.
AliMpMotifPosition * GetMotifPosition(UInt_t index) const
Int_t GetNofPads() const
Return the total number of pads.
void SetOwner(Bool_t owner)
Definition: AliMpExMap.cxx:331
Abstract base class for a motif with its unique ID and the motif type.
Definition: AliMpVMotif.h:24
void PrintGlobalIndices(const char *fileName) const
TString GetID() const
Return unique motif ID.
Bool_t AddMotifType(AliMpMotifType *motifType, Bool_t warn=true)
AliMpMotifPosition * FindMotifPosition(Int_t motifPositionID) const
virtual Double_t GetPadDimensionX(Int_t i) const =0
Return the i-th pad x dimension.
void PrintMotifTypes() const
Double_t GetPositionX() const
Return x position.
Int_t GetHighLimitIx() const
static TString GetString(Long_t index)
Definition: AliMpExMap.cxx:85
Implementation of TIterator for AliMpExMap.
AliMpExMap fMotifPositions
motifs positions map
Definition: AliMpMotifMap.h:84
virtual ~AliMpMotifMap()
AliMpExMapIterator * CreateIterator() const
Definition: AliMpExMap.cxx:356
Class that defines the motif properties.
void GetAllMotifPositionsIDs(TArrayI &enc) const
Find all motifPositionsIDs (=electronicCardNumbers) handled by this map.