ATLAS Offline Software
Loading...
Searching...
No Matches
LinearPacker.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRTCONDITIONSDATA_LINEARPACKER_H
6#define TRTCONDITIONSDATA_LINEARPACKER_H
7
8#include <limits>
9
10namespace TRTCond
11{
15 template <class UnpackedType, class PackedType>
17 {
18 public:
19
22
24 LinearPacker(UnpackedType xmin, UnpackedType xmax) : m_xmin(xmin), m_xmax(xmax) {}
25
27 UnpackedType unpack(PackedType val ) const { return m_xmin + (val-valmin()) * dx() ; }
28
30 PackedType pack(UnpackedType x )const {
31 return x>=m_xmax ? valmax() : (x<=m_xmin ? valmin() : valmin() + PackedType((x - m_xmin) /dx() + 0.5) ) ;
32 }
33
34 private:
35
37 PackedType valmax() const { return std::numeric_limits<PackedType>::max() ; }
38
40 PackedType valmin() const { return std::numeric_limits<PackedType>::min() ; }
41
43 UnpackedType dx() const { return (m_xmax - m_xmin)/(UnpackedType(valmax()-valmin())+1) ; }
44 private:
45 UnpackedType m_xmin ;
46 UnpackedType m_xmax ;
47 } ;
48
49}
50
51#endif
#define x
LinearPacker()
default constructor
UnpackedType m_xmin
minimum data value
UnpackedType m_xmax
maximum data value
PackedType pack(UnpackedType x) const
Pack method.
PackedType valmin() const
returns numeric lower limit of packed type
UnpackedType unpack(PackedType val) const
Unpack method.
PackedType valmax() const
returns numeric upper limit of packed type
UnpackedType dx() const
returns precision of the packed data
LinearPacker(UnpackedType xmin, UnpackedType xmax)
normal constructor
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60