StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daqFileHacker.C
1 //******************************************************
2 //*** Chops events out of .daq file
3 //***
4 //*** usage: daqFileChopper fn.daq arglist
5 //***
6 //*** arglist is passed to the function
7 //*** FilterEvent(), which returns true
8 //*** if the event is to be saved
9 //***
10 //*** output goes to standard out...
11 //*****************************************************
12 
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <getopt.h>
16 #include <sys/types.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <assert.h>
20 
21 #include <rtsLog.h> // for my LOG() call
22 #include <rtsSystems.h>
23 
24 #include <daqFormats.h>
25 #include <SFS/sfs_index.h>
26 
27 // this needs to be always included
28 #include <DAQ_READER/daqReader.h>
29 #include <DAQ_READER/daq_det.h>
30 #include <DAQ_READER/daq_dta.h>
31 #include <DAQ_BTOW/daq_btow.h>
32 #include <DAQ_L4/daq_l4.h>
33 #include <HLT/HLTFormats.h>
34 
35 
36 struct JmlSz {
37  int cld_pix;
38  int cld_cl;
39  UINT64 cld_adc;
40  int adc_pix;
41  UINT64 adc_adc;
42 
43  int invalid_count;
44 };
45 
46 
47 
48 int firsttm = 0;
49 
50 void initHack() {
51  firsttm = 0;
52 
53  printf("# tm, x, y, z, n, mb, hlt70, hlt150, hltall\n");
54 }
55 
56 // l4 hack!
57 void doHack(daqReader *rdr) {
58  daq_dta *dd = rdr->det("l4")->get("gl3");
59 
60  float x = -999;
61  float y = -999;
62  float z = -999;
63  int n = -999;
64 
65  while (dd && dd->iterate()) {
66  l4_gl3_t *h = (l4_gl3_t *)dd->Void;
67  //printf("L4: %s\n", h->name);
68 
69  if(strcmp(h->name, "HLT_EVE") == 0) {
70  HLT_EVE *eve = (HLT_EVE *)h->data;
71  x = eve->vertexX;
72  y = eve->vertexY;
73  z = eve->vertexZ;
74  }
75  if(strcmp(h->name, "HLT_PT") == 0) {
76  HLT_PT *pt = (HLT_PT *)h->data;
77  n = pt->nPrimaryTracks;
78  }
79  }
80 
81  if(firsttm == 0) firsttm = rdr->evt_time;
82 
83  int mb=0;
84  int hlt70 = 0;
85  int hlt150 = 0;
86  int hltall = 0;
87  if(rdr->daqbits64 & (1ll << 1)) mb = 1;
88  if(rdr->daqbits64 & (1ll << 12)) hlt70 = 1;
89  if(rdr->daqbits64 & (1ll << 13)) hlt150 = 1;
90  if(rdr->daqbits64 & (1ll << 14)) hltall = 1;
91 
92  if(x == -999) return;
93  if(!mb && !hlt70 && !hlt150 && !hltall) return;
94 
95  printf("%d %f %f %f %d %d %d %d %d\n", rdr->evt_time - firsttm, x, y, z, n, mb, hlt70, hlt150, hltall);
96 }
97 /*
98 void doHack(daqReader *rdr) {
99  struct JmlSz tpxSz;
100  struct JmlSz itpcSz;
101  int sz = 0;
102  UINT64 bx64 = 0;
103  int bx7 = 0;
104 
105 
106 
107  memset(&tpxSz, 0, sizeof(tpxSz));
108  memset(&itpcSz, 0, sizeof(itpcSz));
109  sz = rdr->event_size;
110 
111  // Only minbias events!
112  if((rdr->daqbits64 & (1ll << 1)) == 0) return;
113 
114  // get bx64
115  daq_dta *dd = rdr->det("trg")->get("raw");
116  if(dd) {
117  if(dd->iterate()) {
118  TriggerDataBlk *trg = (TriggerDataBlk *)dd->Byte;
119 
120  EvtDescData *evtDesc = (EvtDescData *)(((char *)trg) + swap32(trg->EventDesc_ofl.offset));
121  UINT32 bx_high = swap32(evtDesc->bunchXing_hi);
122  UINT32 bx_low = swap32(evtDesc->bunchXing_lo);
123  bx64 = bx_high;
124  bx64 = (bx64 << 32) + bx_low;
125  bx7 = bx64 % 120;
126  //printf("%llu %d\n", bx64, bx7);
127  }
128  }
129 
130 
131  for(int s=1;s<=24;s++) {
132 
133  // Get itpc ADC data
134  dd = rdr->det("itpc")->get("adc", s);
135  if(dd) {
136  while(dd->iterate()) {
137  for(int i=0;i<dd->ncontent;i++) {
138  itpcSz.adc_pix++;
139  itpcSz.adc_adc += dd->adc[i].adc;
140  }
141  }
142  }
143 
144  // Get itpc CLD data
145  dd = rdr->det("itpc")->get("cld", s);
146  if(dd) {
147  while(dd->iterate()) {
148  for(int i=0;i<dd->ncontent;i++) {
149  itpcSz.cld_cl++;
150  itpcSz.cld_adc += dd->cld[i].charge;
151 
152  if(dd->cld[i].t2 <= dd->cld[i].t1) {
153  itpcSz.invalid_count++;
154 
155  // printf("jjj itpc: sec=%d row=%d pad=%lf tb=%lf charge=%d (%d = %d)\n",
156  // s,
157  // dd->row,
158  // dd->cld[i].pad,
159  // dd->cld[i].tb,
160  // dd->cld[i].charge,
161  // dd->cld[i].t1,
162  // dd->cld[i].t2);
163  }
164  else {
165  itpcSz.cld_pix += dd->cld[i].t2 - dd->cld[i].t1 + 1;
166  }
167  }
168  }
169  }
170 
171 
172  // Get tpx ADC data
173  dd = rdr->det("tpx")->get("adc", s);
174  if(dd) {
175  while(dd->iterate()) {
176  for(int i=0;i<dd->ncontent;i++) {
177  tpxSz.adc_pix++;
178  tpxSz.adc_adc += dd->adc[i].adc;
179  }
180  }
181  }
182 
183  // Get tpx CLD data
184  dd = rdr->det("tpx")->get("cld", s);
185  if(dd) {
186  while(dd->iterate()) {
187  for(int i=0;i<dd->ncontent;i++) {
188  tpxSz.cld_cl++;
189  tpxSz.cld_adc += dd->cld[i].charge;
190  if(dd->cld[i].t2 <= dd->cld[i].t1) {
191  tpxSz.invalid_count++;
192  //printf("jjj tpx: sec=%d row=%d pad=%lf tb=%lf charge=%d (%d = %d)\n", s, dd->row, dd->cld[i].pad, dd->cld[i].tb, dd->cld[i].charge, dd->cld[i].t1, dd->cld[i].t2);
193  }
194  else {
195  tpxSz.cld_pix += dd->cld[i].t2 - dd->cld[i].t1 + 1;
196  }
197  }
198  }
199  }
200  }
201 
202  printf("%d %llu %d %d %llu %d %d %llu %d %d %llu %d %d %llu %d\n",
203  rdr->seq, //1
204  bx64, //2
205  bx7, //3
206  itpcSz.adc_pix, //4
207  itpcSz.adc_adc, //5
208  itpcSz.cld_cl, //6
209  itpcSz.cld_pix, //7
210  itpcSz.cld_adc, //8
211  itpcSz.invalid_count, // 9
212  tpxSz.adc_pix, //10
213  tpxSz.adc_adc, //11
214  tpxSz.cld_cl, //12
215  tpxSz.cld_pix, //13
216  tpxSz.cld_adc, //14
217  tpxSz.invalid_count); // 15
218 
219 }
220 */
221 
222 
223 void finishHack() {
224 }
225 
226 
227 
228 void displayHelp()
229 {
230  LOG(ERR,"Usage: daqFileHacker filename");
231 }
232 
233 int main(int argc, char *argv[])
234 {
235  rtsLogOutput(RTS_LOG_STDERR) ;
236  rtsLogLevel(WARN) ;
237 
238  if(argc < 2) {
239  displayHelp();
240  exit(0);
241  }
242 
243  initHack();
244 
245  for(int file=1;file<argc;file++) {
246  daqReader *evp;
247  evp = new daqReader(argv[file]) ; // create it with the filename argument..
248 
249  int good=0;
250  int bad=0;
251 
252  for(;;) {
253  char *ret = evp->get(0,EVP_TYPE_ANY);
254 
255  if(ret) {
256  if(evp->status) {
257  LOG(ERR,"evp status is non-null [0x08X, %d dec]",evp->status,evp->status) ;
258  continue ;
259  }
260  good++;
261  }
262  else { // something other than an event, check what.
263  switch(evp->status) {
264  case EVP_STAT_OK: // just a burp!
265  continue;
266  case EVP_STAT_EOR:
267  LOG(OPER, "Done after scanning %d events (%d bad)",good,bad);
268  break; // file, we're done...
269  case EVP_STAT_EVT:
270  bad++;
271  LOG(WARN, "Problem getting event - skipping [good %d, bad %d]",good,bad);
272  continue;
273  case EVP_STAT_CRIT:
274  LOG(CRIT,"evp->status CRITICAL (?)") ;
275  return -1;
276  }
277  }
278 
279  if(evp->status == EVP_STAT_EOR) {
280  LOG(INFO,"Done after scanning %d events (%d bad)",good,bad) ;
281  break;
282  }
283 
284  doHack(evp);
285  }
286 
287  delete evp;
288  }
289 
290  finishHack();
291  return 0 ;
292 }
Definition: daq_l4.h:5