StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
emc_reader.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <arpa/inet.h>
4 #include <assert.h>
5 
6 #include <rtsLog.h>
7 #include <rtsSystems.h>
8 #include <rts.h>
9 
10 #define TRG_VERSION 0x32
11 #include <daqFormats.h>
12 #include <trgStructures.h>
13 
14 #include "daq_emc.h"
15 
16 
17 
18 
19 
20 
21 
22 
23 //static char *getEmcTrgData(char *input, int idx, int *bytes) ;
24 
25 static int readBTOW(u_short *_data, int token);
26 static int readETOW(u_short *_data, int token);
27 
28 static emc_t *emc_p ;
29 
30 /*
31 static char *id2char(int id)
32 {
33  switch(id) {
34  case BTOW_ID :
35  return "BARREL" ;
36  case ETOW_ID :
37  return "ENDCAP" ;
38  default :
39  return "unknown" ;
40  }
41 
42 }
43 
44 
45 static char *inst2char(int inst)
46 {
47  switch(inst) {
48  case 1 :
49  return "TOWER" ;
50  case 2 :
51  return "SMD" ;
52  default :
53  return "UNKNOWN" ;
54  }
55 
56 }
57 
58 */
59 
60 
61 
62 static struct emc_describe_t {
63  int id ;
64 
65  const char *p ;
66  const char *secp ;
67  const char *rbp ;
68  const char *adcr ;
69  const char *adcd ;
70  int trg_index ;
71  int type ; // 0 Barrel, 1 Endcap
72  int sub ; // 0 tower, 1 SMD
73 } emc_describe[4] = {
74  { BTOW_ID, CHAR_EMCP, CHAR_EMCSECP, CHAR_EMCRBP, CHAR_EMCADCR, CHAR_EMCADCD, BTOW_INDEX, 0, 0 },
75  { BSMD_ID, CHAR_EMCP, CHAR_EMCSECP, CHAR_EMCRBP, CHAR_EMCADCR, CHAR_EMCADCD, -1 , 0, 1},
76  { ETOW_ID, CHAR_EECP, CHAR_EECSECP, CHAR_EECRBP, CHAR_EECADCR, CHAR_EECADCD, ETOW_INDEX, 1, 0 },
77  { ESMD_ID, CHAR_EECP, CHAR_EECSECP, CHAR_EECRBP, CHAR_EECADCR, CHAR_EECADCD, -1, 1, 1 },
78 } ;
79 
80 
81 int emc_reader(char *m, struct emc_t *emc, u_int driver, int rts_id, char *ptrs[12], int f_bytes[12])
82 {
83 #if 1
84  return 0 ;
85 #else
86  struct DATAP *datap = (struct DATAP *)m ;
87  struct DATAPX *datapx ;
88  struct EMCP *emcp;
89  struct EMCSECP *emcsecp ;
90  struct EMCRBP *emcrbp ;
91  struct DUMMYDATA *dummy ;
92  int len, off ;
93  int err ;
94 
95  int swapdatap = 0;
96  int swapdatapx = 0;
97  int swapemcp = 0;
98 
99  // setup
100  if(datap == 0) return 0 ;
101  if(f_bytes) memset(f_bytes,0,sizeof(f_bytes)) ;
102 
103  emc_p = emc ;
104  u_char emc_wanted[4] ;
105 
106  if(emc_p == 0) { // just the concrete rts_id!
107  for(int i=0;i<4;i++) {
108  if(emc_describe[i].id == rts_id) {
109  emc_wanted[i] = 1 ;
110  }
111  else {
112  emc_wanted[i] = 0 ;
113  }
114  }
115  }
116  else { // ALL!
117  memset(emc,0,sizeof(emc_t)) ;
118 
119  emc_p->btow_max_ch = BTOW_MAXFEE*BTOW_DATSIZE ;
120  emc_p->bsmd_max_ch = 12*4800 ; // extended with BPRE
121  emc_p->etow_max_ch = ETOW_MAXFEE*ETOW_DATSIZE ;
122  emc_p->esmd_max_ch = ESMD_MAXFEE*ESMD_DATSIZE ; // unknown...
123 
124  memset(emc_wanted,0x1,sizeof(emc_wanted)) ;
125  }
126 
127  err = 0 ;
128  int found = -1 ;
129 
130  for(int i=0;i<4;i++) { // go through all EMC typez
131 
132  if(emc_wanted[i] == 0) continue ;
133 
134  char *dta_ptr = 0 ;
135  int bytes = 0 ;
136 
137  // let's check for data within the trigger bank first...
138  dta_ptr = getEmcTrgData((char *)datap, emc_describe[i].trg_index, &bytes);
139 
140 
141  if(dta_ptr) {
142  f_bytes[0] = bytes ;
143  ptrs[0] = dta_ptr ;
144  found = 1 ;
145  goto found_specific_emc ;
146  }
147 
148 
149  // OK, nothing in the Trigger bank, let's continue ;;;
150 
151  if(emc_describe[i].type==0) {
152  int id = BTOW_ID ;
153 
154  len = qswap32(swapdatap, datap->det[id].len) * 4 ;
155  off = qswap32(swapdatap, datap->det[id].off) ;
156  if((len == 0) || (off == 0)) {
157  continue;
158  }
159  }
160  else {
161  int id = ETOW_ID ;
162 
163  // EEC is in DATAPX...
164  len = qswap32(swapdatap, datap->det[EXT_ID].len) ;
165  off = qswap32(swapdatap, datap->det[EXT_ID].off) ;
166 
167  LOG(DBG, "Checking for datapx: len=%d off=%d",len,off);
168 
169  if((len == 0) || (off == 0)) {
170  continue;
171  }
172 
173  datapx = (struct DATAPX *)(m + off*4) ;
174 
175  // verify bank
176  if(checkBank(datapx->bh.bank_type, CHAR_DATAPX) < 0) {
177  err = 1 ;
178  continue ;
179  }
180 
181  if(datapx->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapdatapx = 1;
182 
183  len = qswap32(swapdatapx, datapx->det[id-10].len) * 4 ;
184  off = qswap32(swapdatapx, datapx->det[id-10].off) ;
185 
186  LOG(DBG, "Checking for EEC: len=%d off=%d",len,off);
187 
188  if((len == 0) || (off == 0)) {
189  continue;
190  }
191 
192  // override "m"
193  m = (char *)datapx ;
194  }
195 
196 
197  emcp = (struct EMCP *)((u_int *)m + off) ;
198 
199  if(checkBank(emcp->bh.bank_type,emc_describe[i].p) < 0) {
200  err = 1 ;
201  continue ;
202  }
203 
204  if(emcp->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swapemcp = 1;
205 
206  int token = qswap32(swapemcp, emcp->bh.token) ;
207 
208  char *name = rts2name(emc_describe[i].id) ;
209  int sub = emc_describe[i].sub ;
210 
211 
212  // let's see how many contributions (subdetectors) does this event have
213 
214  len = qswap32(swapemcp, emcp->sec[sub].len) ;
215  off = qswap32(swapemcp, emcp->sec[sub].off) ;
216 
217  if(!len || !off) continue ; // not found...
218 
219  emcsecp = (struct EMCSECP *)((u_int *)emcp + off) ;
220 
221  if(checkBank(emcsecp->bh.bank_type,emc_describe[i].secp) <= 0) {
222  err = 1 ;
223  continue ;
224  }
225 
226  int fibers = (b2h32(emcsecp->bh.length) - 10) / 2 ; // contributions aka fibers
227 
228  if(fibers > 12) {
229  LOG(ERR,"%s: too many fibers %d > %d",name,fibers,12) ;
230  err = 1 ;
231  continue ;
232  }
233 
234  LOG(DBG,"EMC %s: %d fibers possible",name,fibers) ;
235 
236  for(int j=0;j<fibers;j++) { // and now we count the fibers
237  len = b2h32(emcsecp->fiber[j].len) ;
238  off = b2h32(emcsecp->fiber[j].off) ;
239 
240  if(!len || !off) continue ;
241 
242  emcrbp = (struct EMCRBP *)((u_int *)emcsecp + off) ;
243 
244  if(checkBank(emcrbp->bh.bank_type,emc_describe[i].rbp) <= 0) {
245  err = 1 ;
246  continue ;
247  }
248 
249  found = i ;
250 
251  int banks = (b2h32(emcrbp->bh.length) - 10) /2 ;
252 
253  if(banks > 3) {
254  LOG(ERR,"%s: fiber %d: too many banks %d > %d",name,j,banks,3) ;
255  err = 1 ;
256  continue ;
257  }
258 
259  LOG(DBG,"EMC %s: fiber %d: %d banks used",name,j,banks) ;
260 
261  /* extract stuff from the banks:
262  ESMD, BTOW, ETOW: ADCR
263  BSMD: ADCR, ADCD, PED_RMS ;
264  */
265 
266  char *b_ptrs[3] ;
267  int b_bytes[3] ;
268 
269  memset(b_ptrs,0,sizeof(b_ptrs)) ;
270  memset(b_bytes,0,sizeof(b_bytes)) ;
271 
272  for(int k=0;k<banks;k++) {
273  len = b2h32(emcrbp->banks[k].len) ;
274  off = b2h32(emcrbp->banks[k].off) ;
275 
276  if(!len || !off) continue ;
277 
278  bytes = len *4 ;
279  dta_ptr = 40 + (char *)emcrbp + off*4 ; // points to raw data, skipping 40 bytes bankHeader!
280 
281  dummy = (DUMMYDATA *) ((u_int *)emcrbp + off) ;
282 
283  b_bytes[k] = bytes ;
284  b_ptrs[k] = dta_ptr ;
285 
286 
287  switch(k) {
288  case 0 : // ADCR, raw non-ZS data
289  if(checkBank(dummy->bh.bank_type, emc_describe[i].adcr)<0) {
290  err = 1 ;
291  continue ;
292  }
293 
294  break ;
295  case 1 : // ADCD, ZS data -- BSMD only!
296  if(checkBank(dummy->bh.bank_type, "EMCADCD")<0) {
297  err = 1 ;
298  continue ;
299  }
300 
301  break ;
302  case 2 : // PEDRMSR -- BSMD only!
303  if(checkBank(dummy->bh.bank_type, "EMCPEDR")<0) {
304  err = 1 ;
305  continue ;
306  }
307 
308  break ;
309  default :
310  LOG(ERR,"%s: fiber %d: unknown bank at %d",name,j,k) ;
311  err = 1 ;
312  continue ;
313  }
314 
315  } // banks
316 
317 
318  if(asdasd & (1<<2)) { // gimme ZS data!
319  f_bytes[j] = b_bytes[1] ;
320  ptrs[j] = b_ptrs[1] ;
321  }
322  else if(b_bytes[2]) {
323  f_bytes[j] = b_bytes[2] ;
324  ptrs[j] = b_ptrs[1] ;
325  }
326  else {
327  f_bytes[j] = b_bytes[0] ;
328  ptrs[j] = b_ptrs[0] ;
329  }
330 
331  } // fibers
332 
333 
334  found_specific_emc:
335 
336  if(found <0) continue ; // keep going...
337 
338 
339  if(emc==0) {
340  if(err) return -1 ;
341 
342  return 1 ;
343  }
344 
345  // here I need to fill in the old emc_t struct....
346  if(err) continue ;
347 
348 
349 
350 
351  } // dets
352 
353  if(err) return -1 ;
354  if(found<0) return 0 ;
355 
356 
357 #if 0
358 
359  emcadcr = NULL ;
360 
361 
362  emcadcd = NULL ;
363 
364  switch(k) {
365  case 0 : // Raw, ADCR
366  emcadcr = (struct DUMMYDATA *)((u_int *)emcrbp + off) ;
367  if(checkBank(emcadcr->bh.bank_type,adcr) < 0) {
368  continue ;
369  }
370 
371  break ;
372  case 1 : // zero-suppressed...
373  emcadcd = (struct DUMMYDATA *)((u_int *)emcrbp + off) ;
374  if(checkBank(emcadcd->bh.bank_type,adcd) < 0) {
375  continue ;
376  }
377 
378  break ;
379  default :
380  LOG(ERR,"Unknown subbank %d in EMCRBP!",k,0,0,0,0) ;
381  continue ;
382  }
383 
384  /* this is not true anymore since BSMD can have ZS data
385  // I currently only know about RAW data
386 
387  if(emcadcr == NULL) {
388  LOG(WARN,"EMC %d: instance %d, format %d is not implemented yet!",
389  id2char(id),inst2char(instance), k,0,0) ;
390  continue ;
391  }
392  */
393 
394  if((type==0) && (i == EMC_B_TOW)) { // barrel tower
395  if(trg_btow_data) {
396  LOG(ERR, "Reading BTOW data from DAQ banks but already read it from trigger banks");
397  }
398 
399 
400  if((rts_id == BTOW_ID) && (emc==0)) {
401  ptrs[0] = (char *) emcadcr + 40 ;
402  f_bytes[0] = l2h32(emcadcr->bh.length)*4 - 40 ;
403  return 1 ;
404  }
405 
406  readBTOW((u_short *)((u_int)emcadcr + 40), token);
407 
408  }
409  else if((type==0) && (i == EMC_B_SMD)) { // barrel SMD
410  u_short *data ;
411  int l ;
412 
413  emc_p->bsmd_in = 1;
414 
415  // logic...
416  if(emcadcr) { //raw data present
417 
418 
419  // get to the data: 40 bytes bank header, 4 bytes dummy,
420  // 256 bytes fiber header...
421  data = (u_short *) ((u_int) emcadcr + 40 + 4 + 256) ;
422 
423 
424  emc_p->bsmd_cap[j] = *(u_char *)((u_int)emcadcr + 40 + 4 + 4*16) ;
425  if(adcd_found) { // ALSO the ZS present!!!
426  emc_p->bsmd_raw_in = 1 ;
427  for(l=0;l<4800;l++) {
428  emc_p->bsmd_raw[j][l] = l2h16(*data++) ;
429  }
430  }
431  else {
432  for(l=0;l<4800;l++) {
433  emc_p->bsmd[j][l] = l2h16(*data++) ;
434  if(emc_p->bsmd[j][l] > 0) emc_p->bsmd_ch++ ;
435 
436  }
437  }
438 
439  LOG(DBG,"BSMD raw data present. Sent to the bsmd_raw bank? -- %s",(emc_p->bsmd_raw_in?"Yes":"No")) ;
440  }
441 
442  if(emcadcd) {
443 
444  int datums = b2h32(emcadcd->bh.length)-10-1 ; // 10 header, 1 fiber:count combo
445 
446  LOG(DBG,"BSMD ZS data present, %d hits",datums) ;
447 
448  data = (u_short *) ((uint) emcadcd + 40) ; // skip header
449  LOG(DBG,"local fiber %d, channels %d [== %d]",b2h16(data[0]),b2h16(data[1]),datums) ;
450  data += 2 ;
451 
452  for(l=0;l<datums;l++) {
453  int ch = b2h16(*data++) ;
454  int adc = b2h16(*data++) ;
455 
456  emc_p->bsmd[j][ch] = adc ;
457 
458  //LOG(DBG,"ch %4d = %4d",ch,adc) ;
459 
460 
461 
462  }
463 
464  emc_p->bsmd_ch += datums ;
465  }
466 
467  }
468  else if((type==1) && (i == EMC_B_TOW)) { // endcap tower
469 
470  if(trg_etow_data) {
471  LOG(ERR, "Reading ETOW data in the DAQ banks, but already read it from the trigger banks.");
472  }
473 
474 
475 
476  if((rts_id == ETOW_ID) && (emc == 0)) {
477  ptrs[0] = (char *) emcadcr + 40 ;
478  f_bytes[0] = l2h32(emcadcr->bh.length)*4 - 40 ;
479  return 1 ;
480  }
481 
482  readETOW((u_short *)((u_int)emcadcr + 40), token);
483 
484  }
485  else if((type==1) && (i == EMC_B_SMD)) { // endcap SMD
486 
487  u_short *data ;
488  u_int tlo, thi ;
489  int l, m ;
490 
491  emc_p->esmd_in = 1;
492 
493  // get to the data: 40 bytes bank header, 4 bytes dummy,
494  // 128 bytes fiber header...
495  // ...but first grab the token from the header...
496  data = (u_short *) ((u_int) emcadcr + 40 + 4 + 4) ;
497  thi = l2h16(*data) ;
498  data = (u_short *) ((u_int) emcadcr + 40 + 4 + 6) ;
499  tlo = l2h16(*data) ;
500 
501  local_token = thi * 256 + tlo ;
502 
503  if(token != local_token) {
504  LOG(ERR,"ESMD: Token in bank %d different from token in data %d",token,local_token,0,0,0) ;
505  }
506 
507  ptrs[0] = (char *) emcadcr + 40 ;
508  f_bytes[0] = l2h32(emcadcr->bh.length)*4 - 40 ;
509  if((rts_id == ESMD_ID) && (emc == 0)) return 1 ;
510 
511 
512  data = (u_short *) ((u_int) emcadcr + 40 + 4 + 128) ;
513 
514  emc_p->esmd_raw = data ;
515 
516  // get the header size...
517  if(l2h32(emcadcr->bh.length) < 3000) { // FY04 data
518  emc_p->esmd_max_fee = 30 ;
519  }
520  else {
521  emc_p->esmd_max_fee = 48 ;
522  }
523 
524  emc_p->esmd_max_ch = emc_p->esmd_max_fee*ETOW_DATSIZE ;
525 
526 
527  // get the preamble
528  for(m=0;m<ESMD_PRESIZE;m++) {
529  for(l=0;l<emc_p->esmd_max_fee;l++) {
530  emc_p->esmd_pre[l][m] = l2h16(*data++) ;
531  }
532  }
533 
534  for(m=0;m<ESMD_DATSIZE;m++) {
535  for(l=0;l<emc_p->esmd_max_fee;l++) {
536  emc_p->esmd[l][m] = l2h16(*data++) ;
537  if(emc_p->esmd[l][m] > 0) emc_p->esmd_ch++ ;
538  }
539  }
540  }
541  }
542  }
543  }
544  }
545 
546 
547  return bytes ;
548 #endif
549 #endif
550 
551 }
552 
553 // Starts from after the EMCADCR bankHeader...
554 //
555 // ie... data = (u_`int)emcadcr + 40
556 // = (u_int)trg_btow_data
557 //
558 int readBTOW(u_short *_data, int token)
559 {
560  u_short *data ;
561  int l, m ;
562  int thi, tlo, local_token;
563 
564  emc_p->btow_in = 1;
565 
566  data = (u_short *)((char *)_data + 4 + 4);
567  thi = l2h16(*data);
568  data = (u_short *)((char *)_data + 4 + 6);
569  tlo = l2h16(*data);
570  data = (u_short *)((char *)_data + 4 + 128);
571 
572  local_token = thi * 256 + tlo ;
573 
574  if(token != local_token) {
575  LOG(ERR,"BTOW: Event token different from token in BTOW data %d vs %d (%d,%d)",token,local_token,thi,tlo,0) ;
576  }
577 
578  // 4 bytes dummy, 128 bytes fiber header...
579  data = (u_short *)((char *)_data + 4 + 128);
580  emc_p->btow_raw = data ;
581 
582  // get the preamble
583  for(m=0;m<BTOW_PRESIZE;m++) {
584  for(l=0;l<BTOW_MAXFEE;l++) {
585  emc_p->btow_pre[l][m] = l2h16(*data++) ;;
586  }
587  }
588 
589  for(m=0;m<BTOW_DATSIZE;m++) {
590  for(l=0;l<BTOW_MAXFEE;l++) {
591  emc_p->btow_new[l][m] = l2h16(*data++) ;
592  }
593  }
594 
595  // roll back
596  data = emc_p->btow_raw ;
597  data += 120 ; // skip the preamble of 4X30 shorts
598 
599  for(l=0;l<4800;l++) {
600  emc_p->btow[l] = l2h16(*data++) ;
601  if(emc_p->btow[l] > 0) emc_p->btow_ch++ ;
602  }
603 
604  return 0;
605 }
606 
607 
608 
609 // Starts from after the bankHeader...
610 //
611 // ie... data = (u_int)emcadcr + 40
612 // = (u_int)trg_btow_data + 136
613 //
614 int readETOW(u_short *_data, int token) {
615  u_short *data ;
616  u_int tlo, thi ;
617  int local_token;
618 
619  int l,m ;
620 
621  emc_p->etow_in = 1;
622  // get to the data: 40 bytes bank header, 4 bytes dummy,
623  // 128 bytes fiber header...
624  // ...but first grab the token from the header...
625 
626 
627  data = (u_short *)((char *)_data + 4 + 4);
628  thi = l2h16(*data);
629  data = (u_short *)((char *)_data + 4 + 6);
630  tlo = l2h16(*data);
631  data = (u_short *)((char *)_data + 4 + 128);
632 
633  local_token = thi * 256 + tlo ;
634 
635  if(token != local_token) {
636  LOG(ERR,"ETOW: Event token different from token in ETOW data %d vs %d (%d,%d)",token,local_token,thi,tlo,0) ;
637  }
638 
639  emc_p->etow_raw = data ;
640 
641  // get the preamble
642  for(m=0;m<ETOW_PRESIZE;m++) {
643  for(l=0;l<ETOW_MAXFEE;l++) {
644  emc_p->etow_pre[l][m] = l2h16(*data++) ;;
645  }
646  }
647 
648 
649  for(m=0;m<ETOW_DATSIZE;m++) {
650  for(l=0;l<ETOW_MAXFEE;l++) {
651  emc_p->etow[l][m] = l2h16(*data++) ;
652  if(emc_p->etow[l][m] > 0) emc_p->etow_ch++ ;
653  }
654  }
655 
656  // hack!
657  //emc_p->etow[0][0] = local_token ;
658 
659  return 0;
660 }
661 
662 char *getEmcTrgData(char *input, int idx, int *bytes)
663 {
664  DATAP *datap = (DATAP *) input ;
665  struct TRGP *trgp ;
666  struct TRGD *trgd ;
667  UINT32 *ptr;
668 
669  int len, off ;
670 
671  *bytes = 0 ;
672  if(idx < 0) return 0 ;
673  if(datap == 0) return 0 ;
674 
675  int swapdatap=0;
676  int swaptrgp=0;
677  int swaptrgd=0;
678 
679 
680  LOG(DBG, "Starting getEmcTrgData 0x%x",datap);
681 
682  if(datap->bh.byte_order != DAQ_RAW_FORMAT_ORDER)
683  swapdatap = 1;
684 
685  len = qswap32(swapdatap, datap->det[TRG_ID].len);
686  if(len == 0) return NULL;
687  len *= 4 ;
688 
689  off = qswap32(swapdatap, datap->det[TRG_ID].off);
690  if(off == 0) return NULL;
691 
692 
693  ptr = (UINT32 *)datap;
694  trgp = (struct TRGP *)(ptr + off) ;
695  if(checkBank(trgp->bh.bank_type,"TRGP") < 0) { // wrong bank!
696  return NULL;
697  }
698 
699  if(trgp->bh.byte_order != DAQ_RAW_FORMAT_ORDER)
700  swaptrgp = 1;
701 
702  if(trgp->bh.token == 0) {
703  LOG(DBG,"Token 0 - skipping...",0,0,0,0,0) ;
704  return NULL;
705  }
706 
707  if(trgp->trgData.len == 0) return NULL;
708  if(trgp->trgData.off == 0) return NULL;
709 
710  off = qswap32(swaptrgp, trgp->trgData.off);
711  ptr = (u_int *)trgp;
712  trgd = (struct TRGD *)(ptr + off) ;
713 
714  if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swaptrgd = 1;
715 
716  // check misc. things
717  if(checkBank(trgd->bh.bank_type,"TRGD") < 0) {
718  return NULL;
719  }
720 
721  LOG(DBG,"TRGD len %d",
722  qswap32(swaptrgd, trgd->bh.length),0,0,0) ;
723 
724  if(qswap32(swaptrgd, trgd->bh.length) == 10) return NULL; // no trigger data - just bh
725 
726 
727  u_char trg_version = trgd->desc.TrgDataFmtVer ;
728  char *cptr;
729  TrgTowerTrnfer *trgtowertrnfer;
730 
731  switch(trg_version) {
732  case 0x10 :
733 
734  LOG(NOTE, "TRG transverse version 0x%02x, EMC data supported", trg_version);
735 
736 
737  cptr = (char *)trgd;
738  cptr += sizeof(bankHeader);
739 
740  trgtowertrnfer = (TrgTowerTrnfer *)cptr;
741 
742  off = qswap32(swaptrgd, trgtowertrnfer->OffsetBlock[idx].offset);
743  len = qswap32(swaptrgd, trgtowertrnfer->OffsetBlock[idx].length);
744 
745  // Tonko: "len" is _already_ in bytes!!! Arghhhhh...
746 
747  LOG(NOTE, "IDX = %d offset = %d length = %d",
748  idx, off, len);
749 
750  if(off && len) {
751  if(idx == BTOW_INDEX) {
752 
753  if(len != (64 + 2 + 30*164)*2) {
754  LOG(ERR, "Have BTOW in event, but data length incorrect: len=%d not %d, ignoring data...",
755  len, (64 + 2 + 30 * 164) * 2);
756  return NULL;
757  }
758 
759  LOG(NOTE, "Have BTOW data in trigger banks: off=%d, len=%d", off, len);
760  }
761  else if (idx == ETOW_INDEX) {
762 
763  if(len != (64 + 2 + 6*164)*2) {
764  LOG(ERR, "Have ETOW in event, but data length incorrect: len=%d not %d. Ignoring data...",len,
765  (64+2+6*164)*2);
766  return NULL;
767  }
768 
769  LOG(NOTE, "Have ETOW data in trigger banks: off=%d, len=%d", off, len);
770  }
771 
772  cptr += off; // move to data
773  *bytes = len ; // length: was already in bytes! Contrary to the usual practices....
774  return cptr;
775  }
776  break;
777 
778  default :
779  LOG(NOTE, "Trigger transfer version 0x%x... no EMC data in trigger banks.", trg_version);
780  }
781 
782 
783  return NULL;
784 }
Definition: daq_emc.h:52
u_short * esmd_raw
ESMD preamble.
Definition: daq_emc.h:96
u_short esmd_pre[ESMD_MAXFEE][ESMD_PRESIZE]
ADC data.
Definition: daq_emc.h:95