StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_sc.cxx
1 #include <sys/types.h>
2 #include <string.h>
3 
4 #include <rtsLog.h>
5 #include <rtsSystems.h>
6 #include <daqFormats.h>
7 
8 #include <SFS/sfs_index.h>
9 #include <DAQ_READER/daqReader.h>
10 #include <DAQ_READER/daq_dta.h>
11 
12 #include "daq_sc.h"
13 
14 extern int sc_reader(char *m, struct sc_t *sc, u_int driver) ;
15 
16 
18 {
19 public:
21  //fprintf(stderr,"SC: inserting into factory\n") ;
22  daq_det_factory::det_factories[SC_ID] = this ;
23  }
24 
25  daq_det *create() {
26  //fprintf(stderr,"SC: creating\n") ;
27  return new daq_sc ;
28  }
29 } ;
30 
31 static daq_det_sc_factory sc_factory ;
32 
33 
34 
35 const char *daq_sc::help_string = "SC tst\n" ;
36 
37 
38 
39 daq_sc::daq_sc(daqReader *rts_caller) : daq_det(rts_caller)
40 {
41  LOG(DBG,"SC: rts_id %d, name %s",rts_id,name) ;
42 
43  // dname is ignored
44  rts_id = SC_ID ;
45  name = rts2name(rts_id) ;
46  sfs_name = "scd" ;
47 
48  caller = rts_caller ;
49 
50  if(caller) caller->insert(this, rts_id) ;
51 
52  legacy = new daq_dta ;
53  raw = new daq_dta ;
54 
55  LOG(DBG,"%s: constructor: caller %p",name,caller) ;
56 }
57 
58 daq_sc::~daq_sc()
59 {
60  LOG(DBG,"%s: destructor",name) ;
61 
62  delete legacy ;
63  delete raw ;
64 
65  return ;
66 }
67 
68 
69 daq_dta *daq_sc::get(const char *bank, int c1, int c2, int c3, void *p1, void *p2)
70 {
71  Make() ;
72  if(!present) return 0 ;
73 
74 
75  if(!bank || strcmp(bank,"*")==0) bank = "legacy" ; // set default, if called with *
76 
77  if(strcasecmp(bank,"legacy") == 0) {
78  return handle_legacy() ;
79  }
80  else if(strcasecmp(bank,"raw") == 0) {
81  return handle_raw() ;
82  }
83 
84  LOG(ERR,"%s: unknown bank %s",name,bank) ;
85  return 0 ;
86 
87 
88 }
89 
90 
91 daq_dta *daq_sc::handle_raw()
92 {
93  int err = 0 ;
94  char *local_store = 0 ;
95  int ret ;
96  char str[256] ;
97  char *full_name ;
98  int bytes ;
99 
100  if(!(present & DET_PRESENT_SFS)) return 0 ; // no SFS -> no raw
101 
102 
103 
104  sprintf(str,"%s",sfs_name) ;
105  full_name = caller->get_sfs_name(str) ;
106 
107  if(!full_name) {
108  err = 1 ;
109  goto ret_error ;
110  }
111 
112  bytes = caller->sfs->fileSize(full_name) ;
113  if(bytes <= 0) {
114  err = 2 ;
115  goto ret_error ;
116  }
117 
118  raw->create(bytes,"sc_raw",rts_id,DAQ_DTA_STRUCT(char)) ;
119 
120  local_store = (char *) raw->request(bytes) ;
121 
122  ret = caller->sfs->read(str, local_store, bytes) ;
123  if(ret != bytes) {
124  err = 3 ;
125  goto ret_error ;
126  }
127 
128 
129  raw->finalize(bytes,0,0,0) ;
130  raw->rewind() ;
131 
132  return raw ;
133 
134  ret_error:;
135 
136  LOG(ERR,"%s: handle_raw: error %d",name,err) ;
137  return 0 ;
138 
139 }
140 
141 daq_dta *daq_sc::handle_legacy()
142 {
143 
144  int err = 0 ;
145 
146 
147  // I need one object of sc_t type but let the create decide on the necessary size
148  legacy->create(1,"sc_t",rts_id,DAQ_DTA_STRUCT(sc_t)) ;
149 
150 
151  sc_t *sc_p = (sc_t *) legacy->request(1) ; // need ONE sc_t object
152 
153 
154  if(present & DET_PRESENT_DATAP) {
155  sc_reader(caller->mem, sc_p, m_Debug) ;
156  }
157  else { // SFS
158  daq_dta *dd = handle_raw() ;
159 
160  if(dd==0) {
161  err = 1 ;
162  goto ret_error ;
163  }
164 
165  dd->iterate() ; // do it once...
166 
167 
168  struct SCD *scd = (struct SCD *) dd->Void ;
169 
170  int swapit = 0 ;
171  if(scd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) { // swap
172  swapit = 1 ;
173  }
174 
175  LOG(DBG,"Need to swap SCD(sfs) %d?",swapit) ;
176 
177  sc_p->time = qswap32(swapit,scd->time) ;
178 
179  u_int tmp_f = qswap32(swapit,scd->mag_field) ;
180  memcpy(&(sc_p->mag_field),&tmp_f,4) ;
181 
182 
183  sc_p->timelag = 0 ; // I don't have DATAP! I can't tell the time difference!
184  sc_p->valid = 1 ; // what else can I say????
185 
186  for(u_int i=0;i<(sizeof(sc_p->rich_scalers)/4);i++) {
187  sc_p->rich_scalers[i] = qswap32(swapit, scd->rich_scalers[i]) ;
188  }
189 
190  }
191 
192  legacy->finalize(1,0,0,0) ; // 1 entry; sector 0, row 0, pad 0
193  legacy->rewind() ;
194 
195  return legacy ;
196 
197  ret_error :;
198 
199  LOG(ERR,"%s: handle_legacy: error %d",name,err) ;
200 
201  return 0 ;
202 }
Definition: daq_sc.h:20
Definition: daq_sc.h:6