CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
trklet::VarSubtract Class Reference

#include <imath.h>

Inheritance diagram for trklet::VarSubtract:
trklet::VarBase

Public Member Functions

void local_calculate () override
 
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
 
 VarSubtract (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range=-1, int nmax=18)
 
 ~VarSubtract () override=default
 
- Public Member Functions inherited from trklet::VarBase
void add_cut (VarCut *cut, const bool call_set_cut_var=true)
 
void add_delay (int i)
 
void add_latency (unsigned int l)
 
void analyze ()
 
bool calculate ()
 
bool calculate (int debug_level)
 
VarBasecut_var ()
 
std::string dump ()
 
void dump_msg ()
 
double fval () const
 
bool has_delay (int i)
 
void inputs (std::vector< VarBase * > *vd)
 
long int ival () const
 
double K () const
 
std::map< std::string, int > Kmap () const
 
std::string kstring () const
 
int latency () const
 
bool local_passes () const
 
void makeready ()
 
double maxval () const
 
double minval () const
 
std::string name () const
 
int nbits () const
 
std::string op () const
 
VarBasep1 () const
 
VarBasep2 () const
 
VarBasep3 () const
 
void passes (std::map< const VarBase *, std::vector< bool > > &passes, const std::map< const VarBase *, std::vector< bool > > *const previous_passes=nullptr) const
 
int pipe_counter ()
 
std::string pipe_delays (const int step)
 
void pipe_increment ()
 
void print_all (std::ofstream &fs, HLS)
 
void print_all (std::ofstream &fs, Verilog)
 
