Commenting out the infamous speed eater = StdoutToAliDebug until a better solution...
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifType.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: AliMpMotifType.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
5f91c9e8 18// Category: motif
19//
20// Class AliMpMotifType
21// --------------------
22// Class that defines the motif properties.
dbe945cc 23// Included in AliRoot: 2003/05/02
5f91c9e8 24// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
25
5f91c9e8 26#include "AliMpMotifType.h"
27#include "AliMpMotifTypePadIterator.h"
28#include "AliMpConnection.h"
29
da635033 30#include "AliLog.h"
31#include "AliMpFiles.h"
32#include "TSystem.h"
63ed9c6b 33
da635033 34#include <Riostream.h>
5f91c9e8 35
13985652 36/// \cond CLASSIMP
63ed9c6b 37ClassImp(AliMpMotifType)
13985652 38/// \endcond
39
40const Int_t AliMpMotifType::fgkPadNumForA = 65;
63ed9c6b 41
5f91c9e8 42//______________________________________________________________________________
43AliMpMotifType::AliMpMotifType(const TString &id)
44 : TObject(),
45 fID(id),
46 fNofPadsX(0),
47 fNofPadsY(0),
48 fVerboseLevel(0),
5006ec94 49#ifdef WITH_STL
5f91c9e8 50 fConnections()
5006ec94 51#endif
52#ifdef WITH_ROOT
53 fConnections(true)
54#endif
5f91c9e8 55{
dee1d5f1 56 /// Standard constructor
da635033 57 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
5f91c9e8 58}
59
60//______________________________________________________________________________
61AliMpMotifType::AliMpMotifType()
62 : TObject(),
63 fID(""),
64 fNofPadsX(0),
65 fNofPadsY(0),
66 fVerboseLevel(0),
67 fConnections()
68{
dee1d5f1 69 /// Default constructor
da635033 70 AliDebug(1,Form("this=%p",this));
71}
72
73//______________________________________________________________________________
74AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
75: TObject(),
76 fID(""),
77 fNofPadsX(0),
78 fNofPadsY(0),
79 fVerboseLevel(0),
80 fConnections()
81{
144129ae 82 /// Copy constructor
83
da635033 84 AliDebug(1,Form("this=%p (copy ctor)",this));
85 rhs.Copy(*this);
86}
87
88//______________________________________________________________________________
89AliMpMotifType&
90AliMpMotifType::operator=(const AliMpMotifType& rhs)
91{
144129ae 92 /// Assignment operator
93
da635033 94 TObject::operator=(rhs);
95 rhs.Copy(*this);
96 return *this;
97}
98
99//______________________________________________________________________________
100TObject*
101AliMpMotifType::Clone(const char* /*newname*/) const
102{
103 /// Returns a full copy of this object
104 return new AliMpMotifType(*this);
105}
106
107//______________________________________________________________________________
108void
109AliMpMotifType::Copy(TObject& object) const
110{
144129ae 111 /// Copy object
112
da635033 113 TObject::Copy(object);
114 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
115 mt.fID = fID;
116 mt.fNofPadsX = fNofPadsX;
117 mt.fNofPadsY = fNofPadsY;
118 mt.fVerboseLevel = fVerboseLevel;
119 mt.fConnections = fConnections;
5f91c9e8 120}
121
122//______________________________________________________________________________
dee1d5f1 123AliMpMotifType::~AliMpMotifType()
124{
125/// Destructor
5f91c9e8 126
f79c58a5 127#ifdef WITH_STL
2f2452f8 128 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 129 i!=fConnections.end();++i)
130 delete i->second;
131
132 fConnections.erase(fConnections.begin(),fConnections.end());
f79c58a5 133#endif
da635033 134
135 AliDebug(1,Form("this=%p",this));
4cb363de 136// StdoutToAliDebug(1,this->Print(););
5f91c9e8 137}
138
139//______________________________________________________________________________
140AliMpVPadIterator* AliMpMotifType::CreateIterator() const
141{
dee1d5f1 142/// Create new motif type iterator
143
5f91c9e8 144 return new AliMpMotifTypePadIterator(this);
145}
146
147//______________________________________________________________________________
148void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
149{
dee1d5f1 150 /// Change the number of pads in this motif
5f91c9e8 151
152 fNofPadsX = nofPadsX;
153 fNofPadsY = nofPadsY;
154}
155
156
157//______________________________________________________________________________
158Int_t AliMpMotifType::PadNum(const TString &padName) const
159{
dee1d5f1 160 /// Transform a pad name into the equivalent pad number
161
5f91c9e8 162 if ( (padName[0]>='A') && (padName[0]<='Z') )
163 return fgkPadNumForA+padName[0]-'A';
164 else
165 return atoi(padName.Data());
166}
167
168//______________________________________________________________________________
169TString AliMpMotifType::PadName(Int_t padNum) const
170{
dee1d5f1 171 /// Transform a pad number into its equivalent pad name
172
5f91c9e8 173 if (padNum<fgkPadNumForA)
174 return Form("%d",padNum);
175 else
176 return char('A'+padNum-fgkPadNumForA);
177}
178
179//______________________________________________________________________________
180void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
181 AliMpConnection* connection)
182{
dee1d5f1 183 /// Add the connection to the map
5f91c9e8 184
f79c58a5 185#ifdef WITH_STL
5f91c9e8 186 fConnections[localIndices]=connection;
f79c58a5 187#endif
188
189#ifdef WITH_ROOT
5006ec94 190 fConnections.Add(localIndices, connection);
f79c58a5 191#endif
192
5f91c9e8 193 connection->SetOwner(this);
194}
f79c58a5 195
5f91c9e8 196//______________________________________________________________________________
197AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
198{
dee1d5f1 199 /// Retrieve the AliMpConnection pointer from its pad num
200
f79c58a5 201#ifdef WITH_STL
2f2452f8 202 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 203 i!=fConnections.end();++i)
204 if (i->second->GetPadNum()==padNum) return i->second;
205 return 0;
f79c58a5 206#endif
207
208#ifdef WITH_ROOT
5006ec94 209 TExMapIter i = fConnections.GetIterator();
f79c58a5 210 Long_t key, value;
211 while ( i.Next(key, value) ) {
212 AliMpConnection* connection = (AliMpConnection*)value;
213 if (connection->GetPadNum()==padNum) return connection;
214 }
215 return 0;
216#endif
5f91c9e8 217}
218
219//______________________________________________________________________________
220AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
2f2452f8 221 const AliMpIntPair& localIndices) const
5f91c9e8 222{
dee1d5f1 223 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
224
5f91c9e8 225 if (!localIndices.IsValid()) return 0;
226
f79c58a5 227#ifdef WITH_STL
2f2452f8 228 ConnectionMapCIterator i = fConnections.find(localIndices);
5f91c9e8 229 if (i != fConnections.end())
230 return i->second;
231 else return 0;
f79c58a5 232#endif
233
234#ifdef WITH_ROOT
5006ec94 235 return (AliMpConnection*)fConnections.GetValue(localIndices);
f79c58a5 236#endif
5f91c9e8 237}
238
239//______________________________________________________________________________
240AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
241{
dee1d5f1 242 /// Return the connection for the given gassiplex number
243
f79c58a5 244#ifdef WITH_STL
2f2452f8 245 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 246 i!=fConnections.end();++i)
247 if (i->second->GetGassiNum()==gassiNum) return i->second;
248 return 0;
f79c58a5 249#endif
250
251#ifdef WITH_ROOT
5006ec94 252 TExMapIter i = fConnections.GetIterator();
f79c58a5 253 Long_t key, value;
254 while ( i.Next(key, value) ) {
255 AliMpConnection* connection = (AliMpConnection*)value;
256 if (connection->GetGassiNum()==gassiNum) return connection;
257 }
258 return 0;
259#endif
5f91c9e8 260}
f79c58a5 261
5f91c9e8 262//______________________________________________________________________________
263AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
264{
dee1d5f1 265 /// Give the connection related to the given kapton number
266
f79c58a5 267#ifdef WITH_STL
2f2452f8 268 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 269 i!=fConnections.end();++i)
270 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
271 return 0;
f79c58a5 272#endif
273
274#ifdef WITH_ROOT
5006ec94 275 TExMapIter i = fConnections.GetIterator();
f79c58a5 276 Long_t key, value;
277 while ( i.Next(key, value) ) {
278 AliMpConnection* connection = (AliMpConnection*)value;
279 if (connection->GetKaptonNum()==kaptonNum) return connection;
280 }
281 return 0;
282#endif
5f91c9e8 283}
284//______________________________________________________________________________
285AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
286{
dee1d5f1 287 /// Retrieve the connection from a Berg connector number
288
f79c58a5 289#ifdef WITH_STL
2f2452f8 290 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 291 i!=fConnections.end();++i)
292 if (i->second->GetBergNum()==bergNum) return i->second;
293 return 0;
f79c58a5 294#endif
295
296#ifdef WITH_ROOT
5006ec94 297 TExMapIter i = fConnections.GetIterator();
f79c58a5 298 Long_t key, value;
299 while ( i.Next(key, value) ) {
300 AliMpConnection* connection = (AliMpConnection*)value;
301 if (connection->GetBergNum()==bergNum) return connection;
302 }
303 return 0;
304#endif
5f91c9e8 305}
306
307
308//______________________________________________________________________________
309AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
f79c58a5 310 const AliMpConnection* connection) const
5f91c9e8 311{
dee1d5f1 312 /// Retrieve the pad position from the connection pointer.
313 /// Not to be used widely, since it use a search in the
314 /// connection list...
5f91c9e8 315
f79c58a5 316#ifdef WITH_STL
2f2452f8 317 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 318 i!=fConnections.end();++i)
319 if (i->second==connection) return i->first;
f79c58a5 320#endif
321
322#ifdef WITH_ROOT
5006ec94 323 TExMapIter i = fConnections.GetIterator();
f79c58a5 324 Long_t key, value;
325 while ( i.Next(key, value) ) {
326 AliMpConnection* aConnection = (AliMpConnection*)value;
5006ec94 327 if (aConnection == connection) return AliMpExMap::GetPair(key);
f79c58a5 328 }
329#endif
330
331 return AliMpIntPair::Invalid();
5f91c9e8 332}
333
334//______________________________________________________________________________
335AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
336{
dee1d5f1 337 /// Retrieve the AliMpConnection pointer from its pad num
338
f79c58a5 339#ifdef WITH_STL
2f2452f8 340 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 341 i!=fConnections.end();++i)
342 if (i->second->GetPadNum()==padNum) return i->first;
f79c58a5 343#endif
5f91c9e8 344
f79c58a5 345#ifdef WITH_ROOT
5006ec94 346 TExMapIter i = fConnections.GetIterator();
f79c58a5 347 Long_t key, value;
348 while ( i.Next(key, value) ) {
349 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 350 if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
f79c58a5 351 }
352#endif
5f91c9e8 353 return AliMpIntPair::Invalid();
354}
355
356//______________________________________________________________________________
357AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
358{
dee1d5f1 359 /// Return the connection for the given gassiplex number
360
f79c58a5 361#ifdef WITH_STL
2f2452f8 362 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 363 i!=fConnections.end();++i)
364 if (i->second->GetGassiNum()==gassiNum) return i->first;
f79c58a5 365#endif
366
367#ifdef WITH_ROOT
5006ec94 368 TExMapIter i = fConnections.GetIterator();
f79c58a5 369 Long_t key, value;
370 while ( i.Next(key, value) ) {
371 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 372 if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
f79c58a5 373 }
374#endif
5f91c9e8 375
376 return AliMpIntPair::Invalid();
377}
378
379//______________________________________________________________________________
380AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
381{
dee1d5f1 382 /// Give the connection related to the given kapton number
383
f79c58a5 384#ifdef WITH_STL
2f2452f8 385 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 386 i!=fConnections.end();++i)
387 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
f79c58a5 388#endif
389
390#ifdef WITH_ROOT
5006ec94 391 TExMapIter i = fConnections.GetIterator();
f79c58a5 392 Long_t key, value;
393 while ( i.Next(key, value) ) {
394 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 395 if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
f79c58a5 396 }
397#endif
5f91c9e8 398
399 return AliMpIntPair::Invalid();
400}
401
402//______________________________________________________________________________
403AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
404{
dee1d5f1 405 /// Retrieve the connection from a Berg connector number
406
f79c58a5 407#ifdef WITH_STL
2f2452f8 408 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 409 i!=fConnections.end();++i)
410 if (i->second->GetBergNum()==bergNum) return i->first;
f79c58a5 411#endif
412
413#ifdef WITH_ROOT
5006ec94 414 TExMapIter i = fConnections.GetIterator();
f79c58a5 415 Long_t key, value;
416 while ( i.Next(key, value) ) {
417 AliMpConnection* connection = (AliMpConnection*)value;
5006ec94 418 if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
f79c58a5 419 }
420#endif
5f91c9e8 421
422 return AliMpIntPair::Invalid();
423}
424
425//______________________________________________________________________________
f79c58a5 426Int_t AliMpMotifType::GetNofPads() const
427{
dee1d5f1 428/// Return the number of pads
f79c58a5 429
430#ifdef WITH_STL
431 return fConnections.size();
432#endif
433
434#ifdef WITH_ROOT
435 return fConnections.GetSize();
436#endif
437}
438
439//______________________________________________________________________________
5f91c9e8 440Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
441{
13985652 442 /// Return true if the pad indexed by \a localIndices has a connection
dee1d5f1 443
5f91c9e8 444 if (!localIndices.IsValid()) return false;
445
f79c58a5 446#ifdef WITH_STL
5f91c9e8 447 return fConnections.find(localIndices)!=fConnections.end();
f79c58a5 448#endif
5f91c9e8 449
f79c58a5 450#ifdef WITH_ROOT
5006ec94 451 TObject* value = fConnections.GetValue(localIndices);
f79c58a5 452 return value!=0;
453#endif
5f91c9e8 454}
455
456//______________________________________________________________________________
457void AliMpMotifType::Print(Option_t *option) const
458{
dee1d5f1 459 /// Print the map of the motif. In each cell, the value
460 /// printed depends of option, as the following:
461 /// - option="N" the "name" of the pad is written
462 /// - option="K" the Kapton connect. number attached to the pad is written
463 /// - option="B" the Berg connect. number attached to the pad is written
464 /// - option="G" the Gassiplex channel number attached to the pad is written
465 /// otherwise the number of the pad is written
466 ///
467 /// NOTE : this method is really not optimized, in case 'N' or '',
468 /// but the Print() this should not be very important in a Print() method
5f91c9e8 469
470 switch (option[0]){
471 case 'N':cout<<"Name mapping";
472 break;
473 case 'K':cout<<"Kapton mapping";
474 break;
475 case 'B':cout<<"Berg mapping";
476 break;
477 case 'G':cout<<"Gassiplex number mapping";
478 break;
479 default:cout<<"Pad mapping";
480 }
481 cout<<" in the motif "<<fID<<endl;
482 cout<<"-----------------------------------"<<endl;
483
484 for (Int_t j=fNofPadsY-1;j>=0;j--){
485 for (Int_t i=0;i<fNofPadsX;i++){
486 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
487 TString str;
488 if (connexion){
da635033 489 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
490
491 switch (option[0]){
492 case 'N':str=PadName(connexion->GetPadNum());
493 break;
494 case 'K':str=Form("%d",connexion->GetKaptonNum());
495 break;
496 case 'B':str=Form("%d",connexion->GetBergNum());
497 break;
498 case 'G':str=Form("%d",connexion->GetGassiNum());
499 break;
500 default:str= Form("%d",connexion->GetPadNum());
501 }
502 cout<<setw(2)<<str;
5f91c9e8 503 } else cout<<setw(2)<<"--";
504 cout<<" ";
505 }
506 cout<<endl;
507 }
508}
da635033 509
510//_____________________________________________________________________________
511Bool_t
512AliMpMotifType::Save() const
513{
514 return Save(fID.Data());
515}
516
517//_____________________________________________________________________________
518Bool_t
519AliMpMotifType::Save(const char* motifName) const
520{
521 /// Generate the 2 files needed to describe the motif
522
523 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
524
525 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
526
527 // first a protection : do not allow overwriting existing files...
528 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
529 if (test==kFALSE) // AccessPathName has a strange return value convention...
530 {
531 AliError("Cannot overwrite existing padPos file");
532 return kFALSE;
533 }
534 test = gSystem->AccessPathName(motifTypeFileName.Data());
535 if (test==kFALSE)
536 {
537 AliError("Cannot overwrite existing motifType file");
538 return kFALSE;
539 }
540
541 ofstream padPosFile(padPosFileName.Data());
542 ofstream motifFile(motifTypeFileName.Data());
543
544 motifFile << "# Motif " << motifName << endl
545 << "#" << endl
546 << "#connecteur_berg kapton padname not_used" << endl
547 << "#for slats there's no kapton connector, so it's always 1"
548 << " (zero make the reader" << endl
549 << "#abort, so it's not a valid value here)." << endl
550 << "#" << endl;
551
552 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
553 {
554 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
555 {
556 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
557 if (con)
558 {
559 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
560 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;
561 }
562 }
563 }
564
565 padPosFile.close();
566 motifFile.close();
567
568 return kTRUE;
569}
570
571
572