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 #include <Stiostream.h>
00052
00053 #include "StDaqLib/GENERIC/EventReader.hh"
00054 #include "TPCV1P0.hh"
00055 #define MAKE_THE_DAMNED_COMPILER_SILENT
00056 #include "fee_pin.h"
00057
00058 using namespace OLDEVP;
00059
00060
00061 TPCV1P0_ZS_SR::TPCV1P0_ZS_SR(int s, TPCV1P0_Reader *det)
00062 {
00063 cout << "Constructing TPCV1P0_ZS_SR" << endl;
00064 sector = s-1;
00065 detector = det;
00066
00067
00068 memset((char *)adcd_p, 0, sizeof(adcd_p));
00069 memset((char *)adcx_p, 0, sizeof(adcx_p));
00070 memset((char *)seqd_p, 0, sizeof(seqd_p));
00071 }
00072
00073 int TPCV1P0_ZS_SR::initialize()
00074 {
00075
00076
00077 int row;
00078 for (row=0; row<TPC_PADROWS; row++) {
00079 Row_array[row].pad = &Pad_array[row][0];
00080 Row_array[row].npads = 0;
00081 for (int pad=0; pad<TPC_MAXPADS; pad++) {
00082 Pad_array[row][pad].nseq=0;
00083 Pad_array[row][pad].seq= (Sequence *)0;
00084 }
00085 }
00086
00087 int rcb;
00088
00089 for(rcb = 0; rcb < 6; rcb++)
00090 {
00091 for(int mz = 0; mz < 3; mz++)
00092 {
00093 adcd_p[rcb][mz] = detector->getBankTPCADCD(sector,rcb,mz);
00094 if ((void *)adcd_p[rcb][mz] != NULL) {
00095
00096 fflush(stdout);
00097 }
00098 adcx_p[rcb][mz] = detector->getBankTPCADCX(sector,rcb,mz);
00099 if ((void *)adcx_p[rcb][mz] != NULL) {
00100
00101 fflush(stdout);
00102 }
00103 seqd_p[rcb][mz] = detector->getBankTPCSEQD(sector,rcb,mz);
00104 if ((void *)seqd_p[rcb][mz] != NULL) {
00105
00106 fflush(stdout);
00107 }
00108 }
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 for( rcb = 0; rcb < 6; rcb++) {
00118 for(int mz = 0; mz < 3; mz++) {
00119 if (seqd_p[rcb][mz] == (classname(Bank_TPCSEQD) *)NULL) continue;
00120 printf("TPCSEQD found sector %d RB%d MZ%d\n",sector+1,rcb+1,mz+1);
00121 int padrow=-1, pad=-1, lastbin=-2, oldstart=0;
00122 int len = seqd_p[rcb][mz]->header.BankLength - (sizeof(Bank_Header)/4);
00123 int numseq = (4*len)/sizeof(short);
00124
00125
00126 for (int i=0; i<numseq; i++) {
00127 if (seqd_p[rcb][mz]->sequence[i]<0) {
00128 padrow = (seqd_p[rcb][mz]->sequence[i]>>8)& 0x7f;
00129 pad = (seqd_p[rcb][mz]->sequence[i])& 0xff;
00130 if (pad==255) break;
00131 Row_array[padrow-1].npads++;
00132 oldstart = 0;
00133 }
00134 else {
00135 if (padrow <0 || pad <0) {
00136 printf("encountered bad SEQD bank RB %d, Mezz %d\n", rcb+1, mz+1);
00137 return FALSE;
00138 }
00139 unsigned short work = seqd_p[rcb][mz]->sequence[i];
00140 int start = work>>6;
00141 int len = work & 0x1f;
00142 if (start >= oldstart) {
00143 if (start>lastbin+1) Pad_array[padrow-1][pad-1].nseq++;
00144
00145 lastbin = start+len-1;
00146 oldstart = start;
00147 if (work & 0x20 ) {
00148 pad++;
00149 Row_array[padrow-1].npads++;
00150 lastbin = -2;
00151 oldstart=0;
00152 }
00153 }
00154 else {
00155 printf("new pad detected with bit 5 clear!\n");
00156 fflush(stdout);
00157 return FALSE;
00158 }
00159 }
00160 }
00161 }
00162 }
00163
00164
00165
00166
00167
00168 for (row=0; row<TPC_PADROWS; row++) {
00169
00170 for (int pad=0; pad<TPC_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
00183
00184
00185 for(rcb = 0; rcb < 6; rcb++) {
00186 for(int mz = 0; mz < 3; mz++) {
00187 if (seqd_p[rcb][mz] == (classname(Bank_TPCSEQD) *)NULL) continue;
00188 int padrow=-1, pad=-1, lastbin=-2, pad_seq, oldstart = 0;
00189 int len = seqd_p[rcb][mz]->header.BankLength - (sizeof(Bank_Header)/4);
00190 int numseq = (4*len)/sizeof(short);
00191 u_char *adc_locn = (u_char *)adcd_p[rcb][mz]->ADC;
00192 for (int i=0; i<numseq; i++) {
00193 if (seqd_p[rcb][mz]->sequence[i]<0) {
00194 padrow = (seqd_p[rcb][mz]->sequence[i]>>8)& 0x7f;
00195 pad = (seqd_p[rcb][mz]->sequence[i])& 0xff;
00196 if (pad==255) break;
00197 pad_seq = 0;
00198 oldstart=0;
00199 }
00200 else {
00201 unsigned short work = seqd_p[rcb][mz]->sequence[i];
00202 int start = work>>6;
00203 int len = work & 0x1f;
00204 if (start >= oldstart) {
00205
00206 if (start>lastbin+1) {
00207 Pad_array[padrow-1][pad-1].seq[pad_seq].startTimeBin = start;
00208 Pad_array[padrow-1][pad-1].seq[pad_seq].Length = len;
00209 Pad_array[padrow-1][pad-1].seq[pad_seq].FirstAdc = adc_locn;
00210 adc_locn +=len;
00211 pad_seq++;
00212 }
00213 else {
00214 Pad_array[padrow-1][pad-1].seq[pad_seq].Length += len;
00215 adc_locn +=len;
00216 }
00217 lastbin = start+len-1;
00218 if (work & 0x20) {
00219 pad++;
00220 pad_seq = 0;
00221 lastbin = -2;
00222 oldstart=0;
00223 }
00224 }
00225 else {
00226 printf("new pad detected with bit 5 clear!\n");
00227 fflush(stdout);
00228 return FALSE;
00229 }
00230 }
00231 }
00232 }
00233 }
00234 return TRUE;
00235 }
00236
00237 TPCV1P0_ZS_SR::~TPCV1P0_ZS_SR()
00238 {
00239 cout << "Deleting TPCV1P0_ZS_SR" << endl;
00240
00241 for (int row=0; row<TPC_PADROWS; row++) {
00242 for (int pad=0; pad<TPC_MAXPADS; pad++) {
00243 void *memaddr = Pad_array[row][pad].seq;
00244 if (memaddr) free(memaddr);
00245 }
00246 }
00247 }
00248
00249 int TPCV1P0_ZS_SR::getPadList(int PadRow, u_char **padList)
00250 {
00251
00252 int pad;
00253 if (PadRow == 0 || PadRow > TPC_PADROWS) return -1;
00254
00255
00256 int npad=0;
00257 for(pad=1; pad<=TPC_MAXPADS; pad++)
00258 {
00259 if (Pad_array[PadRow-1][pad-1].nseq) padlist[PadRow-1][npad++] = pad;
00260 }
00261
00262 *padList = &padlist[PadRow-1][0];
00263
00264 return npad;
00265 }
00266
00267 int TPCV1P0_ZS_SR::getSequences(int PadRow, int Pad, int *nSeq,
00268 Sequence **SeqData)
00269 {
00270 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
00271 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
00272 return 0;
00273 }
00274
00275 int TPCV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
00276 Sequence **SeqData)
00277 {
00278 unsigned short PadRow = row_vs_fee[Fee][Pin];
00279 unsigned short Pad = pad_vs_fee[Fee][Pin];
00280 *nSeq = Pad_array[PadRow-1][Pad-1].nseq;
00281 *SeqData = Pad_array[PadRow-1][Pad-1].seq;
00282 return 0;
00283 }
00284
00285
00286 int TPCV1P0_ZS_SR::getSpacePts(int PadRow, int *nSpacePts, SpacePt **SpacePts)
00287 {
00288 cout <<"getSpacePoints() method not implemented" <<endl;
00289 return 0;
00290 }
00291
00292
00293 int TPCV1P0_ZS_SR::MemUsed()
00294 {
00295 return 0;
00296 }
00297