8 #include <rtsSystems.h>
9 #include <daqFormats.h>
11 #include <SFS/sfs_index.h>
13 #include <DAQ_READER/daqReader.h>
14 #include <DAQ_READER/daq_dta.h>
18 #include "fcs_data_c.h"
20 const char *daq_fcs::help_string =
"\
24 raw returns=ptr of start of DDL data; c1=sector[1..1]; c2=rdo[1..4]; \n\
33 LOG(DBG,
"%s",__PRETTY_FUNCTION__) ;
34 daq_det_factory::det_factories[FCS_ID] = this ;
38 LOG(DBG,
"%s",__PRETTY_FUNCTION__) ;
49 LOG(DBG,
"%s",__PRETTY_FUNCTION__) ;
52 name = rts2name(rts_id) ;
56 if(caller) caller->insert(
this, rts_id) ;
63 zs->meta = (
void *)&fcs_meta ;
65 LOG(DBG,
"%s: constructor: caller %p",name,rts_caller) ;
71 LOG(DBG,
"%s: DEstructor",name) ;
83 daq_dta *daq_fcs::get(
const char *bank,
int sec,
int raw,
int pad,
void *p1,
void *p2)
87 if(present==0)
return 0 ;
92 LOG(DBG,
"%s: looking for bank %s",name,bank) ;
94 if(strcmp(bank,
"*")==0) bank =
"raw" ;
98 if(strcasecmp(bank,
"raw")==0) {
99 if((present & DET_PRESENT_SFS)==0)
return 0 ;
100 return handle_raw() ;
102 else if(strcasecmp(bank,
"adc")==0) {
103 if((present & DET_PRESENT_SFS)==0)
return 0 ;
104 return handle_adc() ;
106 else if(strcasecmp(bank,
"zs")==0) {
107 if((present & DET_PRESENT_SFS)==0)
return 0 ;
110 else if(strcasecmp(bank,
"ped")==0) {
111 if((present & DET_PRESENT_SFS)==0)
return 0 ;
112 return handle_ped() ;
115 LOG(ERR,
"%s: unknown bank type \"%s\"",name,bank) ;
133 ped->create(1024,
"fcs_ped",rts_id,DAQ_DTA_STRUCT(u_char)) ;
136 for(
int s=1;s<=12;s++) {
137 for(
int r=min_rdo;r<=max_rdo;r++) {
138 sprintf(str,
"%s/sec%02d/rdo%d/ped",sfs_name,s,r) ;
139 full_name = caller->get_sfs_name(str) ;
142 if(full_name==0) continue ;
144 int size = caller->sfs->fileSize(full_name) ;
146 LOG(DBG,
"S%d:%d: Got size %d",1,r,size) ;
148 LOG(NOTE,
"%s: %s: not found in this event",name,str) ;
154 char *st = (
char *) ped->request(size) ;
156 caller->sfs->read(full_name, st, size) ;
158 LOG(DBG,
"sfs read succeeded") ;
160 ped->finalize(size,s,r,0) ;
187 sprintf(str,
"%s/sec01/rb01/raw",sfs_name) ;
188 full_name = caller->get_sfs_name(str) ;
190 LOG(DBG,
"%s: trying sfs on \"%s\"",name,str) ;
197 raw->create(1024,
"fcs_raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
200 for(
int s=1;s<=12;s++) {
201 for(
int r=min_rdo;r<=max_rdo;r++) {
203 sprintf(str,
"%s/sec%02d/rdo%d/raw",sfs_name,s,r) ;
204 full_name = caller->get_sfs_name(str) ;
206 LOG(NOTE,
"str %s, full_name %s",str,full_name) ;
207 if(full_name) version = 2018 ;
211 if(full_name==0) continue ;
213 int size = caller->sfs->fileSize(full_name) ;
215 LOG(DBG,
"S%d:%d: Got size %d",1,r,size) ;
217 LOG(NOTE,
"%s: %s: not found in this event",name,str) ;
223 char *st = (
char *) raw->request(size) ;
225 caller->sfs->read(full_name, st, size) ;
227 LOG(DBG,
"sfs read succeeded") ;
229 raw->finalize(size,s,r,0) ;
257 memset(&fcs_meta,0,
sizeof(fcs_meta)) ;
258 fcs_meta.version = 0x00000001 ;
259 zs->meta = (
void *)&fcs_meta ;
263 zs->create(8*1024,
"fcs_zs",rts_id,DAQ_DTA_STRUCT(
daq_adc_tb)) ;
265 for(
int s=1;s<=12;s++) {
267 sprintf(str,
"%s/sec%02d/zs",sfs_name,s) ;
269 full_name = caller->get_sfs_name(str) ;
282 bytes = caller->sfs->fileSize(full_name) ;
284 m_st = st = (
char *)malloc(bytes) ;
285 caller->sfs->read(full_name,st,bytes) ;
287 u_int *zs_int = (u_int *)st ;
289 int bytes_data = zs_int[0] & 0x0FFFFFFF ;
291 LOG(NOTE,
"zs first 0x%X, bytes data %d",zs_int[0],bytes_data) ;
293 zs_start = (u_short *)st ;
294 for(
int j=0;j<16;j++) LOG(DBG,
"%d = 0x%04X",j,zs_start[j]) ;
306 zs_start = (u_short *)st ;
307 u_short *zs_dta = zs_start ;
308 u_int *zs_int = (u_int *)st ;
310 int zs_tkn = (zs_int[0]>>16)&0xFFF ;
311 LOG(NOTE,
"... board_id 0x%08X, zs_tkn %d, shorts %d, bytes_data %d",zs_int[0],zs_tkn,zs_int[1],bytes_data) ;
325 if(zs_int[0] & 0xF0000000) {
326 sec = zs_int[0] & 0xFFFF ;
327 rdo = zs_int[0] & 0x1F ;
329 fcs_meta.sector1 = ((sec>>11)&0x1F)+1 ;
330 fcs_meta.rdo1 = ((sec>>8)&0x7)+1 ;
341 LOG(WARN,
"0 shorts??") ;
346 bytes_data -= zs_int[1]*2 ;
348 LOG(DBG,
"S%d:%d - bytes_data %d",(sec>>11)+1,((sec>>8)&0x7)+1,bytes_data) ;
352 u_short *zs_end = zs_dta + zs_int[1] ;
358 while(zs_dta < zs_end) {
360 int seq_cou = *zs_dta++ ;
363 LOG(DBG,
"Ch %d(%d), seq %d: %d",ch,ch_cou,seq_cou,zs_end-zs_dta) ;
366 if(seq_cou==0) continue ;
372 for(
int i=0;i<seq_cou;i++) {
373 int t_start = *zs_dta++ ;
374 int t_cou = *zs_dta++ ;
375 int t_end = t_start + t_cou ;
377 LOG(DBG,
"..... t_start %d, t_cou %d",t_start,t_cou) ;
379 for(
int t=t_start;t<t_end;t++) {
380 u_short d = *zs_dta++ ;
389 zs->finalize(a_cou,sec,rdo,ch) ;
397 if(m_st) free(m_st) ;
410 if(got_any)
return zs ;
414 for(u_int r=min_rdo;r<=max_rdo;r++) {
417 sprintf(str,
"%s/sec01/rdo%d/zs",sfs_name,r) ;
418 full_name = caller->get_sfs_name(str) ;
420 LOG(DBG,
"full %s, str %s",full_name,str) ;
422 if(full_name==0) continue ;
424 int bytes = caller->sfs->fileSize(full_name) ;
426 LOG(DBG,
"S%d:%d: Got size %d",1,r,bytes) ;
428 LOG(NOTE,
"%s: %s: not found in this event",name,str) ;
434 char *st = (
char *)malloc(bytes) ;
436 caller->sfs->read(full_name, st, bytes) ;
438 LOG(DBG,
"sfs read succeeded") ;
440 u_short *zs_start = (u_short *)st ;
441 u_short *zs_dta = zs_start ;
442 u_int *zs_int = (u_int *)st ;
444 LOG(NOTE,
"... board_id 0x%08X, shorts %d",zs_int[0],zs_int[1]) ;
455 if(zs_int[0] & 0xF0000000) {
456 sec = zs_int[0] & 0xFFFF ;
457 rdo = zs_int[0] & 0x1F ;
461 sec = ((1-1)<<11)|((r-1)<<8)|(2<<6)|(1<<5)|0 ;
464 sec = ((1-1)<<11)|((r-1)<<8)|(0<<6)|(1<<5)|0 ;
478 u_short *zs_end = zs_dta + zs_int[1] ;
482 while(zs_dta < zs_end) {
484 int seq_cou = *zs_dta++ ;
487 LOG(DBG,
"Ch %d, seq %d: %d",ch,seq_cou,zs_end-zs_dta) ;
489 if(seq_cou==0) continue ;
495 for(
int i=0;i<seq_cou;i++) {
496 int t_start = *zs_dta++ ;
497 int t_cou = *zs_dta++ ;
498 int t_end = t_start + t_cou ;
500 LOG(DBG,
"..... t_start %d, t_cou %d",t_start,t_cou) ;
502 for(
int t=t_start;t<t_end;t++) {
503 u_short d = *zs_dta++ ;
512 zs->finalize(a_cou,sec,rdo,ch) ;
536 if(dta==0)
return 0 ;
538 adc->create(1000,
"adc",rts_id,DAQ_DTA_STRUCT(u_short)) ;
541 while(dta && dta->iterate()) {
542 u_short *ptr = (u_short *) dta->Void ;
549 fcs_c.sector = dta->sec ;
550 fcs_c.set_rdo(dta->rdo) ;
552 fcs_c.start(ptr,dta->ncontent/2) ;
556 while(fcs_c.event()) {
560 u_short *at = (u_short *)adc->request(fcs_c.tb_cou) ;
562 for(
int i=0;i<fcs_c.tb_cou;i++) {
563 at[i] = fcs_c.adc[i] ;
571 int sec = fcs_c.hdr_board_id ;
572 int rdo = fcs_c.hdr_board_id & 0x1F ;
574 adc->finalize(fcs_c.tb_cou, sec, rdo, fcs_c.ch) ;
585 int daq_fcs::get_token(
char *addr,
int words)
587 LOG(ERR,
"get_token") ;
592 cou = get_l2(addr,words,trg,1) ;
594 if(cou==0)
return -1000 ;
595 if(trg[0].t==0)
return -ENOSYS ;
600 static inline u_int sw16(u_int d)
606 d |= (tmp & 0xFFFF)<<16 ;
614 int daq_fcs::get_l2(
char *addr,
int words,
struct daq_trg_word *trg,
int rdo)
617 u_int *d = (u_int *)addr ;
622 int trg_cmd, daq_cmd ;
623 int t_hi, t_mid, t_lo ;
626 if(addr==0)
return 0 ;
637 if(d[0] != 0xCCCC001C) {
638 LOG(ERR,
"%d: comma word 0x%08X bad, words %d",rdo,d[0],words) ;
642 hdr = sw16(d[1]) >> 16 ;
650 trg_word = (d16[4]<<16) | d16[3] ;
654 trg_word = (d16[5]<<16) | d16[4] ;
657 trg_word = sw16(d[3]) ;
665 LOG(ERR,
"%d: unexpected HDR 0x%04X",rdo,hdr) ;
670 trg_cmd = trg_word & 0xF ;
671 daq_cmd = (trg_word >> 4) & 0xF ;
672 t_hi = (trg_word >> 8) & 0xF ;
673 t_mid = (trg_word >> 12) & 0xF ;
674 t_lo = (trg_word >> 16) & 0xF ;
676 t_lo |= (t_hi<<8) | (t_mid << 4) ;
688 LOG(ERR,
"%d: token-0 in event HDR 0x%04X: trg_cmd 0x%05X: trg %d, daq %d",rdo,hdr,trg_word,trg_cmd,daq_cmd) ;
696 u_short *d16 = (u_short *)d ;
697 for(
int i=0;i<16;i++) {
698 LOG(TERR,
"... %d = 0x%04X",i,d16[i]) ;
714 LOG(WARN,
"%d: unusual trg_cmd=0x%X in event 0x%04X: T %d, daq 0x%X",rdo,trg_cmd,hdr,t_lo,daq_cmd) ;
721 u_short *d16 = (u_short *)d ;
722 for(
int i=0;i<16;i++) {
723 LOG(TERR,
"... %d = 0x%04X",i,d16[i]) ;
728 trg[t_cou].t = t_lo ;
729 trg[t_cou].trg = trg_cmd ;
730 trg[t_cou].daq = daq_cmd ;
731 trg[t_cou].rhic = 0 ;
732 trg[t_cou].rhic_delta = 0 ;