ATLAS Offline Software
PackedParameters.icc
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$
6 /**
7  * @file AthContainers/PackedParameters.icc
8  * @author scott snyder <snyder@bnl.gov>
9  * @date Nov, 2014
10  * @brief Describe how the contents of a @c PackedContainer are to be saved.
11  */
12 
13 
14 namespace SG {
15 
16 
17 /**
18  * @brief Initialize with default packing parameters for type @c T.
19  *
20  * For integer types, the number of bits and signedness is set to match @c T.
21  * For floating types, nbits is set to 32, nmantissa to 23, isSigned to true,
22  * and the scale is cleared.
23  */
24 template <class T>
25 PackedParameters::PackedParameters (T /*val*/)
26  : m_nbits(8 * sizeof(uint32_t)),
27  m_nmantissa(23),
28  m_scale(0),
29  m_flags(0)
30 {
31  if (std::numeric_limits<T>::is_signed)
32  setSigned (true);
33 
34  if (std::numeric_limits<T>::is_integer)
35  setNbits (8*sizeof(T));
36  else
37  setFloat (true);
38 }
39 
40 
41 /**
42  * @brief The number of bits used to store each element.
43  */
44 inline
45 uint8_t PackedParameters::nbits() const
46 {
47  return m_nbits;
48 }
49 
50 
51 /**
52  * @brief The number of bits used for the mantissa portion of a float-point
53  * representation, excluding a sign bit (if any).
54  *
55  * If there are at least two bits left over after accounting
56  * for the mantissa and sign bits, then numbers will be saved
57  * in a floating-point format; otherwise, fixed-point.
58  */
59 inline
60 uint8_t PackedParameters::nmantissa() const
61 {
62  return m_nmantissa;
63 }
64 
65 
66 /**
67  * @brief Additional flags describing the packing.
68  *
69  * (This should really only be used by converters.)
70  */
71 inline
72 uint8_t PackedParameters::flags() const
73 {
74  return m_flags;
75 }
76 
77 
78 /**
79  * @brief Return the scale for floating-point numbers.
80  *
81  * If enabled, float-point numbers will be divided by this value
82  * before being saved. If not enabled, this may return 0.
83  */
84 inline
85 float PackedParameters::scale() const
86 {
87  return m_scale;
88 }
89 
90 
91 /**
92  * @brief Are elements being written as signed numbers?
93  */
94 inline
95 bool PackedParameters::isSigned() const
96 {
97  return m_flags & FLAG_IS_SIGNED;
98 }
99 
100 
101 /**
102  * @brief Are elements being written as floating-point numbers?
103  */
104 inline
105 bool PackedParameters::isFloat() const
106 {
107  return m_flags & FLAG_IS_FLOAT;
108 }
109 
110 
111 /**
112  * @brief Should floats be rescaled before writing?
113  */
114 inline
115 bool PackedParameters::hasScale() const
116 {
117  return m_flags & FLAG_HAS_SCALE;
118 }
119 
120 
121 /**
122  * @brief Should floats be rounded during writing?
123  */
124 inline
125 bool PackedParameters::rounding() const
126 {
127  return m_flags & FLAG_ROUNDING;
128 }
129 
130 
131 } // namespace SG