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"
31 #include "AliMpExMapIterator.h"
32 #include "AliMpMotifTypePadIterator.h"
33 #include "AliMpConnection.h"
36 #include "AliMpFiles.h"
39 #include <Riostream.h>
42 ClassImp(AliMpMotifType)
45 const Int_t AliMpMotifType::fgkPadNumForA = 65;
47 //______________________________________________________________________________
48 AliMpMotifType::AliMpMotifType(const TString &id)
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
59 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
62 //______________________________________________________________________________
63 AliMpMotifType::AliMpMotifType(TRootIOCtor* ioCtor)
75 /// Default constructor
76 AliDebug(1,Form("this=%p",this));
79 //______________________________________________________________________________
80 AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
89 AliDebug(1,Form("this=%p (copy ctor)",this));
93 //______________________________________________________________________________
95 AliMpMotifType::operator=(const AliMpMotifType& rhs)
97 /// Assignment operator
99 TObject::operator=(rhs);
104 //______________________________________________________________________________
106 AliMpMotifType::Clone(const char* /*newname*/) const
108 /// Returns a full copy of this object
109 return new AliMpMotifType(*this);
112 //______________________________________________________________________________
114 AliMpMotifType::Copy(TObject& object) const
118 TObject::Copy(object);
119 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
121 mt.fNofPadsX = fNofPadsX;
122 mt.fNofPadsY = fNofPadsY;
123 mt.fConnections = fConnections;
126 //______________________________________________________________________________
127 AliMpMotifType::~AliMpMotifType()
132 for(ConnectionMapCIterator i = fConnections.begin();
133 i!=fConnections.end();++i)
136 fConnections.erase(fConnections.begin(),fConnections.end());
139 AliDebug(1,Form("this=%p",this));
140 // StdoutToAliDebug(1,this->Print(););
143 //______________________________________________________________________________
144 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
146 /// Create new motif type iterator
148 return new AliMpMotifTypePadIterator(this);
151 //______________________________________________________________________________
152 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
154 /// Change the number of pads in this motif
156 fNofPadsX = nofPadsX;
157 fNofPadsY = nofPadsY;
161 //______________________________________________________________________________
162 Int_t AliMpMotifType::PadNum(const TString &padName) const
164 /// Transform a pad name into the equivalent pad number
166 if ( (padName[0]>='A') && (padName[0]<='Z') )
167 return fgkPadNumForA+padName[0]-'A';
169 return atoi(padName.Data());
172 //______________________________________________________________________________
173 TString AliMpMotifType::PadName(Int_t padNum) const
175 /// Transform a pad number into its equivalent pad name
177 if (padNum<fgkPadNumForA)
178 return Form("%d",padNum);
180 return char('A'+padNum-fgkPadNumForA);
183 //______________________________________________________________________________
184 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
185 AliMpConnection* connection)
187 /// Add the connection to the map
190 fConnections[localIndices]=connection;
194 fConnections.Add(localIndices, connection);
197 connection->SetOwner(this);
200 //______________________________________________________________________________
201 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
203 /// Retrieve the AliMpConnection pointer from its pad num
206 for(ConnectionMapCIterator i = fConnections.begin();
207 i!=fConnections.end();++i)
208 if (i->second->GetPadNum()==padNum) return i->second;
213 TIter next(fConnections.CreateIterator());
214 AliMpConnection* connection;
216 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
218 if (connection->GetPadNum()==padNum) return connection;
224 //______________________________________________________________________________
225 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
226 const AliMpIntPair& localIndices) const
228 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
230 if (!localIndices.IsValid()) return 0;
233 ConnectionMapCIterator i = fConnections.find(localIndices);
234 if (i != fConnections.end())
240 return (AliMpConnection*)fConnections.GetValue(localIndices);
244 //______________________________________________________________________________
245 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
247 /// Return the connection for the given gassiplex number
250 for(ConnectionMapCIterator i = fConnections.begin();
251 i!=fConnections.end();++i)
252 if (i->second->GetGassiNum()==gassiNum) return i->second;
257 TIter next(fConnections.CreateIterator());
258 AliMpConnection* connection;
260 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
262 if (connection->GetGassiNum()==gassiNum) return connection;
268 //______________________________________________________________________________
269 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
271 /// Give the connection related to the given kapton number
274 for(ConnectionMapCIterator i = fConnections.begin();
275 i!=fConnections.end();++i)
276 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
281 TIter next(fConnections.CreateIterator());
282 AliMpConnection* connection;
284 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
286 if (connection->GetKaptonNum()==kaptonNum) return connection;
291 //______________________________________________________________________________
292 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
294 /// Retrieve the connection from a Berg connector number
297 for(ConnectionMapCIterator i = fConnections.begin();
298 i!=fConnections.end();++i)
299 if (i->second->GetBergNum()==bergNum) return i->second;
304 TIter next(fConnections.CreateIterator());
305 AliMpConnection* connection;
307 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
309 if (connection->GetBergNum()==bergNum) return connection;
316 //______________________________________________________________________________
317 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(const AliMpConnection* connection) const
319 /// Reurn the pad position from the connection pointer.
321 return connection->LocalIndices();
324 //______________________________________________________________________________
325 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
327 /// Retrieve the AliMpConnection pointer from its pad num
330 for(ConnectionMapCIterator i = fConnections.begin();
331 i!=fConnections.end();++i)
332 if (i->second->GetPadNum()==padNum) return i->first;
336 TIter next(fConnections.CreateIterator());
337 AliMpConnection* connection;
339 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
341 if (connection->GetPadNum()==padNum) return connection->LocalIndices();
344 return AliMpIntPair::Invalid();
347 //______________________________________________________________________________
348 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
350 /// Return the connection for the given gassiplex number
353 for(ConnectionMapCIterator i = fConnections.begin();
354 i!=fConnections.end();++i)
355 if (i->second->GetGassiNum()==gassiNum) return i->first;
359 TIter next(fConnections.CreateIterator());
360 AliMpConnection* connection;
362 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
364 if (connection->GetGassiNum()==gassiNum) return connection->LocalIndices();
368 return AliMpIntPair::Invalid();
371 //______________________________________________________________________________
372 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
374 /// Give the connection related to the given kapton number
377 for(ConnectionMapCIterator i = fConnections.begin();
378 i!=fConnections.end();++i)
379 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
383 TIter next(fConnections.CreateIterator());
384 AliMpConnection* connection;
386 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
388 if (connection->GetKaptonNum()==kaptonNum) return connection->LocalIndices();
392 return AliMpIntPair::Invalid();
395 //______________________________________________________________________________
396 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
398 /// Retrieve the connection from a Berg connector number
401 for(ConnectionMapCIterator i = fConnections.begin();
402 i!=fConnections.end();++i)
403 if (i->second->GetBergNum()==bergNum) return i->first;
407 TIter next(fConnections.CreateIterator());
408 AliMpConnection* connection;
410 while ( ( connection = static_cast<AliMpConnection*>(next()) ) )
412 if (connection->GetBergNum()==bergNum) return connection->LocalIndices();
416 return AliMpIntPair::Invalid();
419 //______________________________________________________________________________
420 Int_t AliMpMotifType::GetNofPads() const
422 /// Return the number of pads
425 return fConnections.size();
429 return fConnections.GetSize();
433 //______________________________________________________________________________
434 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
436 /// Return true if the pad indexed by \a localIndices has a connection
438 if (!localIndices.IsValid()) return false;
441 return fConnections.find(localIndices)!=fConnections.end();
445 TObject* value = fConnections.GetValue(localIndices);
450 //______________________________________________________________________________
451 void AliMpMotifType::Print(Option_t *option) const
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
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
465 case 'N':cout<<"Name mapping";
467 case 'K':cout<<"Kapton mapping";
469 case 'B':cout<<"Berg mapping";
471 case 'G':cout<<"Gassiplex number mapping";
473 default:cout<<"Pad mapping";
475 cout<<" in the motif "<<fID<<endl;
476 cout<<"-----------------------------------"<<endl;
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));
483 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
486 case 'N':str=PadName(connexion->GetPadNum());
488 case 'K':str=Form("%d",connexion->GetKaptonNum());
490 case 'B':str=Form("%d",connexion->GetBergNum());
492 case 'G':str=Form("%d",connexion->GetGassiNum());
494 default:str= Form("%d",connexion->GetPadNum());
497 } else cout<<setw(2)<<"--";
504 //_____________________________________________________________________________
506 AliMpMotifType::Save() const
508 /// Save this motif type
510 return Save(fID.Data());
513 //_____________________________________________________________________________
515 AliMpMotifType::Save(const char* motifName) const
517 /// Generate the 2 files needed to describe the motif
519 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
521 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
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...
527 AliError("Cannot overwrite existing padPos file");
530 test = gSystem->AccessPathName(motifTypeFileName.Data());
533 AliError("Cannot overwrite existing motifType file");
537 ofstream padPosFile(padPosFileName.Data());
538 ofstream motifFile(motifTypeFileName.Data());
540 motifFile << "# Motif " << motifName << 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
548 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
550 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
552 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
555 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
556 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;