ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawChannel2Bytes5.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TILEBYTESTREAM_TILERAWCHANNEL2BYTES5_H
6#define TILEBYTESTREAM_TILERAWCHANNEL2BYTES5_H
7// This class converts the TileRawChannel object into bytes
8// as it is defined at the commissioning 2007
9// in one 32-bit word, 1 bit for the gain, 15 for the energy,
10// 11 bits for time and 4+1 bits for quality factor and energy
11// trigger flag
12
20
21#include <vector>
22#include <stdio.h>
23#include <stdint.h>
24
25
26// Amplitude encoding: 15 bits
27// Value = amp*factor + offset
28// amp = (Value - offset)/factor
29// the offset depends on the gain
30// the factor depends on the units
31const int AMPLITUDE_OFFSET5[2] = { 512, 2048 };
32const double AMPLITUDE_FACTOR5_LG[4] = { 16.0, 32.0, 32.0, 2.0/64.0 };
33const double AMPLITUDE_FACTOR5_HG[4] = { 16.0, 32.0*64, 32.0*64., 2.0 };
34
38
39
40class TileRawChannel;
41
43{
44 public:
45
47 code_amp5 = 0x20, // G 0 1 . . . . .
48 code_raws = 0x40, // G 1 0 . . . . .
49 code_dump = 0x60, // G 1 1 . . . . .
50 code_ped4 = 0x10, // 0 0 0 1 . . . .
51 code_ped5 = 0x90, // 1 0 0 1 . . . .
52 code_rawf = 0x08, // G 0 0 0 1 . . .
53 code_amp6 = 0x04, // G 0 0 0 0 1 . .
54 code_full = 0x01, // G 0 0 0 0 0 0 1
55 code_null = 0x00 // 0 0 0 0 0 0 0 0
56 };
57
58 typedef struct {
59 int code;
60 int bad;
61 int gain;
64 float ene;
65 float time;
66 int s[7];
68
69 uint8_t m_FormatLookup[256];
70
75
77 inline static bool is_code_amp5(uint32_t code) { return ((code & 0x60) == code_amp5); }
78 inline static bool is_code_raws(uint32_t code) { return ((code & 0x60) == code_raws); }
79 inline static bool is_code_dump(uint32_t code) { return ((code & 0x60) == code_dump); }
80 inline static bool is_code_ped4(uint32_t code) { return ((code & 0xF0) == code_ped4); }
81 inline static bool is_code_ped5(uint32_t code) { return ((code & 0xF0) == code_ped5); }
82 inline static bool is_code_rawf(uint32_t code) { return ((code & 0x78) == code_rawf); }
83 inline static bool is_code_amp6(uint32_t code) { return ((code & 0x7C) == code_amp6); }
84 inline static bool is_code_full(uint32_t code) { return ((code & 0x3F) == code_full); }
85 inline static bool is_code_null(uint32_t code) { return ((code & 0xFF) == code_null); }
86
87 inline static bool is_code_ped(uint32_t code) { return ((code & 0x70) == code_ped4); }
88 inline static bool is_code_amp(uint32_t code) { return (is_code_amp5(code) || is_code_amp6(code)); }
89 inline static bool is_code_amp_raw_dump(uint32_t code) { return (code & 0x6C); }
90
92 inline void unpack_reco(unsigned int w, unsigned int unit, int &fmt, int &gain, double &amp, double &time) const;
93 inline bool unpack_reco_bin(unsigned int w, int &fmt, int &gain, int &amp, int &time) const;
94
96 inline double getSum(const uint32_t* ptr_frag, int n) const;
97
98 inline double getSumEt(const uint32_t* ptr_frag) const;
99 inline double getSumEz(const uint32_t* ptr_frag) const;
100 inline double getSumE (const uint32_t* ptr_frag) const;
101
103 inline void setVerbose(bool /*verbose*/) { }
104
105 inline static int get_code(uint32_t reco)
106 {
107 int code = reco >> 24;
108
109 if (is_code_null(code)) code = code_null; else
110 if (is_code_ped4(code)) code = code_ped4; else
111 if (is_code_ped5(code)) code = code_ped5; else
112 if (is_code_amp5(code)) code = code_amp5; else
113 if (is_code_amp6(code)) code = code_amp6; else
114 if (is_code_raws(code)) code = code_raws; else
115 if (is_code_rawf(code)) code = code_rawf; else
116 if (is_code_full(code)) code = code_full; else
117 if (is_code_dump(code)) code = code_dump; else {
118 printf("\nTileRawChannel2Bytes5::get_code ERROR\n");
119 code = -1;
120 }
121 return code;
122 }
123
124 inline static void print_code(uint32_t code)
125 {
126 if (code == code_ped4) printf("ped4"); else
127 if (code == code_ped5) printf("ped5"); else
128 if (code == code_amp5) printf("amp5"); else
129 if (code == code_amp6) printf("amp6"); else
130 if (code == code_raws) printf("raws"); else
131 if (code == code_rawf) printf("rawf"); else
132 if (code == code_full) printf("full"); else
133 if (code == code_dump) printf("dump"); else
134 if (code == code_null) printf("null"); else
135 printf("ERR ");
136 }
137
138 inline static int get_size_code(uint32_t code)
139 {
140 int size = 0;
141 if (is_code_null(code)) size = 32; else
142 if (is_code_ped4(code)) size = 40; else
143 if (is_code_ped5(code)) size = 48; else
144 if (is_code_amp5(code)) size = 56; else
145 if (is_code_amp6(code)) size = 64; else
146 if (is_code_raws(code)) size = 72; else
147 if (is_code_rawf(code)) size = 80; else
148 if (is_code_full(code)) size = 80; else
149 if (is_code_dump(code)) size = 88;
150
151 return size/8;
152 }
153
154 inline int get_format(int code) const { return m_FormatLookup[code & 0xFF]; }
155 inline static int get_quality(int bad, int format) { return (bad << 4) + format; }
156
157 inline void setFormatLookup()
158 {
159 uint8_t fmt;
160 for (int code = 0; code < 0xFF; code++) {
161 if (is_code_null(code)) fmt = 0; else
162 if (is_code_ped4(code)) fmt = 1; else
163 if (is_code_ped5(code)) fmt = 2; else
164 if (is_code_amp5(code)) fmt = 3; else
165 if (is_code_amp6(code)) fmt = 4; else
166 if (is_code_raws(code)) fmt = 5; else
167 if (is_code_rawf(code)) fmt = 6; else
168 if (is_code_full(code)) fmt = 7; else
169 if (is_code_dump(code)) fmt = 8; else
170 fmt = 0xFF;
171 m_FormatLookup[code] = fmt;
172 }
173 }
174
175 int amplitude(const uint32_t* ofw, int unit, int chan, int gain, int s[]) const;
176
177 void unpack(const uint32_t* ofw, const uint32_t* ptr_frag, TileChanData* ChanData) const;
178 bool check_raw(const uint32_t* feb, int of_energy[], TileChanData* ChanData) const;
179 bool check_reco(const uint32_t* frag, int of_energy[]) const;
180};
181
183#define if_Frag5_DO_PED(w, code, gain, amp, time) \
184if (TileRawChannel2Bytes5::is_code_ped(code)) { \
185 gain = 1; \
186 amp = (w & 0x1FF) - 256; \
187 time = 0; \
188}
189
191#define if_Frag5_DO_AMP_RAW_DUMP(w, code, gain, amp, time) \
192if (TileRawChannel2Bytes5::is_code_amp_raw_dump(code)) { \
193 gain = (w >> 31); \
194 amp = (w & 0x7FFF) - AMPLITUDE_OFFSET5[gain]; \
195 if (TileRawChannel2Bytes5::is_code_amp(code)) { \
196 time = ((int32_t)(w << (32 - 15 - 6)) >> (32 - 6)); \
197 } else { \
198 time = 0; \
199 } \
200}
201
203#define if_Frag5_DO_NULL(w, code, gain, amp, time) \
204if (TileRawChannel2Bytes5::is_code_null(code)) { \
205 int bit = w & 0x1; \
206 gain = bit; \
207 amp = 0; \
208 time = 0; \
209}
210
212#define if_Frag5_DO_FULL(w, code, gain, amp, time) \
213if (TileRawChannel2Bytes5::is_code_full(code)) { \
214 gain = (w >> 31); \
215 int overflow = (w >> 23) & 0x1; \
216 amp = (overflow ? 0x7FFF : 0x0) - AMPLITUDE_OFFSET5[gain]; \
217 time = 0; \
218}
219
221#define if_Frag5_unpack_reco_bin(w, code, gain, amp, time) \
222 if_Frag5_DO_PED(w, code, gain, amp, time) else \
223 if_Frag5_DO_AMP_RAW_DUMP(w, code, gain, amp, time) else \
224 if_Frag5_DO_NULL(w, code, gain, amp, time) else \
225 if_Frag5_DO_FULL(w, code, gain, amp, time) \
226
227
228#define Frag5_unpack_reco_bin(w, code, gain, amp, time) \
229 if_Frag5_unpack_reco_bin(w, code, gain, amp, time);
230
232#define Frag5_unpack_bin2reco(unit, gain, amp_bin, amp, time_bin, time) \
233{ \
234 time = time_bin/2.0; \
235 amp = (gain) ? amp_bin/AMPLITUDE_FACTOR5_HG[unit] \
236 : amp_bin/AMPLITUDE_FACTOR5_LG[unit]; \
237}
238
240#define Frag5_unpack_bin2sum(unit, amp_bin) \
241 amp_bin/AMPLITUDE_FACTOR5_HG[unit]
242
243
244// inline functions
245
246inline bool TileRawChannel2Bytes5::unpack_reco_bin(unsigned int w, int &fmt, int &gain, int &amp, int &time) const
247{
248 uint32_t code = w >> 24;
249 fmt = m_FormatLookup[code];
250
251 if_Frag5_unpack_reco_bin(w, code, gain, amp, time)
252 else {
253 gain = 0; amp = 0; time = 0;
254 printf("\nTileRawChannel2Bytes5::unpack_reco_bin.ERROR reco = %08X\n", w);
255 return false;
256 }
257 return true;
258}
259
260inline void TileRawChannel2Bytes5::unpack_reco(unsigned int w, unsigned int unit,
261 int &fmt, int &gain, double &amp, double &time) const
262{
263 int amp_bin, time_bin;
264 if (unpack_reco_bin(w, fmt, gain, amp_bin, time_bin)) {
265 Frag5_unpack_bin2reco(unit, gain, amp_bin, amp, time_bin, time);
266 } else {
267 amp = 0.0; time = 0.0;
268 }
269}
270
271inline double TileRawChannel2Bytes5::getSum(const uint32_t* ptr_frag, int n) const
272{
273 int unit = ptr_frag[2] >> (32 - 2);
274 int amp_bin = (int) (ptr_frag[3 + 48 + n]); // Header + Reco + [SumEt, SumEz, SumE]
275 return Frag5_unpack_bin2sum(unit, amp_bin);
276}
277
278inline double TileRawChannel2Bytes5::getSumEt(const uint32_t* ptr_frag) const { return getSum(ptr_frag, 0); }
279inline double TileRawChannel2Bytes5::getSumEz(const uint32_t* ptr_frag) const { return getSum(ptr_frag, 1); }
280inline double TileRawChannel2Bytes5::getSumE (const uint32_t* ptr_frag) const { return getSum(ptr_frag, 2); }
281
282#endif
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
const double AMPLITUDE_FACTOR5_HG[4]
const double AMPLITUDE_FACTOR5_LG[4]
const int AMPLITUDE_OFFSET5[2]
const int NOFWORDS_WEIGHTS_7S
#define Frag5_unpack_bin2sum(unit, amp_bin)
unpack_bin2sum
#define if_Frag5_unpack_reco_bin(w, code, gain, amp, time)
if_unpack_reco_bin
const int RECALIB_OFFSET
const int NOFWORDS_WEIGHTS_7S_1GAIN
#define Frag5_unpack_bin2reco(unit, gain, amp_bin, amp, time_bin, time)
unpack_bin2reco
const char *const fmt
int get_format(int code) const
static void print_code(uint32_t code)
double getSumEz(const uint32_t *ptr_frag) const
static bool is_code_amp6(uint32_t code)
static int get_code(uint32_t reco)
bool check_reco(const uint32_t *frag, int of_energy[]) const
bool unpack_reco_bin(unsigned int w, int &fmt, int &gain, int &amp, int &time) const
static bool is_code_ped(uint32_t code)
int amplitude(const uint32_t *ofw, int unit, int chan, int gain, int s[]) const
double getSumE(const uint32_t *ptr_frag) const
static bool is_code_ped5(uint32_t code)
static bool is_code_raws(uint32_t code)
void unpack_reco(unsigned int w, unsigned int unit, int &fmt, int &gain, double &amp, double &time) const
Unpack Frag5 reco from 32-bit word w.
static bool is_code_amp_raw_dump(uint32_t code)
static bool is_code_ped4(uint32_t code)
static bool is_code_null(uint32_t code)
static bool is_code_dump(uint32_t code)
double getSumEt(const uint32_t *ptr_frag) const
static bool is_code_rawf(uint32_t code)
static int get_quality(int bad, int format)
void setVerbose(bool)
Sets verbose mode true or false.
static bool is_code_amp5(uint32_t code)
Compression Format Code inlile functions.
static bool is_code_amp(uint32_t code)
double getSum(const uint32_t *ptr_frag, int n) const
Get SumEt, SumEz, SumE value.
static bool is_code_full(uint32_t code)
void unpack(const uint32_t *ofw, const uint32_t *ptr_frag, TileChanData *ChanData) const
static int get_size_code(uint32_t code)
bool check_raw(const uint32_t *feb, int of_energy[], TileChanData *ChanData) const