]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpMotifType.cxx
Updated comments for Doxygen - corrected warnings
[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.10 2006/05/24 13:58:41 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 "AliMpMotifType.h"
27 #include "AliMpMotifTypePadIterator.h"
28 #include "AliMpConnection.h"
29
30 #include <Riostream.h>
31
32 #include <stdlib.h>
33
34 /// \cond CLASSIMP
35 ClassImp(AliMpMotifType)
36 /// \endcond
37
38 const Int_t AliMpMotifType::fgkPadNumForA = 65;
39
40 //______________________________________________________________________________
41 AliMpMotifType::AliMpMotifType(const TString &id) 
42   : TObject(),
43     fID(id),
44     fNofPadsX(0),   
45     fNofPadsY(0),
46     fVerboseLevel(0),
47 #ifdef WITH_STL
48     fConnections()
49 #endif
50 #ifdef WITH_ROOT
51     fConnections(true)
52 #endif
53 {
54   /// Standard constructor
55 }
56
57 //______________________________________________________________________________
58 AliMpMotifType::AliMpMotifType() 
59   : TObject(),
60     fID(""),
61     fNofPadsX(0),   
62     fNofPadsY(0),
63     fVerboseLevel(0),
64     fConnections()
65 {
66   /// Default constructor
67 }
68
69 //______________________________________________________________________________
70 AliMpMotifType::~AliMpMotifType() 
71 {
72 /// Destructor
73
74 #ifdef WITH_STL
75  for(ConnectionMapCIterator i = fConnections.begin();
76   i!=fConnections.end();++i)
77    delete i->second;
78
79   fConnections.erase(fConnections.begin(),fConnections.end());
80 #endif  
81 }
82
83 //______________________________________________________________________________
84 AliMpVPadIterator* AliMpMotifType::CreateIterator() const
85 {
86 /// Create new motif type iterator
87
88   return new AliMpMotifTypePadIterator(this);
89 }
90
91 //______________________________________________________________________________
92 void AliMpMotifType::SetNofPads(Int_t nofPadsX, Int_t nofPadsY)
93 {
94   /// Change the number of pads in this motif
95
96   fNofPadsX = nofPadsX;
97   fNofPadsY = nofPadsY;
98 }
99
100
101 //______________________________________________________________________________
102 Int_t AliMpMotifType::PadNum(const TString &padName) const
103 {
104   /// Transform a pad name into the equivalent pad number
105
106   if ( (padName[0]>='A') && (padName[0]<='Z') )
107     return fgkPadNumForA+padName[0]-'A';
108   else
109     return atoi(padName.Data());
110 }
111
112 //______________________________________________________________________________
113 TString AliMpMotifType::PadName(Int_t padNum) const
114 {
115   /// Transform a pad number into its equivalent pad name
116
117   if (padNum<fgkPadNumForA)
118     return Form("%d",padNum);
119   else
120     return char('A'+padNum-fgkPadNumForA);
121 }
122
123 //______________________________________________________________________________
124 void AliMpMotifType::AddConnection(const AliMpIntPair &localIndices, 
125                                AliMpConnection* connection)
126 {
127   /// Add the connection to the map
128   
129 #ifdef WITH_STL
130   fConnections[localIndices]=connection;
131 #endif
132
133 #ifdef WITH_ROOT
134   fConnections.Add(localIndices, connection);
135 #endif   
136
137   connection->SetOwner(this);
138 }  
139
140 //______________________________________________________________________________
141 AliMpConnection *AliMpMotifType::FindConnectionByPadNum(Int_t padNum) const
142 {
143   /// Retrieve the AliMpConnection pointer from its pad num
144   
145 #ifdef WITH_STL
146  for(ConnectionMapCIterator i = fConnections.begin();
147   i!=fConnections.end();++i)
148    if (i->second->GetPadNum()==padNum) return i->second;
149  return 0;
150 #endif
151
152 #ifdef WITH_ROOT
153   TExMapIter i = fConnections.GetIterator();
154   Long_t key, value;
155   while ( i.Next(key, value) ) {
156     AliMpConnection* connection = (AliMpConnection*)value;
157     if (connection->GetPadNum()==padNum) return connection;
158   }  
159  return 0;
160 #endif
161 }
162
163 //______________________________________________________________________________
164 AliMpConnection *AliMpMotifType::FindConnectionByLocalIndices(
165                                        const AliMpIntPair& localIndices) const
166 {
167   /// Retrieve the AliMpConnection pointer from its position (in pad unit)
168   
169   if (!localIndices.IsValid()) return 0;
170
171 #ifdef WITH_STL
172   ConnectionMapCIterator i = fConnections.find(localIndices);
173  if (i != fConnections.end())
174    return i->second;
175  else return 0;
176 #endif
177
178 #ifdef WITH_ROOT
179   return (AliMpConnection*)fConnections.GetValue(localIndices);
180 #endif
181 }
182
183 //______________________________________________________________________________
184 AliMpConnection *AliMpMotifType::FindConnectionByGassiNum(Int_t gassiNum) const
185 {
186   /// Return the connection for the given gassiplex number
187   
188 #ifdef WITH_STL
189  for(ConnectionMapCIterator i = fConnections.begin();
190   i!=fConnections.end();++i)
191    if (i->second->GetGassiNum()==gassiNum) return i->second;
192  return 0;
193 #endif
194
195 #ifdef WITH_ROOT
196   TExMapIter i = fConnections.GetIterator();
197   Long_t key, value;
198   while ( i.Next(key, value) ) {
199     AliMpConnection* connection = (AliMpConnection*)value;
200     if (connection->GetGassiNum()==gassiNum) return connection;
201   }  
202  return 0;
203 #endif
204 }
205
206 //______________________________________________________________________________
207 AliMpConnection *AliMpMotifType::FindConnectionByKaptonNum(Int_t kaptonNum) const
208 {
209   /// Give the connection related to the given kapton number
210   
211 #ifdef WITH_STL
212  for(ConnectionMapCIterator i = fConnections.begin();
213   i!=fConnections.end();++i)
214    if (i->second->GetKaptonNum()==kaptonNum) return i->second;
215  return 0;
216 #endif
217
218 #ifdef WITH_ROOT
219   TExMapIter i = fConnections.GetIterator();
220   Long_t key, value;
221   while ( i.Next(key, value) ) {
222     AliMpConnection* connection = (AliMpConnection*)value;
223     if (connection->GetKaptonNum()==kaptonNum) return connection;
224   }  
225  return 0;
226 #endif
227 }
228 //______________________________________________________________________________
229 AliMpConnection *AliMpMotifType::FindConnectionByBergNum(Int_t bergNum) const
230 {
231   /// Retrieve the connection from a Berg connector number
232   
233 #ifdef WITH_STL
234  for(ConnectionMapCIterator i = fConnections.begin();
235   i!=fConnections.end();++i)
236    if (i->second->GetBergNum()==bergNum) return i->second;
237  return 0;
238 #endif
239
240 #ifdef WITH_ROOT
241   TExMapIter i = fConnections.GetIterator();
242   Long_t key, value;
243   while ( i.Next(key, value) ) {
244     AliMpConnection* connection = (AliMpConnection*)value;
245     if (connection->GetBergNum()==bergNum) return connection;
246   }  
247   return 0;
248 #endif
249 }
250
251
252 //______________________________________________________________________________
253 AliMpIntPair AliMpMotifType::FindLocalIndicesByConnection(
254                                  const AliMpConnection* connection) const
255 {
256   /// Retrieve the pad position from the connection pointer.
257   /// Not to be used widely, since it use a search in the
258   /// connection list...
259
260 #ifdef WITH_STL
261  for(ConnectionMapCIterator i = fConnections.begin();
262   i!=fConnections.end();++i)
263    if (i->second==connection) return i->first;
264 #endif
265
266 #ifdef WITH_ROOT
267   TExMapIter i = fConnections.GetIterator();
268   Long_t key, value;
269   while ( i.Next(key, value) ) {
270     AliMpConnection* aConnection = (AliMpConnection*)value;
271     if (aConnection == connection) return AliMpExMap::GetPair(key);
272   }  
273 #endif
274
275   return AliMpIntPair::Invalid();
276 }
277
278 //______________________________________________________________________________
279 AliMpIntPair AliMpMotifType::FindLocalIndicesByPadNum(Int_t padNum) const
280 {
281   /// Retrieve the AliMpConnection pointer from its pad num
282   
283 #ifdef WITH_STL
284  for(ConnectionMapCIterator i = fConnections.begin();
285   i!=fConnections.end();++i)
286    if (i->second->GetPadNum()==padNum) return i->first;
287 #endif
288    
289 #ifdef WITH_ROOT
290   TExMapIter i = fConnections.GetIterator();
291   Long_t key, value;
292   while ( i.Next(key, value) ) {
293     AliMpConnection* connection = (AliMpConnection*)value;
294     if (connection->GetPadNum() == padNum) return AliMpExMap::GetPair(key);
295   }  
296 #endif
297  return AliMpIntPair::Invalid();
298 }
299
300 //______________________________________________________________________________
301 AliMpIntPair AliMpMotifType::FindLocalIndicesByGassiNum(Int_t gassiNum) const
302 {
303   /// Return the connection for the given gassiplex number
304   
305 #ifdef WITH_STL
306  for(ConnectionMapCIterator i = fConnections.begin();
307   i!=fConnections.end();++i)
308    if (i->second->GetGassiNum()==gassiNum) return i->first;
309 #endif
310    
311 #ifdef WITH_ROOT
312   TExMapIter i = fConnections.GetIterator();
313   Long_t key, value;
314   while ( i.Next(key, value) ) {
315     AliMpConnection* connection = (AliMpConnection*)value;
316     if (connection->GetGassiNum()==gassiNum) return AliMpExMap::GetPair(key);
317   }  
318 #endif
319    
320  return AliMpIntPair::Invalid();
321 }
322
323 //______________________________________________________________________________
324 AliMpIntPair AliMpMotifType::FindLocalIndicesByKaptonNum(Int_t kaptonNum) const
325 {
326   /// Give the connection related to the given kapton number
327   
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   TExMapIter i = fConnections.GetIterator();
336   Long_t key, value;
337   while ( i.Next(key, value) ) {
338     AliMpConnection* connection = (AliMpConnection*)value;
339     if (connection->GetKaptonNum()==kaptonNum) return AliMpExMap::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   
351 #ifdef WITH_STL
352  for(ConnectionMapCIterator i = fConnections.begin();
353   i!=fConnections.end();++i)
354    if (i->second->GetBergNum()==bergNum) return i->first;
355 #endif
356    
357 #ifdef WITH_ROOT
358   TExMapIter i = fConnections.GetIterator();
359   Long_t key, value;
360   while ( i.Next(key, value) ) {
361     AliMpConnection* connection = (AliMpConnection*)value;
362     if (connection->GetBergNum()==bergNum) return AliMpExMap::GetPair(key);
363   }  
364 #endif
365    
366  return AliMpIntPair::Invalid();
367 }
368
369 //______________________________________________________________________________
370 Int_t  AliMpMotifType::GetNofPads() const   
371 {
372 /// Return the number of pads
373
374 #ifdef WITH_STL
375   return fConnections.size();
376 #endif
377    
378 #ifdef WITH_ROOT
379   return fConnections.GetSize();
380 #endif
381 }
382
383 //______________________________________________________________________________
384 Bool_t AliMpMotifType::HasPad(const AliMpIntPair& localIndices) const
385 {
386   /// Return true if the pad indexed by \a localIndices has a connection
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 }