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 //-----------------------------------------------------------------------------
28 #include "AliMpMotifType.h"
29 #include "AliMpExMapIterator.h"
30 #include "AliMpMotifTypePadIterator.h"
31 #include "AliMpConnection.h"
32 #include "AliMpConstants.h"
33 #include "AliMpFiles.h"
34 #include "AliMpEncodePair.h"
39 #include <Riostream.h>
44 ClassImp(AliMpMotifType)
47 const Int_t AliMpMotifType::fgkPadNumForA = 65;
49 //______________________________________________________________________________
50 AliMpMotifType::AliMpMotifType(const TString &id)
56 fMaxNofPads(AliMpConstants::ManuNofChannels()),
57 fConnectionsByLocalIndices(fMaxNofPads*fMaxNofPads),
58 fConnectionsByManuChannel(fMaxNofPads)
60 /// Standard constructor \n
61 /// Please note that id should be of the form %s for station 1,2,
62 // %s-%e-%e for station345 and %sx%e for stationTrigger
64 fConnectionsByLocalIndices.SetOwner(kTRUE);
65 fConnectionsByManuChannel.SetOwner(kFALSE);
66 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
69 //______________________________________________________________________________
70 AliMpMotifType::AliMpMotifType(TRootIOCtor*)
77 fConnectionsByLocalIndices(),
78 fConnectionsByManuChannel()
80 /// Default constructor
81 AliDebug(1,Form("this=%p",this));
84 //______________________________________________________________________________
85 AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
92 fConnectionsByLocalIndices(),
93 fConnectionsByManuChannel()
96 AliDebug(1,Form("this=%p (copy ctor)",this));
100 //______________________________________________________________________________
102 AliMpMotifType::operator=(const AliMpMotifType& rhs)
104 /// Assignment operator
106 TObject::operator=(rhs);
111 //______________________________________________________________________________
113 AliMpMotifType::Clone(const char* /*newname*/) const
115 /// Returns a full copy of this object
116 return new AliMpMotifType(*this);
119 //______________________________________________________________________________
121 AliMpMotifType::Copy(TObject& object) const
125 TObject::Copy(object);
126 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
128 mt.fNofPadsX = fNofPadsX;
129 mt.fNofPadsY = fNofPadsY;
130 mt.fNofPads = fNofPads;
131 mt.fMaxNofPads = fMaxNofPads;
132 mt.fConnectionsByLocalIndices = fConnectionsByLocalIndices;
133 mt.fConnectionsByManuChannel = fConnectionsByManuChannel;
136 //______________________________________________________________________________
137 AliMpMotifType::~AliMpMotifType()
141 AliDebug(1,Form("this=%p",this));
144 //______________________________________________________________________________
145 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
147 /// Create new motif type iterator
149 return new AliMpMotifTypePadIterator(this);
152 //______________________________________________________________________________
153 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
155 /// Change the number of pads in this motif
157 fNofPadsX = nofPadsX;
158 fNofPadsY = nofPadsY;
162 //______________________________________________________________________________
163 Int_t AliMpMotifType::PadNum(const TString &padName) const
165 /// Transform a pad name into the equivalent pad number
167 if ( (padName[0]>='A') && (padName[0]<='Z') )
168 return fgkPadNumForA+padName[0]-'A';
170 return atoi(padName.Data());
173 //______________________________________________________________________________
174 TString AliMpMotifType::PadName(Int_t padNum) const
176 /// Transform a pad number into its equivalent pad name
178 if (padNum<fgkPadNumForA)
179 return Form("%d",padNum);
181 return char('A'+padNum-fgkPadNumForA);
184 //______________________________________________________________________________
186 AliMpMotifType::AddConnection(AliMpConnection* connection)
188 /// Add the connection to the map
190 if (!connection) return kFALSE;
192 Int_t ix = connection->GetLocalIx();
193 Int_t iy = connection->GetLocalIy();
195 Int_t manuChannel = connection->GetManuChannel();
197 if ( ix >=0 && ix < fMaxNofPads &&
198 iy >=0 && iy < fMaxNofPads &&
199 manuChannel >= 0 && manuChannel < AliMpConstants::ManuNofChannels())
202 Int_t index = ix + iy*AliMpConstants::ManuNofChannels();
204 AliMpConnection* c = FindConnectionByLocalIndices(
205 connection->GetLocalIndices());
209 AliError(Form("Connection already exists for ix=%d iy=%d",ix,iy));
215 fConnectionsByLocalIndices[index] = connection;
216 fConnectionsByManuChannel[manuChannel] = connection;
218 connection->SetOwner(this);
226 //______________________________________________________________________________
228 AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
230 /// Retrieve the AliMpConnection pointer from its pad num
231 /// This method is quite inefficient as we're looping over all connections
233 TIter next(&fConnectionsByManuChannel);
234 AliMpConnection* connection;
236 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
238 if (connection->GetPadNum()==padNum) return connection;
243 //______________________________________________________________________________
245 AliMpMotifType::FindConnectionByLocalIndices(MpPair_t localIndices) const
247 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
249 return FindConnectionByLocalIndices(AliMp::PairFirst(localIndices),
250 AliMp::PairSecond(localIndices));
253 //______________________________________________________________________________
255 AliMpMotifType::FindConnectionByLocalIndices(Int_t ix, Int_t iy) const
257 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
259 if ( ix < fNofPadsX && iy < fNofPadsY && ix >= 0 && iy >= 0 )
261 Int_t index = ix + iy*fMaxNofPads;
263 return static_cast<AliMpConnection*>(fConnectionsByLocalIndices.UncheckedAt(index));
271 //______________________________________________________________________________
273 AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
275 /// Return the connection for the given gassiplex number
277 if ( gassiNum >=0 && gassiNum < fMaxNofPads )
279 return static_cast<AliMpConnection*>(fConnectionsByManuChannel.UncheckedAt(gassiNum));
285 //______________________________________________________________________________
287 AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
289 /// Give the connection related to the given kapton number
290 /// Inefficient method as we loop over connections to find the right one
292 TIter next(&fConnectionsByManuChannel);
293 AliMpConnection* connection;
295 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
297 if ( connection && connection->GetKaptonNum()==kaptonNum) return connection;
302 //______________________________________________________________________________
304 AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
306 /// Retrieve the connection from a Berg connector number
307 /// Inefficient method as we loop over connections to find the right one
309 TIter next(&fConnectionsByManuChannel);
310 AliMpConnection* connection;
312 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
314 if ( connection && connection->GetBergNum()==bergNum) return connection;
320 //______________________________________________________________________________
321 MpPair_t AliMpMotifType::FindLocalIndicesByConnection(const AliMpConnection* connection) const
323 /// Reurn the pad position from the connection pointer.
325 return connection->GetLocalIndices();
328 //______________________________________________________________________________
329 MpPair_t AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
331 /// Retrieve the AliMpConnection pointer from its pad num
333 AliMpConnection* connection = FindConnectionByPadNum(padNum);
335 if ( ! connection) return -1;
337 return connection->GetLocalIndices();
340 //______________________________________________________________________________
341 MpPair_t AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
343 /// Return the connection for the given gassiplex number
345 AliMpConnection* connection = FindConnectionByGassiNum(gassiNum);
347 if ( ! connection) return -1;
349 return connection->GetLocalIndices();
352 //______________________________________________________________________________
353 MpPair_t AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
355 /// Give the connection related to the given kapton number
357 AliMpConnection* connection = FindConnectionByKaptonNum(kaptonNum);
359 if ( ! connection) return -1;
361 return connection->GetLocalIndices();
364 //______________________________________________________________________________
365 MpPair_t AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
367 /// Retrieve the connection from a Berg connector number
369 AliMpConnection* connection = FindConnectionByBergNum(bergNum);
371 if ( ! connection) return -1;
373 return connection->GetLocalIndices();
376 //______________________________________________________________________________
378 AliMpMotifType::HasPadByLocalIndices(MpPair_t localIndices) const
380 /// Return true if the pad indexed by \a localIndices has a connection
382 return ( FindConnectionByLocalIndices(localIndices) != 0x0 );
385 //______________________________________________________________________________
387 AliMpMotifType::HasPadByLocalIndices(Int_t localIx, Int_t localIy) const
389 /// Return true if the pad indexed by \a localIndices has a connection
391 return ( FindConnectionByLocalIndices(localIx, localIy) != 0x0 );
394 //______________________________________________________________________________
396 AliMpMotifType::HasPadByManuChannel(Int_t manuChannel) const
398 /// Return true if the pad indexed by \a localIndices has a connection
400 // if ( manuChannel >= fNofPads ) return kFALSE;
402 return ( FindConnectionByGassiNum(manuChannel) != 0x0 );
405 //______________________________________________________________________________
406 void AliMpMotifType::Print(Option_t *option) const
408 /// Print the map of the motif. In each cell, the value
409 /// printed depends of option, as the following:
410 /// - option="N" the "name" of the pad is written
411 /// - option="K" the Kapton connect. number attached to the pad is written
412 /// - option="B" the Berg connect. number attached to the pad is written
413 /// - option="G" the Gassiplex channel number attached to the pad is written
414 /// otherwise the number of the pad is written
416 /// NOTE : this method is really not optimized, in case 'N' or '',
417 /// but the Print() this should not be very important in a Print() method
420 case 'N':cout<<"Name mapping";
422 case 'K':cout<<"Kapton mapping";
424 case 'B':cout<<"Berg mapping";
426 case 'G':cout<<"Gassiplex number mapping";
428 default:cout<<"Pad mapping";
430 cout<<" in the motif "<<fID<<endl;
431 cout<<"-----------------------------------"<<endl;
433 for (Int_t j=fNofPadsY-1;j>=0;j--){
434 for (Int_t i=0;i<fNofPadsX;i++){
435 AliMpConnection *connexion = FindConnectionByLocalIndices(i,j);
438 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
441 case 'N':str=PadName(connexion->GetPadNum());
443 case 'K':str=Form("%d",connexion->GetKaptonNum());
445 case 'B':str=Form("%d",connexion->GetBergNum());
447 case 'G':str=Form("%d",connexion->GetManuChannel());
449 default:str= Form("%d",connexion->GetPadNum());
452 } else cout<<setw(2)<<"--";
459 //_____________________________________________________________________________
461 AliMpMotifType::Save() const
463 /// Save this motif type
465 return Save(fID.Data());
468 //_____________________________________________________________________________
470 AliMpMotifType::Save(const char* motifName) const
472 /// Generate the 2 files needed to describe the motif
474 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
476 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
478 // first a protection : do not allow overwriting existing files...
479 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
480 if (test==kFALSE) // AccessPathName has a strange return value convention...
482 AliError("Cannot overwrite existing padPos file");
485 test = gSystem->AccessPathName(motifTypeFileName.Data());
488 AliError("Cannot overwrite existing motifType file");
492 ofstream padPosFile(padPosFileName.Data());
493 ofstream motifFile(motifTypeFileName.Data());
495 motifFile << "# Motif " << motifName << endl
497 << "#connecteur_berg kapton padname not_used" << endl
498 << "#for slats there's no kapton connector, so it's always 1"
499 << " (zero make the reader" << endl
500 << "#exit, so it's not a valid value here)." << endl
503 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
505 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
507 AliMpConnection* con = FindConnectionByLocalIndices(ix,iy);
510 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
511 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;