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)
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()
70 /// Default constructor
71 AliDebug(1,Form("this=%p",this));
74 //______________________________________________________________________________
75 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.fConnections = fConnections;
121 //______________________________________________________________________________
122 AliMpMotifType::~AliMpMotifType()
127 for(ConnectionMapCIterator i = fConnections.begin();
128 i!=fConnections.end();++i)
131 fConnections.erase(fConnections.begin(),fConnections.end());
134 AliDebug(1,Form("this=%p",this));
135 // StdoutToAliDebug(1,this->Print(););
138 //______________________________________________________________________________
139 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
141 /// Create new motif type iterator
143 return new AliMpMotifTypePadIterator(this);
146 //______________________________________________________________________________
147 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
149 /// Change the number of pads in this motif
151 fNofPadsX = nofPadsX;
152 fNofPadsY = nofPadsY;
156 //______________________________________________________________________________
157 Int_t AliMpMotifType::PadNum(const TString &padName) const
159 /// Transform a pad name into the equivalent pad number
161 if ( (padName[0]>='A') && (padName[0]<='Z') )
162 return fgkPadNumForA+padName[0]-'A';
164 return atoi(padName.Data());
167 //______________________________________________________________________________
168 TString AliMpMotifType::PadName(Int_t padNum) const
170 /// Transform a pad number into its equivalent pad name
172 if (padNum<fgkPadNumForA)
173 return Form("%d",padNum);
175 return char('A'+padNum-fgkPadNumForA);
178 //______________________________________________________________________________
179 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
180 AliMpConnection* connection)
182 /// Add the connection to the map
185 fConnections[localIndices]=connection;
189 fConnections.Add(localIndices, connection);
192 connection->SetOwner(this);
195 //______________________________________________________________________________
196 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
198 /// Retrieve the AliMpConnection pointer from its pad num
201 for(ConnectionMapCIterator i = fConnections.begin();
202 i!=fConnections.end();++i)
203 if (i->second->GetPadNum()==padNum) return i->second;
208 TExMapIter i = fConnections.GetIterator();
210 while ( i.Next(key, value) ) {
211 AliMpConnection* connection = (AliMpConnection*)value;
212 if (connection->GetPadNum()==padNum) return connection;
218 //______________________________________________________________________________
219 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
220 const AliMpIntPair& localIndices) const
222 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
224 if (!localIndices.IsValid()) return 0;
227 ConnectionMapCIterator i = fConnections.find(localIndices);
228 if (i != fConnections.end())
234 return (AliMpConnection*)fConnections.GetValue(localIndices);
238 //______________________________________________________________________________
239 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
241 /// Return the connection for the given gassiplex number
244 for(ConnectionMapCIterator i = fConnections.begin();
245 i!=fConnections.end();++i)
246 if (i->second->GetGassiNum()==gassiNum) return i->second;
251 TExMapIter i = fConnections.GetIterator();
253 while ( i.Next(key, value) ) {
254 AliMpConnection* connection = (AliMpConnection*)value;
255 if (connection->GetGassiNum()==gassiNum) return connection;
261 //______________________________________________________________________________
262 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
264 /// Give the connection related to the given kapton number
267 for(ConnectionMapCIterator i = fConnections.begin();
268 i!=fConnections.end();++i)
269 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
274 TExMapIter i = fConnections.GetIterator();
276 while ( i.Next(key, value) ) {
277 AliMpConnection* connection = (AliMpConnection*)value;
278 if (connection->GetKaptonNum()==kaptonNum) return connection;
283 //______________________________________________________________________________
284 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
286 /// Retrieve the connection from a Berg connector number
289 for(ConnectionMapCIterator i = fConnections.begin();
290 i!=fConnections.end();++i)
291 if (i->second->GetBergNum()==bergNum) return i->second;
296 TExMapIter i = fConnections.GetIterator();
298 while ( i.Next(key, value) ) {
299 AliMpConnection* connection = (AliMpConnection*)value;
300 if (connection->GetBergNum()==bergNum) return connection;
307 //______________________________________________________________________________
308 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
309 const AliMpConnection* connection) const
311 /// Retrieve the pad position from the connection pointer.
312 /// Not to be used widely, since it use a search in the
313 /// connection list...
316 for(ConnectionMapCIterator i = fConnections.begin();
317 i!=fConnections.end();++i)
318 if (i->second==connection) return i->first;
322 TExMapIter i = fConnections.GetIterator();
324 while ( i.Next(key, value) ) {
325 AliMpConnection* aConnection = (AliMpConnection*)value;
326 if (aConnection == connection) return AliMpExMap::GetPair(key);
330 return AliMpIntPair::Invalid();
333 //______________________________________________________________________________
334 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
336 /// Retrieve the AliMpConnection pointer from its pad num
339 for(ConnectionMapCIterator i = fConnections.begin();
340 i!=fConnections.end();++i)
341 if (i->second->GetPadNum()==padNum) return i->first;
345 TExMapIter i = fConnections.GetIterator();
347 while ( i.Next(key, value) ) {
348 AliMpConnection* connection = (AliMpConnection*)value;
349 if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
352 return AliMpIntPair::Invalid();
355 //______________________________________________________________________________
356 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
358 /// Return the connection for the given gassiplex number
361 for(ConnectionMapCIterator i = fConnections.begin();
362 i!=fConnections.end();++i)
363 if (i->second->GetGassiNum()==gassiNum) return i->first;
367 TExMapIter i = fConnections.GetIterator();
369 while ( i.Next(key, value) ) {
370 AliMpConnection* connection = (AliMpConnection*)value;
371 if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
375 return AliMpIntPair::Invalid();
378 //______________________________________________________________________________
379 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
381 /// Give the connection related to the given kapton number
384 for(ConnectionMapCIterator i = fConnections.begin();
385 i!=fConnections.end();++i)
386 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
390 TExMapIter i = fConnections.GetIterator();
392 while ( i.Next(key, value) ) {
393 AliMpConnection* connection = (AliMpConnection*)value;
394 if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::GetPair(key);
398 return AliMpIntPair::Invalid();
401 //______________________________________________________________________________
402 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
404 /// Retrieve the connection from a Berg connector number
407 for(ConnectionMapCIterator i = fConnections.begin();
408 i!=fConnections.end();++i)
409 if (i->second->GetBergNum()==bergNum) return i->first;
413 TExMapIter i = fConnections.GetIterator();
415 while ( i.Next(key, value) ) {
416 AliMpConnection* connection = (AliMpConnection*)value;
417 if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
421 return AliMpIntPair::Invalid();
424 //______________________________________________________________________________
425 Int_t AliMpMotifType::GetNofPads() const
427 /// Return the number of pads
430 return fConnections.size();
434 return fConnections.GetSize();
438 //______________________________________________________________________________
439 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
441 /// Return true if the pad indexed by \a localIndices has a connection
443 if (!localIndices.IsValid()) return false;
446 return fConnections.find(localIndices)!=fConnections.end();
450 TObject* value = fConnections.GetValue(localIndices);
455 //______________________________________________________________________________
456 void AliMpMotifType::Print(Option_t *option) const
458 /// Print the map of the motif. In each cell, the value
459 /// printed depends of option, as the following:
460 /// - option="N" the "name" of the pad is written
461 /// - option="K" the Kapton connect. number attached to the pad is written
462 /// - option="B" the Berg connect. number attached to the pad is written
463 /// - option="G" the Gassiplex channel number attached to the pad is written
464 /// otherwise the number of the pad is written
466 /// NOTE : this method is really not optimized, in case 'N' or '',
467 /// but the Print() this should not be very important in a Print() method
470 case 'N':cout<<"Name mapping";
472 case 'K':cout<<"Kapton mapping";
474 case 'B':cout<<"Berg mapping";
476 case 'G':cout<<"Gassiplex number mapping";
478 default:cout<<"Pad mapping";
480 cout<<" in the motif "<<fID<<endl;
481 cout<<"-----------------------------------"<<endl;
483 for (Int_t j=fNofPadsY-1;j>=0;j--){
484 for (Int_t i=0;i<fNofPadsX;i++){
485 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
488 AliDebug(1,Form("i,j=%2d,%2d connexion=%p",i,j,connexion));
491 case 'N':str=PadName(connexion->GetPadNum());
493 case 'K':str=Form("%d",connexion->GetKaptonNum());
495 case 'B':str=Form("%d",connexion->GetBergNum());
497 case 'G':str=Form("%d",connexion->GetGassiNum());
499 default:str= Form("%d",connexion->GetPadNum());
502 } else cout<<setw(2)<<"--";
509 //_____________________________________________________________________________
511 AliMpMotifType::Save() const
513 /// Save this motif type
515 return Save(fID.Data());
518 //_____________________________________________________________________________
520 AliMpMotifType::Save(const char* motifName) const
522 /// Generate the 2 files needed to describe the motif
524 TString padPosFileName(AliMpFiles::PadPosFileName(motifName));
526 TString motifTypeFileName(AliMpFiles::MotifFileName(motifName));
528 // first a protection : do not allow overwriting existing files...
529 Bool_t test = gSystem->AccessPathName(padPosFileName.Data());
530 if (test==kFALSE) // AccessPathName has a strange return value convention...
532 AliError("Cannot overwrite existing padPos file");
535 test = gSystem->AccessPathName(motifTypeFileName.Data());
538 AliError("Cannot overwrite existing motifType file");
542 ofstream padPosFile(padPosFileName.Data());
543 ofstream motifFile(motifTypeFileName.Data());
545 motifFile << "# Motif " << motifName << endl
547 << "#connecteur_berg kapton padname not_used" << endl
548 << "#for slats there's no kapton connector, so it's always 1"
549 << " (zero make the reader" << endl
550 << "#abort, so it's not a valid value here)." << endl
553 for ( Int_t ix = 0; ix < GetNofPadsX(); ++ix )
555 for ( Int_t iy = 0; iy < GetNofPadsY(); ++iy )
557 AliMpConnection* con = FindConnectionByLocalIndices(AliMpIntPair(ix,iy));
560 motifFile << con->GetBergNum() << "\t1\t" << con->GetPadNum() << "\t-" << endl;
561 padPosFile << con->GetPadNum() << "\t" << ix << "\t" << iy << endl;