20 #include "RICH_Reader.hh"
21 #include "RichEventReader.hh"
24 using namespace OLDEVP;
25 using namespace RICH_READER;
27 void RICH_Reader::ProcessEvent(
const Bank_RICP * RichPTR)
29 int cramBlock, cramBank, dataDWord ;
33 unsigned short channelNum,ADC, Token, SeqWc1, SeqWc2, BankId;
35 Token = RichPTR->header.Token;
37 cout<<
"hack: do not know how to deal with token==0"<<endl;
40 BankId=RICH_CRAM_BANKS;
41 mTheRichArray.NumOfChannels=0;
42 mTheRichArray.EventNumber = Token;
43 for (cramBlock = 0; cramBlock < 2 * RICH_NUM_CRAMS ; cramBlock++) {
45 if(RichPTR->CramPTR[cramBlock].len > 0)
47 RicCramP = (
RICCRAMP *)( (
unsigned long *)RichPTR + RichPTR->CramPTR[cramBlock].off);
51 for(cramBank=0; cramBank < RICH_CRAM_BANKS ; cramBank++) {
53 if(RicCramP->banks[cramBank].len > 0)
55 RicDataD = (
RICDATAD *)((
unsigned long *)RicCramP+RicCramP->banks[cramBank].off);
57 if (BankId==RICH_CRAM_BANKS){
58 BankId=RicDataD->header.BankId;
61 if(BankId!=RicDataD->header.BankId){
62 printf(
"Mismatch BankType or more than one BankType Present!\n");
66 mTheRichArray.BankType = name2str(RicDataD->header.BankType);
67 if (RicDataD->header.Token!=Token){
68 mTheRichArray.EventNumber=0;
69 printf(
"Token mismatch: RICP %d !=RICD %d\n",Token, RicDataD->header.Token);
73 secPTR = &(RicDataD->chanADC[0]);
83 SeqWc1=RicDataD->header.BankLength - (INT32)
sizeof(
Bank_Header)/4 ;
85 mTheRichArray.NumOfChannels +=SeqWc1;
86 for (dataDWord = 0; (INT32)dataDWord < SeqWc1; dataDWord++)
88 channelNum = (secPTR[ dataDWord ] >> 16) & 0x3ff;
89 ADC = secPTR[ dataDWord ] & MAX_ADC;
90 if (channelNum>MAX_CHANNEL_NUM||ADC>MAX_ADC){
91 printf(
"Wrong Data Word: %x\n",secPTR[dataDWord]);
94 if(mTheRichArray.RichMatrix[ channelNum / 6 ][ cramBlock * 6 + channelNum % 6] ==0){
95 mTheRichArray.RichMatrix[ channelNum / 6 ][ cramBlock * 6 + channelNum % 6] = ADC ;
99 printf(
"Channel =%d of block %d has been occupied\n",channelNum, cramBlock);
104 if (SeqWc1!=SeqWc2) {
105 printf(
"Mismatch Word Counts %d !=%d\n",SeqWc1, SeqWc2);
120 if (!pBankRICP->test_CRC()) {
121 printf(
"CRC error in RICP: %s %d\n",__FILE__,__LINE__) ;
124 if (pBankRICP->swap() < 0) {
125 printf(
"swap error in RICP: %s %d\n",__FILE__,__LINE__) ;
128 pBankRICP->header.CRC = 0;
130 int Token = pBankRICP->header.Token;
132 if(Token !=dp->header.Token){
133 printf(
"Token mismatch between global %d and RICH %d\n",dp->header.Token,Token);
139 for(
int i = 0 ; i <RICH_PAD ; i++)
140 for(
int j = 0 ; j < RICH_ROW; j++)
141 mTheRichArray.RichMatrix[i][j] = 0;
144 mTheRichArray.ByteSwapped = 0x04030201;
147 ProcessEvent(pBankRICP);
155 if (!pBankRICP->test_CRC()) {
156 printf(
"CRC error in RICP: %s %d\n",__FILE__,__LINE__) ;
159 if (pBankRICP->swap() < 0) {
160 printf(
"swap error in RICP: %s %d\n",__FILE__,__LINE__) ;
163 pBankRICP->header.CRC = 0;
169 for(
int i = 0 ; i <RICH_PAD ; i++)
170 for(
int j = 0 ; j < RICH_ROW; j++)
171 mTheRichArray.RichMatrix[i][j] = 0;
174 mTheRichArray.ByteSwapped = 0x04030201;
177 ProcessEvent(pBankRICP);
181 unsigned short RICH_Reader::GetADCFromCoord(
int x,
int y)
183 return mTheRichArray.RichMatrix[x][RICH_ROW-y-1];
186 unsigned short RICH_Reader::GetADCFromCramChannel(
int cramBlock,
int channelNum){
187 return mTheRichArray.RichMatrix[ channelNum / 6 ][ cramBlock * 6 + channelNum % 6 ];}
189 unsigned int RICH_Reader::GetEventNumber(){
190 return mTheRichArray.EventNumber ;}
192 unsigned int RICH_Reader::GetNumOfChannels(){
193 return mTheRichArray.NumOfChannels ;}
195 const char * RICH_Reader::GetBankType(){
196 return mTheRichArray.BankType;}
198 int RICH_Reader::IsByteSwapped(){
199 return mTheRichArray.ByteSwapped; }