ATLAS Offline Software
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 
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
31 const int AMPLITUDE_OFFSET5[2] = { 512, 2048 };
32 const double AMPLITUDE_FACTOR5_LG[4] = { 16.0, 32.0, 32.0, 2.0/64.0 };
33 const double AMPLITUDE_FACTOR5_HG[4] = { 16.0, 32.0*64, 32.0*64., 2.0 };
34 
38 
39 
40 class TileRawChannel;
41 
43 {
44  public:
45 
46  enum FormatCode {
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;
62  int ene_bin;
63  int time_bin;
64  float ene;
65  float time;
66  int s[7];
67  } TileChanData;
68 
70 
72  {
74  }
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;
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) \
184 if (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) \
192 if (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) \
204 if (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) \
213 if (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 #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 
246 inline bool TileRawChannel2Bytes5::unpack_reco_bin(unsigned int w, int &fmt, int &gain, int &amp, int &time) const
247 {
248  uint32_t code = w >> 24;
250 
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 
260 inline 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 
271 inline 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 
278 inline double TileRawChannel2Bytes5::getSumEt(const uint32_t* ptr_frag) const { return getSum(ptr_frag, 0); }
279 inline double TileRawChannel2Bytes5::getSumEz(const uint32_t* ptr_frag) const { return getSum(ptr_frag, 1); }
280 inline double TileRawChannel2Bytes5::getSumE (const uint32_t* ptr_frag) const { return getSum(ptr_frag, 2); }
281 
282 #endif
bad
@ bad
Definition: SUSYToolsTester.cxx:95
TileRawChannel2Bytes5::is_code_dump
static bool is_code_dump(uint32_t code)
Definition: TileRawChannel2Bytes5.h:79
Frag5_unpack_bin2reco
#define Frag5_unpack_bin2reco(unit, gain, amp_bin, amp, time_bin, time)
unpack_bin2reco
Definition: TileRawChannel2Bytes5.h:232
TileRawChannel2Bytes5::TileRawChannel2Bytes5
TileRawChannel2Bytes5()
Definition: TileRawChannel2Bytes5.h:71
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
vtune_athena.format
format
Definition: vtune_athena.py:14
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
TileRawChannel2Bytes5::code_raws
@ code_raws
Definition: TileRawChannel2Bytes5.h:48
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TileRawChannel2Bytes5::code_ped4
@ code_ped4
Definition: TileRawChannel2Bytes5.h:50
TileRawChannel2Bytes5::is_code_amp6
static bool is_code_amp6(uint32_t code)
Definition: TileRawChannel2Bytes5.h:83
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TileRawChannel2Bytes5::TileChanData::time_bin
int time_bin
Definition: TileRawChannel2Bytes5.h:63
TileRawChannel2Bytes5::unpack
void unpack(const uint32_t *ofw, const uint32_t *ptr_frag, TileChanData *ChanData) const
Definition: TileRawChannel2Bytes5.cxx:672
TileRawChannel2Bytes5::print_code
static void print_code(uint32_t code)
Definition: TileRawChannel2Bytes5.h:124
TileRawChannel2Bytes5::TileChanData::time
float time
Definition: TileRawChannel2Bytes5.h:65
TileRawChannel2Bytes5::TileChanData::gain
int gain
Definition: TileRawChannel2Bytes5.h:61
TileRawChannel2Bytes5::is_code_null
static bool is_code_null(uint32_t code)
Definition: TileRawChannel2Bytes5.h:85
Frag5_unpack_bin2sum
#define Frag5_unpack_bin2sum(unit, amp_bin)
unpack_bin2sum
Definition: TileRawChannel2Bytes5.h:240
TileRawChannel2Bytes5::TileChanData
Definition: TileRawChannel2Bytes5.h:58
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
TileRawChannel2Bytes5::getSumEt
double getSumEt(const uint32_t *ptr_frag) const
Definition: TileRawChannel2Bytes5.h:278
AMPLITUDE_FACTOR5_LG
const double AMPLITUDE_FACTOR5_LG[4]
Definition: TileRawChannel2Bytes5.h:32
NOFWORDS_WEIGHTS_7S
const int NOFWORDS_WEIGHTS_7S
Definition: TileRawChannel2Bytes5.h:36
fmt
const char *const fmt
Definition: TripleGaussCollFit.cxx:84
TileRawChannel2Bytes5::TileChanData::bad
int bad
Definition: TileRawChannel2Bytes5.h:60
TileRawChannel2Bytes5::is_code_full
static bool is_code_full(uint32_t code)
Definition: TileRawChannel2Bytes5.h:84
TileRawChannel2Bytes5::code_dump
@ code_dump
Definition: TileRawChannel2Bytes5.h:49
TileRawChannel2Bytes5::is_code_amp5
static bool is_code_amp5(uint32_t code)
Compression Format Code inlile functions.
Definition: TileRawChannel2Bytes5.h:77
TileRawChannel2Bytes5::is_code_ped5
static bool is_code_ped5(uint32_t code)
Definition: TileRawChannel2Bytes5.h:81
TileRawChannel2Bytes5::get_code
static int get_code(uint32_t reco)
Definition: TileRawChannel2Bytes5.h:105
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TileRawChannel2Bytes5::is_code_rawf
static bool is_code_rawf(uint32_t code)
Definition: TileRawChannel2Bytes5.h:82
TileRawChannel2Bytes5::is_code_ped
static bool is_code_ped(uint32_t code)
Definition: TileRawChannel2Bytes5.h:87
TileRawChannel2Bytes5::code_full
@ code_full
Definition: TileRawChannel2Bytes5.h:54
TileRawChannel2Bytes5::code_amp5
@ code_amp5
Definition: TileRawChannel2Bytes5.h:47
TileRawChannel2Bytes5::get_size_code
static int get_size_code(uint32_t code)
Definition: TileRawChannel2Bytes5.h:138
TileRawChannel2Bytes5::m_FormatLookup
uint8_t m_FormatLookup[256]
Definition: TileRawChannel2Bytes5.h:69
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
beamspotman.n
n
Definition: beamspotman.py:731
TileRawChannel2Bytes5::check_reco
bool check_reco(const uint32_t *frag, int of_energy[]) const
Definition: TileRawChannel2Bytes5.cxx:811
if_Frag5_unpack_reco_bin
#define if_Frag5_unpack_reco_bin(w, code, gain, amp, time)
if_unpack_reco_bin
Definition: TileRawChannel2Bytes5.h:221
TileRawChannel2Bytes5::FormatCode
FormatCode
Definition: TileRawChannel2Bytes5.h:46
RECALIB_OFFSET
const int RECALIB_OFFSET
Definition: TileRawChannel2Bytes5.h:37
TileRawChannel
Definition: TileRawChannel.h:35
TileRawChannel2Bytes5::get_format
int get_format(int code) const
Definition: TileRawChannel2Bytes5.h:154
TileRawChannel2Bytes5
Converts the TileRawChannel object into bytes as it.
Definition: TileRawChannel2Bytes5.h:43
AMPLITUDE_OFFSET5
const int AMPLITUDE_OFFSET5[2]
Definition: TileRawChannel2Bytes5.h:31
TileRawChannel2Bytes5::get_quality
static int get_quality(int bad, int format)
Definition: TileRawChannel2Bytes5.h:155
TileRawChannel2Bytes5::is_code_ped4
static bool is_code_ped4(uint32_t code)
Definition: TileRawChannel2Bytes5.h:80
TileRawChannel2Bytes5::is_code_amp_raw_dump
static bool is_code_amp_raw_dump(uint32_t code)
Definition: TileRawChannel2Bytes5.h:89
NOFWORDS_WEIGHTS_7S_1GAIN
const int NOFWORDS_WEIGHTS_7S_1GAIN
Definition: TileRawChannel2Bytes5.h:35
TileRawChannel2Bytes5::code_ped5
@ code_ped5
Definition: TileRawChannel2Bytes5.h:51
pmontree.code
code
Definition: pmontree.py:443
TileRawChannel2Bytes5::is_code_raws
static bool is_code_raws(uint32_t code)
Definition: TileRawChannel2Bytes5.h:78
TileRawChannel2Bytes5::setFormatLookup
void setFormatLookup()
Definition: TileRawChannel2Bytes5.h:157
TileRawChannel2Bytes5::getSumE
double getSumE(const uint32_t *ptr_frag) const
Definition: TileRawChannel2Bytes5.h:280
TileRawChannel2Bytes5::getSum
double getSum(const uint32_t *ptr_frag, int n) const
Get SumEt, SumEz, SumE value.
Definition: TileRawChannel2Bytes5.h:271
fmt
TileRawChannel2Bytes5::amplitude
int amplitude(const uint32_t *ofw, int unit, int chan, int gain, int s[]) const
Definition: TileRawChannel2Bytes5.cxx:624
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
TileRawChannel2Bytes5::unpack_reco_bin
bool unpack_reco_bin(unsigned int w, int &fmt, int &gain, int &amp, int &time) const
Definition: TileRawChannel2Bytes5.h:246
TileRawChannel2Bytes5::setVerbose
void setVerbose(bool)
Sets verbose mode true or false.
Definition: TileRawChannel2Bytes5.h:103
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
TileRawChannel2Bytes5::is_code_amp
static bool is_code_amp(uint32_t code)
Definition: TileRawChannel2Bytes5.h:88
TileRawChannel2Bytes5::TileChanData::ene
float ene
Definition: TileRawChannel2Bytes5.h:64
TileRawChannel2Bytes5::TileChanData::ene_bin
int ene_bin
Definition: TileRawChannel2Bytes5.h:62
TileRawChannel2Bytes5::check_raw
bool check_raw(const uint32_t *feb, int of_energy[], TileChanData *ChanData) const
Definition: TileRawChannel2Bytes5.cxx:757
AMPLITUDE_FACTOR5_HG
const double AMPLITUDE_FACTOR5_HG[4]
Definition: TileRawChannel2Bytes5.h:33
TileRawChannel2Bytes5::unpack_reco
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.
Definition: TileRawChannel2Bytes5.h:260
TileRawChannel2Bytes5::code_rawf
@ code_rawf
Definition: TileRawChannel2Bytes5.h:52
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
TileRawChannel2Bytes5::code_null
@ code_null
Definition: TileRawChannel2Bytes5.h:55
TileRawChannel2Bytes5::getSumEz
double getSumEz(const uint32_t *ptr_frag) const
Definition: TileRawChannel2Bytes5.h:279
TileRawChannel2Bytes5::code_amp6
@ code_amp6
Definition: TileRawChannel2Bytes5.h:53
TileRawChannel2Bytes5::TileChanData::code
int code
Definition: TileRawChannel2Bytes5.h:59
MuonSegmentReaderConfig.reco
reco
Definition: MuonSegmentReaderConfig.py:133