StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
daq_emc.cxx
1 #include <sys/types.h>
2 #include <string.h>
3 
4 #include <rtsLog.h>
5 #include <rtsSystems.h>
6 
7 #include <DAQ_READER/daqReader.h>
8 #include <DAQ_READER/daq_dta.h>
9 
10 #include "daq_emc.h"
11 
12 #include <DAQ_BTOW/daq_btow.h>
13 #include <DAQ_ETOW/daq_etow.h>
14 #include <DAQ_ESMD/daq_esmd.h>
15 #include <DAQ_BSMD/daq_bsmd.h>
16 
17 const char *daq_emc::help_string = "EMC tst\n" ;
18 
20 {
21 public:
23  daq_det_factory::pseudo_factories[BTOW_ID] = this ;
24  }
25 
26  daq_det *create() {
27  return new daq_emc ;
28  }
29 } ;
30 
31 static daq_det_emc_factory emc_factory ;
32 
33 
34 
35 daq_emc::daq_emc(daqReader *rts_caller)
36 {
37  LOG(WARN,"Using EMC_LEGACY is deprecated! Rather use the specific readers: BTOW, BSMD, ETOW, ESMD") ;
38 
39  LOG(DBG,"EMC: rts_id %d, name %s",rts_id,name) ;
40 
41  // dname is ignored
42  rts_id = -BTOW_ID ; // watch it! this is ust here for show...
43  name = sfs_name = "emc_pseudo" ;
44  caller = rts_caller ;
45 
46  if(caller) caller->insert(this, rts_id) ;
47 
48  legacy = new daq_dta ;
49 
50  LOG(DBG,"%s: constructor: caller %p",name,caller) ;
51 }
52 
53 daq_emc::~daq_emc()
54 {
55  LOG(DBG,"%s: destructor",name) ;
56 
57  delete legacy ;
58 
59  return ;
60 }
61 
62 int daq_emc::Make()
63 {
64  return 0 ;
65 }
66 
67 daq_dta *daq_emc::get(const char *bank, int c1, int c2, int c3, void *p1, void *p2)
68 {
69 
70  if(strcmp(bank,"*")==0) bank = "legacy" ; // set default, if called with *
71 
72  if(strcasecmp(bank,"legacy") != 0) {
73  LOG(ERR,"%s: unknown bank %s",name,bank) ;
74  return 0 ;
75  }
76 
77  return handle_legacy() ;
78 
79 }
80 
81 
82 daq_dta *daq_emc::handle_legacy()
83 {
84  daq_dta *dd ;
85  int found_some = 0 ;
86 
87  // I need one object of emc_t type.
88  // It's ugly that I need to allocate memory before I know
89  // if the detectors are present but it would just get too
90  // ugly otherwise
91 
92  legacy->create(1,"emc_t",rts_id,DAQ_DTA_STRUCT(emc_t)) ;
93 
94  emc_t *emc_p = (emc_t *) legacy->request(1) ; // need ONE emc_t object
95 
96  memset(emc_p,0,sizeof(struct emc_t)) ; // must clear all
97 
98  emc_p->etow_max_ch = ETOW_MAXFEE * ETOW_DATSIZE ;
99  emc_p->btow_max_ch = BTOW_MAXFEE * BTOW_DATSIZE ;
100  emc_p->esmd_max_ch = ESMD_MAXFEE * ESMD_DATSIZE ;
101  emc_p->bsmd_max_ch = BSMD_FIBERS * BSMD_DATSIZE ;
102 
103  dd = caller->det("btow")->get("adc") ;
104  while(dd && dd->iterate()) {
105  found_some = 1 ;
106 
107 
108  emc_p->btow_in = 1;
109 
110  btow_t *d = (btow_t *) dd->Void ;
111 
112  for(int i=0;i<BTOW_MAXFEE;i++) {
113  for(int j=0;j<BTOW_PRESIZE;j++) {
114  emc_p->btow_pre[i][j] = d->preamble[i][j] ;
115  }
116  for(int j=0;j<BTOW_DATSIZE;j++) {
117  if(d->adc[i][j] > 0) emc_p->btow_ch++ ;
118  emc_p->btow_new[i][j] = d->adc[i][j] ;
119  }
120 
121  }
122 
123  }
124 
125  dd = caller->det("etow")->get("adc") ;
126  while(dd && dd->iterate()) {
127  found_some = 1 ;
128 
129  emc_p->etow_in = 1;
130 
131  etow_t *d = (etow_t *) dd->Void ;
132 
133  for(int i=0;i<ETOW_MAXFEE;i++) {
134  for(int j=0;j<ETOW_PRESIZE;j++) {
135  emc_p->etow_pre[i][j] = d->preamble[i][j] ;
136  }
137  for(int j=0;j<ETOW_DATSIZE;j++) {
138  if(d->adc[i][j] > 0) emc_p->etow_ch++ ;
139  emc_p->etow[i][j] = d->adc[i][j] ;
140  }
141 
142  }
143 
144 
145  }
146 
147  dd = caller->det("esmd")->get("adc") ;
148  while(dd && dd->iterate()) {
149  found_some = 1 ;
150 
151  emc_p->esmd_in = 1;
152  emc_p->esmd_max_fee = ESMD_MAXFEE ; // NOTE that this is the max value, always!
153 
154  esmd_t *d = (esmd_t *) dd->Void ;
155 
156  for(int i=0;i<ESMD_MAXFEE;i++) {
157  for(int j=0;j<ESMD_PRESIZE;j++) {
158  emc_p->esmd_pre[i][j] = d->preamble[i][j] ;
159  }
160  for(int j=0;j<ESMD_DATSIZE;j++) {
161  if(d->adc[i][j] > 0) emc_p->esmd_ch++ ;
162  emc_p->esmd[i][j] = d->adc[i][j] ;
163  }
164 
165  }
166  }
167 
168 
169 
170  // BSMD is slightly more complex
171  if((dd=caller->det("bsmd")->get("adc_non_zs"))) { // try the non-ZS banks first..
172  while(dd->iterate()) {
173  found_some = 1 ;
174 
175  emc_p->bsmd_in = 1 ;
176  emc_p->bsmd_raw_in = 1 ;
177 
178  bsmd_t *d = (bsmd_t *) dd->Void ;
179 
180  int rdo_ix = dd->rdo - 1 ; // rdo from 1; but ix from 0
181  for(int i=0;i<BSMD_DATSIZE;i++) {
182  if(d->adc[i] > 0) emc_p->bsmd_ch++ ; // count >0
183 
184  emc_p->bsmd[rdo_ix][i] = d->adc[i] ;
185  }
186 
187  emc_p->bsmd_cap[rdo_ix] = d->cap ;
188  }
189  }
190  else if((dd=caller->det("bsmd")->get("adc"))) {
191  while(dd->iterate()) {
192  found_some = 1 ;
193 
194  emc_p->bsmd_in = 1 ;
195  emc_p->bsmd_raw_in = 0 ; // make sure!
196 
197  bsmd_t *d = (bsmd_t *) dd->Void ;
198 
199  int rdo_ix = dd->rdo - 1 ; // rdo from 1; but ix from 0
200 
201  for(int i=0;i<BSMD_DATSIZE;i++) {
202  if(d->adc[i] > 0) emc_p->bsmd_ch++ ; // count >0
203 
204  emc_p->bsmd[rdo_ix][i] = d->adc[i] ;
205  }
206 
207  emc_p->bsmd_cap[rdo_ix] = d->cap ;
208 
209  }
210  }
211 
212 
213  legacy->finalize(1,0,0,0) ; // 1 entry; sector 0, row 0, pad 0
214  legacy->rewind() ;
215 
216  if(found_some) return legacy ;
217  else return 0 ;
218 }
Definition: daq_emc.h:52
Definition: daq_etow.h:9
Definition: daq_btow.h:9
u_short esmd_pre[ESMD_MAXFEE][ESMD_PRESIZE]
ADC data.
Definition: daq_emc.h:95