StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerDataReader.cxx
1 #include <iostream>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <strings.h>
7 #include "trgStructuresVer0x22.h"
8 #include "trgUtil.h"
9 
10 #include "StTriggerDataReader.h"
11 
12 ClassImp(StTriggerDataReader)
13 
14 typedef struct {
15  unsigned short TrgDataBytes;
16  unsigned short TrgFiller;
17 } TrgEvtHeader;
18 TrgEvtHeader trgHead;
19 
20 TrgDataType TrgData;
21 
22 unsigned int BunchCrossingId(unsigned short b3, unsigned short b10, unsigned short b11){
23  unsigned long long bxinghi,bxing1,bxinglo,bxing,bx0,bx1,bx2;
24  int b120;
25  bxinghi = b3;
26  bxing1 = b10;
27  bxinglo = (bxing1 << 16) + b11;
28  bxing = (bxinghi << 32) + bxinglo;
29  bx0 = bxing;
30  bx1 = bx0/120;
31  bx2 = bx1 * 120;
32  b120 = bx0 - bx2;
33  return (unsigned int)(b120);
34 }
35 
36 unsigned int BunchCrossingId7bit(unsigned short b2){
37  int b7=0, b7dat;
38  b7dat = b2;
39  b7 = b7dat & 0x7f;
40  return b7;
41 }
42 
43 StTriggerDataReader::StTriggerDataReader(const char *name):StMaker(name)
44 {
45  mFile=0;
46  cout << "Constructing StTriggerDataReader with name=" << name << endl;
47 }
48 
49 Int_t StTriggerDataReader::OpenFile(char* file){
50  if ( (mFile= fopen (file, "r") )==NULL ) {
51  printf("Error opening data file %s\n",file);
52  return kStErr;
53  }
54  printf("Opening data file %s\n",file);
55  return kStOK;
56 }
57 
58 Int_t StTriggerDataReader::CloseFile(){
59  if (mFile){
60  printf("Closing trigger data file\n");
61  fclose(mFile);
62  return kStOK;
63  }else{
64  printf("No file to close\n");
65  return kStOK;
66  }
67 }
68 
70  // cout << "StTriggerDataReader Make() starting..................................." << endl;
71  volatile unsigned int *x;
72  int err;
73 
74  if((err=fread((char *)&trgHead.TrgDataBytes, sizeof(char), sizeof(TrgEvtHeader) , mFile)) <=0) {
75  if(err==0) {
76  printf("End of file\n");
77  return kStEOF;
78  }
79  printf("Error in reading TrgHead\n");
80  fclose(mFile);
81  return kStErr;
82  }
83  // printf("DataBytes = 0x%4.4x TrgFilter=0x%4.4x \n",trgHead.TrgDataBytes, trgHead.TrgFiller);
84  // printf("Swapping Header\n");
85  x = (volatile unsigned int*)&trgHead;
86  *x = swapSCC(*x);
87  // printf("DataBytes = 0x%4.4x TrgFilter=0x%4.4x \n",trgHead.TrgDataBytes, trgHead.TrgFiller);
88 
89  if((err=fread((char *)&(TrgData.EvtDesc.TCUdataBytes), sizeof(char),trgHead.TrgDataBytes,mFile))<=0){
90  printf("Error in reading TrgData\n");
91  fclose(mFile);
92  return kStErr;
93  }
94 
95  //printf("NPre=%d NPost=%d\n",TrgData.EvtDesc.npre,TrgData.EvtDesc.npost);
96  //printf("Swapping Data\n");
97  swapTrg(&TrgData, TrgData.EvtDesc.npre, TrgData.EvtDesc.npost);
98  //printf("NPre=%d NPost=%d\n",TrgData.EvtDesc.npre,TrgData.EvtDesc.npost);
99  //printf("Token=%d\n",TrgData.EvtDesc.TrgToken);
100  //printf("trgword=%d tucbit=%x\n",TrgData.EvtDesc.TriggerWord,TrgData.EvtDesc.DSMInput);
101  //printf("Bunch=%d\n",BunchCrossingId(TrgData.TrgSum.DSMdata.BCdata[3],
102  // TrgData.TrgSum.DSMdata.BCdata[10],
103  // TrgData.TrgSum.DSMdata.BCdata[11]));
104  //printf("Bunch7bit=%d\n",BunchCrossingId7bit(TrgData.TrgSum.DSMdata.BCdata[2]));
105  //for (int j=0; j<96; j++) printf("BBC(%d)=%d\n",j,TrgData.rawTriggerDet[0].BBC[j]);
106 
107  mTrg=(void *)(& TrgData);
108  return kStOK;
109 }
Definition: Stypes.h:43
Definition: Stypes.h:40
Definition: Stypes.h:44