]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpMotifType.cxx
New digits structure, cathode planes are mixed in the same list (Christian)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifType.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: motif
3//
4// Class AliMpMotifType
5// --------------------
6// Class that defines the motif properties.
dbe945cc 7// Included in AliRoot: 2003/05/02
5f91c9e8 8// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
9
ec094451 10#include <stdlib.h>
5f91c9e8 11#include <Riostream.h>
12
13#include "AliMpMotifType.h"
14#include "AliMpMotifTypePadIterator.h"
15#include "AliMpConnection.h"
16
17ClassImp(AliMpMotifType)
18
19const Int_t AliMpMotifType::fgkPadNumForA = 65;
f79c58a5 20#ifdef WITH_ROOT
21const Int_t AliMpMotifType::fgkSeparator = 10000;
22#endif
5f91c9e8 23
24
25//______________________________________________________________________________
26AliMpMotifType::AliMpMotifType(const TString &id)
27 : TObject(),
28 fID(id),
29 fNofPadsX(0),
30 fNofPadsY(0),
31 fVerboseLevel(0),
32 fConnections()
33{
34 // Constructor
35}
36
37//______________________________________________________________________________
38AliMpMotifType::AliMpMotifType()
39 : TObject(),
40 fID(""),
41 fNofPadsX(0),
42 fNofPadsY(0),
43 fVerboseLevel(0),
44 fConnections()
45{
46 // Default constructor (dummy)
47}
48
49//______________________________________________________________________________
50AliMpMotifType::~AliMpMotifType() {
51// Destructor
52
f79c58a5 53#ifdef WITH_STL
2f2452f8 54 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 55 i!=fConnections.end();++i)
56 delete i->second;
57
58 fConnections.erase(fConnections.begin(),fConnections.end());
f79c58a5 59#endif
60
61#ifdef WITH_ROOT
62 ConnectionMapCIterator i(&fConnections);
63 Long_t key, value;
64 while ( i.Next(key, value) ) delete (AliMpConnection*)value;
65#endif
5f91c9e8 66}
67
f79c58a5 68#ifdef WITH_ROOT
69//______________________________________________________________________________
70Int_t AliMpMotifType::GetIndex(const AliMpIntPair& pair) const
71{
72// Converts the pair of integers to integer.
73// ---
74
75 if (pair.GetFirst() >= fgkSeparator || pair.GetSecond() >= fgkSeparator)
76 Fatal("GetIndex", "Index out of limit.");
77
78 return pair.GetFirst()*fgkSeparator + pair.GetSecond() + 1;
79}
80
81//______________________________________________________________________________
82AliMpIntPair AliMpMotifType::GetPair(Int_t index) const
83{
84// Converts the integer index to the pair of integers.
85// ---
86
87 return AliMpIntPair((index-1)/fgkSeparator,(index-1)%fgkSeparator);
88}
89#endif
90
5f91c9e8 91//______________________________________________________________________________
92AliMpVPadIterator* AliMpMotifType::CreateIterator() const
93{
94 return new AliMpMotifTypePadIterator(this);
95}
96
97//______________________________________________________________________________
98void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
99{
100 // Change the number of pads in this motif
101
102 fNofPadsX = nofPadsX;
103 fNofPadsY = nofPadsY;
104}
105
106
107//______________________________________________________________________________
108Int_t AliMpMotifType::PadNum(const TString &padName) const
109{
110 // Transform a pad name into the equivalent pad number
111 if ( (padName[0]>='A') && (padName[0]<='Z') )
112 return fgkPadNumForA+padName[0]-'A';
113 else
114 return atoi(padName.Data());
115}
116
117//______________________________________________________________________________
118TString AliMpMotifType::PadName(Int_t padNum) const
119{
120 // Transform a pad number into its equivalent pad name
121 if (padNum<fgkPadNumForA)
122 return Form("%d",padNum);
123 else
124 return char('A'+padNum-fgkPadNumForA);
125}
126
127//______________________________________________________________________________
128void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices,
129 AliMpConnection* connection)
130{
131 // Add the connection to the map
132
f79c58a5 133#ifdef WITH_STL
5f91c9e8 134 fConnections[localIndices]=connection;
f79c58a5 135#endif
136
137#ifdef WITH_ROOT
138 fConnections.Add(GetIndex(localIndices), (Long_t)connection);
139#endif
140
5f91c9e8 141 connection->SetOwner(this);
142}
f79c58a5 143
5f91c9e8 144//______________________________________________________________________________
145AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
146{
f79c58a5 147 // Retrieve the AliMpConnection pointer from its pad num
148#ifdef WITH_STL
2f2452f8 149 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 150 i!=fConnections.end();++i)
151 if (i->second->GetPadNum()==padNum) return i->second;
152 return 0;
f79c58a5 153#endif
154
155#ifdef WITH_ROOT
156 ConnectionMapCIterator i(&fConnections);
157 Long_t key, value;
158 while ( i.Next(key, value) ) {
159 AliMpConnection* connection = (AliMpConnection*)value;
160 if (connection->GetPadNum()==padNum) return connection;
161 }
162 return 0;
163#endif
5f91c9e8 164}
165
166//______________________________________________________________________________
167AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
2f2452f8 168 const AliMpIntPair& localIndices) const
5f91c9e8 169{
31e62cbe 170 // Retrieve the AliMpConnection pointer from its position (in pad unit)
5f91c9e8 171 if (!localIndices.IsValid()) return 0;
172
f79c58a5 173#ifdef WITH_STL
2f2452f8 174 ConnectionMapCIterator i = fConnections.find(localIndices);
5f91c9e8 175 if (i != fConnections.end())
176 return i->second;
177 else return 0;
f79c58a5 178#endif
179
180#ifdef WITH_ROOT
181 Long_t value = fConnections.GetValue(GetIndex(localIndices));
182 if (value)
183 return (AliMpConnection*)value;
184 else
185 return 0;
186#endif
5f91c9e8 187}
188
189//______________________________________________________________________________
190AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
191{
31e62cbe 192 // Return the connection for the given gassiplex number
f79c58a5 193#ifdef WITH_STL
2f2452f8 194 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 195 i!=fConnections.end();++i)
196 if (i->second->GetGassiNum()==gassiNum) return i->second;
197 return 0;
f79c58a5 198#endif
199
200#ifdef WITH_ROOT
201 ConnectionMapCIterator i(&fConnections);
202 Long_t key, value;
203 while ( i.Next(key, value) ) {
204 AliMpConnection* connection = (AliMpConnection*)value;
205 if (connection->GetGassiNum()==gassiNum) return connection;
206 }
207 return 0;
208#endif
5f91c9e8 209}
f79c58a5 210
5f91c9e8 211//______________________________________________________________________________
212AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
213{
214 // Gives the connection related to the given kapton number
f79c58a5 215#ifdef WITH_STL
2f2452f8 216 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 217 i!=fConnections.end();++i)
218 if (i->second->GetKaptonNum()==kaptonNum) return i->second;
219 return 0;
f79c58a5 220#endif
221
222#ifdef WITH_ROOT
223 ConnectionMapCIterator i(&fConnections);
224 Long_t key, value;
225 while ( i.Next(key, value) ) {
226 AliMpConnection* connection = (AliMpConnection*)value;
227 if (connection->GetKaptonNum()==kaptonNum) return connection;
228 }
229 return 0;
230#endif
5f91c9e8 231}
232//______________________________________________________________________________
233AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
234{
235 // Retrieve the connection from a Berg connector number
f79c58a5 236#ifdef WITH_STL
2f2452f8 237 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 238 i!=fConnections.end();++i)
239 if (i->second->GetBergNum()==bergNum) return i->second;
240 return 0;
f79c58a5 241#endif
242
243#ifdef WITH_ROOT
244 ConnectionMapCIterator i(&fConnections);
245 Long_t key, value;
246 while ( i.Next(key, value) ) {
247 AliMpConnection* connection = (AliMpConnection*)value;
248 if (connection->GetBergNum()==bergNum) return connection;
249 }
250 return 0;
251#endif
5f91c9e8 252}
253
254
255//______________________________________________________________________________
256AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
f79c58a5 257 const AliMpConnection* connection) const
5f91c9e8 258{
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...
262
f79c58a5 263#ifdef WITH_STL
2f2452f8 264 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 265 i!=fConnections.end();++i)
266 if (i->second==connection) return i->first;
f79c58a5 267#endif
268
269#ifdef WITH_ROOT
270 ConnectionMapCIterator i(&fConnections);
271 Long_t key, value;
272 while ( i.Next(key, value) ) {
273 AliMpConnection* aConnection = (AliMpConnection*)value;
274 if (aConnection == connection) return GetPair(key);
275 }
276#endif
277
278 return AliMpIntPair::Invalid();
5f91c9e8 279}
280
281//______________________________________________________________________________
282AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
283{
f79c58a5 284 // Retrieve the AliMpConnection pointer from its pad num
285#ifdef WITH_STL
2f2452f8 286 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 287 i!=fConnections.end();++i)
288 if (i->second->GetPadNum()==padNum) return i->first;
f79c58a5 289#endif
5f91c9e8 290
f79c58a5 291#ifdef WITH_ROOT
292 ConnectionMapCIterator i(&fConnections);
293 Long_t key, value;
294 while ( i.Next(key, value) ) {
295 AliMpConnection* connection = (AliMpConnection*)value;
296 if (connection->GetPadNum() == padNum) return GetPair(key);
297 }
298#endif
5f91c9e8 299 return AliMpIntPair::Invalid();
300}
301
302//______________________________________________________________________________
303AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
304{
305 // return the connection for the given gassiplex number
f79c58a5 306#ifdef WITH_STL
2f2452f8 307 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 308 i!=fConnections.end();++i)
309 if (i->second->GetGassiNum()==gassiNum) return i->first;
f79c58a5 310#endif
311
312#ifdef WITH_ROOT
313 ConnectionMapCIterator i(&fConnections);
314 Long_t key, value;
315 while ( i.Next(key, value) ) {
316 AliMpConnection* connection = (AliMpConnection*)value;
317 if (connection->GetGassiNum()==gassiNum) return GetPair(key);
318 }
319#endif
5f91c9e8 320
321 return AliMpIntPair::Invalid();
322}
323
324//______________________________________________________________________________
325AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
326{
327 // Gives the connection related to the given kapton number
f79c58a5 328#ifdef WITH_STL
2f2452f8 329 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 330 i!=fConnections.end();++i)
331 if (i->second->GetKaptonNum()==kaptonNum) return i->first;
f79c58a5 332#endif
333
334#ifdef WITH_ROOT
335 ConnectionMapCIterator i(&fConnections);
336 Long_t key, value;
337 while ( i.Next(key, value) ) {
338 AliMpConnection* connection = (AliMpConnection*)value;
339 if (connection->GetKaptonNum()==kaptonNum) return GetPair(key);
340 }
341#endif
5f91c9e8 342
343 return AliMpIntPair::Invalid();
344}
345
346//______________________________________________________________________________
347AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
348{
349 // Retrieve the connection from a Berg connector number
f79c58a5 350#ifdef WITH_STL
2f2452f8 351 for(ConnectionMapCIterator i = fConnections.begin();
5f91c9e8 352 i!=fConnections.end();++i)
353 if (i->second->GetBergNum()==bergNum) return i->first;
f79c58a5 354#endif
355
356#ifdef WITH_ROOT
357 ConnectionMapCIterator i(&fConnections);
358 Long_t key, value;
359 while ( i.Next(key, value) ) {
360 AliMpConnection* connection = (AliMpConnection*)value;
361 if (connection->GetBergNum()==bergNum) return GetPair(key);
362 }
363#endif
5f91c9e8 364
365 return AliMpIntPair::Invalid();
366}
367
f79c58a5 368//______________________________________________________________________________
369Int_t AliMpMotifType::GetNofPads() const
370{
371// Returns the number of pads
372
373#ifdef WITH_STL
374 return fConnections.size();
375#endif
376
377#ifdef WITH_ROOT
378 return fConnections.GetSize();
379#endif
380}
381
5f91c9e8 382//______________________________________________________________________________
383Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
384{
31e62cbe 385 // Return true if the pad indexed by <localIndices> has a connection
5f91c9e8 386 if (!localIndices.IsValid()) return false;
387
f79c58a5 388#ifdef WITH_STL
5f91c9e8 389 return fConnections.find(localIndices)!=fConnections.end();
f79c58a5 390#endif
5f91c9e8 391
f79c58a5 392#ifdef WITH_ROOT
393 Long_t value = fConnections.GetValue(GetIndex(localIndices));
394 return value!=0;
395#endif
5f91c9e8 396}
397
398//______________________________________________________________________________
399void AliMpMotifType::Print(Option_t *option) const
400{
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
408
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
411
412 switch (option[0]){
413 case 'N':cout<<"Name mapping";
414 break;
415 case 'K':cout<<"Kapton mapping";
416 break;
417 case 'B':cout<<"Berg mapping";
418 break;
419 case 'G':cout<<"Gassiplex number mapping";
420 break;
421 default:cout<<"Pad mapping";
422 }
423 cout<<" in the motif "<<fID<<endl;
424 cout<<"-----------------------------------"<<endl;
425
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));
429 TString str;
430 if (connexion){
431 switch (option[0]){
432 case 'N':str=PadName(connexion->GetPadNum());
433 break;
434 case 'K':str=Form("%d",connexion->GetKaptonNum());
435 break;
436 case 'B':str=Form("%d",connexion->GetBergNum());
437 break;
438 case 'G':str=Form("%d",connexion->GetGassiNum());
439 break;
440 default:str= Form("%d",connexion->GetPadNum());
441 }
442 cout<<setw(2)<<str;
443 } else cout<<setw(2)<<"--";
444 cout<<" ";
445 }
446 cout<<endl;
447 }
448}