StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RICH_Reader.cxx
1 /***************************************************************************
2  * $id: Rich Event Reader.cxx
3  * Author: M.J. LeVine and Jon Gans
4  ***************************************************************************
5  * Description: common definitions for RICH (dummy placeholder)
6  *
7  *
8  * change log
9  * GetNumOfChannels() returns total number of channels
10  * 02-Jul-99 MJL add navigation code to get to RICHP bank
11  * 08-Jul-99 MJL completely change definition - RICH_Reader is independent
12  * class which is handed a pointer at the constructor invocation
13  * 12-Mar-00 XZB Token check, EventNumber=Token, consistancy check, BankId
14  * 21-Apr-00 xzb add in RichEventReader for standalone data file
15  ***************************************************************************
16  * Opens Event From File, Fills Struct
17  *
18  **************************************************************************/
19 
20 #include "RICH_Reader.hh"
21 #include "RichEventReader.hh"
22 #define MAX_ADC 0xFFF
23 
24 using namespace OLDEVP;
25 using namespace RICH_READER;
26 
27 void RICH_Reader::ProcessEvent(const Bank_RICP * RichPTR)
28 {
29  int cramBlock, cramBank, dataDWord ;
30  unsigned int *secPTR;
31  RICCRAMP * RicCramP;
32  RICDATAD * RicDataD;
33  unsigned short channelNum,ADC, Token, SeqWc1, SeqWc2, BankId;
34 
35  Token = RichPTR->header.Token;
36  if (Token==0){
37  cout<<"hack: do not know how to deal with token==0"<<endl;
38  return;
39  }
40  BankId=RICH_CRAM_BANKS; // Init to out of range
41  mTheRichArray.NumOfChannels=0;
42  mTheRichArray.EventNumber = Token;
43  for (cramBlock = 0; cramBlock < 2 * RICH_NUM_CRAMS ; cramBlock++) {
44  // for each C-RAM block
45  if(RichPTR->CramPTR[cramBlock].len > 0)
46  {
47  RicCramP = (RICCRAMP *)( (unsigned long *)RichPTR + RichPTR->CramPTR[cramBlock].off);
48  // Must Make RichPTR and pointer to unsigned int so can add to the offet
49  RicCramP->swap();
50 
51  for(cramBank=0; cramBank < RICH_CRAM_BANKS ; cramBank++) {
52  // for each bank in each block
53  if(RicCramP->banks[cramBank].len > 0)
54  {
55  RicDataD = (RICDATAD *)((unsigned long *)RicCramP+RicCramP->banks[cramBank].off);
56  RicDataD->swap();
57  if (BankId==RICH_CRAM_BANKS){
58  BankId=RicDataD->header.BankId;
59  }
60  else{
61  if(BankId!=RicDataD->header.BankId){
62  printf("Mismatch BankType or more than one BankType Present!\n");
63  return;
64  }
65  }
66  mTheRichArray.BankType = name2str(RicDataD->header.BankType); // move to global bankType
67  if (RicDataD->header.Token!=Token){
68  mTheRichArray.EventNumber=0;
69  printf("Token mismatch: RICP %d !=RICD %d\n",Token, RicDataD->header.Token);
70  }
71  // must use this function as header.BankType does not have terminating NULL
72  // also must Un-swap the banktype as char arrays are not effected by endian changes
73  secPTR = &(RicDataD->chanADC[0]);
74 
75  // go From 0, to the number of ADC/ChannelNumber pairs in back
76  // RicDataD->header.BankLength is total length of Bank
77  // sizeof(BANK_HEADER) is the number of words of the header
78  // their differnce must be the number of ADC/ChannelNumber pairs
79  // NOTE: for completness should probably subtract sizeof(RicDataD->header)/4 instead of
80  // sizeof(BANK_HEADER)/4 however, i am also develuping this code in ROOT
81  // and it has problems with inheritence, so am leave the code like this for portability
82 
83  SeqWc1=RicDataD->header.BankLength - (INT32)sizeof(Bank_Header)/4 ;
84  SeqWc2=0;
85  mTheRichArray.NumOfChannels +=SeqWc1;
86  for (dataDWord = 0; (INT32)dataDWord < SeqWc1; dataDWord++)
87  {
88  channelNum = (secPTR[ dataDWord ] >> 16) & 0x3ff; // Channel in High Bits
89  ADC = secPTR[ dataDWord ] & MAX_ADC; // ADC in Low Bits
90  if (channelNum>MAX_CHANNEL_NUM||ADC>MAX_ADC){
91  printf("Wrong Data Word: %x\n",secPTR[dataDWord]);
92  }
93  else{
94  if(mTheRichArray.RichMatrix[ channelNum / 6 ][ cramBlock * 6 + channelNum % 6] ==0){
95  mTheRichArray.RichMatrix[ channelNum / 6 ][ cramBlock * 6 + channelNum % 6] = ADC ; // put in array that
96  SeqWc2++;
97  }
98  else
99  printf("Channel =%d of block %d has been occupied\n",channelNum, cramBlock);
100  }
101  // represents actual
102  // geometry of pad plane
103  }
104  if (SeqWc1!=SeqWc2) {
105  printf("Mismatch Word Counts %d !=%d\n",SeqWc1, SeqWc2);
106  }
107  }
108  }
109  }
110  }
111 }
112 
113 
114 
115 RICH_Reader::RICH_Reader(EventReader *er, Bank_RICP *pRICP)
116 {
117 
118  pBankRICP = pRICP; //copy into class data member for use by other methods
119  ercpy = er; // squirrel away pointer eventreader for our friends
120  if (!pBankRICP->test_CRC()) {
121  printf("CRC error in RICP: %s %d\n",__FILE__,__LINE__) ;
122  }
123 
124  if (pBankRICP->swap() < 0) {
125  printf("swap error in RICP: %s %d\n",__FILE__,__LINE__) ;
126  }
127 
128  pBankRICP->header.CRC = 0;
129  //do whatever else needs to be done
130  int Token = pBankRICP->header.Token;
131  Bank_DATAP *dp = (Bank_DATAP *)ercpy->getDATAP();
132  if(Token !=dp->header.Token){
133  printf("Token mismatch between global %d and RICH %d\n",dp->header.Token,Token);
134  }
135 
136  // Stuff jon is adding
137 
138  // Initialize RichDATA array to 0's
139  for(int i = 0 ; i <RICH_PAD ; i++)
140  for(int j = 0 ; j < RICH_ROW; j++)
141  mTheRichArray.RichMatrix[i][j] = 0;
142 
143 
144  mTheRichArray.ByteSwapped = 0x04030201; // This is to signal Endianness if struct is saved
145 
146 
147  ProcessEvent(pBankRICP); // switch locations in little endian machines
148 
149  }
150 
151 RICH_Reader::RICH_Reader(RichEventReader *er, Bank_RICP *pRICP)
152 {
153 
154  pBankRICP = pRICP; //copy into class data member for use by other methods
155  if (!pBankRICP->test_CRC()) {
156  printf("CRC error in RICP: %s %d\n",__FILE__,__LINE__) ;
157  }
158 
159  if (pBankRICP->swap() < 0) {
160  printf("swap error in RICP: %s %d\n",__FILE__,__LINE__) ;
161  }
162 
163  pBankRICP->header.CRC = 0;
164  //do whatever else needs to be done
165 
166  // Stuff jon is adding
167 
168  // Initialize RichDATA array to 0's
169  for(int i = 0 ; i <RICH_PAD ; i++)
170  for(int j = 0 ; j < RICH_ROW; j++)
171  mTheRichArray.RichMatrix[i][j] = 0;
172 
173 
174  mTheRichArray.ByteSwapped = 0x04030201; // This is to signal Endianness if struct is saved
175 
176 
177  ProcessEvent(pBankRICP); // switch locations in little endian machines
178 
179  }
180 
181 unsigned short RICH_Reader::GetADCFromCoord(int x,int y)
182 {
183  return mTheRichArray.RichMatrix[x][RICH_ROW-y-1]; // swapping the coordinate
184 }
185 
186 unsigned short RICH_Reader::GetADCFromCramChannel(int cramBlock,int channelNum){
187  return mTheRichArray.RichMatrix[ channelNum / 6 ][ cramBlock * 6 + channelNum % 6 ];}
188 
189 unsigned int RICH_Reader::GetEventNumber(){
190  return mTheRichArray.EventNumber ;}
191 
192 unsigned int RICH_Reader::GetNumOfChannels(){
193  return mTheRichArray.NumOfChannels ;}
194 
195 const char * RICH_Reader::GetBankType(){
196  return mTheRichArray.BankType;}
197 
198 int RICH_Reader::IsByteSwapped(){
199  return mTheRichArray.ByteSwapped; }
200