CMS 3D CMS Logo

Functions
vhdl_functions.h File Reference
#include <cstdint>
#include <vector>
#include <cmath>

Go to the source code of this file.

Functions

void vhdl_int_to_signed (int value, std::vector< int > &v)
 
void vhdl_int_to_unsigned (int value, std::vector< int > &v)
 
void vhdl_resize_signed (std::vector< int > &v, int new_size)
 
bool vhdl_resize_signed_ok (std::vector< int > v, int new_size)
 
void vhdl_resize_unsigned (std::vector< int > &v, int new_size)
 
bool vhdl_resize_unsigned_ok (std::vector< int > v, int new_size)
 
int vhdl_signed_to_int (std::vector< int > v)
 
std::vector< int > vhdl_slice (std::vector< int > v, int upper, int lower)
 
int vhdl_unsigned_to_int (std::vector< int > v)
 

Function Documentation

◆ vhdl_int_to_signed()

void vhdl_int_to_signed ( int  value,
std::vector< int > &  v 
)

Definition at line 44 of file vhdl_functions.cc.

References mps_fire::i, findQualityFiles::size, findQualityFiles::v, heppy_batch::val, and vhdl_int_to_unsigned().

Referenced by MPCorFilter::coarsify(), and MuonPathFitter::fit().

44  {
45  if (value < 0) {
46  int val = 1;
47  int size = 1;
48  while (val < -value) {
49  val *= 2;
50  size += 1;
51  }
53  for (int i = v.size(); i < size - 1; i++) {
54  v.push_back(0);
55  }
56  v.push_back(1);
57  } else {
59  v.push_back(0);
60  }
61  return;
62 }
size
Write out results.
Definition: value.py:1
void vhdl_int_to_unsigned(int value, std::vector< int > &v)

◆ vhdl_int_to_unsigned()

void vhdl_int_to_unsigned ( int  value,
std::vector< int > &  v 
)

Definition at line 32 of file vhdl_functions.cc.

References findQualityFiles::v.

Referenced by MPCorFilter::coarsify(), MuonPathFitter::fit(), MPSLFilter::get_chi2(), MPCorFilter::get_chi2(), and vhdl_int_to_signed().

32  {
33  if (value == 0) {
34  v.push_back(0);
35  } else if (value != 1) {
36  v.push_back(value % 2);
38  } else {
39  v.push_back(1);
40  }
41  return;
42 }
Definition: value.py:1
void vhdl_int_to_unsigned(int value, std::vector< int > &v)

◆ vhdl_resize_signed()

void vhdl_resize_signed ( std::vector< int > &  v,
int  new_size 
)

Definition at line 70 of file vhdl_functions.cc.

References mps_fire::i, and findQualityFiles::v.

Referenced by MPCorFilter::coarsify(), and MuonPathFitter::fit().

70  {
71  int elem = 0;
72  if (v[v.size() - 1] == 1)
73  elem = 1;
74  for (int i = v.size(); i < new_size; i++) {
75  v.push_back(elem);
76  }
77 }

◆ vhdl_resize_signed_ok()

bool vhdl_resize_signed_ok ( std::vector< int >  v,
int  new_size 
)

Definition at line 79 of file vhdl_functions.cc.

References mps_fire::i, and findQualityFiles::v.

Referenced by MuonPathFitter::fit().

79  {
80  for (size_t i = v.size() - 1 - 1; i >= v.size() - 1 - (v.size() - new_size); i--) {
81  if (v[i] != v[v.size() - 1])
82  return false;
83  }
84  return true;
85 };

◆ vhdl_resize_unsigned()

void vhdl_resize_unsigned ( std::vector< int > &  v,
int  new_size 
)

Definition at line 64 of file vhdl_functions.cc.

References mps_fire::i, and findQualityFiles::v.

Referenced by MPCorFilter::coarsify(), MuonPathFitter::fit(), MPSLFilter::get_chi2(), and MuonPathFitter::RomDataConvert().

64  {
65  for (int i = v.size(); i < new_size; i++) {
66  v.push_back(0);
67  }
68 }

◆ vhdl_resize_unsigned_ok()

bool vhdl_resize_unsigned_ok ( std::vector< int >  v,
int  new_size 
)

Definition at line 87 of file vhdl_functions.cc.

References mps_fire::i, and findQualityFiles::v.

Referenced by MuonPathFitter::fit().

87  {
88  for (size_t i = v.size() - 1; i >= v.size() - 1 + 1 - (v.size() - new_size); i--) {
89  if (v[i] != 0)
90  return false;
91  }
92  return true;
93 };

◆ vhdl_signed_to_int()

int vhdl_signed_to_int ( std::vector< int >  v)

Definition at line 25 of file vhdl_functions.cc.

References funct::pow(), findQualityFiles::v, and vhdl_unsigned_to_int().

Referenced by MPCorFilter::coarsify(), and MuonPathFitter::fit().

25  {
26  if (v[v.size() - 1] == 0)
27  return vhdl_unsigned_to_int(v);
28  else
29  return -(std::pow(2, v.size()) - vhdl_unsigned_to_int(v));
30 }
int vhdl_unsigned_to_int(std::vector< int > v)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ vhdl_slice()

std::vector<int> vhdl_slice ( std::vector< int >  v,
int  upper,
int  lower 
)

Definition at line 4 of file vhdl_functions.cc.

References mps_fire::i, and findQualityFiles::v.

Referenced by MPCorFilter::coarsify(), MPSLFilter::get_chi2(), and MuonPathFitter::RomDataConvert().

4  {
5  int final_value = lower;
6  if (final_value < 0)
7  final_value = 0;
8 
9  std::vector<int> v1;
10  for (int i = final_value; i <= upper; i++) {
11  v1.push_back(v[i]);
12  }
13  return v1;
14 }

◆ vhdl_unsigned_to_int()

int vhdl_unsigned_to_int ( std::vector< int >  v)

Definition at line 16 of file vhdl_functions.cc.

References mps_fire::i, funct::pow(), and findQualityFiles::v.

Referenced by MPCorFilter::coarsify(), MPSLFilter::get_chi2(), MuonPathSLFitter::get_rom_addr(), MuonPathCorFitter::get_rom_addr(), and vhdl_signed_to_int().

16  {
17  int res = 0;
18 
19  for (size_t i = 0; i < v.size(); i++) {
20  res = res + v[i] * std::pow(2, i);
21  }
22  return res;
23 }
Definition: Electron.h:6
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29