21 #include "FPD_Reader.hh"
23 using namespace OLDEVP;
25 void FPD_Reader::ProcessEvent(
const Bank_FPDP * FpdPTR) {
26 unsigned short numberOfDataWords;
29 unsigned short Token = FpdPTR->header.Token;
31 cout <<
"FPD_Reader: do not know how to handle token==0"<<endl;
34 mTheFpdArray.EventNumber = Token;
35 mTheFpdArray.ByteSwapped = 0x04030201;
39 if (FpdPTR->AdcPTR.length>0) {
40 FpdAdcD = (
FPDDATA *) ((
unsigned long *)FpdPTR + FpdPTR->AdcPTR.offset);
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;
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;
56 for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
57 mTheFpdArray.AdcData[dataDWord]=FpdAdcD->data[dataDWord];
63 if (FpdPTR->TdcPTR.length>0) {
64 FpdTdcD = (
FPDDATA *) ((
unsigned long *)FpdPTR + FpdPTR->TdcPTR.offset);
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;
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;
79 for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
80 mTheFpdArray.TdcData[dataDWord]=FpdTdcD->data[dataDWord];
86 if (FpdPTR->RegPTR.length>0) {
87 FpdRegD = (
FPDDATA *) ((
unsigned long *)FpdPTR + FpdPTR->RegPTR.offset);
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;
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;
102 for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
103 mTheFpdArray.RegData[dataDWord]=FpdRegD->data[dataDWord];
109 if (FpdPTR->PedPTR.length>0) {
110 FpdPedD = (
FPDDATA *) ((
unsigned long *)FpdPTR + FpdPTR->PedPTR.offset);
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;
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;
125 for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
126 mTheFpdArray.PedData[dataDWord]=FpdPedD->data[dataDWord];
132 if (FpdPTR->SclPTR.length>0) {
133 FpdSclD = (
FPDSCLDATA *) ((
unsigned long *)FpdPTR + FpdPTR->SclPTR.offset);
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;
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;
148 for (dataDWord=0; dataDWord < numberOfDataWords; dataDWord++) {
149 mTheFpdArray.SclData[dataDWord]=FpdSclD->data[dataDWord];
155 if (FpdPTR->BbcAdcPTR.length>0) {
156 BbcAdcD = (
FPDDATA *) ((
unsigned long *)FpdPTR + FpdPTR->BbcAdcPTR.offset);
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;
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;
171 for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
172 mTheFpdArray.BbcAdcData[dataDWord]=BbcAdcD->data[dataDWord];
178 if (FpdPTR->BbcPedPTR.length>0) {
179 BbcPedD = (
FPDDATA *) ((
unsigned long *)FpdPTR + FpdPTR->BbcPedPTR.offset);
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;
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;
194 for (dataDWord=0; dataDWord < numberOfDataWords*2; dataDWord++) {
195 mTheFpdArray.BbcPedData[dataDWord]=BbcPedD->data[dataDWord];
200 if (FpdPTR->BbcSclPTR.length>0) {
201 BbcSclD = (
FPDSCLDATA *) ((
unsigned long *)FpdPTR + FpdPTR->BbcSclPTR.offset);
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;
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;
216 for (dataDWord=0; dataDWord < numberOfDataWords; dataDWord++) {
217 mTheFpdArray.BbcSclData[dataDWord]=BbcSclD->data[dataDWord];
227 if (!pBankFPDP->test_CRC()) {
228 printf(
"CRC error in FPDP: %s %d\n",__FILE__,__LINE__) ;
230 if (pBankFPDP->swap() < 0) {
231 printf(
"swap error in FPDP: %s %d\n",__FILE__,__LINE__) ;
234 pBankFPDP->header.CRC = 0;
235 int Token = pBankFPDP->header.Token;
237 if(Token != dp->header.Token){
238 printf(
"Token mismatch between global %d and FPD %d\n",dp->header.Token,Token);
240 ProcessEvent(pBankFPDP);
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;
249 return mTheFpdArray.AdcData[id];
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;
258 return mTheFpdArray.TdcData[id];
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;
266 return mTheFpdArray.RegData[id];
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;
274 return mTheFpdArray.PedData[id];
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;
282 return mTheFpdArray.SclData[id];
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;
290 return mTheFpdArray.BbcAdcData[id];
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;
298 return mTheFpdArray.BbcPedData[id];
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;
306 return mTheFpdArray.BbcSclData[id];
309 unsigned int FPD_Reader::GetEventNumber(){
310 return mTheFpdArray.EventNumber;
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;