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 "AliMpMotifTypePadIterator.h"
30 #include "AliMpConnection.h"
33 #include "AliMpFiles.h"
36 #include <Riostream.h>
39 ClassImp(AliMpMotifType)
42 const Int_t AliMpMotifType::fgkPadNumForA = 65;
44 //______________________________________________________________________________
45 AliMpMotifType::AliMpMotifType(const TString &id)
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 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
64 //______________________________________________________________________________
65 AliMpMotifType::AliMpMotifType()
72 /// Default constructor
73 AliDebug(1,Form("this=%p",this));
76 //______________________________________________________________________________
77 AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
86 AliDebug(1,Form("this=%p (copy ctor)",this));
90 //______________________________________________________________________________
92 AliMpMotifType::operator=(const AliMpMotifType& rhs)
94 /// Assignment operator
96 TObject::operator=(rhs);
101 //______________________________________________________________________________
103 AliMpMotifType::Clone(const char* /*newname*/) const
105 /// Returns a full copy of this object
106 return new AliMpMotifType(*this);
109 //______________________________________________________________________________
111 AliMpMotifType::Copy(TObject& object) const
115 TObject::Copy(object);
116 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
118 mt.fNofPadsX = fNofPadsX;
119 mt.fNofPadsY = fNofPadsY;
120 mt.fConnections = fConnections;
123 //______________________________________________________________________________
124 AliMpMotifType::~AliMpMotifType()
129 for(ConnectionMapCIterator i = fConnections.begin();
130 i!=fConnections.end();++i)
133 fConnections.erase(fConnections.begin(),fConnections.end());
136 AliDebug(1,Form("this=%p",this));
137 // StdoutToAliDebug(1,this->Print(););
140 //______________________________________________________________________________
141 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
143 /// Create new motif type iterator
145 return new AliMpMotifTypePadIterator(this);
148 //______________________________________________________________________________
149 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
151 /// Change the number of pads in this motif
153 fNofPadsX = nofPadsX;
154 fNofPadsY = nofPadsY;
158 //______________________________________________________________________________
159 Int_t AliMpMotifType::PadNum(const TString &padName) const
161 /// Transform a pad name into the equivalent pad number
163 if ( (padName[0]>='A') && (padName[0]<='Z') )
164 return fgkPadNumForA+padName[0]-'A';
166 return atoi(padName.Data());
169 //______________________________________________________________________________
170 TString AliMpMotifType::PadName(Int_t padNum) const
172 /// Transform a pad number into its equivalent pad name
174 if (padNum<fgkPadNumForA)
175 return Form("%d",padNum);
177 return char('A'+padNum-fgkPadNumForA);
180 //______________________________________________________________________________
181 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
182 AliMpConnection* connection)
184 /// Add the connection to the map
187 fConnections[localIndices]=connection;
191 fConnections.Add(localIndices, connection);
194 connection->SetOwner(this);
197 //______________________________________________________________________________
198 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
200 /// Retrieve the AliMpConnection pointer from its pad num
203 for(ConnectionMapCIterator i = fConnections.begin();
204 i!=fConnections.end();++i)
205 if (i->second->GetPadNum()==padNum) return i->second;
210 TExMapIter i = fConnections.GetIterator();
212 while ( i.Next(key, value) ) {
213 AliMpConnection* connection = (AliMpConnection*)value;
214 if (connection->GetPadNum()==padNum) return connection;
220 //______________________________________________________________________________
221 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
222 const AliMpIntPair& localIndices) const
224 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
226 if (!localIndices.IsValid()) return 0;
229 ConnectionMapCIterator i = fConnections.find(localIndices);
230 if (i != fConnections.end())
236 return (AliMpConnection*)fConnections.GetValue(localIndices);
240 //______________________________________________________________________________
241 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
243 /// Return the connection for the given gassiplex number
246 for(ConnectionMapCIterator i = fConnections.begin();
247 i!=fConnections.end();++i)
248 if (i->second->GetGassiNum()==gassiNum) return i->second;
253 TExMapIter i = fConnections.GetIterator();
255 while ( i.Next(key, value) ) {
256 AliMpConnection* connection = (AliMpConnection*)value;
257 if (connection->GetGassiNum()==gassiNum) return connection;
263 //______________________________________________________________________________
264 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
266 /// Give the connection related to the given kapton number
269 for(ConnectionMapCIterator i = fConnections.begin();
270 i!=fConnections.end();++i)
271 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
276 TExMapIter i = fConnections.GetIterator();
278 while ( i.Next(key, value) ) {
279 AliMpConnection* connection = (AliMpConnection*)value;
280 if (connection->GetKaptonNum()==kaptonNum) return connection;
285 //______________________________________________________________________________
286 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
288 /// Retrieve the connection from a Berg connector number
291 for(ConnectionMapCIterator i = fConnections.begin();
292 i!=fConnections.end();++i)
293 if (i->second->GetBergNum()==bergNum) return i->second;
298 TExMapIter i = fConnections.GetIterator();
300 while ( i.Next(key, value) ) {
301 AliMpConnection* connection = (AliMpConnection*)value;
302 if (connection->GetBergNum()==bergNum) return connection;
309 //______________________________________________________________________________
310 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
311 const AliMpConnection* connection) const
313 /// Retrieve the pad position from the connection pointer.
314 /// Not to be used widely, since it use a search in the
315 /// connection list...
318 for(ConnectionMapCIterator i = fConnections.begin();
319 i!=fConnections.end();++i)
320 if (i->second==connection) return i->first;
324 TExMapIter i = fConnections.GetIterator();
326 while ( i.Next(key, value) ) {
327 AliMpConnection* aConnection = (AliMpConnection*)value;
328 if (aConnection == connection) return AliMpExMap::GetPair(key);
332 return AliMpIntPair::Invalid();
335 //______________________________________________________________________________
336 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
338 /// Retrieve the AliMpConnection pointer from its pad num
341 for(ConnectionMapCIterator i = fConnections.begin();
342 i!=fConnections.end();++i)
343 if (i->second->GetPadNum()==padNum) return i->first;
347 TExMapIter i = fConnections.GetIterator();
349 while ( i.Next(key, value) ) {
350 AliMpConnection* connection = (AliMpConnection*)value;
351 if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
354 return AliMpIntPair::Invalid();
357 //______________________________________________________________________________
358 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
360 /// Return the connection for the given gassiplex number
363 for(ConnectionMapCIterator i = fConnections.begin();
364 i!=fConnections.end();++i)
365 if (i->second->GetGassiNum()==gassiNum) return i->first;
369 TExMapIter i = fConnections.GetIterator();
371 while ( i.Next(key, value) ) {
372 AliMpConnection* connection = (AliMpConnection*)value;
373 if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
377 return AliMpIntPair::Invalid();
380 //______________________________________________________________________________
381 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
383 /// Give the connection related to the given kapton number
386 for(ConnectionMapCIterator i = fConnections.begin();
387 i!=fConnections.end();++i)
388 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
392 TExMapIter i = fConnections.GetIterator();
394 while ( i.Next(key, value) ) {
395 AliMpConnection* connection = (AliMpConnection*)value;
396 if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
400 return AliMpIntPair::Invalid();
403 //______________________________________________________________________________
404 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
406 /// Retrieve the connection from a Berg connector number
409 for(ConnectionMapCIterator i = fConnections.begin();
410 i!=fConnections.end();++i)
411 if (i->second->GetBergNum()==bergNum) return i->first;
415 TExMapIter i = fConnections.GetIterator();
417 while ( i.Next(key, value) ) {
418 AliMpConnection* connection = (AliMpConnection*)value;
419 if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
423 return AliMpIntPair::Invalid();
426 //______________________________________________________________________________
427 Int_t AliMpMotifType::GetNofPads() const
429 /// Return the number of pads
432 return fConnections.size();
436 return fConnections.GetSize();
440 //______________________________________________________________________________
441 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
443 /// Return true if the pad indexed by \a localIndices has a connection
445 if (!localIndices.IsValid()) return false;
448 return fConnections.find(localIndices)!=fConnections.end();
452 TObject* value = fConnections.GetValue(localIndices);
457 //______________________________________________________________________________
458 void AliMpMotifType::Print(Option_t *option) const
460 /// Print the map of the motif. In each cell, the value
461 /// printed depends of option, as the following:
462 /// - option="N" the "name" of the pad is written
463 /// - option="K" the Kapton connect. number attached to the pad is written
464 /// - option="B" the Berg connect. number attached to the pad is written
465 /// - option="G" the Gassiplex channel number attached to the pad is written
466 /// otherwise the number of the pad is written
468 /// NOTE : this method is really not optimized, in case 'N' or '',
469 /// but the Print() this should not be very important in a Print() method
472 case 'N':cout<<"Name mapping";
474 case 'K':cout<<"Kapton mapping";
476 case 'B':cout<<"Berg mapping";
478 case 'G':cout<<"Gassiplex number mapping";
480 default:cout<<"Pad mapping";
482 cout<<" in the motif "<<fID<<endl;
483 cout<<"-----------------------------------"<<endl;
485 for (Int_t j=fNofPadsY-1;j>=0;j--){
486 for (Int_t i=0;i<fNofPadsX;i++){
487 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
490 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
493 case 'N':str=PadName(connexion->GetPadNum());
495 case 'K':str=Form("%d",connexion->GetKaptonNum());
497 case 'B':str=Form("%d",connexion->GetBergNum());
499 case 'G':str=Form("%d",connexion->GetGassiNum());
501 default:str= Form("%d",connexion->GetPadNum());
504 } else cout<<setw(2)<<"--";
511 //_____________________________________________________________________________
513 AliMpMotifType::Save() const
515 /// Save this motif type
517 return Save(fID.Data());
520 //_____________________________________________________________________________
522 AliMpMotifType::Save(const char* motifName) const
524 /// Generate the 2 files needed to describe the motif
526 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
528 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
530 // first a protection : do not allow overwriting existing files...
531 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
532 if (test==kFALSE) // AccessPathName has a strange return value convention...
534 AliError("Cannot overwrite existing padPos file");
537 test = gSystem->AccessPathName(motifTypeFileName.Data());
540 AliError("Cannot overwrite existing motifType file");
544 ofstream padPosFile(padPosFileName.Data());
545 ofstream motifFile(motifTypeFileName.Data());
547 motifFile << "# Motif " << motifName << endl
549 << "#connecteur_berg kapton padname not_used" << endl
550 << "#for slats there's no kapton connector, so it's always 1"
551 << " (zero make the reader" << endl
552 << "#abort, so it's not a valid value here)." << endl
555 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
557 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
559 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
562 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
563 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;