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