StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_pp2pp.cxx
1 #include <sys/types.h>
2 #include <errno.h>
3 #include <assert.h>
4 #include <arpa/inet.h>
5 
6 #include <rtsLog.h>
7 #include <rtsSystems.h>
8 
9 #include <SFS/sfs_index.h>
10 #include <DAQ_READER/daq_dta.h>
11 #include <DAQ_READER/daqReader.h>
12 
13 #include "daq_pp2pp.h"
14 
15 
16 
18 {
19 public:
21  daq_det_factory::det_factories[PP_ID] = this ;
22  }
23 
24  daq_det *create() {
25  return new daq_pp2pp ;
26  }
27 } ;
28 
29 static daq_det_pp2pp_factory pp2pp_factory ;
30 
31 
32 
33 const char *daq_pp2pp::help_string = "\
34 \n\
35 PP2PP Help: \n\
36 Supported Banks: \n\
37  raw returns=ptr of start of DDL data; c1=pp[1..2]; \n\
38  adc returns=ptr of ADC data; c1=pp[1..2]; \n\
39 \n\
40 \n\
41 " ;
42 
43 
44 
45 daq_pp2pp::daq_pp2pp(daqReader *rts_caller)
46 {
47  rts_id = PP_ID ;
48  name = rts2name(rts_id) ;
49  sfs_name = "pp2pp" ;
50  caller = rts_caller ;
51 #ifndef PP_MVME
52  if(caller) caller->insert(this, rts_id) ;
53 #endif
54 
55  raw = new daq_dta ;
56  adc = new daq_dta ;
57  pedrms = new daq_dta ;
58  adc_ped_sub = new daq_dta ;
59 
60  LOG(DBG,"%s: constructor: caller %p, endianess %d",name,rts_caller,endianess) ;
61 
62 
63  return ;
64 }
65 
66 daq_pp2pp::~daq_pp2pp()
67 {
68  LOG(DBG,"%s: Destructor",name) ;
69  if(raw) delete raw ;
70  if(adc) delete adc ;
71  if(pedrms) delete pedrms ;
72  if(adc_ped_sub) delete adc_ped_sub ;
73 
74  return ;
75 }
76 
77 
78 
79 daq_dta *daq_pp2pp::get(const char *bank, int sec, int row, int pad, void *p1, void *p2)
80 {
81  Make() ;
82  if(!present) return 0 ; // this det is not in this event...
83 
84 
85  LOG(DBG,"%s: looking for bank %s",name,bank) ;
86 
87  if(strcasecmp(bank,"raw")==0) {
88  return handle_raw(sec,row) ; // actually sec, rdo; r1 is the number of bytes
89  }
90  else if(strcasecmp(bank,"adc")==0) {
91  return handle_adc(sec, row) ;
92  }
93  else if(strcasecmp(bank,"adc_ped_sub")==0) {
94  return handle_adc_ped_sub(sec, row) ;
95  }
96  else if(strcasecmp(bank,"pedrms")==0) {
97  return handle_pedrms(sec) ;
98  }
99  else {
100  LOG(ERR,"%s: unknown bank type \"%s\"",name,bank) ;
101  }
102 
103  return 0 ;
104 }
105 
106 daq_dta *daq_pp2pp::handle_pedrms(int sec)
107 {
108  char str[128] ;
109  char *full_name ;
110  int found_some = 0 ;
111 
112  int tot_bytes ;
113  int min_sec, max_sec ;
114  struct {
115  int sec ;
116  u_int bytes ;
117  } obj[MAX_SEC*(MAX_RDO+1)] ; // pp2pp has a special rdo#0 case!
118 
119  // sanity
120  if(sec==-1) {
121  min_sec = 1 ;
122  max_sec = MAX_SEC ;
123  }
124  else if((sec<0) || (sec>MAX_SEC)) return 0 ;
125  else {
126  min_sec = max_sec = sec ;
127  }
128 
129  // bring in the bacon from the SFS file....
130  assert(caller) ;
131 
132  // calc total bytes
133  tot_bytes = 0 ;
134  int o_cou = 0 ;
135  for(int s=min_sec;s<=max_sec;s++) {
136 
137  sprintf(str,"%s/sec%02d/pedrms",sfs_name, s) ;
138  full_name = caller->get_sfs_name(str) ;
139  if(!full_name) continue ;
140 
141  LOG(DBG,"%s: trying sfs on \"%s\"",name,str) ;
142 
143  int size = caller->sfs->fileSize(str) ; // this is bytes
144 
145  LOG(DBG,"Got %d",size) ;
146 
147  if(size <= 0) {
148  LOG(NOTE,"%s: %s: not found in this event",name,str) ;
149  continue ;
150  }
151  else {
152  obj[o_cou].sec = s ;
153  obj[o_cou].bytes = size ;
154 
155  o_cou++ ;
156 
157  tot_bytes += size ;
158  found_some = 1 ;
159  LOG(NOTE,"%s: %s: reading in \"%s\": bytes %d",name,str,"pedrms", size) ;
160  }
161  }
162 
163  if(o_cou == 0) return 0 ;
164 
165  pedrms->create(2,"pp2pp_rms",rts_id,DAQ_DTA_STRUCT(pp2pp_pedrms_t)) ;
166 
167  for(int i=0;i<o_cou;i++) {
168 
169  sprintf(str,"%s/sec%02d/pedrms",sfs_name, obj[i].sec) ;
170  full_name = caller->get_sfs_name(str) ;
171  if(!full_name) continue ;
172 
173  char *mem = (char *)malloc(obj[i].bytes) ;
174  int ret = caller->sfs->read(full_name, mem, obj[i].bytes) ;
175 
176  if(ret != (int)obj[i].bytes) {
177  LOG(ERR,"%s: %s: read failed, expect %d, got %d [%s]",name,str,
178  obj[i].bytes,ret,strerror(errno)) ;
179  }
180  else {
181  LOG(NOTE,"%s: %s read %d bytes",name,str,ret) ;
182 
183  }
184 
185  int banks = obj[i].bytes / sizeof(pp2pp_pedrms_t) ;
186  int remain = obj[i].bytes % sizeof(pp2pp_pedrms_t) ;
187 
188  int version = ((pp2pp_pedrms_t *)mem)->version ;
189 
190  if(remain || (version != PP2PP_PED_VERSION)) {
191  LOG(ERR,"PEDRMS bank corrupt (%d, %d); version %d but I known version %d",banks,remain,version,PP2PP_PED_VERSION) ;
192  continue ;
193  }
194 
195  for(int j=0;j<banks;j++) {
196  pp2pp_pedrms_t *ped = (pp2pp_pedrms_t *)pedrms->request(1) ;
197 
198  memcpy(ped,mem+j*sizeof(pp2pp_pedrms_t),sizeof(pp2pp_pedrms_t)) ;
199 
200  pedrms->finalize(1, obj[i].sec, ped->seq_id, ped->chain_id) ;
201  }
202 
203  free(mem) ;
204  }
205 
206 
207  pedrms->rewind() ;
208 
209  if(found_some) return pedrms ;
210  else return 0 ;
211 
212 
213 }
214 
215 daq_dta *daq_pp2pp::handle_adc_ped_sub(int sec, int rdo)
216 {
217  int min_sec, max_sec ;
218  int found_some = 0 ;
219 
220  // sanity
221  if(sec==-1) {
222  min_sec = 1 ;
223  max_sec = MAX_SEC ;
224  }
225  else if((sec<0) || (sec>MAX_SEC)) return 0 ;
226  else {
227  min_sec = max_sec = sec ;
228  }
229 
230  LOG(DBG,"In handle_adc_ped_sub [%d,%d]",min_sec,max_sec) ;
231 
232  adc_ped_sub->create(1,"pp2pp_t",rts_id,DAQ_DTA_STRUCT(pp2pp_t)) ;
233 
234 
235  for(int i=min_sec;i<=max_sec;i++) { //loop over sequencers
236  char str[128] ;
237  char *full_name ;
238 
239  sprintf(str,"%s/sec%02d/rb00/adc_ped_sub",sfs_name, i) ;
240  LOG(DBG,"Checking %s",str) ;
241 
242  full_name = caller->get_sfs_name(str) ;
243  if(!full_name) continue ;
244 
245  LOG(DBG, "No bank %s",str) ;
246 
247  int bytes = caller->sfs->fileSize(str) ; // this is bytes
248  if(bytes <= 0) continue ;
249 
250 
251  char *mem = (char *)malloc(bytes) ;
252 
253  int ret = caller->sfs->read(full_name, mem, bytes) ;
254  if(ret < 0) {
255  LOG(ERR,"read error") ;
256  free(mem) ;
257  continue ;
258  }
259 
260  LOG(NOTE,"Got %d bytes",bytes) ;
261 
262  char *u_mem = mem ; // the one we will advance...
263 
264  while(bytes>0) {
265  pp2pp_ped_sub_t *ps = (pp2pp_ped_sub_t *)u_mem ;
266 
267  int l_bytes = sizeof(pp2pp_ped_sub_t) + ps->ch_cou*(1+1) ;
268 
269  LOG(DBG,"Chs %d: bytes %d",ps->ch_cou,l_bytes) ;
270 
271  pp2pp_t *pp = (pp2pp_t *)adc_ped_sub->request(1) ;
272 
273 
274  memset(pp,0,sizeof(pp2pp_t)) ;
275  memcpy(pp,ps,sizeof(pp2pp_ped_sub_t)) ; // to get all the variables...
276 
277 
278  for(int j=0;j<ps->ch_cou;j++) {
279  int ch = ps->dta[j].ch ;
280  int adc = ps->dta[j].adc ;
281 
282  LOG(DBG,"ix %d: ch %d, adc %d",j,ch,adc) ;
283 
284  pp->adc[ch] = adc ;
285  pp->trace[ch] = 1 ;
286  }
287 
288 
289  adc_ped_sub->finalize(1,i,pp->seq_id,pp->chain_id) ;
290 
291  u_mem += l_bytes ;
292  bytes -= l_bytes ;
293 
294  LOG(DBG,"%d %d %d -- left %d",pp->seq_id,pp->chain_id,pp->svx_id,bytes) ;
295 
296  }
297 
298  free(mem) ;
299  found_some++ ;
300 
301  }
302 
303  LOG(DBG,"exiting handle adc_ped_sub") ;
304 
305  adc_ped_sub->rewind() ;
306 
307  if(found_some) return adc_ped_sub ;
308  else return 0 ;
309 }
310 
311 daq_dta *daq_pp2pp::handle_adc(int sec, int rdo)
312 {
313  int min_sec, max_sec ;
314  int found_some = 0 ;
315 
316  // sanity
317  if(sec==-1) {
318  min_sec = 1 ;
319  max_sec = MAX_SEC ;
320  }
321  else if((sec<0) || (sec>MAX_SEC)) return 0 ;
322  else {
323  min_sec = max_sec = sec ;
324  }
325 
326  adc->create(1,"pp2pp_t",rts_id,DAQ_DTA_STRUCT(pp2pp_t)) ;
327 
328  for(int i=min_sec;i<=max_sec;i++) {
329  daq_dta *sec_dta ;
330 
331  LOG(DBG,"Before sec %d",i) ;
332  sec_dta = handle_raw(i, -1) ; // rdo is ignored...
333  LOG(DBG,"After raw") ;
334  if(sec_dta == 0) continue ;
335 
336  LOG(DBG,"Before ite") ;
337  int ret = sec_dta->iterate() ;
338  LOG(DBG,"After it %d",ret) ;
339  if(ret == 0) continue ;
340 
341 
342  found_some = 1 ;
343  LOG(DBG,"pp2pp adc: sector %d, words %d",i,sec_dta->ncontent) ;
344 
345  // extract modules
346  ret = decode(i,(char *)sec_dta->Void, sec_dta->ncontent) ;
347  if(ret < 0) {
348  LOG(ERR,"pp2pp_decode failed for sector %d",i) ;
349  continue ;
350  }
351  LOG(DBG,"After decode %d",ret) ;
352  }
353 
354  adc->rewind() ;
355 
356  if(found_some) return adc ;
357  else return 0 ;
358 }
359 
360 
361 daq_dta *daq_pp2pp::handle_raw(int sec, int rdo)
362 {
363  char str[128] ;
364  char *full_name ;
365  int found_some = 0 ;
366 
367  int tot_bytes ;
368  int min_rdo, max_rdo ;
369  int min_sec, max_sec ;
370  struct {
371  int sec ;
372  int rb ;
373  u_int bytes ;
374  } obj[MAX_SEC*(MAX_RDO+1)] ; // pp2pp has a special rdo#0 case!
375 
376  // sanity
377  if(sec==-1) {
378  min_sec = 1 ;
379  max_sec = MAX_SEC ;
380  }
381  else if((sec<0) || (sec>MAX_SEC)) return 0 ;
382  else {
383  min_sec = max_sec = sec ;
384  }
385 
386  if(rdo==-1) {
387  min_rdo = 0 ;
388  max_rdo = 0 ;
389  }
390  else if((rdo<0) || (rdo>MAX_RDO)) return 0 ;
391  else {
392  min_rdo = max_rdo = rdo ;
393  }
394 
395 #ifdef PP_MVME
396  return 0 ;
397 #else
398  // bring in the bacon from the SFS file....
399  assert(caller) ;
400 
401  // calc total bytes
402  tot_bytes = 0 ;
403  int o_cou = 0 ;
404  for(int s=min_sec;s<=max_sec;s++) {
405  for(int r=min_rdo;r<=max_rdo;r++) {
406 
407  sprintf(str,"%s/sec%02d/rb%02d/raw",sfs_name, s, r) ;
408  full_name = caller->get_sfs_name(str) ;
409  if(!full_name) continue ;
410 
411  LOG(DBG,"%s: trying sfs on \"%s\"",name,str) ;
412 
413  int size = caller->sfs->fileSize(str) ; // this is bytes
414 
415  LOG(DBG,"Got %d",size) ;
416 
417  if(size <= 0) {
418  LOG(NOTE,"%s: %s: not found in this event",name,str) ;
419  continue ;
420  }
421  else {
422  obj[o_cou].sec = s ;
423  obj[o_cou].rb = r ;
424  obj[o_cou].bytes = size ;
425 
426  o_cou++ ;
427 
428  tot_bytes += size ;
429  found_some = 1 ;
430  LOG(NOTE,"%s: %s: reading in \"%s\": bytes %d",name,str,"raw", size) ;
431  }
432  }
433  }
434 
435  if(o_cou == 0) return 0 ;
436 
437  raw->create(tot_bytes,"pp2pp_raw",rts_id,DAQ_DTA_STRUCT(u_char)) ;
438 
439  for(int i=0;i<o_cou;i++) {
440 
441  sprintf(str,"%s/sec%02d/rb%02d/raw",sfs_name, obj[i].sec, obj[i].rb) ;
442  full_name = caller->get_sfs_name(str) ;
443  if(!full_name) continue ;
444 
445  char *mem = (char *)raw->request(obj[i].bytes) ;
446 
447  int ret = caller->sfs->read(full_name, mem, obj[i].bytes) ;
448 
449  if(ret != (int)obj[i].bytes) {
450  LOG(ERR,"%s: %s: read failed, expect %d, got %d [%s]",name,str,
451  obj[i].bytes,ret,strerror(errno)) ;
452  }
453  else {
454  LOG(NOTE,"%s: %s read %d bytes",name,str,ret) ;
455 
456  }
457 
458  raw->finalize(obj[i].bytes, obj[i].sec, obj[i].rb, 0) ;
459 
460  }
461 
462 
463  raw->rewind() ;
464 
465  if(found_some) return raw ;
466  else return 0 ;
467 #endif
468 }
469 
470 int daq_pp2pp::get_token(char *addr, int words)
471 {
472  int cou ;
473  struct daq_trg_word trg[8] ;
474 
475  cou = get_l2(addr,words,trg,1) ;
476 
477  if(cou==0) return -1000 ;
478  if(trg[0].t==0) return -ENOSYS ;
479 
480  return trg[0].t ;
481 }
482 
483 
484 int daq_pp2pp::get_l2(char *addr, int words, struct daq_trg_word *trgs, int prompt)
485 {
486  u_int *d = (u_int *)addr ;
487  int t_cou = 0 ;
488  u_int datum ;
489  u_int trg_cou ;
490  u_int *trg_dta ;
491 
492 
493  if(prompt) {
494  LOG(DBG,"words %d: dta 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X",words,d[0],d[1],d[2],d[3],d[4]) ;
495 
496  }
497  // get count
498  trg_cou = ntohl(d[words-1]) ;
499 
500  if(trg_cou>100) {
501  LOG(ERR,"trg_cou 0x%08X, words %d",trg_cou,words) ;
502  return -1 ;
503  }
504 
505  // move to start
506  trg_dta = &(d[words-1-trg_cou]) ;
507 
508 
509  for(u_int i=0;i<trg_cou;i++) {
510  datum = trg_dta[i] ;
511 
512  if((datum & 0xFF000000) == 0xEE000000) { // prompt
513 
514  trgs[t_cou].t = (datum&0xF00) | ((datum & 0xF000)>>8) | ((datum & 0xF0000)>>16);
515  trgs[t_cou].daq = (datum>>4) & 0xF ;
516  trgs[t_cou].trg = datum & 0xF ;
517  trgs[t_cou].rhic = 0 ;
518  trgs[t_cou].rhic_delta = 0 ;
519 
520  if(prompt) {
521  LOG(NOTE,"T %4d (prompt): daq %d, trg %d",trgs[t_cou].t,trgs[t_cou].daq,trgs[t_cou].trg) ;
522  }
523 
524  t_cou++ ;
525  break ;
526  }
527 
528  }
529 
530  if(t_cou == 0) { // no prompt contrib! invent token 4097
531 
532  LOG(NOTE,"No prompt trigger, trg_cou %d",trg_cou) ;
533 
534  trgs[t_cou].t = 4097 ;
535  trgs[t_cou].daq = 0 ;
536  trgs[t_cou].trg = 5 ;
537  trgs[t_cou].rhic = 0 ;
538  trgs[t_cou].rhic_delta = 0 ;
539 
540  if(prompt) {
541  LOG(NOTE,"T %4d (no data): daq %d, trg %d",trgs[t_cou].t,trgs[t_cou].daq,trgs[t_cou].trg) ;
542  }
543 
544  t_cou++ ;
545 
546 
547  }
548 
549  for(u_int i=0;i<trg_cou;i++) {
550  datum = trg_dta[i] ;
551 
552  if((datum & 0xFF000000) != 0xEE000000) { // FIFO!
553 
554  trgs[t_cou].t = (datum&0xF00) | ((datum & 0xF000)>>8) | ((datum & 0xF0000)>>16);
555  trgs[t_cou].daq = (datum>>4) & 0xF ;
556  trgs[t_cou].trg = datum & 0xF ;
557  trgs[t_cou].rhic = 1 ;
558  trgs[t_cou].rhic_delta = 1 ;
559 
560  if(prompt) {
561  LOG(NOTE,"T %4d (FIFO): daq %d, trg %d",trgs[t_cou].t,trgs[t_cou].daq,trgs[t_cou].trg) ;
562  }
563 
564 
565  // keep only L2 commands!
566  switch(trgs[t_cou].trg) {
567  case 13 :
568  case 15 :
569  break ;
570  default :
571  continue ;
572  }
573 
574  if(trgs[t_cou].t == 0) {
575  LOG(ERR,"T %4d (FIFO): daq %d, trg %d -- token 0, skipping",trgs[t_cou].t,trgs[t_cou].daq,trgs[t_cou].trg) ;
576  }
577  else {
578  t_cou++ ;
579  }
580  }
581 
582  }
583 
584 
585 
586  return t_cou ;
587 }
588 
589 
590 
591 
592 int daq_pp2pp::decode(int sec_id, char *raw, int bytes)
593 {
594  u_int *d32 ;
595  u_short *d16 ;
596  u_short seq[2], trg[2] ;
597  u_char *d8 ;
598  int ret = 0 ;
599 
600  LOG(DBG,"adc %p",adc) ;
601 
602  int seq_id, chain_id, svx_id ;
603 
604  int words = bytes/4 ;
605 
606  // we are still debugging!
607  d32 = (u_int *) raw ; // data is BIG ENDIAN!
608  d16 = (u_short *) raw ;
609 
610  for(int i=0;i<bytes/4;i++) {
611  LOG(DBG,"pp2pp data: %2d: 0x%08X",i,b2h32(d32[i])) ;
612  }
613 
614  //2014 note: for compatibility reasons the trg_cou word in the payload
615  // (last word) is maintained in BIG_ENDIAN!
616  int trg_cou = b2h32(d32[words-1]) ; //thr trigger count
617 // int trg_cou = (d32[words-1]) ; //thr trigger count
618 // LOG(WARN,"Using unswapped!!!") ;
619  int trg_ix = words - 1 - trg_cou ;
620 
621  LOG(DBG,"words %d, trg_cou %d",words,trg_cou) ;
622  for(int i=0;i<trg_cou;i++) {
623  LOG(NOTE,"pp2pp: trg %d/%d: 0x%08X",i+1,trg_cou,b2h32(d32[trg_ix+i])) ;
624  }
625 
626 
627  int w16 = 2 * (words - trg_cou - 1) ; // 16 bit words left
628 
629  LOG(DBG,"16bit words left: %d",w16) ;
630 
631  int cur_ix = 0 ;
632  int next_good_ix = 0 ;
633 
634  int bunch_xing = -1 ;
635  u_int trigger = 0xFFFFFFFF ;
636 
637  svx_id = 0 ;
638  int not_sparse = 0 ;
639 
640  while(cur_ix < w16) {
641  struct pp2pp_t *d = 0 ; // to provoke a core dump
642  int requested = 0 ;
643 
644  int i ;
645 
646  // grab sequencer descriptor
647  seq[0] = b2h16(d16[cur_ix]) ;
648  cur_ix++ ;
649  seq[1] = b2h16(d16[cur_ix]) ;
650  cur_ix++ ;
651 
652  // grab trigger data, although I will ignore it...
653  trg[0] = b2h16(d16[cur_ix]) ;
654  cur_ix++ ;
655  trg[1] = b2h16(d16[cur_ix]) ;
656  cur_ix++ ;
657 
658  seq_id = (seq[0] >> 8) >> 2 ;
659  chain_id = (seq[0] >> 8) & 3 ;
660 
661 
662  if(trigger == 0xFFFFFFFF) {
663  trigger = (trg[1] << 16) | trg[0] ;
664  }
665  else {
666  u_int tmp = (trg[1] << 16) | trg[0] ;
667 
668  if(tmp != trigger) {
669  ret |= 1 ;
670  LOG(ERR,"pp2pp: seq %d:%d: expect trigger 0x%08X, read 0x%08X",seq_id,chain_id,trigger,tmp) ;
671  return ret ;
672  }
673  else {
674  LOG(DBG,"pp2pp: seq %d:%d: expect trigger 0x%08X, read 0x%08X",seq_id,chain_id,trigger,tmp) ;
675  }
676  }
677 
678  if(bunch_xing < 0) { // first time...
679  bunch_xing = seq[0] & 0x7F ;
680  not_sparse = (seq[0] & 0x80)?1:0 ;
681  }
682  else {
683  int tmp = seq[0] & 0x7F ;
684 
685  if(tmp != bunch_xing) {
686  ret |= 2 ;
687  LOG(ERR,"pp2pp: seq %d:%d: expect xing 0x%02X, read 0x%02X",seq_id,chain_id,bunch_xing,tmp) ;
688  return ret ;
689  }
690  else {
691  LOG(DBG,"pp2pp: seq %d:%d: expect xing 0x%02X, read 0x%02X",seq_id,chain_id,bunch_xing,tmp) ;
692  }
693 
694 
695  tmp = (seq[0] & 0x80)?1:0 ;
696 
697  if(tmp != not_sparse) {
698  ret |= 2 ;
699  LOG(ERR,"pp2pp: seq %d:%d: expect not_sparse 0x%02X, read 0x%02X",seq_id,chain_id,not_sparse,tmp) ;
700  return ret ;
701  }
702  else {
703  LOG(DBG,"pp2pp: seq %d:%d: expect not_sparse 0x%02X, read 0x%02X",seq_id,chain_id,not_sparse,tmp) ;
704  }
705 
706 
707 
708 
709  }
710 
711 
712 
713 
714 
715  int fifo_w16 = (seq[1] >>8) | ((seq[1] & 0xF)<<8) ;
716 
717  LOG(DBG,"seq 0x%04X, 0x%04X; trg 0x%04X, 0x%04X; len %d",seq[0],seq[1],trg[0],trg[1],fifo_w16) ;
718  LOG(NOTE,"pp2pp: seq_id %d:%d; words %d",seq_id,chain_id,fifo_w16) ;
719 
720  // subtract 2 because of the trigger word
721  fifo_w16 -= 2 ;
722 
723  d8 = (u_char *) &(d16[cur_ix]) ;
724 
725  next_good_ix = cur_ix + fifo_w16 ;
726  if(fifo_w16 & 1) { // padding
727  next_good_ix++ ;
728  }
729 
730  for(i=0;i<fifo_w16;i++) {
731  int ch, c_adc ;
732 
733  ch = *d8++ ;
734  c_adc = *d8++ ;
735 
736  LOG(DBG,"Word %d/%d: ch %d, c_adc %d",i,fifo_w16,ch,c_adc) ;
737 
738  if(ch & 0x80) {
739  if(c_adc != 0) {
740  ret |= 4 ;
741  LOG(ERR,"Bad channel in seq %d:%d: %d %d",seq_id,chain_id,ch,c_adc) ;
742  //break ;
743  }
744  else {
745  LOG(NOTE,"SVX break: seq %d:%d: SVX 0x%02X",seq_id, chain_id,ch) ;
746  }
747 
748  LOG(DBG,"requested %d",requested) ;
749 
750  if(requested) {
751  LOG(DBG,"finalize %d %d %d",sec_id,d->seq_id,d->chain_id) ;
752  adc->finalize(1, sec_id, d->seq_id, d->chain_id) ;
753  requested = 0 ;
754  }
755 
756  svx_id = ch & 0x7F ;
757 
758  LOG(DBG,"svx_id %d",svx_id) ;
759 
760  LOG(DBG,"Calling adc request %p",adc) ;
761 
762  d = (struct pp2pp_t *) adc->request(1) ;
763 
764  LOG(DBG,"d is %p",d) ;
765 
766  requested = 1 ;
767 
768  d->seq_id = seq_id ;
769  d->chain_id = chain_id ;
770  d->svx_id = svx_id ;
771  d->bunch_xing = bunch_xing ;
772  d->not_sparse = not_sparse ;
773 
774  d->error = ret ;
775 
776  memset(d->adc,0,sizeof(d->adc)) ;
777  memset(d->trace,0,sizeof(d->trace)) ;
778  }
779  else {
780  if(!requested) {
781  LOG(ERR,"Bad data -- SVX ID was not found in sequencer %d, chain %d (0x%X 0x%X)",seq_id, chain_id, ch,c_adc) ;
782  ret |=4 ;
783  break ;
784  }
785  else {
786  LOG(DBG,"datum %d/%d: %3d = 0x%02X",i,fifo_w16,ch,c_adc) ;
787 
788  if(d->trace[ch]) {
789  LOG(WARN,"Seq %d, chain %c, SVX %d: duplicate channel %d: ADC now %d, was %d!",
790  seq_id,chain_id+'A',svx_id,
791  ch,c_adc,d->adc[ch]) ;
792  ret |= 4;
793  d->trace[ch] = 2 ;
794  }
795  else d->trace[ch] = 1 ;
796 
797  d->adc[ch] = c_adc ;
798  }
799  }
800 
801  cur_ix++ ;
802  }
803 
804 
805 
806  if(fifo_w16 & 1) {
807  int ch, c_adc ;
808 
809  ch = *d8++ ;
810  c_adc = *d8++ ;
811 
812  LOG(DBG,"Padding %d/%d: %3d = 0x%02X",i,fifo_w16,ch,c_adc) ;
813 
814  cur_ix++ ;
815  }
816 
817  if(requested) {
818  adc->finalize(1, sec_id, d->seq_id, d->chain_id) ;
819  requested = 0 ;
820  }
821 
822  cur_ix = next_good_ix ;
823 
824  }
825 
826  return ret ;
827 }
Definition: rb.hh:21
void version(std::ostream &os=std::cout)
print HepMC version
Definition: Version.h:27