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