StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FTPV1P0.cxx
1 /***************************************************************************
2  * $Id: FTPV1P0.cxx,v 1.6 2007/12/24 06:04:13 fine Exp $
3  * Author: M.J. LeVine, J.Klay, H.Huemmler
4  ***************************************************************************
5  * Description: FTPV1P0 implementation
6  *
7  *
8  * change log
9  *
10  * JLK 11-Jul-2000 Added new geometry files to correctly navigate banks
11  ***************************************************************************
12  * $Log: FTPV1P0.cxx,v $
13  * Revision 1.6 2007/12/24 06:04:13 fine
14  * introduce OLDEVP namespace to allow ole and new EVP library concurrently
15  *
16  * Revision 1.5 2001/06/27 22:05:11 jcs
17  * Comment out unsed variable rcvb
18  *
19  * Revision 1.4 2001/06/25 22:57:22 jcs
20  * add correction for FTPC sector handling
21  *
22  * Revision 1.3 2001/06/19 20:51:21 jeromel
23  * Commited for Janet S.
24  *
25  * Revision 1.2 2000/08/18 15:38:58 ward
26  * New FTPC stuff from JKlay and Hummler.
27  *
28  * Revision 1.2 2000/07/11 16:07:58 jklay
29  * Added new include file which properly translates the global sector
30  * numbering 0-59 to the physical mapping as per
31  * http://wwwstar.mppmu.mpg.de/map/mapping.html
32  *
33  * Revision 1.1 2000/01/18 18:01:19 levine
34  * Hummler's implementaiton of FTPC reader. Note that method
35  *
36  * FTPV1P0_ZS_SR::getFeeSequences(int Fee, int Pin, int *nSeq,
37  * Sequence **SeqData)
38  *
39  * causes exit() since the required #include file has not yet been
40  * (correctly) implemented.
41  *
42  *
43  **************************************************************************/
44 
45 #include "FTPV1P0.hh"
46 #include "azim_to_rcvb.h"
47 
48 using namespace OLDEVP;
49 
50 FTPV1P0_PADK_SR::FTPV1P0_PADK_SR(int s, FTPV1P0_Reader *det)
51 {
52  sector = s;
53  detector = det;
54 }
55 
56 int FTPV1P0_PADK_SR::initialize()
57 {
58 
59  // zero out lookup array
60  memset((char *)packed_address, 0, sizeof(packed_address));
61 
62 
63  FTPPADK_entry ent;
64 
65  classname(Bank_FTPPADK) *raw_bank = detector->getBankFTPPADK(sector);
66  if(!raw_bank)
67  {
68 // printf("No PADK DATA, sector %d\n",sector);
69 // printf("ERR: %s\n",detector->errstr0);
70  }
71  else
72  {
73 // printf("PADK DATA for sector %d\n",sector);
74  for(int i=0; i < FTP_MZPADS; i++)
75  {
76  int padrow = raw_bank->index[i].pad_row;
77  int pad = raw_bank->index[i].pad;
78  if((padrow == 0xFF) && (pad == 0xFF)) continue;
79 
80  ent.offset = i;
81 
82  // convert to correct FTPC software padrow
83  padrow = ((int)(padrow-1)/6)%2+1;
84  place(padrow, pad, &ent);
85  }
86 
87  }
88 
89  return TRUE;
90 }
91 
92 void FTPV1P0_PADK_SR::place(short padrow, short pad, FTPPADK_entry *p)
93 {
94  padrow--; pad--; // use c standard for array
95  packed_address[padrow][pad] = pack(p->offset);
96 }
97 
98 void FTPV1P0_PADK_SR::get(short padrow, short pad, FTPPADK_entry *p)
99 {
100  padrow--; pad--; // use c standard for array
101  unpack(p,packed_address[padrow][pad]);
102 // printf("get row %d pad %d address %d\n", padrow, pad, packed_address[padrow][pad]);
103 }
104 
105 short FTPV1P0_PADK_SR::pack(short offset)
106 {
107  short p = offset; // 10 bits
108  return p;
109 }
110 
111 void FTPV1P0_PADK_SR::unpack(FTPPADK_entry *entry, short paddress)
112 {
113  entry->offset = paddress & 0x03FF;
114 }
115 
116 ZeroSuppressedReader *FTPV1P0_Reader::getZeroSuppressedReader(int sector)
117 {
118 
119  FTPV1P0_ZS_SR *zs = new FTPV1P0_ZS_SR(sector, this);
120  if(!zs->initialize())
121  {
122  delete zs;
123  zs = NULL;
124  }
125  return (ZeroSuppressedReader *)zs;
126 }
127 
128 ADCRawReader *FTPV1P0_Reader::getADCRawReader(int sector)
129 {
130  FTPV1P0_ADCR_SR *adc = new FTPV1P0_ADCR_SR(sector, this);
131  if(!adc->initialize())
132  {
133  delete adc;
134  adc = NULL;
135  }
136  return (ADCRawReader *)adc;
137 }
138 
139 PedestalReader *FTPV1P0_Reader::getPedestalReader(int sector)
140 {
141  FTPV1P0_PEDR_SR *ped = new FTPV1P0_PEDR_SR(sector, this);
142  if(!ped->initialize())
143  {
144  delete ped;
145  ped = NULL;
146  }
147 
148  return (PedestalReader *)ped;
149 }
150 
151 PedestalRMSReader *FTPV1P0_Reader::getPedestalRMSReader(int sector)
152 {
153  FTPV1P0_PRMS_SR *rms = new FTPV1P0_PRMS_SR(sector, this);
154  if(!rms->initialize())
155  {
156  delete rms;
157  rms = NULL;
158  }
159 
160  return (PedestalRMSReader *)rms;
161 }
162 
163 GainReader *FTPV1P0_Reader::getGainReader(int sector)
164 {
165  return NULL;
166 }
167 
168 CPPReader *FTPV1P0_Reader::getCPPReader(int sector)
169 {
170  FTPV1P0_CPP_SR *cpp = new FTPV1P0_CPP_SR(sector, this);
171  if(!cpp->initialize())
172  {
173  delete cpp;
174  cpp = NULL;
175  }
176 
177  return (CPPReader *)cpp;
178 }
179 
180 BadChannelReader *FTPV1P0_Reader::getBadChannelReader(int sector)
181 {
182  return NULL;
183 }
184 
185 ConfigReader *FTPV1P0_Reader::getConfigReader(int sector)
186 {
187  return NULL;
188 }
189 
190 FTPV1P0_PADK_SR *FTPV1P0_Reader::getPADKReader(int sector)
191 {
192 
193  FTPV1P0_PADK_SR *p;
194 
195  if ((sector <= 0) || (sector > 60))
196  {
197  pERROR(ERR_BAD_ARG);
198  return NULL;
199  }
200 
201 // p = padk[sector];
202  p = padk[sector-1]; //JCS
203  if(p == NULL)
204  {
205  p = new FTPV1P0_PADK_SR(sector, this);
206  if(!p->initialize())
207  {
208  cout << "Error Reading PADK banks, sector=" << sector
209  << ": " << errstr().c_str() << endl;
210  delete p;
211  return NULL;
212  }
213  }
214 // padk[sector] = p;
215  padk[sector-1] = p;
216  return p;
217 }
218 
219 FTPV1P0_Reader::FTPV1P0_Reader(EventReader *er, classname(Bank_FTPP) *pftp)
220 {
221  pBankFTPP = pftp; // copy arg into class variable
222  ercpy = er; // squirrel away pointer eventreader for our friends
223 
224  if (!pBankFTPP->test_CRC()) ERROR(ERR_CRC);
225  if (pBankFTPP->swap() < 0) ERROR(ERR_SWAP);
226  pBankFTPP->header.CRC = 0;
227 
228  // We can have a padk for each of 60 sectors
229  for(int i=0;i<FTP_SECTORS;i++)
230  {
231  padk[i] = NULL;
232  }
233 }
234 
235 FTPV1P0_Reader::~FTPV1P0_Reader()
236 {
237 
238  // Delete Sector Readers buffers (The actual readers are deleted by client)
239 
240  // Delete PADK's
241  for(int i=0;i<FTP_SECTORS;i++)
242  {
243  if(padk[i] != NULL) delete padk[i];
244  }
245 }
246 
247 int FTPV1P0_Reader::MemUsed()
248 {
249  return 0;
250 }
251 
252 // -----------------------------------------------------
253 // Here lie bank retrieval functions
254 // ---- These NAVIGATE to the raw banks
255 // -----------------------------------------------------
256 
257 classname(Bank_FTPCHAP) *FTPV1P0_Reader::getBankFTPCHAP(int sector)
258 {
259  if((sector <= 0) || (sector > 60))
260  {
261  pERROR(ERR_BAD_ARG);
262  return NULL;
263  }
264 
265 // //JLK This is new 11-July-2000 - we now have geometry files
266  int chamber = sector_map[sector-1][0]; //convert to internal...
267  if((chamber < 0) || (chamber >= 2)) //check...
268  {
269  pERROR(ERR_BAD_ARG);
270  return NULL;
271  }
272 
273 // int chamber = sector;
274  if((!pBankFTPP->Chamber[chamber].offset) ||
275  (!pBankFTPP->Chamber[chamber].length))
276  {
277  pERROR(ERR_BANK);
278  return NULL;
279  }
280 
281  classname(Bank_FTPCHAP) *ptr = (classname(Bank_FTPCHAP) *)
282  (((INT32 *)pBankFTPP) +
283  pBankFTPP->Chamber[chamber].offset);
284 
285  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
286  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
287  ptr->header.CRC = 0;
288 
289 // ptr->print();
290 
291  return ptr;
292 }
293 
294 classname(Bank_FTPRBP) *FTPV1P0_Reader::getBankFTPRBP(int sector,
295  classname(Bank_FTPCHAP) *chap)
296 {
297  if ((sector <= 0) || (sector > 60))
298  {
299  pERROR(ERR_BAD_ARG);
300  return NULL;
301  }
302 
303  //JLK This is new 11-July-2000 - we now have geometry files
304  int rcvb = sector_map[sector-1][1]; if(rcvb>9) rcvb-=10;
305  if ((rcvb < 0) || (rcvb >= 10))
306  {
307  pERROR(ERR_BAD_ARG);
308  return NULL;
309  }
310 
311 // printf("getBankFTPRBP RB: %d\n",rcvb);
312 // chap->print();
313 
314 // cout << "getBankFTPRBP RB Offset: " << chap->RcvBoard[rcvb].offset << endl;
315 // cout << "getBankFTPRBP RB Length: " << chap->RcvBoard[rcvb].length << endl;
316  if ((!chap->RcvBoard[rcvb].offset) ||
317  (!chap->RcvBoard[rcvb].length) )
318  {
319  pERROR(ERR_BANK);
320  return NULL;
321  }
322 
323  classname(Bank_FTPRBP) *ptr = (classname(Bank_FTPRBP) *)
324  (((INT32 *)chap) +
325  chap->RcvBoard[rcvb].offset);
326 
327  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
328  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
329  ptr->header.CRC = 0;
330 
331 // ptr->print();
332  return ptr;
333 }
334 
335 classname(Bank_FTPAZIP) *FTPV1P0_Reader::getBankFTPAZIP(int sector,
336  classname(Bank_FTPRBP) *rbp)
337 {
338  if((sector <= 0) || (sector > 60))
339  {
340  pERROR(ERR_BAD_ARG);
341  return NULL;
342  }
343  //JLK This is new 11-July-2000 - we now have geometry files
344 // int rcvb = sector_map[sector-1][1]; //JCS - apparently unused
345  int intsec = sector_map[sector-1][2];
346 
347  if((intsec < 0) || (intsec >= 3))
348  {
349  pERROR(ERR_BAD_ARG);
350  return NULL;
351  }
352 
353  if((!rbp->Sector[intsec].offset) ||
354  (!rbp->Sector[intsec].length))
355  {
356  pERROR(ERR_BANK);
357  return NULL;
358  }
359 
360  classname(Bank_FTPAZIP) *ptr = (classname(Bank_FTPAZIP) *)
361  (((INT32 *)rbp) +
362  rbp->Sector[intsec].offset);
363 
364  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
365  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
366  ptr->header.CRC = 0;
367 
368 // ptr->print();
369  return ptr;
370 }
371 
372 classname(Bank_FTPMZP) *FTPV1P0_Reader::getBankFTPMZP(int sector,
373  classname(Bank_FTPRBP) *azip)
374 // classname(Bank_FTPAZIP) *azip)
375 {
376 
377  if ((sector <= 0) || (sector > 60))
378  {
379  pERROR(ERR_BAD_ARG);
380  return NULL;
381  }
382 
383  //JLK This is new 11-July-2000 - we now have geometry files
384 // int rcvb = sector_map[sector-1][1]; //JCS - apparently unused
385  int mz = sector_map[sector-1][2]; //SAME as rcvbsector
386  if ((mz < 0) || (mz >= 3))
387  {
388  pERROR(ERR_BAD_ARG);
389  return NULL;
390  }
391 
392 // cout << "getBankFTPMZP Mezz Offset: " << azip->Mz[mz].offset << endl;
393 // cout << "getBankFTPMZP Mezz Length: " << azip->Mz[mz].length << endl;
394 // if ((!azip->Mz[mz].offset) || (!azip->Mz[mz].length))
395 // cout << "getBankFTPMZP Mezz Offset: " << azip->Sector[mz].offset << endl;
396 // cout << "getBankFTPMZP Mezz Length: " << azip->Sector[mz].length << endl;
397  if ((!azip->Sector[mz].offset) || (!azip->Sector[mz].length))
398  {
399  pERROR(ERR_BANK);
400  return NULL;
401  }
402 
403  classname(Bank_FTPMZP) *ptr = (classname(Bank_FTPMZP) *)
404  (((INT32 *)azip) +
405  azip->Sector[mz].offset);
406 // azip->Mz[mz].offset);
407 
408  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
409  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
410  ptr->header.CRC = 0;
411 
412 // printf("getBankFTPMZP Mezz: %d\n",mz);
413 // ptr->print();
414 
415  return ptr;
416 }
417 
418 classname(Bank_FTPMZP) *FTPV1P0_Reader::getBankFTPMZP(int sector)
419 {
420  if ((sector <= 0) || (sector > 60))
421  {
422  pERROR(ERR_BAD_ARG);
423  return NULL;
424  }
425 
426  classname(Bank_FTPCHAP) *chap = getBankFTPCHAP(sector);
427  if(!chap) return NULL;
428 
429  classname(Bank_FTPRBP) *rbp = getBankFTPRBP(sector, chap);
430  if(!rbp) return NULL;
431 
432  classname(Bank_FTPAZIP) *azip = getBankFTPAZIP(sector, rbp);
433  if(!azip) return NULL;
434 
435 //classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector,azip);
436  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector,rbp);
437  if(!mzp)
438  {
439  return NULL;
440  } else return mzp;
441 }
442 
443 classname(Bank_FTPADCD) *FTPV1P0_Reader::getBankFTPADCD(int sector)
444 {
445  errnum = 0;
446  errstr0[0] = '\0';
447 
448  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
449  if(!mzp) return NULL;
450 
451  if((!mzp->FTPADCD.offset) || (!mzp->FTPADCD.length))
452  {
453  pERROR(ERR_BANK);
454  return NULL;
455  }
456 
457  classname(Bank_FTPADCD) *ptr = (classname(Bank_FTPADCD) *)
458  (((INT32 *)mzp) +
459  mzp->FTPADCD.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 
468 classname(Bank_FTPSEQD) *FTPV1P0_Reader::getBankFTPSEQD(int sector)
469 {
470  errnum = 0;
471  errstr0[0] = '\0';
472 
473  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
474  if(!mzp) return NULL;
475 
476  if((!mzp->FTPSEQD.offset) || (!mzp->FTPSEQD.length))
477  {
478  pERROR(ERR_BANK);
479  return NULL;
480  }
481 
482  classname(Bank_FTPSEQD) *ptr = (classname(Bank_FTPSEQD) *)
483  (((INT32 *)mzp) +
484  mzp->FTPSEQD.offset);
485 
486  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
487  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
488  ptr->header.CRC = 0;
489 
490  return ptr;
491 }
492 
493 classname(Bank_FTPADCX) *FTPV1P0_Reader::getBankFTPADCX(int sector)
494 {
495  errnum = 0;
496  errstr0[0] = '\0';
497 
498  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
499  if(!mzp) return NULL;
500 
501  if((!mzp->FTPADCX.offset) || (!mzp->FTPADCX.length))
502  {
503  pERROR(ERR_BANK);
504  return NULL;
505  }
506 
507  classname(Bank_FTPADCX) *ptr = (classname(Bank_FTPADCX) *)
508  (((INT32 *)mzp) +
509  mzp->FTPADCX.offset);
510 
511  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
512  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
513  ptr->header.CRC = 0;
514 
515  return ptr;
516 }
517 
518 classname(Bank_FTPPADK) *FTPV1P0_Reader::getBankFTPPADK(int sector)
519 {
520  errnum = 0;
521  errstr0[0] = '\0';
522 
523  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
524  if(!mzp) return NULL;
525 
526 // printf(" sector: %d\n",sector);
527 // mzp->print();
528 
529  if((!mzp->FTPPADK.offset) || (!mzp->FTPPADK.length))
530  {
531  pERROR(ERR_BANK);
532  return NULL;
533  }
534 
535  classname(Bank_FTPPADK) *ptr = (classname(Bank_FTPPADK) *)
536  (((INT32 *)mzp) +
537  mzp->FTPPADK.offset);
538 
539  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
540  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
541  ptr->header.CRC = 0;
542 
543  return ptr;
544 };
545 
546 classname(Bank_FTPCPPR) *FTPV1P0_Reader::getBankFTPCPPR(int sector)
547 {
548  errnum = 0;
549  errstr0[0] = '\0';
550 
551  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
552  if(!mzp) return NULL;
553 
554  if((!mzp->FTPCPPR.offset) || (!mzp->FTPCPPR.length))
555  {
556  pERROR(ERR_BANK);
557  return NULL;
558  }
559 
560  classname(Bank_FTPCPPR) *ptr = (classname(Bank_FTPCPPR) *)
561  (((INT32 *)mzp) +
562  mzp->FTPCPPR.offset);
563 
564  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
565  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
566  ptr->header.CRC = 0;
567 
568  return ptr;
569 }
570 
571 classname(Bank_FTPADCR) *FTPV1P0_Reader::getBankFTPADCR(int sector)
572 {
573  errnum = 0;
574  errstr0[0] = '\0';
575 
576  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
577  if(!mzp) return NULL;
578 
579  if((!mzp->FTPADCR.offset) || (!mzp->FTPADCR.length))
580  {
581  pERROR(ERR_BANK);
582  return NULL;
583  }
584 
585  classname(Bank_FTPADCR) *ptr = (classname(Bank_FTPADCR) *)
586  (((INT32 *)mzp) +
587  mzp->FTPADCR.offset);
588 
589  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
590  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
591  ptr->header.CRC = 0;
592 
593  return ptr;
594 }
595 
596 classname(Bank_FTPCFGR) *FTPV1P0_Reader::getBankFTPCFGR(int sector)
597 {
598  return NULL;
599 }
600 
601 classname(Bank_FTPPEDR) *FTPV1P0_Reader::getBankFTPPEDR(int sector)
602 {
603  errnum = 0;
604  errstr0[0] = '\0';
605 
606  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
607  if(!mzp) return NULL;
608 
609  if((!mzp->FTPPEDR.offset) || (!mzp->FTPPEDR.length))
610  {
611  pERROR(ERR_BANK);
612  return NULL;
613  }
614 
615  classname(Bank_FTPPEDR) *ptr = (classname(Bank_FTPPEDR) *)
616  (((INT32 *)mzp) +
617  mzp->FTPPEDR.offset);
618 
619  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
620  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
621  ptr->header.CRC = 0;
622 
623  return ptr;
624 
625 }
626 
627 classname(Bank_FTPRMSR) *FTPV1P0_Reader::getBankFTPRMSR(int sector)
628 {
629  errnum = 0;
630  errstr0[0] = '\0';
631 
632  classname(Bank_FTPMZP) *mzp = getBankFTPMZP(sector);
633  if(!mzp) return NULL;
634 
635  if((!mzp->FTPRMSR.offset) || (!mzp->FTPRMSR.length))
636  {
637  pERROR(ERR_BANK);
638  return NULL;
639  }
640 
641  classname(Bank_FTPRMSR) *ptr = (classname(Bank_FTPRMSR) *)
642  (((INT32 *)mzp) +
643  mzp->FTPRMSR.offset);
644 
645  if(!ptr->test_CRC()) { pERROR(ERR_CRC); return NULL; }
646  if(ptr->swap() < 0) { pERROR(ERR_SWAP); return NULL; }
647  ptr->header.CRC = 0;
648 
649  return ptr;
650 
651 }
652 
653 classname(Bank_FTPGAINR) *FTPV1P0_Reader::getBankFTPGAINR(int sector)
654 {
655  cout << "warning: FTPV1P0_Reader::getBankFTPGAINR() not implemented!"<< endl;
656  return NULL;
657 }
658 
659 classname(Bank_FTPBADR) *FTPV1P0_Reader::getBankFTPBADR(int sector)
660 {
661  cout << "warning: FTPV1P0_Reader::getBankFTPBADR() not implemented!"<< endl;
662  return NULL;
663 }
Definition: FTPV1P0.hh:198