ATLAS Offline Software
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$
15 
16 
17 namespace 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),
46  m_flags(flags)
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
SG::PackedParameters::setOption
bool setOption(const AuxDataOption &option)
Set a packing option.
Definition: PackedParameters.cxx:222
SG::PackedParameters::PackedParameters
PackedParameters()
Default constructor.
Definition: PackedParameters.cxx:25
SG::AuxDataOption::intVal
int intVal() const
Return the option value as an integer.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
SG::PackedParameters::m_flags
uint8_t m_flags
Additional flags.
Definition: PackedParameters.h:286
PackedParameters.h
Describe how the contents of a PackedContainer are to be saved.
SG::PackedParameters::setNbits
bool setNbits(uint8_t nbits)
Set the number of bits to be used for each element.
Definition: PackedParameters.cxx:69
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
SG::PackedParameters::m_nmantissa
uint8_t m_nmantissa
The number of bits for the mantissa of floating-point representations.
Definition: PackedParameters.h:280
SG::PackedParameters::setFloat
bool setFloat(bool flag)
Set the floating-point flag.
Definition: PackedParameters.cxx:180
SG::PackedParameters::isSigned
bool isSigned() const
Are elements being written as signed numbers?
SG::PackedParameters::FLAG_HAS_SCALE
@ FLAG_HAS_SCALE
Definition: PackedParameters.h:269
SG::PackedParameters::nmantissa
uint8_t nmantissa() const
The number of bits used for the mantissa portion of a float-point representation, excluding a sign bi...
SG::PackedParameters::hasScale
bool hasScale() const
Should floats be rescaled before writing?
SG::AuxDataOption::floatVal
float floatVal() const
Return the option value as a float.
master.flag
bool flag
Definition: master.py:29
SG::PackedParameters::nbits
uint8_t nbits() const
The number of bits used to store each element.
SG::PackedParameters::setNmantissa
bool setNmantissa(uint8_t nmantissa)
Set the number of mantissa bits used in the packed representation.
Definition: PackedParameters.cxx:95
SG::AuxDataOption
Hold information about an option setting request.
Definition: AuxDataOption.h:37
SG::PackedParameters::FLAG_IS_FLOAT
@ FLAG_IS_FLOAT
Definition: PackedParameters.h:268
SG::PackedParameters::FLAG_IS_SIGNED
@ FLAG_IS_SIGNED
Definition: PackedParameters.h:267
SG::PackedParameters::isValidOption
static bool isValidOption(const AuxDataOption &option)
Test to see if option is a recognized packing option.
Definition: PackedParameters.cxx:197
SG::AuxDataOption::name
const std::string & name() const
The name of the option.
SG::PackedParameters::setScale
bool setScale(float scale)
Set the scale to use when packing floating-point data.
Definition: PackedParameters.cxx:116
SG::PackedParameters::m_nbits
uint8_t m_nbits
The number of bits to use for each element.
Definition: PackedParameters.h:276
SG::PackedParameters::m_scale
float m_scale
If nonzero, divide floating-point numbers by this before writing.
Definition: PackedParameters.h:283
SG::PackedParameters::setRounding
bool setRounding(bool flag)
Set the rounding mode.
Definition: PackedParameters.cxx:161
SG::PackedParameters::scale
float scale() const
Return the scale for floating-point numbers.
SG::PackedParameters::FLAG_ROUNDING
@ FLAG_ROUNDING
Definition: PackedParameters.h:270
SG::PackedParameters::setSigned
bool setSigned(bool flag)
Set the signedness flag for the packed representation.
Definition: PackedParameters.cxx:138