StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FPD_Reader.cxx
1 /***************************************************************************
2 * $Id: FPD_Reader.cxx,v 1.4 2007/12/24 06:04:11 fine Exp $
3 * Author: Akio Ogawa
4 ***************************************************************************
5 * Description: FPD Event Reader
6 ***************************************************************************
7 * $Log: FPD_Reader.cxx,v $
8 * Revision 1.4 2007/12/24 06:04:11 fine
9 * introduce OLDEVP namespace to allow ole and new EVP library concurrently
10 *
11 * Revision 1.3 2003/10/02 22:33:35 jeromel
12 * Cosmetic change
13 *
14 * Revision 1.2 2003/05/22 20:48:17 perev
15 * method added to remove unprintef chars
16 *
17 * Revision 1.1 2002/01/17 17:19:58 akio
18 * First version of FPD daq reader
19 *
20 **************************************************************************/
21 #include "FPD_Reader.hh"
22 
23 using namespace OLDEVP;
24 
25 void FPD_Reader::ProcessEvent(const Bank_FPDP * FpdPTR) {
26  unsigned short numberOfDataWords;
27  int dataDWord;
28  //FpdPTR->print();
29  unsigned short Token = FpdPTR->header.Token;
30  if (Token==0){
31  cout << "FPD_Reader: do not know how to handle token==0"<<endl;
32  //return;
33  }
34  mTheFpdArray.EventNumber = Token;
35  mTheFpdArray.ByteSwapped = 0x04030201;
36 
37  //Read ADC Bank
38  FPDDATA * FpdAdcD;
39  if (FpdPTR->AdcPTR.length>0) {
40  FpdAdcD = (FPDDATA *) ((unsigned long *)FpdPTR + FpdPTR->AdcPTR.offset);
41  //FpdAdcD->print();
42 
43  FpdAdcD->swap();
44  cout << "FPD_Reader(FPDADCD): Got a bank named " << FpdAdcD->bankTypeString() << endl;
45  if (FpdAdcD->header.Token!=Token){
46  cout << "FPD_Reader: Token mismatch FPDP "<< Token<<" "
47  << " FPDADCD " << FpdAdcD->header.Token << endl;
48  mTheFpdArray.EventNumber=0;
49  }
50  numberOfDataWords=FpdAdcD->header.BankLength - (INT32)sizeof(FpdAdcD->header)/4;
51  if (numberOfDataWords!=FPDP_NUM_ADC_CHANNELS/2){
52  cout << "FPD_Reader: ADCD #channels mismatch " << numberOfDataWords << endl;
53  if (numberOfDataWords>FPDP_NUM_ADC_CHANNELS/2) numberOfDataWords=FPDP_NUM_ADC_CHANNELS/2;
54  }
55  // decode and fill data structure
56  for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
57  mTheFpdArray.AdcData[dataDWord]=FpdAdcD->data[dataDWord];
58  }
59  }
60 
61  //Read TDC Bank
62  FPDDATA * FpdTdcD;
63  if (FpdPTR->TdcPTR.length>0) {
64  FpdTdcD = (FPDDATA *) ((unsigned long *)FpdPTR + FpdPTR->TdcPTR.offset);
65  //FpdTdcD->print();
66  FpdTdcD->swap();
67  cout << "FPD_Reader(FPDTDCD): Got a bank named " << FpdTdcD->bankTypeString() << endl;
68  if (FpdTdcD->header.Token!=Token){
69  cout << "FPD_Reader: Token mismatch FPDP "<< Token
70  << " FPDTDCD " << FpdTdcD->header.Token << endl;
71  mTheFpdArray.EventNumber=0;
72  }
73  numberOfDataWords=FpdTdcD->header.BankLength - (INT32)sizeof(FpdTdcD->header)/4;
74  if (numberOfDataWords!=FPDP_NUM_TDC_CHANNELS/2){
75  cout << "FPD_Reader: TDCD #channels mismatch " << numberOfDataWords << endl;
76  if (numberOfDataWords>FPDP_NUM_TDC_CHANNELS/2) numberOfDataWords=FPDP_NUM_TDC_CHANNELS/2;
77  }
78  // decode and fill data structure
79  for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
80  mTheFpdArray.TdcData[dataDWord]=FpdTdcD->data[dataDWord];
81  }
82  }
83 
84  //Read REG Bank...
85  FPDDATA * FpdRegD;
86  if (FpdPTR->RegPTR.length>0) {
87  FpdRegD = (FPDDATA *) ((unsigned long *)FpdPTR + FpdPTR->RegPTR.offset);
88  //FpdRegD->print();
89  FpdRegD->swap();
90  cout << "FPD_Reader(FPDREGD): Got a bank named " << FpdRegD->bankTypeString() << endl;
91  if (FpdRegD->header.Token!=Token){
92  cout << "FPD_Reader: Token mismatch FPDP "<< Token
93  << " FPDREGD " << FpdRegD->header.Token << endl;
94  mTheFpdArray.EventNumber=0;
95  }
96  numberOfDataWords=FpdRegD->header.BankLength - (INT32)sizeof(FpdRegD->header)/4;
97  if (numberOfDataWords!=FPDP_NUM_REG_CHANNELS/2){
98  cout << "FPD_Reader: REGD #channels mismatch " << numberOfDataWords << endl;
99  if (numberOfDataWords>FPDP_NUM_REG_CHANNELS/2) numberOfDataWords=FPDP_NUM_REG_CHANNELS/2;
100  }
101  // decode and fill data structure
102  for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
103  mTheFpdArray.RegData[dataDWord]=FpdRegD->data[dataDWord];
104  }
105  }
106 
107  //Read PED Bank
108  FPDDATA * FpdPedD;
109  if (FpdPTR->PedPTR.length>0) {
110  FpdPedD = (FPDDATA *) ((unsigned long *)FpdPTR + FpdPTR->PedPTR.offset);
111  //FpdPedD->print();
112  FpdPedD->swap();
113  cout << "FPD_Reader(FPDPEDD): Got a bank named " << FpdPedD->bankTypeString() << endl;
114  if (FpdPedD->header.Token!=Token){
115  cout << "FPD_Reader: Token mismatch FPDP "<< Token
116  << " FPDPEDD " << FpdPedD->header.Token << endl;
117  mTheFpdArray.EventNumber=0;
118  }
119  numberOfDataWords=FpdPedD->header.BankLength - (INT32)sizeof(FpdPedD->header)/4;
120  if (numberOfDataWords!=FPDP_NUM_PED_CHANNELS/2){
121  cout << "FPD_Reader: PEDD #channels mismatch " << numberOfDataWords << endl;
122  if (numberOfDataWords>FPDP_NUM_PED_CHANNELS/2) numberOfDataWords=FPDP_NUM_PED_CHANNELS/2;
123  }
124  // decode and fill data structure
125  for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
126  mTheFpdArray.PedData[dataDWord]=FpdPedD->data[dataDWord];
127  }
128  }
129 
130  //Read SCL Bank
131  FPDSCLDATA * FpdSclD;
132  if (FpdPTR->SclPTR.length>0) {
133  FpdSclD = (FPDSCLDATA *) ((unsigned long *)FpdPTR + FpdPTR->SclPTR.offset);
134  //FpdSclD->print();
135  FpdSclD->swap();
136  cout << "FPD_Reader(FPDSCL): Got a bank named " << FpdSclD->bankTypeString() << endl;
137  if (FpdSclD->header.Token!=Token){
138  cout << "FPD_Reader: Token mismatch FPDP "<< Token
139  << " FPDSCL " << FpdSclD->header.Token << endl;
140  mTheFpdArray.EventNumber=0;
141  }
142  numberOfDataWords=FpdSclD->header.BankLength - (INT32)sizeof(FpdSclD->header)/4;
143  if (numberOfDataWords!=FPDP_NUM_SCL_CHANNELS){
144  cout << "FPD_Reader: SCLD #channels mismatch " << numberOfDataWords << endl;
145  if (numberOfDataWords>FPDP_NUM_SCL_CHANNELS) numberOfDataWords=FPDP_NUM_SCL_CHANNELS;
146  }
147  // decode and fill data structure
148  for (dataDWord=0; dataDWord < numberOfDataWords; dataDWord++) {
149  mTheFpdArray.SclData[dataDWord]=FpdSclD->data[dataDWord];
150  }
151  }
152 
153  //Read BBC ADC Bank
154  FPDDATA * BbcAdcD;
155  if (FpdPTR->BbcAdcPTR.length>0) {
156  BbcAdcD = (FPDDATA *) ((unsigned long *)FpdPTR + FpdPTR->BbcAdcPTR.offset);
157  //FpdPedD->print();
158  BbcAdcD->swap();
159  cout << "FPD_Reader(BBCDAT): Got a bank named " << BbcAdcD->bankTypeString() << endl;
160  if (BbcAdcD->header.Token!=Token){
161  cout << "FPD_Reader: Token mismatch FPDP "<< Token
162  << " BBCDAT " << BbcAdcD->header.Token << endl;
163  mTheFpdArray.EventNumber=0;
164  }
165  numberOfDataWords=BbcAdcD->header.BankLength - (INT32)sizeof(BbcAdcD->header)/4;
166  if (numberOfDataWords!=FPDP_BBC_NUM_ADC_CHANNELS/2){
167  cout << "FPD_Reader: BBCDAT #channels mismatch " << numberOfDataWords << endl;
168  if (numberOfDataWords>FPDP_BBC_NUM_ADC_CHANNELS/2) numberOfDataWords=FPDP_BBC_NUM_ADC_CHANNELS/2;
169  }
170  // decode and fill data structure
171  for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
172  mTheFpdArray.BbcAdcData[dataDWord]=BbcAdcD->data[dataDWord];
173  }
174  }
175 
176  //Read BBC Pedestal Bank
177  FPDDATA * BbcPedD;
178  if (FpdPTR->BbcPedPTR.length>0) {
179  BbcPedD = (FPDDATA *) ((unsigned long *)FpdPTR + FpdPTR->BbcPedPTR.offset);
180  //FpdPedD->print();
181  BbcPedD->swap();
182  cout << "FPD_Reader(BBCPED): Got a bank named " << BbcPedD->bankTypeString() << endl;
183  if (BbcPedD->header.Token!=Token){
184  cout << "FPD_Reader: Token mismatch FPDP "<< Token
185  << " BBCPED " << BbcPedD->header.Token << endl;
186  mTheFpdArray.EventNumber=0;
187  }
188  numberOfDataWords=BbcPedD->header.BankLength - (INT32)sizeof(BbcPedD->header)/4;
189  if (numberOfDataWords!=FPDP_BBC_NUM_PED_CHANNELS/2){
190  cout << "FPD_Reader: BBCPED #channels mismatch " << numberOfDataWords << endl;
191  if (numberOfDataWords>FPDP_BBC_NUM_PED_CHANNELS/2) numberOfDataWords=FPDP_BBC_NUM_PED_CHANNELS/2;
192  }
193  // decode and fill data structure
194  for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
195  mTheFpdArray.BbcPedData[dataDWord]=BbcPedD->data[dataDWord];
196  }
197  }
198  //Read BBC Scalar Bank
199  FPDSCLDATA * BbcSclD;
200  if (FpdPTR->BbcSclPTR.length>0) {
201  BbcSclD = (FPDSCLDATA *) ((unsigned long *)FpdPTR + FpdPTR->BbcSclPTR.offset);
202  //FpdPedD->print();
203  BbcSclD->swap();
204  cout << "FPD_Reader(BBCSCL): Got a bank named " << BbcSclD->bankTypeString() << endl;
205  if (BbcSclD->header.Token!=Token){
206  cout << "FPD_Reader: Token mismatch FPDP "<< Token
207  << " BBCSCLD " << BbcSclD->header.Token << endl;
208  mTheFpdArray.EventNumber=0;
209  }
210  numberOfDataWords=BbcSclD->header.BankLength - (INT32)sizeof(BbcSclD->header)/4;
211  if (numberOfDataWords!=FPDP_BBC_NUM_SCL_CHANNELS){
212  cout << "FPD_Reader: BBCSCL #channels mismatch " << numberOfDataWords << endl;
213  if (numberOfDataWords>FPDP_BBC_NUM_SCL_CHANNELS) numberOfDataWords=FPDP_BBC_NUM_SCL_CHANNELS/2;
214  }
215  // decode and fill data structure
216  for (dataDWord=0; dataDWord < numberOfDataWords; dataDWord++) {
217  mTheFpdArray.BbcSclData[dataDWord]=BbcSclD->data[dataDWord];
218  }
219  }
220 
221 }
222 
223 FPD_Reader::FPD_Reader(EventReader *er, Bank_FPDP *pFPDP)
224 {
225  pBankFPDP = pFPDP;
226  ercpy = er;
227  if (!pBankFPDP->test_CRC()) {
228  printf("CRC error in FPDP: %s %d\n",__FILE__,__LINE__) ;
229  }
230  if (pBankFPDP->swap() < 0) {
231  printf("swap error in FPDP: %s %d\n",__FILE__,__LINE__) ;
232  }
233 
234  pBankFPDP->header.CRC = 0;
235  int Token = pBankFPDP->header.Token;
236  Bank_DATAP *dp = (Bank_DATAP *)ercpy->getDATAP();
237  if(Token != dp->header.Token){
238  printf("Token mismatch between global %d and FPD %d\n",dp->header.Token,Token);
239  }
240  ProcessEvent(pBankFPDP);
241 }
242 
243 
244 unsigned short FPD_Reader::GetAdc(int id){
245  if ((id<0) || (id>FPDP_NUM_ADC_CHANNELS-1)){
246  cout << "FPD_Reader::GetAdc id out of range " << id << endl;
247  return 0;
248  }
249  return mTheFpdArray.AdcData[id];
250 }
251 
252 
253 unsigned short FPD_Reader::GetTdc(int id){
254  if ((id<0) || (id>FPDP_NUM_TDC_CHANNELS-1)){
255  cout << "FPD_Reader::GetTdc id out of range " << id << endl;
256  return 0;
257  }
258  return mTheFpdArray.TdcData[id];
259 }
260 
261 unsigned short FPD_Reader::GetReg(int id){
262  if ((id<0) || (id>FPDP_NUM_REG_CHANNELS-1)){
263  cout << "FPD_Reader::GetReg id out of range " << id << endl;
264  return 0;
265  }
266  return mTheFpdArray.RegData[id];
267 }
268 
269 unsigned short FPD_Reader::GetPed(int id){
270  if ((id<0) || (id>FPDP_NUM_PED_CHANNELS-1)){
271  cout << "FPD_Reader::GetPed id out of range " << id << endl;
272  return 0;
273  }
274  return mTheFpdArray.PedData[id];
275 }
276 
277 unsigned int FPD_Reader::GetScl(int id){
278  if ((id<0) || (id>FPDP_NUM_SCL_CHANNELS-1)){
279  cout << "FPD_Reader::GetScl id out of range " << id << endl;
280  return 0;
281  }
282  return mTheFpdArray.SclData[id];
283 }
284 
285 unsigned short FPD_Reader::GetBbcAdc(int id){
286  if ((id<0) || (id>FPDP_BBC_NUM_ADC_CHANNELS-1)){
287  cout << "FPD_Reader::GetBbcAdc id out of range " << id << endl;
288  return 0;
289  }
290  return mTheFpdArray.BbcAdcData[id];
291 }
292 
293 unsigned short FPD_Reader::GetBbcPed(int id){
294  if ((id<0) || (id>FPDP_BBC_NUM_PED_CHANNELS-1)){
295  cout << "FPD_Reader::GetBbcPed id out of range " << id << endl;
296  return 0;
297  }
298  return mTheFpdArray.BbcPedData[id];
299 }
300 
301 unsigned int FPD_Reader::GetBbcScl(int id){
302  if ((id<0) || (id>FPDP_BBC_NUM_SCL_CHANNELS-1)){
303  cout << "FPD_Reader::GetBbcScl id out of range " << id << endl;
304  return 0;
305  }
306  return mTheFpdArray.BbcSclData[id];
307 }
308 
309 unsigned int FPD_Reader::GetEventNumber(){
310  return mTheFpdArray.EventNumber;
311 }
312 
313 void FPD_Reader::printRawData(){
314  cout << "StDaqLib/FPD/FPD_Reader Printing Raw Data...";
315  cout << "\n --- ADCD: ";
316  for (int i=0;i<FPDP_NUM_ADC_CHANNELS;i++) cout << " " << mTheFpdArray.AdcData[i];
317  cout << "\n --- TDCD: ";
318  for (int i=0;i<FPDP_NUM_TDC_CHANNELS;i++) cout << " " << mTheFpdArray.TdcData[i];
319  cout << "\n --- REG: ";
320  for (int i=0;i<FPDP_NUM_REG_CHANNELS;i++) cout << " " << mTheFpdArray.RegData[i];
321  cout << "\n --- PED: ";
322  for (int i=0;i<FPDP_NUM_PED_CHANNELS;i++) cout << " " << mTheFpdArray.PedData[i];
323  cout << "\n --- SCL: ";
324  for (int i=0;i<FPDP_NUM_SCL_CHANNELS;i++) cout << " " << mTheFpdArray.SclData[i];
325  cout << "\n --- BBC ADC: ";
326  for (int i=0;i<FPDP_BBC_NUM_ADC_CHANNELS;i++) cout << " " << mTheFpdArray.BbcAdcData[i];
327  cout << "\n --- BBC Ped: ";
328  for (int i=0;i<FPDP_BBC_NUM_PED_CHANNELS;i++) cout << " " << mTheFpdArray.BbcPedData[i];
329  cout << "\n --- BBC ADC: ";
330  for (int i=0;i<FPDP_BBC_NUM_SCL_CHANNELS;i++) cout << " " << mTheFpdArray.BbcSclData[i];
331  cout << "\nStDaqLib/FPD/FPD_Reader Done Printing Raw Data..." << endl;
332 }