6 #include <rtsSystems.h>
8 #include <daqFormats.h>
15 enum { ADCD = 0, TDCD, A2DD, SCAD };
17 const unsigned short gaindata[32] = {
27 const float decal[5] = {0., 0.38748E-1, 0.332922E-4, 0.20618E-6, -0.2188E-8};
28 const float calib[7] = {0., 2.5928E-2, -7.602961E-7, 4.637791E-11,
29 -2.165394E-13,6.048144E-20, -7.293422E-25};
30 const float calib2[7] = {0., 2.5929192E-2, -2.1316967E-7, 7.9018692E-10,
31 4.2527777E-13, 1.330447E-16, 2.0241446E-20};
32 const float calibration[16] = {
33 305.175E-6, 152.580E-6, 0, 76.290E-6,
34 0, 38.150E-6, 19.073E-6, 0,
35 9.536E-6, 4.786E-6, 0, 2.384E-6,
36 1.192E-6, 596.046E-9, 0, 298.023E-9
42 int tof_reader(
char *m,
struct tof_t *
tof, u_int driver)
58 tof->max_channels = 48+48+32+12 ;
61 memset(tof->ddl_words,0,
sizeof(tof->ddl_words)) ;
63 if(datap == NULL)
return 0 ;
65 if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER) {
72 len = (datap->det[TOF_ID].len) ;
73 if(len == 0)
return 0 ;
75 off = (datap->det[TOF_ID].off) ;
76 if(off == 0)
return 0 ;
79 off = qswap32(do_swap,off) ;
80 len = qswap32(do_swap,len) ;
85 LOG(DBG,
"TOF len %d, off %d",len,off,0,0,0);
87 tofp = (
struct TOFP *)((u_int *)m + off) ;
89 if(checkBank(tofp->bh.bank_type,CHAR_TOFP) < 0) {
93 if(tofp->bh.token == 0) {
94 LOG(DBG,
"token 0 - skipping ...",0,0,0,0,0);
99 if(tofp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) {
100 fmt_version = swap32(tofp->bh.format_ver) ;
103 fmt_version = tofp->bh.format_ver ;
107 if(fmt_version >= 0x50000) {
108 LOG(NOTE,
"TOF FY05+ data version 0x%X",fmt_version) ;
112 LOG(DBG,
"TOF pre-FY05 data version 0x%X",fmt_version) ;
118 memset(tof->adc,0,
sizeof(tof->adc));
119 memset(tof->tdc,0,
sizeof(tof->tdc));
120 memset(tof->a2d,0,
sizeof(tof->a2d));
121 memset(tof->sca,0,
sizeof(tof->sca));
127 for(bank_t=0; bank_t<max_contrib; bank_t++) {
128 if(tofp->type[bank_t].len <= 0)
continue;
131 tofadcd = (
struct TOFADCD *)((u_int *)tofp + l2h32(tofp->type[bank_t].off));
132 if(checkBank(tofadcd->bh.bank_type,CHAR_TOFADCD) < 0) {
136 blen = l2h32(tofadcd->bh.length) ;
139 LOG(DBG,
"TOFADCD has %d items",blen,0,0,0,0) ;
140 if(blen >
sizeof(tof->adc)/
sizeof(tof->adc[0])) {
141 LOG(ERR,
"TOFADCD too big [%d > %d] - skipping!",blen,
sizeof(tof->adc)/
sizeof(tof->adc[0]),0,0,0) ;
145 for(u_int i=0;i<blen;i++) {
146 tof->adc[i] = (( (l2h32(tofadcd->data[i])) & 0xffff0000)>>16);
147 if(tof->adc[i] > 1024) tof->adc[i] = 1024;
153 toftdcd = (
struct TOFTDCD *)((u_int *)tofp + l2h32(tofp->type[bank_t].off));
154 if(checkBank(toftdcd->bh.bank_type,CHAR_TOFTDCD) < 0) {
158 blen = l2h32(toftdcd->bh.length) ;
161 LOG(DBG,
"TOFTDCD has %d items",blen,0,0,0,0) ;
162 if(blen >
sizeof(tof->tdc)/
sizeof(tof->tdc[0])) {
163 LOG(ERR,
"TOFTDCD too big [%d > %d] - skipping!",blen,
sizeof(tof->tdc)/
sizeof(tof->tdc[0]),0,0,0) ;
167 for(u_int i=0;i<blen;i++) {
168 tof->tdc[i] = (( (l2h32(toftdcd->data[i])) & 0xffff0000)>>16);
169 if(tof->tdc[i] > 2048) tof->tdc[i] = 2048;
171 if(i==41)tof->tdc[i] = 0;
177 tofa2dd = (
struct TOFA2DD *)((u_int *)tofp + l2h32(tofp->type[bank_t].off));
178 if(checkBank(tofa2dd->bh.bank_type,CHAR_TOFA2DD) < 0) {
181 tof->a2d[0] = (int)((
int) (l2h32(tofa2dd->data[0])) >>16)*calibration[gaindata[0]]/.001-273.;
183 for(
int i=1;i<29;i++) {
185 if( (i!=13) && (i!= 14) && (i!=15)) {
186 V = short( (l2h32(tofa2dd->data[i])) >>16)*calibration[gaindata[i]]/.000001;
188 uncorT = calib2[0]+calib2[1]*V+calib2[2]*V*V+calib2[3]*V*V*V+calib2[4]*V*V*V*V+calib2[5]*V*V*V*V*V+calib2[6]*V*V*V*V*V*V;
190 uncorT = calib[0]+calib[1]*V+calib[2]*V*V+calib[3]*V*V*V+calib[4]*V*V*V*V+calib[5]*V*V*V*V*V+calib[6]*V*V*V*V*V*V;
192 tof->a2d[i] = uncorT+tof->a2d[0];
193 if(tof->a2d[i] < 0) tof->a2d[i] = 0;
194 if(tof->a2d[i] > 100) tof->a2d[i] = 100;
203 for(
int i=29;i<32;i++) {
204 tof->a2d[i] = ((short)((l2h32(tofa2dd->data[i]))>>16)-3280)/13.08;
205 if(tof->a2d[i] < 0) tof->a2d[i] = 0;
211 tofscad = (
struct TOFSCAD *)((u_int *)tofp + l2h32(tofp->type[bank_t].off));
212 if(checkBank(tofscad->bh.bank_type,CHAR_TOFSCAD) < 0) {
215 for(
int i=0;i<12;i++) {
216 tof->sca[i] = (( (l2h32(tofscad->data[i])) & 0xffffff00)>>8);
222 ddlr = (
struct TOFDDLR *)((u_int *)tofp + l2h32(tofp->type[bank_t].off)) ;
223 if(checkBank(ddlr->bh.bank_type,CHAR_TOFDDLR) < 0) {
227 LOG(DBG,
"TOFDDLR %d: length %d words",bank_t-3,l2h32(ddlr->bh.length)-10) ;
228 data_words = l2h32(ddlr->bh.length) - 10 ;
230 tof->ddl_words[bank_t-4] = data_words ;
232 u_int *data_word_p = (u_int *)ddlr->data ;
233 for(
int i=0;i<data_words;i++) {
235 tof->ddl[bank_t-4][i] = l2h32(data_word_p[i]) ;
237 LOG(DBG,
"DDLR %d: %3d: 0x%08X",bank_t-3,i,l2h32(data_word_p[i])) ;