12 #include <rtsSystems.h>
14 #include <DAQ_READER/daq_dta.h>
55 void sstPed::init(
int active_rbs)
59 rb_mask = active_rbs ;
65 if(sst_rdr == 0) sst_rdr =
new daq_sst(0) ;
67 memset(ped_store,0,sizeof_ped) ;
69 memset(sst_rdr->events,0,
sizeof(sst_rdr->events)) ;
70 memset(sst_rdr->fiber_events,0,
sizeof(sst_rdr->fiber_events)) ;
72 LOG(TERR,
"Pedestals zapped: rb_mask 0x%02X",rb_mask) ;
82 void sstPed::accum(
char *evbuff,
int bytes,
int rdo1)
84 LOG(NOTE,
"entering %d",rdo1) ;
88 LOG(NOTE,
"accum %d",rdo1) ;
92 sst_rdr->raw_to_adc_utility(sector,rdo1,evbuff,bytes/4,p,2) ;
94 LOG(NOTE,
"accum done %d",rdo1) ;
104 const u_int MIN_EVENTS = 90 ;
107 LOG(NOTE,
"Calculating pedestals") ;
109 u_int bad[SST_RDO_COU][SST_FIBER_COU] ;
111 memset(bad,0,
sizeof(bad)) ;
113 for(
int r=0;r<SST_RDO_COU;r++) {
114 if(rb_mask & (1<<r)) ;
119 for(
int fib=0;fib<SST_FIBER_COU;fib++) {
120 for(
int hy=0;hy<SST_HYBRID_COU;hy++) {
121 for(
int strip=0;strip<SST_STRIP_COU;strip++) {
124 if(ped->cou[fib][hy][strip] == 0) {
125 ped->ped[fib][hy][strip] = 0 ;
126 ped->rms[fib][hy][strip] = -1.0 ;
132 pp = (double) ped->ped[fib][hy][strip] / (
double) ped->cou[fib][hy][strip] ;
134 rr = (double) ped->rms[fib][hy][strip] / (
double) ped->cou[fib][hy][strip] ;
137 if(rr < (pp*pp)) rr = 0.0 ;
138 else rr = sqrt(rr - pp*pp) ;
140 ped->ped[fib][hy][strip] = pp ;
141 ped->rms[fib][hy][strip] = rr ;
148 if(ped->cou[fib][hy][strip] < MIN_EVENTS) {
158 for(
int r=0;r<SST_RDO_COU;r++) {
159 if(rb_mask & (1<<r)) ;
162 for(
int fib=0;fib<SST_FIBER_COU;fib++) {
164 LOG(WARN,
"RDO %d, FIBER %d: has %d strips with insufficent counts!",r+1,fib,bad[r][fib]) ;
166 if(sst_rdr->fiber_events[r][fib] < MIN_EVENTS) {
167 LOG(ERR,
"RDO %d, FIBER %d has only %d events (< %d)",r+1,fib,sst_rdr->fiber_events[r][fib],MIN_EVENTS) ;
173 LOG(TERR,
"Pedestals calculated.") ;
179 int sstPed::to_evb(
char *buff)
182 u_short *dta = (u_short *) buff ;
187 LOG(ERR,
"ped::to_evb peds are bad: valid %d",valid) ;
193 for(r=0;r<SST_RDO_COU;r++) {
194 if(rb_mask & (1<<r)) ;
201 LOG(TERR,
"Preparing pedestals for later EVB: mask 0x%X, rdos %d",rb_mask,rdo_cou) ;
206 *dta++ = SST_FIBER_COU ;
207 *dta++ = SST_HYBRID_COU ;
208 *dta++ = SST_STRIP_COU ;
211 for(r=0;r<SST_RDO_COU;r++) {
212 if(rb_mask & (1<<r)) ;
220 for(f=0;f<SST_FIBER_COU;f++) {
221 for(h=0;h<SST_HYBRID_COU;h++) {
223 for(s=0;s<SST_STRIP_COU;s++) {
227 pp = (short)(ped->ped[f][h][s] + 0.5) ;
230 pp = (u_short)(ped->rms[f][h][s]*16.0 + 0.5) ;
237 while(((
char *)dta-buff)%4) dta++ ;
239 LOG(TERR,
"Pedestals prepared for later EVB, %d bytes",(
char *)dta-buff) ;
241 return ((
char *)dta-buff) ;
245 int sstPed::to_cache(
char *fname, u_int run)
252 LOG(CAUTION,
"Pedestals are not valid -- not caching!") ;
255 time_t tim = time(0) ;
257 for(
int r=0;r<SST_RDO_COU;r++) {
258 if(rb_mask & (1<<r)) ;
263 sprintf(f_fname,
"%s/sst_pedestals_s%d_r%d.txt",fname,sector,r+1) ;
266 sprintf(f_fname,
"/RTScache/sst_pedestals_s%d_r%d.txt",sector,r+1) ;
270 f = fopen(
"/tmp/ssd_peds",
"w") ;
272 LOG(U_TONKO,
"ped::to_cache can't open output file \"%s\" [%s]",
"/tmp/ssd_peds",strerror(errno)) ;
278 fprintf(f,
"# Run %08u\n",run) ;
279 fprintf(f,
"# Date %s",ctime(&tim)) ;
280 fprintf(f,
"# Sector %d\n",sector) ;
281 fprintf(f,
"# RDO %d\n",r+1) ;
287 for(
int fib=0;fib<SST_FIBER_COU;fib++) {
288 for(
int hy=0;hy<SST_HYBRID_COU;hy++) {
289 for(
int strip=0;strip<SST_STRIP_COU;strip++) {
291 fprintf(f,
"%d %2d %3d %.1f %.1f\n",fib,hy,strip,
292 peds->ped[fib][hy][strip],
293 peds->rms[fib][hy][strip]) ;
304 sprintf(sys,
"/bin/cp /tmp/ssd_peds %s",f_fname) ;
307 LOG(TERR,
"Pedestals written to cache \"%s\" [ret %d]",f_fname,ret) ;
310 LOG(U_TONKO,
"Pedestals not written to cache \"%s\" [ret %d]",f_fname,ret) ;
316 sprintf(sys,
"/bin/cp /tmp/ssd_peds /net/ssd-upgrade/data/PEDESTALS/sst_pedestals_%08u_s%d_r%d.txt >/dev/null 2>/dev/null",run,sector,r+1) ;
319 LOG(TERR,
"Executed [%s], ret %d",sys,ret) ;
322 LOG(U_TONKO,
"Not executed [%s], ret %d",sys,ret) ;