108 #ifndef L1Trigger_TrackFindingTracklet_interface_imath_h 109 #define L1Trigger_TrackFindingTracklet_interface_imath_h 139 #define MULT_LATENCY 1 140 #define LUT_LATENCY 2 141 #define DSP_LATENCY 3 151 TFile *h_file_ =
new TFile(
"imath.root",
"RECREATE");
217 const std::map<
const VarBase *, std::vector<bool> > *
const previous_passes =
nullptr)
const;
221 const std::map<
const VarBase *, std::set<std::string> > *
const previous_cut_strings =
nullptr)
const;
225 const std::map<
const VarBase *, std::set<std::string> > *
const previous_cut_strings =
nullptr)
const;
233 TH2F *
h() {
return h_; }
244 std::map<std::string, int>
Kmap()
const {
return Kmap_; }
246 double K()
const {
return K_; };
256 virtual void print(std::ofstream &
fs,
Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0) {
257 fs <<
"// VarBase here. Soemthing is wrong!! " << l1 <<
", " << l2 <<
", " << l3 <<
"\n";
259 virtual void print(std::ofstream &
fs,
HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0) {
260 fs <<
"// VarBase here. Soemthing is wrong!! " << l1 <<
", " << l2 <<
", " << l3 <<
"\n";
268 void inputs(std::vector<VarBase *> *
vd);
276 static void design_print(
const std::vector<VarBase *> &
v, std::ofstream &
fs, Verilog);
277 static void design_print(
const std::vector<VarBase *> &
v, std::ofstream &
fs, HLS);
285 static TTree *addToTree(
imathGlobals *globals,
double *
v,
char *
s);
325 void set_hist_pars(
int n = 256,
double p = 0.05) {
342 bool do_assert =
false,
349 double r = Knew /
K_;
369 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
370 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
383 bool do_assert =
false,
390 double r = Knew /
K_;
408 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
409 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
418 :
VarBase(globals,
name, nullptr, nullptr, nullptr, 0) {
428 :
VarBase(globals,
name, nullptr, nullptr, nullptr, 0) {
439 snprintf(slog, 100,
"defining unitless constant, yet K is not a power of 2! %g, %g",
K,
pow(2,
l));
461 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
462 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
469 :
VarBase(globals,
name, nullptr, nullptr, nullptr, 1) {
472 nbits_ = log2(fmax /
K) + 1.999999;
480 snprintf(slog, 100,
"defining unitless constant, yet K is not a power of 2! %g, %g",
K,
pow(2,
l));
507 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
508 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
517 std::map<std::string, int> map1 =
p1->
Kmap();
518 std::map<std::string, int> map2 =
p2->
Kmap();
524 for (
const auto &it : map2) {
525 if (map1.find(it.first) == map1.end())
526 map1[it.first] = -it.second;
528 map1[it.first] = map1[it.first] - it.second;
534 for (
const auto &it : map1) {
535 if (it.second != 0) {
536 if (it.first !=
"2") {
538 slog, 100,
"VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second,
name_.c_str());
542 throw cms::Exception(
"BadConfig") <<
"imath units are different!";
547 double ki1 =
p1->
K() /
pow(2, s1);
548 double ki2 =
p2->
K() /
pow(2, s2);
551 snprintf(slog, 100,
"VarAdd: bad constants! %f %f for variable %s", ki1, ki2,
name_.c_str());
555 throw cms::Exception(
"BadConfig") <<
"imath constants are different!";
561 int s0 = s1 < s2 ? s1 : s2;
567 int n0 = 1 + (n1 > n2 ? n1 : n2);
589 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
590 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
604 std::map<std::string, int> map1 =
p1->
Kmap();
605 std::map<std::string, int> map2 =
p2->
Kmap();
610 for (
const auto &it : map2) {
611 if (map1.find(it.first) == map1.end())
612 map1[it.first] = -it.second;
614 map1[it.first] = map1[it.first] - it.second;
620 for (
const auto &it : map1) {
621 if (it.second != 0) {
622 if (it.first !=
"2") {
624 slog, 100,
"VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second,
name_.c_str());
628 throw cms::Exception(
"BadConfig") <<
"imath units are different!";
633 double ki1 =
p1->
K() /
pow(2, s1);
634 double ki2 =
p2->
K() /
pow(2, s2);
637 snprintf(slog, 100,
"VarAdd: bad constants! %f %f for variable %s", ki1, ki2,
name_.c_str());
641 throw cms::Exception(
"BadConfig") <<
"imath constants are different!";
647 int s0 = s1 < s2 ? s1 : s2;
653 int n0 = 1 + (n1 > n2 ? n1 : n2);
677 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
678 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
695 double ki =
p1->
K() /
pow(2, s1);
700 double c = ki *
pow(2, -
m);
706 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
707 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
728 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
729 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
748 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
749 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
765 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
766 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
793 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
794 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
808 const std::map<std::string, int> map1 =
p1->
Kmap();
809 const std::map<std::string, int> map2 =
p2->
Kmap();
810 for (
const auto &it : map1) {
812 Kmap_[it.first] = it.second;
814 Kmap_[it.first] =
Kmap_[it.first] + it.second;
816 for (
const auto &it : map2) {
818 Kmap_[it.first] = it.second;
820 Kmap_[it.first] =
Kmap_[it.first] + it.second;
842 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
843 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
857 std::map<std::string, int> map1 =
p1->
Kmap();
858 std::map<std::string, int> map2 =
p2->
Kmap();
859 for (
const auto &it : map2) {
860 if (map1.find(it.first) == map1.end())
861 map1[it.first] = it.second;
863 map1[it.first] = map1[it.first] + it.second;
869 std::map<std::string, int> map3 =
p3->
Kmap();
874 for (
const auto &it : map3) {
875 if (map1.find(it.first) == map1.end())
876 map1[it.first] = -it.second;
878 map1[it.first] = map1[it.first] - it.second;
884 for (
const auto &it : map1) {
885 if (it.second != 0) {
886 if (it.first !=
"2") {
889 "VarDSPPostadd: bad units! %s^%i for variable %s",
897 throw cms::Exception(
"BadConfig") <<
"imath units are different!";
902 double ki1 =
k0 /
pow(2, s0);
903 double ki2 =
p3->
K() /
pow(2, s3);
906 snprintf(slog, 100,
"VarDSPPostadd: bad constants! %f %f for variable %s", ki1, ki2,
name_.c_str());
911 throw cms::Exception(
"BadConfig") <<
"imath constants are different!";
917 throw cms::Exception(
"BadConfig") <<
"imath VarDSPPostadd: loosing precision on C in A*B+C: " <<
shift3_;
925 int n0 = 1 + (n12 > n3 ? n12 : n3);
948 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
984 const std::map<std::string, int> map1 =
p1->
Kmap();
985 for (
const auto &it : map1)
986 Kmap_[it.first] = -it.second;
1005 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
1006 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
1008 void writeLUT(std::ofstream &
fs, Verilog)
const;
1024 unsigned int ms =
sizeof(
int) * 8 -
nbits_;
1028 int lut1 = (lround((1 <<
n_) /
i) << ms) >> ms;
1029 int lut2 = (lround((1 <<
n_) / (
i1)) << ms) >> ms;
1030 lut = 0.5 * (lut1 + lut2);
1031 }
else if (
i < -1) {
1034 int lut1 = (lround((1 <<
n_) /
i1) << ms) >> ms;
1035 int lut2 = (lround((1 <<
n_) /
i2) << ms) >> ms;
1036 lut = 0.5 * (lut1 + lut2);
1057 :
VarBase(globals,
"", nullptr, nullptr, nullptr, 0),
1074 const std::map<
const VarBase *, std::vector<bool> > *
const previous_passes =
nullptr)
const;
1079 const std::map<
const VarBase *, std::set<std::string> > *
const previous_cut_strings =
nullptr)
const;
1083 const std::map<
const VarBase *, std::set<std::string> > *
const previous_cut_strings =
nullptr)
const;
1097 template <
class... Args>
1099 :
VarBase(globals,
name, nullptr, nullptr, nullptr, 0) {
1105 template <
class... Args>
1117 void print(std::ofstream &
fs, Verilog,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
1118 void print(std::ofstream &
fs, HLS,
int l1 = 0,
int l2 = 0,
int l3 = 0)
override;
void set_cut_var(VarBase *cut_var, const bool call_add_cut=true)
VarShiftround(imathGlobals *globals, std::string name, VarBase *p1, int shift)
Log< level::Info, true > LogVerbatim
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
static void verilog_print(const std::vector< VarBase *> &v, std::ofstream &fs)
static void hls_print(const std::vector< VarBase *> &v, std::ofstream &fs)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarDef(imathGlobals *globals, std::string name, VarBase *p)
~VarMult() override=default
void inputs(std::vector< VarBase *> *vd)
void add_cut(VarCut *cut, const bool call_set_cut_var=true)
void local_calculate() override
void print_step(int step, std::ofstream &fs, Verilog)
void local_calculate() override
void add_cuts(VarBase *cut, Args... args)
void print_all(std::ofstream &fs, Verilog)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarFlag(imathGlobals *globals, std::string name, VarBase *cut, Args... args)
~VarTimesC() override=default
void local_calculate() override
void add_cuts(VarBase *cut)
std::string pipe_delays(const int step)
void set_fval(double fval)
std::string kstring() const
VarDef(imathGlobals *globals, std::string name, std::string units, double fmax, double K)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
~VarAdd() override=default
~VarParam() override=default
std::vector< int > pipe_delays_
void print(std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, Verilog, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
static struct trklet::VarBase::Verilog verilog
VarInv(imathGlobals *globals, std::string name, VarBase *p1, double offset, int nbits, int n, unsigned int shift, mode m, int nbaddr=-1)
int ival_to_addr(int ival)
void passes(std::map< const VarBase *, std::vector< bool > > &passes, const std::map< const VarBase *, std::vector< bool > > *const previous_passes=nullptr) const
int addr_to_ival(int addr)
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
void local_calculate() override
VarSubtract(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
VarShift(imathGlobals *globals, std::string name, VarBase *p1, int shift)
VarAdd(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void initLUT(double offset)
VarParam(imathGlobals *globals, std::string name, std::string units, double fval, double K)
void local_calculate() override
virtual void local_calculate()
bool local_passes() const
~VarShift() override=default
void set_fval(double fval)
std::map< std::string, int > Kmap() const
void local_calculate() override
void local_calculate() override
~VarSubtract() override=default
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
~VarShiftround() override=default
Abs< T >::type abs(const T &t)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarAdjustK(imathGlobals *globals, std::string name, VarBase *p1, double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
VarNounits(imathGlobals *globals, std::string name, VarBase *p1, int ps=17)
void local_calculate() override
static std::string itos(int i)
void adjust(double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
std::vector< DeviationSensor2D * > vd
void set_parent_flag(VarFlag *parent_flag, const bool call_add_cut)
void local_calculate() override
virtual void print(std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0)
void local_calculate() override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
virtual void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0)
static struct trklet::VarBase::HLS hls
void add_latency(unsigned int l)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
~VarDSPPostadd() override=default
void add_cut(VarBase *cut, const bool call_set_parent_flag=true)
VarDSPPostadd(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, double range=-1, int nmax=18)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const
VarAdjustKR(imathGlobals *globals, std::string name, VarBase *p1, double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
static std::string pipe_delay_wire(VarBase *v, std::string name_delayed, int nbits, int delay)
std::vector< VarBase * > cuts_
static std::string pipe_delay(VarBase *v, int nbits, int delay)
std::map< std::string, int > Kmap_
static void design_print(const std::vector< VarBase *> &v, std::ofstream &fs, Verilog)
VarCut(imathGlobals *globals, double lower_cut, double upper_cut)
~VarCut() override=default
void local_calculate() override
~VarAdjustK() override=default
~VarNeg() override=default
VarTimesC(imathGlobals *globals, std::string name, VarBase *p1, double cF, int ps=17)
TString units(TString variable, Char_t axis)
VarCut(imathGlobals *globals, VarBase *cut_var, double lower_cut, double upper_cut)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarMult(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
~VarAdjustKR() override=default
VarNeg(imathGlobals *globals, std::string name, VarBase *p1)
~VarDef() override=default
VarParam(imathGlobals *globals, std::string name, double fval, int nbits)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void writeLUT(std::ofstream &fs) const
std::vector< unsigned short int > LUT
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
~VarNounits() override=default
Power< A, B >::type pow(const A &a, const B &b)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void print_cuts(std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, Verilog, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
void local_calculate() override