Script to get # of dead channels from OCDB
[u/mrichter/AliRoot.git] / FMD / scripts / TestAltroMapping.C
CommitLineData
502fbe9a 1//____________________________________________________________________
2//
3// $id$
4//
5// Check integrety of Hardware2Detector and Detector2Hardware
6//
9b48326f 7/** @defgroup ALTRO_test ALTRO test
8 @ingroup FMD_script
9*/
f38b1653 10#ifndef __CINT__
11# include <TString.h>
12// # include <FMD/AliFMDParameters.h>
13# include <FMD/AliFMDAltroMapping.h>
14// # include <FMD/AliFMDUShortMap.h>
15// # include <FMD/AliFMDBoolMap.h>
b995fc28 16# include <AliLog.h>
f38b1653 17# include <TError.h>
18# include <iostream>
19#endif
5cf05dbb 20bool show_all=false;
21
502fbe9a 22//____________________________________________________________________
9b48326f 23/** @ingroup ALTRO_test
24 @param ddl
25 @param hwaddr
26 @return */
f38b1653 27const Char_t*
28Addr2Str(UInt_t ddl, UInt_t hwaddr, UShort_t timebin)
502fbe9a 29{
30 static TString s;
31 UInt_t board = (hwaddr >> 7) & 0x1F;
32 UInt_t chip = (hwaddr >> 4) & 0x7;
33 UInt_t chan = hwaddr & 0xF;
f38b1653 34 s = Form("(0x%05X,0x%02X,0x%1X,0x%1X,%04d)", ddl, board, chip, chan, timebin);
502fbe9a 35 return s.Data();
36}
37
38//____________________________________________________________________
9b48326f 39/** @ingroup ALTRO_test
40 @param det
41 @param ring
42 @param sec
43 @param str
44 @return */
f38b1653 45const Char_t*
46Det2Str(UShort_t det, Char_t ring, UShort_t sec, UShort_t str, UShort_t sam)
502fbe9a 47{
48 static TString s;
f38b1653 49 s = Form("FMD%d%c[%2d,%3d]-%d", det, ring, sec, str, sam);
502fbe9a 50 return s.Data();
51}
52
53//____________________________________________________________________
9b48326f 54/** @ingroup ALTRO_test
55 @param det
56 @param ring
57 @param sec
58 @param str
59 @param ddl
60 @param hwaddr
61 @param odet
62 @param oring
63 @param osec
64 @param ostr
65*/
502fbe9a 66void
f38b1653 67PrintTrans(UShort_t det, Char_t ring, UShort_t sec, Short_t str, UShort_t sam,
68 UInt_t ddl, UInt_t hwaddr, UShort_t timebin,
69 UShort_t odet, Char_t oring, UShort_t osec, Short_t ostr,
70 UShort_t osam)
502fbe9a 71{
72 static TString s1, s2, s3;
f38b1653 73 s1 = Det2Str(det, ring, sec, str, sam);
74 s2 = Addr2Str(ddl,hwaddr,timebin);
75 s3 = Det2Str(odet, oring, osec, ostr, osam);
502fbe9a 76 Info("TestHWMap","%s -> %s -> %s", s1.Data(), s2.Data(), s3.Data());
77}
78
79//____________________________________________________________________
9b48326f 80/** @ingroup ALTRO_test
81 @param det
82 @param ring
83 @param sec
84 @param str
85 @param odet
86 @param oring
87 @param osec
88 @param ostr
89*/
502fbe9a 90void
f38b1653 91CheckTrans(UShort_t det, Char_t ring, UShort_t sec, UShort_t str, UShort_t sam,
92 UInt_t ddl, UInt_t hwaddr, UShort_t timebin,
93 UShort_t odet, Char_t oring, UShort_t osec, UShort_t ostr,
94 UShort_t osam)
502fbe9a 95{
f38b1653 96 bool ok = true;
97 if (det != odet) {
a9579262 98 Warning("TestHWMap", "Detector # differ %d != %d", det, odet);
f38b1653 99 ok = false;
100 }
101 if (ring != oring) {
a9579262 102 Warning("TestHWMap", "Ring Id differ %c != %c", ring, oring);
f38b1653 103 ok = false;
104 }
105 if (sec != osec) {
502fbe9a 106 Warning("TestHWMap", "Sector # differ %d != %d", sec, osec);
f38b1653 107 ok = false;
108 }
109 if (str != ostr) {
110 ok = false;
502fbe9a 111 Warning("TestHWMap", "Strip # differ %d != %d", str, ostr);
f38b1653 112 }
113 if (sam != osam) {
114 ok = false;
115 Warning("TestHWMap", "Sample # differ %d != %d", sam, osam);
116 }
5cf05dbb 117
118 if (!show_all) {
119 if (!ok)
120 PrintTrans(det,ring,sec,str,sam,
121 ddl,hwaddr,timebin,
122 odet,oring,osec,ostr,osam);
123 }
502fbe9a 124}
125
126//____________________________________________________________________
9b48326f 127/** @ingroup ALTRO_test
128 */
502fbe9a 129void
5cf05dbb 130TestAltroMapping(bool sa=false, Int_t min=1, Int_t max=3)
502fbe9a 131{
5cf05dbb 132 show_all = sa;
b995fc28 133 // AliLog::SetModuleDebugLevel("FMD", 1);
a9579262 134 // if (min < 1 || min > 3) min = 1;
135 if (max < min) max = min;
f38b1653 136 // AliFMDParameters* param = AliFMDParameters::Instance();
502fbe9a 137 AliFMDAltroMapping m;
b995fc28 138 UShort_t presamp = 19;
f38b1653 139 UShort_t oversamp = 4;
140
a9579262 141 for (UShort_t det = min; det <= max; det++) {
502fbe9a 142 for (UShort_t rng = 0; rng < 2; rng++) {
143 Char_t ring = (rng == 0 ? 'I' : 'O');
144 Int_t nsec = (ring == 'I' ? 20 : 40);
145 Int_t nstr = (ring == 'I' ? 512 : 256);
146 for (UShort_t sec = 0; sec < nsec; sec++) {
f38b1653 147 for (Short_t str = 0; str < nstr; str ++ /*= 128*/) {
148 for(UShort_t sam = 0; sam < oversamp; sam++) {
b995fc28 149 UShort_t ddl, hwaddr;
f38b1653 150 UShort_t timebin;
151 if (!m.Detector2Hardware(det, ring, sec, str, sam,
152 presamp, oversamp,
153 ddl, hwaddr, timebin)) {
154 Warning("TestHWMap", "detector to hardware failed on %s",
155 Det2Str(det, ring, sec, str, sam));
156 continue;
157 }
158 UShort_t odet, osec, osam;
159 Short_t ostr;
160 Char_t oring;
161 if (!m.Hardware2Detector(ddl, hwaddr, timebin,
162 presamp, oversamp,
163 odet, oring, osec, ostr, osam)){
164 Warning("TestHWMap", "hardware to detector failed on %s",
165 Addr2Str(ddl, hwaddr, timebin));
166 continue;
167 }
5cf05dbb 168 if (show_all)
169 PrintTrans(det,ring,sec,str,sam,
170 ddl,hwaddr,timebin,
171 odet,oring,osec,ostr,osam);
f38b1653 172 CheckTrans(det,ring,sec,str,sam,
173 ddl,hwaddr,timebin,
174 odet,oring,osec,ostr,osam);
502fbe9a 175 }
502fbe9a 176 }// Loop over strips
177 } // Loop over sectors
178 } // Loop over rings
179 } // Loop over detectors
180}
181
182
183//____________________________________________________________________
184//
185// EOF
186//
187
188
189
190