ATLAS Offline Software
Compressor.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*
6  * Compressor.h
7  * Compressor
8  *
9  * Created by Ilija Vukotic on 05/07/07.
10  * <ivukotic@cern.ch>
11  *
12  */
13 
14 
15 #ifndef ATHENAPOOLCNVSVC_COMPRESSOR_H
16 #define ATHENAPOOLCNVSVC_COMPRESSOR_H
17 
18 // TO DO :
19 // add double to int compressor
20 // enable 32 bit "compression"
21 // should be smart enough to call compression to short when 16 bits required. or maybe people should be aware that 16 bits is faster than 17?
22 
23 #include <vector>
24 #include <iostream>
25 
26 class Compressor{
27 
28 public:
30  m_sign=false;
31  m_bits=16;
32  m_bitStrip = false;
33  }
35 
36  void setNrBits(int bits){
37  m_bits=bits;
38  m_bitStrip=true; // will be used to disable compression (already programmed for compressor but not decompressor.)
39  if (bits<12){
40  std::cout<<"WARNING -> Too large compression requested. Will leave 12 bits instead!"<<std::endl;
41  m_bits=12;
42  }
43  else if(bits>=32 || bits==0){
44  std::cout<<"WARNING -> Compression to "<<bits<<" bits is not possible. Compressing to 31 bits !"<<std::endl;
45  m_bits=31;
46  }
47  }
48 
49  void setIgnoreSign(){m_sign=true;}
50 
51  // standard compression 32 to 16 bits - precision is better than 0.4%
52  void reduceToUS(const std::vector<float> &vf, std::vector<unsigned short> &vi);
53 
54  // standard uncompression from 16 bits to 32
55  void expandFromUStoFloat(const std::vector<unsigned short> &vi, std::vector<float>&vf);
56 
57  //------------
58 
59  // compression with variable sign, range and precision
60  void reduce(const std::vector<float> & vf, std::vector<unsigned int> &vi);
61 
62  // uncompression with variable sign,range and precision
63  void expandToFloat(const std::vector<unsigned int> & vc, std::vector<float> & vf);
64 
65 private:
66  int m_bits;
67  bool m_sign;
68  bool m_bitStrip;
69 };
70 
71 #endif // not ATHENAPOOLCNVSVC_COMPRESSOR_H
Compressor::reduceToUS
void reduceToUS(const std::vector< float > &vf, std::vector< unsigned short > &vi)
Definition: Compressor.cxx:18
Compressor
Definition: Compressor.h:26
Compressor::m_bitStrip
bool m_bitStrip
Definition: Compressor.h:68
Compressor::expandToFloat
void expandToFloat(const std::vector< unsigned int > &vc, std::vector< float > &vf)
Definition: Compressor.cxx:115
Compressor::reduce
void reduce(const std::vector< float > &vf, std::vector< unsigned int > &vi)
Definition: Compressor.cxx:42
Compressor::setNrBits
void setNrBits(int bits)
Definition: Compressor.h:36
Compressor::m_sign
bool m_sign
Definition: Compressor.h:67
Compressor::m_bits
int m_bits
Definition: Compressor.h:66
Compressor::~Compressor
~Compressor()
Definition: Compressor.h:34
Compressor::setIgnoreSign
void setIgnoreSign()
Definition: Compressor.h:49
Compressor::expandFromUStoFloat
void expandFromUStoFloat(const std::vector< unsigned short > &vi, std::vector< float > &vf)
Definition: Compressor.cxx:30
Compressor::Compressor
Compressor()
Definition: Compressor.h:29