]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/mapping/AliMpMotifMap.cxx
Fixing previous change, empty argument macros not supported everywhere
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifMap.cxx
... / ...
CommitLineData
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/// \cond CLASSIMP
46ClassImp(AliMpMotifMap)
47/// \endcond
48
49//_____________________________________________________________________________
50AliMpMotifMap::AliMpMotifMap()
51 : TObject(),
52 fMotifs(),
53 fMotifTypes(),
54 fMotifPositions(),
55 fMotifPositions2()
56{
57/// Standard constructor
58
59 fMotifPositions2.SetOwner(false);
60}
61
62//_____________________________________________________________________________
63AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
64 : TObject(),
65 fMotifs(ioCtor),
66 fMotifTypes(ioCtor),
67 fMotifPositions(ioCtor),
68 fMotifPositions2(ioCtor)
69{
70/// Root IO constructor
71
72 fMotifPositions2.SetOwner(false);
73}
74
75//_____________________________________________________________________________
76AliMpMotifMap::~AliMpMotifMap()
77{
78/// Destructor
79
80 // Delete all registered motifs, motif types, motif positions
81}
82
83//
84// private methods
85//
86
87//_____________________________________________________________________________
88void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
89{
90/// Print the motif.
91
92 cout << motif->GetID().Data() << " "
93 << motif->GetMotifType()->GetID() << " "
94 << motif->DimensionX() << " "
95 << motif->DimensionY();
96}
97
98//_____________________________________________________________________________
99void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
100{
101/// Print the motif type.
102
103 cout << motifType->GetID().Data() << " "
104 << motifType->GetNofPadsX() << " "
105 << motifType->GetNofPadsY() << " ";
106}
107
108//_____________________________________________________________________________
109void AliMpMotifMap::PrintMotifPosition(
110 const AliMpMotifPosition* motifPosition) const
111{
112/// Print the motif position.
113
114 cout << " ID " << motifPosition->GetID() << " "
115 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
116 << " Pos (X,Y) = (" << motifPosition->GetPositionX() << ","
117 << motifPosition->GetPositionY() << ")";
118}
119
120//_____________________________________________________________________________
121void AliMpMotifMap::PrintMotifPosition2(
122 const AliMpMotifPosition* motifPosition) const
123{
124/// Print the motif position.
125
126 cout << setw(3) << motifPosition->GetLowLimitIx() << " "
127 << setw(3) << motifPosition->GetLowLimitIy() << " "
128 << setw(3) << motifPosition->GetHighLimitIx() << " "
129 << setw(3) << motifPosition->GetHighLimitIy() << " "
130 << motifPosition->GetID() << " ";
131}
132
133//_____________________________________________________________________________
134void AliMpMotifMap::PrintMotifs() const
135{
136/// Print all the motifs and their motif types
137/// for all motifs in the motifs map.
138
139 if (fMotifs.GetSize()) {
140 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
141 Int_t counter = 0;
142 AliMpExMapIterator* it = fMotifs.CreateIterator();
143 Int_t key;
144 AliMpVMotif* motif;
145
146 while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
147 {
148 TString id = fMotifs.AliMpExMap::GetString(key);
149 cout << "Map element "
150 << setw(3) << counter++ << " "
151 << id.Data() << " " ;
152 PrintMotif(motif);
153 cout << endl;
154 }
155 cout << endl;
156 delete it;
157 }
158}
159
160//_____________________________________________________________________________
161void AliMpMotifMap::PrintMotifTypes() const
162{
163/// Print all the the motifs types and their motif dimensions
164/// for all motif types in the motif types map.
165
166 if (fMotifTypes.GetSize()) {
167 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
168 Int_t counter = 0;
169 AliMpExMapIterator* it = fMotifTypes.CreateIterator();
170 Int_t key;
171 AliMpMotifType* motifType;
172
173 while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
174 {
175 TString id = AliMpExMap::GetString(key);
176 cout << "Map element "
177 << setw(3) << counter++ << " "
178 << id.Data() << " " ;
179 PrintMotifType(motifType);
180 cout << endl;
181 }
182 cout << endl;
183 delete it;
184 }
185}
186
187//_____________________________________________________________________________
188void
189AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
190{
191/// Fill the given array with all motif positions IDs (electronic card numbers)
192/// defined in the map
193
194 ecn.Set(fMotifPositions.GetSize());
195 TIter next(fMotifPositions.CreateIterator());
196 AliMpMotifPosition* motifPosition;
197 Int_t i(0);
198 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
199 {
200 ecn[i] = motifPosition->GetID();
201 ++i;
202 }
203}
204
205//_____________________________________________________________________________
206UInt_t AliMpMotifMap::GetNofMotifPositions() const
207{
208/// Return the number of all motif positions IDs (electronic card numbers)
209
210 return fMotifPositions.GetSize();
211}
212
213//_____________________________________________________________________________
214AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
215{
216/// Return the motif position which is in the map on the index-th position
217
218 AliCodeTimerAuto("",0);
219
220 if ( index >= GetNofMotifPositions() ) {
221 AliErrorStream() << "Index " << index << " outside limits." << endl;
222 return 0;
223 }
224
225 TIter next(fMotifPositions.CreateIterator());
226 while (index-- > 0) next();
227 return static_cast<AliMpMotifPosition*>(next());
228}
229
230//_____________________________________________________________________________
231Int_t AliMpMotifMap::CalculateNofPads() const
232{
233/// Calculate total number of pads in the map
234
235 Int_t nofPads = 0;
236
237 TIter next(fMotifPositions.CreateIterator());
238 AliMpMotifPosition* motifPosition;
239 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
240 {
241 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
242 }
243
244 return nofPads;
245}
246
247//_____________________________________________________________________________
248void AliMpMotifMap::PrintMotifPositions() const
249{
250/// Print all motif positions.
251
252 if (fMotifPositions.GetSize()) {
253 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
254 Int_t counter = 0;
255 TIter next(fMotifPositions.CreateIterator());
256 AliMpMotifPosition* motifPosition;
257
258 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
259 {
260 cout << "Map element "
261 << setw(3) << counter++ << " ";
262 PrintMotifPosition(motifPosition);
263 cout << endl;
264 }
265 cout << endl;
266 }
267}
268
269//_____________________________________________________________________________
270void AliMpMotifMap::PrintMotifPositions2() const
271{
272/// Print all motif positions from the second map
273/// (by global indices)
274
275 if (fMotifPositions2.GetSize())
276 {
277 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
278 TIter next(fMotifPositions2.CreateIterator());
279 AliMpMotifPosition* motifPosition(0x0);
280 Int_t counter = 0;
281
282 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
283 {
284 cout << "Map element " << setw(3) << counter++ << " ";
285 PrintMotifPosition2(motifPosition);
286 cout << endl;
287 }
288 cout << endl;
289 }
290}
291
292//
293// public methods
294//
295
296//_____________________________________________________________________________
297Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
298{
299/// Add the specified motif
300/// if the motif with this ID is not yet present.
301
302 AliMpVMotif* found = FindMotif(motif->GetID());
303 if (found) {
304 if (warn && found == motif)
305 AliWarningStream() << "The motif is already in map." << endl;
306
307 if (warn && found != motif) {
308 AliWarningStream()
309 << "Another motif with the same ID is already in map." << endl;
310 }
311 return false;
312 }
313
314 fMotifs.Add(motif->GetID(), motif);
315
316 return true;
317}
318
319//_____________________________________________________________________________
320Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
321{
322/// Add the specified motif type
323/// if the motif with this ID is not yet present.
324
325 AliMpMotifType* found = FindMotifType(motifType->GetID());
326 if (found) {
327 if (warn && found == motifType)
328 AliWarningStream() << "The motif type is already in map." << endl;
329
330 if (warn && found != motifType) {
331 AliWarningStream()
332 << "Another motif type with the same ID is already in map." << endl;
333 }
334 return false;
335 }
336
337 fMotifTypes.Add(motifType->GetID(), motifType);
338
339 return true;
340}
341
342//_____________________________________________________________________________
343Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
344{
345/// Add the specified motif position
346/// if this position is not yet present.
347
348 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
349 if (found) {
350 if (warn && found == motifPosition) {
351 AliWarningStream()
352 << "ID: " << motifPosition->GetID()
353 << " found: " << found
354 << " new: " << motifPosition << endl
355 << "This motif position is already in map." << endl;
356 }
357
358 if (warn && found != motifPosition) {
359 AliWarningStream()
360 << "ID: " << motifPosition->GetID()
361 << " found: " << found
362 << " new: " << motifPosition << endl
363 << "Another motif position with the same ID is already in map."
364 << endl;
365 }
366
367 return false;
368 }
369
370 fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
371
372 return true;
373}
374
375//_____________________________________________________________________________
376void AliMpMotifMap::FillMotifPositionMap2()
377{
378/// Fill the second map (by global indices) of motif positions.
379
380 if (fMotifPositions2.GetSize() > 0 ) {
381 AliWarningStream() <<"Map has been already filled." << endl;
382 return;
383 }
384
385 TIter next(fMotifPositions.CreateIterator());
386 AliMpMotifPosition* motifPosition(0x0);
387 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
388 {
389 fMotifPositions2.Add(motifPosition->GetLowLimitIx(),
390 motifPosition->GetLowLimitIy(),
391 motifPosition);
392 }
393}
394
395//_____________________________________________________________________________
396void AliMpMotifMap::Print(const char* opt) const
397{
398/// Print the motifs and motif types maps.
399
400 TString sopt(opt);
401
402 sopt.ToUpper();
403
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();
408}
409
410//_____________________________________________________________________________
411void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
412{
413/// Print all motif positions and their global indices.
414
415 ofstream out(fileName, ios::out);
416
417 if (fMotifPositions.GetSize()) {
418 TIter next(fMotifPositions.CreateIterator());
419 AliMpMotifPosition* motifPosition;
420 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
421 {
422 out << setw(5) << motifPosition->GetID() << " "
423 << setw(3) << motifPosition->GetLowLimitIx() << " "
424 << setw(3) << motifPosition->GetLowLimitIy()
425 << endl;
426 }
427 out << endl;
428 }
429}
430
431//_____________________________________________________________________________
432void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
433{
434/// Update the motif positions global indices from the file.
435
436 ifstream in(fileName, ios::in);
437
438 Int_t motifPositionId, offx, offy;
439
440 do {
441 in >> motifPositionId >> offx >> offy;
442
443 if (in.eof()) {
444 FillMotifPositionMap2();
445 return;
446 }
447
448 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
449
450 if (motifPosition) {
451 AliDebugStream(1)
452 << "Processing "
453 << motifPosition->GetID() << " " << offx << " " << offy << endl;
454
455 motifPosition->SetLowIndicesLimit(offx, offy);
456
457 Int_t offx2
458 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
459
460 Int_t offy2
461 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
462
463 motifPosition->SetHighIndicesLimit(offx2, offy2);
464 }
465 else {
466 AliWarningStream()
467 << "Motif position " << motifPositionId << " not found" << endl;
468 }
469 }
470 while (!in.eof());
471}
472
473
474//_____________________________________________________________________________
475AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
476{
477/// Find the motif with the specified ID.
478
479 //AliCodeTimerAuto("",0);
480
481 return (AliMpVMotif*)fMotifs.GetValue(motifID);
482}
483
484//_____________________________________________________________________________
485AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
486 const TString& motifTypeID,
487 Double_t padDimensionX,
488 Double_t padDimensionY ) const
489{
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.
494
495 //AliCodeTimerAuto("",0);
496
497 AliMpVMotif* motif = FindMotif(motifID);
498
499 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
500 AliFatal("Motif has been already defined with a different type.");
501 return 0;
502 }
503
504 // check pad dimension in case of a normal motif
505 if ( motif &&
506 dynamic_cast<AliMpMotif*>(motif) &&
507 ( motif->GetPadDimensionX(0) != padDimensionX ||
508 motif->GetPadDimensionY(0) != padDimensionY ) ) {
509
510 AliFatal("Motif type has been already defined with different dimensions.");
511 return 0;
512
513 }
514
515 // check case of a special motif
516 if ( motif &&
517 ( padDimensionX == 0. && padDimensionY == 0.) &&
518 ! dynamic_cast<AliMpMotifSpecial*>(motif) ) {
519
520 AliFatal("Motif type has been already defined with different dimensions.");
521 return 0;
522
523 }
524
525 return motif;
526}
527
528//_____________________________________________________________________________
529AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
530{
531/// Find the motif type with the specified motif type ID.
532
533 //AliCodeTimerAuto("",0);
534
535 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
536}
537
538//_____________________________________________________________________________
539AliMpMotifPosition*
540AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
541{
542/// Find the motif position with the specified motif position ID.
543
544 //AliCodeTimerAuto("",0);
545
546 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID << 16);
547}