ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SG::PackedParameters Class Reference

Describe how the contents of a PackedContainer are to be saved. More...

#include <PackedParameters.h>

Collaboration diagram for SG::PackedParameters:

Public Types

enum  { FLAG_IS_SIGNED = (1<<0), FLAG_IS_FLOAT = (1<<1), FLAG_HAS_SCALE = (1<<2), FLAG_ROUNDING = (1<<3) }
 Define bit assignments for the flags field. More...
 

Public Member Functions

 PackedParameters ()
 Default constructor. More...
 
 PackedParameters (uint8_t nbits, uint8_t flags)
 Constructor from nbits and flags. More...
 
template<class T >
 PackedParameters (T)
 Initialize with default packing parameters for type T. More...
 
uint8_t nbits () const
 The number of bits used to store each element. More...
 
uint8_t nmantissa () const
 The number of bits used for the mantissa portion of a float-point representation, excluding a sign bit (if any). More...
 
uint8_t flags () const
 Additional flags describing the packing. More...
 
float scale () const
 Return the scale for floating-point numbers. More...
 
bool isSigned () const
 Are elements being written as signed numbers? More...
 
bool isFloat () const
 Are elements being written as floating-point numbers? More...
 
bool hasScale () const
 Should floats be rescaled before writing? More...
 
bool rounding () const
 Should floats be rounded during writing? More...
 
bool setNbits (uint8_t nbits)
 Set the number of bits to be used for each element. More...
 
bool setNmantissa (uint8_t nmantissa)
 Set the number of mantissa bits used in the packed representation. More...
 
bool setScale (float scale)
 Set the scale to use when packing floating-point data. More...
 
bool setSigned (bool flag)
 Set the signedness flag for the packed representation. More...
 
bool setRounding (bool flag)
 Set the rounding mode. More...
 
bool setFloat (bool flag)
 Set the floating-point flag. More...
 
bool setOption (const AuxDataOption &option)
 Set a packing option. More...
 

Static Public Member Functions

static bool isValidOption (const AuxDataOption &option)
 Test to see if option is a recognized packing option. More...
 

Private Attributes

uint8_t m_nbits
 The number of bits to use for each element. More...
 
uint8_t m_nmantissa
 The number of bits for the mantissa of floating-point representations. More...
 
float m_scale
 If nonzero, divide floating-point numbers by this before writing. More...
 
uint8_t m_flags
 Additional flags. More...
 

Detailed Description

Describe how the contents of a PackedContainer are to be saved.

When a PackedContainer is saved to a root file, the contents may be stored with reduced precision. How this packing is done is described by the parameters held in this structure. These include:

The remaining parameters are only used when elements are being saved as floating-point.

User code will should usually not interact with this class directly. Use the setOption interfaces instead.

Definition at line 65 of file PackedParameters.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Define bit assignments for the flags field.

Existing flag assignments should never be changed, as the persistent format may depend on them.

Enumerator
FLAG_IS_SIGNED 
FLAG_IS_FLOAT 
FLAG_HAS_SCALE 
FLAG_ROUNDING 

Definition at line 266 of file PackedParameters.h.

266  {
267  FLAG_IS_SIGNED = (1<<0),
268  FLAG_IS_FLOAT = (1<<1),
269  FLAG_HAS_SCALE = (1<<2),
270  FLAG_ROUNDING = (1<<3),
271  };

Constructor & Destructor Documentation

◆ PackedParameters() [1/3]

SG::PackedParameters::PackedParameters ( )

Default constructor.

Set up to write unsigned integers with 32 bits.

Definition at line 25 of file PackedParameters.cxx.

26  : m_nbits(8 * sizeof(uint32_t)),
27  m_nmantissa(23),
28  m_scale(0),
29  m_flags(0)
30 {
31 }

◆ PackedParameters() [2/3]

SG::PackedParameters::PackedParameters ( uint8_t  nbits,
uint8_t  flags 
)

Constructor from nbits and flags.

Parameters
nbitsThe number of bits for each element.
flagsExtra flags describing the packing.

Additionally nmantissa is set to correspond to a fixed-point representation and the scale is cleared.

This is meant to be used by the read converter.

Definition at line 44 of file PackedParameters.cxx.

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 }

◆ PackedParameters() [3/3]

template<class T >
SG::PackedParameters::PackedParameters ( )

Initialize with default packing parameters for type T.

For integer types, the number of bits and signedness is set to match T. For floating types, nbits is set to 32, nmantissa to 23, isSigned to true, and the scale is cleared.

Member Function Documentation

◆ flags()

uint8_t SG::PackedParameters::flags ( ) const

Additional flags describing the packing.

(This should really only be used by converters.)

◆ hasScale()

bool SG::PackedParameters::hasScale ( ) const

Should floats be rescaled before writing?

◆ isFloat()

bool SG::PackedParameters::isFloat ( ) const

Are elements being written as floating-point numbers?

◆ isSigned()

bool SG::PackedParameters::isSigned ( ) const

Are elements being written as signed numbers?

◆ isValidOption()

bool SG::PackedParameters::isValidOption ( const AuxDataOption option)
static

Test to see if option is a recognized packing option.

Parameters
optionThe option to test.

Returns true if the name of option is recognized as a valid packing option; false otherwise.

