]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/TestHWMap.C
Fixed a few coding problems
[u/mrichter/AliRoot.git] / FMD / scripts / TestHWMap.C
1 //____________________________________________________________________
2 //
3 // $id$
4 //
5 // Check integrety of Hardware2Detector and Detector2Hardware
6 //
7 /** @defgroup HW_Test Hardware map test
8     @ingroup FMD_script 
9 */
10 //____________________________________________________________________
11 /** 
12  * Convert hardware address to board,altro,channel
13  * 
14  * @param w Hardware address
15  * @param b out, Board
16  * @param a out, Altro 
17  * @param c out, Channel
18  */
19 void
20 HwAddr2Channel(UShort_t w, UShort_t& b, UShort_t& a, UShort_t& c)
21 {
22   b = (w >> 7) & 0x1F;
23   a = (w >> 4) & 0x7;
24   c = w & 0xF;
25 }
26
27 //____________________________________________________________________
28 /** 
29  * Convert board,altro,channel to hardware address
30  * 
31  * @param b Board
32  * @param a Altro
33  * @param c Channel
34  * 
35  * @return Hardware address
36  */
37 UShort_t
38 Channel2HwAddr(UShort_t b, UShort_t a, UShort_t c)
39 {
40   return (((b & 0x1F) << 7) | ((a & 0x7) << 4) | (c & 0xF));
41 }
42 //____________________________________________________________________
43 /** 
44  * Format a hardware addresss
45  * 
46  * @ingroup HW_test
47  * 
48  * @param l  DDL ID
49  * @param b  Board
50  * @param a  Altro
51  * @param c  Channel
52  * @param tb Timebin
53  * 
54  * @return Formatted hardware address
55  */
56 Char_t* 
57 Addr2Str(UInt_t l, UShort_t b, UShort_t a, UShort_t c, UShort_t tb)
58 {
59   static TString s;
60   s = Form("(0x%01X,0x%02X,0x%1X,0x%1X)-%4d", l, b, a, c, tb);
61   return s.Data();
62 }
63
64 //____________________________________________________________________
65 /** 
66  * Format a hardware addresss
67  * 
68  * @ingroup HW_test
69  * 
70  * @param l  DDL ID
71  * @param w  Hardware address
72  * @param tb Timebin
73  * 
74  * @return Formatted hardware address
75  */
76 Char_t* 
77 Addr2Str(UShort_t l, UShort_t w, UShort_t tb)
78 {
79   UShort_t b, a, c;
80   HwAddr2Channel(w, b, a, c);
81   return Addr2Str(l, b, a, c, tb);
82 }
83
84 //____________________________________________________________________
85 /** 
86  * Format a detector address 
87  * 
88  * @ingroup HW_test
89  * 
90  * @param d Detector
91  * @param r Ring 
92  * @param s Sector  
93  * @param t Strip
94  * @param n Sample
95  * 
96  * @return 
97  */
98 Char_t* 
99 Det2Str(UShort_t d, Char_t r, UShort_t s, UShort_t t, UShort_t n)
100 {
101   static TString str;
102   str = Form("FMD%d%c[%2d,%3d]-%d", d, r, s, t, n);
103   return str.Data();
104 }
105
106 //____________________________________________________________________
107 /** 
108  * Print full transformation
109  * 
110  * @ingroup HW_test
111  *
112  * @param d    Detector
113  * @param r    Ring
114  * @param s    Sector 
115  * @param t    Strip
116  * @param n    Sample
117  * @param l    DDL ID
118  * @param w    Hardware address
119  * @param tb   Timebin
120  * @param od   Detector output
121  * @param oR   Ring output    
122  * @param os   Sector output  
123  * @param ot   Strip output   
124  * @param on   Sample output  
125  */
126 void 
127 PrintTrans(UShort_t d,   Char_t r,   UShort_t s,  UShort_t t,  UShort_t n, 
128            UShort_t l,   UShort_t w, UShort_t tb,
129            UShort_t od,  Char_t oR,  UShort_t os, Short_t  ot, UShort_t on)
130 {
131   static TString s1, s2, s3;
132   s1 = Det2Str(d, r, s, t, n);
133   s2 = Addr2Str(l,w,tb);
134   s3 = Det2Str(od, oR, os, ot, on);
135   Info("TestHWMap","%s -> %s -> %s", s1.Data(), s2.Data(), s3.Data());
136 }
137 //____________________________________________________________________
138 /** 
139  * Print full transformation
140  * 
141  * @ingroup HW_test
142  *
143  * @param d    Detector
144  * @param r    Ring
145  * @param s    Sector 
146  * @param t    Strip
147  * @param n    Sample
148  * @param l    DDL ID
149  * @param b    Board
150  * @param a    ALTRO
151  * @param c    Channel
152  * @param tb   Timebin
153  * @param od   Detector output
154  * @param oR   Ring output    
155  * @param os   Sector output  
156  * @param ot   Strip output   
157  * @param on   Sample output  
158  */
159 void 
160 PrintTrans(UShort_t d,   Char_t   r,  UShort_t s,  UShort_t t,  UShort_t n, 
161            UShort_t l,   UShort_t b,  UShort_t a,  UShort_t c,  UShort_t tb,
162            UShort_t od,  Char_t   oR, UShort_t os, Short_t  ot, UShort_t on)
163 {
164   static TString s1, s2, s3;
165   s1 = Det2Str(d, r, s, t, n);
166   s2 = Addr2Str(l,b,a,c,tb);
167   s3 = Det2Str(od, oR, os, ot, on);
168   Info("TestHWMap","%s -> %s -> %s", s1.Data(), s2.Data(), s3.Data());
169 }
170
171 //____________________________________________________________________
172 /** 
173  * Check transformation
174  * 
175  * @ingroup HW_test
176  *
177  * @param d    Detector
178  * @param r    Ring
179  * @param s    Sector 
180  * @param t    Strip
181  * @param n    Sample
182  * @param od   Detector output
183  * @param oR   Ring output    
184  * @param os   Sector output  
185  * @param ot   Strip output   
186  * @param on   Sample output  
187  * 
188  * @return true on success 
189  */
190 Bool_t
191 CheckTrans(UShort_t d,  Char_t r,  UShort_t s,  UShort_t t,  UShort_t n, 
192            UShort_t od, Char_t oR, UShort_t os, Short_t  ot, UShort_t on)
193 {
194   bool ok = true;
195   TString what;
196   if (d != od) {
197     what.Append(Form("\n\tDetector # differ %d != %d", d, od));
198     ok = false;
199   }
200   if (r != oR) {
201     what.Append(Form("\n\tRing Id differ %c != %c", r, oR));  
202     ok = false; 
203   }
204   if (s != os) {
205     what.Append(Form("\n\tSector # differ %d != %d", s, os));
206     ok = false;
207   }
208   if (t != ot) {
209     what.Append(Form("\n\tStrip # differ %d != %d", (t / 128) * 128, ot));
210     ok = false;
211   }
212   if (!ok) {
213     static TString s1, s3;
214     s1 = Det2Str(d, r, s, t);
215     s3 = Det2Str(od, oR, os, ot);
216     Warning("TestHWMap", "%s -> %s %s", s1.Data(), s3.Data(), what.Data());
217   }
218   return ok;
219 }
220
221 //____________________________________________________________________
222 /** 
223  * Test hardware address map by converting from detector coordinates
224  * to hardware address and then back again.
225  * 
226  * @ingroup HW_test
227  *
228  * @param useHwAddr Whether to use 12 bit hardware address, or
229  *                  board,altro,channel 
230  * @param few       Only do a few - 1 detector, one sector 
231  */
232 void
233 TestHWMap(bool useHwAddr=false, bool few=false)
234 {
235   AliCDBManager* cdb = AliCDBManager::Instance();
236   cdb->SetDefaultStorage("local://${ALICE_ROOT}/OCDB");
237   cdb->SetRun(0);
238
239   AliFMDParameters* param = AliFMDParameters::Instance();
240   param->Init(true, AliFMDParameters::kAltroMap);
241   param->SetSampleRate(2);
242   AliLog::SetModuleDebugLevel("FMD", 51);
243
244   UInt_t ol = 0, ow = 0xFFFFFFFF;
245   UShort_t nd = (few ? 1 : 3); 
246   for (UShort_t d = 1; d <= nd; d++) {
247     UShort_t nr = (d == 1 ? 1 : 2);
248     for (UShort_t q = 0; q < nr; q++) {
249       Char_t r  = (q ==   0 ? 'I' : 'O');
250       Int_t  ns = (few ? 1 : (r == 'I' ?  20 :  40));
251       Int_t  nt =            (r == 'I' ? 512 : 256);
252       for (UShort_t s = 0; s < ns; s++) {
253         for (UShort_t t = 0; t < nt; t++) {
254           Int_t nsam = param->GetSampleRate(d, r, s, t);
255           for (UShort_t n=0; n < nsam; n++) {
256             UShort_t l, b, a, c, w, tb;
257             bool ret = true;
258             if (useHwAddr) 
259               ret = param->Detector2Hardware(d, r, s, t, n, l, w, tb);
260             else {
261               ret = param->Detector2Hardware(d, r, s, t, n, l, b, a, c, tb);
262               w   = Channel2HwAddr(b, a, c);
263             }
264             if (!ret) {
265               Warning("TestHWMap", "detector to hardware failed on %s", 
266                       Det2Str(d, r, s, t, n));
267               continue;
268             }
269             UShort_t od, os, on;
270             Short_t  ot;
271             Char_t   oR;
272             if (useHwAddr) 
273               ret = param->Hardware2Detector(l,w,tb,od,oR,os,ot,on);
274             else 
275               ret = param->Hardware2Detector(l,b,a,c,tb,od,oR,os,ot,on);
276             if (!ret) {
277               Warning("TestHWMap", "hardware to detector failed on %s", 
278                       Addr2Str(l, w, tb));
279               continue;
280             }
281             bool print = few;
282             if (ol != l || ow != w) {
283               print = true;
284               ol    = l;
285               ow    = w;
286             }
287             if (!CheckTrans(d,r,s,t,n,od,oR,os,ot,on)) print = true;
288             if (print) {
289               if (useHwAddr)  
290                 PrintTrans(d,r,s,t,n,l,w,tb,od,oR,os,ot,on);
291               else
292                 PrintTrans(d,r,s,t,n,l,b,a,c,tb,od,oR,os,ot,on);
293             }
294           } // Loop over samples
295         }// Loop over strips
296       } // Loop over sectors
297     } // Loop over rings
298   } // Loop over detectors
299 }
300
301   
302 //____________________________________________________________________
303 //
304 // EOF
305 //
306     
307         
308
309