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>
48 ClassImp(AliMpMotifType)
51 const Int_t AliMpMotifType::fgkPadNumForA = 65;
53 //______________________________________________________________________________
54 AliMpMotifType::AliMpMotifType(const TString &id)
60 fMaxNofPads(AliMpConstants::ManuNofChannels()),
61 fConnectionsByLocalIndices(fMaxNofPads*fMaxNofPads),
62 fConnectionsByManuChannel(fMaxNofPads)
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
68 fConnectionsByLocalIndices.SetOwner(kTRUE);
69 fConnectionsByManuChannel.SetOwner(kFALSE);
70 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
73 //______________________________________________________________________________
74 AliMpMotifType::AliMpMotifType(TRootIOCtor*)
81 fConnectionsByLocalIndices(),
82 fConnectionsByManuChannel()
84 /// Default constructor
85 AliDebug(1,Form("this=%p",this));
88 //______________________________________________________________________________
89 AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
96 fConnectionsByLocalIndices(),
97 fConnectionsByManuChannel()
100 AliDebug(1,Form("this=%p (copy ctor)",this));
104 //______________________________________________________________________________
106 AliMpMotifType::operator=(const AliMpMotifType& rhs)
108 /// Assignment operator
110 TObject::operator=(rhs);
115 //______________________________________________________________________________
117 AliMpMotifType::Clone(const char* /*newname*/) const
119 /// Returns a full copy of this object
120 return new AliMpMotifType(*this);
123 //______________________________________________________________________________
125 AliMpMotifType::Copy(TObject& object) const
129 TObject::Copy(object);
130 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
132 mt.fNofPadsX = fNofPadsX;
133 mt.fNofPadsY = fNofPadsY;
134 mt.fNofPads = fNofPads;
135 mt.fMaxNofPads = fMaxNofPads;
136 mt.fConnectionsByLocalIndices = fConnectionsByLocalIndices;
137 mt.fConnectionsByManuChannel = fConnectionsByManuChannel;
140 //______________________________________________________________________________
141 AliMpMotifType::~AliMpMotifType()
145 AliDebug(1,Form("this=%p",this));
148 //______________________________________________________________________________
149 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
151 /// Create new motif type iterator
153 return new AliMpMotifTypePadIterator(this);
156 //______________________________________________________________________________
157 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
159 /// Change the number of pads in this motif
161 fNofPadsX = nofPadsX;
162 fNofPadsY = nofPadsY;
166 //______________________________________________________________________________
167 Int_t AliMpMotifType::PadNum(const TString &padName) const
169 /// Transform a pad name into the equivalent pad number
171 if ( (padName[0]>='A') && (padName[0]<='Z') )
172 return fgkPadNumForA+padName[0]-'A';
174 return atoi(padName.Data());
177 //______________________________________________________________________________
178 TString AliMpMotifType::PadName(Int_t padNum) const
180 /// Transform a pad number into its equivalent pad name
182 if (padNum<fgkPadNumForA)
183 return Form("%d",padNum);
185 return char('A'+padNum-fgkPadNumForA);
188 //______________________________________________________________________________
190 AliMpMotifType::AddConnection(AliMpConnection* connection)
192 /// Add the connection to the map
194 if (!connection) return kFALSE;
196 Int_t ix = connection->GetLocalIx();
197 Int_t iy = connection->GetLocalIy();
199 Int_t manuChannel = connection->GetManuChannel();
201 if ( ix >=0 && ix < fMaxNofPads &&
202 iy >=0 && iy < fMaxNofPads &&
203 manuChannel >= 0 && manuChannel < AliMpConstants::ManuNofChannels())
206 Int_t index = ix + iy*AliMpConstants::ManuNofChannels();
208 AliMpConnection* c = FindConnectionByLocalIndices(
209 connection->GetLocalIndices());
213 AliError(Form("Connection already exists for ix=%d iy=%d",ix,iy));
219 fConnectionsByLocalIndices[index] = connection;
220 fConnectionsByManuChannel[manuChannel] = connection;
222 connection->SetOwner(this);
230 //______________________________________________________________________________
232 AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
234 /// Retrieve the AliMpConnection pointer from its pad num
235 /// This method is quite inefficient as we're looping over all connections
237 TIter next(&fConnectionsByManuChannel);
238 AliMpConnection* connection;
240 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
242 if (connection->GetPadNum()==padNum) return connection;
247 //______________________________________________________________________________
249 AliMpMotifType::FindConnectionByLocalIndices(MpPair_t localIndices) const
251 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
253 return FindConnectionByLocalIndices(AliMp::PairFirst(localIndices),
254 AliMp::PairSecond(localIndices));
257 //______________________________________________________________________________
259 AliMpMotifType::FindConnectionByLocalIndices(Int_t ix, Int_t iy) const
261 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
263 if ( ix < fNofPadsX && iy < fNofPadsY && ix >= 0 && iy >= 0 )
265 Int_t index = ix + iy*fMaxNofPads;
267 return static_cast<AliMpConnection*>(fConnectionsByLocalIndices.UncheckedAt(index));
275 //______________________________________________________________________________
277 AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
279 /// Return the connection for the given gassiplex number
281 if ( gassiNum >=0 && gassiNum < fMaxNofPads )
283 return static_cast<AliMpConnection*>(fConnectionsByManuChannel.UncheckedAt(gassiNum));
289 //______________________________________________________________________________
291 AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
293 /// Give the connection related to the given kapton number
294 /// Inefficient method as we loop over connections to find the right one
296 TIter next(&fConnectionsByManuChannel);
297 AliMpConnection* connection;
299 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
301 if ( connection && connection->GetKaptonNum()==kaptonNum) return connection;
306 //______________________________________________________________________________
308 AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
310 /// Retrieve the connection from a Berg connector number
311 /// Inefficient method as we loop over connections to find the right one
313 TIter next(&fConnectionsByManuChannel);
314 AliMpConnection* connection;
316 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
318 if ( connection && connection->GetBergNum()==bergNum) return connection;
324 //______________________________________________________________________________
325 MpPair_t AliMpMotifType::FindLocalIndicesByConnection(const AliMpConnection* connection) const
327 /// Reurn the pad position from the connection pointer.
329 return connection->GetLocalIndices();
332 //______________________________________________________________________________
333 MpPair_t AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
335 /// Retrieve the AliMpConnection pointer from its pad num
337 AliMpConnection* connection = FindConnectionByPadNum(padNum);
339 if ( ! connection) return -1;
341 return connection->GetLocalIndices();
344 //______________________________________________________________________________
345 MpPair_t AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
347 /// Return the connection for the given gassiplex number
349 AliMpConnection* connection = FindConnectionByGassiNum(gassiNum);
351 if ( ! connection) return -1;
353 return connection->GetLocalIndices();
356 //______________________________________________________________________________
357 MpPair_t AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
359 /// Give the connection related to the given kapton number
361 AliMpConnection* connection = FindConnectionByKaptonNum(kaptonNum);
363 if ( ! connection) return -1;
365 return connection->GetLocalIndices();
368 //______________________________________________________________________________
369 MpPair_t AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
371 /// Retrieve the connection from a Berg connector number
373 AliMpConnection* connection = FindConnectionByBergNum(bergNum);
375 if ( ! connection) return -1;
377 return connection->GetLocalIndices();
380 //______________________________________________________________________________
382 AliMpMotifType::HasPadByLocalIndices(MpPair_t localIndices) const
384 /// Return true if the pad indexed by \a localIndices has a connection
386 return ( FindConnectionByLocalIndices(localIndices) != 0x0 );
389 //______________________________________________________________________________
391 AliMpMotifType::HasPadByLocalIndices(Int_t localIx, Int_t localIy) const
393 /// Return true if the pad indexed by \a localIndices has a connection
395 return ( FindConnectionByLocalIndices(localIx, localIy) != 0x0 );
398 //______________________________________________________________________________
400 AliMpMotifType::HasPadByManuChannel(Int_t manuChannel) const
402 /// Return true if the pad indexed by \a localIndices has a connection
404 // if ( manuChannel >= fNofPads ) return kFALSE;
406 return ( FindConnectionByGassiNum(manuChannel) != 0x0 );
409 //______________________________________________________________________________
410 void AliMpMotifType::Print(Option_t *option) const
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
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
424 case 'N':cout<<"Name mapping";
426 case 'K':cout<<"Kapton mapping";
428 case 'B':cout<<"Berg mapping";
430 case 'G':cout<<"Gassiplex number mapping";
432 default:cout<<"Pad mapping";
434 cout<<" in the motif "<<fID<<endl;
435 cout<<"-----------------------------------"<<endl;
437 for (Int_t j=fNofPadsY-1;j>=0;j--){
438 for (Int_t i=0;i<fNofPadsX;i++){
439 AliMpConnection *connexion = FindConnectionByLocalIndices(i,j);
442 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
445 case 'N':str=PadName(connexion->GetPadNum());
447 case 'K':str=Form("%d",connexion->GetKaptonNum());
449 case 'B':str=Form("%d",connexion->GetBergNum());
451 case 'G':str=Form("%d",connexion->GetManuChannel());
453 default:str= Form("%d",connexion->GetPadNum());
456 } else cout<<setw(2)<<"--";
463 //_____________________________________________________________________________
465 AliMpMotifType::Save() const
467 /// Save this motif type
469 return Save(fID.Data());
472 //_____________________________________________________________________________
474 AliMpMotifType::Save(const char* motifName) const
476 /// Generate the 2 files needed to describe the motif
478 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
480 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
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...
486 AliError("Cannot overwrite existing padPos file");
489 test = gSystem->AccessPathName(motifTypeFileName.Data());
492 AliError("Cannot overwrite existing motifType file");
496 ofstream padPosFile(padPosFileName.Data());
497 ofstream motifFile(motifTypeFileName.Data());
499 motifFile << "# Motif " << motifName << 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
504 << "#exit, so it's not a valid value here)." << endl
507 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
509 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
511 AliMpConnection* con = FindConnectionByLocalIndices(ix,iy);
514 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
515 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;