1 //____________________________________________________________________
5 // Check integrety of Hardware2Detector and Detector2Hardware
7 /** @defgroup HW_Test Hardware map test
10 //____________________________________________________________________
12 * Convert hardware address to board,altro,channel
14 * @param w Hardware address
17 * @param c out, Channel
20 HwAddr2Channel(UShort_t w, UShort_t& b, UShort_t& a, UShort_t& c)
27 //____________________________________________________________________
29 * Convert board,altro,channel to hardware address
35 * @return Hardware address
38 Channel2HwAddr(UShort_t b, UShort_t a, UShort_t c)
40 return (((b & 0x1F) << 7) | ((a & 0x7) << 4) | (c & 0xF));
42 //____________________________________________________________________
44 * Format a hardware addresss
54 * @return Formatted hardware address
57 Addr2Str(UInt_t l, UShort_t b, UShort_t a, UShort_t c, UShort_t tb)
60 s = Form("(0x%01X,0x%02X,0x%1X,0x%1X)-%4d", l, b, a, c, tb);
64 //____________________________________________________________________
66 * Format a hardware addresss
71 * @param w Hardware address
74 * @return Formatted hardware address
77 Addr2Str(UShort_t l, UShort_t w, UShort_t tb)
80 HwAddr2Channel(w, b, a, c);
81 return Addr2Str(l, b, a, c, tb);
84 //____________________________________________________________________
86 * Format a detector address
99 Det2Str(UShort_t d, Char_t r, UShort_t s, UShort_t t, UShort_t n)
102 str = Form("FMD%d%c[%2d,%3d]-%d", d, r, s, t, n);
106 //____________________________________________________________________
108 * Print full transformation
118 * @param w Hardware address
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
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)
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());
137 //____________________________________________________________________
139 * Print full transformation
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
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)
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());
171 //____________________________________________________________________
173 * Check transformation
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
188 * @return true on success
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)
197 what.Append(Form("\n\tDetector # differ %d != %d", d, od));
201 what.Append(Form("\n\tRing Id differ %c != %c", r, oR));
205 what.Append(Form("\n\tSector # differ %d != %d", s, os));
209 what.Append(Form("\n\tStrip # differ %d != %d", (t / 128) * 128, ot));
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());
221 //____________________________________________________________________
223 * Test hardware address map by converting from detector coordinates
224 * to hardware address and then back again.
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
233 TestHWMap(bool useHwAddr=false, bool few=false)
235 AliCDBManager* cdb = AliCDBManager::Instance();
236 cdb->SetDefaultStorage("local://${ALICE_ROOT}/OCDB");
239 AliFMDParameters* param = AliFMDParameters::Instance();
240 param->Init(true, AliFMDParameters::kAltroMap);
241 param->SetSampleRate(2);
242 AliLog::SetModuleDebugLevel("FMD", 51);
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;
259 ret = param->Detector2Hardware(d, r, s, t, n, l, w, tb);
261 ret = param->Detector2Hardware(d, r, s, t, n, l, b, a, c, tb);
262 w = Channel2HwAddr(b, a, c);
265 Warning("TestHWMap", "detector to hardware failed on %s",
266 Det2Str(d, r, s, t, n));
273 ret = param->Hardware2Detector(l,w,tb,od,oR,os,ot,on);
275 ret = param->Hardware2Detector(l,b,a,c,tb,od,oR,os,ot,on);
277 Warning("TestHWMap", "hardware to detector failed on %s",
282 if (ol != l || ow != w) {
287 if (!CheckTrans(d,r,s,t,n,od,oR,os,ot,on)) print = true;
290 PrintTrans(d,r,s,t,n,l,w,tb,od,oR,os,ot,on);
292 PrintTrans(d,r,s,t,n,l,b,a,c,tb,od,oR,os,ot,on);
294 } // Loop over samples
296 } // Loop over sectors
298 } // Loop over detectors
302 //____________________________________________________________________