4 #include <daqFormats.h>
5 #include <rtsSystems.h>
12 #include <TPC/padfinder.h>
13 #include <TPC/rowlen.h>
14 #include <adcLogTable.h>
26 #define FCF_MAX_CLUSTERS 6000
33 int daq_tpc::fcfReader(
int sector,
int *t0c, u_int *gainc,
tpc_t *tpc)
43 u_short startFlags[183];
44 u_int output[2*FCF_MAX_CLUSTERS];
50 memset(tpc->cl_counts, 0,
sizeof(tpc->cl_counts));
51 memset(tpc->cl, 0,
sizeof(tpc->cl));
52 tpc->has_clusters = 1;
54 if(tpc->mode != 0)
return -1;
59 for(
int r=0;r<45;r++) {
66 memset(adc, 0,
sizeof(adc));
69 for(t=0;t<tpc->counts[r][p];t++) {
71 tb = tpc->timebin[r][p][t];
72 val = tpc->adc[r][p][t];
88 u_short cpp[182][32*2];
92 memset(cpp, 0xff,
sizeof(cpp));
94 int started, cou, max_seq;
96 started = cou = max_seq = 0;
98 for(tb=0;tb<512;tb++) {
101 if(started)
continue;
109 LOG(NOTE,
"Cou is begger %d pad %d tb %d",cou,p,tb);
112 if(started && (adc[p][tb] == 0)) {
117 cpp[p][cou++] = tb-1;
119 LOG(NOTE,
"Cou is bigger %d pad %d tb %d",cou,p,tb);
138 cpp[p][cou++] = tb-1;
150 for(
int i=0;i<182;i++) {
151 adcOff[i+1] = (
char *)(&adc[i][0]) - (
char *)(&adc[0][0]);
152 cppOff[i+1] = (
char *)(&cpp[i][0]) - (
char *)(&cpp[0][0]) ;
185 fcf->adcOff = adcOff;
186 fcf->cppOff = cppOff;
189 fcf->timebinHi = 400;
191 fcf->set8to10(log8to10_table);
195 for(
int i=0;i<182;i++) t0[i+1] = t0c[46*r + i];
198 for(
int i=0;i<182;i++) t0[i+1] = 0;
202 for(
int i=0;i<182;i++) gain[i+1] = gainc[46*r + i];
205 for(
int i=0;i<182;i++) gain[i+1] = 64;
209 fcf->gainCorr = gain;
211 fcf->maxClusters = FCF_MAX_CLUSTERS;
216 fcf_after->setVerbose(
false);
218 fcf->startFlags = startFlags;
220 memset(startFlags, 0,
sizeof(startFlags));
222 memset(output, 0,
sizeof(output));
225 memset(fcf_ptrs, 0,
sizeof(fcf_ptrs));
229 for(
int mz=0;mz<3;mz++) {
231 if(padfinder[r][mz].rdo == 0)
continue;
233 fcf->padStart = padfinder[r][mz].minpad;
234 fcf->padStop = padfinder[r][mz].maxpad;
237 if(fcf->padStart == 1) startFlags[fcf->padStart] |= FCF_ROW_EDGE;
238 else(startFlags[fcf->padStart]) |= FCF_BROKEN_EDGE;
240 if(tpc_rowlen[r+1] == fcf->padStop)
241 startFlags[fcf->padStop] |= FCF_ROW_EDGE;
243 startFlags[fcf->padStop] |= FCF_BROKEN_EDGE;
247 u_int words = fcf->finder((u_char *)adc,
256 if(words != (*(out+1))*2 + 2) {
257 LOG(ERR,
"Words should match %d vs %d (%d)",
258 words, (*(out+1))*2 + 2, *(out+1));
289 fcf_after->burn(fcf_ptrs);
295 while(fcf_after->next(&h)) {
296 cld = &tpc->cl[r][ccou];
300 cld->p = (double)h.pad/64.0 + 0.5;
301 cld->t = (
double)h.tm/64.0 + 0.5;
314 tpc->cl_counts[r] = ccou;