]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifMap.cxx
AliMUONDigitCalibrator
[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#ifdef WITH_ROOT
60 fMotifPositions2.SetOwner(false);
61#endif
5006ec94 62}
f79c58a5 63
5f91c9e8 64//_____________________________________________________________________________
630711ed 65AliMpMotifMap::AliMpMotifMap(TRootIOCtor* ioCtor)
5006ec94 66 : TObject(),
630711ed 67#ifdef WITH_STL
5006ec94 68 fMotifs(),
69 fMotifTypes(),
70 fMotifPositions(),
71 fMotifPositions2()
630711ed 72#endif
73#ifdef WITH_ROOT
74 fMotifs(ioCtor),
75 fMotifTypes(ioCtor),
76 fMotifPositions(ioCtor),
77 fMotifPositions2(ioCtor)
78#endif
5f91c9e8 79{
630711ed 80/// Root IO constructor
81
82#ifdef WITH_ROOT
83 fMotifPositions2.SetOwner(false);
84#endif
5f91c9e8 85}
86
87//_____________________________________________________________________________
dee1d5f1 88AliMpMotifMap::~AliMpMotifMap()
89{
90/// Destructor
5f91c9e8 91
92 // Delete all registered motifs, motif types, motif positions
93
f79c58a5 94#ifdef WITH_STL
5f91c9e8 95 for (MotifMapIterator im=fMotifs.begin(); im != fMotifs.end(); im++) {
96 delete im->second;
97 }
f79c58a5 98
5f91c9e8 99 for (MotifTypeMapIterator it=fMotifTypes.begin();
100 it != fMotifTypes.end(); it++) {
101 delete it->second;
102 }
f79c58a5 103
5f91c9e8 104 for (MotifPositionMapIterator ip=fMotifPositions.begin();
105 ip != fMotifPositions.end(); ip++) {
106 delete ip->second;
107 }
f79c58a5 108#endif
630711ed 109
5f91c9e8 110}
111
112//
113// private methods
114//
115
f79c58a5 116//_____________________________________________________________________________
117void AliMpMotifMap::PrintMotif(const AliMpVMotif* motif) const
118{
dee1d5f1 119/// Print the motif.
f79c58a5 120
121 cout << motif->GetID().Data() << " "
122 << motif->GetMotifType()->GetID() << " "
123 << motif->Dimensions().X() << " "
124 << motif->Dimensions().Y();
125}
126
127//_____________________________________________________________________________
128void AliMpMotifMap::PrintMotifType(const AliMpMotifType* motifType) const
129{
dee1d5f1 130/// Print the motif type.
f79c58a5 131
132 cout << motifType->GetID().Data() << " "
133 << motifType->GetNofPadsX() << " "
134 << motifType->GetNofPadsY() << " ";
135}
136
137//_____________________________________________________________________________
138void AliMpMotifMap::PrintMotifPosition(
139 const AliMpMotifPosition* motifPosition) const
140{
dee1d5f1 141/// Print the motif position.
f79c58a5 142
6d5f608a 143 cout << " ID " << motifPosition->GetID() << " "
144 << " Motif ID " << motifPosition->GetMotif()->GetID() << " "
145 << " Pos (X,Y) = (" << motifPosition->Position().X() << ","
146 << motifPosition->Position().Y() << ")";
f79c58a5 147}
148
149//_____________________________________________________________________________
150void AliMpMotifMap::PrintMotifPosition2(
151 const AliMpMotifPosition* motifPosition) const
152{
dee1d5f1 153/// Print the motif position.
f79c58a5 154
155 cout << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
156 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond() << " "
157 << setw(3) << motifPosition->GetHighIndicesLimit().GetFirst() << " "
158 << setw(3) << motifPosition->GetHighIndicesLimit().GetSecond() << " "
159 << motifPosition->GetID() << " ";
160}
161
5f91c9e8 162//_____________________________________________________________________________
163void AliMpMotifMap::PrintMotifs() const
164{
dee1d5f1 165/// Print all the motifs and their motif types
166/// for all motifs in the motifs map.
5f91c9e8 167
f79c58a5 168#ifdef WITH_STL
5f91c9e8 169 if (fMotifs.size()) {
170 cout << "Dump of Motif Map - " << fMotifs.size() << " entries:" << endl;
171 Int_t counter = 0;
172 for (MotifMapIterator i=fMotifs.begin(); i != fMotifs.end(); i++) {
173 const TString& id = (*i).first;
5f91c9e8 174 cout << "Map element "
175 << setw(3) << counter++ << " "
f79c58a5 176 << id.Data() << " " ;
177 PrintMotif((*i).second);
178 cout << endl;
5f91c9e8 179 }
180 cout << endl;
181 }
f79c58a5 182#endif
183
184#ifdef WITH_ROOT
185 if (fMotifs.GetSize()) {
186 cout << "Dump of Motif Map - " << fMotifs.GetSize() << " entries:" << endl;
187 Int_t counter = 0;
630711ed 188 AliMpExMapIterator* it = fMotifs.CreateIterator();
189 Int_t key;
190 AliMpVMotif* motif;
191
192 while ( ( motif = static_cast<AliMpVMotif*>(it->Next(key)) ) )
193 {
194 TString id = fMotifs.AliMpExMap::GetString(key);
f79c58a5 195 cout << "Map element "
196 << setw(3) << counter++ << " "
197 << id.Data() << " " ;
198 PrintMotif(motif);
199 cout << endl;
200 }
201 cout << endl;
630711ed 202 delete it;
f79c58a5 203 }
204#endif
5f91c9e8 205}
206
207//_____________________________________________________________________________
208void AliMpMotifMap::PrintMotifTypes() const
209{
dee1d5f1 210/// Print all the the motifs types and their motif dimensions
211/// for all motif types in the motif types map.
5f91c9e8 212
f79c58a5 213#ifdef WITH_STL
5f91c9e8 214 if (fMotifTypes.size()) {
215 cout << "Dump of Motif Type Map - " << fMotifTypes.size() << " entries:" << endl;
216 Int_t counter = 0;
217 for (MotifTypeMapIterator i=fMotifTypes.begin(); i != fMotifTypes.end(); i++) {
218 const TString& id = (*i).first;
5f91c9e8 219 cout << "Map element "
220 << setw(3) << counter++ << " "
f79c58a5 221 << id.Data() << " ";
222 PrintMotifType((*i).second);
223 cout << endl;
224 }
225 cout << endl;
226 }
227#endif
228
229#ifdef WITH_ROOT
230 if (fMotifTypes.GetSize()) {
231 cout << "Dump of Motif Type Map - " << fMotifTypes.GetSize() << " entries:" << endl;
630711ed 232 Int_t counter = 0;
233 AliMpExMapIterator* it = fMotifTypes.CreateIterator();
234 Int_t key;
235 AliMpMotifType* motifType;
236
237 while ( ( motifType = static_cast<AliMpMotifType*>(it->Next(key)) ) )
238 {
5006ec94 239 TString id = AliMpExMap::GetString(key);
f79c58a5 240 cout << "Map element "
241 << setw(3) << counter++ << " "
242 << id.Data() << " " ;
243 PrintMotifType(motifType);
244 cout << endl;
5f91c9e8 245 }
246 cout << endl;
630711ed 247 delete it;
5f91c9e8 248 }
f79c58a5 249#endif
5f91c9e8 250}
251
6d5f608a 252//_____________________________________________________________________________
253void
254AliMpMotifMap::GetAllMotifPositionsIDs(TArrayI& ecn) const
255{
490da820 256/// Fill the given array with all motif positions IDs (electronic card numbers)
257/// defined in the map
258
6d5f608a 259#ifdef WITH_STL
260 ecn.Set(fMotifPositions.size());
261 Int_t i(0);
262 MotifPositionMapIterator it;
263 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
264 AliMpMotifPosition* motifPosition = (*it).second;
265 ecn[i++] = motifPosition->GetID();
266 }
267#endif
268
269#ifdef WITH_ROOT
270 ecn.Set(fMotifPositions.GetSize());
630711ed 271 TIter next(fMotifPositions.CreateIterator());
272 AliMpMotifPosition* motifPosition;
6d5f608a 273 Int_t i(0);
630711ed 274 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
6d5f608a 275 {
6d5f608a 276 ecn[i] = motifPosition->GetID();
277 ++i;
278 }
6d5f608a 279#endif
280}
281
a70d5d20 282//_____________________________________________________________________________
283UInt_t AliMpMotifMap::GetNofMotifPositions() const
284{
285/// Return the number of all motif positions IDs (electronic card numbers)
286
287#ifdef WITH_STL
288 return fMotifPositions.size();
289#endif
290
291#ifdef WITH_ROOT
292 return fMotifPositions.GetSize();
293#endif
294}
295
296//_____________________________________________________________________________
297AliMpMotifPosition* AliMpMotifMap::GetMotifPosition(UInt_t index) const
298{
299/// Return the motif position which is in the map on the index-th position
300
630711ed 301 AliCodeTimerAuto("");
302
a70d5d20 303 if ( index >= GetNofMotifPositions() ) {
304 AliErrorStream() << "Index " << index << " outside limits." << endl;
305 return 0;
306 }
307
308#ifdef WITH_STL
309 MotifPositionMapIterator it = fMotifPositions.begin();
310 std::advance(it, index);
311 return it->second;
312#endif
313
314#ifdef WITH_ROOT
630711ed 315 TIter next(fMotifPositions.CreateIterator());
316 while (index-- > 0) next();
317 return static_cast<AliMpMotifPosition*>(next());
a70d5d20 318#endif
319}
320
3283cfc7 321//_____________________________________________________________________________
322Int_t AliMpMotifMap::CalculateNofPads() const
323{
abaf1dad 324/// Calculate total number of pads in the map
325
3283cfc7 326 Int_t nofPads = 0;
327
328#ifdef WITH_STL
329 MotifPositionMapIterator it;
330 for (it=fMotifPositions.begin(); it != fMotifPositions.end(); it++) {
331 AliMpMotifPosition* motifPosition = (*it).second;
332 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
333 }
334#endif
335
336#ifdef WITH_ROOT
630711ed 337 TIter next(fMotifPositions.CreateIterator());
338 AliMpMotifPosition* motifPosition;
339 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
340 {
3283cfc7 341 nofPads += motifPosition->GetMotif()->GetMotifType()->GetNofPads();
342 }
343#endif
344
3283cfc7 345 return nofPads;
346}
347
5f91c9e8 348//_____________________________________________________________________________
349void AliMpMotifMap::PrintMotifPositions() const
350{
abaf1dad 351/// Print all motif positions.
5f91c9e8 352
f79c58a5 353#ifdef WITH_STL
5f91c9e8 354 if (fMotifPositions.size()) {
355 cout << "Dump of Motif Position Map - " << fMotifPositions.size() << " entries:" << endl;
356 Int_t counter = 0;
357 for (MotifPositionMapIterator i=fMotifPositions.begin();
358 i != fMotifPositions.end(); i++) {
359
5f91c9e8 360 cout << "Map element "
f79c58a5 361 << setw(3) << counter++ << " ";
362 PrintMotifPosition((*i).second);
363 cout << endl;
5f91c9e8 364 }
365 cout << endl;
366 }
f79c58a5 367#endif
368
369#ifdef WITH_ROOT
370 if (fMotifPositions.GetSize()) {
dee1d5f1 371 cout << "Dump of Motif Position Map - " << fMotifPositions.GetSize() << " entries:" << endl;
f79c58a5 372 Int_t counter = 0;
630711ed 373 TIter next(fMotifPositions.CreateIterator());
374 AliMpMotifPosition* motifPosition;
375
376 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
377 {
f79c58a5 378 cout << "Map element "
379 << setw(3) << counter++ << " ";
380 PrintMotifPosition(motifPosition);
381 cout << endl;
382 }
383 cout << endl;
384 }
385#endif
5f91c9e8 386}
387
388//_____________________________________________________________________________
389void AliMpMotifMap::PrintMotifPositions2() const
390{
abaf1dad 391/// Print all motif positions from the second map
dee1d5f1 392/// (by global indices)
5f91c9e8 393
f79c58a5 394#ifdef WITH_STL
5f91c9e8 395 if (fMotifPositions2.size()) {
396 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.size() << " entries:" << endl;
397 Int_t counter = 0;
398 for (MotifPositionMap2Iterator i=fMotifPositions2.begin();
399 i != fMotifPositions2.end(); i++) {
400
5f91c9e8 401 cout << "Map element "
f79c58a5 402 << setw(3) << counter++ << " ";
403 PrintMotifPosition2((*i).second);
404 cout << endl;
405 }
406 cout << endl;
407 }
408#endif
409
410#ifdef WITH_ROOT
630711ed 411
412 if (fMotifPositions2.GetSize())
413 {
f79c58a5 414 cout << "Dump of Motif Position Map 2 - " << fMotifPositions2.GetSize() << " entries:" << endl;
630711ed 415 TIter next(fMotifPositions2.CreateIterator());
416 AliMpMotifPosition* motifPosition(0x0);
f79c58a5 417 Int_t counter = 0;
630711ed 418
419 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
420 {
421 cout << "Map element " << setw(3) << counter++ << " ";
f79c58a5 422 PrintMotifPosition2(motifPosition);
423 cout << endl;
5f91c9e8 424 }
425 cout << endl;
426 }
f79c58a5 427#endif
5f91c9e8 428}
429
430//
431// public methods
432//
433
434//_____________________________________________________________________________
435Bool_t AliMpMotifMap::AddMotif(AliMpVMotif* motif, Bool_t warn)
436{
dee1d5f1 437/// Add the specified motif
438/// if the motif with this ID is not yet present.
5f91c9e8 439
440 AliMpVMotif* found = FindMotif(motif->GetID());
441 if (found) {
442 if (warn && found == motif)
2c605e66 443 AliWarningStream() << "The motif is already in map." << endl;
444
445 if (warn && found != motif) {
446 AliWarningStream()
447 << "Another motif with the same ID is already in map." << endl;
448 }
5f91c9e8 449 return false;
450 }
451
f79c58a5 452#ifdef WITH_STL
5f91c9e8 453 fMotifs[motif->GetID()] = motif;
f79c58a5 454#endif
455
456#ifdef WITH_ROOT
5006ec94 457 fMotifs.Add(motif->GetID(), motif);
f79c58a5 458#endif
459
5f91c9e8 460 return true;
461}
462
463//_____________________________________________________________________________
464Bool_t AliMpMotifMap::AddMotifType(AliMpMotifType* motifType, Bool_t warn)
465{
dee1d5f1 466/// Add the specified motif type
467/// if the motif with this ID is not yet present.
5f91c9e8 468
469 AliMpMotifType* found = FindMotifType(motifType->GetID());
470 if (found) {
471 if (warn && found == motifType)
2c605e66 472 AliWarningStream() << "The motif type is already in map." << endl;
473
474 if (warn && found != motifType) {
475 AliWarningStream()
476 << "Another motif type with the same ID is already in map." << endl;
477 }
5f91c9e8 478 return false;
479 }
480
f79c58a5 481#ifdef WITH_STL
5f91c9e8 482 fMotifTypes[motifType->GetID()] = motifType;
f79c58a5 483#endif
484
485#ifdef WITH_ROOT
5006ec94 486 fMotifTypes.Add(motifType->GetID(), motifType);
f79c58a5 487#endif
488
5f91c9e8 489 return true;
490}
491
492//_____________________________________________________________________________
493Bool_t AliMpMotifMap::AddMotifPosition(AliMpMotifPosition* motifPosition, Bool_t warn)
494{
dee1d5f1 495/// Add the specified motif position
496/// if this position is not yet present.
5f91c9e8 497
498 AliMpMotifPosition* found = FindMotifPosition(motifPosition->GetID());
7a854749 499 if (found) {
500 if (warn && found == motifPosition) {
2c605e66 501 AliWarningStream()
502 << "ID: " << motifPosition->GetID()
7a854749 503 << " found: " << found
2c605e66 504 << " new: " << motifPosition << endl
505 << "This motif position is already in map." << endl;
7a854749 506 }
2c605e66 507
7a854749 508 if (warn && found != motifPosition) {
2c605e66 509 AliWarningStream()
510 << "ID: " << motifPosition->GetID()
7a854749 511 << " found: " << found
2c605e66 512 << " new: " << motifPosition << endl
513 << "Another motif position with the same ID is already in map."
514 << endl;
515 }
516
5f91c9e8 517 return false;
518 }
519
f79c58a5 520#ifdef WITH_STL
5f91c9e8 521 fMotifPositions[motifPosition->GetID()] = motifPosition;
f79c58a5 522#endif
523
524#ifdef WITH_ROOT
630711ed 525 fMotifPositions.Add(motifPosition->GetID() << 16, motifPosition);
f79c58a5 526#endif
527
5f91c9e8 528 return true;
529}
530
531//_____________________________________________________________________________
532void AliMpMotifMap::FillMotifPositionMap2()
533{
dee1d5f1 534/// Fill the second map (by global indices) of motif positions.
5f91c9e8 535
f79c58a5 536#ifdef WITH_STL
5f91c9e8 537 if (fMotifPositions2.size() > 0 ) {
2c605e66 538 AliWarningStream() << "Map has been already filled." << endl;
5f91c9e8 539 return;
540 }
541
542 for (MotifPositionMapIterator ip=fMotifPositions.begin();
543 ip != fMotifPositions.end(); ip++) {
544
545 fMotifPositions2[(*ip).second->GetLowIndicesLimit()] = (*ip).second;
546 }
f79c58a5 547#endif
548
549#ifdef WITH_ROOT
550 if (fMotifPositions2.GetSize() > 0 ) {
2c605e66 551 AliWarningStream() <<"Map has been already filled." << endl;
f79c58a5 552 return;
553 }
554
630711ed 555 TIter next(fMotifPositions.CreateIterator());
556 AliMpMotifPosition* motifPosition(0x0);
557 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
558 {
5006ec94 559 fMotifPositions2.Add(motifPosition->GetLowIndicesLimit(), motifPosition);
f79c58a5 560 }
561#endif
5f91c9e8 562
563}
564
565//_____________________________________________________________________________
6d5f608a 566void AliMpMotifMap::Print(const char* opt) const
5f91c9e8 567{
dee1d5f1 568/// Print the motifs and motif types maps.
5f91c9e8 569
6d5f608a 570 TString sopt(opt);
571
572 sopt.ToUpper();
573
574 if ( sopt.Contains("MOTIFS") || sopt == "ALL" ) PrintMotifs();
575 if ( sopt.Contains("MOTIFTYPES") || sopt == "ALL" ) PrintMotifTypes();
576 if ( sopt.Contains("MOTIFPOSITIONS") || sopt == "ALL" ) PrintMotifPositions();
577 if ( sopt.Contains("MOTIFPOSITIONS2") || sopt == "ALL" ) PrintMotifPositions2();
5f91c9e8 578}
579
580//_____________________________________________________________________________
581void AliMpMotifMap::PrintGlobalIndices(const char* fileName) const
582{
abaf1dad 583/// Print all motif positions and their global indices.
5f91c9e8 584
585 ofstream out(fileName, ios::out);
586
f79c58a5 587#ifdef WITH_STL
5f91c9e8 588 if (fMotifPositions.size()) {
589 for (MotifPositionMapIterator i=fMotifPositions.begin();
590 i != fMotifPositions.end(); i++) {
591
592 AliMpMotifPosition* motifPosition = (*i).second;
593 out << setw(5) << motifPosition->GetID() << " "
594 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
595 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
596 << endl;
597 }
598 out << endl;
599 }
f79c58a5 600#endif
601
602#ifdef WITH_ROOT
603 if (fMotifPositions.GetSize()) {
630711ed 604 TIter next(fMotifPositions.CreateIterator());
605 AliMpMotifPosition* motifPosition;
606 while ( ( motifPosition = static_cast<AliMpMotifPosition*>(next()) ) )
607 {
f79c58a5 608 out << setw(5) << motifPosition->GetID() << " "
609 << setw(3) << motifPosition->GetLowIndicesLimit().GetFirst() << " "
610 << setw(3) << motifPosition->GetLowIndicesLimit().GetSecond()
611 << endl;
612 }
613 out << endl;
614 }
615#endif
5f91c9e8 616}
617
618//_____________________________________________________________________________
619void AliMpMotifMap::UpdateGlobalIndices(const char* fileName)
620{
abaf1dad 621/// Update the motif positions global indices from the file.
5f91c9e8 622
623 ifstream in(fileName, ios::in);
624
625 Int_t motifPositionId, offx, offy;
626
627 do {
628 in >> motifPositionId >> offx >> offy;
629
630 if (in.eof()) {
631 FillMotifPositionMap2();
632 return;
633 }
634
635 AliMpMotifPosition* motifPosition = FindMotifPosition(motifPositionId);
636
637 if (motifPosition) {
2c605e66 638 AliDebugStream(1)
639 << "Processing "
5f91c9e8 640 << motifPosition->GetID() << " " << offx << " " << offy << endl;
641
642 motifPosition->SetLowIndicesLimit(AliMpIntPair(offx, offy));
643
644 Int_t offx2
645 = offx + motifPosition->GetMotif()->GetMotifType()->GetNofPadsX() - 1;
646
647 Int_t offy2
648 = offy + motifPosition->GetMotif()->GetMotifType()->GetNofPadsY() - 1;
649
650 motifPosition->SetHighIndicesLimit(AliMpIntPair(offx2, offy2));
651 }
652 else {
2c605e66 653 AliWarningStream()
654 << "Motif position " << motifPositionId << " not found" << endl;
5f91c9e8 655 }
656 }
657 while (!in.eof());
658}
659
660
661//_____________________________________________________________________________
662AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID) const
663{
abaf1dad 664/// Find the motif with the specified ID.
5f91c9e8 665
630711ed 666 //AliCodeTimerAuto("");
667
f79c58a5 668#ifdef WITH_STL
5f91c9e8 669 MotifMapIterator i = fMotifs.find(motifID);
5f91c9e8 670 if (i != fMotifs.end())
671 return (*i).second;
672 else
673 return 0;
f79c58a5 674#endif
675
676#ifdef WITH_ROOT
5006ec94 677 return (AliMpVMotif*)fMotifs.GetValue(motifID);
f79c58a5 678#endif
5f91c9e8 679}
680
681//_____________________________________________________________________________
682AliMpVMotif* AliMpMotifMap::FindMotif(const TString& motifID,
7a854749 683 const TString& motifTypeID,
684 const TVector2& padDimensions ) const
5f91c9e8 685{
abaf1dad 686/// Find the motif with the specified ID and returns it
dee1d5f1 687/// only if its motif type and motif dimensions agree
688/// with the given motifTypeID and motifDimensions.
689/// Disagreement causes fatal error.
690
630711ed 691 //AliCodeTimerAuto("");
692
5f91c9e8 693 AliMpVMotif* motif = FindMotif(motifID);
694
695 if (motif && motif->GetMotifType()->GetID() != motifTypeID) {
630711ed 696 AliFatal("Motif has been already defined with a different type.");
5f91c9e8 697 return 0;
698 }
699
700 // check pad dimension in case of a normal motif
701 if (motif &&
702 dynamic_cast<AliMpMotif*>(motif) &&
703 ( motif->GetPadDimensions(0).X() != padDimensions.X() ||
704 motif->GetPadDimensions(0).Y() != padDimensions.Y())) {
705
630711ed 706 AliFatal("Motif type has been already defined with different dimensions.");
5f91c9e8 707 return 0;
708
709 }
710
711 // check case of a special motif
712 if (motif &&
713 (padDimensions.X() == 0. && padDimensions.Y() == 0.) &&
714 !dynamic_cast<AliMpMotifSpecial*>(motif)) {
715
630711ed 716 AliFatal("Motif type has been already defined with different dimensions.");
5f91c9e8 717 return 0;
718
719 }
720
721 return motif;
722}
723
724//_____________________________________________________________________________
725AliMpMotifType* AliMpMotifMap::FindMotifType(const TString& motifTypeID) const
726{
dee1d5f1 727/// Find the motif type with the specified motif type ID.
5f91c9e8 728
630711ed 729 //AliCodeTimerAuto("");
730
f79c58a5 731#ifdef WITH_STL
5f91c9e8 732 MotifTypeMapIterator i = fMotifTypes.find(motifTypeID);
5f91c9e8 733 if (i != fMotifTypes.end())
734 return (*i).second;
735 else
736 return 0;
f79c58a5 737#endif
738
739#ifdef WITH_ROOT
5006ec94 740 return (AliMpMotifType*)fMotifTypes.GetValue(motifTypeID);
f79c58a5 741#endif
5f91c9e8 742}
743
744//_____________________________________________________________________________
7a854749 745AliMpMotifPosition*
746AliMpMotifMap::FindMotifPosition(Int_t motifPositionID) const
5f91c9e8 747{
dee1d5f1 748/// Find the motif position with the specified motif position ID.
5f91c9e8 749
630711ed 750 //AliCodeTimerAuto("");
751
f79c58a5 752#ifdef WITH_STL
5f91c9e8 753 MotifPositionMapIterator i = fMotifPositions.find(motifPositionID);
5f91c9e8 754 if (i != fMotifPositions.end())
755 return (*i).second;
756 else
757 return 0;
f79c58a5 758#endif
759
760#ifdef WITH_ROOT
630711ed 761 return (AliMpMotifPosition*)fMotifPositions.GetValue(motifPositionID << 16);
f79c58a5 762#endif
5f91c9e8 763}
764
f79c58a5 765/*
5f91c9e8 766//_____________________________________________________________________________
7a854749 767AliMpMotifPosition*
768AliMpMotifMap::FindMotifPosition(const AliMpIntPair& indices) const
5f91c9e8 769{
dee1d5f1 770/// Find the last motif position which has the global indices (low limit)
771/// less then the indices specified.
5f91c9e8 772
f79c58a5 773#ifdef WITH_STL
5f91c9e8 774 MotifPositionMap2Iterator found
775 = fMotifPositions2.lower_bound(indices);
776
777 if (found == fMotifPositions2.end()) found--;
778
779 MotifPositionMap2Iterator i=found;
780 do {
781 AliMpIntPair low = (*i).second->GetLowIndicesLimit();
782 AliMpIntPair up = (*i).second->GetHighIndicesLimit();
783
784 if ( indices.GetFirst() >= low.GetFirst() &&
785 indices.GetSecond() >= low.GetSecond() &&
786 indices.GetFirst() <= up.GetFirst() &&
787 indices.GetSecond() <= up.GetSecond())
788
789 return (*i).second;
790 }
791 while ( i-- != fMotifPositions2.begin());
792
793 return 0;
f79c58a5 794#endif
795
796#ifdef WITH_ROOT
797 // HOW TO DO THIS WITH ROOT ????
798 // Fortunately it seems not to be used anywhere
799 Fatal("FindMotifPosition", "Difficult in Root to do this.");
800 return 0;
801#endif
5f91c9e8 802}
f79c58a5 803*/