|
|
Go to the documentation of this file.
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";
264 void print_all(std::ofstream &fs, Verilog);
268 void inputs(std::vector<VarBase *> *
vd);
276 static void design_print(std::vector<VarBase *>
v, std::ofstream &fs, Verilog);
277 static void design_print(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);
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);
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;
1009 void writeLUT(std::ofstream &fs, HLS)
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 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
VarAdjustKR(imathGlobals *globals, std::string name, VarBase *p1, double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
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
VarSubtract(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
VarAdjustK(imathGlobals *globals, std::string name, VarBase *p1, double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
void writeLUT(std::ofstream &fs) const
VarParam(imathGlobals *globals, std::string name, double fval, int nbits)
void local_calculate() override
VarShiftround(imathGlobals *globals, std::string name, VarBase *p1, int shift)
void local_calculate() override
void print_step(int step, std::ofstream &fs, Verilog)
~VarParam() override=default
void local_calculate() override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
~VarMult() override=default
void set_parent_flag(VarFlag *parent_flag, const bool call_add_cut)
~VarSubtract() override=default
void add_cuts(VarBase *cut)
void local_calculate() override
void add_cut(VarCut *cut, const bool call_set_cut_var=true)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarNeg(imathGlobals *globals, std::string name, VarBase *p1)
void inputs(std::vector< VarBase * > *vd)
static void verilog_print(std::vector< VarBase * > v, std::ofstream &fs)
VarCut(imathGlobals *globals, double lower_cut, double upper_cut)
~VarCut() override=default
void add_cuts(VarBase *cut, Args... args)
void print_all(std::ofstream &fs, Verilog)
std::string kstring() const
~VarShift() override=default
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
std::vector< DeviationSensor2D * > vd
VarFlag(imathGlobals *globals, std::string name, VarBase *cut, Args... args)
VarCut(imathGlobals *globals, VarBase *cut_var, double lower_cut, double upper_cut)
std::vector< int > pipe_delays_
std::string pipe_delays(const int step)
static struct trklet::VarBase::Verilog verilog
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
VarTimesC(imathGlobals *globals, std::string name, VarBase *p1, double cF, int ps=17)
~VarDef() override=default
~VarNounits() override=default
TString units(TString variable, Char_t axis)
static void design_print(std::vector< VarBase * > v, std::ofstream &fs, Verilog)
void local_calculate() override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void passes(std::map< const VarBase *, std::vector< bool > > &passes, const std::map< const VarBase *, std::vector< bool > > *const previous_passes=nullptr) const
std::map< std::string, int > Kmap() const
~VarNeg() override=default
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void set_cut_var(VarBase *cut_var, const bool call_add_cut=true)
~VarShiftround() override=default
virtual void local_calculate()
~VarAdd() override=default
bool local_passes() const
static std::string itos(int i)
VarNounits(imathGlobals *globals, std::string name, VarBase *p1, int ps=17)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void initLUT(double offset)
~VarAdjustK() override=default
void local_calculate() override
virtual void print(std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0)
virtual void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0)
void set_fval(double fval)
VarParam(imathGlobals *globals, std::string name, std::string units, double fval, double K)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void add_latency(unsigned int l)
VarAdd(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
~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)
VarDef(imathGlobals *globals, std::string name, VarBase *p)
void local_calculate() override
void local_calculate() override
std::map< std::string, int > Kmap_
static struct trklet::VarBase::HLS hls
~VarTimesC() override=default
~VarAdjustKR() override=default
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void set_fval(double fval)
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
void local_calculate() override
VarDef(imathGlobals *globals, std::string name, std::string units, double fmax, double K)
void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const
void adjust(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)
VarInv(imathGlobals *globals, std::string name, VarBase *p1, double offset, int nbits, int n, unsigned int shift, mode m, int nbaddr=-1)
std::vector< VarBase * > cuts_
std::vector< unsigned short int > LUT
static std::string pipe_delay(VarBase *v, int nbits, int delay)
void local_calculate() override
void local_calculate() override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
VarShift(imathGlobals *globals, std::string name, VarBase *p1, int shift)
static void hls_print(std::vector< VarBase * > v, std::ofstream &fs)
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
Power< A, B >::type pow(const A &a, const B &b)
VarMult(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
int ival_to_addr(int ival)
Abs< T >::type abs(const T &t)
void local_calculate() override
void print(std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
int addr_to_ival(int addr)