StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TPCV1P0.cxx
1 /***************************************************************************
2  * $Id: TPCV1P0.cxx,v 1.6 2007/12/24 06:04:31 fine Exp $
3  * Author: M.J. LeVine
4  ***************************************************************************
5  * Description: TPCV1P0 implementation
6  *
7  *
8  * change log
9  * 02-Jun-99 MJL fixed test on hypersector arg of getBankTPCSECP
10  *
11  ***************************************************************************
12  * $Log: TPCV1P0.cxx,v $
13  * Revision 1.6 2007/12/24 06:04:31 fine
14  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
15  *
16  * Revision 1.5 2000/01/11 22:03:44 levine
17  * convert string to char* via c_str() member
18  * (from Brian Lasiuk)
19  *
20  * Revision 1.4 1999/07/10 21:31:25 levine
21  * Detectors RICH, EMC, TRG now have their own (defined by each detector) interfaces.
22  * Existing user code will not have to change any calls to TPC-like detector
23  * readers.
24  *
25  * Revision 1.3 1999/07/02 04:43:23 levine
26  * Many changes -
27  * navigates to head of TPCP bank independent of position.
28  * move declarations out of loops where they were upsetting some compilers
29  * suppress output from class libraries with run-time switch EventReader.verbose
30  * added TPCV2P0_CPP_SR::getAsicParams()
31  *
32  *
33  **************************************************************************/
34 
35 #include "TPCV1P0.hh"
36 
37 using namespace OLDEVP;
38 
39 
40 TPCV1P0_PADK_SR::TPCV1P0_PADK_SR(int s, TPCV1P0_Reader *det)
41 {
42  sector = s;
43  detector = det;
44 }
45 
46 int TPCV1P0_PADK_SR::initialize()
47 {
48  // cout << "Initializing PADK sector: " << sector << endl;
49 
50  // zero out lookup array
51  memset((char *)packed_address, 0, sizeof(packed_address));
52 
53  // cout << "Sizeof() = " << sizeof(packed_address) << endl;
54 
55  PADK_entry ent;
56 
57  for(int rcb = 0; rcb < 6; rcb++)
58  {
59  for(int mz = 0; mz < 3; mz++)
60  {
61  classname(Bank_TPCPADK) *raw_bank = detector->getBankTPCPADK(sector, rcb, mz);
62  if(raw_bank)
63  {
64  // printf("PADK DATA for sector %d, rcb %d, mz %d\n",sector,rcb,mz);
65  }
66  else
67  {
68  // printf("No PADK DATA, sector %d, rcb %d, mz %d\n",sector,rcb,mz);
69  // printf("ERR: %s\n",detector->errstr0);
70  continue;
71  }
72 
73  for(int i=0; i < TPC_MZPADS; i++)
74  {
75  int padrow = raw_bank->index[i].pad_row;
76  int pad = raw_bank->index[i].pad;
77  if((padrow == 0xFF) && (pad == 0xFF)) continue;
78 
79  ent.offset = i;
80  ent.mz = mz+1;
81  ent.rb = rcb+1;
82 
83  place(padrow, pad, &ent);
84  }
85  }
86  }
87 
88  return TRUE;
89 }
90 
91 void TPCV1P0_PADK_SR::place(short padrow, short pad, PADK_entry *p)
92 {
93  padrow--; pad--; // use c standard for array
94  packed_address[padrow][pad] = pack(p->rb, p->mz, p->offset);
95 }
96 
97 void TPCV1P0_PADK_SR::get(short padrow, short pad, PADK_entry *p)
98 {
99  padrow--; pad--; // use c standard for array
100  unpack(p,packed_address[padrow][pad]);
101 }
102 
103 short TPCV1P0_PADK_SR::pack(short rcb, short mz, short offset)
104 {
105  short p = rcb; // 4 bits
106  p = p << 2;
107  p += mz; // 2 bits
108  p = p << 10;
109  p += offset; // 10 bits
110  return p;
111 }
112 
113 void TPCV1P0_PADK_SR::unpack(PADK_entry *entry, short paddress)
114 {
115  entry->offset = paddress & 0x03FF;
116  entry->mz = (paddress & 0x0C00) >> 10;
117  entry->rb = paddress >> 12;
118 }
119 
120 ZeroSuppressedReader *TPCV1P0_Reader::getZeroSuppressedReader(int sector)
121 {
122  cout << "getTPCV1P0_ZS_SR sector(" << sector <<")" << endl;
123 
124  TPCV1P0_ZS_SR *zsp = new TPCV1P0_ZS_SR(sector, this);
125  if(!zsp->initialize())
126  {
127  cout << "ERROR: getTPCV1P0_ZS_SR FAILED sector(" << sector <<")" << endl;
128  delete zsp;
129  zsp = NULL;
130  }
131 
132  return (ZeroSuppressedReader *)zsp;
133 }
134 
135 ADCRawReader *TPCV1P0_Reader::getADCRawReader(int sector)
136 {
137  // cout << "getTPCV1P0_ADCR_SR" << endl;
138  TPCV1P0_ADCR_SR *adc = new TPCV1P0_ADCR_SR(sector, this);
139  if(!adc->initialize())
140  {
141  delete adc;
142  adc = NULL;
143  }
144 
145  return (ADCRawReader *)adc;
146 }
147 
148 PedestalReader *TPCV1P0_Reader::getPedestalReader(int sector)
149 {
150  // cout << "getTPCV1P0_P_SR" << endl;
151  TPCV1P0_PEDR_SR *ped = new TPCV1P0_PEDR_SR(sector, this);
152  if(!ped->initialize())
153  {
154  delete ped;
155  ped = NULL;
156  }
157 
158  return (PedestalReader *)ped;
159 }
160 
161 PedestalRMSReader *TPCV1P0_Reader::getPedestalRMSReader(int sector)
162 {
163  // cout << "getTPCV1P0_PRMS_SR" << endl;
164  TPCV1P0_PRMS_SR *rms = new TPCV1P0_PRMS_SR(sector, this);
165  if(!rms->initialize())
166  {
167  delete rms;
168  rms = NULL;
169  }
170 
171  return (PedestalRMSReader *)rms;
172 }
173 
174 GainReader *TPCV1P0_Reader::getGainReader(int sector)
175 {
176  cout << "getTPCV1P0_G_SR" << endl;
177  return NULL;
178 }
179 
180 CPPReader *TPCV1P0_Reader::getCPPReader(int sector)
181 {
182  // cout << "getTPCV1P0_CPP_SR" << endl;
183  TPCV1P0_CPP_SR *cpp = new TPCV1P0_CPP_SR(sector, this);
184  if(!cpp->initialize())
185  {
186  delete cpp;
187  cpp = NULL;
188  }
189 
190  return (CPPReader *)cpp;}
191 
192 BadChannelReader *TPCV1P0_Reader::getBadChannelReader(int sector)
193 {
194  cout << "getTPCV1P0_BC_SR" << endl;
195  return NULL;
196 }
197 
198 ConfigReader *TPCV1P0_Reader::getConfigReader(int sector)
199 {
200  cout << "getTPCV1P0_CR_SR" << endl;
201  return NULL;
202 }
203 
204 TPCV1P0_PADK_SR *TPCV1P0_Reader::getPADKReader(int sector)
205 {
206  // cout << "GetPADKReader" << endl;
207 
208  TPCV1P0_PADK_SR *p;
209  p = padk[sector];
210  if(p == NULL)
211  {
212  p = new TPCV1P0_PADK_SR(sector, this);
213  if(!p->initialize())
214  {
215  cout << "Error Reading PADK banks, sector=" << sector
216  << ": " << errstr().c_str() << endl;
217  delete p;
218  return NULL;
219  }
220  }
221  padk[sector] = p;
222  return p;
223 }
224 
225 TPCV1P0_Reader::TPCV1P0_Reader(EventReader *er, classname(Bank_TPCP) *ptpc)
226 {
227  pBankTPCP = ptpc; // copy arg into class variable
228 
229  if (!pBankTPCP->test_CRC()) ERROR(ERR_CRC);
230  if (pBankTPCP->swap() < 0) ERROR(ERR_SWAP);
231  pBankTPCP->header.CRC = 0;
232 
233  // We can have a padk for each of 24 sectors
234  for(int i=0;i<TPC_SECTORS;i++)
235  {
236  padk[i] = NULL;
237  }
238 }
239 
240 TPCV1P0_Reader::~TPCV1P0_Reader()
241 {
242  // cout << "TPCV1P0 destructor" << endl;
243 
244  // Delete Sector Readers buffers (The actual readers are deleted by client)
245 
246  // Delete PADK's
247  for(int i=0;i<TPC_SECTORS;i++)
248  {
249  if(padk[i] != NULL) delete padk[i];
250  }
251 }
252 
253 int TPCV1P0_Reader::MemUsed()
254 {
255  return 0;
256 }
257 
258 // -----------------------------------------------------
259 // Here lie bank retrieval functions
260 // ---- These NAVAGATE to the raw banks
261 // -----------------------------------------------------
262 
263 classname(Bank_TPCSECP) *TPCV1P0_Reader::getBankTPCSECP(int hypersector)
264 {
265  if((hypersector <= 0) || (hypersector >= 24))
266  {
267  pERROR(ERR_BAD_ARG);
268  return NULL;
269  }
270  hypersector--; //convert to internal represenation
271 
272  if((!pBankTPCP->HyperSector[hypersector].offset) ||
273  (!pBankTPCP->HyperSector[hypersector].length))
274  {
275  pERROR(ERR_BANK);
276  return NULL;
277  }
278 
279  classname(Bank_TPCSECP) *ptr = (classname(Bank_TPCSECP) *)
280  (((INT32 *)pBankTPCP) +
281  pBankTPCP->HyperSector[hypersector].offset);
282 
283  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
284  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
285  ptr->header.CRC = 0;
286 
287  return ptr;
288 }
289 
290 classname(Bank_TPCRBP) *TPCV1P0_Reader::getBankTPCRBP(int interleaved_rb,
291  classname(Bank_TPCSECP) *secp)
292 {
293  if ((interleaved_rb < 0) || (interleaved_rb >= 12))
294  {
295  pERROR(ERR_BAD_ARG);
296  return NULL;
297  }
298 
299 // printf("getBankTPCRBP RB: %d\n",interleaved_rb);
300 // secp->print();
301 
302  if ((!secp->RcvBoard[interleaved_rb].offset) ||
303  (!secp->RcvBoard[interleaved_rb].length) )
304  {
305  // pERROR(ERR_BANK);
306  return NULL;
307  }
308 
309  classname(Bank_TPCRBP) *ptr = (classname(Bank_TPCRBP) *)
310  (((INT32 *)secp) +
311  secp->RcvBoard[interleaved_rb].offset);
312 
313  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
314  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
315  ptr->header.CRC = 0;
316 
317  return ptr;
318 }
319 
320 classname(Bank_TPCMZP) *TPCV1P0_Reader::getBankTPCMZP(int mz, classname(Bank_TPCRBP) *rbp)
321 {
322  if ((mz < 0) || (mz >= 3))
323  {
324  pERROR(ERR_BAD_ARG);
325  return NULL;
326  }
327 
328  if ((!rbp->Mz[mz].offset) || (!rbp->Mz[mz].length))
329  {
330  pERROR(ERR_BANK);
331  return NULL;
332  }
333 
334  classname(Bank_TPCMZP) *ptr = (classname(Bank_TPCMZP) *)
335  (((INT32 *)rbp) +
336  rbp->Mz[mz].offset);
337 
338  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
339  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
340  ptr->header.CRC = 0;
341 
342 // printf("getBankTPCMZP Mezz: %d\n",mz);
343 // ptr->print();
344 
345  return ptr;
346 }
347 
348 classname(Bank_TPCMZP) *TPCV1P0_Reader::getBankTPCMZP(int sector, int rb, int mz)
349 {
350  if ((sector < 0) || (sector >= TPC_SECTORS))
351  {
352  pERROR(ERR_BAD_ARG);
353  return NULL;
354  }
355  if ((rb < 0) || (rb >= 6))
356  {
357  pERROR(ERR_BAD_ARG);
358  return NULL;
359  }
360  if ((mz < 0) || (mz >= 3))
361  {
362  pERROR(ERR_BAD_ARG);
363  return NULL;
364  }
365 
366  classname(Bank_TPCSECP) *secp = getBankTPCSECP(2*(sector/2)+1);
367  // use odd slots 1,...,23
368  if(!secp) return NULL;
369 
370  classname(Bank_TPCRBP) *rbp;
371  if (sector%2) // internal sector odd->sector even->7..12
372  {
373  rbp = getBankTPCRBP(rb + 6, secp);
374  }
375  else // internal sector even->sector odd->1..6
376  {
377  rbp = getBankTPCRBP(rb, secp);
378  }
379  if(!rbp) return NULL;
380 
381  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(mz,rbp);
382  return mzp;
383 }
384 
385 classname(Bank_TPCADCD) *TPCV1P0_Reader::getBankTPCADCD(int sector, int rb, int mz)
386 {
387  errnum = 0;
388  errstr0[0] = '\0';
389 
390  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
391  if(!mzp) return NULL;
392 
393 // printf(" sector: %d RB: %d MZ: %d\n", sector, rb, mz);
394 // mzp->print();
395 
396  if((!mzp->TPCADCD.offset) || (!mzp->TPCADCD.length))
397  {
398  pERROR(ERR_BANK);
399  return NULL;
400  }
401 
402  classname(Bank_TPCADCD) *ptr = (classname(Bank_TPCADCD) *)
403  (((INT32 *)mzp) +
404  mzp->TPCADCD.offset);
405 
406  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
407  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
408  ptr->header.CRC = 0;
409 
410  return ptr;
411 }
412 
413 classname(Bank_TPCSEQD) *TPCV1P0_Reader::getBankTPCSEQD(int sector, int rb, int mz)
414 {
415  errnum = 0;
416  errstr0[0] = '\0';
417 
418  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
419  if(!mzp) return NULL;
420 
421 // printf(" sector: %d RB: %d MZ: %d\n", sector, rb, mz);
422 // mzp->print();
423 
424  if((!mzp->TPCSEQD.offset) || (!mzp->TPCSEQD.length))
425  {
426  pERROR(ERR_BANK);
427  return NULL;
428  }
429 
430  classname(Bank_TPCSEQD) *ptr = (classname(Bank_TPCSEQD) *)
431  (((INT32 *)mzp) +
432  mzp->TPCSEQD.offset);
433 
434  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
435  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
436  ptr->header.CRC = 0;
437 
438  return ptr;}
439 
440 classname(Bank_TPCADCX) *TPCV1P0_Reader::getBankTPCADCX(int sector, int rb, int mz)
441 {
442  errnum = 0;
443  errstr0[0] = '\0';
444 
445  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
446  if(!mzp) return NULL;
447 
448 // printf(" sector: %d RB: %d MZ: %d\n", sector, rb, mz);
449 // mzp->print();
450 
451  if((!mzp->TPCADCX.offset) || (!mzp->TPCADCX.length))
452  {
453  pERROR(ERR_BANK);
454  return NULL;
455  }
456 
457  classname(Bank_TPCADCX) *ptr = (classname(Bank_TPCADCX) *)
458  (((INT32 *)mzp) +
459  mzp->TPCADCX.offset);
460 
461  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
462  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
463  ptr->header.CRC = 0;
464 
465  return ptr;}
466 
467 classname(Bank_TPCPADK) *TPCV1P0_Reader::getBankTPCPADK(int sector, int rb, int mz)
468 {
469  errnum = 0;
470  errstr0[0] = '\0';
471 
472  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
473  if(!mzp) return NULL;
474 
475 // printf(" sector: %d RB: %d MZ: %d\n", sector, rb, mz);
476 // mzp->print();
477 
478  if((!mzp->TPCPADK.offset) || (!mzp->TPCPADK.length))
479  {
480  pERROR(ERR_BANK);
481  return NULL;
482  }
483 
484  classname(Bank_TPCPADK) *ptr = (classname(Bank_TPCPADK) *)
485  (((INT32 *)mzp) +
486  mzp->TPCPADK.offset);
487 
488  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
489  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
490  ptr->header.CRC = 0;
491 
492  return ptr;
493 };
494 
495 classname(Bank_TPCCPPR) *TPCV1P0_Reader::getBankTPCCPPR(int sector, int rb, int mz)
496 {
497  errnum = 0;
498  errstr0[0] = '\0';
499 
500  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
501  if(!mzp) return NULL;
502 
503  if((!mzp->TPCCPPR.offset) || (!mzp->TPCCPPR.length))
504  {
505  pERROR(ERR_BANK);
506  return NULL;
507  }
508 
509  classname(Bank_TPCCPPR) *ptr = (classname(Bank_TPCCPPR) *)
510  (((INT32 *)mzp) +
511  mzp->TPCCPPR.offset);
512 
513  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
514  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
515  ptr->header.CRC = 0;
516 
517  return ptr;
518 }
519 
520 classname(Bank_TPCADCR) *TPCV1P0_Reader::getBankTPCADCR(int sector, int rb, int mz)
521 {
522  errnum = 0;
523  errstr0[0] = '\0';
524 
525  classname(Bank_TPCMZP) *mzp = getBankTPCMZP(sector, rb, mz);
526  if(!mzp) return NULL;
527 
528  if((!mzp->TPCADCR.offset) || (!mzp->TPCADCR.length))
529  {
530  pERROR(ERR_BANK);
531  return NULL;
532  }
533 
534  classname(Bank_TPCADCR) *ptr = (classname(Bank_TPCADCR) *)
535  (((INT32 *)mzp) +
536  mzp->TPCADCR.offset);
537 
538  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
539  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
540  ptr->header.CRC = 0;
541 
542  return ptr;
543 }
544 
545 classname(Bank_TPCCFGR) *TPCV1P0_Reader::getBankTPCCFGR(int sector, int rb, int mz)
546 {
547  return NULL;
548 }
549 
550 classname(Bank_TPCPEDR) *TPCV1P0_Reader::getBankTPCPEDR(int sector, int rb, int mz)
551 {
552  return NULL;
553 }
554 
555 
556 classname(Bank_TPCRMSR) *TPCV1P0_Reader::getBankTPCRMSR(int sector, int rb, int mz)
557 {
558  return NULL;
559 }
560 
561 classname(Bank_TPCGAINR) *TPCV1P0_Reader::getBankTPCGAINR(int sector, int rb, int mz)
562 {
563  return NULL;
564 }
565 
566 classname(Bank_TPCBADR) *TPCV1P0_Reader::getBankTPCBADR(int sector, int rb, int mz)
567 {
568  return NULL;
569 }
570 
Definition: rb.hh:21
Definition: TPCV1P0.hh:217