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