Belle II Software  release-08-01-10
JLUT.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 //-----------------------------------------------------------------------------
10 // Description : A class for LUT in CDC Trigger
11 //-----------------------------------------------------------------------------
12 
13 #ifndef TRGCDCJLUT_FLAG_
14 #define TRGCDCJLUT_FLAG_
15 
16 #include <string>
17 #include <vector>
18 #include <map>
19 #include <functional>
20 #include "JSignal.h"
21 
22 #ifdef TRGCDC_SHORT_NAMES
23 #define JLUT TRGCDCJLUT
24 #endif
25 
26 namespace Belle2 {
32 //class TRGCDCJSignal;
33 
35  class TRGCDCJLUT {
36 
37  public:
38 
40  TRGCDCJLUT(const std::string& name = "no_name");
41 
43  TRGCDCJLUT(const TRGCDCJLUT& in);
44 
46  virtual ~TRGCDCJLUT();
47 
49  //TRGCDCJLUT& operator= (const TRGCDCJLUT& in);
50 
51  public:
52 
54  std::string name(void) const;
55 
57  std::string version(void) const;
58 
60  void setData(int inputBitsize, int outputBitSize, const std::string& filename, bool twoscomplement = 0);
61 
63  void setFunction(std::function<int(int)> function);
64 
66  int setFloatFunction(std::function<double(double)> function,
67  TRGCDCJSignal const& input,
68  TRGCDCJSignal const& minInv, TRGCDCJSignal const& maxInv, double outputToReal,
69  int lutInputBitwidth, int lutOutputBitwidth);
70 
72  void setOutputFlag(int outputFlag);
73 
75  void setBitsize(int inputBitsize, int outputBitsize);
76 
78  void setInputBitsize(int inputBitsize);
79 
81  void setOutputBitsize(int outputBitsize);
82 
84  std::string getFileName() const;
85 
87  int getInputBitsize() const;
88 
90  int getOutputBitsize() const;
91 
93  std::function<int(int)> getFunction();
94 
96  std::function<double(double)> getFloatFunction();
97 
99  int getOutputFlag() const;
100 
102  int getOutputType() const;
103 
105  int getOutput(int) const;
106 
108  double getFloatOutput(double) const;
109 
111  void dump();
112 
114  void makeCOE(const std::string& fileName = "");
115 
117  std::vector<double> m_const;
118 
120  std::string operate(std::string out, std::string in, std::map<std::string, std::map<std::string, double>* >& m_intStorage);
121 
123  TRGCDCJSignal const operate(const TRGCDCJSignal& in, TRGCDCJSignal& out);
124 
126  void operateNoOffset(TRGCDCJSignal const& in, TRGCDCJSignal& out) const;
127 
129  std::string const lutVhdlCode(std::string const& shiftOffsetInput) const;
130 
131  private:
132 
134  std::string m_name;
135 
137  std::vector<int> m_data;
138 
140  std::string m_fileName;
141 
143  std::function<int(int)> m_function;
144 
146  std::function<double(double)> m_floatFunction;
147 
150 
153 
156 
158  bool m_write;
159 
162 
165 
168 
171 
173  double m_toReal;
174 
177 
179  double m_outputType;
180 
183 
186 
189 
192 
195 
198 
199  };
200 
201 //-----------------------------------------------------------------------------
202 
203  inline
204  std::string
205  TRGCDCJLUT::name(void) const
206  {
207  return m_name;
208  }
209 
210 
212 } // namespace Belle2
213 
214 #endif /* TRGCDCLUT_FLAG_ */
A class to use LUTs for TRGCDC.
Definition: JLUT.h:35
double m_outputIntMax
The integer offset of the output for LUT.
Definition: JLUT.h:167
bool m_write
VHDL write flag for signals. 1: Write is on. 0: Write is off.
Definition: JLUT.h:158
int m_outputFlag
Flag for output. 0 is from function. 1 is from LUT file.
Definition: JLUT.h:149
TRGCDCJSignal m_shiftOffsetOutputMax
The maximum output value that is bit shifted.
Definition: JLUT.h:194
double m_toReal
The factor to change integer to float value.
Definition: JLUT.h:173
TRGCDCJSignal m_shiftOutputMin
The minimum output signal that is bit shifted.
Definition: JLUT.h:191
void operateNoOffset(TRGCDCJSignal const &in, TRGCDCJSignal &out) const
Output is LUT Out + offset. Input is non offset input.
std::function< int(int)> m_function
LUT function.
Definition: JLUT.h:143
double m_outputOffset
The float offset of the output for LUT.
Definition: JLUT.h:164
int m_inputShiftBits
The number of bits to shift to make input the wanted bit width.
Definition: JLUT.h:176
TRGCDCJSignal m_inputMin
The minimum input signal.
Definition: JLUT.h:185
std::string m_fileName
LUT filename.
Definition: JLUT.h:140
double m_outputType
The output type of the LUT. (Will be deprecated.)
Definition: JLUT.h:179
int m_inputBitsize
input bitsize. Number of bits.
Definition: JLUT.h:152
std::vector< int > m_data
LUT data.
Definition: JLUT.h:137
TRGCDCJSignal m_shiftOffsetInput
The bt shifted offset signal of input.
Definition: JLUT.h:197
int m_outputBitsize
output bitsize. Number of bits.
Definition: JLUT.h:155
std::function< double(double)> m_floatFunction
Float LUT function.
Definition: JLUT.h:146
double m_inputOffset
Changing float function to int function variables.
Definition: JLUT.h:161
std::vector< double > m_const
Storage for values used in function.
Definition: JLUT.h:117
TRGCDCJSignal m_inputMax
The maximum input signal.
Definition: JLUT.h:188
double m_inputToReal
The factor of the input integer to change to float value.
Definition: JLUT.h:170
std::string m_name
Name.
Definition: JLUT.h:134
double m_outputNBitsWithOffset
The output bit width with offset. (Will be deprecated.)
Definition: JLUT.h:182
A class to use Signals for TRGCDC 3D tracker.
Definition: JSignal.h:35
TRGCDCJLUT(const std::string &name="no_name")
Contructor.
Definition: JLUT.cc:47
virtual ~TRGCDCJLUT()
Destructor.
Definition: JLUT.cc:82
void setData(int inputBitsize, int outputBitSize, const std::string &filename, bool twoscomplement=0)
set LookUpTable(LUT) data.
Definition: JLUT.cc:86
void setOutputBitsize(int outputBitsize)
set output bitsize.
Definition: JLUT.cc:363
std::string version(void) const
returns version.
Definition: JLUT.cc:42
int setFloatFunction(std::function< double(double)> function, TRGCDCJSignal const &input, TRGCDCJSignal const &minInv, TRGCDCJSignal const &maxInv, double outputToReal, int lutInputBitwidth, int lutOutputBitwidth)
set LUT function using JSignals.
Definition: JLUT.cc:200
double getFloatOutput(double) const
get output using float values.
Definition: JLUT.cc:408
void setBitsize(int inputBitsize, int outputBitsize)
set input & output bitsize.
Definition: JLUT.cc:347
std::function< int(int)> getFunction()
get LUT function using int values.
Definition: JLUT.cc:383
std::string getFileName() const
get LUT filename
Definition: JLUT.cc:368
void makeCOE(const std::string &fileName="")
make COE file.
Definition: JLUT.cc:425
void setFunction(std::function< int(int)> function)
set LUT function directly using int values.
Definition: JLUT.cc:194
int getInputBitsize() const
get input bitsize
Definition: JLUT.cc:373
std::string operate(std::string out, std::string in, std::map< std::string, std::map< std::string, double > * > &m_intStorage)
Operate on LUT. (Will be deprecated.)
Definition: JLUT.cc:475
int getOutputType() const
get output type.
Definition: JLUT.cc:398
std::string name(void) const
Operators.
Definition: JLUT.h:205
int getOutput(int) const
get output using int values.
Definition: JLUT.cc:403
std::function< double(double)> getFloatFunction()
get LUT function using float values.
Definition: JLUT.cc:388
void dump()
Print variables for LUT.
Definition: JLUT.cc:413
void setOutputFlag(int outputFlag)
set output flag.
Definition: JLUT.cc:353
int getOutputBitsize() const
get output bitsize
Definition: JLUT.cc:378
std::string const lutVhdlCode(std::string const &shiftOffsetInput) const
Creates vhdlCode for lut.
Definition: JLUT.cc:596
void setInputBitsize(int inputBitsize)
set input bitsize.
Definition: JLUT.cc:358
int getOutputFlag() const
get output type.
Definition: JLUT.cc:393
Abstract base class for different kinds of events.