StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rts_example.C
1 //#define JMLSECSZ
2 //#define JMLADC
3 #define JMLEVTMIN 206150
4 #define JMLEVTMAX 206200
5 
6 #include <stdio.h>
7 #include <unistd.h>
8 #include <getopt.h>
9 #include <sys/types.h>
10 #include <stdlib.h>
11 #include <time.h>
12 #include <arpa/inet.h>
13 
14 #include <rtsLog.h> // for my LOG() call
15 #include <rtsSystems.h>
16 
17 // this needs to be always included
18 #include <DAQ_READER/daqReader.h>
19 #include <DAQ_READER/daq_dta.h>
20 
21 //#include <trgDataDefs.h>
22 #include "trgConfNum.h"
23 
24 // only the detectors we will use need to be included
25 // for their structure definitions...
26 #include <DAQ_BSMD/daq_bsmd.h>
27 #include <DAQ_BTOW/daq_btow.h>
28 #include <DAQ_EMC/daq_emc.h>
29 #include <DAQ_ESMD/daq_esmd.h>
30 #include <DAQ_ETOW/daq_etow.h>
31 #include <DAQ_FPD/daq_fpd.h>
32 #include <DAQ_FTP/daq_ftp.h>
33 #include <DAQ_L3/daq_l3.h>
34 #include <DAQ_PMD/daq_pmd.h>
35 #include <DAQ_PP2PP/daq_pp2pp.h>
36 #include <DAQ_RIC/daq_ric.h>
37 #include <DAQ_SC/daq_sc.h>
38 #include <DAQ_SSD/daq_ssd.h>
39 #include <DAQ_SVT/daq_svt.h>
40 #include <DAQ_TOF/daq_tof.h>
41 #include <DAQ_TPC/daq_tpc.h>
42 #include <DAQ_TPX/daq_tpx.h>
43 #include <DAQ_TPX/tpxCore.h>
44 
45 #include <DAQ_TRG/daq_trg.h>
46 #include <DAQ_HLT/daq_hlt.h>
47 #include <DAQ_L4/daq_l4.h>
48 #include <DAQ_FGT/daq_fgt.h> //includes GMT & IST & FST
49 #include <DAQ_MTD/daq_mtd.h>
50 #include <DAQ_PXL/daq_pxl.h>
51 #include <DAQ_SST/daq_sst.h>
52 #include <DAQ_FPS/daq_fps.h>
53 #include <DAQ_RHICF/daq_rhicf.h>
54 #include <DAQ_ETOF/daq_etof.h>
55 
56 #include <DAQ_ITPC/daq_itpc.h>
57 #include <DAQ_ITPC/itpcCore.h>
58 #include <TPC/rowlen.h>
59 
60 #include <DAQ_FCS/daq_fcs.h>
61 #include <DAQ_FCS/fcs_data_c.h>
62 
63 #include <DAQ_STGC/daq_stgc.h>
64 
65 
66 
67 /* various test routines... typically used by Tonko only */
68 #include <DAQ_FGT/fgtPed.h>
69 static int fgt_test(daqReader *rdr, const char *do_print, int which) ;
70 #include <DAQ_SST/sstPed.h>
71 static int sst_test(daqReader *rdr, int mode) ;
72 
73 // I wrapped more complicated detectors inside their own functions
74 // for this example
75 #ifdef INSIST_ON_EMC_PSEUDO
76 static int emc_pseudo_doer(daqReader *rdr, const char *do_print) ;
77 #endif
78 
79 static int bsmd_doer(daqReader *rdr, const char *do_print) ;
80 static int esmd_doer(daqReader *rdr, const char *do_print) ;
81 static int btow_doer(daqReader *rdr, const char *do_print) ;
82 static int etow_doer(daqReader *rdr, const char *do_print) ;
83 static int tpc_doer(daqReader *rdr, const char *do_print) ;
84 static int tpx_doer(daqReader *rdr, const char *do_print) ;
85 static int trg_doer(daqReader *rdr, const char *do_print) ;
86 static int ftp_doer(daqReader *rdr, const char *do_print) ;
87 static int pmd_doer(daqReader *rdr, const char *do_print) ;
88 static int hlt_doer(daqReader *rdr, const char *do_print) ;
89 static int l4_doer(daqReader *rdr, const char *do_print) ;
90 
91 static int pp2pp_doer(daqReader *rdr, const char *do_print) ;
92 static int l3_doer(daqReader *rdr, const char *do_print) ;
93 static int fgt_doer(daqReader *rdr, const char *do_print, int which) ;
94 static int mtd_doer(daqReader *rdr, const char *do_print) ;
95 static int tinfo_doer(daqReader *rdr, const char *do_print);
96 static int pxl_doer(daqReader *rdr, const char *do_print) ;
97 static int sst_doer(daqReader *rdr, const char *do_print) ;
98 static int fps_doer(daqReader *rdr, const char *do_print) ;
99 static int rhicf_doer(daqReader *rdr, const char *do_print) ;
100 static int etof_doer(daqReader *rdr, const char *do_print) ;
101 static int itpc_doer(daqReader *rdr, const char *do_print) ;
102 static int fcs_doer(daqReader *rdr, const char *do_print) ;
103 static int stgc_doer(daqReader *rdr, const char *do_print) ;
104 
105 static int good ;
106 static int bad ;
107 static int nfs_loops ;
108 
109 static int run_number ;
110 static int print_mode ;
111 
112 //trigger related globals
113 u_int rcc_timestamp ;
114 
115 
116 
117 int altro_override[256] ;
118 
119 extern int *tpx_altro_to_row_override ;
120 
121 
122 //static double det_raw_bytes[6] ;
123 //static u_int det_events ;
124 
125 
126 static class daqReader *evp = 0 ; // tha main guy
127 
128 int main(int argc, char *argv[])
129 {
130  extern char *optarg ;
131  extern int optind ;
132  int c ;
133  const char *print_det = "" ;
134  char _mountpoint[256];
135  const char *mountpoint = "/net/evp"; // sensible default from daqman...
136 
137  rtsLogOutput(RTS_LOG_STDERR) ;
138  rtsLogLevel((char *)WARN) ;
139 
140 
141 // LOG(WARN,"Special override for TPX!") ;
142 // altro_override[50] = 1 ;
143 // altro_override[56] = 2 ;
144 // tpx_altro_to_row_override = altro_override ;
145 
146  run_number = -1 ;
147 
148  while((c = getopt(argc, argv, "D:d:m:f:")) != EOF) {
149  switch(c) {
150  case 'd' :
151  rtsLogLevel(optarg) ;
152  break ;
153  case 'D' :
154  print_det = optarg ;
155  break ;
156  case 'm' :
157  mountpoint = _mountpoint;
158  strncpy(_mountpoint, (char *)optarg,sizeof(_mountpoint)-1);
159  break;
160  case 'f' : // to tweak bank outputs
161  print_mode = atoi(optarg) ;
162  break ;
163  default :
164  break ;
165  }
166  }
167 
168 
169 
170  if(optind >= argc) { // no arguments -- NFS
171 
172 
173  evp = new daqReader(argv[optind]) ; // create it with the filename argument..
174 
175  evp->setEvpDisk((char *)mountpoint);
176 
177  LOG(INFO,"Using direct access via NFS directory %s to host %s",mountpoint,evp->EVP_HOSTNAME) ;
178 
179  optind = argc - 1 ; //hack up 1 loop
180 
181  }
182 
183 
184  while(optind < argc) {
185 
186  if(evp==0) {
187  LOG(INFO,"Opening file %s",argv[optind]) ;
188  evp = new daqReader(argv[optind]) ; // create it with the filename argument..
189  }
190 
191 
192  optind++ ;
193 
194  for(;;) {
195  char *ret = evp->get(0,EVP_TYPE_ANY);
196 
197  if(ret) {
198  if(evp->status) {
199  bad++ ;
200  LOG(ERR,"evp status is non-null [0x08X, %d dec]",evp->status,evp->status) ;
201  continue ;
202  }
203  good++;
204  }
205  else { // something other than an event, check what.
206  switch(evp->status) {
207  case EVP_STAT_OK: // just a burp!
208  continue;
209  case EVP_STAT_EOR:
210  LOG(DBG, "End of Run/File");
211  if(evp->IsEvp()) { // but event pool, keep trying...
212  LOG(DBG, "Wait a second...");
213  sleep(1);
214  nfs_loops++ ;
215  if((nfs_loops%5)==0) {
216  LOG(WARN,"Still waiting for Event Pool...") ;
217  }
218  continue;
219  }
220  break; // file, we're done...
221  case EVP_STAT_EVT:
222  bad++;
223  LOG(WARN, "Problem getting event - skipping [good %d, bad %d]",good,bad);
224  sleep(1);
225  continue;
226  case EVP_STAT_CRIT:
227  bad++ ;
228  LOG(CRIT,"evp->status CRITICAL (?)") ;
229  break ;
230  }
231  }
232 
233 // if(good>1000) break ;
234 
235  if(run_number < 0) {
236 
237  run_number = evp->run ;
238  LOG(INFO,"Opened run number %08u",evp->run) ;
239  }
240 
241  if(evp->status == EVP_STAT_EOR) {
242  LOG(INFO,"End of File reached...") ;
243  break ; // of the for() loop...
244  }
245 
246  daq_dta *dd ; // generic data pointer; reused all the time
247 
248  time_t e_time = (time_t) evp->evt_time ;
249  char *date = ctime(&e_time) ;
250  date[strlen(date)-1] = 0 ; //get rid of NL
251 
252  LOG(INFO,"evt %d: sequence %d: token %4d, trgcmd %d, daqcmd %d, time \"%s\", detectors 0x%08X (status 0x%X), evpgroups 0x%X",good,evp->seq, evp->token, evp->trgcmd, evp->daqcmd,
253  date, evp->detectors, evp->status,evp->evpgroups) ;
254 
255 // if(strlen(print_det)) { // if any detector full printout is requested
256 // printf("*** Event %d, sequence %d: token %d, trgcmd %d, daqcmd %d\n",good,
257 // evp->seq,evp->token,evp->trgcmd,evp->daqcmd) ;
258 // }
259 
260 
261  //printf("tinfo evt %d: sequence %d: token %4d, trgcmd %d, daqcmd %d, time \"%s\", detectors 0x%08X (status 0x%X), evpgroups 0x%X\n",good,evp->seq, evp->token, evp->trgcmd, evp->daqcmd,
262  // date, evp->detectors, evp->status,evp->evpgroups) ;
263 
264  /***************** let's do simple detectors; the ones which only have legacy *****/
265 
266  if(print_det[0]) {
267  if(strcmp(print_det, "tinfo") == 0) {
268  int ret = tinfo_doer(evp, "tinfo");
269  if(ret) LOG(INFO,"Trigger Info FOUND") ;
270  }
271  }
272 
273  if(print_det[0]) {
274  if(strcmp(print_det, "readahead") == 0) {
275  SummaryInfo nsummary;
276  int ret = evp->readNextFutureSummaryInfo(&nsummary);
277 
278 
279  if(ret <= 0) {
280  printf("Event #%d, token %d triggers 0x%llx ----> No Next Event...",
281  evp->seq,evp->token,evp->daqbits64);
282  }
283  else {
284  printf("Event #%d, token %d triggers 0x%llx ----> Next Event: #%d, token %d triggers 0x%llx\n",
285  evp->seq,evp->token,evp->daqbits64,
286  nsummary.seq, nsummary.token,
287  make64(nsummary.L3summary[0],nsummary.L3summary[1]));
288  }
289  }
290  }
291 
292  dd = evp->det("sc")->get() ;
293  if(dd && dd->iterate()) {
294  LOG(INFO,"SC found") ;
295  if(strcasecmp(print_det,"sc")==0) {
296  sc_t *sc_p = (sc_t *) dd->Void ;
297 
298  // oh well, one needs to to these calculations here
299  // since the SFS daq_sc.cxx doesn't know the absolute time
300  int alag ;
301 
302  sc_p->timelag = evp->evt_time - sc_p->time ;
303  if(sc_p->timelag > 0) alag = sc_p->timelag ;
304  else alag = -sc_p->timelag ;
305 
306  if(alag > 5) sc_p->valid = 0 ;
307  else sc_p->valid = 1 ;
308 
309  printf("SC: valid %d, time %u, timelag %d, B field %.3f\n",sc_p->valid,sc_p->time,sc_p->timelag,sc_p->mag_field) ;
310  for(int i=0;i<16;i++) {
311  printf("\tRICH scaler %2d: %u\n",i,sc_p->rich_scalers[i]) ;
312  }
313  }
314  }
315 
316  dd = evp->det("fpd")->get("legacy") ;
317  if(dd) LOG(INFO,"FPD found") ;
318 
319  if(ftp_doer(evp,print_det)) LOG(INFO,"FTP found") ;
320 
321 
322  dd = evp->det("rich")->get("legacy") ;
323  if(dd) LOG(INFO,"RIC found") ;
324 
325  dd = evp->det("ssd")->get("legacy") ;
326  if(dd) LOG(INFO,"SSD found") ;
327 
328  dd = evp->det("svt")->get("legacy") ;
329  if(dd) LOG(INFO,"SVT found") ;
330 
331 
332  if(pmd_doer(evp, print_det)) LOG(INFO,"PMD found") ;
333 
334  dd = evp->det("tof")->get("legacy") ;
335  if(dd) {
336  LOG(INFO,"TOF found") ;
337  if(strcasecmp(print_det,"tof")==0) {
338  while(dd->iterate()) {
339  tof_t *tof = (tof_t *)dd->Void ;
340  for(int r=0;r<4;r++) {
341  printf("TOF RDO %d: words %d:\n",r+1,tof->ddl_words[r]) ;
342  for(u_int i=0;i<tof->ddl_words[r];i++) {
343  printf("\t%d: 0x%08X [%u dec]\n",i,tof->ddl[r][i],tof->ddl[r][i]) ;
344  }
345  }
346  }
347  }
348  }
349 
350  if(trg_doer(evp, print_det)) LOG(INFO,"TRG found") ;
351 
352  /***************** EMCs ************************/
353 
354  if(btow_doer(evp, print_det)) LOG(INFO,"BTOW found") ;
355 
356  // logging done in the doer...
357  bsmd_doer(evp,print_det) ;
358 
359  if(etow_doer(evp, print_det)) LOG(INFO,"ETOW found") ;
360 
361  if(esmd_doer(evp, print_det)) LOG(INFO,"ESMD found") ;
362 
363  /******************** TPC (old electronics) ***********************/
364 
365  if(tpc_doer(evp,print_det)) LOG(INFO,"TPC found (legacy)") ;
366 
367  /********************** TPX ***************************/
368  tpx_doer(evp,print_det) ;
369 
370 
371 
372  /*************************** PP2PP **********************/
373  pp2pp_doer(evp,print_det) ;
374 
375 
376  /*************************** L3/HLT09 **************************/
377  if(l3_doer(evp,print_det)) LOG(INFO,"L3/HLT_FY09 found") ;
378 
379  /*************************** HLT10 **************************/
380  if(hlt_doer(evp,print_det)) LOG(INFO,"HLT_FY10 found") ;
381 
382  /*************************** L4 (HLT 12) *******************/
383  if(l4_doer(evp,print_det)) {
384  LOG(INFO, "HLT FY12 found");
385  }
386 
387  /*************************** FGT **************************/
388  fgt_doer(evp,print_det,FGT_ID) ;
389 
390  /*************************** MTD **************************/
391  if(mtd_doer(evp,print_det)) LOG(INFO,"MTD found") ;
392 
393 
394  /*************************** GMT **************************/
395  fgt_doer(evp,print_det,GMT_ID) ;
396 
397  /*************************** IST **************************/
398  fgt_doer(evp,print_det,IST_ID) ;
399  fgt_test(evp,print_det,IST_ID) ; //used by Tonko; ignore
400 
401  /*************************** PXL **************************/
402  if(pxl_doer(evp,print_det)) LOG(INFO,"PXL found") ;
403 
404  /*************************** SST **************************/
405  sst_doer(evp,print_det) ;
406 
407  /*************************** FPS **************************/
408  fps_doer(evp,print_det) ;
409 
410  /*************************** RHICF **************************/
411  rhicf_doer(evp,print_det) ;
412 
413  /*************************** ETOF **************************/
414  etof_doer(evp,print_det) ;
415 
416  /*************************** ITPC **************************/
417  itpc_doer(evp,print_det) ;
418 
419  /*************************** FCS **************************/
420  fcs_doer(evp,print_det) ;
421 
422  /*************************** STGC **************************/
423  stgc_doer(evp,print_det) ;
424 
425  /*************************** FST **************************/
426  fgt_doer(evp,print_det,FST_ID) ;
427 
428 
429  /************ PSEUDO: SHOULD ONLY BE USED FOR BACKWARD COMPATIBILITY! ************/
430 #ifdef INSIST_ON_EMC_PSEUDO
431  if(emc_pseudo_doer(evp,print_det)) LOG(INFO,"EMC found (any detector)") ;
432 #endif
433 
434  }
435 
436  delete evp ; // cleanup i.e. if running through a set of files.
437  evp = 0 ;
438  run_number = -1 ;
439 
440  }
441 
442  LOG(INFO,"Found %d good, %d bad events",good,bad) ;
443 
444 // sst_test(0,2) ;
445  return 0 ;
446 }
447 
448 static int trg_doer(daqReader *rdr, const char *do_print)
449 {
450  int found = 0 ;
451  daq_dta *dd ;
452 
453  if(strcasestr(do_print,"trg")) ;
454  else do_print = 0 ;
455 
456  // If i want decoded data ala old evpReader I call "legacy" ;
457 
458  dd = rdr->det("trg")->get("legacy") ;
459  if(dd) {
460  if(dd->iterate()) {
461  trg_t *trg_p = (trg_t *) dd->Void ;
462 
463  if(do_print) { // print something...
464  printf("Trigger: tcubits 0x%08X, trg_word 0x%04X\n",trg_p->tcubits,trg_p->trg_word) ;
465  }
466 
467  }
468  }
469 
470 
471  // if you need the void black box of untouched trigger data:
472  dd = rdr->det("trg")->get("raw") ;
473  if(dd) {
474  if(dd->iterate()) {
475  found = 1 ;
476 
477 
478  u_char *trg_raw = dd->Byte;
479 
480  TriggerDataBlk *trg = (TriggerDataBlk *)dd->Byte;
481 
482  EvtDescData *evtDesc = (EvtDescData *)(((char *)trg) + swap32(trg->EventDesc_ofl.offset));
483 
484  rcc_timestamp = (ntohs(evtDesc->tcuCtrBunch_hi)<<16) | ntohs(evtDesc->DSMAddress) ;
485 
486  //LOG(TERR,"0x%X 0x%X 0x%X 0x%X",evtDesc->tcuCtrBunch_hi,evtDesc->DSMAddress,ntohs(evtDesc->tcuCtrBunch_hi),ntohs(evtDesc->DSMAddress)) ;
487 
488 
489 
490  if(do_print) { // I have no clue but let me print first few words...
491 
492  //printf("EvtDescData %u %u --> %u mark: 0x%x\n",evtDesc->tcuCtrBunch_hi,evtDesc->DSMAddress,rcc_timestamp,evtDesc->TCUMark) ;
493 
494  // simple start of trig desc; the way it should be...
495  struct simple_desc {
496  short len ;
497  char evt_desc ;
498  char ver ;
499  } *desc ;
500 
501  desc = (simple_desc *) trg_raw ;
502 
503 
504  printf("Trigger: raw bank has %d bytes: ver 0x%02X, desc %d, len %d\n",dd->ncontent,desc->ver, desc->evt_desc, desc->len) ;
505 
506  // dump first 10 ints...
507  u_int *i32 = (u_int *) trg_raw ;
508  for(int i=0;i<10;i++) {
509  printf("Trigger: word %d: 0x%08X\n",i,i32[i]) ;
510  }
511  }
512  }
513  }
514 
515  return found ;
516 }
517 
518 
519 static int hlt_doer(daqReader *rdr, const char *do_print)
520 {
521  int found = 0 ;
522  daq_dta *dd ;
523 
524  if(strcasestr(do_print,"hlt")) ; // leave as is...
525  else do_print = 0 ;
526 
527  for(int s=1;s<=24;s++) {
528  dd = rdr->det("hlt")->get("tpx",s) ;
529  while(dd && dd->iterate()) {
530  found = 1 ;
531  if(do_print) {
532  printf("HLT TPX sec %02d: bytes %d\n",dd->sec,dd->ncontent) ;
533  }
534  }
535  }
536 
537  dd = rdr->det("hlt")->get("trg") ;
538  while(dd && dd->iterate()) {
539  found = 1 ;
540  if(do_print) {
541  printf("HLT TRG sec %02d: bytes %d\n",dd->sec,dd->ncontent) ;
542  }
543  }
544 
545  dd = rdr->det("hlt")->get("tof") ;
546  while(dd && dd->iterate()) {
547  found = 1 ;
548  if(do_print) {
549  printf("HLT TOF sec %02d: bytes %d\n",dd->sec,dd->ncontent) ;
550  }
551  }
552 
553  dd = rdr->det("hlt")->get("gl3") ;
554  while(dd && dd->iterate()) {
555  found = 1 ;
556  if(do_print) {
557  hlt_gl3_t *h = (hlt_gl3_t *) dd->Void ;
558  printf("HLT GL3 sec %02d: bytes %d: %d %s\n",dd->sec,dd->ncontent,h->bytes,h->name) ;
559  }
560  }
561 
562 
563 
564  return found ;
565 }
566 
567 static int l4_doer(daqReader *rdr, const char *do_print)
568 {
569  int found = 0 ;
570  daq_dta *dd ;
571 
572  if(strcasestr(do_print,"l4")) ; // leave as is...
573  else do_print = 0 ;
574 
575  for(int s=1;s<=24;s++) {
576  dd = rdr->det("l4")->get("tpx",s) ;
577  while(dd && dd->iterate()) {
578  found = 1 ;
579  if(do_print) {
580  printf("L4 TPX sec %02d: bytes %d\n",dd->sec,dd->ncontent) ;
581  }
582  }
583  }
584 
585  dd = rdr->det("l4")->get("trg") ;
586  while(dd && dd->iterate()) {
587  found = 1 ;
588  if(do_print) {
589  printf("l4 TRG sec %02d: bytes %d\n",dd->sec,dd->ncontent) ;
590  }
591  }
592 
593  dd = rdr->det("l4")->get("tof") ;
594  while(dd && dd->iterate()) {
595  found = 1 ;
596  if(do_print) {
597  printf("l4 TOF sec %02d: bytes %d\n",dd->sec,dd->ncontent) ;
598  }
599  }
600 
601  dd = rdr->det("l4")->get("gl3") ;
602  while(dd && dd->iterate()) {
603  found = 1 ;
604  if(do_print) {
605  l4_gl3_t *h = (l4_gl3_t *) dd->Void ;
606  UINT32 *x = (UINT32 *)h->data;
607  printf("L4 GL3 sec %02d: bytes %d: %d %s [0x%08x 0x%08x 0x%08x 0x%08x]\n",dd->sec,dd->ncontent,h->bytes,h->name,x[0],x[1],x[2],x[3]) ;
608  printf("sizeof %ld offset %ld\n", sizeof(l4_gl3_t), (char *)h->data - (char *)h);
609  }
610  }
611 
612 
613 
614  return found ;
615 }
616 
617 static int tpx_doer(daqReader *rdr, const char *do_print)
618 {
619  int found = 0 ;
620  int adc_found = 0 ;
621  int cld_found = 0 ;
622  int ped_found = 0 ;
623  char s_mask[24] ;
624  u_int tot_pixels = 0 ;
625  daq_dta *dd ;
626  u_int sec_cou[24] ;
627 
628  memset(sec_cou,0,sizeof(sec_cou)) ;
629 
630  //tpx_rdo_override = 3 ;
631 
632  if(strcasestr(do_print,"tpx")) ; // leave as is...
633  else do_print = 0 ;
634 
635  // TPX
636  // it is better, more memory efficient, to call stuff sector by sector (if possible)
637 
638  memset(s_mask,0,sizeof(s_mask)) ;
639 
640  for(int s=1;s<=24;s++) {
641 
642  double adctb[100];
643  memset(adctb, 0, sizeof(adctb));
644 
645 /* stop using legacy, even in the example...
646  dd = rdr->det("tpx")->get("legacy",s) ; // uses tpc_t
647  while(dd && dd->iterate()) {
648  found = 1 ;
649 
650  struct tpc_t *tpc = (tpc_t *) dd->Void ;
651  if(do_print) {
652  int cls = 0 ;
653  for(int r=0;r<45;r++) {
654  cls += tpc->cl_counts[r] ;
655  }
656 
657  printf("TPX: sec %02d (as legacy): %d pixels, %d clusters\n",dd->sec,tpc->channels_sector,cls) ;
658  }
659 
660  }
661 */
662 
663  int pcount = 0;
664  int pixel_count[46] ; // as an example we'll count pixels per row
665  memset(pixel_count,0,sizeof(pixel_count)) ;
666  int sec_found = 0 ;
667 
668  dd = rdr->det("tpx")->get("adc",s) ;
669  if(dd) {
670  while(dd->iterate()) {
671  found = 1 ; // any sector...
672  sec_found = 1 ;
673  adc_found = 1 ; // any sector...
674 
675  //if(dd->row > 8) continue ;
676 
677  if(do_print) {
678  printf("TPX: sec %02d, row %2d, pad %3d: %3d pixels\n",dd->sec,dd->row,dd->pad,dd->ncontent) ;
679  }
680 
681  pixel_count[dd->row] += dd->ncontent ;
682  pcount += dd->ncontent;
683 
684  int seq = 0 ;
685  int last_tb = -1 ;
686  int first_i = 0 ;
687 
688  for(u_int i=0;i<dd->ncontent;i++) {
689  int tb = dd->adc[i].tb ;
690  int adc = dd->adc[i].adc ;
691 
692  if(tb < 100) {
693  adctb[tb] += adc;
694  }
695 
696  if(adc > 80) {
697  //printf("ADC %d: tb %d, last_tb %d: seq %d\n",adc,tb,last_tb,seq) ;
698  if(seq==0) first_i = i ;
699 
700  if(tb==(last_tb-1)) {
701  seq++ ;
702  if(seq>=5) {
703  //printf("%d %d %d %d %d\n",good,dd->row,dd->pad,dd->adc[i].tb,dd->adc[i].adc) ;
704  }
705  }
706  else {
707  if(seq>=5 && (dd->adc[first_i].tb<30)) {
708  for(u_int j=first_i;j<i;j++) {
709  //printf("%d %d %d %d %d\n",good,dd->row,dd->pad,dd->adc[j].tb,dd->adc[j].adc) ;
710  }
711  }
712  seq = 0 ;
713  }
714  }
715  else {
716  if(seq>=5 && (dd->adc[first_i].tb<30)) {
717  for(u_int j=first_i;j<i;j++) {
718  //printf("%d %d %d %d %d\n",good,dd->row,dd->pad,dd->adc[j].tb,dd->adc[j].adc) ;
719  }
720  }
721 
722  seq = 0 ;
723  }
724 
725  last_tb = tb ;
726  }
727 
728 #if 1
729  for(u_int i=0;i<dd->ncontent;i++) {
730  if(do_print) {
731  printf("%d %d %d %d %d\n",dd->sec,dd->row,dd->pad,dd->adc[i].tb,dd->adc[i].adc) ;
732  //printf("\ttb %3d = %4d ADC\n",dd->adc[i].tb, dd->adc[i].adc) ;
733  }
734  }
735 #endif
736  }
737 
738 
739  if(sec_found) {
740 
741  s_mask[dd->sec-1]=1 ;
742  //if(0) {
743  if(do_print) {
744 
745  for(int row=0;row<=45;row++) {
746  int max_cou = tpc_rowlen[row] * 400 ;
747  if(max_cou==0) max_cou = 1 ;
748  double occ = 100.0*(double)pixel_count[row]/(double)max_cou ;
749  printf("+sector %2d, row %2d: pixels %d, occupancy %.1f%%\n",s,row,pixel_count[row],occ) ;
750  }
751  }
752  }
753 
754 #ifdef JMLADC
755  if((rdr->seq > JMLEVTMIN) && (rdr->seq < JMLEVTMAX)) {
756  for(int i=0;i<100;i++) {
757  printf("%d %d %d %d %lf %d\n",
758  rdr->run,
759  rdr->seq,
760  s,
761  i,
762  adctb[i],
763  1);
764  }
765  }
766 
767 
768 #endif
769  }
770 
771  LOG(DBG,"Doing TPX get CLD, s %d",s) ;
772 
773  dd = rdr->det("tpx")->get("cld",s) ;
774  while(dd && dd->iterate()) {
775 
776  found = 1 ;
777  cld_found = 1 ;
778 
779  s_mask[dd->sec-1]=1 ;
780  sec_cou[dd->sec-1] += dd->ncontent ;
781 
782  if(do_print) {
783  printf("CLD: sec %02d, row %2d: %3d clusters (evt %d)\n",dd->sec,dd->row,dd->ncontent,good) ;
784  }
785 
786  tot_pixels += dd->ncontent ;
787 
788  for(u_int i=0;i<dd->ncontent;i++) {
789  if(do_print) {
790  int p1,p2,t1,t2 ;
791  int bad = 0 ;
792  p1 = dd->cld[i].p1 ;
793  p2 = dd->cld[i].p2 ;
794  t1 = dd->cld[i].t1 ;
795  t2 = dd->cld[i].t2 ;
796 
797  if(p1 > 200) bad = 1 ;
798  if(p2 > 200) bad = 1 ;
799  if(p2<p1) bad = 1 ;
800  if((p2-p1)>14) bad = 1 ;
801 
802  if(t1 > 1200) bad = 1 ;
803  if(t2 > 1200) bad = 1 ;
804  if(t2<t1) bad = 1 ;
805  if((t2-t1)>30) bad = 1 ;
806 
807  //if(bad) printf("BAD: ") ;
808  printf("\tpad %7.3f[%d,%d], time %7.3f[%d,%d], charge %5d, flags 0x%02X\n",
809  dd->cld[i].pad,dd->cld[i].p1,dd->cld[i].p2,
810  dd->cld[i].tb,dd->cld[i].t1,dd->cld[i].t2,
811  dd->cld[i].charge,dd->cld[i].flags) ;
812 
813  //printf("-%d %d %f %f %d\n",dd->sec,dd->row,dd->cld[i].pad,dd->cld[i].tb,dd->cld[i].charge) ;
814 
815  }
816  }
817  }
818 
819 #ifdef JMLSECSZ
820 
821  printf("%d %d %d %d %d %d\n",
822  rdr->run,
823  rdr->seq,
824  rdr->evt_time,
825  1,
826  s,
827  pcount);
828 
829 #endif
830 
831  // will only exist in token 0 of a pedestal run!
832  dd = rdr->det("tpx")->get("pedrms",s) ;
833  while(dd && dd->iterate()) {
834  found = 1 ;
835  ped_found = 1 ;
836 
837  s_mask[dd->sec-1]=1 ;
838 
839  if(do_print) {
840  printf("TPX: sec %02d, row %2d, pad %3d (%d pix)\n",dd->sec,dd->row,dd->pad,dd->ncontent) ;
841  daq_det_pedrms *ped = (daq_det_pedrms *)dd->Void ;
842  for(u_int tb=0;tb<dd->ncontent;tb++) {
843  printf(" tb %3d: ped %3d, rms %.2f\n",tb,ped[tb].ped,ped[tb].rms) ;
844  }
845  }
846  }
847 
848 #if 1
849  //new ALTRO bank, for a test
850  for(int r=1;r<=6;r++) {
851  dd = rdr->det("tpx")->get("altro",s,r) ;
852  while(dd && dd->iterate()) {
853  found = 1 ;
854  if(do_print) {
855  printf("TPX ALTRO: sec %02d, RDO %d: ALTRO %3d, ch %2d: %3d pixels\n",dd->sec,r,dd->row,dd->pad,dd->ncontent) ;
856  }
857  }
858  }
859 #endif
860 
861 
862  }
863 
864  char fstr[128] ;
865  fstr[0] = 0 ; // EOS marker...
866 
867  if(cld_found) {
868  strcat(fstr,"CLD ") ;
869 // for(int i=0;i<24;i++) {
870 // printf("%d 1 %d %d\n",good,i+1,sec_cou[i]) ;
871 // LOG(TERR,"TPX %d %d",i+1,sec_cou[i]) ;
872 // }
873  }
874  if(adc_found) {
875  strcat(fstr,"ADC " ) ;
876  }
877  if(ped_found) {
878  strcat(fstr,"PEDRMS ") ;
879  }
880 
881 
882  int s_cou = 0 ;
883  for(int s=0;s<24;s++) {
884  if(s_mask[s]) {
885  char stmp[8] ;
886  sprintf(stmp,"%d ",s+1) ;
887  strcat(fstr,stmp) ;
888  s_cou++ ;
889  }
890  }
891 
892  if(found) {
893  LOG(INFO,"TPX found [%s;%d]",fstr,s_cou) ;
894  }
895 
896 
897 
898 
899  return found ;
900 
901 }
902 
903 static int ftp_doer(daqReader *rdr, const char *do_print)
904 {
905  int found = 0;
906  daq_dta *dd;
907 
908  if(strcasestr(do_print,"ftp")) ; // leave as is...
909  else do_print = 0 ;
910 
911  dd = rdr->det("ftp")->get("legacy") ;
912 
913  while(dd && dd->iterate()) {
914  found++ ; // mark as found..
915  ftp_t *ftp = (ftp_t *) dd->Void ;
916 
917  if(do_print) {
918  printf("FTP sector %d: pixels %d\n",dd->sec,ftp->channels) ;
919 
920 
921  for(int ss=0;ss<2;ss++) {
922  for(int rb=0;rb<10;rb++) {
923  for(int pad=0;pad<960;pad++) {
924  for(int tbi=0;tbi<ftp->counts[ss][rb][pad];tbi++) {
925  printf("%d %d %d %d %d\n",
926  ss,rb,pad,
927  ftp->timebin[ss][rb][pad][tbi],
928  ftp->adc[ss][rb][pad][tbi]);
929  }
930  }
931  }
932  }
933  }
934  }
935 
936 
937  return found ;
938 }
939 
940 
941 static int tpc_doer(daqReader *rdr, const char *do_print)
942 {
943  int found = 0 ;
944  daq_dta *dd ;
945 
946  if(strcasestr(do_print,"tpc")) ; // leave as is...
947  else do_print = 0 ;
948 
949  // although it is possible to have all sectors of the TPC
950  // present in memory, it is better to do this sector-by-sector
951  // ala the old evpReader, due to the memory footprint
952  for(int s=1;s<=24;s++) {
953  dd = rdr->det("tpc")->get("legacy",s) ;
954 
955  while(dd && dd->iterate()) {
956  found++ ; // mark as found..
957  tpc_t *tpc = (tpc_t *) dd->Void ;
958 
959  if(do_print) {
960  printf("TPC sector %d: pixels %d\n",dd->sec,tpc->channels_sector) ;
961  for(int r=0;r<45;r++) {
962  for(int c=0;c<tpc->cl_counts[r];c++) {
963  printf("row %2d: pad %1.f, tb %.1f, charge %d\n",r+1,
964  tpc->cl[r][c].p,tpc->cl[r][c].t,tpc->cl[r][c].charge) ;
965  }
966  }
967  }
968 
969  // one can rerun the afterburner as well with:
970 
971  //daq_tpc *tpc_class = (daq_tpc *)rdr->det("tpc") ;
972  //int cl_found = tpc_class->fcfReader(dd->sec,0,0,tpc) ;
973  //LOG(NOTE,"TPC: rerun cluster finder: sector %d: found %d clusters",dd->sec,cl_found) ;
974  }
975  }
976 
977  return found ;
978 
979 
980 }
981 
982 
983 static int pmd_doer(daqReader *rdr, const char *do_print)
984 {
985  int found = 0 ;
986  daq_dta *dd ;
987 
988  if(strcasestr(do_print,"pmd")) ; // leave as is...
989  else do_print = 0 ;
990 
991  dd = rdr->det("pmd")->get("legacy") ;
992 
993  if(dd && dd->iterate()) {
994  struct pmd_t *pmd_p = (pmd_t *) dd->Void ;
995 
996  if(do_print) {
997  for(int crate=0;crate<2;crate++) {
998  printf("Crate %s: status %d, mode %d\n",crate==0?"Up":"Dn",pmd_p->status[crate],pmd_p->mode) ;
999 
1000  for(int c=0;c<PMD_CRAMS_MAX;c++) {
1001  for(int s=0;s<2;s++) {
1002  for(int ch=0;ch<PMD_CRAMS_CH_MAX;ch++) {
1003  printf(" CRAM %2d: side %d: ch %4d: adc %4d [ped %4.1f, rms %4.2f, thr %4.1f]\n",
1004  c,s,ch,
1005  pmd_p->adc[crate][c][s][ch],
1006  (double)pmd_p->ped[crate][c][s][ch]/16.0,
1007  (double)pmd_p->rms[crate][c][s][ch]/16.0,
1008  (double)pmd_p->thr[crate][c][s][ch]/16.0) ;
1009 
1010  }}}
1011  }
1012 
1013  }
1014 
1015  found = 1 ; // mark as found..
1016  }
1017 
1018  if(found) LOG(NOTE,"PMD legacy found") ;
1019 
1020  return found ;
1021 
1022 
1023 }
1024 
1025 static int bsmd_doer(daqReader *rdr, const char *do_print)
1026 {
1027  int found = 0 ;
1028  daq_dta *dd ;
1029 
1030  int raw_found = 0 ;
1031  int adc_non_zs_found = 0 ;
1032  int adc_found = 0 ;
1033  int ped_found = 0 ;
1034 
1035  if(strcasestr(do_print,"bsmd")) ; // leave as is...
1036  else do_print = 0 ;
1037 
1038 
1039  // do I see the non-zero-suppressed bank? let's do this by fiber...
1040  for(int f=1;f<=12;f++) {
1041  dd = rdr->det("bsmd")->get("raw",0,f) ; // sector is ignored (=0)
1042  if(dd) {
1043  while(dd->iterate()) {
1044  found = 1 ;
1045  raw_found = 1 ;
1046 
1047  if(do_print) printf("BSMD RAW: fiber %2d [==%d], sector %d:\n",dd->rdo,f,dd->sec) ;
1048 
1049  // just the header
1050  for(int i=0;i<10;i++) {
1051  if(do_print) printf(" Head %2d = %08X\n",i,dd->Int32[i]) ;
1052  }
1053  }
1054  }
1055  }
1056 
1057 
1058  // do I see the non-zero-suppressed bank? let's do this by fiber...
1059  for(int f=1;f<=12;f++) {
1060  dd = rdr->det("bsmd")->get("adc_non_zs",0,f) ; // sector is ignored (=0)
1061  if(dd) {
1062  while(dd->iterate()) {
1063  found = 1 ;
1064  adc_non_zs_found = 1 ;
1065 
1066  bsmd_t *d = (bsmd_t *) dd->Void ;
1067 
1068  if(do_print) printf("BSMD non-ZS: fiber %2d, capacitor %d:\n",dd->rdo,d->cap) ;
1069 
1070 
1071  for(int i=0;i<BSMD_DATSIZE;i++) {
1072  if(do_print) printf(" %4d = %4d\n",i,d->adc[i]) ;
1073  }
1074  }
1075  }
1076  }
1077 
1078  // do I see the zero suppressed bank?
1079  for(int f=1;f<=12;f++) {
1080  dd = rdr->det("bsmd")->get("adc",0,f) ;
1081  if(dd) {
1082  while(dd->iterate()) {
1083  found = 1 ;
1084  adc_found = 1 ;
1085 
1086  bsmd_t *d = (bsmd_t *) dd->Void ;
1087 
1088  if(do_print) printf("BSMD ZS: fiber %2d, capacitor %d:\n",dd->rdo,d->cap) ;
1089 
1090  for(int i=0;i<BSMD_DATSIZE;i++) {
1091  // since this is zero-suppressed, I'll skip zeros...
1092  if(do_print) if(d->adc[i]) printf(" %4d = %4d\n",i,d->adc[i]) ;
1093  }
1094  }
1095  }
1096  }
1097 
1098  // do I see the pedestal bank?
1099  for(int f=1;f<=12;f++) {
1100  dd = rdr->det("bsmd")->get("ped",0,f) ;
1101  if(dd) {
1102  while(dd->iterate()) {
1103  found = 1 ;
1104  ped_found = 1 ;
1105 
1106  bsmd_t *d = (bsmd_t *) dd->Void ;
1107 
1108  if(do_print) printf("BSMD PED: fiber %2d, capacitor %d:\n",dd->rdo,d->cap) ;
1109 
1110  for(int i=0;i<BSMD_DATSIZE;i++) {
1111  if(do_print) printf(" %4d = %4d\n",i,d->adc[i]) ;
1112  }
1113  }
1114  }
1115  }
1116 
1117  // do I see the rms bank?
1118  for(int f=1;f<=12;f++) {
1119  dd = rdr->det("bsmd")->get("rms",0,f) ;
1120  if(dd) {
1121  while(dd->iterate()) {
1122  found = 1 ;
1123  ped_found = 1 ;
1124 
1125  bsmd_t *d = (bsmd_t *) dd->Void ;
1126 
1127  if(do_print) printf("BSMD RMS: fiber %2d, capacitor %d:\n",dd->rdo,d->cap) ;
1128 
1129  for(int i=0;i<BSMD_DATSIZE;i++) {
1130  if(do_print) printf(" %4d = %.2f\n",i,(double)d->adc[i]/8.0) ;
1131  }
1132  }
1133  }
1134  }
1135 
1136 
1137  char fstr[64] ;
1138  fstr[0] = 0 ; // EOS marker...
1139 
1140  if(raw_found) {
1141  strcat(fstr,"RAW ") ;
1142  }
1143 
1144  if(adc_found) {
1145  strcat(fstr,"ADC-ZS ") ;
1146  }
1147  if(adc_non_zs_found) {
1148  strcat(fstr,"ADC-non-ZS " ) ;
1149  }
1150  if(ped_found) {
1151  strcat(fstr,"PEDRMS ") ;
1152  }
1153 
1154  if(found) {
1155  LOG(INFO,"BSMD found [%s]",fstr) ;
1156  }
1157 
1158 
1159  return found ;
1160 }
1161 
1162 static int esmd_doer(daqReader *rdr, const char *do_print)
1163 {
1164  int found = 0 ;
1165  daq_dta *dd ;
1166 
1167  if(strcasestr(do_print,"esmd")) ; // leave as is...
1168  else do_print = 0 ;
1169 
1170 
1171  dd = rdr->det("esmd")->get("adc") ;
1172  if(dd) {
1173  while(dd->iterate()) {
1174  found = 1 ;
1175 
1176  esmd_t *d = (esmd_t *) dd->Void ;
1177 
1178  for(int i=0;i<ESMD_MAXFEE;i++) {
1179  for(int j=0;j<ESMD_PRESIZE;j++) {
1180  if(do_print) printf("ESMD: fee %2d: preamble %d: 0x%04X [%d dec]\n",i,j,d->preamble[i][j], d->preamble[i][j]) ;
1181  }
1182  for(int j=0;j<ESMD_DATSIZE;j++) {
1183  if(do_print) printf("ESMD: fee %2d: data %d: 0x%04X [%d dec]\n",i,j,d->adc[i][j], d->adc[i][j]) ;
1184  }
1185 
1186  }
1187  }
1188  }
1189 
1190  return found ;
1191 }
1192 
1193 static int etow_doer(daqReader *rdr, const char *do_print)
1194 {
1195  int found = 0 ;
1196  daq_dta *dd ;
1197 
1198  if(strcasestr(do_print,"etow")) ; // leave as is...
1199  else do_print = 0 ;
1200 
1201 
1202  dd = rdr->det("etow")->get("adc") ;
1203  if(dd) {
1204  while(dd->iterate()) {
1205  found = 1 ;
1206 
1207  etow_t *d = (etow_t *) dd->Void ;
1208 
1209  for(int i=0;i<ETOW_MAXFEE;i++) {
1210  for(int j=0;j<ETOW_PRESIZE;j++) {
1211  if(do_print) printf("ETOW: fee %2d: preamble %d: 0x%04X [%d dec]\n",i,j,d->preamble[i][j], d->preamble[i][j]) ;
1212  }
1213  for(int j=0;j<ETOW_DATSIZE;j++) {
1214  if(do_print) printf("ETOW: fee %2d: data %d: 0x%04X [%d dec]\n",i,j,d->adc[i][j], d->adc[i][j]) ;
1215  }
1216 
1217  }
1218  }
1219  }
1220 
1221  return found ;
1222 }
1223 
1224 static int btow_doer(daqReader *rdr, const char *do_print)
1225 {
1226  int found = 0 ;
1227  daq_dta *dd ;
1228 
1229  if(strcasestr(do_print,"btow")) ; // leave as is...
1230  else do_print = 0 ;
1231 
1232 /* generally commented out... */
1233 #if 0
1234  dd = rdr->det("btow")->get("raw") ;
1235  if(dd) {
1236  while(dd->iterate()) {
1237  u_short *s16 = (u_short *) dd->Void ;
1238 
1239  if(do_print) {
1240  printf("BTOW: bytes %d\n",dd->ncontent) ;
1241  }
1242 
1243  for(u_int i=0;i<dd->ncontent/2;i++) {
1244  if(do_print) {
1245  printf("%d: 0x%04X [%d dec]\n",i,s16[i],s16[i]) ;
1246  }
1247  }
1248  }
1249  }
1250 #endif
1251 
1252  dd = rdr->det("btow")->get("adc") ;
1253  if(dd) {
1254  while(dd->iterate()) {
1255  found = 1 ;
1256 
1257  btow_t *d = (btow_t *) dd->Void ;
1258 
1259  for(int i=0;i<BTOW_MAXFEE;i++) {
1260  for(int j=0;j<BTOW_PRESIZE;j++) {
1261  if(do_print) printf("BTOW: fee %2d: preamble %d: 0x%04X [%d dec]\n",i,j,d->preamble[i][j], d->preamble[i][j]) ;
1262  }
1263  for(int j=0;j<BTOW_DATSIZE;j++) {
1264  if(do_print) printf("BTOW: fee %2d: data %d: 0x%04X [%d dec]\n",i,j,d->adc[i][j], d->adc[i][j]) ;
1265  }
1266 
1267  }
1268  }
1269  }
1270 
1271  return found ;
1272 }
1273 
1274 #ifdef INSIST_ON_EMC_PSEUDO
1275 static int emc_pseudo_doer(daqReader *rdr, const char *do_print)
1276 {
1277  int found = 0 ;
1278  daq_dta *dd ;
1279 
1280  if(strcasestr(do_print,"emc_pseudo")) ; // leave as is...
1281  else do_print = 0 ;
1282 
1283 
1284  dd = rdr->det("emc_pseudo")->get("legacy") ;
1285  if(dd) {
1286  while(dd->iterate()) {
1287  found = 1 ;
1288 
1289  emc_t *d = (emc_t *) dd->Void ;
1290 
1291  if(do_print) printf("BTOW found %d (%d ch), BSMD found %d (%d ch), ETOW found %d (%d ch), ESMD found %d (%d ch)\n",
1292  d->btow_in, d->btow_ch, d->bsmd_in, d->bsmd_ch, d->etow_in, d->etow_ch, d->esmd_in, d->esmd_ch) ;
1293  }
1294  }
1295 
1296  return found ;
1297 
1298 }
1299 #endif
1300 
1301 
1302 static int pp2pp_doer(daqReader *rdr, const char *do_print)
1303 {
1304  int raw_found = 0 ;
1305  int adc_found = 0 ;
1306  int pedrms_found = 0 ;
1307  int adc_ped_sub_found = 0 ;
1308 
1309  daq_dta *dd ;
1310 
1311  if(strcasestr(do_print,"pp2pp")) ; // leave as is...
1312  else do_print = 0 ;
1313 
1314  dd = rdr->det("pp2pp")->get("raw") ;
1315  if(dd) {
1316  while(dd->iterate()) {
1317  raw_found++ ;
1318 
1319  if(do_print) {
1320  printf("PP2PP: RAW: sector %d, RDO %d, bytes %d\n",dd->sec,dd->rdo,dd->ncontent) ;
1321 
1322  u_int *d32 = (u_int *)dd->Void ;
1323  for(int i=0;i<16;i++) {
1324  printf(" %2d: 0x%08X\n",i,d32[i]) ;
1325 
1326  }
1327  }
1328 
1329  }
1330  }
1331 
1332 
1333  dd = rdr->det("pp2pp")->get("adc") ;
1334  if(dd) {
1335  while(dd->iterate()) {
1336  adc_found++ ;
1337 
1338  pp2pp_t *d = (pp2pp_t *) dd->Void ;
1339 
1340  if(do_print) {
1341  int cou = 0 ;
1342  for(int c=0;c<PP2PP_SVX_CH;c++) {
1343  if(d->trace[c]) cou++ ;
1344  }
1345 
1346  printf("PP2PP: sector %d, sequencer %d, chain %c, SVX %d: %d channels:\n",dd->sec,d->seq_id,'A'+d->chain_id,d->svx_id,cou) ;
1347  for(int c=0;c<PP2PP_SVX_CH;c++) {
1348  // print only found channels via the "trace" array
1349  if(d->trace[c]) printf(" ch %3d: ADC %3d [0x%02X], trace %d\n",c,d->adc[c],d->adc[c],d->trace[c]) ;
1350  //printf(" ch %3d: ADC %3d [0x%02X], trace %d\n",c,d->adc[c],d->adc[c],d->trace[c]) ;
1351  }
1352  }
1353 
1354  }
1355  }
1356 
1357  dd = rdr->det("pp2pp")->get("adc_ped_sub") ;
1358  if(dd) {
1359  while(dd->iterate()) {
1360  adc_ped_sub_found++ ;
1361 
1362  pp2pp_t *d = (pp2pp_t *) dd->Void ;
1363 
1364  if(do_print) {
1365  int cou = 0 ;
1366  for(int c=0;c<PP2PP_SVX_CH;c++) {
1367  if(d->trace[c]) cou++ ;
1368  }
1369 
1370  printf("PP2PP PED_SUB: sector %d, sequencer %d, chain %c, SVX %d: %d channels:\n",dd->sec,d->seq_id,'A'+d->chain_id,d->svx_id,cou) ;
1371 
1372  for(int c=0;c<PP2PP_SVX_CH;c++) {
1373  // print only found channels via the "trace" array
1374  if(d->trace[c]) printf(" ch %3d: ADC %3d [0x%02X], trace %d\n",c,d->adc[c],d->adc[c],d->trace[c]) ;
1375  //printf(" ch %3d: ADC %3d [0x%02X], trace %d\n",c,d->adc[c],d->adc[c],d->trace[c]) ;
1376  }
1377  }
1378 
1379  }
1380  }
1381 
1382  dd = rdr->det("pp2pp")->get("pedrms") ;
1383  if(dd) {
1384  while(dd->iterate()) {
1385  pedrms_found++ ;
1386 
1387  pp2pp_pedrms_t *d = (pp2pp_pedrms_t *) dd->Void ;
1388 
1389  if(do_print) {
1390  printf("PP2PP PEDRMS: sector %d, sequencer %d, chain %c, SVX %d: SVX pedestal %f +- %f\n",dd->sec,d->seq_id,'A'+d->chain_id,d->svx_id,
1391  d->svx_ped,d->svx_rms) ;
1392 
1393  for(int c=0;c<PP2PP_SVX_CH;c++) {
1394  printf(" ch %3d: ped %f, rms %f\n",c,d->ped[c],d->rms[c]) ;
1395  }
1396  }
1397 
1398  }
1399  }
1400 
1401  char fstr[256] ;
1402  fstr[0] = 0 ;
1403 
1404  if(raw_found) strcat(fstr,"RAW ") ;
1405  if(adc_found) strcat(fstr,"ADC ") ;
1406  if(adc_ped_sub_found) strcat(fstr,"ADC-PED-SUB ") ;
1407  if(pedrms_found) strcat(fstr,"PEDRMS ") ;
1408 
1409  int found = raw_found || adc_found || pedrms_found ;
1410 
1411  if(found) {
1412  LOG(INFO,"PP2PP found [%s]",fstr) ;
1413  }
1414 
1415  return found ;
1416 }
1417 
1418 static int l3_doer(daqReader *rdr, const char *do_print)
1419 {
1420  int found = 0 ;
1421  daq_dta *dd ;
1422 
1423  if(strcasestr(do_print,"l3")) ; // leave as is...
1424  else do_print = 0 ;
1425 
1426 
1427  dd = rdr->det("l3")->get("legacy") ;
1428  if(dd) {
1429  while(dd->iterate()) {
1430  found = 1 ;
1431 
1432  l3_t *l3_p = (l3_t *) dd->Void ;
1433 
1434  if(do_print) {
1435  printf("L3/HLT: sequence %u, decision 0x%X: tracks %d, clusters %d, vertex %f:%f:%f\n",
1436  l3_p->channels, l3_p->mode, // note comment in daq_l3.h!
1437  l3_p->tracks_num, l3_p->cluster_num,
1438  l3_p->xVertex, l3_p->yVertex, l3_p->xVertex) ;
1439 
1440 
1441  for(u_int i=0;i<l3_p->tracks_num;i++) {
1442  // just an example of what one would print out...
1443  printf(" track %d: Pt %f, charge %d, nHits %d\n",i+1,
1444  l3_p->track[i].pt, l3_p->track[i].q, l3_p->track[i].nHits) ;
1445 
1446  }
1447  }
1448 
1449  }
1450  }
1451 
1452  return found ;
1453 }
1454 
1455 static int fgt_doer(daqReader *rdr, const char *do_print, int which)
1456 {
1457  int found = 0 ;
1458  char s_found[128] ;
1459  daq_dta *dd ;
1460 
1461  const char *d_name = 0 ;
1462 
1463 
1464  switch(which) {
1465  case GMT_ID :
1466  d_name = "GMT" ;
1467  break ;
1468  case IST_ID :
1469  d_name = "IST" ;
1470  break ;
1471  case FST_ID :
1472  d_name = "FST" ;
1473  break ;
1474  case FGT_ID :
1475  default :
1476  d_name = "FGT" ;
1477  }
1478 
1479 
1480  if(strcasestr(do_print,d_name)) ; // leave as is...
1481  else do_print = 0 ;
1482 
1483  s_found[0] = 0 ;
1484 
1485  dd = rdr->det(d_name)->get("raw") ;
1486  if(dd) {
1487  while(dd->iterate()) {
1488  found |= 1 ;
1489 
1490  // point to the start of the DDL raw data
1491  u_int *d = (u_int *) dd->Void ;
1492 
1493 
1494  if(do_print) {
1495  printf("%s RAW: RDO %d:%d: %d bytes, %d words\n",d_name,dd->sec,dd->rdo,dd->ncontent,dd->ncontent/4) ;
1496  // dump a few ints
1497  for(int i=0;i<10;i++) {
1498  printf(" %3d: 0x%08X\n",i,d[i]) ;
1499  }
1500  }
1501 
1502  }
1503  }
1504 
1505 
1506  // one can get the data in the electronics/logical layout
1507  dd = rdr->det(d_name)->get("adc") ;
1508 
1509  // let's dump the meta-data first
1510  if(dd && dd->meta && do_print) {
1511  apv_meta_t *meta = (apv_meta_t *)dd->meta ;
1512 
1513  printf("%s meta data:\n",d_name) ;
1514  for(int r=1;r<=FGT_RDO_COU;r++) {
1515  if(meta->arc[r].present == 0) continue ;
1516 
1517  printf(" ARC %d: error %c; format %d, ARM mask 0x%X\n",r,meta->arc[r].error?'Y':'N',
1518  meta->arc[r].format_code,
1519  meta->arc[r].arm_mask) ;
1520 
1521  for(int arm=0;arm<FGT_ARM_COU;arm++) {
1522  if(meta->arc[r].arm[arm].present == 0) continue ;
1523 
1524  printf(" ARM %d: error %c\n",arm,meta->arc[r].arm[arm].error?'Y':'N') ;
1525  printf(" : arm_id %d, arm_seq %d, arm_err %d, apv_mask 0x%X\n",
1526  meta->arc[r].arm[arm].arm_id,
1527  meta->arc[r].arm[arm].arm_seq,
1528  meta->arc[r].arm[arm].arm_err,
1529  meta->arc[r].arm[arm].apv_mask) ;
1530 
1531  for(int apv=0;apv<FGT_APV_COU;apv++) {
1532  if(meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
1533 
1534  printf(" APV %2d: error %c\n",apv,meta->arc[r].arm[arm].apv[apv].error?'Y':'N') ;
1535  printf(" : apv_id %d, fmt %d, length %d, seq %d, capid %d, nhits %d, is_error %d, refadc %d, ntim %d\n",
1536  meta->arc[r].arm[arm].apv[apv].apv_id,
1537  meta->arc[r].arm[arm].apv[apv].fmt,
1538  meta->arc[r].arm[arm].apv[apv].length,
1539  meta->arc[r].arm[arm].apv[apv].seq,
1540  meta->arc[r].arm[arm].apv[apv].capid,
1541  meta->arc[r].arm[arm].apv[apv].nhits,
1542  meta->arc[r].arm[arm].apv[apv].is_error,
1543  meta->arc[r].arm[arm].apv[apv].refadc,
1544  meta->arc[r].arm[arm].apv[apv].ntim) ;
1545  }
1546  }
1547  }
1548 
1549  }
1550 
1551 
1552  while(dd && dd->iterate()) {
1553  found |= 2 ;
1554 
1555  fgt_adc_t *f = (fgt_adc_t *) dd->Void ;
1556 
1557 
1558  if(do_print) {
1559  printf("EVT %d: %s ADC: RDO %d, ARM %d, APV %d: %d values\n",good,d_name,dd->rdo,dd->sec,dd->pad,dd->ncontent) ;
1560 
1561  for(u_int i=0;i<dd->ncontent;i++) {
1562  printf(" %5d: ch %3d, tb %d = %3d\n",i,f[i].ch,f[i].tb,f[i].adc) ;
1563  }
1564  }
1565  }
1566 
1567 
1568 
1569 
1570 
1571 
1572  // one can get the data in the electronics/logical layout
1573  dd = rdr->det(d_name)->get("zs") ;
1574  if(dd) found |= 4 ;
1575 
1576  // let's dump the meta-data first
1577  if(dd && dd->meta && do_print) {
1578  apv_meta_t *meta = (apv_meta_t *)dd->meta ;
1579 
1580  printf("%s ZS meta data:\n",d_name) ;
1581  for(int r=1;r<=FGT_RDO_COU;r++) {
1582  if(meta->arc[r].present == 0) continue ;
1583 
1584  printf(" ARC %d: error %c; format %d, ARM mask 0x%X\n",r,meta->arc[r].error?'Y':'N',
1585  meta->arc[r].format_code,
1586  meta->arc[r].arm_mask) ;
1587 
1588  for(int arm=0;arm<FGT_ARM_COU;arm++) {
1589  if(meta->arc[r].arm[arm].present == 0) continue ;
1590 
1591  printf(" ARM %d: error %c\n",arm,meta->arc[r].arm[arm].error?'Y':'N') ;
1592  printf(" : arm_id %d, arm_seq %d, arm_err %d, apv_mask 0x%X\n",
1593  meta->arc[r].arm[arm].arm_id,
1594  meta->arc[r].arm[arm].arm_seq,
1595  meta->arc[r].arm[arm].arm_err,
1596  meta->arc[r].arm[arm].apv_mask) ;
1597 
1598  for(int apv=0;apv<FGT_APV_COU;apv++) {
1599  if(meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
1600 
1601  printf(" APV %2d: error %c\n",apv,meta->arc[r].arm[arm].apv[apv].error?'Y':'N') ;
1602  printf(" : apv_id %d, fmt %d, length %d, seq %d, capid %d, nhits %d, is_error %d, refadc %d, ntim %d\n",
1603  meta->arc[r].arm[arm].apv[apv].apv_id,
1604  meta->arc[r].arm[arm].apv[apv].fmt,
1605  meta->arc[r].arm[arm].apv[apv].length,
1606  meta->arc[r].arm[arm].apv[apv].seq,
1607  meta->arc[r].arm[arm].apv[apv].capid,
1608  meta->arc[r].arm[arm].apv[apv].nhits,
1609  meta->arc[r].arm[arm].apv[apv].is_error,
1610  meta->arc[r].arm[arm].apv[apv].refadc,
1611  meta->arc[r].arm[arm].apv[apv].ntim) ;
1612  }
1613  }
1614  }
1615 
1616  }
1617 
1618  int charge_sum = 0 ;
1619 
1620  while(dd && dd->iterate()) {
1621  found |= 4 ;
1622 
1623  fgt_adc_t *f = (fgt_adc_t *) dd->Void ;
1624 
1625  for(u_int i=0;i<dd->ncontent;i++) {
1626  if(f[i].adc > 0) {
1627  charge_sum += f[i].adc ;
1628  }
1629  }
1630 
1631 
1632  if(do_print) {
1633  printf("%s ZS: RDO %d, ARM %d, APV %d: %d values\n",d_name,dd->rdo,dd->sec,dd->pad,dd->ncontent) ;
1634 
1635  for(u_int i=0;i<dd->ncontent;i++) {
1636  printf(" %5d: ch %3d, tb %d = %3d (flags %d)\n",i,f[i].ch,f[i].tb,f[i].adc,f[i].flags) ;
1637  }
1638  }
1639  }
1640 
1641  if((found & 4) && do_print) {
1642  printf("+++ Charge sum %d\n",charge_sum) ;
1643  }
1644 
1645  dd = rdr->det(d_name)->get("pedrms") ;
1646  while(dd && dd->iterate()) {
1647  found |= 8 ;
1648 
1649  fgt_pedrms_t *f = (fgt_pedrms_t *) dd->Void ;
1650 
1651 
1652  if(do_print) {
1653  int arc = dd->rdo ;
1654  int arm = dd->sec ;
1655  int apv = dd->pad ;
1656 
1657  printf("%s PEDRMS: RDO %d, ARM %d, APV %d: %d values\n",d_name,dd->rdo,dd->sec,dd->pad,dd->ncontent) ;
1658 
1659  for(u_int i=0;i<dd->ncontent;i++) {
1660  printf("%d %d %2d %3d %2d: %.3f +- %.3f\n",arc,arm,apv,f[i].ch,f[i].tb,f[i].ped,f[i].rms) ;
1661  }
1662  }
1663 
1664 
1665 
1666  }
1667 
1668  if(found & 1) {
1669  strcat(s_found,"RAW ") ;
1670  }
1671  if(found & 2) {
1672  strcat(s_found,"ADC ") ;
1673  }
1674  if(found & 4) {
1675  strcat(s_found,"ZS ") ;
1676  }
1677  if(found & 8) {
1678  strcat(s_found,"PEDRMS ") ;
1679  }
1680 
1681  if(found) LOG(INFO,"%s found: %s",d_name,s_found) ;
1682 
1683  return found ;
1684 }
1685 
1686 static int mtd_doer(daqReader *rdr, const char *do_print)
1687 {
1688  int found = 0 ;
1689  daq_dta *dd ;
1690 
1691  if(strcasestr(do_print,"mtd")) ; // leave as is...
1692  else do_print = 0 ;
1693 
1694 
1695  // right now only the "raw" pointer is available/known
1696  dd = rdr->det("mtd")->get("raw") ;
1697  if(dd) {
1698  while(dd->iterate()) {
1699  found = 1 ;
1700 
1701  // point to the start of the DDL raw data
1702  u_int *d = (u_int *) dd->Void ;
1703 
1704 
1705  if(do_print) {
1706  printf("MTD: RDO %d: %d bytes\n",dd->rdo,dd->ncontent) ;
1707 
1708  for(u_int i=0;i<dd->ncontent/4;i++) {
1709  printf(" %2d: 0x%08X\n",i,d[i]) ;
1710  }
1711  }
1712 
1713  }
1714  }
1715 
1716  return found ;
1717 }
1718 
1719 
1720 
1721 
1722 // This is called by tinfo flag:
1723 
1724 int QtParse(int conf_num, TriggerDataBlk *trg, int *sz, int *internal_usecs, UINT64 *bx_time, UINT64 bx64) {
1725  *sz = 0;
1726  *internal_usecs = 0;
1727  if(trg->MainX[conf_num].offset == 0) {
1728  *sz = -1; *internal_usecs = -1; *bx_time = 0ll;
1729  return -1;
1730  }
1731 
1732  char *base = (char *)trg;
1733  QTBlock *qtb = (QTBlock *)(base + swap32(trg->MainX[conf_num].offset));
1734  int len = swap32(trg->MainX[conf_num].length);
1735  *sz = len;
1736 
1737  if((len - swap32(qtb->length)) != 12) {
1738  LOG(DBG, "Conf num %d not a QT board!", conf_num);
1739  *sz = -1;
1740  *internal_usecs = -1;
1741  *bx_time = 0ll;
1742  return -1;
1743  }
1744 
1745  // loop over boards
1746 
1747  if(swap32(qtb->length) > 0 ) {
1748  unsigned int *dword = (unsigned int *)qtb->data;
1749  for(;;) {
1750  unsigned int x = swap32(*dword);
1751  LOG(DBG, "x=0x%x", x);
1752  if(x == 0xac10) break;
1753 
1754  int addr = (x>>16) & 0xff;
1755  int nlines = x & 0xff;
1756  int usec = x & 0xff00;
1757  usec >>= 8;
1758  //usec *= 4; // Johns error...
1759 
1760  LOG(DBG, "addr=%d nlines=%d usec=%d", addr, nlines, usec);
1761 
1762  *internal_usecs += usec;
1763 
1764  while(nlines--) {
1765  dword++;
1766  }
1767  dword++;
1768  }
1769  }
1770 
1771  TrgSumData *trgSum = (TrgSumData *)(((char *)trg) + swap32(trg->Summary_ofl.offset));
1772 
1773  UINT64 tms = trgSum->LocalClocks[conf_num];
1774  if(tms) {
1775  while(tms < bx64) tms += 0xffffffffll;
1776  tms = tms - bx64;
1777  }
1778 
1779  *bx_time = tms;
1780  return conf_num;
1781 }
1782 
1783 
1784 static const char *confnum2str[] = {
1785  "rcc",
1786  "l1",
1787  "bc1",
1788  "mxq",
1789  "mix",
1790  "bcw",
1791  "bce",
1792  "eq3",
1793  "bbc",
1794  "bbq",
1795  "fms",
1796  "qt1",
1797  "qt2",
1798  "qt3",
1799  "qt4",
1800  "eq1",
1801  "eq2",
1802  "inf",
1803  NULL,
1804  NULL,
1805  NULL,
1806  NULL };
1807 
1808 
1809 
1810 int tinfo_fps(daqReader *rdr, UINT64 bx64) {
1811  UINT32 fpre_bx=0;
1812  UINT32 fpost_bx=0;
1813  UINT32 fpre_sz=0;
1814  UINT32 fpost_sz = 0;
1815  daq_dta *dd;
1816  dd = rdr->det("fps")->get("adc",1);
1817  if(dd) {
1818  fpre_bx = ((fps_evt_hdr_t *)(dd->meta))->reserved[1];
1819  fpre_sz = ((fps_evt_hdr_t *)(dd->meta))->words * 4;
1820  }
1821  dd = rdr->det("fps")->get("adc",2);
1822  if(dd) {
1823  fpost_bx = ((fps_evt_hdr_t *)(dd->meta))->reserved[1];
1824  fpost_sz = ((fps_evt_hdr_t *)(dd->meta))->words * 4;
1825  }
1826 
1827  // Get FPS timing...
1828  if(fpre_bx && fpost_bx)
1829  printf("%d %u %u %u %d %d 0x%llx #FPS seq bx fpre fpost fpresz fpostsz trg\n",
1830  rdr->seq,
1831  (UINT32)bx64, fpre_bx, fpost_bx, fpre_sz, fpost_sz, rdr->daqbits64_l1);
1832 
1833  return 0 ;
1834 }
1835 
1836 
1837 
1838 static int tinfo_doer(daqReader *rdr, const char *do_print)
1839 {
1840  int found = 0;
1841 
1842  printf("tinfo: seq = #%d (%s %d %d) token = %d detectors = 0x%x triggers = 0x%llx/0x%llx/0x%llx evpgroups=0x%x flags=0x%x freq=%f\n",
1843  rdr->seq,
1844  rdr->streaming_node,
1845  rdr->streaming_evb,
1846  rdr->streaming_seq,
1847  rdr->token,
1848  rdr->detectors,
1849  rdr->daqbits64_l1,
1850  rdr->daqbits64_l2,
1851  rdr->daqbits64,
1852  rdr->evpgroups,
1853  rdr->flags,
1854  rdr->triggerFrequency);
1855 
1856  daq_dta *dd;
1857  dd = rdr->det("trg")->get("raw") ;
1858  if(dd) {
1859  if(dd->iterate()) {
1860  found = 1;
1861  TriggerDataBlk *trg = (TriggerDataBlk *)dd->Byte;
1862 
1863 
1864 
1865  EvtDescData *evtDesc = (EvtDescData *)(((char *)trg) + swap32(trg->EventDesc_ofl.offset));
1866  int trgDetMask = swap16(evtDesc->trgDetMask);
1867  int pre = swap16(evtDesc->npre) & 0xF ;
1868  int post = swap16(evtDesc->npost) & 0xF;
1869  int res1 = swap16(evtDesc->res1);
1870  int trgCrateMask = (res1 & 0xfff0) << 20 | (swap16(evtDesc->npost) & 0xfff0) << 8 | (swap16(evtDesc->npre) & 0xfff0) >> 4;
1871  UINT32 bx_high = swap32(evtDesc->bunchXing_hi);
1872  UINT32 bx_low = swap32(evtDesc->bunchXing_lo);
1873  UINT64 bx64 = bx_high;
1874  bx64 = (bx64 << 32) + bx_low;
1875  float bx_sec = bx64/9.3e6;
1876  int bx7 = bx64 % 120;
1877 
1878  int addBits = swap16(evtDesc->addBits);
1879 
1880  int trg_tkn = swap16(evtDesc->TrgToken) ;
1881 
1882  if(addBits != 0) {
1883  printf("tinfo: token %d, pre %d, post %d, 0x%016llx 0x%04x\n",trg_tkn,pre,post, rdr->daqbits64, addBits) ;
1884  }
1885 
1886  int crate_sz[MAX_CONF_NUM];
1887  int crate_internal_usec[MAX_CONF_NUM];
1888  UINT64 crate_bx_time[MAX_CONF_NUM];
1889 
1890  for(int i=0;i<MAX_CONF_NUM;i++) {
1891  QtParse(i, trg, &crate_sz[i], &crate_internal_usec[i], &crate_bx_time[i], bx64);
1892  }
1893 
1894 
1895  int corrupt = 0;
1896  for(int i=0;i<MAX_CONF_NUM;i++) {
1897  if(crate_bx_time[i] > 0xffffll) {
1898  corrupt = 1;
1899 
1900  printf("CORRUPT evt %d: %s bxtime %lld %lld\n",
1901  rdr->seq,
1902  confnum2str[i],
1903  crate_bx_time[i],
1904  bx64);
1905  }
1906  }
1907 
1908  // seq, size, bx, bx % 120
1909  //printf("L4BUG: %d %d %lld %lld\n", rdr->seq, rdr->event_size, bx64, bx64 % 120);
1910 
1911  //printf("EvtDescData %d %d %d\n",evtDesc->tcuCtrBunch_hi,evtDesc->DSMAddress,0) ;
1912 
1913 
1914  //TrgSumData *trgSum = (TrgSumData *)(((char *)trg) + swap32(trg->Summary_ofl.offset));
1915  L1_DSM_Data *l1Dsm = (L1_DSM_Data *)(((char *)trg) + swap32(trg->L1_DSM_ofl.offset));
1916 
1917 
1918  printf("l1Dsm offset %d\n",swap32(trg->L1_DSM_ofl.offset)) ; // should NOT be 0!
1919 
1920  u_int bc2 = swap16(l1Dsm->BCdata[2]) ;
1921  u_int bc7bit = bc2 & 0x7F ;
1922 
1923  u_int lastdsm[8] ;
1924 
1925  for(int i=0;i<8;i++) {
1926 
1927  lastdsm[i] = swap16(l1Dsm->lastDSM[i]) ;
1928  printf(".... lastdsm[%d]: 0x%04X\n",i,lastdsm[i]) ;
1929  }
1930 
1931  // The first line is bit 10 in Hank's list counting from the top
1932  // of his list. This translates to my FCS bit 0.
1933  // And so on... look at the shifts (>>) in lastdsm[4] to get to
1934  // "Hank's bits". And note the mess...
1935  // On the right, in comments is Hank's name of the bit...
1936 
1937  u_int fcs2019 = (lastdsm[4] >> 10) & 1 ; // bit 0: REVTICKIN-4
1938  fcs2019 |= ((lastdsm[4] >> 5) & 1) << 1 ; // bit 1: FCSIN-0
1939  fcs2019 |= ((lastdsm[4] >> 7) & 1) << 2 ; // bit 2: FCSIN-1
1940  fcs2019 |= ((lastdsm[4] >> 8) & 1) << 3 ; // bit 3: FCSIN-2
1941  fcs2019 |= ((lastdsm[4] >> 9) & 1) << 4 ; // bit 4: FCSIN-3
1942  fcs2019 |= ((lastdsm[4] >> 12) & 1) << 5 ; // bit 5: FCSIN-4
1943  fcs2019 |= ((lastdsm[4] >> 13) & 1) << 6 ; // bit 6: FCSIN-5
1944  fcs2019 |= ((lastdsm[4] >> 14) & 1) << 7 ; // bit 7: FCSIN-6
1945  fcs2019 |= ((lastdsm[4] >> 15) & 1) << 8 ; // bit 8: FCSIN-7 -- never fires?
1946 
1947  u_int fcs2021 = lastdsm[5] ;
1948  printf("fcs2021 0x%04X\n",fcs2021) ;
1949 
1950  u_int fcs_main_2022 = lastdsm[2] ;
1951  u_int fcs_north_2022 = lastdsm[5] & 0xFF ;
1952  u_int fcs_south_2022 = lastdsm[5] >> 8 ;
1953 
1954  printf("fcs_2022: main 0x%04X, north 0x%02X, south 0x%02X\n",fcs_main_2022,fcs_north_2022,fcs_south_2022) ;
1955 
1956 
1957  printf("bc7bit %3d, fcs2019 0x%04X : 0x%04X 0x%04X 0x%04X 0x%04X\n",bc7bit,fcs2019,
1958  lastdsm[0],lastdsm[1],lastdsm[2],lastdsm[3]) ;
1959 
1960  printf("ids: ");
1961  for(int i=0;i<64;i++) {
1962  if(rdr->daqbits64 & (1ll << i)) {
1963  printf("{%d=%d}",i,rdr->getOfflineId(i));
1964  }
1965  }
1966  printf("\n") ;
1967 
1968  printf(" l1=0x%llx trgDetMask=0%x trgCrateMask=0x%x\n",rdr->daqbits64_l1,trgDetMask,trgCrateMask);
1969 
1970 
1971  for(int i=2;i<MAX_OFFLEN-1;i++) {
1972  if(swap32(trg->MainX[i].length)) {
1973 
1974  char *nm = (char *)trg + swap32(trg->MainX[i].offset);
1975  nm[4] =0 ;
1976  int *datasz = (int *)nm;
1977  datasz++;
1978 
1979 
1980  // if(confnum2str[i]) {
1981  printf("ids %2d: crate %s[%s](0x%x):\toffset=%d\tsize=%d\tdsize=%d\n",i,
1982  confnum2str[i],nm,
1983  1<<i,
1984  swap32(trg->MainX[i].offset),
1985  swap32(trg->MainX[i].length),
1986  swap32(*datasz));
1987  }
1988 
1989  }
1990  }
1991  }
1992 
1993 
1994  return found;
1995 }
1996 
1997 
1998 
1999 static int pxl_doer(daqReader *rdr, const char *do_print)
2000 {
2001  int found = 0 ;
2002  daq_dta *dd ;
2003 
2004  if(strcasestr(do_print,"pxl")) ; // leave as is...
2005  else do_print = 0 ;
2006 
2007 
2008  // right now only the "raw" pointer is available/known
2009  dd = rdr->det("pxl")->get("raw") ;
2010  if(dd) {
2011  while(dd->iterate()) {
2012  found = 1 ;
2013 
2014  // point to the start of the DDL raw data
2015  u_int *d = (u_int *) dd->Void ;
2016 
2017 
2018  if(do_print) {
2019  printf("PXL RAW: Sector %d, RDO %d: %d bytes (%d words)\n",dd->sec,dd->rdo,dd->ncontent,dd->ncontent/4) ;
2020  // dump a few
2021  int cou = dd->ncontent/4 ;
2022 
2023  if(cou > 30) cou = 30 ;
2024 
2025  for(int i=0;i<cou;i++) {
2026  printf(" %2d: 0x%08X\n",i,d[i]) ;
2027  }
2028  }
2029 
2030  }
2031  }
2032 
2033 
2034 
2035  return found ;
2036 }
2037 
2038 static int sst_doer(daqReader *rdr, const char *do_print)
2039 {
2040  int found = 0 ;
2041  daq_dta *dd ;
2042 
2043  if(strcasestr(do_print,"sst")) ; // leave as is...
2044  else do_print = 0 ;
2045 
2046 
2047 
2048  dd = rdr->det("sst")->get("raw") ;
2049  if(dd) {
2050  while(dd->iterate()) {
2051  found |= 1 ;
2052 
2053  // point to the start of the DDL raw data
2054  u_int *d = (u_int *) dd->Void ;
2055 
2056 
2057  if(do_print) {
2058  printf("SST RAW: Sector %d, RDO %d: %d bytes (%d words)\n",dd->sec,dd->rdo,dd->ncontent,dd->ncontent/4) ;
2059  // dump a few
2060  int cou = dd->ncontent/4 ;
2061 
2062  if(cou > 30) cou = 30 ;
2063 
2064  for(int i=0;i<cou;i++) {
2065  printf(" %2d: 0x%08X\n",i,d[i]) ;
2066  }
2067  }
2068 
2069  }
2070  }
2071 
2072 
2073  dd = rdr->det("sst")->get("adc") ;
2074  if(dd) {
2075  while(dd->iterate()) {
2076  found |= 2 ;
2077 
2078  daq_sst_data_t *sst = (daq_sst_data_t *)dd->Void ;
2079 
2080 
2081  if(do_print) {
2082 
2083  printf("SST ADC: Sector %d, RDO %d, fiber %d: %d ADCs\n",dd->sec,dd->rdo,dd->pad,dd->ncontent) ;
2084 
2085  for(u_int i=0;i<dd->ncontent;i++) {
2086  printf(" Strip %3d, hybrid %2d: %4d\n",sst[i].strip,sst[i].hybrid,sst[i].adc) ;
2087  }
2088  }
2089 
2090  }
2091  }
2092 
2093  dd = rdr->det("sst")->get("pedrms") ;
2094  if(dd) {
2095  while(dd->iterate()) {
2096  found |= 4 ;
2097 
2098  daq_sst_pedrms_t *sst = (daq_sst_pedrms_t *)dd->Void ;
2099 
2100 
2101  if(do_print) {
2102 
2103  printf("SST PEDRMS: Sector %d, RDO %d, fiber %d: %d vals\n",dd->sec,dd->rdo,dd->pad,dd->ncontent) ;
2104 
2105  for(u_int i=0;i<dd->ncontent;i++) {
2106  for(int h=0;h<SST_HYBRID_COU;h++) {
2107  for(int s=0;s<SST_STRIP_COU;s++) {
2108  printf(" ped %d, rms %.3f\n",sst->ped[h][s],(float)sst->rms[h][s]/16.0) ;
2109  }
2110  }
2111  }
2112  }
2113 
2114  }
2115  }
2116 
2117 
2118 
2119  char s_found[128] ;
2120  s_found[0] = 0 ;
2121 
2122  if(found & 1) {
2123  strcat(s_found,"RAW ") ;
2124  }
2125  if(found & 2) {
2126  strcat(s_found,"ADC ") ;
2127  }
2128  if(found & 4) {
2129  strcat(s_found,"PEDRMS ") ;
2130  }
2131 
2132  if(found) LOG(INFO,"SST: found %s",s_found) ;
2133 
2134  sst_test(rdr,1) ;
2135 
2136  return found ;
2137 }
2138 
2139 
2140 
2141 /* various test routines... typically used by Tonko only */
2142 static int fgt_test(daqReader *rdr, const char *do_print, int which)
2143 {
2144 //#define DO_FGT_TEST
2145 #ifdef DO_FGT_TEST
2146  fgtPed *ped = new fgtPed() ;
2147 
2148  ped->tb_cou_xpect = 9 ;
2149  ped->init(0x3F, which) ;
2150  ped->from_cache("/net/ist01/RTScache/pedestals.txt") ;
2151  ped->bad_from_cache() ;
2152  double perc_bad = ped->do_thresh(5.0,2) ;
2153 
2154  LOG(INFO,"IST: bad channels %.1f%%",perc_bad) ;
2155 #endif
2156  return 0 ;
2157 }
2158 
2159 static int sst_test(daqReader *rdr, int mode)
2160 {
2161 //#define DO_SST_TEST
2162 #ifdef DO_SST_TEST
2163  static sstPed *ped[2] ;
2164 
2165  LOG(TERR,"sst_test: mode %d",mode) ;
2166 
2167  if(ped[0]==0) {
2168  ped[0] = new sstPed() ;
2169  ped[0]->init(0x7) ;
2170  ped[0]->sector = 1 ;
2171 
2172  ped[1] = new sstPed() ;
2173  ped[1]->init(0x3) ;
2174  ped[1]->sector = 2 ;
2175 
2176  }
2177 
2178  if(mode==1) {
2179  daq_dta *dd = rdr->det("sst")->get("raw") ;
2180 
2181  LOG(NOTE,"Here") ;
2182 
2183  while(dd && dd->iterate()) {
2184  // this part works in non-ped runs
2185  ((daq_sst *)(rdr->det("sst")))->raw_to_adc_utility(dd->sec,dd->rdo,(char *)dd->Void,dd->ncontent/4,0,0) ;
2186 
2187 
2188  ped[dd->sec-1]->accum((char *)dd->Void, dd->ncontent, dd->rdo) ;
2189 
2190  LOG(NOTE,"Accum done") ;
2191 
2192  }
2193  }
2194  else {
2195  ped[0]->calc() ;
2196  ped[1]->calc() ;
2197 
2198  ped[0]->to_cache("/log",run_number) ;
2199  ped[1]->to_cache("/log",run_number) ;
2200  }
2201 
2202 #endif
2203  return 0 ;
2204 }
2205 
2206 
2207 
2208 static int fps_doer(daqReader *rdr, const char *do_print)
2209 {
2210  int adc_found = 0 ;
2211  int pedrms_found = 0 ;
2212 // const double cpu_clock = 2166872000.0 ;
2213  const double cpu_clock = 2166855000.0 ;
2214  daq_dta *dd ;
2215 
2216  if(strcasestr(do_print,"fps")) ; // leave as is...
2217  else do_print = 0 ;
2218 
2219 
2220  //to be able to get to the meta-data for both "sectors" (aka FPS & FPOST)
2221  //I need to make a specific loop!
2222  for(int sec=1;sec<=2;sec++) {
2223 
2224  dd = rdr->det("fps")->get("adc",sec) ;
2225 
2226  while(dd && dd->iterate()) { //per xing and per RDO
2227  adc_found |= 1 << (dd->sec - 1) ; //sector mask
2228 
2229 
2230  fps_adc_t *a = (fps_adc_t *)dd->Void ;
2231 
2232  if(do_print) {
2233  double occ = 100.0 * (double)dd->ncontent / (double)32 ;
2234 
2235  int sum = 0 ;
2236 
2237  for(u_int i=0;i<dd->ncontent;i++) {
2238  sum += a[i].adc ;
2239  }
2240 
2241  printf("FPS sector %d: xing %2d, QT %d, chs %d (occupancy %.2f %%, charge %d)\n",dd->sec,(char)dd->pad,dd->row,dd->ncontent,occ,sum) ;
2242 
2243 
2244 
2245 
2246  fps_evt_hdr_t *hdr = (fps_evt_hdr_t *)dd->meta ;
2247 
2248  //time of arrival of the STP command
2249  double stp = ((double) hdr->tick) * 1024.0 ; //in clocks
2250 
2251  stp /= cpu_clock ;
2252  stp *= 1000000.0 ;
2253 
2254  //time at the end of the full event readout
2255  double readout = ((double) (u_int) hdr->delta) * 1024.0 ;
2256 
2257  readout /= cpu_clock ;
2258  readout *= 1000000.0 ;
2259 
2260  double just_readout = ((double)(u_int) hdr->reserved[0]) * 1024.0 ;
2261  just_readout /= cpu_clock ;
2262  just_readout *= 1000000.0 ;
2263 
2264  u_int rcc_tick = hdr->reserved[1] ;
2265 
2266  printf("FPS Sector %d META: time of STP-arrival %.1f us, time of End-of-Readout %.1f us (delta %.1f us, just readout %.1f us), RCC tick %u, RCC delta %d\n",
2267  dd->sec,stp, readout, readout-stp, readout-just_readout, rcc_tick, rcc_tick-rcc_timestamp) ;
2268 
2269  for(u_int i=0;i<dd->ncontent;i++) {
2270  printf(" ch %2d: ADC %4d, TDC %2d\n",a[i].ch, a[i].adc, a[i].tdc) ;
2271  }
2272 
2273  }
2274 
2275  }
2276  }
2277 
2278 
2279  dd = rdr->det("fps")->get("pedrms") ;
2280  if(dd) {
2281  while(dd->iterate()) {
2282  pedrms_found = 1 ;
2283 
2284  fps_pedrms_t *ped = (fps_pedrms_t *) dd->Void ;
2285 
2286  if(do_print) {
2287  printf("FPS PEDRMS: Sector %d: QT %d\n",dd->sec,dd->rdo) ;
2288 
2289  for(int i=0;i<ped->ch_cou;i++) {
2290  printf(" ch %2d: %f +- %f (bad 0x%X)\n",i,
2291  ped->ped[i].ped,ped->ped[i].rms,ped->ped[i].flag) ;
2292  }
2293  }
2294 
2295  }
2296  }
2297 
2298 
2299  char fstr[256] ;
2300  fstr[0] = 0 ;
2301 
2302  if(adc_found & 1) strcat(fstr,"FPS-ADC ") ;
2303  if(adc_found & 2) strcat(fstr,"FPOST-ADC ") ;
2304 
2305  if(pedrms_found) strcat(fstr,"PEDRMS ") ;
2306 
2307  int found = 0 ;
2308  if(adc_found || pedrms_found) found = 1 ;
2309 
2310 
2311  if(found) {
2312  LOG(INFO,"FPS found: [%s]",fstr) ;
2313  }
2314 
2315  return found ;
2316 
2317 }
2318 
2319 static int rhicf_doer(daqReader *rdr, const char *do_print)
2320 {
2321  int found = 0 ;
2322  daq_dta *dd ;
2323 
2324  if(strcasestr(do_print,"rhicf")) ; // leave as is...
2325  else do_print = 0 ;
2326 
2327  dd = rdr->det("rhicf")->get("raw") ;
2328 
2329 
2330  if(dd) {
2331  while(dd->iterate()) { //per xing and per RDO
2332  found = 1 ;
2333 
2334  if(do_print) {
2335  printf("RHICF: %d bytes\n",dd->ncontent) ;
2336 
2337  for(int i=0;i<10;i++) {
2338  printf(" %d: 0x%08X\n",i,dd->Int32[i]) ;
2339  }
2340  }
2341 
2342  }
2343 
2344  }
2345 
2346 
2347  if(found) {
2348  LOG(INFO,"RHICF found") ;
2349  }
2350 
2351  return found ;
2352 
2353 }
2354 
2355 static int etof_doer(daqReader *rdr, const char *do_print)
2356 {
2357  int found = 0 ;
2358  daq_dta *dd ;
2359 
2360  if(strcasestr(do_print,"etof")) ; // leave as is...
2361  else do_print = 0 ;
2362 
2363  dd = rdr->det("etof")->get("raw") ;
2364 
2365 
2366  if(dd) {
2367  while(dd->iterate()) { //per xing and per RDO
2368  found = 1 ;
2369 
2370  if(do_print) {
2371  printf("ETOF: %d bytes\n",dd->ncontent) ;
2372 
2373  u_int words = dd->ncontent/4 ;
2374  if(words > 16) words = 16 ;
2375 
2376  for(u_int i=0;i<words;i++) {
2377  printf(" %d/%d: 0x%08X\n",i,dd->ncontent/4,dd->Int32[i]) ;
2378  }
2379  }
2380 
2381  }
2382 
2383  }
2384 
2385 
2386  if(found) {
2387  LOG(INFO,"ETOF found") ;
2388  }
2389 
2390  return found ;
2391 
2392 }
2393 
2394 static int itpc_doer(daqReader *rdr, const char *do_print)
2395 {
2396 
2397  int adc_found = 0 ;
2398  int cld_found = 0 ;
2399  int ped_found = 0 ;
2400  int clusters = 0 ;
2401  int pixels = 0 ;
2402 
2403  int sec[25] ;
2404 
2405  daq_dta *dd ;
2406 
2407  u_char rdos[4] ;
2408 
2409  memset(rdos,0,sizeof(rdos)) ;
2410 
2411  memset(sec,0,sizeof(sec)) ;
2412 
2413  if(strcasestr(do_print,"itpc")) ; // leave as is...
2414  else do_print = 0 ;
2415 
2416  for(int s=1;s<=24;s++) {
2417 
2418 #if 0
2419  dd = rdr->det("itpc")->get("raw",s) ;
2420 
2421  if(dd) {
2422  while(dd->iterate()) {
2423  adc_found = 1 ;
2424 
2425  rdos[dd->row-1] = 1 ;
2426 
2427 // det_raw_bytes[dd->rdo-1] += dd->ncontent ;
2428 
2429  if(do_print) {
2430  printf("ITPC RAW: %d: sector %2d, RDO %d: %d rawbytes\n",rdr->seq,dd->sec,dd->row,dd->ncontent) ;
2431 
2432  u_int *d32 = (u_int *)dd->Void ;
2433 
2434  for(u_int i=0;i<dd->ncontent/4;i++) {
2435  printf("%4d = 0x%08X\n",i,d32[i]) ;
2436  }
2437  }
2438  }
2439 // if(adc_found) det_events++ ;
2440  }
2441 #endif
2442 
2443 
2444 
2445 
2446 
2447 #if 0
2448  // In SAMPA form
2449  dd = rdr->det("itpc")->get("sampa",s) ;
2450  if(dd) {
2451  while(dd->iterate()) {
2452  adc_found = 1 ;
2453 
2454 
2455 
2456  if(do_print) {
2457  int rdo = (dd->row >> 4)+1;
2458  int port = (dd->row & 0xF)+1 ;
2459  int ch = (dd->pad) & 0xFF ;
2460  int fee_id = (dd->pad >> 8) ;
2461 
2462  if(dd->ncontent) printf("ITPC SAMPA: sector %2d, RDO %d, FEE #%02d (padplane %02d), CH %2d: %3d timebins\n",dd->sec,rdo,port,fee_id,ch,dd->ncontent) ;
2463 
2464  for(u_int i=0;i<dd->ncontent;i++) {
2465  printf("\ttb %3d = %4d ADC\n",dd->adc[i].tb,dd->adc[i].adc) ;
2466  }
2467  }
2468  }
2469  }
2470 #endif
2471 
2472 
2473 #if 1
2474  // In Row/Pad form
2475  double adctb[512];
2476  memset(adctb, 0, sizeof(adctb));
2477 
2478  dd = rdr->det("itpc")->get("adc",s) ;
2479  if(dd) {
2480  while(dd->iterate()) {
2481  adc_found = 1 ;
2482 
2483  pixels += dd->ncontent ;
2484 
2485 
2486 
2487  for(u_int i=0;i<dd->ncontent;i++) {
2488  adctb[dd->adc[i].tb] += dd->adc[i].adc;
2489  }
2490 
2491  if(do_print) {
2492  if(dd->ncontent) printf("ITPC ADC %d: sector %2d, row %2d, pad %3d: %3d timebins\n",rdr->seq,dd->sec,dd->row,dd->pad,dd->ncontent) ;
2493 
2494  for(u_int i=0;i<dd->ncontent;i++) {
2495  printf("\ttb %3d = %4d ADC\n",dd->adc[i].tb,dd->adc[i].adc) ;
2496 
2497  }
2498  }
2499  }
2500  }
2501 
2502 
2503 #ifdef JMLADC
2504  if((rdr->seq > JMLEVTMIN) && rdr->seq < JMLEVTMAX) {
2505  for(int i=0;i<100;i++) {
2506  printf("%d %d %d %d %lf %d\n",
2507  rdr->run,
2508  rdr->seq,
2509  s,
2510  i,
2511  adctb[i],
2512  0);
2513  }
2514  }
2515 #endif
2516 
2517 
2518 #endif
2519 
2520  // CLD data
2521  dd = rdr->det("itpc")->get("cld",s) ;
2522  if(dd) {
2523  while(dd->iterate()) {
2524  cld_found = 1 ;
2525 
2526  clusters += dd->ncontent ;
2527 
2528 
2529  sec[dd->sec] += dd->ncontent ;
2530 
2531  if(do_print) {
2532  printf("ITPC CLD: %d: sector %2d, row %2d: %3d clusters\n",rdr->seq,dd->sec,dd->row,dd->ncontent) ;
2533 
2534  for(u_int i=0;i<dd->ncontent;i++) {
2535  printf("\t%f %d %d %f %d %d %d 0x%X\n", dd->cld[i].pad,dd->cld[i].p1,dd->cld[i].p2,
2536  dd->cld[i].tb,dd->cld[i].t1,dd->cld[i].t2,
2537  dd->cld[i].charge,dd->cld[i].flags) ;
2538  }
2539 
2540  }
2541  }
2542  }
2543 
2544 
2545 
2546  // PEDESTALS
2547  dd = rdr->det("itpc")->get("pedrms",s) ;
2548  if(dd) {
2549  while(dd->iterate()) {
2550  ped_found = 1 ;
2551 
2552  if(do_print) {
2553  printf("ITPC PEDRMS: sector %2d, FEE %3d, CH %2d: %d content\n",dd->sec,dd->row,dd->pad,dd->ncontent) ;
2554  }
2555  }
2556  }
2557 
2558 
2559 
2560 
2561  }
2562 
2563 #if 0
2564  int adc_fy17_found = 0 ;
2565 
2566  dd = rdr->det("itpc")->get("ifee_fy17_sampa") ;
2567 
2568  if(dd) {
2569  while(dd->iterate()) { //per xing and per RDO
2570  adc_fy17_found = 1 ;
2571 
2572  if(do_print) {
2573  printf("ITPC: sector %2d, FEE %2d, ch %2d: pixels %3d\n",dd->sec,dd->row,dd->pad,dd->ncontent) ;
2574  for(u_int i=0;i<dd->ncontent;i++) {
2575  printf("\ttb %3d = %4d ADC\n",dd->adc[i].tb, dd->adc[i].adc) ;
2576  }
2577  }
2578 
2579  }
2580 
2581  }
2582 
2583  if(adc_fy17_found) {
2584  LOG(INFO,"ITPC-FY17 found") ;
2585  }
2586 #endif
2587 
2588  fflush(stdout) ; // just in case
2589 
2590  int found = 0 ;
2591  if(adc_found || cld_found || ped_found) found = 1 ;
2592 
2593 // int rdos_found = 0 ;
2594 // for(int i=0;i<4;i++) {
2595 // if(rdos[i]) rdos_found++ ;
2596 // }
2597 
2598  char fstr[128] ;
2599  fstr[0] = 0 ;
2600 
2601  if(adc_found) {
2602 
2603 #ifdef JMLSECSZ
2604  for(int i=1;i<=24;i++) {
2605  // run, seq, time, in/out, sector, size
2606  printf("%d %d %d %d %d %d\n",
2607  rdr->run,
2608  rdr->seq,
2609  rdr->evt_time,
2610  0,
2611  i,
2612  sec[i]);
2613  }
2614 
2615 #endif
2616 
2617  sprintf(fstr,"ADC ") ;
2618 
2619 // for(int i=1;i<=24;i++) {
2620 // LOG(TERR," %2d = %d",i,sec[i]) ;
2621 // }
2622  }
2623  if(cld_found) {
2624  strcat(fstr,"CLD ") ;
2625 // for(int i=1;i<=24;i++) {
2626 // printf("%d 2 %d %d\n",good,i,sec[i]) ;
2627 // LOG(TERR," %2d = %d",i,sec[i]) ;
2628 // }
2629  }
2630  if(ped_found) strcat(fstr,"PEDRMS ") ;
2631 
2632  if(found) {
2633  LOG(INFO,"ITPC found [%s] pixels %d, clusters %d",fstr,pixels,clusters) ;
2634 // for(int i=0;i<4;i++) {
2635 // LOG(TERR," RDO %d: ave words %.1f",i+1,det_raw_bytes[i]/det_events/4) ;
2636 // }
2637  }
2638 
2639 
2640  return found ;
2641 
2642 }
2643 
2644 static int fcs_doer(daqReader *rdr, const char *do_print)
2645 {
2646  int raw_found = 0 ;
2647  int zs_found = 0 ;
2648  int ped_found = 0 ;
2649 
2650  char want_adc = 0 ;
2651  char want_zs = 0 ;
2652  char want_ped = 0 ;
2653 
2654  daq_dta *dd ;
2655 
2656  if(strcasestr(do_print,"fcs")) ; // leave as is...
2657  else do_print = 0 ;
2658 
2659  if(print_mode==0) { // default
2660  want_adc = 1 ;
2661  want_zs = 1 ;
2662  want_ped = 1 ;
2663  }
2664 
2665  if(print_mode & 1) {
2666  want_adc = 1 ;
2667  }
2668  if(print_mode & 2) {
2669  want_zs = 1 ;
2670  }
2671 
2672  if(print_mode & 3) {
2673  want_ped = 1 ;
2674  }
2675 
2676  if(do_print) {
2677  printf("FCS evt %d, token %d\n",good,evp->token) ;
2678  }
2679 
2680  dd = rdr->det("fcs")->get("ped") ;
2681  while(dd && dd->iterate()) {
2682  struct fcs_data_c::fcs_ped_inline_t *p ;
2683 
2684  ped_found = 1 ;
2685 
2686  p = (fcs_data_c::fcs_ped_inline_t *)dd->Void ;
2687 
2688  if(do_print && want_ped) {
2689  printf("FCS PED: %d: S%02d:%d: %d:%d:%d (V%d)\n",good,dd->sec,dd->rdo,
2690  p->det,p->ns,p->dep,p->fmt_version) ;
2691 
2692  printf(" s1_delay %d\n",p->s1_delay) ;
2693 
2694  if(p->det<=2) { // pedestals
2695  for(int c=0;c<32;c++) {
2696  printf(" ch %02d: ped %6.3f, gain %6.3f\n",c,
2697  (double)p->ped[c].ped/8.0,(double)p->ped[c].gain/256.0) ;
2698  }
2699  }
2700  else {
2701  printf(" ch_mask 0x%llX, dsm_delay %d, dsm_mode %d, dsm_pattern 0x%04X\n",
2702  p->ch_mask,p->dsm_delay,p->dsm_mode,p->dsm_pattern) ;
2703  }
2704 
2705 
2706 
2707  }
2708 
2709  }
2710 #if 0
2711 
2712  dd = rdr->det("fcs")->get("raw") ;
2713 
2714 
2715  if(dd) {
2716  while(dd->iterate()) { //per xing and per RDO
2717  raw_found = 1 ;
2718 
2719  if(do_print) {
2720  u_short *d = (u_short *)dd->Void ;
2721  for(u_int i=0;i<dd->ncontent/2;i++) {
2722  printf("%d = 0x%04X\n",i,d[i]) ;
2723  }
2724  }
2725 
2726  }
2727 
2728  }
2729 #endif
2730 
2731  dd = rdr->det("fcs")->get("adc") ;
2732 
2733  if(dd) {
2734  while(dd->iterate()) { //per xing and per RDO
2735  raw_found = 1 ;
2736 
2737  if(do_print && want_adc) {
2738  int sector = ((dd->sec >> 11) & 0x1F)+1 ;
2739  int rdo = ((dd->sec >> 8) & 0x7)+1 ;
2740  int det = (dd->sec >> 6) & 0x3;
2741  int ns = (dd-> sec >> 5) & 1 ;
2742  int dep = dd->row ;
2743  int ch = dd->pad ;
2744 
2745  // prints out Sector, RDO, channel
2746  printf("FCS ADC %d: S%d:%d [det %d, ns %d, dep %d] ch %d, %d words\n",good,sector,rdo,det,ns,dep,ch,dd->ncontent) ;
2747  u_short *d16 = (u_short *)dd->Void ;
2748 
2749  for(u_int i=0;i<dd->ncontent;i++) {
2750  u_int flags = d16[i] >> 12 ;
2751  u_int data = d16[i] & 0xFFF ;
2752 
2753  if(det!=3) { // main
2754  printf(" %5d = 0x%X = %4u\n",i,flags,data) ;
2755  }
2756  else {
2757  printf(" %5d = 0x%X = 0x%04X\n",i,flags,data) ;
2758  }
2759  }
2760  }
2761 
2762  }
2763 
2764  }
2765 
2766  dd = rdr->det("fcs")->get("zs") ;
2767  if(dd) {
2768 // fcs_meta_t *meta = (fcs_meta_t *)dd->meta ;
2769 
2770  while(dd->iterate()) {
2771  zs_found = 1 ;
2772 
2773  int sector = ((dd->sec >> 11) & 0x1F)+1 ;
2774  int rdo = ((dd->sec >> 8) & 0x7)+1 ;
2775  int det = (dd->sec >> 6) & 0x3;
2776  int ns = (dd-> sec >> 5) & 1 ;
2777  int dep = dd->row ;
2778  int ch = dd->pad ;
2779 
2780 
2781  //LOG(TERR,"META: version 0x%X: sector %d:%d, rdo %d:%d",meta->version,meta->sector1,sector,meta->rdo1,rdo) ;
2782 
2783  if(do_print && want_zs) {
2784 
2785  printf("FCS ZS %d: S%d:%d [det %d, ns %d, dep %d] ch %d, %d ADCs\n",good,sector,rdo,det,ns,dep,ch,dd->ncontent) ;
2786 
2787  for(u_int i=0;i<dd->ncontent;i++) {
2788  if(det==3) {
2789  printf(" TB %5d, flags %d, ADC 0x%02X\n",dd->adc[i].tb,dd->adc[i].adc>>12,dd->adc[i].adc&0xFFF) ;
2790  }
2791  else {
2792  printf(" TB %5d, flags %d, ADC %4u\n",dd->adc[i].tb,dd->adc[i].adc>>12,dd->adc[i].adc&0xFFF) ;
2793  }
2794  }
2795  }
2796  }
2797  }
2798 
2799  char fstr[128] ;
2800  fstr[0] = 0 ;
2801 
2802 
2803 
2804  if(zs_found) {
2805  strcat(fstr,"ZS") ;
2806  }
2807 
2808  if(raw_found) {
2809  if(zs_found) strcat(fstr," ") ;
2810  strcat(fstr,"ADC") ;
2811  }
2812 
2813  if(ped_found) {
2814  strcat(fstr," PED") ;
2815  }
2816 
2817 
2818  if(raw_found || zs_found || ped_found) {
2819  LOG(INFO,"FCS found: %s",fstr) ;
2820  }
2821 
2822  return raw_found ;
2823 
2824 }
2825 
2826 static int stgc_doer(daqReader *rdr, const char *do_print)
2827 {
2828  int altro_found = 0 ;
2829  int vmm_found = 0 ;
2830 
2831  daq_dta *dd ;
2832 
2833  if(strcasestr(do_print,"stgc")) ; // leave as is...
2834  else do_print = 0 ;
2835 
2836 
2837 
2838 #if 0
2839  dd = rdr->det("stgc")->get("raw") ;
2840 
2841 
2842  if(dd) {
2843  while(dd->iterate()) { //per xing and per RDO
2844  altro_found = 1 ;
2845 
2846  if(do_print) {
2847  printf("STGC RAW: sec %02d, RDO %d: bytes %d\n",dd->sec,dd->rdo,dd->ncontent) ;
2848 
2849  //u_int *d = (u_int *)dd->Void ;
2850  //for(u_int i=0;i<dd->ncontent/4;i++) {
2851  // printf(" %d/%d = 0x%04X\n",i,dd->ncontent/4,d[i]) ;
2852  //}
2853  }
2854 
2855  }
2856 
2857  }
2858 #endif
2859 
2860 
2861 
2862  dd = rdr->det("stgc")->get("altro") ;
2863 
2864  ((daq_stgc *)rdr->det("stgc"))->xing_min = -65000 ;
2865  ((daq_stgc *)rdr->det("stgc"))->xing_max = 65000 ;
2866 
2867  while(dd && dd->iterate()) {
2868  altro_found = 1 ;
2869 
2870  if(do_print) {
2871  // there is NO RDO in the bank
2872  printf("STGC ALTRO: evt %d: sec %d, ALTRO %2d(FEE%02d):%02d\n",good,dd->sec,dd->row,dd->row/2,dd->pad) ;
2873 
2874  for(u_int i=0;i<dd->ncontent;i++) {
2875  printf(" %3d %3d\n",dd->adc[i].tb,dd->adc[i].adc) ;
2876  }
2877  }
2878  }
2879 
2880 
2881  dd = rdr->det("stgc")->get("vmm") ;
2882 
2883 // LOG(TERR,"min %d, max %d",((daq_stgc *)rdr->det("stgc"))->xing_min,((daq_stgc *)rdr->det("stgc"))->xing_max) ;
2884 
2885  while(dd && dd->iterate()) {
2886  vmm_found = 1 ;
2887 
2888 
2889  if(do_print) {
2890  // there is NO RDO in the bank
2891  printf("STGC VMM: evt %d: sec %d, RDO %d: hits %d\n",good,dd->sec,dd->rdo,dd->ncontent) ;
2892 
2893  struct stgc_vmm_t *vmm = (stgc_vmm_t *)dd->Void ;
2894  for(u_int i=0;i<dd->ncontent;i++) {
2895  u_char feb = vmm[i].feb_vmm >> 2 ; // feb [0..5]
2896  u_char vm = vmm[i].feb_vmm & 3 ; // VMM [0..3]
2897 
2898  printf(" FEB %d:%d [0x%X], ch %02d: ADC %3d, BCID %4d, tb %4d, BCID_delta %4d\n",feb,vm,vmm[i].feb_vmm,vmm[i].ch,
2899  vmm[i].adc,vmm[i].bcid,vmm[i].tb,vmm[i].bcid_delta) ;
2900  }
2901  }
2902  }
2903 
2904  if(altro_found || vmm_found) {
2905  char fstr[64] ;
2906 
2907  strcpy(fstr,"STGC found: ") ;
2908 
2909  if(altro_found) strcat(fstr,"ALTRO ") ;
2910  if(vmm_found) strcat(fstr,"VMM ") ;
2911 
2912  LOG(INFO,"%s",fstr) ;
2913  }
2914 
2915  return (altro_found || vmm_found) ;
2916 
2917 }
2918 
Definition: fgtPed.h:15
Definition: daq_l3.h:10
Definition: daq_l4.h:5
Definition: daq_tof.h:7
Definition: tof.h:15
Definition: rb.hh:21
Definition: daq_emc.h:52
Definition: daq_etow.h:9
Definition: daq_sc.h:6
Definition: daq_tpc.h:22
Definition: daq_btow.h:9
Definition: daq_trg.h:9
Definition: daq_pmd.h:7
Definition: sstPed.h:11
Definition: daq_ftp.h:4