StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_trg.cxx
1 #include <sys/types.h>
2 #include <string.h>
3 
4 #include <rtsLog.h>
5 #include <rtsSystems.h>
6 
7 #include <SFS/sfs_index.h>
8 #include <DAQ_READER/daqReader.h>
9 #include <DAQ_READER/daq_dta.h>
10 
11 
12 #include "daq_trg.h"
13 
14 
15 const char *daq_trg::help_string = "TRG tst\n" ;
16 
18 {
19 public:
21  daq_det_factory::det_factories[TRG_ID] = this ;
22  }
23 
24  daq_det *create() {
25  return new daq_trg ;
26  }
27 } ;
28 
29 static daq_det_trg_factory trg_factory ;
30 
31 
32 extern int trg_reader(char *m, struct trg_t *trg, u_int driver, u_int daqbits) ;
33 extern char *trg_find_raw(char *m, int *bytes);
34 
35 daq_trg::daq_trg(daqReader *rts_caller) : daq_det(rts_caller)
36 {
37  LOG(DBG,"TRG: rts_id %d, name %s, caller %p",rts_id,name,caller) ;
38 
39  // dname is ignored
40  rts_id = TRG_ID ;
41  name = rts2name(rts_id) ;
42  sfs_name = "trg" ;
43 
44  caller = rts_caller ;
45  if(caller) caller->insert(this, rts_id) ;
46 
47  legacy = new daq_dta ;
48  raw = new daq_dta ;
49 
50  LOG(DBG,"%s: constructor: caller %p",name,caller) ;
51 }
52 
53 daq_trg::~daq_trg()
54 {
55  LOG(DBG,"%s: destructor",name) ;
56 
57  delete legacy ;
58  delete raw ;
59 
60  return ;
61 }
62 
63 
64 daq_dta *daq_trg::get(const char *bank, int c1, int c2, int c3, void *p1, void *p2)
65 {
66  Make() ;
67  if(!present) return 0 ;
68 
69  if(strcmp(bank,"*")==0) bank = "legacy" ; // set default, if called with *
70 
71  if(strcasecmp(bank,"legacy") == 0) {
72  return handle_legacy() ;
73  }
74  else if(strcasecmp(bank,"raw") == 0) {
75  return handle_raw() ;
76  }
77  else {
78  LOG(ERR,"%s: unknown bank %s",name,bank) ;
79  }
80 
81  return 0 ;
82 
83 }
84 
85 
86 daq_dta *daq_trg::handle_legacy()
87 {
88 
89  if(!(present & DET_PRESENT_DATAP)) {
90  LOG(NOTE,"%s: can't have legacy without DATAP (post FY08), yet...",name) ;
91  return 0 ;
92  }
93 
94  // I need one object of trg_t type but let the create decide on the necessary size
95  legacy->create(1,"trg_t",rts_id,DAQ_DTA_STRUCT(trg_t)) ;
96 
97 
98  trg_t *trg_p = (trg_t *) legacy->request(1) ; // need ONE trg_t object
99 
100  // dabits hack...
101  trg_reader(caller->mem, trg_p, m_Debug,caller->daqbits) ;
102 
103 
104  trg_p->daqbits = caller->daqbits ;
105 
106  legacy->finalize(1,0,0,0) ; // 1 entry; sector 0, row 0, pad 0
107  legacy->rewind() ;
108 
109  return legacy ;
110 }
111 
112 daq_dta *daq_trg::handle_raw()
113 {
114  int err = 0 ;
115  int bytes = 0 ;
116  char *ptr = 0 ;
117  char str[256] ;
118  char *full_name ;
119  int ret ;
120 
121  if(present & DET_PRESENT_DATAP) { // old DATAP based
122  ptr = trg_find_raw(caller->mem, &bytes) ;
123 
124  LOG(DBG,"%s: raw from DATAP: %d bytes",name,bytes) ;
125 
126  if((ptr == 0) || (bytes == 0)) {
127  err = 1 ;
128  goto ret_error ;
129  }
130 
131 
132  raw->create(bytes,"trg_raw",rts_id,DAQ_DTA_STRUCT(char)) ;
133 
134  char *where = (char *) raw->request(bytes) ;
135  memcpy(where, ptr, bytes) ;
136 
137 
138 
139  }
140  else { // new SFS based
141  sprintf(str,"%s",sfs_name) ;
142  full_name = caller->get_sfs_name(str) ;
143 
144  if(!full_name) {
145  err = 2 ;
146  goto ret_error ;
147  }
148 
149  bytes = caller->sfs->fileSize(full_name) ;
150  if(bytes <= 0) {
151  err = 3 ;
152  goto ret_error ;
153  }
154 
155  LOG(DBG,"%s(%s): full_name %s, bytes %d",name,sfs_name,full_name,bytes) ;
156 
157  raw->create(bytes,"trg_raw",rts_id,DAQ_DTA_STRUCT(char)) ;
158 
159  ptr = (char *) raw->request(bytes) ;
160 
161  ret = caller->sfs->read(full_name, ptr, bytes) ;
162  if(ret != bytes) {
163  err = 3 ;
164  goto ret_error ;
165  }
166 
167  }
168 
169 
170  raw->finalize(bytes,0,0,0) ;
171  raw->rewind() ;
172  return raw ;
173 
174  ret_error:;
175 
176  LOG(ERR,"%s: handle_raw: error %d",name,err) ;
177  return 0 ;
178 }
Definition: daq_trg.h:9