Definition at line 197 of file PackedParameters.cxx.

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 }

◆ nbits()

uint8_t SG::PackedParameters::nbits ( ) const

The number of bits used to store each element.

◆ nmantissa()

uint8_t SG::PackedParameters::nmantissa ( ) const

The number of bits used for the mantissa portion of a float-point representation, excluding a sign bit (if any).

If there are at least two bits left over after accounting for the mantissa and sign bits, then numbers will be saved in a floating-point format; otherwise, fixed-point.

◆ rounding()

bool SG::PackedParameters::rounding ( ) const

Should floats be rounded during writing?

◆ scale()

float SG::PackedParameters::scale ( ) const

Return the scale for floating-point numbers.

If enabled, float-point numbers will be divided by this value before being saved. If not enabled, this may return 0.

◆ setFloat()

bool SG::PackedParameters::setFloat ( bool  flag)

Set the floating-point flag.

Parameters
flagShould numbers be written as floating-point?

If true, numbers will be written in a floating/fixed point representation; otherwise, they will be written as integers.

Returns true to indicate success.

Definition at line 180 of file PackedParameters.cxx.

181 {
182  if (flag)
184  else
186  return true;
187 }

◆ setNbits()

bool SG::PackedParameters::setNbits ( uint8_t  nbits)

Set the number of bits to be used for each element.

nbits The desired number of bits.

nbits must be in the range 1-32 for unsigned numbers, 2-32 for signed numbers.

If necessary, nmantissa will be adjusted so that it still fits within the requested number of bits.

Returns true if successful, false otherwise.

Definition at line 69 of file PackedParameters.cxx.

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 }

◆ setNmantissa()

bool SG::PackedParameters::setNmantissa ( uint8_t  nmantissa)

Set the number of mantissa bits used in the packed representation.

nmantissa The desired number of mantissa bits.

This has an effect only when saving floating-point types.

nmantissa must fit within the requested number of bits. nmantissa does not include the sign bit. If there are at least two bits left over, then numbers will be saved in a floating-point format; otherwise, fixed point will be used.

Returns true if successful, false otherwise.

Definition at line 95 of file PackedParameters.cxx.

96 {
97  uint8_t navail = m_nbits;
98  if (isSigned()) --navail;
99  if (nmantissa <= 0 || nmantissa > navail) return false;
101  return true;
102 }

◆ setOption()

bool SG::PackedParameters::setOption ( const AuxDataOption option)

Set a packing option.

Parameters
optionThe option to set.

Recognized options are ‘nbits’, ‘nmantissa’, ‘scale’, ‘signed’, ‘rounding’, and ‘float’. See the setter functions above for details on their semantics.

Returns true on success; false otherwise.

Definition at line 222 of file PackedParameters.cxx.

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 }

◆ setRounding()

bool SG::PackedParameters::setRounding ( bool  flag)

Set the rounding mode.

Parameters
flagShould numbers be rounded when being written?

This has an effect only when saving floating-point types.

Returns true to indicate success.

Definition at line 161 of file PackedParameters.cxx.

162 {
163  if (flag)
165  else
167  return true;
168 }

◆ setScale()

bool SG::PackedParameters::setScale ( float  scale)

Set the scale to use when packing floating-point data.

Parameters
scaleThe new scale, or 0 to disable.

This has an effect only when saving floating-point types.

If set to something non-zero, then floating-point numbers will be divided by this value before being written.

Returns true to indicate success.

Definition at line 116 of file PackedParameters.cxx.

117 {
118  m_scale = scale;
119  if (m_scale == 0 || m_scale == 1)
121  else
123  return true;
124 }

◆ setSigned()

bool SG::PackedParameters::setSigned ( bool  flag)

Set the signedness flag for the packed representation.

Parameters
flagShould elements be saved as signed numbers?

If the flag is false (unsigned), this always succeeds. If the flag is true (signed), then this fails if nbits is 1. nmantissa will be adjusted if there are now insufficient bits for it.

Returns true if successful, false otherwise.

Definition at line 138 of file PackedParameters.cxx.

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 }

Member Data Documentation

◆ m_flags

uint8_t SG::PackedParameters::m_flags
private

Additional flags.

Definition at line 286 of file PackedParameters.h.

◆ m_nbits

uint8_t SG::PackedParameters::m_nbits
private

The number of bits to use for each element.

Definition at line 276 of file PackedParameters.h.

◆ m_nmantissa

uint8_t SG::PackedParameters::m_nmantissa
private

The number of bits for the mantissa of floating-point representations.

Does not include the sign bit.

Definition at line 280 of file PackedParameters.h.

◆ m_scale

float SG::PackedParameters::m_scale
private

If nonzero, divide floating-point numbers by this before writing.

Definition at line 283 of file PackedParameters.h.


The documentation for this class was generated from the following files:
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::PackedParameters::flags
uint8_t flags() const
Additional flags describing the packing.
SG::PackedParameters::m_flags
uint8_t m_flags
Additional flags.
Definition: PackedParameters.h:286
SG::PackedParameters::setNbits
bool setNbits(uint8_t nbits)
Set the number of bits to be used for each element.
Definition: PackedParameters.cxx:69
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?
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::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::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