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 #include "TPCV1P0.hh"
00036
00037 using namespace OLDEVP;
00038
00039
00040 TPCV1P0_PADK_SR::TPCV1P0_PADK_SR(int s, TPCV1P0_Reader *det)
00041 {
00042 sector = s;
00043 detector = det;
00044 }
00045
00046 int TPCV1P0_PADK_SR::initialize()
00047 {
00048
00049
00050
00051 memset((char *)packed_address, 0, sizeof(packed_address));
00052
00053
00054
00055 PADK_entry ent;
00056
00057 for(int rcb = 0; rcb < 6; rcb++)
00058 {
00059 for(int mz = 0; mz < 3; mz++)
00060 {
00061 classname(Bank_TPCPADK) *raw_bank = detector->getBankTPCPADK(sector, rcb, mz);
00062 if(raw_bank)
00063 {
00064
00065 }
00066 else
00067 {
00068
00069
00070 continue;
00071 }
00072
00073 for(int i=0; i < TPC_MZPADS; i++)
00074 {
00075 int padrow = raw_bank->index[i].pad_row;
00076 int pad = raw_bank->index[i].pad;
00077 if((padrow == 0xFF) && (pad == 0xFF)) continue;
00078
00079 ent.offset = i;
00080 ent.mz = mz+1;
00081 ent.rb = rcb+1;
00082
00083 place(padrow, pad, &ent);
00084 }
00085 }
00086 }
00087
00088 return TRUE;
00089 }
00090
00091 void TPCV1P0_PADK_SR::place(short padrow, short pad, PADK_entry *p)
00092 {
00093 padrow--; pad--;
00094 packed_address[padrow][pad] = pack(p->rb, p->mz, p->offset);
00095 }
00096
00097 void TPCV1P0_PADK_SR::get(short padrow, short pad, PADK_entry *p)
00098 {
00099 padrow--; pad--;
00100 unpack(p,packed_address[padrow][pad]);
00101 }
00102
00103 short TPCV1P0_PADK_SR::pack(short rcb, short mz, short offset)
00104 {
00105 short p = rcb;
00106 p = p << 2;
00107 p += mz;
00108 p = p << 10;
00109 p += offset;
00110 return p;
00111 }
00112
00113 void TPCV1P0_PADK_SR::unpack(PADK_entry *entry, short paddress)
00114 {
00115 entry->offset = paddress & 0x03FF;
00116 entry->mz = (paddress & 0x0C00) >> 10;
00117 entry->rb = paddress >> 12;
00118 }
00119
00120 ZeroSuppressedReader *TPCV1P0_Reader::getZeroSuppressedReader(int sector)
00121 {
00122 cout << "getTPCV1P0_ZS_SR sector(" << sector <<")" << endl;
00123
00124 TPCV1P0_ZS_SR *zsp = new TPCV1P0_ZS_SR(sector, this);
00125 if(!zsp->initialize())
00126 {
00127 cout << "ERROR: getTPCV1P0_ZS_SR FAILED sector(" << sector <<")" << endl;
00128 delete zsp;
00129 zsp = NULL;
00130 }
00131
00132 return (ZeroSuppressedReader *)zsp;
00133 }
00134
00135 ADCRawReader *TPCV1P0_Reader::getADCRawReader(int sector)
00136 {
00137
00138 TPCV1P0_ADCR_SR *adc = new TPCV1P0_ADCR_SR(sector, this);
00139 if(!adc->initialize())
00140 {
00141 delete adc;
00142 adc = NULL;
00143 }
00144
00145 return (ADCRawReader *)adc;
00146 }
00147
00148 PedestalReader *TPCV1P0_Reader::getPedestalReader(int sector)
00149 {
00150
00151 TPCV1P0_PEDR_SR *ped = new TPCV1P0_PEDR_SR(sector, this);
00152 if(!ped->initialize())
00153 {
00154 delete ped;
00155 ped = NULL;
00156 }
00157
00158 return (PedestalReader *)ped;
00159 }
00160
00161 PedestalRMSReader *TPCV1P0_Reader::getPedestalRMSReader(int sector)
00162 {
00163
00164 TPCV1P0_PRMS_SR *rms = new TPCV1P0_PRMS_SR(sector, this);
00165 if(!rms->initialize())
00166 {
00167 delete rms;
00168 rms = NULL;
00169 }
00170
00171 return (PedestalRMSReader *)rms;
00172 }
00173
00174 GainReader *TPCV1P0_Reader::getGainReader(int sector)
00175 {
00176 cout << "getTPCV1P0_G_SR" << endl;
00177 return NULL;
00178 }
00179
00180 CPPReader *TPCV1P0_Reader::getCPPReader(int sector)
00181 {
00182
00183 TPCV1P0_CPP_SR *cpp = new TPCV1P0_CPP_SR(sector, this);
00184 if(!cpp->initialize())
00185 {
00186 delete cpp;
00187 cpp = NULL;
00188 }
00189
00190 return (CPPReader *)cpp;}
00191
00192 BadChannelReader *TPCV1P0_Reader::getBadChannelReader(int sector)
00193 {
00194 cout << "getTPCV1P0_BC_SR" << endl;
00195 return NULL;
00196 }
00197
00198 ConfigReader *TPCV1P0_Reader::getConfigReader(int sector)
00199 {
00200 cout << "getTPCV1P0_CR_SR" << endl;
00201 return NULL;
00202 }
00203
00204 TPCV1P0_PADK_SR *TPCV1P0_Reader::getPADKReader(int sector)
00205 {
00206
00207
00208 TPCV1P0_PADK_SR *p;
00209 p = padk[sector];
00210 if(p == NULL)
00211 {
00212 p = new TPCV1P0_PADK_SR(sector, this);
00213 if(!p->initialize())
00214 {
00215 cout << "Error Reading PADK banks, sector=" << sector
00216 << ": " << errstr().c_str() << endl;
00217 delete p;
00218 return NULL;
00219 }
00220 }
00221 padk[sector] = p;
00222 return p;
00223 }
00224
00225 TPCV1P0_Reader::TPCV1P0_Reader(EventReader *er, classname(Bank_TPCP) *ptpc)
00226 {
00227 pBankTPCP = ptpc;
00228
00229 if (!pBankTPCP->test_CRC()) ERROR(ERR_CRC);
00230 if (pBankTPCP->swap() < 0) ERROR(ERR_SWAP);
00231 pBankTPCP->header.CRC = 0;
00232
00233
00234 for(int i=0;i<TPC_SECTORS;i++)
00235 {
00236 padk[i] = NULL;
00237 }
00238 }
00239
00240 TPCV1P0_Reader::~TPCV1P0_Reader()
00241 {
00242
00243
00244
00245
00246
00247 for(int i=0;i<TPC_SECTORS;i++)
00248 {
00249 if(padk[i] != NULL) delete padk[i];
00250 }
00251 }
00252
00253 int TPCV1P0_Reader::MemUsed()
00254 {
00255 return 0;
00256 }
00257
00258
00259
00260
00261
00262
00263 classname(Bank_TPCSECP) *TPCV1P0_Reader::getBankTPCSECP(int hypersector)
00264 {
00265 if((hypersector <= 0) || (hypersector >= 24))
00266 {
00267 pERROR(ERR_BAD_ARG);
00268 return NULL;
00269 }
00270 hypersector--;
00271
00272 if((!pBankTPCP->HyperSector[hypersector].offset) ||
00273 (!pBankTPCP->HyperSector[hypersector].length))
00274 {
00275 pERROR(ERR_BANK);
00276 return NULL;
00277 }
00278
00279 classname(Bank_TPCSECP) *ptr = (classname(Bank_TPCSECP) *)
00280 (((INT32 *)pBankTPCP) +
00281 pBankTPCP->HyperSector[hypersector].offset);
00282
00283 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00284 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00285 ptr->header.CRC = 0;
00286
00287 return ptr;
00288 }
00289
00290 classname(Bank_TPCRBP) *TPCV1P0_Reader::getBankTPCRBP(int interleaved_rb,
00291 classname(Bank_TPCSECP) *secp)
00292 {
00293 if ((interleaved_rb < 0) || (interleaved_rb >= 12))
00294 {
00295 pERROR(ERR_BAD_ARG);
00296 return NULL;
00297 }
00298
00299
00300
00301
00302 if ((!secp->RcvBoard[interleaved_rb].offset) ||
00303 (!secp->RcvBoard[interleaved_rb].length) )
00304 {
00305
00306 return NULL;
00307 }
00308
00309 classname(Bank_TPCRBP) *ptr = (classname(Bank_TPCRBP) *)
00310 (((INT32 *)secp) +
00311 secp->RcvBoard[interleaved_rb].offset);
00312
00313 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00314 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00315 ptr->header.CRC = 0;
00316
00317 return ptr;
00318 }
00319
00320 classname(Bank_TPCMZP) *TPCV1P0_Reader::getBankTPCMZP(int mz, classname(Bank_TPCRBP) *rbp)
00321 {
00322 if ((mz < 0) || (mz >= 3))
00323 {
00324 pERROR(ERR_BAD_ARG);
00325 return NULL;
00326 }
00327
00328 if ((!rbp->Mz[mz].offset) || (!rbp->Mz[mz].length))
00329 {
00330 pERROR(ERR_BANK);
00331 return NULL;
00332 }
00333
00334 classname(Bank_TPCMZP) *ptr = (classname(Bank_TPCMZP) *)
00335 (((INT32 *)rbp) +
00336 rbp->Mz[mz].offset);
00337
00338 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00339 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00340 ptr->header.CRC = 0;
00341
00342
00343
00344
00345 return ptr;
00346 }
00347
00348 classname(Bank_TPCMZP) *TPCV1P0_Reader::getBankTPCMZP(int sector, int rb, int mz)
00349 {
00350 if ((sector < 0) || (sector >= TPC_SECTORS))
00351 {
00352 pERROR(ERR_BAD_ARG);
00353 return NULL;
00354 }
00355 if ((rb < 0) || (rb >= 6))
00356 {
00357 pERROR(ERR_BAD_ARG);
00358 return NULL;
00359 }
00360 if ((mz < 0) || (mz >= 3))
00361 {
00362 pERROR(ERR_BAD_ARG);
00363 return NULL;
00364 }
00365
00366 classname(Bank_TPCSECP) *secp = getBankTPCSECP(2*(sector/2)+1);
00367
00368 if(!secp) return NULL;
00369
00370 classname(Bank_TPCRBP) *rbp;
00371 if (sector%2)
00372 {
00373 rbp = getBankTPCRBP(rb + 6, secp);
00374 }
00375 else
00376 {
00377 rbp = getBankTPCRBP(rb, secp);
00378 }
00379 if(!rbp) return NULL;
00380
00381 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(mz,rbp);
00382 return mzp;
00383 }
00384
00385 classname(Bank_TPCADCD) *TPCV1P0_Reader::getBankTPCADCD(int sector, int rb, int mz)
00386 {
00387 errnum = 0;
00388 errstr0[0] = '\0';
00389
00390 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
00391 if(!mzp) return NULL;
00392
00393
00394
00395
00396 if((!mzp->TPCADCD.offset) || (!mzp->TPCADCD.length))
00397 {
00398 pERROR(ERR_BANK);
00399 return NULL;
00400 }
00401
00402 classname(Bank_TPCADCD) *ptr = (classname(Bank_TPCADCD) *)
00403 (((INT32 *)mzp) +
00404 mzp->TPCADCD.offset);
00405
00406 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00407 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00408 ptr->header.CRC = 0;
00409
00410 return ptr;
00411 }
00412
00413 classname(Bank_TPCSEQD) *TPCV1P0_Reader::getBankTPCSEQD(int sector, int rb, int mz)
00414 {
00415 errnum = 0;
00416 errstr0[0] = '\0';
00417
00418 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
00419 if(!mzp) return NULL;
00420
00421
00422
00423
00424 if((!mzp->TPCSEQD.offset) || (!mzp->TPCSEQD.length))
00425 {
00426 pERROR(ERR_BANK);
00427 return NULL;
00428 }
00429
00430 classname(Bank_TPCSEQD) *ptr = (classname(Bank_TPCSEQD) *)
00431 (((INT32 *)mzp) +
00432 mzp->TPCSEQD.offset);
00433
00434 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00435 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00436 ptr->header.CRC = 0;
00437
00438 return ptr;}
00439
00440 classname(Bank_TPCADCX) *TPCV1P0_Reader::getBankTPCADCX(int sector, int rb, int mz)
00441 {
00442 errnum = 0;
00443 errstr0[0] = '\0';
00444
00445 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
00446 if(!mzp) return NULL;
00447
00448
00449
00450
00451 if((!mzp->TPCADCX.offset) || (!mzp->TPCADCX.length))
00452 {
00453 pERROR(ERR_BANK);
00454 return NULL;
00455 }
00456
00457 classname(Bank_TPCADCX) *ptr = (classname(Bank_TPCADCX) *)
00458 (((INT32 *)mzp) +
00459 mzp->TPCADCX.offset);
00460
00461 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00462 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00463 ptr->header.CRC = 0;
00464
00465 return ptr;}
00466
00467 classname(Bank_TPCPADK) *TPCV1P0_Reader::getBankTPCPADK(int sector, int rb, int mz)
00468 {
00469 errnum = 0;
00470 errstr0[0] = '\0';
00471
00472 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
00473 if(!mzp) return NULL;
00474
00475
00476
00477
00478 if((!mzp->TPCPADK.offset) || (!mzp->TPCPADK.length))
00479 {
00480 pERROR(ERR_BANK);
00481 return NULL;
00482 }
00483
00484 classname(Bank_TPCPADK) *ptr = (classname(Bank_TPCPADK) *)
00485 (((INT32 *)mzp) +
00486 mzp->TPCPADK.offset);
00487
00488 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00489 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00490 ptr->header.CRC = 0;
00491
00492 return ptr;
00493 };
00494
00495 classname(Bank_TPCCPPR) *TPCV1P0_Reader::getBankTPCCPPR(int sector, int rb, int mz)
00496 {
00497 errnum = 0;
00498 errstr0[0] = '\0';
00499
00500 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
00501 if(!mzp) return NULL;
00502
00503 if((!mzp->TPCCPPR.offset) || (!mzp->TPCCPPR.length))
00504 {
00505 pERROR(ERR_BANK);
00506 return NULL;
00507 }
00508
00509 classname(Bank_TPCCPPR) *ptr = (classname(Bank_TPCCPPR) *)
00510 (((INT32 *)mzp) +
00511 mzp->TPCCPPR.offset);
00512
00513 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00514 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00515 ptr->header.CRC = 0;
00516
00517 return ptr;
00518 }
00519
00520 classname(Bank_TPCADCR) *TPCV1P0_Reader::getBankTPCADCR(int sector, int rb, int mz)
00521 {
00522 errnum = 0;
00523 errstr0[0] = '\0';
00524
00525 classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
00526 if(!mzp) return NULL;
00527
00528 if((!mzp->TPCADCR.offset) || (!mzp->TPCADCR.length))
00529 {
00530 pERROR(ERR_BANK);
00531 return NULL;
00532 }
00533
00534 classname(Bank_TPCADCR) *ptr = (classname(Bank_TPCADCR) *)
00535 (((INT32 *)mzp) +
00536 mzp->TPCADCR.offset);
00537
00538 if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
00539 if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
00540 ptr->header.CRC = 0;
00541
00542 return ptr;
00543 }
00544
00545 classname(Bank_TPCCFGR) *TPCV1P0_Reader::getBankTPCCFGR(int sector, int rb, int mz)
00546 {
00547 return NULL;
00548 }
00549
00550 classname(Bank_TPCPEDR) *TPCV1P0_Reader::getBankTPCPEDR(int sector, int rb, int mz)
00551 {
00552 return NULL;
00553 }
00554
00555
00556 classname(Bank_TPCRMSR) *TPCV1P0_Reader::getBankTPCRMSR(int sector, int rb, int mz)
00557 {
00558 return NULL;
00559 }
00560
00561 classname(Bank_TPCGAINR) *TPCV1P0_Reader::getBankTPCGAINR(int sector, int rb, int mz)
00562 {
00563 return NULL;
00564 }
00565
00566 classname(Bank_TPCBADR) *TPCV1P0_Reader::getBankTPCBADR(int sector, int rb, int mz)
00567 {
00568 return NULL;
00569 }
00570