68 #include "StDaqLib/GENERIC/EventReader.hh"
70 #include "StDaqLib/FTPC/fee_pin_FTPC.h"
72 using namespace OLDEVP;
89 int FTPV1P0_ZS_SR::initialize()
93 for (row=0; row<FTP_PADROWS; row++) {
94 Row_array[row].pad = &Pad_array[row][0];
95 Row_array[row].npads = 0;
96 for (
int pad=0; pad<FTP_MAXPADS; pad++) {
97 Pad_array[row][pad].nseq=0;
98 Pad_array[row][pad].seq= (
Sequence *)0;
104 adcd_p = detector->getBankFTPADCD(sector);
105 if ((
void *)adcd_p != NULL) {
109 cout<<
"No FTPADCD bank found for sector "<<sector<<endl;
112 adcx_p = detector->getBankFTPADCX(sector);
113 if ((
void *)adcx_p != NULL) {
117 cout<<
"No FTPADCX bank found for sector "<<sector<<endl;
120 seqd_p = detector->getBankFTPSEQD(sector);
121 if ((
void *)seqd_p != NULL) {
124 int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
125 int len = seqd_p->header.BankLength - (
sizeof(
Bank_Header)/4);
126 int numseq = (4*len)/
sizeof(
short);
129 for (i=0; i<numseq; i++) {
130 if (seqd_p->sequence[i]<0) {
131 padrow = (seqd_p->sequence[i]>>8)& 0x7f;
132 padrow = ((int)(padrow-1)/6)%2+1;
133 pad = (seqd_p->sequence[i])& 0xff;
135 Row_array[padrow-1].npads++;
139 if (padrow <0 || pad <0) {
140 printf(
"encountered bad SEQD bank\n");
143 unsigned short work = seqd_p->sequence[i];
145 int len = work & 0x1f;
146 if (start >= oldstart) {
147 if (start>lastbin+1) Pad_array[padrow-1][pad-1].nseq++;
149 lastbin = start+len-1;
153 Row_array[padrow-1].npads++;
159 printf(
"new pad detected with bit 5 clear!\n");
168 for (row=0; row<FTP_PADROWS; row++) {
170 for (
int pad=0; pad<FTP_MAXPADS; pad++) {
171 int nseq = Pad_array[row][pad].nseq;
174 if (Pad_array[row][pad].seq==NULL) {
175 cout <<
"failed to malloc() Sequence structures " << endl;
187 len = seqd_p->header.BankLength - (
sizeof(
Bank_Header)/4);
188 numseq = (4*len)/
sizeof(
short);
189 u_char *adc_locn = (u_char *)adcd_p->ADC;
190 for (i=0; i<numseq; i++) {
191 if (seqd_p->sequence[i]<0) {
192 padrow = (seqd_p->sequence[i]>>8)& 0x7f;
193 padrow = ((int)(padrow-1)/6)%2+1;
194 pad = (seqd_p->sequence[i])& 0xff;
200 unsigned short work = seqd_p->sequence[i];
202 int len = work & 0x1f;
203 if (start >= oldstart) {
205 if (start>lastbin+1) {
206 Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
207 Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
208 Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
213 Pad_array[padrow-1][pad-1].seq[pad_seq-1].Length += len;
216 lastbin = start+len-1;
225 printf(
"new pad detected with bit 5 clear!\n");
236 if (!padkr)
return FALSE;
237 classname(Bank_FTPADCR) *adcr =
238 detector->getBankFTPADCR(sector) ;
239 if (!adcr)
return FALSE;
240 classname(Bank_FTPCPPR) *cppr =
241 detector->getBankFTPCPPR(sector) ;
242 if (!cppr)
return FALSE;
245 if (detector->ercpy->verbose)
246 printf(
"reconstructing from RAW banks: SEC %d\n",sector);
249 for (
int row=1; row<=FTP_PADROWS; row++) {
250 for (
int pad=1; pad<=FTP_MAXPADS; pad++) {
251 padkr->get(row, pad, &ent);
256 int lastbin = -2, len = 0;
257 int i, start, stop=-1, newseq;
259 for (i=0; i<FTP_MXSEQUENCE; i++) {
260 start = clusters[i].start_time_bin;
261 if ((start < 0)||(start==255)||(start<=stop))
break;
263 newseq = (start>lastbin+1);
264 stop = clusters[i].stop_time_bin;
267 if ( stop<start || start<0 || start>255 || stop<0 || stop>255) {
269 ei = detector->ercpy->getEventInfo();
270 printf(
"%s:%d: bad FTP cluster data detected\n",
272 printf(
"evt# %d , sector %d, row %d, pad %d\n",
273 ei.EventSeqNo,sector,row,pad);
276 printf(
"cluster %d: start=0x%x stop=0x%x\n",
277 i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
281 if (newseq) Pad_array[row-1][pad-1].nseq++;
285 if (i==FTP_MXSEQUENCE) {
293 int nseq = Pad_array[row-1][pad-1].nseq;
295 Pad_array[row-1][pad-1].seq=
297 if (Pad_array[row-1][pad-1].seq==NULL) {
298 cout <<
"failed to malloc() Sequence structures " << endl;
306 for (i=0; seqCnt<nseq; i++) {
307 if (i<FTP_MXSEQUENCE) {
308 start = clusters[i].start_time_bin;
310 if ((start < 0)||(start==255))
break;
311 newseq = (start>lastbin+1);
313 stop = clusters[i].stop_time_bin;
314 len = stop - start + 1;
316 if ( stop<start || start<0 || start>255 || stop<0 || stop>255) {
318 ei = detector->ercpy->getEventInfo();
319 printf(
"%s:%d: bad FTP cluster data detected\n",
321 printf(
"evt# %d , sector %d, row %d, pad %d\n",
322 ei.EventSeqNo,sector,row,pad);
324 printf(
"cluster %d: start=0x%x stop=0x%x\n",
325 i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
332 int offset = ent.offset * padkr->getADCBytes() + start;
333 Pad_array[row-1][pad-1].seq[seqCnt].startTimeBin = start;
334 Pad_array[row-1][pad-1].seq[seqCnt].Length = len;
335 Pad_array[row-1][pad-1].seq[seqCnt].FirstAdc =
336 (u_char *)(adcr->ADC + offset);
340 assert( seqCnt>=1 && seqCnt<=nseq );
341 Pad_array[row-1][pad-1].seq[seqCnt-1].Length += len;
354 FTPV1P0_ZS_SR::~FTPV1P0_ZS_SR()
358 for (
int row=0; row<FTP_PADROWS; row++) {
359 for (
int pad=0; pad<FTP_MAXPADS; pad++) {
360 void *memaddr = Pad_array[row][pad].seq;
361 if (memaddr) free(memaddr);
366 int FTPV1P0_ZS_SR::getPadList(
int PadRow, u_char **padList)
370 if (PadRow == 0 || PadRow > FTP_PADROWS)
return -1;
374 for(pad=1; pad<=FTP_MAXPADS; pad++)
376 if (Pad_array[PadRow-1][pad-1].nseq) padlist[PadRow-1][npad++] = pad;
379 *padList = &padlist[PadRow-1][0];
384 int FTPV1P0_ZS_SR::getSequences(
int PadRow,
int Pad,
int *nSeq,
387 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
388 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
397 int FTPV1P0_ZS_SR::getFeeSequences(
int Fee,
int Pin,
int *nSeq,
401 unsigned short PadRow = row_vs_fee_FTPC[Fee][Pin];
402 unsigned short Pad = pad_vs_fee_FTPC[Fee][Pin];
403 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
404 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
413 int FTPV1P0_ZS_SR::getSpacePts(
int PadRow,
int *nSpacePts,
SpacePt **SpacePts)
415 cout <<
"getSpacePoints() method not implemented" <<endl;
420 int FTPV1P0_ZS_SR::MemUsed()