]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifType.cxx
Mapping test macros (D. Guez, I. Hrivnacova)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpMotifType.cxx
1 // $Id$
2 // Category: motif
3 //
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
9
10 #include <stdlib.h>
11 #include <Riostream.h>
12
13 #include "AliMpMotifType.h"
14 #include "AliMpMotifTypePadIterator.h"
15 #include "AliMpConnection.h"
16
17 ClassImp(AliMpMotifType)
18
19 const Int_t AliMpMotifType::fgkPadNumForA = 65;
20 #ifdef WITH_ROOT
21 const Int_t AliMpMotifType::fgkSeparator = 10000;
22 #endif
23
24
25 //______________________________________________________________________________
26 AliMpMotifType::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 //______________________________________________________________________________
38 AliMpMotifType::AliMpMotifType() 
39   : TObject(),
40     fID(""),
41     fNofPadsX(0),   
42     fNofPadsY(0),
43     fVerboseLevel(0),
44     fConnections()
45 {
46   // Default constructor (dummy)
47 }
48
49 //______________________________________________________________________________
50 AliMpMotifType::~AliMpMotifType() {
51 // Destructor
52
53 #ifdef WITH_STL
54  for(ConnectionMapCIterator i = fConnections.begin();
55   i!=fConnections.end();++i)
56    delete i->second;
57
58   fConnections.erase(fConnections.begin(),fConnections.end());
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  
66 }
67
68 #ifdef WITH_ROOT
69 //______________________________________________________________________________
70 Int_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 //______________________________________________________________________________
82 AliMpIntPair  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
91 //______________________________________________________________________________
92 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
93 {
94   return new AliMpMotifTypePadIterator(this);
95 }
96
97 //______________________________________________________________________________
98 void 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 //______________________________________________________________________________
108 Int_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 //______________________________________________________________________________
118 TString 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 //______________________________________________________________________________
128 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices, 
129                                AliMpConnection* connection)
130 {
131   // Add the connection to the map
132   
133 #ifdef WITH_STL
134   fConnections[localIndices]=connection;
135 #endif
136
137 #ifdef WITH_ROOT
138   fConnections.Add(GetIndex(localIndices), (Long_t)connection);
139 #endif   
140
141   connection->SetOwner(this);
142 }  
143
144 //______________________________________________________________________________
145 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
146 {
147   // Retrieve the AliMpConnection pointer from its pad num
148 #ifdef WITH_STL
149  for(ConnectionMapCIterator i = fConnections.begin();
150   i!=fConnections.end();++i)
151    if (i->second->GetPadNum()==padNum) return i->second;
152  return 0;
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
164 }
165
166 //______________________________________________________________________________
167 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
168                                        const AliMpIntPair& localIndices) const
169 {
170   // Retrieve the AliMpConnection pointer from its position (in pad unit)
171   if (!localIndices.IsValid()) return 0;
172
173 #ifdef WITH_STL
174   ConnectionMapCIterator i = fConnections.find(localIndices);
175  if (i != fConnections.end())
176    return i->second;
177  else return 0;
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
187 }
188
189 //______________________________________________________________________________
190 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
191 {
192   // Return the connection for the given gassiplex number
193 #ifdef WITH_STL
194  for(ConnectionMapCIterator i = fConnections.begin();
195   i!=fConnections.end();++i)
196    if (i->second->GetGassiNum()==gassiNum) return i->second;
197  return 0;
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
209 }
210
211 //______________________________________________________________________________
212 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
213 {
214   // Gives the connection related to the given kapton number
215 #ifdef WITH_STL
216  for(ConnectionMapCIterator i = fConnections.begin();
217   i!=fConnections.end();++i)
218    if (i->second->GetKaptonNum()==kaptonNum) return i->second;
219  return 0;
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
231 }
232 //______________________________________________________________________________
233 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
234 {
235   // Retrieve the connection from a Berg connector number
236 #ifdef WITH_STL
237  for(ConnectionMapCIterator i = fConnections.begin();
238   i!=fConnections.end();++i)
239    if (i->second->GetBergNum()==bergNum) return i->second;
240  return 0;
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
252 }
253
254
255 //______________________________________________________________________________
256 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
257                                  const AliMpConnection* connection) const
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
263 #ifdef WITH_STL
264  for(ConnectionMapCIterator i = fConnections.begin();
265   i!=fConnections.end();++i)
266    if (i->second==connection) return i->first;
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();
279 }
280
281 //______________________________________________________________________________
282 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
283 {
284   // Retrieve the AliMpConnection pointer from its pad num
285 #ifdef WITH_STL
286  for(ConnectionMapCIterator i = fConnections.begin();
287   i!=fConnections.end();++i)
288    if (i->second->GetPadNum()==padNum) return i->first;
289 #endif
290    
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
299  return AliMpIntPair::Invalid();
300 }
301
302 //______________________________________________________________________________
303 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
304 {
305   // return the connection for the given gassiplex number
306 #ifdef WITH_STL
307  for(ConnectionMapCIterator i = fConnections.begin();
308   i!=fConnections.end();++i)
309    if (i->second->GetGassiNum()==gassiNum) return i->first;
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
320    
321  return AliMpIntPair::Invalid();
322 }
323
324 //______________________________________________________________________________
325 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
326 {
327   // Gives the connection related to the given kapton number
328 #ifdef WITH_STL
329  for(ConnectionMapCIterator i = fConnections.begin();
330   i!=fConnections.end();++i)
331    if (i->second->GetKaptonNum()==kaptonNum) return i->first;
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
342    
343  return AliMpIntPair::Invalid();
344 }
345
346 //______________________________________________________________________________
347 AliMpIntPair AliMpMotifType::FindLocalIndicesByBergNum(Int_t bergNum) const
348 {
349   // Retrieve the connection from a Berg connector number
350 #ifdef WITH_STL
351  for(ConnectionMapCIterator i = fConnections.begin();
352   i!=fConnections.end();++i)
353    if (i->second->GetBergNum()==bergNum) return i->first;
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
364    
365  return AliMpIntPair::Invalid();
366 }
367
368 //______________________________________________________________________________
369 Int_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
382 //______________________________________________________________________________
383 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
384 {
385   // Return true if the pad indexed by <localIndices> has a connection
386   if (!localIndices.IsValid()) return false;
387
388 #ifdef WITH_STL
389   return fConnections.find(localIndices)!=fConnections.end();
390 #endif
391
392 #ifdef WITH_ROOT
393   Long_t value = fConnections.GetValue(GetIndex(localIndices));
394   return value!=0;
395 #endif
396 }
397
398 //______________________________________________________________________________
399 void 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 }