9 #include <rtsSystems.h>
12 #include <DAQ_READER/daqReader.h>
13 #include <DAQ_READER/daq_dta.h>
15 #include <trgDataDefs.h>
19 #include <DAQ_BSMD/daq_bsmd.h>
20 #include <DAQ_BTOW/daq_btow.h>
21 #include <DAQ_EMC/daq_emc.h>
22 #include <DAQ_ESMD/daq_esmd.h>
23 #include <DAQ_ETOW/daq_etow.h>
24 #include <DAQ_TRG/daq_trg.h>
26 static int bsmd_doer(
daqReader *rdr,
const char *do_print) ;
27 static int esmd_doer(
daqReader *rdr,
const char *do_print) ;
28 static int btow_doer(
daqReader *rdr,
const char *do_print) ;
29 static int etow_doer(
daqReader *rdr,
const char *do_print) ;
30 static int trg_doer(
daqReader *rdr,
const char *do_print) ;
43 TH2F* etow[ETOW_MAXFEE];
44 TH2F* btow[BTOW_MAXFEE];
45 TH2F* bsmd[BSMD_FIBERS];
46 TH2F* bsmd_zs[BSMD_FIBERS];
47 TH2F* esmd[ESMD_MAXFEE];
53 int main(
int argc,
char *argv[])
56 char dir[FILENAME_MAX];
57 getcwd(dir,FILENAME_MAX);
63 const char *print_det =
"" ;
64 char _mountpoint[256];
65 char *mountpoint = NULL;
67 rtsLogOutput(RTS_LOG_STDERR) ;
68 rtsLogLevel((
char* )WARN) ;
70 while((c = getopt(argc, argv,
"D:d:m:h")) != EOF) {
79 mountpoint = _mountpoint;
80 strcpy(mountpoint, optarg);
91 evp->setEvpDisk(mountpoint);
100 int trigID[2]={2048,128};
101 int eventTrig[2]={0,0};
104 char *ret = evp->get(0,EVP_TYPE_ANY);
108 LOG(ERR,
"evp status is non-null [0x08X, %d dec]",evp->status,evp->status) ;
112 if(good%1000 == 0) LOG(INFO,
"%d good events processed",good);
115 switch(evp->status) {
119 LOG(DBG,
"End of Run/File");
121 LOG(DBG,
"Wait a second...");
128 LOG(WARN,
"Problem getting event - skipping [good %d, bad %d]",good,bad);
132 LOG(CRIT,
"evp->status CRITICAL (?)") ;
138 if(evp->status == EVP_STAT_EOR) {
139 LOG(INFO,
"End of File reached...%i good events processed",good) ;
140 LOG(INFO,
"bit %i = %i events processed",trigID[0],eventTrig[0]) ;
141 LOG(INFO,
"bit %i = %i events processed",trigID[1],eventTrig[1]) ;
145 if(evp->run == 0)
continue;
146 if(lastrun != evp->run){
147 printf(
"new run started\n");
154 printf(
"old file closed, deleted\n");
156 printf(
"hists cleared deleted\n");
159 printf(
"need to create new file\n");
160 string infile(argv[optind]);
163 if(infile.find(daq)!=string::npos){
164 string phys(
"st_physics");
166 size_t found = infile.find(phys);
167 if(found==string::npos)found=infile.find(w);
168 string base = infile.substr(found);
169 size_t fd = base.find(daq);
170 base.replace(fd,4,
"");
172 sprintf(name,
"%s/%s.ushist.root",dir,base.c_str());
174 sprintf(name,
"%s/%i.ushist.root",dir,evp->run);
177 outfile =
new TFile(name,
"RECREATE");
179 printf(
"new hists and file created\n");
186 bool goodTrig[2]={0,0};
189 unsigned int bits = evp->daqbits;
192 if(bits & trigID[0]) goodTrig[0]=1;
193 if(bits & trigID[1]) goodTrig[1]=1;
195 if(goodTrig[1]) eventTrig[1]++;
196 if(!goodTrig[0])
continue;
201 if(btow_doer(evp, print_det)) ;
205 if(etow_doer(evp, print_det)) ;
207 if(esmd_doer(evp, print_det)) ;
216 printf(
"old file closed, deleted\n");
218 printf(
"hists cleared deleted\n");
225 for(
int i = 0; i < ETOW_MAXFEE; i++){
228 sprintf(name,
"ETOW_%i",i+1);
229 sprintf(title,
"ETOW FEE %i",i+1);
230 etow[i] =
new TH2F(name,title,ETOW_DATSIZE,-0.5,ETOW_DATSIZE-0.5,4096,-0.5,4095.5);
232 for(
int i = 0; i < BTOW_MAXFEE; i++){
235 sprintf(name,
"BTOW_%i",i+1);
236 sprintf(title,
"BTOW FEE %i",i+1);
237 btow[i] =
new TH2F(name,title,BTOW_DATSIZE,-0.5,BTOW_DATSIZE-0.5,4096,-0.5,4095.5);
239 for(
int i = 0; i < ESMD_MAXFEE; i++){
242 sprintf(name,
"ESMD_%i",i+1);
243 sprintf(title,
"ESMD FEE %i",i+1);
244 esmd[i] =
new TH2F(name,title,ESMD_DATSIZE,-0.5,ESMD_DATSIZE-0.5,4096,-0.5,4095.5);
247 #if 0 //not using BSMD at the moment
248 for(
int i = 0; i < BSMD_FIBERS; i++){
251 sprintf(name,
"BSMD_%i",i+1);
252 sprintf(title,
"BSMD FIBER %i",i+1);
253 bsmd[i] =
new TH2F(name,title,BSMD_DATSIZE,-0.5,BSMD_DATSIZE-0.5,1024,-0.5,1023.5);
255 for(
int i = 0; i < BSMD_FIBERS; i++){
258 sprintf(name,
"BSMD_zs_%i",i+1);
259 sprintf(title,
"BSMD FIBER %i",i+1);
260 bsmd_zs[i] =
new TH2F(name,title,BSMD_DATSIZE,-0.5,BSMD_DATSIZE-0.5,1024,-0.5,1023.5);
272 for(
int i = 0; i < ETOW_MAXFEE; i++){
275 for(
int i = 0; i < BTOW_MAXFEE; i++){
278 for(
int i = 0; i < ESMD_MAXFEE; i++){
281 #if 0 //not using BSMD at the moment
282 for(
int i = 0; i < BSMD_FIBERS; i++){
288 static int trg_doer(
daqReader *rdr,
const char *do_print)
293 if(strcasestr(do_print,
"trg")) ;
298 dd = rdr->det(
"trg")->get(
"legacy") ;
304 printf(
"Trigger: daqbits 0x%08X, trg_word 0x%04X\n",trg_p->daqbits,trg_p->trg_word) ;
312 dd = rdr->det(
"trg")->get(
"raw") ;
318 u_char *trg_raw = dd->Byte;
330 desc = (simple_desc *) trg_raw ;
333 printf(
"Trigger: raw bank has %d bytes: ver 0x%02X, desc %d, len %d\n",dd->ncontent,desc->ver, desc->evt_desc, desc->len) ;
336 u_int *i32 = (u_int *) trg_raw ;
337 for(
int i=0;i<10;i++) {
338 printf(
"Trigger: word %d: 0x%08X\n",i,i32[i]) ;
347 #if 0 //not using BSMD at the moment
348 static int bsmd_doer(
daqReader *rdr,
const char *do_print)
353 if(strcasestr(do_print,
"bsmd")) ;
358 for(
int f=1;f<=12;f++) {
359 dd = rdr->det(
"bsmd")->get(
"adc_non_zs",0,f) ;
361 while(dd->iterate()) {
366 if(do_print) printf(
"BSMD non-ZS: fiber %2d, capacitor %d:\n",dd->rdo,d->cap) ;
369 for(
int i=0;i<BSMD_DATSIZE;i++) {
370 short cap = (short)d->cap;
371 if(cap!=124 && cap!=125)bsmd[f-1]->Fill(i,d->adc[i]);
372 if(do_print) printf(
" %4d = %4d\n",i,d->adc[i]) ;
379 for(
int f=1;f<=12;f++) {
380 dd = rdr->det(
"bsmd")->get(
"adc",0,f) ;
383 while(dd->iterate()) {
388 if(do_print) printf(
"BSMD ZS: fiber %2d, capacitor %d:\n",dd->rdo,d->cap) ;
390 for(
int i=0;i<BSMD_DATSIZE;i++) {
391 short cap = (short)d->cap;
392 if(cap!=124 && cap!=125 && d->adc[i]!=0)bsmd_zs[f-1]->Fill(i,d->adc[i]);
393 if(d->adc[i]!= 0)ngood++;
395 if(do_print)
if(d->adc[i]) printf(
" %4d = %4d\n",i,d->adc[i]) ;
400 printf(
"bsmd rdo %i had no hits in %i event %i\n",f,rdr->run,rdr->event_number);
409 static int esmd_doer(
daqReader *rdr,
const char *do_print)
414 if(strcasestr(do_print,
"esmd")) ;
418 dd = rdr->det(
"esmd")->get(
"adc") ;
420 while(dd->iterate()) {
425 for(
int i=0;i<ESMD_MAXFEE;i++) {
426 for(
int j=0;j<ESMD_PRESIZE;j++) {
427 if(do_print) printf(
"ESMD: fee %2d: preamble %d: 0x%04X [%d dec]\n",i,j,d->preamble[i][j], d->preamble[i][j]) ;
429 for(
int j=0;j<ESMD_DATSIZE;j++) {
430 esmd[i]->Fill(j,d->adc[i][j]);
431 if(do_print) printf(
"ESMD: fee %2d: data %d: 0x%04X [%d dec]\n",i,j,d->adc[i][j], d->adc[i][j]) ;
442 static int etow_doer(
daqReader *rdr,
const char *do_print)
447 if(strcasestr(do_print,
"etow")) ;
451 dd = rdr->det(
"etow")->get(
"adc") ;
453 while(dd->iterate()) {
458 for(
int i=0;i<ETOW_MAXFEE;i++) {
459 for(
int j=0;j<ETOW_PRESIZE;j++) {
460 if(do_print) printf(
"ETOW: fee %2d: preamble %d: 0x%04X [%d dec]\n",i,j,d->preamble[i][j], d->preamble[i][j]) ;
462 for(
int j=0;j<ETOW_DATSIZE;j++) {
463 etow[i]->Fill(j,d->adc[i][j]);
464 if(do_print) printf(
"ETOW: fee %2d: data %d: 0x%04X [%d dec]\n",i,j,d->adc[i][j], d->adc[i][j]) ;
474 static int btow_doer(
daqReader *rdr,
const char *do_print)
479 if(strcasestr(do_print,
"btow")) ;
483 dd = rdr->det(
"btow")->get(
"adc") ;
485 while(dd->iterate()) {
490 for(
int i=0;i<BTOW_MAXFEE;i++) {
491 for(
int j=0;j<BTOW_PRESIZE;j++) {
492 if(do_print) printf(
"BTOW: fee %2d: preamble %d: 0x%04X [%d dec]\n",i,j,d->preamble[i][j], d->preamble[i][j]) ;
494 for(
int j=0;j<BTOW_DATSIZE;j++) {
495 btow[i]->Fill(j,d->adc[i][j]);
496 if(do_print) printf(
"BTOW: fee %2d: data %d: 0x%04X [%d dec]\n",i,j,d->adc[i][j], d->adc[i][j]) ;