StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_hlt.cxx
1 #include <sys/types.h>
2 #include <errno.h>
3 #include <assert.h>
4 
5 #include <rtsLog.h>
6 #include <rtsSystems.h>
7 
8 
9 
10 #include <SFS/sfs_index.h>
11 #include <DAQ_READER/daqReader.h>
12 #include <DAQ_READER/daq_dta.h>
13 
14 
15 #include "daq_hlt.h"
16 
17 
18 const char *daq_hlt::help_string = "HLT\n\
19 tpx returns TPX SL3;\n\
20 trg returns TRG SL3;\n" ;
21 
23 {
24 public:
26  daq_det_factory::pseudo_factories[L3_ID] = this ;
27  }
28 
29  daq_det *create() {
30  return new daq_hlt ;
31  }
32 } ;
33 
34 static daq_det_hlt_factory hlt_factory ;
35 
36 
37 daq_hlt::daq_hlt(daqReader *rts_caller)
38 {
39  rts_id = -L3_ID ; // note negative number!!!
40 
41  name = "hlt" ;
42  sfs_name = "hlt" ;
43  caller = rts_caller ;
44 
45  if(caller) {
46  caller->insert(this, rts_id) ;
47  }
48 
49  tpx = new daq_dta ;
50  tof = new daq_dta ;
51  trg = new daq_dta ;
52  gl3 = new daq_dta ;
53 
54  LOG(DBG,"%s: constructor: caller %p",name,rts_caller) ;
55  return ;
56 }
57 
58 daq_hlt::~daq_hlt()
59 {
60  LOG(DBG,"%s: DEstructor",name) ;
61 
62  delete tpx ;
63  delete tof ;
64  delete trg ;
65  delete gl3 ;
66 
67  return ;
68 }
69 
70 
71 
72 daq_dta *daq_hlt::get(const char *bank, int sec, int rdo, int pad, void *p1, void *p2)
73 {
74  Make() ;
75  if(present == 0) return 0 ;
76 
77 
78  if(strcasecmp(bank,"tpx")==0) {
79  return handle_tpx(sec) ;
80  }
81  else if(strcasecmp(bank,"trg")==0) {
82  return handle_trg() ;
83  }
84  else if(strcasecmp(bank,"tof")==0) {
85  return handle_tof() ;
86  }
87  else if(strncasecmp(bank,"gl3",3)==0) {
88  return handle_gl3(sec, bank) ;
89  }
90 
91 
92  LOG(ERR,"%s: unknown bank type \"%s\"",name,bank) ;
93  return 0 ;
94 }
95 
96 
97 
98 daq_dta *daq_hlt::handle_tpx(int sec)
99 {
100  char *st ;
101  int s_start, s_stop ;
102  int bytes ;
103 
104  assert(caller) ; // sanity...
105 
106  if(!present) {
107  LOG(ERR,"%s: not present?",name) ;
108  return 0 ;
109  }
110  else {
111  LOG(DBG,"%s: present %d",name,present) ;
112  }
113 
114  if(sec<=0) {
115  s_start = 1 ;
116  s_stop = 24 ;
117  }
118  else {
119  s_start = s_stop = sec ;
120  }
121 
122 
123  for(int s=s_start;s<=s_stop;s++) {
124  char str[256] ;
125  char *full_name ;
126 
127  sprintf(str,"%s/tpx/sec%02d/sl3",sfs_name, sec) ;
128  full_name = caller->get_sfs_name(str) ;
129 
130  if(!full_name) return 0 ;
131  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
132 
133  tpx->create(bytes,"hlt_tpx",rts_id,DAQ_DTA_STRUCT(char)) ;
134  st = (char *) tpx->request(bytes) ;
135 
136  int ret = caller->sfs->read(str, st, bytes) ;
137  if(ret != bytes) {
138  LOG(ERR,"ret is %d") ;
139  }
140 
141  tpx->finalize(bytes,s,1,0) ; // sector 1; rdo 1; pad irrelevant...
142  }
143 
144 
145  tpx->rewind() ;
146 
147  return tpx ;
148 
149 }
150 
151 daq_dta *daq_hlt::handle_trg()
152 {
153  char *st ;
154  int bytes ;
155 
156  assert(caller) ; // sanity...
157 
158  if(!present) {
159  LOG(ERR,"%s: not present?",name) ;
160  return 0 ;
161  }
162  else {
163  LOG(DBG,"%s: present %d",name,present) ;
164  }
165 
166  char str[256] ;
167  char *full_name ;
168 
169  sprintf(str,"%s/trg/sec%02d/sl3",sfs_name, 1) ;
170  full_name = caller->get_sfs_name(str) ;
171 
172  if(!full_name) return 0 ;
173  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
174 
175  trg->create(bytes,"hlt_trg",rts_id,DAQ_DTA_STRUCT(char)) ;
176  st = (char *) trg->request(bytes) ;
177 
178  int ret = caller->sfs->read(str, st, bytes) ;
179  if(ret != bytes) {
180  LOG(ERR,"ret is %d") ;
181  }
182 
183  trg->finalize(bytes,1,1,0) ; // sector 1; rdo 1; pad irrelevant...
184 
185  trg->rewind() ;
186 
187  return trg ;
188 
189 }
190 
191 daq_dta *daq_hlt::handle_tof()
192 {
193  char *st ;
194  int bytes ;
195 
196  assert(caller) ; // sanity...
197 
198  if(!present) {
199  LOG(ERR,"%s: not present?",name) ;
200  return 0 ;
201  }
202  else {
203  LOG(DBG,"%s: present %d",name,present) ;
204  }
205 
206  char str[256] ;
207  char *full_name ;
208 
209  sprintf(str,"%s/tof/sec%02d/sl3",sfs_name, 1) ;
210  full_name = caller->get_sfs_name(str) ;
211 
212  if(!full_name) return 0 ;
213  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
214 
215  tof->create(bytes,"hlt_tof",rts_id,DAQ_DTA_STRUCT(char)) ;
216  st = (char *) tof->request(bytes) ;
217 
218  int ret = caller->sfs->read(str, st, bytes) ;
219  if(ret != bytes) {
220  LOG(ERR,"ret is %d") ;
221  }
222 
223  tof->finalize(bytes,1,1,0) ; // sector 1; rdo 1; pad irrelevant...
224 
225  tof->rewind() ;
226 
227  return tof ;
228 
229 }
230 
231 daq_dta *daq_hlt::handle_gl3(int sec, const char *bank)
232 {
233  char *st ;
234  int bytes ;
235  int cou = 0 ;
236 
237  assert(caller) ; // sanity...
238 
239  if(!present) {
240  LOG(ERR,"%s: not present?",name) ;
241  return 0 ;
242  }
243  else {
244  LOG(DBG,"%s: sec %d, bank %s: present %d",name,sec,bank,present) ;
245  }
246 
247  char str[256] ;
248  char *full_name ;
249 
250  sprintf(str,"%s/gl3",sfs_name) ;
251  full_name = caller->get_sfs_name(str) ;
252 
253  LOG(DBG,"Trying 1: %s: got %s",str,full_name) ;
254 
255  if(!full_name) { // alternate, old form
256  sprintf(str,"%s/gl3/sec%02d",sfs_name, 1) ;
257  full_name = caller->get_sfs_name(str) ;
258 
259  LOG(DBG,"Trying 2: %s: got %s",str,full_name) ;
260  if(!full_name) return 0 ;
261  }
262 
263 
264  bytes = caller->sfs->fileSize(full_name) ; // this is bytes
265 
266  gl3->create(1024,"hlt_gl3",rts_id,DAQ_DTA_STRUCT(char)) ;
267 
268  fs_dir *dir = caller->sfs->opendir(full_name) ;
269  if(dir==0) return 0 ;
270 
271  fs_dirent *entry ;
272  while((entry = caller->sfs->readdir(dir))) {
273 
274  bytes = caller->sfs->fileSize(entry->full_name) ; // this is bytes
275  if(bytes == 0) {
276  LOG(WARN,"%s: 0 bytes?",entry->full_name) ;
277  continue ;
278  }
279 
280  cou++ ;
281 
282  LOG(DBG,"%d: %s %s %d",cou,entry->full_name,entry->d_name,bytes) ;
283 
284  st = (char *) gl3->request(bytes+sizeof(hlt_gl3_t)) ;
285 
286  ((hlt_gl3_t *)st)->buff = st + sizeof(hlt_gl3_t) ;
287  ((hlt_gl3_t *)st)->bytes = bytes ;
288  char *yada = ((hlt_gl3_t *)st)->name ;
289  strncpy(yada,entry->d_name,32) ;
290 
291 
292  int ret = caller->sfs->read(entry->full_name, st+sizeof(hlt_gl3_t), bytes) ;
293  if(ret != bytes) {
294  LOG(ERR,"ret is %d") ;
295  }
296 
297  gl3->finalize(bytes+sizeof(hlt_gl3_t),cou,1,0) ; // sector 1; rdo 1; pad irrelevant...
298 
299  }
300 
301  gl3->rewind() ;
302 
303  return gl3 ;
304 
305 }
306 
307 
308 
Definition: tof.h:15