1 #include "StFssSectorReader.hh"
6 StFssSectorReader::StFssSectorReader(
int sector,
7 unsigned short *fcl_ftpcsqndx,
int nSeq,
8 char *fcl_ftpcadc,
int nAdc)
11 m_ftpcsqndx=fcl_ftpcsqndx;
12 m_ftpcadc=fcl_ftpcadc;
18 StFssSectorReader::~StFssSectorReader()
21 for (
int row=0; row<FTP_PADROWS; row++)
23 for (
int pad=0; pad<FTP_MAXPADS; pad++)
25 void *memaddr = Pad_array[row][pad].seq;
26 if (memaddr) free(memaddr);
31 int StFssSectorReader::getPadList(
int PadRow,
unsigned char **padList)
35 if (PadRow == 0 || PadRow > FTP_PADROWS)
return -1;
39 for(pad=1; pad<=FTP_MAXPADS; pad++)
41 if (Pad_array[PadRow-1][pad-1].nseq)
43 padlist[PadRow-1][npad++] = pad;
47 *padList = &padlist[PadRow-1][0];
52 int StFssSectorReader::getSequences(
int PadRow,
int Pad,
int *nSeq,
Sequence **SeqData)
54 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
55 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
59 int StFssSectorReader::initialize()
62 unsigned short *seqTable=m_ftpcsqndx;
63 char *adcTable=m_ftpcadc;
66 int softSec=(mSector-1)%6;
67 int softRow=2*(int)((mSector-1)/6);
70 int row, thisSoftSec=0, thisSoftRow=0;
71 for (row=0; row<FTP_PADROWS; row++)
73 Row_array[row].pad = &Pad_array[row][0];
74 Row_array[row].npads = 0;
75 for (
int pad=0; pad<FTP_MAXPADS; pad++)
77 Pad_array[row][pad].nseq=0;
78 Pad_array[row][pad].seq= (
Sequence *)0;
84 int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
87 for (i=0; i<m_numSqndx; i++)
89 int thisEntry=seqTable[i];
90 if ((thisEntry & 32768) == 32768)
92 thisSoftSec = ((thisEntry >>8) & 127);
93 thisSoftRow = (int) thisSoftSec / 6;
94 thisSoftSec -= 6 * thisSoftRow;
95 pad = (thisEntry & 255)+1;
97 if(thisSoftSec==softSec &&
98 (thisSoftRow==softRow || thisSoftRow==softRow+1))
100 padrow = (thisSoftRow % 2) + 1;
101 Row_array[padrow-1].npads++;
108 if(thisSoftSec==softSec &&
109 (thisSoftRow==softRow || thisSoftRow==softRow+1))
111 int start = (thisEntry>>6) & 511;
112 int len = (thisEntry & 31) +1;
113 if (start >= oldstart)
116 Pad_array[padrow-1][pad-1].nseq++;
118 lastbin = start+len-1;
120 if ((thisEntry & 32)==32)
123 Row_array[padrow-1].npads++;
130 LOG_WARN <<
"1: new pad detected with bit 5 clear!" << endm;
131 LOG_WARN << start <<
" < " << oldstart << endm;
139 for (row=0; row<FTP_PADROWS; row++)
142 for (
int pad=0; pad<FTP_MAXPADS; pad++)
144 int nseq = Pad_array[row][pad].nseq;
148 if (Pad_array[row][pad].seq==NULL)
150 LOG_ERROR <<
"failed to malloc() Sequence structures " << endm;
164 uint8_t *adc_locn = (uint8_t *)(adcTable);
165 for (i=0; i<m_numSqndx; i++)
167 int thisEntry=seqTable[i];
168 if ((thisEntry & 32768) == 32768)
170 thisSoftSec = ((thisEntry >>8) & 127);
171 thisSoftRow = (int) thisSoftSec / 6;
172 thisSoftSec -= 6 * thisSoftRow;
173 pad = (thisEntry & 255)+1;
175 if(thisSoftSec==softSec &&
176 (thisSoftRow==softRow || thisSoftRow==softRow+1))
178 padrow = (thisSoftRow % 2) + 1;
185 int start = (thisEntry>>6) & 511;
186 int len = (thisEntry & 31) +1;
187 if (start >= oldstart)
193 if(thisSoftSec==softSec &&
194 (thisSoftRow==softRow || thisSoftRow==softRow+1))
196 Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
197 Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
198 Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
206 if(thisSoftSec==softSec &&
207 (thisSoftRow==softRow || thisSoftRow==softRow+1))
209 Pad_array[padrow-1][pad-1].seq[pad_seq].Length += len;
213 lastbin = start+len-1;
214 if ((thisEntry&32)==32)
224 LOG_WARN <<
"2: new pad detected with bit 5 clear!" << endm;
225 LOG_WARN << start <<
" < " << oldstart << endm;