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