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