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