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