StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_pxl.cxx
1 #include <sys/types.h>
2 #include <errno.h>
3 #include <assert.h>
4 #include <stdlib.h>
5 
6 #include <rtsLog.h>
7 #include <rtsSystems.h>
8 
9 
10 
11 #include <SFS/sfs_index.h>
12 #include <DAQ_READER/daqReader.h>
13 #include <DAQ_READER/daq_dta.h>
14 
15 
16 #include "daq_pxl.h"
17 
18 
19 const char *daq_pxl::help_string = "PXL\n\
20 raw returns raw data\n" ;
21 
22 // for PXL proper
24 {
25 public:
27  daq_det_factory::det_factories[PXL_ID] = this ;
28  }
29 
30  daq_det *create() {
31  return new daq_pxl ;
32  }
33 } ;
34 
35 static daq_det_pxl_factory pxl_factory ;
36 
37 
38 daq_pxl::daq_pxl(daqReader *rts_caller)
39 {
40  rts_id = PXL_ID ;
41  name = rts2name(rts_id) ;
42  sfs_name = "pxl" ;
43  caller = rts_caller ;
44 
45  if(caller) caller->insert(this, rts_id) ;
46 
47  raw = new daq_dta ;
48 
49  LOG(DBG,"%s: constructor: caller %p",name,rts_caller) ;
50  return ;
51 }
52 
53 daq_pxl::~daq_pxl()
54 {
55  LOG(DBG,"%s: DEstructor",name) ;
56 
57  delete raw ;
58  return ;
59 }
60 
61 
62 
63 daq_dta *daq_pxl::get(const char *bank, int sec, int rdo, int pad, void *p1, void *p2)
64 {
65  Make() ;
66 
67  if(present == 0) return 0 ;
68 
69 
70  if(strcasecmp(bank,"raw")==0) {
71  return handle_raw(sec,rdo) ;
72  }
73 
74  LOG(ERR,"%s: unknown bank type \"%s\"",name,bank) ;
75  return 0 ;
76 }
77 
78 
79 
80 daq_dta *daq_pxl::handle_raw(int sec, int rdo)
81 {
82  char *st ;
83  int r_start, r_stop ;
84  int s_start, s_stop ;
85  int bytes ;
86 
87  assert(caller) ; // sanity...
88 
89  if(!present) {
90  return 0 ;
91  }
92  else {
93  LOG(DBG,"%s: present %d",name,present) ;
94  }
95 
96  char str[256] ;
97  char *full_name ;
98 
99 
100  if(sec<=0) {
101  s_start = 1 ;
102  s_stop = 2 ;
103  }
104  else {
105  s_start = s_stop = sec ;
106  }
107 
108  if(rdo<=0) {
109  r_start = 1 ;
110  r_stop = 5 ;
111  }
112  else {
113  r_start = r_stop = rdo ;
114  }
115 
116 
117  raw->create(8*1024,"pxl_raw",rts_id,DAQ_DTA_STRUCT(char)) ;
118 
119  for(int s=s_start;s<=s_stop;s++) {
120  for(int r=r_start;r<=r_stop;r++) {
121  sprintf(str,"%s/sec%02d/rb%02d/raw",sfs_name, s, r) ;
122  full_name = caller->get_sfs_name(str) ;
123 
124  if(!full_name) continue ;
125  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
126 
127 
128  st = (char *) raw->request(bytes) ;
129 
130  int ret = caller->sfs->read(str, st, bytes) ;
131  if(ret != bytes) {
132  LOG(ERR,"ret is %d") ;
133  }
134 
135 
136  raw->finalize(bytes,s,r,0) ;
137  }
138  }
139 
140  raw->rewind() ;
141 
142  return raw ;
143 
144 }
145 
146 
147 
148 
149 
150 
151 // used to grab trigger info from the event header
152 int daq_pxl::get_l2(char *buff, int words, struct daq_trg_word *trg, int rdo)
153 {
154  int t_cou = 0 ;
155  u_int *d32 = (u_int *)buff ;
156  u_int err = 0 ;
157  int last_ix = words - 1 ;
158  int token, daq_cmd, trg_cmd ;
159 
160  // quick sanity checks...
161  if(d32[0] != 0xAAAAAAAA) err |= 1 ; // header error
162  if(d32[last_ix] != 0xBBBBBBBB) err |= 2 ; // trailer error
163 // if((d32[1] & 0xFFF00000) != 0xCCC00000) err |= 8 ; // junk in trigger/daq/token
164  if((d32[1] & 0xFFF00000) != 0xC0000000) err |= 8 ; // junk in trigger/daq/token
165 
166  // special TCD-only event check
167 // if(d32[1] == 0xCCC0FFFF) {
168  if(d32[1] == 0xC000FFFF) {
169  LOG(NOTE,"RDO %d: trigger-only event...",rdo) ;
170  token = 4097 ;
171  daq_cmd = 0 ;
172  trg_cmd = 4 ;
173  }
174  else {
175 
176  token = d32[1] & 0xFFF ;
177  daq_cmd = (d32[1] & 0xF000) >> 12 ;
178  trg_cmd = (d32[1] & 0xF0000) >> 16 ;
179  }
180 
181  // more sanity
182  if(err || (token == 0)) {
183  token = 4097 ; // override with dummy token!
184  err |= 8 ;
185  }
186 
187  if(trg_cmd != 4) err |= 8 ;
188 
189  trg[t_cou].t = token ;
190  trg[t_cou].daq = daq_cmd ;
191  trg[t_cou].trg = trg_cmd ;
192  trg[t_cou].rhic = d32[7] ;
193  trg[t_cou].rhic_delta = 0 ;
194  t_cou++ ;
195 
196 
197  // get other trigger commands...
198  int last_p = last_ix - 1 ; // at CRC
199 
200  //u_int crc = d32[last_p] ;
201 
202 
203  last_p-- ; // at end of TCD info
204  int first_trg = -1 ;
205 
206  for(int i=last_p;i>=0;i--) {
207  if(d32[i] == 0xCCCCCCCC) { // trigger commands header...
208  first_trg = i + 1 ;
209  break ;
210  }
211  }
212 
213  if(first_trg > 0) { // found other trigger commands...
214  for(int i=first_trg;i<=last_p;i++) {
215  trg[t_cou].t = d32[i] & 0xFFF ;
216  trg[t_cou].daq = (d32[i] & 0xF000) >> 12 ;
217  trg[t_cou].trg = (d32[i] & 0xF0000) >> 16 ;
218  trg[t_cou].rhic = trg[0].rhic + 1 ; // mock it up...
219  trg[t_cou].rhic_delta = 0 ;
220 
221  switch(trg[t_cou].trg) {
222  case 0xF :
223  case 0xE :
224  case 0xD :
225  break ;
226  default :
227  continue ;
228  }
229 
230  t_cou++ ;
231 
232  if(t_cou >= 120) { // put a sanity limiter...
233  err |= 4 ;
234  break ;
235  }
236  }
237  }
238 
239  //err = t_cou ;
240  if(err) {
241  LOG(ERR,"RDO %d: error 0x%X, t_cou %d",rdo,err,t_cou) ;
242 
243  for(int i=0;i<16;i++) {
244  LOG(ERR," RDO %d: %2d/%2d: 0x%08X",rdo,i,words,d32[i]) ;
245  }
246 
247  int s = last_ix - 10 ;
248  if(s < 0) s = 0 ;
249 
250  for(int i=s;i<=last_ix;i++) {
251  LOG(ERR," RDO %d: %2d/%2d: 0x%08X",rdo,i,words,d32[i]) ;
252  }
253 
254 
255  }
256 
257 
258  return t_cou ;
259 
260 
261 }
262 
Definition: daq_pxl.h:8