ROOTANA
TRB3Decoder.hxx
Go to the documentation of this file.
1 #ifndef TRB3Decoder_hxx_seen
2 #define TRB3Decoder_hxx_seen
3 
4 // Decoder for the GSI TRB3 FPGA-TDC
5 // Details on TRB3 here: http://trb.gsi.de/
6 //
7 // Thomas Lindner
8 // Feb 14, 2018
9 
10 
11 #include <vector>
12 #include <iostream>
13 #include <inttypes.h>
14 
15 // Some global variables for setting the TRB3 calibration
16 class Trb3Calib
17 {
18 public:
20  {
21  static Trb3Calib instance;
22  return instance;
23  }
24 
25  void UseTRB3LinearCalibration(bool uselinear);
26  void SetTRB3LinearCalibrationConstants(float low_value, float high_value);
27 
31 
32 private:
34  useLinearCalibration = true;
35  trb3LinearLowEnd = 17.0;
36  trb3LinearHighEnd = 473.0;
37  }
38  Trb3Calib(Trb3Calib const&); // Don't Implement.
39  void operator=(Trb3Calib const&); // Don't implement
40 
41  bool useLinearCalibration; // use linear calibration
42 
43  float trb3LinearLowEnd; // low value of fine TDC hits
44  float trb3LinearHighEnd; // high value of fine TDC hits
45 
46 
47 };
48 
49 // Function to allow
50 
51 
52 
53 /// Decoder for individual hits from GSI TFB3 FPGA-TDC
54 class TrbTdcMeas {
55 
56  friend class TTRB3Data;
57 
58 public:
59 
60  /// Is this the leading edge measurement?
61  bool IsLeading() const {return 0;}
62  /// Is this the trailing edge measurement?
63  bool IsTrailing() const {return 0;}
64 
65  uint32_t GetBoardId() const {return fgpa_header_word & 0xf;}
66 
67  /// Get the TDC measurement
68  uint32_t GetMeasurement() const {
69 
70  return (tdc_measurement_word & 0x7ffff);
71  }
72 
73  // semi calibrated time in picoseconds
74  double GetFinalTime() const {
75  if(Trb3Calib::getInstance().LinearCalib()){ // use linear calibration, if requested
76  return ((double)GetEpochCounter())*10240026.0
77  + ((double) GetCoarseTime()) * 5000.0
80  }
81  return -99.0;
82  }
83 
84  // quasi calibrated time in picoseconds
85  double GetSemiFinalTime() const {
86  if(Trb3Calib::getInstance().LinearCalib()){ // use linear calibration, if requested
87  return ((double) GetCoarseTime()) * 5000.0
90  }
91  return -99.0;
92  }
93 
94  uint32_t GetFineTime() const {
95  return (tdc_measurement_word & 0x1ff000) >> 12;
96  };
97 
98  uint32_t GetCoarseTime() const {return tdc_measurement_word & 0x7ff;};
99 
100  // This epoch counter rolls every 10us
101  uint32_t GetEpochCounter() const {return tdc_epoch_word & 0xfffffff;};
102 
103  /// Get the channel number
104  uint32_t GetChannel() const {
105  return ((tdc_measurement_word & 0xfc00000 ) >> 22 );
106  }
107 
108 
109  /// Constructor;
110  TrbTdcMeas(uint32_t fpga, uint32_t header, uint32_t epoch, uint32_t measurement):
111  fgpa_header_word(fpga),
112  tdc_header_word(header),
113  tdc_epoch_word(epoch),
114  tdc_measurement_word(measurement),
115  event_index(0){};
116 
118 
119 private:
120 
121  /// Found fields to hold the header, measurement error words.
123  uint32_t tdc_header_word;
124  uint32_t tdc_epoch_word;
127 
128 
129 };
130 
131 
132 /// Decoder for data packets from TRB3.
133 class TrbDecoder {
134 
135 public:
136 
137  /// Constructor
138  TrbDecoder(int bklen, void *pdata, std::string bankname, int type);
139 
140 
141  void Print();
142 
143  const int GetNumberMeasurements(){return fMeasurements.size();}
144 
145  /// Get the Vector of TDC Measurements.
146  std::vector<TrbTdcMeas>& GetMeasurements() {return fMeasurements;}
147 
148  /// Get Sub-event ID
149  uint32_t GetSubEventID(){ return fSubEventID;}
150 
151  /// Get Trigger Number
152  uint32_t GetTriggerNumber(){ return ((fTriggerWord & 0xffffff00) >> 8);}
153 
154  /// Get Trigger code
155  uint32_t GetTriggerCode(){ return (fTriggerWord & 0xff);}
156 
157  /// Get Packet size
158  const uint32_t GetPacketSize(){return fPacketSize;}
159  // Get Board ID
160  const uint32_t GetBoardId(){return fBoardId;}
161  // Get sequence number
162  const uint32_t GetSeqNr(){return fSeqNr;}
163  // Get run number
164  const uint32_t GetRunNr(){return fRunNr;};
165  // Get year
166  const uint32_t GetYear(){return (fDate &0xff0000) >> 16;};
167  // Get month
168  const uint32_t GetMonth(){return (fDate &0xff00) >> 8;};
169  // Get day
170  const uint32_t GetDay(){return (fDate &0xff);};
171  // Get time; seconds since when???
172  const uint32_t GetTime(){return (fTime);};;
173 
174 
175 
176 private:
177 
178  uint32_t fPacketSize;
179  uint32_t fDecoding;
180  uint32_t fBoardId;
181  uint32_t fSeqNr;
182  uint32_t fRunNr;
183  uint32_t fDate;
184  uint32_t fTime;
185  uint32_t fSubEventID;
186  uint32_t fTriggerWord;
187 
188  /// Vector of TDC Measurements.
189  std::vector<TrbTdcMeas> fMeasurements;
190 
191 
192 
193 };
194 
195 #endif
void UseTRB3LinearCalibration(bool uselinear)
Definition: TRB3Decoder.cxx:4
bool useLinearCalibration
Definition: TRB3Decoder.hxx:41
static Trb3Calib & getInstance()
Definition: TRB3Decoder.hxx:19
float trb3LinearHighEnd
Definition: TRB3Decoder.hxx:44
float LinearCalibHighEnd()
Definition: TRB3Decoder.hxx:30
bool LinearCalib()
Definition: TRB3Decoder.hxx:28
Trb3Calib(Trb3Calib const &)
float trb3LinearLowEnd
Definition: TRB3Decoder.hxx:43
void operator=(Trb3Calib const &)
void SetTRB3LinearCalibrationConstants(float low_value, float high_value)
Definition: TRB3Decoder.cxx:5
float LinearCalibLowEnd()
Definition: TRB3Decoder.hxx:29
Decoder for data packets from TRB3.
uint32_t fSubEventID
uint32_t fRunNr
const uint32_t GetBoardId()
const uint32_t GetRunNr()
std::vector< TrbTdcMeas > fMeasurements
Vector of TDC Measurements.
const uint32_t GetMonth()
uint32_t GetSubEventID()
Get Sub-event ID.
uint32_t fPacketSize
const int GetNumberMeasurements()
uint32_t fDate
uint32_t fTriggerWord
const uint32_t GetTime()
TrbDecoder(int bklen, void *pdata, std::string bankname, int type)
Constructor.
Definition: TRB3Decoder.cxx:22
const uint32_t GetYear()
uint32_t fDecoding
std::vector< TrbTdcMeas > & GetMeasurements()
Get the Vector of TDC Measurements.
const uint32_t GetSeqNr()
uint32_t GetTriggerNumber()
Get Trigger Number.
uint32_t fTime
const uint32_t GetPacketSize()
Get Packet size.
void Print()
const uint32_t GetDay()
uint32_t fSeqNr
uint32_t fBoardId
uint32_t GetTriggerCode()
Get Trigger code.
Decoder for individual hits from GSI TFB3 FPGA-TDC.
Definition: TRB3Decoder.hxx:54
bool IsTrailing() const
Is this the trailing edge measurement?
Definition: TRB3Decoder.hxx:63
uint32_t GetBoardId() const
Definition: TRB3Decoder.hxx:65
uint32_t tdc_header_word
bool IsLeading() const
Is this the leading edge measurement?
Definition: TRB3Decoder.hxx:61
uint32_t GetMeasurement() const
Get the TDC measurement.
Definition: TRB3Decoder.hxx:68
TrbTdcMeas(uint32_t fpga, uint32_t header, uint32_t epoch, uint32_t measurement)
Constructor;.
double GetSemiFinalTime() const
Definition: TRB3Decoder.hxx:85
uint32_t GetEpochCounter() const
uint32_t GetChannel() const
Get the channel number.
uint32_t tdc_measurement_word
uint32_t tdc_epoch_word
uint32_t fgpa_header_word
Found fields to hold the header, measurement error words.
uint32_t GetCoarseTime() const
Definition: TRB3Decoder.hxx:98
double GetFinalTime() const
Definition: TRB3Decoder.hxx:74
uint32_t GetFineTime() const
Definition: TRB3Decoder.hxx:94