00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 #include <Stiostream.h>
00063 #include <assert.h>
00064
00065 #include "StDaqLib/GENERIC/EventReader.hh"
00066 #include "FTPV1P0.hh"
00067 #include "StDaqLib/FTPC/fee_pin_FTPC.h"
00068
00069 using namespace OLDEVP;
00070
00071 FTPV1P0_ZS_SR::FTPV1P0_ZS_SR(int s, FTPV1P0_Reader *det)
00072 {
00073
00074 sector = s;
00075 detector = det;
00076
00077
00078
00079
00080
00081 adcd_p=0;
00082 adcx_p=0;
00083 seqd_p=0;
00084 }
00085
00086 int FTPV1P0_ZS_SR::initialize()
00087 {
00088 int i;
00089 int row;
00090 for (row=0; row<FTP_PADROWS; row++) {
00091 Row_array[row].pad = &Pad_array[row][0];
00092 Row_array[row].npads = 0;
00093 for (int pad=0; pad<FTP_MAXPADS; pad++) {
00094 Pad_array[row][pad].nseq=0;
00095 Pad_array[row][pad].seq= (Sequence *)0;
00096 }
00097 }
00098
00099
00100
00101 adcd_p = detector->getBankFTPADCD(sector);
00102 if ((void *)adcd_p != NULL) {
00103 fflush(stdout);
00104 }
00105 else {
00106 cout<<"No FTPADCD bank found for sector "<<sector<<endl;
00107 return FALSE;
00108 }
00109 adcx_p = detector->getBankFTPADCX(sector);
00110 if ((void *)adcx_p != NULL) {
00111 fflush(stdout);
00112 }
00113 else {
00114 cout<<"No FTPADCX bank found for sector "<<sector<<endl;
00115 return FALSE;
00116 }
00117 seqd_p = detector->getBankFTPSEQD(sector);
00118 if ((void *)seqd_p != NULL) {
00119 fflush(stdout);
00120
00121
00122
00123 int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
00124 int len = seqd_p->header.BankLength - (sizeof(Bank_Header)/4);
00125 int numseq = (4*len)/sizeof(short);
00126
00127
00128 for (i=0; i<numseq; i++) {
00129 if (seqd_p->sequence[i]<0) {
00130 padrow = (seqd_p->sequence[i]>>8)& 0x7f;
00131 padrow = ((int)(padrow-1)/6)%2+1;
00132 pad = (seqd_p->sequence[i])& 0xff;
00133 if (pad==255) break;
00134 Row_array[padrow-1].npads++;
00135 oldstart = 0;
00136 }
00137 else {
00138 if (padrow <0 || pad <0) {
00139 printf("encountered bad SEQD bank\n");
00140 return FALSE;
00141 }
00142 unsigned short work = seqd_p->sequence[i];
00143 int start = work>>6;
00144 int len = work & 0x1f;
00145 if (start >= oldstart) {
00146 if (start>lastbin+1) Pad_array[padrow-1][pad-1].nseq++;
00147
00148 lastbin = start+len-1;
00149 oldstart = start;
00150 if (work & 0x20 ) {
00151 pad++;
00152 Row_array[padrow-1].npads++;
00153 lastbin = -2;
00154 oldstart=0;
00155 }
00156 }
00157 else {
00158 printf("new pad detected with bit 5 clear!\n");
00159 fflush(stdout);
00160 return FALSE;
00161 }
00162 }
00163 }
00164
00165
00166
00167
00168 for (row=0; row<FTP_PADROWS; row++) {
00169
00170 for (int pad=0; pad<FTP_MAXPADS; pad++) {
00171 int nseq = Pad_array[row][pad].nseq;
00172 if (nseq) {
00173 Pad_array[row][pad].seq= (Sequence *)malloc(nseq*sizeof(Sequence));
00174 if (Pad_array[row][pad].seq==NULL) {
00175 cout << "failed to malloc() Sequence structures " << endl;
00176 return FALSE;
00177 }
00178 }
00179 }
00180 }
00181
00182 padrow=-1;
00183 pad=-1;
00184 lastbin=-2;
00185 int pad_seq=0;
00186 oldstart = 0;
00187 len = seqd_p->header.BankLength - (sizeof(Bank_Header)/4);
00188 numseq = (4*len)/sizeof(short);
00189 u_char *adc_locn = (u_char *)adcd_p->ADC;
00190 for (i=0; i<numseq; i++) {
00191 if (seqd_p->sequence[i]<0) {
00192 padrow = (seqd_p->sequence[i]>>8)& 0x7f;
00193 padrow = ((int)(padrow-1)/6)%2+1;
00194 pad = (seqd_p->sequence[i])& 0xff;
00195 if (pad==255) break;
00196 pad_seq = 0;
00197 oldstart=0;
00198 }
00199 else {
00200 unsigned short work = seqd_p->sequence[i];
00201 int start = work>>6;
00202 int len = work & 0x1f;
00203 if (start >= oldstart) {
00204
00205 if (start>lastbin+1) {
00206 Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
00207 Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
00208 Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
00209 adc_locn +=len;
00210 pad_seq++;
00211 }
00212 else {
00213 Pad_array[padrow-1][pad-1].seq[pad_seq-1].Length += len;
00214 adc_locn +=len;
00215 }
00216 lastbin = start+len-1;
00217 if (work & 0x20) {
00218 pad++;
00219 pad_seq = 0;
00220 lastbin = -2;
00221 oldstart=0;
00222 }
00223 }
00224 else {
00225 printf("new pad detected with bit 5 clear!\n");
00226 fflush(stdout);
00227 return FALSE;
00228 }
00229 }
00230 }
00231 return TRUE;
00232 }
00233 else {
00234
00235
00236 FTPV1P0_PADK_SR *padkr = detector->getPADKReader(sector);
00237 if (!padkr) return FALSE;
00238 classname(Bank_FTPADCR) *adcr =
00239 detector->getBankFTPADCR(sector) ;
00240 if (!adcr) return FALSE;
00241 classname(Bank_FTPCPPR) *cppr =
00242 detector->getBankFTPCPPR(sector) ;
00243 if (!cppr) return FALSE;
00244
00245
00246 if (detector->ercpy->verbose)
00247 printf("reconstructing from RAW banks: SEC %d\n",sector);
00248 FTPPADK_entry ent;
00249
00250 for (int row=1; row<=FTP_PADROWS; row++) {
00251 for (int pad=1; pad<=FTP_MAXPADS; pad++) {
00252 padkr->get(row, pad, &ent);
00253
00254 struct ASIC_Cluster *clusters =
00255 (ASIC_Cluster *)(cppr->entry + 32*ent.offset);
00256
00257 int lastbin = -2, len = 0;
00258 int i, start, stop=-1, newseq;
00259
00260 for (i=0; i<FTP_MXSEQUENCE; i++) {
00261 start = clusters[i].start_time_bin;
00262 if ((start < 0)||(start==255)||(start<=stop)) break;
00263
00264 newseq = (start>lastbin+1);
00265 stop = clusters[i].stop_time_bin;
00266
00267
00268 if ( stop<start || start<0 || start>255 || stop<0 || stop>255) {
00269 struct EventInfo ei;
00270 ei = detector->ercpy->getEventInfo();
00271 printf("%s:%d: bad FTP cluster data detected\n",
00272 __FILE__,__LINE__);
00273 printf("evt# %d , sector %d, row %d, pad %d\n",
00274 ei.EventSeqNo,sector,row,pad);
00275
00276
00277 printf("cluster %d: start=0x%x stop=0x%x\n",
00278 i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
00279 break;
00280 }
00281 lastbin = stop;
00282 if (newseq) Pad_array[row-1][pad-1].nseq++;
00283
00284
00285 }
00286 if (i==FTP_MXSEQUENCE) {
00287
00288
00289 }
00290
00291
00292
00293
00294 int nseq = Pad_array[row-1][pad-1].nseq;
00295 if (!nseq) continue;
00296 Pad_array[row-1][pad-1].seq=
00297 (Sequence *)malloc(nseq*sizeof(Sequence));
00298 if (Pad_array[row-1][pad-1].seq==NULL) {
00299 cout << "failed to malloc() Sequence structures " << endl;
00300 return FALSE;
00301 }
00302 lastbin = -2;
00303 len = 0;
00304 int seqCnt = 0;
00305
00306
00307 for (i=0; seqCnt<nseq; i++) {
00308 if (i<FTP_MXSEQUENCE) {
00309 start = clusters[i].start_time_bin;
00310
00311 if ((start < 0)||(start==255)) break;
00312 newseq = (start>lastbin+1);
00313
00314 stop = clusters[i].stop_time_bin;
00315 len = stop - start + 1;
00316
00317 if ( stop<start || start<0 || start>255 || stop<0 || stop>255) {
00318 struct EventInfo ei;
00319 ei = detector->ercpy->getEventInfo();
00320 printf("%s:%d: bad FTP cluster data detected\n",
00321 __FILE__,__LINE__);
00322 printf("evt# %d , sector %d, row %d, pad %d\n",
00323 ei.EventSeqNo,sector,row,pad);
00324
00325 printf("cluster %d: start=0x%x stop=0x%x\n",
00326 i,clusters[i].start_time_bin,clusters[i].stop_time_bin);
00327 break;
00328
00329 break;
00330 }
00331 lastbin = stop;
00332 if (newseq) {
00333 int offset = ent.offset * padkr->getADCBytes() + start;
00334 Pad_array[row-1][pad-1].seq[seqCnt].startTimeBin = start;
00335 Pad_array[row-1][pad-1].seq[seqCnt].Length = len;
00336 Pad_array[row-1][pad-1].seq[seqCnt].FirstAdc =
00337 (u_char *)(adcr->ADC + offset);
00338 seqCnt++;
00339 }
00340 else {
00341 assert( seqCnt>=1 && seqCnt<=nseq );
00342 Pad_array[row-1][pad-1].seq[seqCnt-1].Length += len;
00343 }
00344 }
00345 else {
00346
00347 }
00348 }
00349 }
00350 }
00351 return TRUE;
00352 }
00353 }
00354
00355 FTPV1P0_ZS_SR::~FTPV1P0_ZS_SR()
00356 {
00357
00358
00359 for (int row=0; row<FTP_PADROWS; row++) {
00360 for (int pad=0; pad<FTP_MAXPADS; pad++) {
00361 void *memaddr = Pad_array[row][pad].seq;
00362 if (memaddr) free(memaddr);
00363 }
00364 }
00365 }
00366
00367 int FTPV1P0_ZS_SR::getPadList(int PadRow, u_char **padList)
00368 {
00369
00370 int pad;
00371 if (PadRow == 0 || PadRow > FTP_PADROWS) return -1;
00372
00373
00374 int npad=0;
00375 for(pad=1; pad<=FTP_MAXPADS; pad++)
00376 {
00377 if (Pad_array[PadRow-1][pad-1].nseq) padlist[PadRow-1][npad++] = pad;
00378 }
00379
00380 *padList = &padlist[PadRow-1][0];
00381
00382 return npad;
00383 }
00384
00385 int FTPV1P0_ZS_SR::getSequences(int PadRow, int Pad, int *nSeq,
00386 Sequence **SeqData)
00387 {
00388 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
00389 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
00390
00391 if (&nSeq) {
00392 return 1;
00393 } else {
00394 return 0;
00395 }
00396 }
00397
00398 int FTPV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
00399 Sequence **SeqData)
00400 {
00401
00402 unsigned short PadRow = row_vs_fee_FTPC[Fee][Pin];
00403 unsigned short Pad = pad_vs_fee_FTPC[Fee][Pin];
00404 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
00405 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
00406 return 0;
00407
00408
00409
00410
00411 }
00412
00413
00414 int FTPV1P0_ZS_SR::getSpacePts(int PadRow, int *nSpacePts, SpacePt **SpacePts)
00415 {
00416 cout <<"getSpacePoints() method not implemented" <<endl;
00417 return 0;
00418 }
00419
00420
00421 int FTPV1P0_ZS_SR::MemUsed()
00422 {
00423 return 0;
00424 }
00425