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 // Class AliMpMotifType
21 // --------------------
22 // Class that defines the motif properties.
23 // Included in AliRoot: 2003/05/02
24 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 #include "AliMpMotifType.h"
27 #include "AliMpMotifTypePadIterator.h"
28 #include "AliMpConnection.h"
31 #include "AliMpFiles.h"
34 #include <Riostream.h>
37 ClassImp(AliMpMotifType)
40 const Int_t AliMpMotifType::fgkPadNumForA = 65;
42 //______________________________________________________________________________
43 AliMpMotifType::AliMpMotifType(const TString &id)
56 /// Standard constructor
57 AliDebug(1,Form("this=%p id=%s",this,id.Data()));
60 //______________________________________________________________________________
61 AliMpMotifType::AliMpMotifType()
69 /// Default constructor
70 AliDebug(1,Form("this=%p",this));
73 //______________________________________________________________________________
74 AliMpMotifType::AliMpMotifType(const AliMpMotifType& rhs)
84 AliDebug(1,Form("this=%p (copy ctor)",this));
88 //______________________________________________________________________________
90 AliMpMotifType::operator=(const AliMpMotifType& rhs)
92 /// Assignment operator
94 TObject::operator=(rhs);
99 //______________________________________________________________________________
101 AliMpMotifType::Clone(const char* /*newname*/) const
103 /// Returns a full copy of this object
104 return new AliMpMotifType(*this);
107 //______________________________________________________________________________
109 AliMpMotifType::Copy(TObject& object) const
113 TObject::Copy(object);
114 AliMpMotifType& mt = static_cast<AliMpMotifType&>(object);
116 mt.fNofPadsX = fNofPadsX;
117 mt.fNofPadsY = fNofPadsY;
118 mt.fVerboseLevel = fVerboseLevel;
119 mt.fConnections = fConnections;
122 //______________________________________________________________________________
123 AliMpMotifType::~AliMpMotifType()
128 for(ConnectionMapCIterator i = fConnections.begin();
129 i!=fConnections.end();++i)
132 fConnections.erase(fConnections.begin(),fConnections.end());
135 AliDebug(1,Form("this=%p",this));
136 // StdoutToAliDebug(1,this->Print(););
139 //______________________________________________________________________________
140 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
142 /// Create new motif type iterator
144 return new AliMpMotifTypePadIterator(this);
147 //______________________________________________________________________________
148 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
150 /// Change the number of pads in this motif
152 fNofPadsX = nofPadsX;
153 fNofPadsY = nofPadsY;
157 //______________________________________________________________________________
158 Int_t AliMpMotifType::PadNum(const TString &padName) const
160 /// Transform a pad name into the equivalent pad number
162 if ( (padName[0]>='A') && (padName[0]<='Z') )
163 return fgkPadNumForA+padName[0]-'A';
165 return atoi(padName.Data());
168 //______________________________________________________________________________
169 TString AliMpMotifType::PadName(Int_t padNum) const
171 /// Transform a pad number into its equivalent pad name
173 if (padNum<fgkPadNumForA)
174 return Form("%d",padNum);
176 return char('A'+padNum-fgkPadNumForA);
179 //______________________________________________________________________________
180 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
181 AliMpConnection* connection)
183 /// Add the connection to the map
186 fConnections[localIndices]=connection;
190 fConnections.Add(localIndices, connection);
193 connection->SetOwner(this);
196 //______________________________________________________________________________
197 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
199 /// Retrieve the AliMpConnection pointer from its pad num
202 for(ConnectionMapCIterator i = fConnections.begin();
203 i!=fConnections.end();++i)
204 if (i->second->GetPadNum()==padNum) return i->second;
209 TExMapIter i = fConnections.GetIterator();
211 while ( i.Next(key, value) ) {
212 AliMpConnection* connection = (AliMpConnection*)value;
213 if (connection->GetPadNum()==padNum) return connection;
219 //______________________________________________________________________________
220 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
221 const AliMpIntPair& localIndices) const
223 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
225 if (!localIndices.IsValid()) return 0;
228 ConnectionMapCIterator i = fConnections.find(localIndices);
229 if (i != fConnections.end())
235 return (AliMpConnection*)fConnections.GetValue(localIndices);
239 //______________________________________________________________________________
240 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
242 /// Return the connection for the given gassiplex number
245 for(ConnectionMapCIterator i = fConnections.begin();
246 i!=fConnections.end();++i)
247 if (i->second->GetGassiNum()==gassiNum) return i->second;
252 TExMapIter i = fConnections.GetIterator();
254 while ( i.Next(key, value) ) {
255 AliMpConnection* connection = (AliMpConnection*)value;
256 if (connection->GetGassiNum()==gassiNum) return connection;
262 //______________________________________________________________________________
263 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
265 /// Give the connection related to the given kapton number
268 for(ConnectionMapCIterator i = fConnections.begin();
269 i!=fConnections.end();++i)
270 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
275 TExMapIter i = fConnections.GetIterator();
277 while ( i.Next(key, value) ) {
278 AliMpConnection* connection = (AliMpConnection*)value;
279 if (connection->GetKaptonNum()==kaptonNum) return connection;
284 //______________________________________________________________________________
285 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
287 /// Retrieve the connection from a Berg connector number
290 for(ConnectionMapCIterator i = fConnections.begin();
291 i!=fConnections.end();++i)
292 if (i->second->GetBergNum()==bergNum) return i->second;
297 TExMapIter i = fConnections.GetIterator();
299 while ( i.Next(key, value) ) {
300 AliMpConnection* connection = (AliMpConnection*)value;
301 if (connection->GetBergNum()==bergNum) return connection;
308 //______________________________________________________________________________
309 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
310 const AliMpConnection* connection) const
312 /// Retrieve the pad position from the connection pointer.
313 /// Not to be used widely, since it use a search in the
314 /// connection list...
317 for(ConnectionMapCIterator i = fConnections.begin();
318 i!=fConnections.end();++i)
319 if (i->second==connection) return i->first;
323 TExMapIter i = fConnections.GetIterator();
325 while ( i.Next(key, value) ) {
326 AliMpConnection* aConnection = (AliMpConnection*)value;
327 if (aConnection == connection) return AliMpExMap::GetPair(key);
331 return AliMpIntPair::Invalid();
334 //______________________________________________________________________________
335 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
337 /// Retrieve the AliMpConnection pointer from its pad num
340 for(ConnectionMapCIterator i = fConnections.begin();
341 i!=fConnections.end();++i)
342 if (i->second->GetPadNum()==padNum) return i->first;
346 TExMapIter i = fConnections.GetIterator();
348 while ( i.Next(key, value) ) {
349 AliMpConnection* connection = (AliMpConnection*)value;
350 if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
353 return AliMpIntPair::Invalid();
356 //______________________________________________________________________________
357 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
359 /// Return the connection for the given gassiplex number
362 for(ConnectionMapCIterator i = fConnections.begin();
363 i!=fConnections.end();++i)
364 if (i->second->GetGassiNum()==gassiNum) return i->first;
368 TExMapIter i = fConnections.GetIterator();
370 while ( i.Next(key, value) ) {
371 AliMpConnection* connection = (AliMpConnection*)value;
372 if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
376 return AliMpIntPair::Invalid();
379 //______________________________________________________________________________
380 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
382 /// Give the connection related to the given kapton number
385 for(ConnectionMapCIterator i = fConnections.begin();
386 i!=fConnections.end();++i)
387 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
391 TExMapIter i = fConnections.GetIterator();
393 while ( i.Next(key, value) ) {
394 AliMpConnection* connection = (AliMpConnection*)value;
395 if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
399 return AliMpIntPair::Invalid();
402 //______________________________________________________________________________
403 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
405 /// Retrieve the connection from a Berg connector number
408 for(ConnectionMapCIterator i = fConnections.begin();
409 i!=fConnections.end();++i)
410 if (i->second->GetBergNum()==bergNum) return i->first;
414 TExMapIter i = fConnections.GetIterator();
416 while ( i.Next(key, value) ) {
417 AliMpConnection* connection = (AliMpConnection*)value;
418 if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
422 return AliMpIntPair::Invalid();
425 //______________________________________________________________________________
426 Int_t AliMpMotifType::GetNofPads() const
428 /// Return the number of pads
431 return fConnections.size();
435 return fConnections.GetSize();
439 //______________________________________________________________________________
440 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
442 /// Return true if the pad indexed by \a localIndices has a connection
444 if (!localIndices.IsValid()) return false;
447 return fConnections.find(localIndices)!=fConnections.end();
451 TObject* value = fConnections.GetValue(localIndices);
456 //______________________________________________________________________________
457 void AliMpMotifType::Print(Option_t *option) const
459 /// Print the map of the motif. In each cell, the value
460 /// printed depends of option, as the following:
461 /// - option="N" the "name" of the pad is written
462 /// - option="K" the Kapton connect. number attached to the pad is written
463 /// - option="B" the Berg connect. number attached to the pad is written
464 /// - option="G" the Gassiplex channel number attached to the pad is written
465 /// otherwise the number of the pad is written
467 /// NOTE : this method is really not optimized, in case 'N' or '',
468 /// but the Print() this should not be very important in a Print() method
471 case 'N':cout<<"Name mapping";
473 case 'K':cout<<"Kapton mapping";
475 case 'B':cout<<"Berg mapping";
477 case 'G':cout<<"Gassiplex number mapping";
479 default:cout<<"Pad mapping";
481 cout<<" in the motif "<<fID<<endl;
482 cout<<"-----------------------------------"<<endl;
484 for (Int_t j=fNofPadsY-1;j>=0;j--){
485 for (Int_t i=0;i<fNofPadsX;i++){
486 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
489 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
492 case 'N':str=PadName(connexion->GetPadNum());
494 case 'K':str=Form("%d",connexion->GetKaptonNum());
496 case 'B':str=Form("%d",connexion->GetBergNum());
498 case 'G':str=Form("%d",connexion->GetGassiNum());
500 default:str= Form("%d",connexion->GetPadNum());
503 } else cout<<setw(2)<<"--";
510 //_____________________________________________________________________________
512 AliMpMotifType::Save() const
514 return Save(fID.Data());
517 //_____________________________________________________________________________
519 AliMpMotifType::Save(const char* motifName) const
521 /// Generate the 2 files needed to describe the motif
523 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
525 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
527 // first a protection : do not allow overwriting existing files...
528 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
529 if (test==kFALSE) // AccessPathName has a strange return value convention...
531 AliError("Cannot overwrite existing padPos file");
534 test = gSystem->AccessPathName(motifTypeFileName.Data());
537 AliError("Cannot overwrite existing motifType file");
541 ofstream padPosFile(padPosFileName.Data());
542 ofstream motifFile(motifTypeFileName.Data());
544 motifFile << "# Motif " << motifName << endl
546 << "#connecteur_berg kapton padname not_used" << endl
547 << "#for slats there's no kapton connector, so it's always 1"
548 << " (zero make the reader" << endl
549 << "#abort, so it's not a valid value here)." << endl
552 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
554 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
556 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
559 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
560 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;