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