4 // Class AliMpMotifType
5 // --------------------
6 // Class that defines the motif properties.
7 // Included in AliRoot: 2003/05/02
8 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
11 #include <Riostream.h>
13 #include "AliMpMotifType.h"
14 #include "AliMpMotifTypePadIterator.h"
15 #include "AliMpConnection.h"
17 ClassImp(AliMpMotifType)
19 const Int_t AliMpMotifType::fgkPadNumForA = 65;
21 const Int_t AliMpMotifType::fgkSeparator = 10000;
25 //______________________________________________________________________________
26 AliMpMotifType::AliMpMotifType(const TString &id)
37 //______________________________________________________________________________
38 AliMpMotifType::AliMpMotifType()
46 // Default constructor (dummy)
49 //______________________________________________________________________________
50 AliMpMotifType::~AliMpMotifType() {
54 for(ConnectionMapCIterator i = fConnections.begin();
55 i!=fConnections.end();++i)
58 fConnections.erase(fConnections.begin(),fConnections.end());
62 ConnectionMapCIterator i(&fConnections);
64 while ( i.Next(key, value) ) delete (AliMpConnection*)value;
69 //______________________________________________________________________________
70 Int_t AliMpMotifType::GetIndex(const AliMpIntPair& pair) const
72 // Converts the pair of integers to integer.
75 if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator)
76 Fatal("GetIndex", "Index out of limit.");
78 return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1;
81 //______________________________________________________________________________
82 AliMpIntPair AliMpMotifType::GetPair(Int_t index) const
84 // Converts the integer index to the pair of integers.
87 return AliMpIntPair((index-1)/fgkSeparator,(index-1)%fgkSeparator);
91 //______________________________________________________________________________
92 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
94 return new AliMpMotifTypePadIterator(this);
97 //______________________________________________________________________________
98 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
100 // Change the number of pads in this motif
102 fNofPadsX = nofPadsX;
103 fNofPadsY = nofPadsY;
107 //______________________________________________________________________________
108 Int_t AliMpMotifType::PadNum(const TString &padName) const
110 // Transform a pad name into the equivalent pad number
111 if ( (padName[0]>='A') && (padName[0]<='Z') )
112 return fgkPadNumForA+padName[0]-'A';
114 return atoi(padName.Data());
117 //______________________________________________________________________________
118 TString AliMpMotifType::PadName(Int_t padNum) const
120 // Transform a pad number into its equivalent pad name
121 if (padNum<fgkPadNumForA)
122 return Form("%d",padNum);
124 return char('A'+padNum-fgkPadNumForA);
127 //______________________________________________________________________________
128 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
129 AliMpConnection* connection)
131 // Add the connection to the map
134 fConnections[localIndices]=connection;
138 fConnections.Add(GetIndex(localIndices), (Long_t)connection);
141 connection->SetOwner(this);
144 //______________________________________________________________________________
145 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
147 // Retrieve the AliMpConnection pointer from its pad num
149 for(ConnectionMapCIterator i = fConnections.begin();
150 i!=fConnections.end();++i)
151 if (i->second->GetPadNum()==padNum) return i->second;
156 ConnectionMapCIterator i(&fConnections);
158 while ( i.Next(key, value) ) {
159 AliMpConnection* connection = (AliMpConnection*)value;
160 if (connection->GetPadNum()==padNum) return connection;
166 //______________________________________________________________________________
167 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
168 const AliMpIntPair& localIndices) const
170 // Retrieve the AliMpConnection pointer from its position (in pad unit)
171 if (!localIndices.IsValid()) return 0;
174 ConnectionMapCIterator i = fConnections.find(localIndices);
175 if (i != fConnections.end())
181 Long_t value = fConnections.GetValue(GetIndex(localIndices));
183 return (AliMpConnection*)value;
189 //______________________________________________________________________________
190 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
192 // Return the connection for the given gassiplex number
194 for(ConnectionMapCIterator i = fConnections.begin();
195 i!=fConnections.end();++i)
196 if (i->second->GetGassiNum()==gassiNum) return i->second;
201 ConnectionMapCIterator i(&fConnections);
203 while ( i.Next(key, value) ) {
204 AliMpConnection* connection = (AliMpConnection*)value;
205 if (connection->GetGassiNum()==gassiNum) return connection;
211 //______________________________________________________________________________
212 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
214 // Gives the connection related to the given kapton number
216 for(ConnectionMapCIterator i = fConnections.begin();
217 i!=fConnections.end();++i)
218 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
223 ConnectionMapCIterator i(&fConnections);
225 while ( i.Next(key, value) ) {
226 AliMpConnection* connection = (AliMpConnection*)value;
227 if (connection->GetKaptonNum()==kaptonNum) return connection;
232 //______________________________________________________________________________
233 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
235 // Retrieve the connection from a Berg connector number
237 for(ConnectionMapCIterator i = fConnections.begin();
238 i!=fConnections.end();++i)
239 if (i->second->GetBergNum()==bergNum) return i->second;
244 ConnectionMapCIterator i(&fConnections);
246 while ( i.Next(key, value) ) {
247 AliMpConnection* connection = (AliMpConnection*)value;
248 if (connection->GetBergNum()==bergNum) return connection;
255 //______________________________________________________________________________
256 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
257 const AliMpConnection* connection) const
259 // Retrieve the pad position from the connection pointer.
260 // Not to be used widely, since it use a search in the
261 // connection list...
264 for(ConnectionMapCIterator i = fConnections.begin();
265 i!=fConnections.end();++i)
266 if (i->second==connection) return i->first;
270 ConnectionMapCIterator i(&fConnections);
272 while ( i.Next(key, value) ) {
273 AliMpConnection* aConnection = (AliMpConnection*)value;
274 if (aConnection == connection) return GetPair(key);
278 return AliMpIntPair::Invalid();
281 //______________________________________________________________________________
282 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
284 // Retrieve the AliMpConnection pointer from its pad num
286 for(ConnectionMapCIterator i = fConnections.begin();
287 i!=fConnections.end();++i)
288 if (i->second->GetPadNum()==padNum) return i->first;
292 ConnectionMapCIterator i(&fConnections);
294 while ( i.Next(key, value) ) {
295 AliMpConnection* connection = (AliMpConnection*)value;
296 if (connection->GetPadNum() == padNum) return GetPair(key);
299 return AliMpIntPair::Invalid();
302 //______________________________________________________________________________
303 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
305 // return the connection for the given gassiplex number
307 for(ConnectionMapCIterator i = fConnections.begin();
308 i!=fConnections.end();++i)
309 if (i->second->GetGassiNum()==gassiNum) return i->first;
313 ConnectionMapCIterator i(&fConnections);
315 while ( i.Next(key, value) ) {
316 AliMpConnection* connection = (AliMpConnection*)value;
317 if (connection->GetGassiNum()==gassiNum) return GetPair(key);
321 return AliMpIntPair::Invalid();
324 //______________________________________________________________________________
325 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
327 // Gives the connection related to the given kapton number
329 for(ConnectionMapCIterator i = fConnections.begin();
330 i!=fConnections.end();++i)
331 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
335 ConnectionMapCIterator i(&fConnections);
337 while ( i.Next(key, value) ) {
338 AliMpConnection* connection = (AliMpConnection*)value;
339 if (connection->GetKaptonNum()==kaptonNum) return GetPair(key);
343 return AliMpIntPair::Invalid();
346 //______________________________________________________________________________
347 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
349 // Retrieve the connection from a Berg connector number
351 for(ConnectionMapCIterator i = fConnections.begin();
352 i!=fConnections.end();++i)
353 if (i->second->GetBergNum()==bergNum) return i->first;
357 ConnectionMapCIterator i(&fConnections);
359 while ( i.Next(key, value) ) {
360 AliMpConnection* connection = (AliMpConnection*)value;
361 if (connection->GetBergNum()==bergNum) return GetPair(key);
365 return AliMpIntPair::Invalid();
368 //______________________________________________________________________________
369 Int_t AliMpMotifType::GetNofPads() const
371 // Returns the number of pads
374 return fConnections.size();
378 return fConnections.GetSize();
382 //______________________________________________________________________________
383 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
385 // Return true if the pad indexed by <localIndices> has a connection
386 if (!localIndices.IsValid()) return false;
389 return fConnections.find(localIndices)!=fConnections.end();
393 Long_t value = fConnections.GetValue(GetIndex(localIndices));
398 //______________________________________________________________________________
399 void AliMpMotifType::Print(Option_t *option) const
401 // Print the map of the motif. In each cel, the value
402 // printed depends of option, as the following:
403 // option="N" the "name" of the pad is written
404 // option="K" the Kapton connect. number attached to the pad is written
405 // option="B" the Berg connect. number attached to the pad is written
406 // option="G" the Gassiplex channel number attached to the pad is written
407 // otherwise the number of the pad is written
409 // NOTE : this method is really not optimized, in case 'N' or '',
410 // but the Print() this should not be very important in a Print() method
413 case 'N':cout<<"Name mapping";
415 case 'K':cout<<"Kapton mapping";
417 case 'B':cout<<"Berg mapping";
419 case 'G':cout<<"Gassiplex number mapping";
421 default:cout<<"Pad mapping";
423 cout<<" in the motif "<<fID<<endl;
424 cout<<"-----------------------------------"<<endl;
426 for (Int_t j=fNofPadsY-1;j>=0;j--){
427 for (Int_t i=0;i<fNofPadsX;i++){
428 AliMpConnection *connexion = FindConnectionByLocalIndices(AliMpIntPair(i,j));
432 case 'N':str=PadName(connexion->GetPadNum());
434 case 'K':str=Form("%d",connexion->GetKaptonNum());
436 case 'B':str=Form("%d",connexion->GetBergNum());
438 case 'G':str=Form("%d",connexion->GetGassiNum());
440 default:str= Form("%d",connexion->GetPadNum());
443 } else cout<<setw(2)<<"--";