00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef TOF_READER_HH
00034 #define TOF_READER_HH
00035
00036 #include "StDaqLib/GENERIC/EventReader.hh"
00037 #include "StDaqLib/GENERIC/RecHeaderFormats.hh"
00038 #include <vector>
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #define TOF_MAX_ADC_CHANNELS (48+12+120)
00051
00052 #define TOF_MAX_TDC_CHANNELS (198)
00053 #define TOF_MAX_TOT_CHANNELS 10
00054 #define TOF_MAX_A2D_CHANNELS 32
00055 #define TOF_MAX_SCA_CHANNELS 12
00056
00057
00058 #ifndef _DAQ_FORMATS_H
00059 typedef unsigned int UINT32;
00060 typedef unsigned short UINT16;
00061 typedef unsigned char UINT8 ;
00062 #endif
00063
00064
00065
00066 #ifdef UNIX_LITTLE_ENDIAN
00067 typedef union {
00068 unsigned int data;
00069 struct {
00070 UINT8 slot;
00071 UINT8 channel;
00072 UINT16 data;
00073 } adc;
00074 } tofadc;
00075 typedef union {
00076 unsigned int data;
00077 struct {
00078 UINT8 slot;
00079 UINT8 channel;
00080 UINT16 data;
00081 } tdc;
00082 } toftdc;
00083 typedef union {
00084 unsigned int data;
00085 struct {
00086 UINT8 slot;
00087 UINT8 channel;
00088 short data;
00089 } a2d;
00090 } tofa2d;
00091 typedef union {
00092 unsigned int data;
00093 struct {
00094 unsigned int channel:8;
00095 unsigned int data:24;
00096 } sca;
00097 } tofsca;
00098 #else
00099 typedef union {
00100 unsigned int data;
00101 struct {
00102 UINT16 data;
00103 UINT8 channel;
00104 UINT8 slot;
00105 } adc;
00106 } tofadc;
00107 typedef union {
00108 unsigned int data;
00109 struct {
00110 UINT16 data;
00111 UINT8 channel;
00112 UINT8 slot;
00113 } tdc;
00114 } toftdc;
00115 typedef union {
00116 unsigned int data;
00117 struct {
00118 short data;
00119 UINT8 channel;
00120 UINT8 slot;
00121 } a2d;
00122 } tofa2d;
00123 typedef union {
00124 unsigned int data;
00125 struct {
00126 unsigned int data:24;
00127 unsigned int channel:8;
00128 } sca;
00129 } tofsca;
00130
00131 #endif
00132
00133
00134 struct Bank_TOFP: public Bank {
00135 Pointer AdcPTR;
00136 Pointer TdcPTR;
00137 Pointer A2dPTR;
00138 Pointer ScaPTR;
00139
00140 Pointer DDLRPTR[4];
00141 };
00142 struct TOFADCD: public Bank {
00143 tofadc data[1];
00144 };
00145 struct TOFTDCD: public Bank {
00146
00147 toftdc data[1];
00148 };
00149 struct TOFA2DD: public Bank {
00150 tofa2d data[1];
00151 };
00152 struct TOFSCAD: public Bank {
00153 tofsca data[1];
00154 };
00155
00156 struct TOFDDLR : public Bank {
00157 unsigned int data[1];
00158 };
00159
00160
00161
00162
00163 struct TofRawHit {
00164 unsigned int EventNumber;
00165 unsigned short fiberid;
00166 unsigned short globaltdcchan;
00167 unsigned int tdc;
00168 };
00169 const int LEADING=4;
00170 const int TRAILING=5;
00171
00172
00173 struct TofDATA {
00174 char * BankType;
00175 unsigned int ByteSwapped ;
00176 unsigned int EventNumber;
00177 unsigned short AdcData[TOF_MAX_ADC_CHANNELS];
00178 unsigned short TdcData[TOF_MAX_TDC_CHANNELS];
00179 short A2dData[TOF_MAX_A2D_CHANNELS];
00180 unsigned short ScaData[TOF_MAX_SCA_CHANNELS];
00181
00182 vector<TofRawHit> TofLeadingHits;
00183 vector<TofRawHit> TofTrailingHits;
00184
00185 unsigned int LdTdcData[TOF_MAX_TDC_CHANNELS];
00186 unsigned int TrTdcData[TOF_MAX_TDC_CHANNELS];
00187 unsigned short LdNHit[TOF_MAX_TDC_CHANNELS];
00188 unsigned short TrNHit[TOF_MAX_TDC_CHANNELS];
00189
00190 };
00191
00192
00193
00194 class StTofReaderInterface {
00195 public:
00196 virtual ~StTofReaderInterface(){}
00197
00198 virtual unsigned short GetAdcFromSlat(int)=0;
00199 virtual unsigned short GetTdcFromSlat(int)=0;
00200 virtual short GetTc(int)=0;
00201 virtual unsigned short GetSc(int)=0;
00202 virtual unsigned int GetEventNumber()=0;
00203 virtual unsigned short GetTofpAdc(int)=0;
00204 virtual unsigned short GetTofpTdc(int)=0;
00205 virtual unsigned short GetTofrAdc(int)=0;
00206 virtual unsigned short GetTofrTdc(int)=0;
00207
00208
00209
00210 virtual unsigned int GetLdTdc(int)=0;
00211 virtual unsigned int GetTrTdc(int)=0;
00212 virtual unsigned int GetLdmTdc(int,int)=0;
00213 virtual unsigned int GetTrmTdc(int,int)=0;
00214
00215 virtual unsigned int GetPvpdLdTdc(int)=0;
00216 virtual unsigned int GetPvpdTrTdc(int)=0;
00217 virtual unsigned int GetPvpdLdmTdc(int,int)=0;
00218 virtual unsigned int GetPvpdTrmTdc(int,int)=0;
00219
00220 virtual unsigned short GetNLdHits(int)=0;
00221 virtual unsigned short GetNTrHits(int)=0;
00222
00223 virtual unsigned int GetNLeadingHits()=0;
00224 virtual unsigned int GetLeadingEventNumber(int)=0;
00225 virtual unsigned short GetLeadingFiberId(int)=0;
00226 virtual unsigned short GetLeadingGlobalTdcChan(int)=0;
00227 virtual unsigned int GetLeadingTdc(int)=0;
00228 virtual unsigned int GetNTrailingHits()=0;
00229 virtual unsigned int GetTrailingEventNumber(int)=0;
00230 virtual unsigned short GetTrailingFiberId(int)=0;
00231 virtual unsigned short GetTrailingGlobalTdcChan(int)=0;
00232 virtual unsigned int GetTrailingTdc(int)=0;
00233 };
00234
00235
00236 class TOF_Reader : public StTofReaderInterface {
00237 private:
00238 void ProcessEvent(const Bank_TOFP * TofPTR);
00239 int mTofRawDataVersion;
00240 int mMaxAdcChannels, mMaxTdcChannels;
00241 int mMaxA2dChannels, mMaxScaChannels;
00242 TofDATA mTheTofArray;
00243
00244 int UnpackYear2to4Data(const Bank_TOFP * TofPTR);
00245 int UnpackYear5Data(const Bank_TOFP * TofPTR);
00246
00247
00248 protected:
00249 EventReader *ercpy;
00250 struct Bank_TOFP *pBankTOFP;
00251 public:
00252 TOF_Reader(EventReader *er, Bank_TOFP *pTOFP);
00253 ~TOF_Reader(){};
00254
00255 unsigned short GetAdcFromSlat(int slatId);
00256 unsigned short GetTdcFromSlat(int slatId);
00257
00258 unsigned short GetAdc(int id);
00259 unsigned short GetTdc(int id);
00260 unsigned short GetTofrAdc(int padId);
00261 unsigned short GetTofrTdc(int padId);
00262 unsigned short GetTofpAdc(int SlatId);
00263 unsigned short GetTofpTdc(int SlatId);
00264 unsigned short GetPvpdAdcHigh(int id);
00265 unsigned short GetPvpdAdc(int id);
00266 unsigned short GetPvpdTdc(int id);
00267 unsigned short GetClockAdc();
00268 unsigned short GetTofrTOT(int totId);
00269
00270
00271 unsigned int GetLdTdc(int id);
00272 unsigned int GetTrTdc(int id);
00273 unsigned int GetLdmTdc(int id ,int n);
00274 unsigned int GetTrmTdc(int id,int n);
00275
00276 unsigned int GetPvpdLdTdc(int id);
00277 unsigned int GetPvpdTrTdc(int id );
00278 unsigned int GetPvpdLdmTdc(int id,int n);
00279 unsigned int GetPvpdTrmTdc(int id,int n);
00280
00281 unsigned short GetNLdHits(int id);
00282 unsigned short GetNTrHits(int id);
00283
00284 unsigned int GetNLeadingHits();
00285 unsigned int GetLeadingEventNumber(int ihit);
00286 unsigned short GetLeadingFiberId(int ihit);
00287 unsigned short GetLeadingGlobalTdcChan(int ihit);
00288 unsigned int GetLeadingTdc(int ihit);
00289 unsigned int GetNTrailingHits();
00290 unsigned int GetTrailingEventNumber(int ihit);
00291 unsigned short GetTrailingFiberId(int ihit);
00292 unsigned short GetTrailingGlobalTdcChan(int ihit);
00293 unsigned int GetTrailingTdc(int ihit);
00294
00295 bool year2Data();
00296 bool year3Data();
00297 bool year4Data();
00298
00299 bool year5Data();
00300
00301 short GetTc(int chanId);
00302 unsigned short GetSc(int chanId);
00303 unsigned int GetEventNumber();
00304 void printRawData();
00305 };
00306
00307 TOF_Reader *getTOFReader(EventReader *er);
00308
00309 #endif