void print_cuts (std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, HLS, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
 
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 print_step (int step, std::ofstream &fs, HLS)
 
void print_step (int step, std::ofstream &fs, Verilog)
 
void print_truncation (std::string &t, const std::string &o1, const int ps, HLS) const
 
void print_truncation (std::string &t, const std::string &o1, const int ps, Verilog) const
 
double range () const
 
void reset ()
 
int shift () const
 
int step () const
 
 VarBase (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
 
virtual ~VarBase ()
 

Protected Attributes

int ps_
 
int shift1
 
int shift2
 
- Protected Attributes inherited from trklet::VarBase
VarBasecut_var_
 
std::vector< VarBase * > cuts_
 
double fval_
 
imathGlobalsglobals_
 
long int ival_
 
double K_
 
std::map< std::string, int > Kmap_
 
int latency_
 
double maxval_
 
double minval_
 
std::string name_
 
int nbits_
 
std::string op_
 
VarBasep1_
 
VarBasep2_
 
VarBasep3_
 
int pipe_counter_
 
std::vector< int > pipe_delays_
 
bool readytoanalyze_
 
bool readytoprint_
 
int step_
 
bool usedasinput_
 
double val_
 

Additional Inherited Members

- Static Public Member Functions inherited from trklet::VarBase
static void design_print (std::vector< VarBase * > v, std::ofstream &fs, HLS)
 
static void design_print (std::vector< VarBase * > v, std::ofstream &fs, Verilog)
 
static void hls_print (std::vector< VarBase * > v, std::ofstream &fs)
 
static std::string itos (int i)
 
static std::string pipe_delay (VarBase *v, int nbits, int delay)
 
static std::string pipe_delay_wire (VarBase *v, std::string name_delayed, int nbits, int delay)
 
static void verilog_print (std::vector< VarBase * > v, std::ofstream &fs)
 
- Static Public Attributes inherited from trklet::VarBase
static struct trklet::VarBase::HLS hls
 
static struct trklet::VarBase::Verilog verilog
 

Detailed Description

Definition at line 598 of file imath.h.

Constructor & Destructor Documentation

◆ VarSubtract()

trklet::VarSubtract::VarSubtract ( imathGlobals globals,
std::string  name,
VarBase p1,
VarBase p2,
double  range = -1,
int  nmax = 18 
)
inline

Definition at line 600 of file imath.h.

601  : VarBase(globals, name, p1, p2, nullptr, 1) {
602  op_ = "subtract";
603 
604  std::map<std::string, int> map1 = p1->Kmap();
605  std::map<std::string, int> map2 = p2->Kmap();
606  int s1 = map1["2"];
607  int s2 = map2["2"];
608 
609  //first check if the constants are all lined up go over the two maps subtracting the units
610  for (const auto &it : map2) {
611  if (map1.find(it.first) == map1.end())
612  map1[it.first] = -it.second;
613  else
614  map1[it.first] = map1[it.first] - it.second;
615  }
616 
617  char slog[100];
618 
619  //assert if different
620  for (const auto &it : map1) {
621  if (it.second != 0) {
622  if (it.first != "2") {
623  snprintf(
624  slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str());
625  edm::LogVerbatim("Tracklet") << slog;
626  p1->dump_msg();
627  p2->dump_msg();
628  throw cms::Exception("BadConfig") << "imath units are different!";
629  }
630  }
631  }
632 
633  double ki1 = p1->K() / pow(2, s1);
634  double ki2 = p2->K() / pow(2, s2);
635  //those should be the same
636  if (std::abs(ki1 / ki2 - 1.) > 1e-6) {
637  snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str());
638  edm::LogVerbatim("Tracklet") << slog;
639  p1->dump_msg();
640  p2->dump_msg();
641  throw cms::Exception("BadConfig") << "imath constants are different!";
642  }
643  //everything checks out!
644 
645  Kmap_ = p1->Kmap();
646 
647  int s0 = s1 < s2 ? s1 : s2;
648  shift1 = s1 - s0;
649  shift2 = s2 - s0;
650 
651  int n1 = p1->nbits() + shift1;
652  int n2 = p2->nbits() + shift2;
653  int n0 = 1 + (n1 > n2 ? n1 : n2);
654 
655  //before shifting, check the range
656  if (range > 0) {
657  n0 = log2(range / ki1 / pow(2, s0)) + 1e-9;
658  n0 = n0 + 2;
659  }
660 
661  if (n0 <= nmax) { //if it fits, we're done
662  ps_ = 0;
663  Kmap_["2"] = s0;
664  nbits_ = n0;
665  } else {
666  ps_ = n0 - nmax;
667  Kmap_["2"] = s0 + ps_;
668  nbits_ = nmax;
669  }
670 
671  K_ = ki1 * pow(2, Kmap_["2"]);
672  }

References funct::abs(), trklet::VarBase::dump_msg(), MillePedeFileConverter_cfg::e, Exception, trklet::VarBase::K(), trklet::VarBase::K_, trklet::VarBase::Kmap(), trklet::VarBase::Kmap_, n0, trklet::VarBase::name_, trklet::VarBase::nbits(), trklet::VarBase::nbits_, trklet::VarBase::op_, trklet::VarBase::p1(), trklet::VarBase::p2(), funct::pow(), ps_, trklet::VarBase::range(), indexGen::s2, shift1, and shift2.

◆ ~VarSubtract()

trklet::VarSubtract::~VarSubtract ( )
overridedefault

Member Function Documentation

◆ local_calculate()

void VarSubtract::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 127 of file imath_calculate.cc.

127  {
128  fval_ = p1_->fval() - p2_->fval();
129  long int i1 = p1_->ival();
130  long int i2 = p2_->ival();
131  if (shift1 > 0)
132  i1 = i1 << shift1;
133  if (shift2 > 0)
134  i2 = i2 << shift2;
135  ival_ = i1 - i2;
136  if (ps_ > 0)
137  ival_ = ival_ >> ps_;
138 }

References trklet::VarBase::fval(), trklet::VarBase::fval_, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, trklet::VarBase::ival(), trklet::VarBase::ival_, trklet::VarBase::p1_, trklet::VarBase::p2_, ps_, shift1, and shift2.

◆ print() [1/2]

void VarSubtract::print ( std::ofstream &  fs,
HLS  ,
int  l1 = 0,
int  l2 = 0,
int  l3 = 0 
)
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 147 of file imath_HLS.cc.

147  {
148  assert(p1_);
149  assert(p2_);
150  assert(l1 == 0);
151  assert(l2 == 0);
152  assert(l3 == 0);
153  std::string o1 = p1_->name();
154  if (shift1 > 0) {
155  o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")";
156  o1 += "<<" + itos(shift1);
157  o1 = "(" + o1 + ")";
158  }
159 
160  std::string o2 = p2_->name();
161  if (shift2 > 0) {
162  o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")";
163  o2 += "<<" + itos(shift2);
164  o2 = "(" + o2 + ")";
165  }
166 
167  o1 = o1 + " - " + o2;
168 
169  std::string t = "";
171  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t;
172 }

References cms::cuda::assert(), trklet::VarBase::hls, trklet::VarBase::itos(), trklet::VarBase::K_, trklet::VarBase::kstring(), trklet::VarBase::name(), trklet::VarBase::nbits_, CastorDigiReco::o1, trklet::VarBase::p1_, trklet::VarBase::p2_, trklet::VarBase::print_truncation(), ps_, shift1, shift2, AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

◆ print() [2/2]

void VarSubtract::print ( std::ofstream &  fs,
Verilog  ,
int  l1 = 0,
int  l2 = 0,
int  l3 = 0 
)
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 164 of file imath_Verilog.cc.

164  {
165  assert(p1_);
166  assert(p2_);
167  assert(l3 == 0);
168  std::string o1 = p1_->name();
169  if (l1 > 0)
170  o1 += "_delay" + itos(l1);
171  if (shift1 > 0) {
172  o1 += "<<" + itos(shift1);
173  o1 = "(" + o1 + ")";
174  }
175 
176  std::string o2 = p2_->name();
177  if (l2 > 0)
178  o2 += "_delay" + itos(l2);
179  if (shift2 > 0) {
180  o2 += "<<" + itos(shift2);
181  o2 = "(" + o2 + ")";
182  }
183 
184  o1 = o1 + " - " + o2;
185 
186  std::string t = "";
188  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t;
189 }

References cms::cuda::assert(), trklet::VarBase::itos(), trklet::VarBase::K_, trklet::VarBase::kstring(), trklet::VarBase::name(), trklet::VarBase::nbits_, CastorDigiReco::o1, trklet::VarBase::p1_, trklet::VarBase::p2_, trklet::VarBase::print_truncation(), ps_, shift1, shift2, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, and trklet::VarBase::verilog.

Member Data Documentation

◆ ps_

int trklet::VarSubtract::ps_
protected

Definition at line 681 of file imath.h.

Referenced by local_calculate(), print(), and VarSubtract().

◆ shift1

int trklet::VarSubtract::shift1
protected

Definition at line 682 of file imath.h.

Referenced by local_calculate(), print(), and VarSubtract().

◆ shift2

int trklet::VarSubtract::shift2
protected

Definition at line 683 of file imath.h.

Referenced by local_calculate(), print(), and VarSubtract().

trklet::VarBase::fval
double fval() const
Definition: imath.h:212
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
trklet::VarBase::name
std::string name() const
Definition: imath.h:207
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
n0
int n0
Definition: AMPTWrapper.h:44
cms::cuda::assert
assert(be >=bs)
trklet::VarBase::p2_
VarBase * p2_
Definition: imath.h:298
trklet::VarBase::kstring
std::string kstring() const
Definition: imath.cc:18
trklet::VarBase::range
double range() const
Definition: imath.h:245
trklet::VarBase::nbits
int nbits() const
Definition: imath.h:243
trklet::VarSubtract::ps_
int ps_
Definition: imath.h:681
indexGen.s2
s2
Definition: indexGen.py:107
trklet::VarBase::p1_
VarBase * p1_
Definition: imath.h:297
trklet::VarBase::verilog
static struct trklet::VarBase::Verilog verilog
trklet::VarBase::VarBase
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:161
trklet::VarSubtract::shift2
int shift2
Definition: imath.h:683
trklet::VarBase::p1
VarBase * p1() const
Definition: imath.h:209
trklet::VarBase::op_
std::string op_
Definition: imath.h:300
trklet::VarBase::Kmap
std::map< std::string, int > Kmap() const
Definition: imath.h:244
trklet::VarSubtract::shift1
int shift1
Definition: imath.h:682
CastorDigiReco.o1
o1
Definition: CastorDigiReco.py:84
trklet::VarBase::itos
static std::string itos(int i)
Definition: imath.cc:16
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trklet::VarBase::ival_
long int ival_
Definition: imath.h:305
trklet::VarBase::K
double K() const
Definition: imath.h:246
trklet::VarBase::dump_msg
void dump_msg()
Definition: imath.cc:96
trklet::VarBase::ival
long int ival() const
Definition: imath.h:213
trklet::VarBase::Kmap_
std::map< std::string, int > Kmap_
Definition: imath.h:313
trklet::VarBase::p2
VarBase * p2() const
Definition: imath.h:210
trklet::VarBase::hls
static struct trklet::VarBase::HLS hls
trklet::VarBase::print_truncation
void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const
Definition: imath_Verilog.cc:10
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
trklet::VarBase::name_
std::string name_
Definition: imath.h:296
Exception
Definition: hltDiff.cc:246
trklet::VarBase::K_
double K_
Definition: imath.h:312
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trklet::VarBase::nbits_
int nbits_
Definition: imath.h:311
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
trklet::VarBase::fval_
double fval_
Definition: imath.h:304
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37