9 #include "PMD_Reader.hh"
13 using namespace OLDEVP;
15 int PMD_Reader::ProcessEvent(
const Bank_PMDP * PmdPTR)
19 Token=PmdPTR->header.Token;
20 printf(
"PMD Token = %d\n", Token);
24 mThePmd.max_channels = 2*PMD_CRAMS_MAX*2*PMD_CRAMS_CH_MAX ;
27 for(sec=0; sec<2; sec++) {
28 if(PmdPTR->sec[sec].length == 0)
continue;
31 if(strncmp(secp->header.BankType,
"PMDSECP",7))
34 cout<<
" PMDSECP error in header name**"<<endl;
35 sprintf(str0,
"Not PMDSECP");
36 ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
return 0;
42 cout<<
"error in CRC**"<<endl;
43 sprintf(str0,
"Not PMDSECP");
44 ercpy->fprintError(ERR_CRC,__FILE__,__LINE__,str0);
return 0;
49 cout<<
"error in swap**"<<endl;
50 sprintf(str0,
" PMDSECP");
51 ercpy->fprintError(ERR_SWAP,__FILE__,__LINE__,str0);
return 0;
54 for( type=0; type < 4; type ++) {
56 if(secp->type[type].length ==0 )
continue;
63 if(strncmp(adcd->header.BankType,
"PMDADCD",7))
66 cout<<
" PMDADCD error in header name**"<<endl;
67 sprintf(str0,
"Not PMDADCD");
68 ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
return 0;
70 ret = adcReader(sec, adcd);
71 if(ret) mThePmd.channels += ret;
80 if(strncmp(pedr->header.BankType,
"PMDPEDR",7))
83 cout<<
" PMDPEDR error in header name**"<<endl;
84 sprintf(str0,
"Not PMDPEDR");
85 ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
return 0;
87 ret = pedReader(sec, type, pedr);
88 if(ret) mThePmd.channels += ret;
98 if(strncmp(rmsr->header.BankType,
"PMDRMSR",7))
101 cout<<
" PMDRMSR error in header name**"<<endl;
102 sprintf(str0,
"Not PMDRMSR");
103 ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
return 0;
105 ret = pedReader(sec, type, rmsr);
106 if(ret) mThePmd.channels += ret;
115 if(strncmp(thrr->header.BankType,
"PMDTHRR",7))
118 cout<<
" PMDTHRR error in header name**"<<endl;
119 sprintf(str0,
"Not PMDTHRR");
120 ercpy->fprintError(ERR_BAD_HEADER,__FILE__,__LINE__, str0);
return 0;
122 ret = pedReader(sec, type, thrr);
123 if(ret) mThePmd.channels += ret;
137 int items = adcd->header.BankLength -(INT32)
sizeof(
Bank_Header)/4 ;
139 unsigned int *datum ;
141 unsigned int cram, blk ;
142 unsigned int ch_num ;
145 if(items <= 0)
return 0 ;
148 datum = (
unsigned int *)adcd->data ;
154 unsigned int *end_datum = datum + items ;
156 for(end_datum=datum+items;datum<end_datum;) {
157 unsigned int tmp = *datum ;
160 cram = (tmp & 0xFF000000) >> 24 ;
161 blk = (tmp & 0x00FF0000) >> 16 ;
162 ch = (tmp & 0x0000FFFF) ;
164 mThePmd.no_of_channels_in_cram_blk[sec][cram][blk] = ch;
166 if(cram >= PMD_CRAMS_MAX) {
167 printf(
"PMD: Bad Cram number %d\n",cram) ;
171 if((blk != 0) && (blk != 1)) {
172 printf(
"PMD: Bad Block %d in Cram %d\n",blk,cram) ;
176 if(ch > PMD_CRAMS_CH_MAX) {
177 printf(
"PMD: too many channels in Cram %d, Block %d: %d\n",cram,blk,ch) ;
187 if(val & 0x40000000) {
188 unsigned int channel = (val & 0x7ff000) >> 12 ;
191 if(channel >= PMD_CRAMS_CH_MAX) {
192 printf(
"PMD: channel too big in Cram %d, Block %d: %d\n",cram,blk,channel) ;
195 mThePmd.adc[sec][cram][blk][channel] = val ;
210 printf(
" This PMD_Reader in ctor , %s. \n", __FILE__ );
212 pBankPMDP->header.BankType[7]=0;
213 cout<<
"header bank type "<<pBankPMDP->header.BankType<<endl;
214 if (!pBankPMDP->test_CRC()) {
215 printf(
"CRC error in PMDP: %s %d\n",__FILE__,__LINE__) ;
218 if (pBankPMDP->swap() < 0) {
219 printf(
"swap error in PMDP: %s %d\n",__FILE__,__LINE__) ;
222 pBankPMDP->header.CRC = 0;
225 int Token = pBankPMDP->header.Token;
227 if(Token !=dp->header.Token){
228 printf(
"Token mismatch between global %d and PMD %d\n",dp->header.Token,Token);
231 for(
int sec=0; sec < 2; sec++){
232 for(
int cram=0; cram<PMD_CRAMS_MAX; cram++){
233 for(
int blk=0; blk < 2; blk ++){
234 for(
int channel=0; channel<PMD_CRAMS_CH_MAX; channel++){
235 mThePmd.adc[sec][cram][blk][channel] = 0;
236 mThePmd.ped[sec][cram][blk][channel] = 0;
237 mThePmd.rms[sec][cram][blk][channel] = 0;
238 mThePmd.thr[sec][cram][blk][channel] = 0;
246 ProcessEvent(pBankPMDP);
254 int PMD_Reader::NPMDHits()
272 int PMD_Reader::NCPVHits()
290 int PMD_Reader::pedReader(
int sec,
int type,
Bank_PMDPEDR *pedr)
293 int items = pedr->header.BankLength -(INT32)
sizeof(
Bank_Header)/4 ;
294 printf(
"intem = %d, 1st=%d, 3nd=%d\n", items, pedr->header.BankLength, (INT32)
sizeof(
Bank_Header)/4);
295 unsigned int *datum ;
300 if(items <= 0)
return 0 ;
302 datum = (
unsigned int *)pedr->data ;
308 unsigned int *end_datum = datum + items ;
310 for(end_datum=datum+items;datum<end_datum;) {
312 unsigned int tmp = (*datum) ;
315 cram = (tmp & 0x7F00) >> 8 ;
316 blk = (tmp & 0x00FF) ;
318 valid = tmp & 0x8000 ;
321 ch = PMD_CRAMS_CH_MAX ;
331 if(cram >= PMD_CRAMS_MAX) {
332 printf(
"PMD: Bad CRAM number %d",cram) ;
336 if((blk != 0) && (blk != 1)) {
337 printf(
"PMD: Bad Block %d in CRAM %d",blk,cram) ;
342 for(channel=0;channel<ch;channel++) {
353 mThePmd.ped[sec][cram][blk][channel] = val;
356 mThePmd.rms[sec][cram][blk][channel] = val ;
359 mThePmd.thr[sec][cram][blk][channel] = val ;
PMD_Reader(EventReader *er, Bank_PMDP *pPMDP)
Process PMD+CPV events.
int adcReader(int sec, Bank_PMDADCD *adcd)
PMD_Reader destructor.