StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TOF_Reader.hh
1 /***************************************************************************
2 * $Id: TOF_Reader.hh,v 2.3 2012/06/11 16:36:22 fisyak Exp $
3 * Author: Frank Geurts
4 ***************************************************************************
5 * Description: TOF Event Reader
6 ***************************************************************************
7 * $Log: TOF_Reader.hh,v $
8 * Revision 2.3 2012/06/11 16:36:22 fisyak
9 * std namespace
10 *
11 * Revision 2.2 2005/04/12 17:22:36 dongx
12 * Update for year 5 new data format, written by Jing Liu.
13 * Previous interfaces are separated out for convenience.
14 *
15 * Revision 2.1 2004/01/28 02:47:45 dongx
16 * change for year4 run (pVPD+TOFp+TOFr')
17 * - Addtional TOFr' ADCs and TDCs put in
18 * - Add TOTs of TOFr' in, combined in TDCs
19 *
20 *
21 * Revision 2.0 2003/01/29 05:27:25 geurts
22 * New TOF reader capable of reading TOF year3 data (pVPD, TOFp and TOFr).
23 * - Added dedicated retrieval methods for different parts of the data.
24 * - Reader is still capable of dealing year2 (pVPD and TOFp) data.
25 *
26 * Revision 1.3 2001/09/28 18:45:43 llope
27 * modified for compatibility w/ updated StTofMaker
28 *
29 * Revision 1.2 2001/07/13 21:12:34 geurts
30 * changed type of A2D data in struct TofDATA to allow negative values
31 *
32 * Revision 1.1 2001/07/08 21:43:41 geurts
33 * First release
34 *
35 **************************************************************************/
36 #ifndef TOF_READER_HH
37 #define TOF_READER_HH
38 
39 #include "StDaqLib/GENERIC/EventReader.hh"
40 #include "StDaqLib/GENERIC/RecHeaderFormats.hh"
41 #include <vector>
42 
43 // Number of channels for each bank
44 // - Year2 Maxima
45 //#define TOFP_NUM_ADC_CHANNELS 48
46 //#define TOFP_NUM_TDC_CHANNELS 48
47 // - Year3 Maxima
48 // #define TOF_MAX_ADC_CHANNELS (48+12+72)
49 // #define TOF_MAX_TDC_CHANNELS (48+72)
50 // #define TOF_MAX_A2D_CHANNELS 32
51 // #define TOF_MAX_SCA_CHANNELS 12
52 // - Year4 Maxima
53 #define TOF_MAX_ADC_CHANNELS (48+12+120)
54 //Jing Liu #define TOF_MAX_TDC_CHANNELS (48+120+16)
55 #define TOF_MAX_TDC_CHANNELS (198)
56 #define TOF_MAX_TOT_CHANNELS 10
57 #define TOF_MAX_A2D_CHANNELS 32
58 #define TOF_MAX_SCA_CHANNELS 12
59 
60 // unsigned typedefs from /RTS/include/daqFormats.h
61 #ifndef _DAQ_FORMATS_H
62 typedef unsigned int UINT32;
63 typedef unsigned short UINT16;
64 typedef unsigned char UINT8 ;
65 #endif
66 
67 
68 // TOFp raw data structures
69 #ifdef UNIX_LITTLE_ENDIAN
70 typedef union {
71  unsigned int data;
72  struct {
73  UINT8 slot;
74  UINT8 channel;
75  UINT16 data;
76  } adc;
77 } tofadc;
78 typedef union {
79  unsigned int data;
80  struct {
81  UINT8 slot;
82  UINT8 channel;
83  UINT16 data;
84  } tdc;
85 } toftdc;
86 typedef union {
87  unsigned int data;
88  struct {
89  UINT8 slot;
90  UINT8 channel;
91  short data; // can be negative
92  } a2d;
93 } tofa2d;
94 typedef union {
95  unsigned int data;
96  struct {
97  unsigned int channel:8;
98  unsigned int data:24;
99  } sca;
100 } tofsca;
101 #else
102 typedef union {
103  unsigned int data;
104  struct {
105  UINT16 data;
106  UINT8 channel;
107  UINT8 slot;
108  } adc;
109 } tofadc;
110 typedef union {
111  unsigned int data;
112  struct {
113  UINT16 data;
114  UINT8 channel;
115  UINT8 slot;
116  } tdc;
117 } toftdc;
118 typedef union {
119  unsigned int data;
120  struct {
121  short data; // can be negative
122  UINT8 channel;
123  UINT8 slot;
124  } a2d;
125 } tofa2d;
126 typedef union {
127  unsigned int data;
128  struct {
129  unsigned int data:24;
130  unsigned int channel:8;
131  } sca;
132 } tofsca;
133 
134 #endif
135 
136 // TOFp Raw Data Banks
137 struct Bank_TOFP: public Bank {
138  Pointer AdcPTR;
139  Pointer TdcPTR;
140  Pointer A2dPTR;
141  Pointer ScaPTR;
142  //Jing Liu, 02/17/2005, for tofr5
143  Pointer DDLRPTR[4];
144 };
145 struct TOFADCD: public Bank {
146  tofadc data[1];
147 };
148 struct TOFTDCD: public Bank {
149  //unsigned int packedData[1];
150  toftdc data[1];
151 };
152 struct TOFA2DD: public Bank {
153  tofa2d data[1];
154 };
155 struct TOFSCAD: public Bank {
156  tofsca data[1];
157 };
158 //Jing Liu, for tofr5
159 struct TOFDDLR : public Bank {
160  unsigned int data[1];
161 };
162 
163 
164 // Jing Liu, tofr5 raw data structure.
165 //----------------------------------------------------
166 struct TofRawHit {
167  unsigned int EventNumber;
168  unsigned short fiberid; // 0 1 2
169  unsigned short globaltdcchan; // 0,1,...,191,...,198 192 tray channels + 6 pvpd channels
170  unsigned int tdc; // tdc value
171 };
172 const int LEADING=4;
173 const int TRAILING=5;
174 //
175 // TOFp Processed Raw Data structure
176 struct TofDATA {
177  char * BankType;
178  unsigned int ByteSwapped ; // Should be 0x04030201
179  unsigned int EventNumber; //Token number
180  unsigned short AdcData[TOF_MAX_ADC_CHANNELS];
181  unsigned short TdcData[TOF_MAX_TDC_CHANNELS];
182  short A2dData[TOF_MAX_A2D_CHANNELS];
183  unsigned short ScaData[TOF_MAX_SCA_CHANNELS];
184  // Jing Liu, use std::vector to save all hits(include multi-hits)
185  std::vector<TofRawHit> TofLeadingHits;
186  std::vector<TofRawHit> TofTrailingHits;
187  // use array to save hits, w/o multi-hits
188  unsigned int LdTdcData[TOF_MAX_TDC_CHANNELS];
189  unsigned int TrTdcData[TOF_MAX_TDC_CHANNELS];
190  unsigned short LdNHit[TOF_MAX_TDC_CHANNELS];
191  unsigned short TrNHit[TOF_MAX_TDC_CHANNELS];
192  // end tofr5, Jing Liu
193 };
194 
195 //-----------------------------------------------------
196 
198 public:
199  virtual ~StTofReaderInterface(){}
200  // old virtual access members
201  virtual unsigned short GetAdcFromSlat(int)=0;
202  virtual unsigned short GetTdcFromSlat(int)=0;
203  virtual short GetTc(int)=0;
204  virtual unsigned short GetSc(int)=0;
205  virtual unsigned int GetEventNumber()=0;
206  virtual unsigned short GetTofpAdc(int)=0;
207  virtual unsigned short GetTofpTdc(int)=0;
208  virtual unsigned short GetTofrAdc(int)=0;
209  virtual unsigned short GetTofrTdc(int)=0;
210 
211  // Jing Liu FY05 --- some new virtual access members
212  // get the tdc for each channel
213  virtual unsigned int GetLdTdc(int)=0;
214  virtual unsigned int GetTrTdc(int)=0;
215  virtual unsigned int GetLdmTdc(int,int)=0;
216  virtual unsigned int GetTrmTdc(int,int)=0;
217  //
218  virtual unsigned int GetPvpdLdTdc(int)=0;
219  virtual unsigned int GetPvpdTrTdc(int)=0;
220  virtual unsigned int GetPvpdLdmTdc(int,int)=0;
221  virtual unsigned int GetPvpdTrmTdc(int,int)=0;
222  //
223  virtual unsigned short GetNLdHits(int)=0;
224  virtual unsigned short GetNTrHits(int)=0;
225  //
226  virtual unsigned int GetNLeadingHits()=0;
227  virtual unsigned int GetLeadingEventNumber(int)=0;
228  virtual unsigned short GetLeadingFiberId(int)=0;
229  virtual unsigned short GetLeadingGlobalTdcChan(int)=0;
230  virtual unsigned int GetLeadingTdc(int)=0;
231  virtual unsigned int GetNTrailingHits()=0;
232  virtual unsigned int GetTrailingEventNumber(int)=0;
233  virtual unsigned short GetTrailingFiberId(int)=0;
234  virtual unsigned short GetTrailingGlobalTdcChan(int)=0;
235  virtual unsigned int GetTrailingTdc(int)=0;
236 };
237 
238 
240 private:
241  void ProcessEvent(const Bank_TOFP * TofPTR);
242  int mTofRawDataVersion;
243  int mMaxAdcChannels, mMaxTdcChannels;
244  int mMaxA2dChannels, mMaxScaChannels;
245  TofDATA mTheTofArray;
246  // unpack function, Jing Liu, 03/15/2005
247  int UnpackYear2to4Data(const Bank_TOFP * TofPTR);
248  int UnpackYear5Data(const Bank_TOFP * TofPTR);
249 
250 
251 protected:
252  EventReader *ercpy; // copy of EventReader pointer
253  struct Bank_TOFP *pBankTOFP; // Bank Pointers
254 public:
255  TOF_Reader(EventReader *er, Bank_TOFP *pTOFP);
256  ~TOF_Reader(){};
257  // old access member
258  unsigned short GetAdcFromSlat(int slatId);
259  unsigned short GetTdcFromSlat(int slatId);
260  // new access members
261  unsigned short GetAdc(int id);
262  unsigned short GetTdc(int id);
263  unsigned short GetTofrAdc(int padId);
264  unsigned short GetTofrTdc(int padId);
265  unsigned short GetTofpAdc(int SlatId);
266  unsigned short GetTofpTdc(int SlatId);
267  unsigned short GetPvpdAdcHigh(int id);
268  unsigned short GetPvpdAdc(int id);
269  unsigned short GetPvpdTdc(int id);
270  unsigned short GetClockAdc();
271  unsigned short GetTofrTOT(int totId);
272  //
273  // Jing Liu, FY05 new access members.
274  unsigned int GetLdTdc(int id);
275  unsigned int GetTrTdc(int id);
276  unsigned int GetLdmTdc(int id ,int n);
277  unsigned int GetTrmTdc(int id,int n);
278  //
279  unsigned int GetPvpdLdTdc(int id);
280  unsigned int GetPvpdTrTdc(int id );
281  unsigned int GetPvpdLdmTdc(int id,int n);
282  unsigned int GetPvpdTrmTdc(int id,int n);
283  //
284  unsigned short GetNLdHits(int id);
285  unsigned short GetNTrHits(int id);
286  //
287  unsigned int GetNLeadingHits();
288  unsigned int GetLeadingEventNumber(int ihit);
289  unsigned short GetLeadingFiberId(int ihit);
290  unsigned short GetLeadingGlobalTdcChan(int ihit);
291  unsigned int GetLeadingTdc(int ihit);
292  unsigned int GetNTrailingHits();
293  unsigned int GetTrailingEventNumber(int ihit);
294  unsigned short GetTrailingFiberId(int ihit);
295  unsigned short GetTrailingGlobalTdcChan(int ihit);
296  unsigned int GetTrailingTdc(int ihit);
297 
298  bool year2Data();
299  bool year3Data();
300  bool year4Data();
301  //Jing Liu
302  bool year5Data();
303 
304  short GetTc(int chanId);
305  unsigned short GetSc(int chanId);
306  unsigned int GetEventNumber();
307  void printRawData();
308 };
309 
310 TOF_Reader *getTOFReader(EventReader *er);
311 
312 #endif
unsigned char globaltdcchan
1,2,......,120,for tray, 121, 122 for upvpd
unsigned char fiberid
data word before unpack