1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpMotifType.cxx,v 1.10 2006/05/24 13:58:41 ivana Exp $
20 //-----------------------------------------------------------------------------
21 // Class AliMpMotifType
22 // --------------------
23 // Class that defines the motif properties.
24 // Included in AliRoot: 2003/05/02
25 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 //-----------------------------------------------------------------------------
29 #include "AliMpMotifType.h"
30 #include "AliMpExMapIterator.h"
31 #include "AliMpMotifTypePadIterator.h"
32 #include "AliMpConnection.h"
33 #include "AliMpConstants.h"
35 #include "AliMpFiles.h"
38 #include <Riostream.h>
41 ClassImp(AliMpMotifType)
44 const Int_t AliMpMotifType::fgkPadNumForA = 65;
46 //______________________________________________________________________________
47 AliMpMotifType::AliMpMotifType(const TString &id)
53 fMaxNofPads(AliMpConstants::ManuNofChannels()),
54 fConnectionsByLocalIndices(fMaxNofPads*fMaxNofPads),
55 fConnectionsByManuChannel(fMaxNofPads)
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
61 fConnectionsByLocalIndices.SetOwner(kTRUE);
62 fConnectionsByManuChannel.SetOwner(kFALSE);
63 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
66 //______________________________________________________________________________
67 AliMpMotifType::AliMpMotifType(TRootIOCtor*)
74 fConnectionsByLocalIndices(),
75 fConnectionsByManuChannel()
77 /// Default constructor
78 AliDebug(1,Form("this=%p",this));
81 //______________________________________________________________________________
82 AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
89 fConnectionsByLocalIndices(),
90 fConnectionsByManuChannel()
93 AliDebug(1,Form("this=%p (copy ctor)",this));
97 //______________________________________________________________________________
99 AliMpMotifType::operator=(const AliMpMotifType& rhs)
101 /// Assignment operator
103 TObject::operator=(rhs);
108 //______________________________________________________________________________
110 AliMpMotifType::Clone(const char* /*newname*/) const
112 /// Returns a full copy of this object
113 return new AliMpMotifType(*this);
116 //______________________________________________________________________________
118 AliMpMotifType::Copy(TObject& object) const
122 TObject::Copy(object);
123 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
125 mt.fNofPadsX = fNofPadsX;
126 mt.fNofPadsY = fNofPadsY;
127 mt.fNofPads = fNofPads;
128 mt.fMaxNofPads = fMaxNofPads;
129 mt.fConnectionsByLocalIndices = fConnectionsByLocalIndices;
130 mt.fConnectionsByManuChannel = fConnectionsByManuChannel;
133 //______________________________________________________________________________
134 AliMpMotifType::~AliMpMotifType()
138 AliDebug(1,Form("this=%p",this));
141 //______________________________________________________________________________
142 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
144 /// Create new motif type iterator
146 return new AliMpMotifTypePadIterator(this);
149 //______________________________________________________________________________
150 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
152 /// Change the number of pads in this motif
154 fNofPadsX = nofPadsX;
155 fNofPadsY = nofPadsY;
159 //______________________________________________________________________________
160 Int_t AliMpMotifType::PadNum(const TString &padName) const
162 /// Transform a pad name into the equivalent pad number
164 if ( (padName[0]>='A') && (padName[0]<='Z') )
165 return fgkPadNumForA+padName[0]-'A';
167 return atoi(padName.Data());
170 //______________________________________________________________________________
171 TString AliMpMotifType::PadName(Int_t padNum) const
173 /// Transform a pad number into its equivalent pad name
175 if (padNum<fgkPadNumForA)
176 return Form("%d",padNum);
178 return char('A'+padNum-fgkPadNumForA);
181 //______________________________________________________________________________
183 AliMpMotifType::AddConnection(AliMpConnection* connection)
185 /// Add the connection to the map
187 if (!connection) return kFALSE;
189 Int_t ix = connection->LocalIndices().GetFirst();
190 Int_t iy = connection->LocalIndices().GetSecond();
192 Int_t manuChannel = connection->GetManuChannel();
194 if ( ix >=0 && ix < fMaxNofPads &&
195 iy >=0 && iy < fMaxNofPads &&
196 manuChannel >= 0 && manuChannel < AliMpConstants::ManuNofChannels())
199 Int_t index = ix + iy*AliMpConstants::ManuNofChannels();
201 AliMpConnection* c = FindConnectionByLocalIndices(connection->LocalIndices());
205 AliError(Form("Connection already exists for ix=%d iy=%d",ix,iy));
211 fConnectionsByLocalIndices[index] = connection;
212 fConnectionsByManuChannel[manuChannel] = connection;
214 connection->SetOwner(this);
222 //______________________________________________________________________________
224 AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
226 /// Retrieve the AliMpConnection pointer from its pad num
227 /// This method is quite inefficient as we're looping over all connections
229 TIter next(&fConnectionsByManuChannel);
230 AliMpConnection* connection;
232 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
234 if (connection->GetPadNum()==padNum) return connection;
239 //______________________________________________________________________________
241 AliMpMotifType::FindConnectionByLocalIndices(const AliMpIntPair& localIndices) const
243 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
245 Int_t ix = localIndices.GetFirst();
246 Int_t iy = localIndices.GetSecond();
248 if ( ix < fNofPadsX && iy < fNofPadsY && ix >= 0 && iy >= 0 )
250 Int_t index = ix + iy*fMaxNofPads;
252 return static_cast<AliMpConnection*>(fConnectionsByLocalIndices.UncheckedAt(index));
260 //______________________________________________________________________________
262 AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
264 /// Return the connection for the given gassiplex number
266 if ( gassiNum >=0 && gassiNum < fMaxNofPads )
268 return static_cast<AliMpConnection*>(fConnectionsByManuChannel.UncheckedAt(gassiNum));
274 //______________________________________________________________________________
276 AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
278 /// Give the connection related to the given kapton number
279 /// Inefficient method as we loop over connections to find the right one
281 TIter next(&fConnectionsByManuChannel);
282 AliMpConnection* connection;
284 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
286 if ( connection && connection->GetKaptonNum()==kaptonNum) return connection;
291 //______________________________________________________________________________
293 AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
295 /// Retrieve the connection from a Berg connector number
296 /// Inefficient method as we loop over connections to find the right one
298 TIter next(&fConnectionsByManuChannel);
299 AliMpConnection* connection;
301 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
303 if ( connection && connection->GetBergNum()==bergNum) return connection;
309 //______________________________________________________________________________
310 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(const AliMpConnection* connection) const
312 /// Reurn the pad position from the connection pointer.
314 return connection->LocalIndices();
317 //______________________________________________________________________________
318 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
320 /// Retrieve the AliMpConnection pointer from its pad num
322 AliMpConnection* connection = FindConnectionByPadNum(padNum);
326 return connection->LocalIndices();
329 return AliMpIntPair::Invalid();
332 //______________________________________________________________________________
333 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
335 /// Return the connection for the given gassiplex number
337 AliMpConnection* connection = FindConnectionByGassiNum(gassiNum);
341 return connection->LocalIndices();
344 return AliMpIntPair::Invalid();
347 //______________________________________________________________________________
348 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
350 /// Give the connection related to the given kapton number
352 AliMpConnection* connection = FindConnectionByKaptonNum(kaptonNum);
356 return connection->LocalIndices();
359 return AliMpIntPair::Invalid();
362 //______________________________________________________________________________
363 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
365 /// Retrieve the connection from a Berg connector number
367 AliMpConnection* connection = FindConnectionByBergNum(bergNum);
371 return connection->LocalIndices();
374 return AliMpIntPair::Invalid();
377 //______________________________________________________________________________
379 AliMpMotifType::HasPadByLocalIndices(const AliMpIntPair& localIndices) const
381 /// Return true if the pad indexed by \a localIndices has a connection
383 return ( FindConnectionByLocalIndices(localIndices) != 0x0 );
386 //______________________________________________________________________________
388 AliMpMotifType::HasPadByManuChannel(Int_t manuChannel) const
390 /// Return true if the pad indexed by \a localIndices has a connection
392 // if ( manuChannel >= fNofPads ) return kFALSE;
394 return ( FindConnectionByGassiNum(manuChannel) != 0x0 );
397 //______________________________________________________________________________
398 void AliMpMotifType::Print(Option_t *option) const
400 /// Print the map of the motif. In each cell, the value
401 /// printed depends of option, as the following:
402 /// - option="N" the "name" of the pad is written
403 /// - option="K" the Kapton connect. number attached to the pad is written
404 /// - option="B" the Berg connect. number attached to the pad is written
405 /// - option="G" the Gassiplex channel number attached to the pad is written
406 /// otherwise the number of the pad is written
408 /// NOTE : this method is really not optimized, in case 'N' or '',
409 /// but the Print() this should not be very important in a Print() method
412 case 'N':cout<<"Name mapping";
414 case 'K':cout<<"Kapton mapping";
416 case 'B':cout<<"Berg mapping";
418 case 'G':cout<<"Gassiplex number mapping";
420 default:cout<<"Pad mapping";
422 cout<<" in the motif "<<fID<<endl;
423 cout<<"-----------------------------------"<<endl;
425 for (Int_t j=fNofPadsY-1;j>=0;j--){
426 for (Int_t i=0;i<fNofPadsX;i++){
427 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
430 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
433 case 'N':str=PadName(connexion->GetPadNum());
435 case 'K':str=Form("%d",connexion->GetKaptonNum());
437 case 'B':str=Form("%d",connexion->GetBergNum());
439 case 'G':str=Form("%d",connexion->GetManuChannel());
441 default:str= Form("%d",connexion->GetPadNum());
444 } else cout<<setw(2)<<"--";
451 //_____________________________________________________________________________
453 AliMpMotifType::Save() const
455 /// Save this motif type
457 return Save(fID.Data());
460 //_____________________________________________________________________________
462 AliMpMotifType::Save(const char* motifName) const
464 /// Generate the 2 files needed to describe the motif
466 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
468 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
470 // first a protection : do not allow overwriting existing files...
471 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
472 if (test==kFALSE) // AccessPathName has a strange return value convention...
474 AliError("Cannot overwrite existing padPos file");
477 test = gSystem->AccessPathName(motifTypeFileName.Data());
480 AliError("Cannot overwrite existing motifType file");
484 ofstream padPosFile(padPosFileName.Data());
485 ofstream motifFile(motifTypeFileName.Data());
487 motifFile << "# Motif " << motifName << endl
489 << "#connecteur_berg kapton padname not_used" << endl
490 << "#for slats there's no kapton connector, so it's always 1"
491 << " (zero make the reader" << endl
492 << "#abort, so it's not a valid value here)." << endl
495 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
497 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
499 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
502 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
503 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;