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