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.6 2005/08/26 15:43:36 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
27 #include <Riostream.h>
29 #include "AliMpMotifType.h"
30 #include "AliMpMotifTypePadIterator.h"
31 #include "AliMpConnection.h"
33 ClassImp(AliMpMotifType)
35 const Int_t AliMpMotifType::fgkPadNumForA = 65;
37 const Int_t AliMpMotifType::fgkSeparator = 10000;
41 //______________________________________________________________________________
42 AliMpMotifType::AliMpMotifType(const TString &id)
50 /// Standard constructor
53 //______________________________________________________________________________
54 AliMpMotifType::AliMpMotifType()
62 /// Default constructor
65 //______________________________________________________________________________
66 AliMpMotifType::~AliMpMotifType()
71 for(ConnectionMapCIterator i = fConnections.begin();
72 i!=fConnections.end();++i)
75 fConnections.erase(fConnections.begin(),fConnections.end());
79 ConnectionMapCIterator i(&fConnections);
81 while ( i.Next(key, value) ) delete (AliMpConnection*)value;
87 //______________________________________________________________________________
88 Int_t AliMpMotifType::GetIndex(const AliMpIntPair& pair) const
90 /// Convert the pair of integers to integer.
92 if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator)
93 Fatal("GetIndex", "Index out of limit.");
95 return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1;
98 //______________________________________________________________________________
99 AliMpIntPair AliMpMotifType::GetPair(Int_t index) const
101 /// Convert the integer index to the pair of integers.
103 return AliMpIntPair((index-1)/fgkSeparator,(index-1)%fgkSeparator);
107 //______________________________________________________________________________
108 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
110 /// Create new motif type iterator
112 return new AliMpMotifTypePadIterator(this);
115 //______________________________________________________________________________
116 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
118 /// Change the number of pads in this motif
120 fNofPadsX = nofPadsX;
121 fNofPadsY = nofPadsY;
125 //______________________________________________________________________________
126 Int_t AliMpMotifType::PadNum(const TString &padName) const
128 /// Transform a pad name into the equivalent pad number
130 if ( (padName[0]>='A') && (padName[0]<='Z') )
131 return fgkPadNumForA+padName[0]-'A';
133 return atoi(padName.Data());
136 //______________________________________________________________________________
137 TString AliMpMotifType::PadName(Int_t padNum) const
139 /// Transform a pad number into its equivalent pad name
141 if (padNum<fgkPadNumForA)
142 return Form("%d",padNum);
144 return char('A'+padNum-fgkPadNumForA);
147 //______________________________________________________________________________
148 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
149 AliMpConnection* connection)
151 /// Add the connection to the map
154 fConnections[localIndices]=connection;
158 fConnections.Add(GetIndex(localIndices), (Long_t)connection);
161 connection->SetOwner(this);
164 //______________________________________________________________________________
165 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
167 /// Retrieve the AliMpConnection pointer from its pad num
170 for(ConnectionMapCIterator i = fConnections.begin();
171 i!=fConnections.end();++i)
172 if (i->second->GetPadNum()==padNum) return i->second;
177 ConnectionMapCIterator i(&fConnections);
179 while ( i.Next(key, value) ) {
180 AliMpConnection* connection = (AliMpConnection*)value;
181 if (connection->GetPadNum()==padNum) return connection;
187 //______________________________________________________________________________
188 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
189 const AliMpIntPair& localIndices) const
191 /// Retrieve the AliMpConnection pointer from its position (in pad unit)
193 if (!localIndices.IsValid()) return 0;
196 ConnectionMapCIterator i = fConnections.find(localIndices);
197 if (i != fConnections.end())
203 Long_t value = fConnections.GetValue(GetIndex(localIndices));
205 return (AliMpConnection*)value;
211 //______________________________________________________________________________
212 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
214 /// Return the connection for the given gassiplex number
217 for(ConnectionMapCIterator i = fConnections.begin();
218 i!=fConnections.end();++i)
219 if (i->second->GetGassiNum()==gassiNum) return i->second;
224 ConnectionMapCIterator i(&fConnections);
226 while ( i.Next(key, value) ) {
227 AliMpConnection* connection = (AliMpConnection*)value;
228 if (connection->GetGassiNum()==gassiNum) return connection;
234 //______________________________________________________________________________
235 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
237 /// Give the connection related to the given kapton number
240 for(ConnectionMapCIterator i = fConnections.begin();
241 i!=fConnections.end();++i)
242 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
247 ConnectionMapCIterator i(&fConnections);
249 while ( i.Next(key, value) ) {
250 AliMpConnection* connection = (AliMpConnection*)value;
251 if (connection->GetKaptonNum()==kaptonNum) return connection;
256 //______________________________________________________________________________
257 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
259 /// Retrieve the connection from a Berg connector number
262 for(ConnectionMapCIterator i = fConnections.begin();
263 i!=fConnections.end();++i)
264 if (i->second->GetBergNum()==bergNum) return i->second;
269 ConnectionMapCIterator i(&fConnections);
271 while ( i.Next(key, value) ) {
272 AliMpConnection* connection = (AliMpConnection*)value;
273 if (connection->GetBergNum()==bergNum) return connection;
280 //______________________________________________________________________________
281 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
282 const AliMpConnection* connection) const
284 /// Retrieve the pad position from the connection pointer.
285 /// Not to be used widely, since it use a search in the
286 /// connection list...
289 for(ConnectionMapCIterator i = fConnections.begin();
290 i!=fConnections.end();++i)
291 if (i->second==connection) return i->first;
295 ConnectionMapCIterator i(&fConnections);
297 while ( i.Next(key, value) ) {
298 AliMpConnection* aConnection = (AliMpConnection*)value;
299 if (aConnection == connection) return GetPair(key);
303 return AliMpIntPair::Invalid();
306 //______________________________________________________________________________
307 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
309 /// Retrieve the AliMpConnection pointer from its pad num
312 for(ConnectionMapCIterator i = fConnections.begin();
313 i!=fConnections.end();++i)
314 if (i->second->GetPadNum()==padNum) return i->first;
318 ConnectionMapCIterator i(&fConnections);
320 while ( i.Next(key, value) ) {
321 AliMpConnection* connection = (AliMpConnection*)value;
322 if (connection->GetPadNum() == padNum) return GetPair(key);
325 return AliMpIntPair::Invalid();
328 //______________________________________________________________________________
329 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
331 /// Return the connection for the given gassiplex number
334 for(ConnectionMapCIterator i = fConnections.begin();
335 i!=fConnections.end();++i)
336 if (i->second->GetGassiNum()==gassiNum) return i->first;
340 ConnectionMapCIterator i(&fConnections);
342 while ( i.Next(key, value) ) {
343 AliMpConnection* connection = (AliMpConnection*)value;
344 if (connection->GetGassiNum()==gassiNum) return GetPair(key);
348 return AliMpIntPair::Invalid();
351 //______________________________________________________________________________
352 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
354 /// Give the connection related to the given kapton number
357 for(ConnectionMapCIterator i = fConnections.begin();
358 i!=fConnections.end();++i)
359 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
363 ConnectionMapCIterator i(&fConnections);
365 while ( i.Next(key, value) ) {
366 AliMpConnection* connection = (AliMpConnection*)value;
367 if (connection->GetKaptonNum()==kaptonNum) return GetPair(key);
371 return AliMpIntPair::Invalid();
374 //______________________________________________________________________________
375 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
377 /// Retrieve the connection from a Berg connector number
380 for(ConnectionMapCIterator i = fConnections.begin();
381 i!=fConnections.end();++i)
382 if (i->second->GetBergNum()==bergNum) return i->first;
386 ConnectionMapCIterator i(&fConnections);
388 while ( i.Next(key, value) ) {
389 AliMpConnection* connection = (AliMpConnection*)value;
390 if (connection->GetBergNum()==bergNum) return GetPair(key);
394 return AliMpIntPair::Invalid();
397 //______________________________________________________________________________
398 Int_t AliMpMotifType::GetNofPads() const
400 /// Return the number of pads
403 return fConnections.size();
407 return fConnections.GetSize();
411 //______________________________________________________________________________
412 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
414 /// Return true if the pad indexed by <localIndices> has a connection
416 if (!localIndices.IsValid()) return false;
419 return fConnections.find(localIndices)!=fConnections.end();
423 Long_t value = fConnections.GetValue(GetIndex(localIndices));
428 //______________________________________________________________________________
429 void AliMpMotifType::Print(Option_t *option) const
431 /// Print the map of the motif. In each cell, the value
432 /// printed depends of option, as the following:
433 /// - option="N" the "name" of the pad is written
434 /// - option="K" the Kapton connect. number attached to the pad is written
435 /// - option="B" the Berg connect. number attached to the pad is written
436 /// - option="G" the Gassiplex channel number attached to the pad is written
437 /// otherwise the number of the pad is written
439 /// NOTE : this method is really not optimized, in case 'N' or '',
440 /// but the Print() this should not be very important in a Print() method
443 case 'N':cout<<"Name mapping";
445 case 'K':cout<<"Kapton mapping";
447 case 'B':cout<<"Berg mapping";
449 case 'G':cout<<"Gassiplex number mapping";
451 default:cout<<"Pad mapping";
453 cout<<" in the motif "<<fID<<endl;
454 cout<<"-----------------------------------"<<endl;
456 for (Int_t j=fNofPadsY-1;j>=0;j--){
457 for (Int_t i=0;i<fNofPadsX;i++){
458 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
462 case 'N':str=PadName(connexion->GetPadNum());
464 case 'K':str=Form("%d",connexion->GetKaptonNum());
466 case 'B':str=Form("%d",connexion->GetBergNum());
468 case 'G':str=Form("%d",connexion->GetGassiNum());
470 default:str= Form("%d",connexion->GetPadNum());
473 } else cout<<setw(2)<<"--";