Belle II Software development
JSignal.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 Signals in CDC Trigger for 3D tracker.
11//-----------------------------------------------------------------------------
12
13#ifndef TRGCDCJSignal_FLAG_
14#define TRGCDCJSignal_FLAG_
15
16#include <string>
17#include <vector>
18#include <utility>
19#include <map>
20#include <tuple>
21
22#ifdef TRGCDC_SHORT_NAMES
23#define JSignal TRGCDCJSignal
24#endif
25
26namespace Belle2 {
32 class TRGCDCJSignalData;
33
36
37 public:
38
44 TRGCDCJSignal(int const& bitwidth, double const& value, double const& min, double const& max, int const& clock, TRGCDCJSignalData*);
46 TRGCDCJSignal(int const& bitwidth, double const& value, double const& min, double const& max, TRGCDCJSignalData*);
48 TRGCDCJSignal(signed long long const& intValue, double const& toReal, signed long long const& minInt,
49 signed long long const& maxInt, double const& actual, double const& minActual, double const& maxActual, int const& finishClock,
50 TRGCDCJSignalData*, bool b_slv = 0);
52 TRGCDCJSignal(double const& value, double const& toReal, TRGCDCJSignalData*);
54 TRGCDCJSignal(std::vector<bool> const& slvValue, int const& finishClock, TRGCDCJSignalData*);
55
58
60 TRGCDCJSignal& assignTo(TRGCDCJSignal const& rhs, int targetClock, std::string& finalCode);
62 TRGCDCJSignal& assignTo(TRGCDCJSignal const& rhs, int targetClock);
66 TRGCDCJSignal const operator- () const;
68 TRGCDCJSignal const operator+ (TRGCDCJSignal const& rhs) const;
70 TRGCDCJSignal const operator- (TRGCDCJSignal const& rhs) const;
72 TRGCDCJSignal const operator* (TRGCDCJSignal const& rhs) const;
73
75 void dump() const;
77 TRGCDCJSignal const shift(int nBits, int operate = 1) const;
79 TRGCDCJSignal const offset(TRGCDCJSignal const& valueMin) const;
81 TRGCDCJSignal const invOffset(TRGCDCJSignal const& valueMin) const;
84 static void choose(TRGCDCJSignal& target, TRGCDCJSignal const& targetMin, TRGCDCJSignal const& targetMax,
85 TRGCDCJSignal const& reference, std::vector<std::vector<TRGCDCJSignal> > data, int targetClock);
87 static void choose(TRGCDCJSignal& target, TRGCDCJSignal const& targetMin, TRGCDCJSignal const& targetMax,
88 TRGCDCJSignal const& reference, const std::vector<std::vector<TRGCDCJSignal> >& data);
90 static void choose(TRGCDCJSignal& target, TRGCDCJSignal const& reference, const std::vector<std::vector<TRGCDCJSignal> >& data,
91 int targetClock);
93 static void choose(TRGCDCJSignal& target, TRGCDCJSignal const& reference, const std::vector<std::vector<TRGCDCJSignal> >& data);
95 static void ifElse(std::vector<std::pair<TRGCDCJSignal, std::vector<std::pair<TRGCDCJSignal*, TRGCDCJSignal> > > >& data,
96 int targetClock);
98 static void ifElse(std::vector<std::pair<TRGCDCJSignal, std::vector<std::pair<TRGCDCJSignal*, TRGCDCJSignal> > > >& data);
100 TRGCDCJSignal const limit(signed long long minInt, signed long long maxInt, double minActual, double maxActual) const;
102 TRGCDCJSignal const limit(TRGCDCJSignal const& min, TRGCDCJSignal const& max) const;
104 TRGCDCJSignal const resize(int bitwidth) const;
106 //TRGCDCJSignal const toSigned() const;
108 //TRGCDCJSignal const toUnsigned() const;
110 static TRGCDCJSignal const toSlv(TRGCDCJSignal const& in, int test);
112 static TRGCDCJSignal const toSlv(TRGCDCJSignal const&);
113
115 static TRGCDCJSignal const slvToSigned(TRGCDCJSignal const& in, double const& toReal, signed long long const& minInt,
116 signed long long const& maxInt, double const& actual, double const& minActual, double const& maxActual, int const& finishClock);
118 static TRGCDCJSignal const slvToSigned(TRGCDCJSignal const& in);
120 static TRGCDCJSignal const slvToUnsigned(TRGCDCJSignal const& in, double const& toReal, signed long long const& minInt,
121 signed long long const& maxInt, double const& actual, double const& minActual, double const& maxActual, int const& finishClock);
123 static TRGCDCJSignal const slvToUnsigned(TRGCDCJSignal const& in);
125 static TRGCDCJSignal const signedToSlv(TRGCDCJSignal const& in);
128
130 static TRGCDCJSignal comp(TRGCDCJSignal const& lhs, const std::string& operate, TRGCDCJSignal const& rhs);
131
132
135 void setName(const std::string& name);
137 void setInt(signed long long value);
139 void setActual(double value);
141 void setToReal(double value);
143 void setType(int type);
145 void setBitsize(int bitsize);
147 void setFinishClock(int finishClock);
149 void setDebug(bool debug);
151 void setPrintVhdl(bool printVhdl);
153 void setVhdlOutputFile(const std::string& filename);
157 std::string getName() const;
159 int getType() const;
161 double getBitsize() const;
163 signed long long getInt() const;
165 signed long long getMinInt() const;
167 signed long long getMaxInt() const;
169 double getActual() const;
171 double getMinActual() const;
173 double getMaxActual() const;
175 double getRealInt() const;
177 double getRealMinInt() const;
179 double getRealMaxInt() const;
181 double getToReal() const;
183 int getFinishClock() const;
185 std::vector<std::pair<std::string, std::vector<int> > > const getArgumentSignals() const;
189 int calType() const;
191 int calType(double minValue) const;
193 int calBitwidth() const;
195 int calBitwidth(int type, signed long long minInt, signed long long maxInt);
197 int calFinishClock() const;
199 std::string getVhdlCode() const;
201 bool getPrintVhdl() const;
203 std::string getVhdlOutputFile() const;
204
207 void matchUnit(TRGCDCJSignal& first, TRGCDCJSignal& second) const;
209 void swap(TRGCDCJSignal& first, TRGCDCJSignal& second) const;
211 bool orderLargestBitsize(TRGCDCJSignal& large, TRGCDCJSignal& small) const;
213 signed long long calMaxInteger() const;
215 signed long long calMinInteger() const;
217 static TRGCDCJSignal const absolute(TRGCDCJSignal const& first);
219 //void calTypeBitwidth(TRGCDCJSignal const & first, std::string operation, TRGCDCJSignal const & second, int & type, int & bitwidth) const;
221 static signed long long calInt(double value, TRGCDCJSignal const& mother);
223 static void calVhdlTypeBitwidth(TRGCDCJSignal const& first, const std::string& operation, TRGCDCJSignal const& second, int& type,
224 int& bitwidth);
226 void initArgumentSignals();
228 static void combineArguments(TRGCDCJSignal const& first, TRGCDCJSignal const& second, TRGCDCJSignal& result) ;
230 void initVhdlCode();
232 void toSignedVhdlCode();
234 void toUnsignedVhdlCode();
236 static void vhdlCode(TRGCDCJSignal const& first, const std::string& operation, TRGCDCJSignal const& second,
237 TRGCDCJSignal const& result,
238 std::string& targtVhdlCode);
240 static void vhdlCode(const std::string& operation, TRGCDCJSignal const& first, TRGCDCJSignal const& result,
241 std::string& targetVhdlCode);
243 static std::string replaceWithSignalNames(std::string const& fromVhdlCode,
244 std::vector<std::pair<std::string, std::vector<int> > > const& fromVhdlSignals, int const& finishClock,
245 std::map<std::string, std::vector<int> >& buffers);
247 static std::string assignVhdlCode(TRGCDCJSignal const& target, TRGCDCJSignal const& from);
249 static std::string chooseVhdlCode(TRGCDCJSignal const& target, TRGCDCJSignal const& reference,
250 std::vector<std::vector<TRGCDCJSignal> > const& data);
252 static std::string ifElseVhdlCode(std::vector<std::pair<TRGCDCJSignal, std::vector<std::pair<TRGCDCJSignal*, TRGCDCJSignal> > > >
253 const& data);
255 void printVhdl(const std::string& vhdlCode) const;
257 void checkInt(const std::string& name) const;
259 static bool isSameSignal(TRGCDCJSignal const& lhs, TRGCDCJSignal const& rhs);
262 // cppcheck-suppress constParameter
263 static void valuesToMapSignals(std::vector<std::tuple<std::string, double, int, double, double, int> > const& inValues,
264 Belle2::TRGCDCJSignalData* inCommonData, std::map<std::string, Belle2::TRGCDCJSignal>& outMap);
268 static void mapSignalsToValues(std::map<std::string, Belle2::TRGCDCJSignal>const& inMap,
269 std::vector<std::pair<std::string, int> > const& inChoose,
270 std::vector<std::tuple<std::string, double, int, double, double, int> >& outValues);
271
272 private:
273
276 std::string m_name;
278 int m_type;
282 signed long long m_int;
284 std::vector<bool> m_slv;
286 signed long long m_minInt;
288 signed long long m_maxInt;
290 double m_actual;
296 double m_toReal;
300 std::string m_vhdlCode;
303 std::vector<std::pair<std::string, std::vector<int> > > m_argumentSignals;
306 //bool m_printVhdl;
309
310 };
311
313}
314
315#endif /* TRGCDCJSignal_FLAG_ */
A class to hold common data for JSignals.
Definition: JSignalData.h:33
A class to use Signals for TRGCDC 3D tracker.
Definition: JSignal.h:35
std::vector< std::pair< std::string, std::vector< int > > > m_argumentSignals
vector<int> is {type, bitwidth, clock} Holds the arguments that made the signal.
Definition: JSignal.h:303
~TRGCDCJSignal()
Destructor.
Definition: JSignal.h:57
int m_finishClock
Holds the clock tick when the signal is valid.
Definition: JSignal.h:305
double m_toReal
The toReal value.
Definition: JSignal.h:296
double m_minActual
The minimum float value.
Definition: JSignal.h:292
static TRGCDCJSignal const signedToSlv(TRGCDCJSignal const &in)
Change signed to slv.
bool m_debug
The debug flag.
Definition: JSignal.h:298
signed long long m_minInt
The minimum integer value.
Definition: JSignal.h:286
double m_maxActual
The maximum float value.
Definition: JSignal.h:294
int m_bitsize
+1: unsigned.
Definition: JSignal.h:280
int m_type
Type of signal.
Definition: JSignal.h:278
signed long long m_int
integer value of signal.
Definition: JSignal.h:282
static TRGCDCJSignal const unsignedToSlv(TRGCDCJSignal const &in)
Change unsigned to slv.
TRGCDCJSignalData * m_commonData
The common JSignalData.
Definition: JSignal.h:308
signed long long m_maxInt
The maximum integer value.
Definition: JSignal.h:288
std::string m_name
Memebers.
Definition: JSignal.h:276
std::string m_vhdlCode
Holds the vhdl code.
Definition: JSignal.h:300
double m_actual
The float value.
Definition: JSignal.h:290
std::vector< bool > m_slv
storage for std_logic_vector. (Will be deprecated.)
Definition: JSignal.h:284
signed long long calMaxInteger() const
Calculate max value for a binary number.
Definition: JSignal.cc:1535
int calType() const
Calculated what type the signal is.
Definition: JSignal.cc:1447
double getActual() const
Get float value of signal.
Definition: JSignal.cc:1392
TRGCDCJSignal const invOffset(TRGCDCJSignal const &valueMin) const
Outputs a signal that is not offset.
Definition: JSignal.cc:606
void printVhdl(const std::string &vhdlCode) const
Prints vhdl code.
Definition: JSignal.cc:2159
std::string getName() const
Get name of signal.
Definition: JSignal.cc:1362
std::string getVhdlOutputFile() const
Gets the vhdl output file name.
Definition: JSignal.cc:1506
void setCommonData(TRGCDCJSignalData *)
Sets JSignalData to signal.
Definition: JSignal.cc:1357
void setBitsize(int bitsize)
Sets bitwidth of signal.
Definition: JSignal.cc:1323
TRGCDCJSignal const operator-() const
Unary operator.
Definition: JSignal.cc:279
static void vhdlCode(TRGCDCJSignal const &first, const std::string &operation, TRGCDCJSignal const &second, TRGCDCJSignal const &result, std::string &targtVhdlCode)
Writes vhdl code using two signals.
Definition: JSignal.cc:1781
static void valuesToMapSignals(std::vector< std::tuple< std::string, double, int, double, double, int > > const &inValues, Belle2::TRGCDCJSignalData *inCommonData, std::map< std::string, Belle2::TRGCDCJSignal > &outMap)
Values => [name, value, bitwidth, min, max, clock] Changes values to signals.
Definition: JSignal.cc:2208
TRGCDCJSignal const operator+(TRGCDCJSignal const &rhs) const
Arithmetic add operator.
Definition: JSignal.cc:310
TRGCDCJSignal & assignTo(TRGCDCJSignal const &rhs, int targetClock, std::string &finalCode)
Assign operator with setting target clock with outputing final code.
Definition: JSignal.cc:172
TRGCDCJSignal const offset(TRGCDCJSignal const &valueMin) const
Outputs an offset signal which is an unsigned signal.
Definition: JSignal.cc:592
bool orderLargestBitsize(TRGCDCJSignal &large, TRGCDCJSignal &small) const
Orders the TRGCDCJSignals by bitsize. Next priority is unsigned, signed, minus unsigned....
Definition: JSignal.cc:1515
static bool isSameSignal(TRGCDCJSignal const &lhs, TRGCDCJSignal const &rhs)
Checks if signal is same signal.
Definition: JSignal.cc:2201
void setActual(double value)
Sets float value of signal.
Definition: JSignal.cc:1308
static std::string replaceWithSignalNames(std::string const &fromVhdlCode, std::vector< std::pair< std::string, std::vector< int > > > const &fromVhdlSignals, int const &finishClock, std::map< std::string, std::vector< int > > &buffers)
Writes final vhdl code.
Definition: JSignal.cc:1899
TRGCDCJSignal const shift(int nBits, int operate=1) const
Shift signal. Shift direction is right. operate=0 to change m_toReal(unit).
Definition: JSignal.cc:561
TRGCDCJSignalData * getCommonData() const
Get the sharged JSignalData.
Definition: JSignal.cc:1437
double getMaxActual() const
Get maximum float value of signal.
Definition: JSignal.cc:1402
static void choose(TRGCDCJSignal &target, TRGCDCJSignal const &targetMin, TRGCDCJSignal const &targetMax, TRGCDCJSignal const &reference, std::vector< std::vector< TRGCDCJSignal > > data, int targetClock)
Case method.
Definition: JSignal.cc:621
static TRGCDCJSignal const toSlv(TRGCDCJSignal const &in, int test)
Change signal to std_logic_vector using vector<bool>. (Will be deprecated.)
Definition: JSignal.cc:1121
void initArgumentSignals()
Initializes the argument signals for the signal.
Definition: JSignal.cc:1707
void setVhdlOutputFile(const std::string &filename)
Sets ouptut VHDL filename.
Definition: JSignal.cc:1349
std::string getVhdlCode() const
Gets the vhdl code for the signal.
Definition: JSignal.cc:1492
void setInt(signed long long value)
Sets integer value of signal.
Definition: JSignal.cc:1303
int calBitwidth() const
Calculates the bit width.
Definition: JSignal.cc:1461
bool getPrintVhdl() const
Gets the print vhdl flag from common JSignalData class.
Definition: JSignal.cc:1497
static void ifElse(std::vector< std::pair< TRGCDCJSignal, std::vector< std::pair< TRGCDCJSignal *, TRGCDCJSignal > > > > &data, int targetClock)
If else implementation with target clock.
Definition: JSignal.cc:800
std::vector< std::pair< std::string, std::vector< int > > > const getArgumentSignals() const
Gets the signal names and values that made this signal.
Definition: JSignal.cc:1432
static std::string assignVhdlCode(TRGCDCJSignal const &target, TRGCDCJSignal const &from)
Writes the assign vhdl code.
Definition: JSignal.cc:1948
TRGCDCJSignal const resize(int bitwidth) const
Resizes signal.
Definition: JSignal.cc:989
double getRealMinInt() const
Get converted float value of minimum integer.
Definition: JSignal.cc:1412
static void combineArguments(TRGCDCJSignal const &first, TRGCDCJSignal const &second, TRGCDCJSignal &result)
Combines arguments of signals.
Definition: JSignal.cc:1734
static std::string chooseVhdlCode(TRGCDCJSignal const &target, TRGCDCJSignal const &reference, std::vector< std::vector< TRGCDCJSignal > > const &data)
Writes the choose vhdl code.
Definition: JSignal.cc:2004
static TRGCDCJSignal const absolute(TRGCDCJSignal const &first)
Absolute TRGCDCJSignal. Removes 1 bit if signed or minus unsigned.
Definition: JSignal.cc:1562
int getFinishClock() const
Gets clock tick where signal is make.
Definition: JSignal.cc:1427
static signed long long calInt(double value, TRGCDCJSignal const &mother)
Calculates integer value with unit of a TRGCDCJSignal.
Definition: JSignal.cc:1662
void setFinishClock(int finishClock)
Sets finish clock of signal.
Definition: JSignal.cc:1331
signed long long getInt() const
Get integer value of signal.
Definition: JSignal.cc:1377
double getToReal() const
Get toReal value of signal.
Definition: JSignal.cc:1422
void matchUnit(TRGCDCJSignal &first, TRGCDCJSignal &second) const
Utilities.
Definition: JSignal.cc:1260
void setDebug(bool debug)
Sets debug flag for signal.
Definition: JSignal.cc:1336
TRGCDCJSignal const limit(signed long long minInt, signed long long maxInt, double minActual, double maxActual) const
Limits min and max values using specific integers. Use only for ifElse. Doesn't check overflow,...
Definition: JSignal.cc:957
static void calVhdlTypeBitwidth(TRGCDCJSignal const &first, const std::string &operation, TRGCDCJSignal const &second, int &type, int &bitwidth)
Calculates vhdl bitwidth and type for operation.
Definition: JSignal.cc:1667
void setName(const std::string &name)
Setters, Getters Sets name of signal.
Definition: JSignal.cc:1298
double getRealMaxInt() const
Get converted float value of maximum integer.
Definition: JSignal.cc:1417
void checkInt(const std::string &name) const
Checks underflow or overflow for TRGCDCJSignal.
Definition: JSignal.cc:2173
void swap(TRGCDCJSignal &first, TRGCDCJSignal &second) const
Swaps the TRGCDCJSignals.
Definition: JSignal.cc:1241
TRGCDCJSignal const operator*(TRGCDCJSignal const &rhs) const
Arithmetic multiply operator.
Definition: JSignal.cc:432
double getBitsize() const
Get bitwidth of signal.
Definition: JSignal.cc:1372
TRGCDCJSignal & operator<=(TRGCDCJSignal const &rhs)
Assign operator.
Definition: JSignal.cc:272
signed long long calMinInteger() const
Calculate min value for a binary number.
Definition: JSignal.cc:1548
void initVhdlCode()
Initializes the vhdl code.
Definition: JSignal.cc:1741
void setPrintVhdl(bool printVhdl)
Sets print flag for signal.
Definition: JSignal.cc:1341
int getType() const
Get type of signal.
Definition: JSignal.cc:1367
static std::string ifElseVhdlCode(std::vector< std::pair< TRGCDCJSignal, std::vector< std::pair< TRGCDCJSignal *, TRGCDCJSignal > > > > const &data)
Writes the ifElse vhdl code.
Definition: JSignal.cc:2115
void toUnsignedVhdlCode()
Changes signal type to unsigned type in VHDL.
Definition: JSignal.cc:1768
double getMinActual() const
Get minimum float value of signal.
Definition: JSignal.cc:1397
signed long long getMaxInt() const
Get maximum integer value of signal.
Definition: JSignal.cc:1387
int calFinishClock() const
Claculates the clock tick where the signal is valid.
Definition: JSignal.cc:1477
static TRGCDCJSignal const slvToUnsigned(TRGCDCJSignal const &in, double const &toReal, signed long long const &minInt, signed long long const &maxInt, double const &actual, double const &minActual, double const &maxActual, int const &finishClock)
Change slv to unsigned with target clock.
Definition: JSignal.cc:1081
void dump() const
Methods.
Definition: JSignal.cc:539
double getRealInt() const
Get converted float value of integer.
Definition: JSignal.cc:1407
TRGCDCJSignal()
Constructor.
Definition: JSignal.cc:55
signed long long getMinInt() const
Get minimum integer value of signal.
Definition: JSignal.cc:1382
void setToReal(double value)
Sets toReal factor of signal.
Definition: JSignal.cc:1313
static void mapSignalsToValues(std::map< std::string, Belle2::TRGCDCJSignal >const &inMap, std::vector< std::pair< std::string, int > > const &inChoose, std::vector< std::tuple< std::string, double, int, double, double, int > > &outValues)
Choose => [signalName, FpgaEffects(=1)/NoFpgaEffects(=0)] Values => [name, value, bitwidth,...
Definition: JSignal.cc:2225
void setType(int type)
Sets type of signal.
Definition: JSignal.cc:1318
void toSignedVhdlCode()
Changes signal type to signed type in VHDL.
Definition: JSignal.cc:1750
static TRGCDCJSignal comp(TRGCDCJSignal const &lhs, const std::string &operate, TRGCDCJSignal const &rhs)
Compare two signals.
Definition: JSignal.cc:1169
static TRGCDCJSignal const slvToSigned(TRGCDCJSignal const &in, double const &toReal, signed long long const &minInt, signed long long const &maxInt, double const &actual, double const &minActual, double const &maxActual, int const &finishClock)
Change slv to signed with target clock.
Definition: JSignal.cc:1040
Abstract base class for different kinds of events.