StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_sst.cxx
1 #include <sys/types.h>
2 #include <errno.h>
3 #include <assert.h>
4 #include <stdlib.h>
5 
6 #include <rtsLog.h>
7 #include <rtsSystems.h>
8 
9 
10 
11 #include <SFS/sfs_index.h>
12 #include <DAQ_READER/daqReader.h>
13 #include <DAQ_READER/daq_dta.h>
14 
15 
16 #include "daq_sst.h"
17 
18 
19 const char *daq_sst::help_string = "SST\n\
20 raw returns raw data\n" ;
21 
23 {
24 public:
26  daq_det_factory::det_factories[SST_ID] = this ;
27  }
28 
29  daq_det *create() {
30  return new daq_sst ;
31  }
32 } ;
33 
34 static daq_det_sst_factory sst_factory ;
35 
36 
37 daq_sst::daq_sst(daqReader *rts_caller)
38 {
39  rts_id = SST_ID ;
40  name = rts2name(rts_id) ;
41  sfs_name = "sst" ;
42  caller = rts_caller ;
43 
44  if(caller) caller->insert(this, rts_id) ;
45 
46  raw = new daq_dta ;
47  adc = new daq_dta ;
48  ped = new daq_dta ;
49 
50  LOG(DBG,"%s: constructor: caller %p",name,rts_caller) ;
51  return ;
52 }
53 
54 daq_sst::~daq_sst()
55 {
56  LOG(DBG,"%s: DEstructor",name) ;
57 
58  delete raw ;
59  delete adc ;
60  delete ped ;
61 
62  return ;
63 }
64 
65 
66 
67 daq_dta *daq_sst::get(const char *bank, int sec, int rdo, int pad, void *p1, void *p2)
68 {
69  Make() ;
70 
71  if(present == 0) return 0 ;
72 
73 
74  if(strcasecmp(bank,"raw")==0) {
75  return handle_raw(sec,rdo) ;
76  }
77  else if(strcasecmp(bank,"adc")==0) {
78  return handle_adc(sec,rdo) ;
79  }
80  else if(strcasecmp(bank,"pedrms")==0) {
81  return handle_ped(sec) ;
82  }
83 
84 
85  LOG(ERR,"%s: unknown bank type \"%s\"",name,bank) ;
86  return 0 ;
87 }
88 
89 
90 
91 
92 /*
93  mode = 0 just check
94  mode = 1 insert int adc strucutres
95  mode = 2 pedestal calculation
96 */
97 int daq_sst::raw_to_adc_utility(int s, int r, char *rdobuff, int words, daq_sst_ped_t *peds, int mode)
98 {
99  u_int *dta = (u_int *)rdobuff ;
100 
101  u_int *d32 = dta ;
102  u_int *d32_end = dta + words ;
103  u_int *d32_start = dta ;
104 
105  int adc_count = 0 ;
106 
107  events[r-1]++ ;
108 
109  int e = events[r-1] ;
110 
111  //sanity!
112  if(d32_end[-1] != 0xBBBBBBBB) {
113  LOG(ERR,"S%d-%d: %u: last word is 0x%08X, expect 0xBBBBBBBB -- data corrupt,skipping!",s,r,e,d32_end[-1]) ;
114  return -1 ;
115  }
116 
117 
118  //we'll assume SST has bugs in the header so we don't do any checks but search for the data
119  //immediatelly
120  int found = 0 ;
121  while(d32<d32_end) {
122  u_int d = *d32++ ;
123 
124  if(d == 0xDDDDDDDD) {
125  d32-- ; // move back ;
126  found = 1 ;
127  break ;
128  }
129  }
130 
131  if(!found) {
132  LOG(ERR,"S%d-%d: %u: can't find 0xDDDDDDDD -- data corrupt, skipping!",s,r,e) ;
133  return -1 ;
134  }
135 
136 
137  int fib = 0 ;
138  while(d32<d32_end) {
139  u_int d = *d32++ ;
140 
141  if(d != 0xDDDDDDDD) {
142  u_int *d_here = d32 - 1 ; // go back one
143  LOG(ERR,"S%d-%d: %u: fiber %d: can't find 0xDDDDDDDD at offset %d [0x%08X] -- data corrupt, skipping!",s,r,e,fib,
144  d_here-d32_start,*d_here) ;
145 
146  d_here -= 2 ;
147  for(int i=0;i<5;i++) {
148  LOG(ERR," %d: 0x%08X",d_here-d32_start,*d_here) ;
149  d_here++ ;
150  }
151  goto err_ret ;
152  }
153 
154  u_int fiber_id = d32[0] ;
155  // fiber id: 0xfffwwwwm
156  // fff-> flags 000 OK, 001 empty, 002 overflow
157  // wwww -> word length
158  // m -> mode: 0 raw, 1 ped-subtracted
159 
160  int words = fiber_id & 0x000FFFF0 ;
161  words >>= 4 ;
162 
163  LOG(NOTE,"S%d-%d: fiber %d: ID 0x%08X, words %d",
164  s,r,fib,fiber_id,words) ;
165 
166  int known_data_format = 1 ; // assume I know what I'm doing...
167 
168  if(fiber_id & 0xFFF00000) {
169  switch(fiber_id) {
170  case 0x001000A0 : // empty fiber in raw mode
171  case 0x001000A1 : // empty fiber in ZS mode
172  LOG(NOTE,"S%d-%d: %u: fiber %d: empty [0x%08X]",s,r,e,fib,fiber_id) ;
173  break ;
174  case 0x002100A1 : //overflow in pedestal subtracted mode *shrug*
175  LOG(NOTE,"S%d-%d: %u: fiber %d: overflow [0x%08X]",s,r,e,fib,fiber_id) ;
176  break ;
177  default:
178  LOG(WARN,"S%d-%d: %u: fiber %d: odd fiber_id [0x%08X]",s,r,e,fib,fiber_id) ;
179  known_data_format = 0 ;
180  break ;
181  }
182  }
183 
184  int pipe_mode = fiber_id & 0xF ;
185 
186  switch(pipe_mode) {
187  case 0 : //RAW
188  break ;
189  case 1 : //COMPRESSED (aka ZS) ;
190  known_data_format = 2 ;
191  break ;
192  case 3 : //Common Mode
193  known_data_format = 2 ;
194  break ;
195  case 2 : //ZS but with RAW
196  case 4 : //Commong Mode with RAW
197  default :
198  LOG(ERR,"S%d-%d: %u: fiber %d: unknown pipe mode 0x%X (0x%08X)",s,r,e,fib,pipe_mode,fiber_id) ;
199  goto err_ret ;
200  }
201 
202 /*
203 
204  if((fiber_id & 0xF) != 0) {
205  if((fiber_id & 0xF)==1) { // ZS data
206  LOG(NOTE,"S%d-%d: %u: fiber %d: ZS data 0x%08X...",s,r,e,fib,fiber_id) ;
207  known_data_format = 2 ;
208  //goto err_ret ;
209  }
210  else {
211  LOG(ERR,"S%d-%d: %u: fiber %d: unknown data mode 0x%08X",s,r,e,fib,fiber_id) ;
212  goto err_ret ;
213  }
214 
215 
216  }
217 */
218 
219 
220 
221  words -= 1 ; // for some reason...
222 
223  //first 9 words are some header
224  for(int i=0;i<12;i++) {
225  LOG(NOTE," %d: 0x%08X",i,d32[i]) ;
226  }
227 
228  d32 += 9 ; // skip this header
229  words -= 9 ; // adjust the remaining words...
230 
231  // If I don't know what the data format is, I'll skip decoding...
232  if(!known_data_format) {
233  LOG(WARN,"Unknown data format") ;
234  d32 += words ;
235  fib++ ;
236  if(fib==8) break ;
237  continue ;
238  }
239 
240  // want only non-ZS data in pedestal runs!
241  if((mode==2) && (known_data_format != 1)) {
242  LOG(ERR,"S%d-%d: %u: fiber %d: ZS data 0x%08X in pedestal runs is not allowed",s,r,e,fib,fiber_id) ;
243  d32 += words ;
244  fib++ ;
245  if(fib==8) break ;
246  continue ;
247  }
248 
249 
250  int strip = 0 ;
251  int hybrid = 0 ;
252 
253 
254  daq_sst_data_t *sst = 0 ;
255  daq_sst_data_t *sst_start ;
256 
257  switch(mode) {
258  case 1 : // used in the DAQ Reader
259  if(words) {
260  sst = (daq_sst_data_t *)adc->request(3*words) ;
261  }
262  break ;
263  case 2 : // used during real-time pedestal calc
264 
265  break ;
266  default :
267  mode = 0 ; // just check the data...
268  break ;
269  }
270 
271  sst_start = sst ;
272 
273  int no_error = 1 ;
274  switch(known_data_format) {
275  case 2 : // ZS data
276 
277  for(int i=0;i<words;i++) {
278  d = *d32++ ;
279 
280  int strip = (d & 0xFFC000)>>14 ;
281 
282  if(mode==1) {
283  sst->adc = d & 0x3FF ;
284  sst->hybrid = (d & 0x3C00)>>10 ;
285  sst->strip = strip ;
286  }
287  if(strip >= 768) {
288  LOG(ERR,"S%d-%d: fiber %d, bad strip %d",s,r,fib,strip) ;
289  no_error = 0 ;
290  }
291  sst++ ;
292 
293  }
294  //assume all OK with fiber
295  if(no_error) fiber_events[r-1][fib]++ ;
296 
297  break ;
298  case 1 :
299 
300 
301 
302  //here is the ADC
303  for(int i=0;i<words;i++) {
304  d = *d32++ ;
305  int adc_prime ;
306  int aadc ;
307 
308  if(strip >= 768) {
309  LOG(ERR,"S%d-%d: fiber %d, bad strip %d",s,r,fib,strip) ;
310  goto err_ret ;
311  }
312 
313  aadc = d & 0x3FF ;
314  switch(mode) {
315  case 1 :
316  sst->strip = strip ;
317  sst->hybrid = hybrid ;
318  sst->adc = aadc ;
319  break ;
320  case 2 :
321  adc_prime = (aadc+SST_PED_ADC_OFFSET)%1024 ;
322  if(adc_prime >= (1024-SST_OUTLIERBAND)) ;
323  else if(adc_prime <= (SST_OUTLIERBAND)) ;
324  else {
325  if(peds->cou[fib][hybrid][strip] < 0xFFF0) { // protect the 16bit counter
326  peds->ped[fib][hybrid][strip] += adc_prime ;
327  peds->rms[fib][hybrid][strip] += adc_prime * adc_prime ;
328  peds->cou[fib][hybrid][strip]++ ;
329  }
330  }
331  break ;
332  }
333  hybrid++ ;
334  sst++ ;
335 
336  if(hybrid==16) {
337  hybrid = 0 ;
338  strip++ ;
339  }
340 
342 
343  if(strip >= 768) {
344  LOG(ERR,"S%d-%d: fiber %d, bad strip %d",s,r,fib,strip) ;
345  goto err_ret ;
346  }
347 
348  aadc = (d & 0xFFC00) >> 10 ;
349  switch(mode) {
350  case 1 :
351  sst->strip = strip ;
352  sst->hybrid = hybrid ;
353  sst->adc = aadc ;
354  break ;
355  case 2 :
356  adc_prime = (aadc+SST_PED_ADC_OFFSET)%1024 ;
357  if(adc_prime >= (1024-SST_OUTLIERBAND)) ;
358  else if(adc_prime <= (SST_OUTLIERBAND)) ;
359  else {
360  if(peds->cou[fib][hybrid][strip] < 0xFFF0) { // protect the 16bit counter
361  peds->ped[fib][hybrid][strip] += adc_prime ;
362  peds->rms[fib][hybrid][strip] += adc_prime * adc_prime ;
363  peds->cou[fib][hybrid][strip]++ ;
364  }
365  }
366 
367 
368  break ;
369 
370  }
371  hybrid++ ;
372  sst++ ;
373 
374  if(hybrid==16) {
375  hybrid = 0 ;
376  strip++ ;
377  }
378 
379 
381 
382  if(strip >= 768) {
383  LOG(ERR,"S%d-%d: fiber %d, bad strip %d",s,r,fib,strip) ;
384  goto err_ret ;
385  }
386 
387  aadc = (d & 0x3FF00000) >> 20 ;
388  switch(mode) {
389  case 1 :
390  sst->strip = strip ;
391  sst->hybrid = hybrid ;
392  sst->adc = aadc ;
393  break ;
394  case 2 :
395  adc_prime = (aadc+SST_PED_ADC_OFFSET)%1024 ;
396 
397  if(adc_prime >= (1024-SST_OUTLIERBAND)) ;
398  else if(adc_prime <= (SST_OUTLIERBAND)) ;
399  else {
400  if(peds->cou[fib][hybrid][strip] < 0xFFF0) { // protect the 16bit counter
401  peds->ped[fib][hybrid][strip] += adc_prime ;
402  peds->rms[fib][hybrid][strip] += adc_prime * adc_prime ;
403  peds->cou[fib][hybrid][strip]++ ;
404  }
405  }
406  break ;
407  }
408  hybrid++ ;
409  sst++ ;
410 
411  if(hybrid==16) {
412  hybrid = 0 ;
413  strip++ ;
414  }
415 
416  }
417  //all OK with fiber; came to the end and counted all the necessary strips
418  if(words==(SST_STRIP_COU*SST_HYBRID_COU)/3) fiber_events[r-1][fib]++ ;
419 
420  break ;
421  }
422 
423  //end of adc
424  if((mode==1) && (sst-sst_start)) {
425  LOG(NOTE,"Got %d structs, requested %d",sst-sst_start,3*words) ;
426  adc->finalize(sst-sst_start,s,r,fib) ;
427  }
428 
429  adc_count += sst-sst_start ;
430 
431 
432  LOG(NOTE,"RDO %d, fiber %d: words %d",r,fib,words) ;
433 
434  fib++ ;
435  if(fib==8) break ;
436 
437 
438  }
439 
440  if(*d32 != 0xCCCCCCCC) {
441  LOG(ERR,"S%d-%d: %u: can't find 0xCCCCCCCC at offset %d [0x%08X] -- data corrupt, skipping!",s,r,e,d32-d32_start,*d32) ;
442  d32 -= 2 ;
443  while(d32 < d32_end) {
444  LOG(ERR," %d: 0x%08X",d32-d32_start,*d32) ;
445  d32++ ;
446  }
447  goto err_ret ;
448  }
449 
450 
451  LOG(NOTE,"%d %d -- returing %d",s,r,adc_count) ;
452 
453  return adc_count ; // objects
454 
455  err_ret:;
456 
457  return -1 ;
458 }
459 
460 
461 daq_dta *daq_sst::handle_adc(int sec, int rdo, char *rdobuff, int words)
462 {
463  int r_start, r_stop ;
464  int s_start, s_stop ;
465 
466 
467 
468  if(sec <= 0) {
469  s_start = 1 ;
470  s_stop = 2 ;
471  }
472  else {
473  s_start = s_stop = sec ;
474  }
475 
476  if(rdo<=0) {
477  r_start = 1 ;
478  r_stop = 3 ; // 1 sector has 3, 2nd has 2
479  }
480  else {
481  r_start = r_stop = rdo ;
482  }
483 
484 
485  adc->create(128,"sst_adc",rts_id,DAQ_DTA_STRUCT(daq_sst_data_t)) ;
486 
487  LOG(NOTE,"handle_adc: %d %d, %d %d",s_start,s_stop,r_start,r_stop) ;
488 
489  for(int s=s_start;s<=s_stop;s++) {
490 
491  for(int r=r_start;r<=r_stop;r++) {
492  u_int *dta ;
493 
494  if(rdobuff == 0) {
495  daq_dta *raw_d = handle_raw(s,r) ;
496  if(raw_d == 0) continue ;
497  if(raw_d->iterate() == 0) continue ;
498 
499  dta = (u_int *) raw_d->Void ;
500  words = raw_d->ncontent/4 ;
501 
502  //for ERRORs printounts
503  daq_trg_word trg[120] ;
504  get_l2((char *)dta,words,trg,r) ;
505 
506  }
507  else {
508  dta = (u_int *) rdobuff ;
509 
510 // LOG(WARN,"Running from buffer: words %d, RDO %d",words,r) ;
511  } ;
512 
513 
514  raw_to_adc_utility(s,r,(char *)dta,words,0,1) ;
515 
516 
517  } // end of loop over RDOs [1..3]
518 
519  } // end of loop over Sectors [1..2]
520 
521  adc->rewind() ;
522 
523  return adc ;
524 
525 }
526 
527 
528 daq_dta *daq_sst::handle_raw(int sec, int rdo)
529 {
530  char *st ;
531  int r_start, r_stop ;
532  int s_start, s_stop ;
533  int bytes ;
534  char str[256] ;
535  char *full_name ;
536 
537 
538  assert(caller) ; // sanity...
539 
540  if(!present) {
541  return 0 ;
542  }
543  else {
544  LOG(DBG,"%s: present %d",name,present) ;
545  }
546 
547 
548 
549  if(sec <= 0) {
550  s_start = 1 ;
551  s_stop = 2 ;
552  }
553  else {
554  s_start = s_stop = sec ;
555  }
556 
557  if(rdo<=0) {
558  r_start = 1 ;
559  r_stop = 3 ; // 1 sector has 3, 2nd has 2
560  }
561  else {
562  r_start = r_stop = rdo ;
563  }
564 
565 
566  raw->create(8*1024,"sst_raw",rts_id,DAQ_DTA_STRUCT(char)) ;
567 
568 
569  for(int s=s_start;s<=s_stop;s++) {
570 
571  for(int r=r_start;r<=r_stop;r++) {
572  sprintf(str,"%s/sec%02d/rb%02d/raw",sfs_name, s, r) ;
573  full_name = caller->get_sfs_name(str) ;
574 
575  if(!full_name) continue ;
576  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
577 
578 
579  st = (char *) raw->request(bytes) ;
580 
581  int ret = caller->sfs->read(str, st, bytes) ;
582  if(ret != bytes) {
583  LOG(ERR,"ret is %d") ;
584  }
585 
586 
587  raw->finalize(bytes,s,r,0) ; ;
588 
589  } // end of loop over RDOs [1..3]
590 
591  } // end of loop over Sectors [1..2]
592 
593  raw->rewind() ;
594 
595  return raw ;
596 
597 }
598 
599 
600 int daq_sst::get_l2(char *buff, int words, struct daq_trg_word *trg, int rdo)
601 {
602  // will look the same as PXL!
603  int t_cou = 0 ;
604  u_int *d32 = (u_int *)buff ;
605  u_int err = 0 ;
606  int last_ix = words - 1 ;
607  int token, daq_cmd, trg_cmd ;
608  u_int token_word ;
609 
610  // quick sanity checks...
611  // errors in the lower 16 bits are critical in the sense that
612  // I'm unsure about the token and events coherency.
613  // Critical errors issue ERROR
614  // Others issue WARN
615 
616  if(d32[0] != 0xAAAAAAAA) err |= 0x10000 ; // header error
617  if(d32[last_ix] != 0xBBBBBBBB) err |= 0x1 ; // trailer error
618 
619  token_word = d32[1] ; // default
620 
621  //let's enumerate observed errors depending on location of 0xDDDDDDDD
622  int got_dd = -1 ;
623  for(int i=0;i<12;i++) { // search, oh, 12 words only...
624  if(d32[i] == 0xDDDDDDDD) {
625  got_dd = i ;
626  break ;
627  }
628  }
629 
630  switch(got_dd) {
631  case 7 : //no 0xAAAAAAAA at all
632  token_word = d32[0] ;
633  err |= 0x20000 ;
634  break ;
635  case 8 : // this is normal
636  break ;
637  case 9 : // double 0xAAAAAAAA
638  token_word = d32[2] ;
639  err |= 0x40000 ;
640  break ;
641  case -1 : // none found
642  if(token_word == 0x22200000) ; // trigger only event?
643  else {
644  err |= 0x2 ; // unknown case so far...
645  }
646  break ;
647  default :
648  err |= 0x2 ; // unknown case so far...
649  break ;
650  }
651 
652 
653  // special TCD-only event check; is this implemented by SST?? Should be!
654  if(token_word == 0x22200000) {
655  LOG(WARN,"RDO %d: trigger-only event...",rdo) ;
656  token = 4097 ;
657  daq_cmd = 0 ;
658  trg_cmd = 4 ;
659  }
660  else {
661  //check for USB trigger
662  if(token_word & 0xFFF00000) { // USB trigger?? Can't be
663  err |= 4 ;
664  }
665 
666  token = token_word & 0xFFF ;
667  daq_cmd = (token_word & 0xF000) >> 12 ;
668  trg_cmd = (token_word & 0xF0000) >> 16 ;
669  }
670 
671  // more sanity
672  if(token == 0) {
673  token = 4097 ; // override with dummy token!
674  err |= 4 ;
675  }
676 
677 
678  if(trg_cmd != 4) err |= 4 ;
679 
680  trg[t_cou].t = token ;
681  trg[t_cou].daq = daq_cmd ;
682  trg[t_cou].trg = trg_cmd ;
683  trg[t_cou].rhic = d32[7] ;
684  trg[t_cou].rhic_delta = 0 ;
685  t_cou++ ;
686 
687 #if 0
688  // get other trigger commands...
689  int last_p = last_ix - 1 ; // at CRC
690 
691  //u_int crc = d32[last_p] ;
692 
693 
694  last_p-- ; // at end of TCD info
695  int first_trg = -1 ;
696 
697  for(int i=last_p;i>=0;i--) {
698  if(d32[i] == 0xCCCCCCCC) { // trigger commands header...
699  first_trg = i + 1 ;
700  break ;
701  }
702  }
703 
704  if(first_trg > 0) { // found other trigger commands...
705  for(int i=first_trg;i<=last_p;i++) {
706  trg[t_cou].t = d32[i] & 0xFFF ;
707  trg[t_cou].daq = (d32[i] & 0xF000) >> 12 ;
708  trg[t_cou].trg = (d32[i] & 0xF0000) >> 16 ;
709  trg[t_cou].rhic = trg[0].rhic + 1 ; // mock it up...
710  trg[t_cou].rhic_delta = 0 ;
711 
712  switch(trg[t_cou].trg) {
713  case 0xF :
714  case 0xE :
715  case 0xD :
716  break ;
717  default :
718  continue ;
719  }
720 
721  t_cou++ ;
722 
723  if(t_cou >= 120) { // put a sanity limiter...
724  err |= 8 ;
725  break ;
726  }
727  }
728  }
729 #endif
730 
731  //err = t_cou ;
732  if(err & 0xFFFF) {
733  LOG(ERR,"RDO %d: error 0x%X, t_cou %d",rdo,err,t_cou) ;
734 
735  for(int i=0;i<16;i++) {
736  LOG(ERR," RDO %d: %2d/%2d: 0x%08X",rdo,i,words,d32[i]) ;
737  }
738 
739  int s = last_ix - 10 ;
740  if(s < 0) s = 0 ;
741 
742  for(int i=s;i<=last_ix;i++) {
743  LOG(ERR," RDO %d: %2d/%2d: 0x%08X",rdo,i,words,d32[i]) ;
744  }
745 
746  //HACK
747  trg[0].t = 4097 ; // kill this guy...
748  if(t_cou) t_cou = 1 ; // disregard anything else as well...
749  }
750  else if(err & 0xFFFF0000) { //non critical, warnings
751 
752  LOG(WARN,"RDO %d: error 0x%X, t_cou %d",rdo,err,t_cou) ;
753 
754  for(int i=0;i<16;i++) {
755  LOG(WARN," RDO %d: %2d/%2d: 0x%08X",rdo,i,words,d32[i]) ;
756  }
757 
758  int s = last_ix - 10 ;
759  if(s < 0) s = 0 ;
760 
761  for(int i=s;i<=last_ix;i++) {
762  LOG(WARN," RDO %d: %2d/%2d: 0x%08X",rdo,i,words,d32[i]) ;
763  }
764 
765 
766 
767  }
768 
769  return t_cou ;
770 }
771 
772 daq_dta *daq_sst::handle_ped(int sec)
773 {
774 
775 
776 
777 
778  char str[128] ;
779  char *full_name ;
780  int bytes ;
781  u_short *d, *d_in ;
782  int s_start, s_stop ;
783 
784 
785  LOG(NOTE,"handle_ped(%d)",sec) ;
786 
787  if(sec<=0) {
788  s_start = 1 ;
789  s_stop = 2 ;
790  }
791  else {
792  s_start = s_stop = sec ;
793  }
794 
795  ped->create(8,"sst_pedrms",rts_id,DAQ_DTA_STRUCT(daq_sst_pedrms_t)) ;
796 
797  for(sec=s_start;sec<=s_stop;sec++) {
798 
799  sprintf(str,"%s/sec%02d/pedrms",sfs_name, sec) ;
800 
801  LOG(NOTE,"Trying %s",str) ;
802 
803  full_name = caller->get_sfs_name(str) ;
804 
805  if(full_name) {
806  LOG(NOTE,"full_name %s",full_name) ;
807  }
808 
809  if(!full_name) continue ;
810  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
811 
812  LOG(NOTE,"bytes %d",bytes) ;
813 
814  d = (u_short *) malloc(bytes) ;
815  d_in = d ;
816 
817  int ret = caller->sfs->read(str, (char *)d, bytes) ;
818  if(ret != bytes) {
819  LOG(ERR,"ret is %d") ;
820  }
821 
822  if(d[0] != 0xBEEF) {
823  LOG(ERR,"Bad pedestal version") ;
824  }
825 
826  if(d[1] != 1 ) {
827  LOG(ERR,"Bad pedestal version") ;
828  }
829 
830  int rdo_cou = d[2] ;
831  int fib_cou = d[3] ;
832  int hy_cou = d[4] ;
833  int strip_cou = d[5] ;
834 
835 
836  d += 6 ; // skip header
837 
838 // int max_ix = (bytes/2) ;
839 
840  daq_sst_pedrms_t *f_ped = 0 ;
841 
842  for(int r=0;r<rdo_cou;r++) {
843  int rdo1 = *d++ ;
844 
845  for(int f=0;f<fib_cou;f++) {
846 
847  f_ped = (daq_sst_pedrms_t *) ped->request(1) ;
848 
849  for(int h=0;h<hy_cou;h++) {
850  for(int s=0;s<strip_cou;s++) {
851  short ped = (short)*d++ ;
852  short rms = (short)*d++ ;
853 
854  f_ped->ped[h][s] = ped ;
855  f_ped->rms[h][s] = rms ;
856 
857  }
858  }
859 
860  ped->finalize(1,sec,rdo1,f) ;
861  }
862 
863  }
864 
865  free(d_in) ;
866 
867  }
868 
869  ped->rewind() ;
870 
871 
872  return ped ;
873 }
874 
875