ATLAS Offline Software
Loading...
Searching...
No Matches
PackedParameters.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id$
12
13
15
16
17namespace SG {
18
19
26 : m_nbits(8 * sizeof(uint32_t)),
27 m_nmantissa(23),
28 m_scale(0),
29 m_flags(0)
30{
31}
32
33
45 : m_nbits(nbits),
47{
49 if (isSigned() && m_nmantissa > 0) --m_nmantissa;
50 if (hasScale())
51 m_scale = 1;
52 else
53 m_scale = 0;
54}
55
56
70{
71 if (nbits <= 0 || nbits > 32) return false;
72 uint8_t navail = nbits;
73 if (isSigned()) --navail;
74 if (navail == 0) return false;
75 m_nbits = nbits;
76 if (m_nmantissa > navail)
77 m_nmantissa = navail;
78 return true;
79}
80
81
96{
97 uint8_t navail = m_nbits;
98 if (isSigned()) --navail;
99 if (nmantissa <= 0 || nmantissa > navail) return false;
101 return true;
102}
103
104
117{
118 m_scale = scale;
119 if (m_scale == 0 || m_scale == 1)
121 else
123 return true;
124}
125
126
139{
140 if (!flag) {
142 return true;
143 }
144
145 if (m_nbits == 1) return false;
146 if (m_nmantissa + 1 > m_nbits)
147 m_nmantissa = m_nbits - 1;
149 return true;
150}
151
152
162{
163 if (flag)
165 else
167 return true;
168}
169
170
181{
182 if (flag)
184 else
186 return true;
187}
188
189
198{
199 if (option.name() == "nbits" ||
200 option.name() == "nmantissa" ||
201 option.name() == "scale" ||
202 option.name() == "signed" ||
203 option.name() == "rounding" ||
204 option.name() == "float")
205 {
206 return true;
207 }
208 return false;
209}
210
211
223{
224 if (option.name() == "nbits")
225 return setNbits (option.intVal());
226
227 else if (option.name() == "nmantissa")
228 return setNmantissa (option.intVal());
229
230 else if (option.name() == "scale")
231 return setScale (option.floatVal());
232
233 else if (option.name() == "signed")
234 return setSigned (option.intVal() != 0);
235
236 else if (option.name() == "rounding")
237 return setRounding (option.intVal() != 0);
238
239 else if (option.name() == "float")
240 return setFloat (option.intVal() != 0);
241
242 return false;
243}
244
245
246} // namespace SG
Describe how the contents of a PackedContainer are to be saved.
Hold information about an option setting request.
const std::string & name() const
The name of the option.
float floatVal() const
Return the option value as a float.
int intVal() const
Return the option value as an integer.
static bool isValidOption(const AuxDataOption &option)
Test to see if option is a recognized packing option.
uint8_t m_flags
Additional flags.
bool hasScale() const
Should floats be rescaled before writing?
bool setRounding(bool flag)
Set the rounding mode.
bool setNbits(uint8_t nbits)
Set the number of bits to be used for each element.
bool isSigned() const
Are elements being written as signed numbers?
bool setOption(const AuxDataOption &option)
Set a packing option.
bool setFloat(bool flag)
Set the floating-point flag.
bool setNmantissa(uint8_t nmantissa)
Set the number of mantissa bits used in the packed representation.
uint8_t nbits() const
The number of bits used to store each element.
uint8_t m_nmantissa
The number of bits for the mantissa of floating-point representations.
bool setScale(float scale)
Set the scale to use when packing floating-point data.
float m_scale
If nonzero, divide floating-point numbers by this before writing.
uint8_t nmantissa() const
The number of bits used for the mantissa portion of a float-point representation, excluding a sign bi...
bool setSigned(bool flag)
Set the signedness flag for the packed representation.
float scale() const
Return the scale for floating-point numbers.
PackedParameters()
Default constructor.
uint8_t m_nbits
The number of bits to use for each element.
uint8_t flags() const
Additional flags describing the packing.
Forward declaration.