CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
PhiMemoryImage Class Reference

#include <PhiMemoryImage.h>

Public Types

typedef uint64_t value_type
 

Public Member Functions

void clear_bit (unsigned int layer, unsigned int bit)
 
int get_straightness () const
 
value_type get_word (unsigned int layer, unsigned int unit) const
 
unsigned int op_and (const PhiMemoryImage &other) const
 
PhiMemoryImageoperator= (PhiMemoryImage other)
 
 PhiMemoryImage ()
 
 PhiMemoryImage (const PhiMemoryImage &other)
 
 PhiMemoryImage (PhiMemoryImage &&other) noexcept
 
void print (std::ostream &out) const
 
void reset ()
 
void rotl (unsigned int n)
 
void rotr (unsigned int n)
 
void set_bit (unsigned int layer, unsigned int bit)
 
void set_straightness (int s)
 
void set_word (unsigned int layer, unsigned int unit, value_type value)
 
void swap (PhiMemoryImage &other)
 
bool test_bit (unsigned int layer, unsigned int bit) const
 
 ~PhiMemoryImage ()
 

Private Member Functions

void check_input (unsigned int layer, unsigned int bit) const
 

Private Attributes

value_type _buffer [_layers][_units]
 
int _straightness
 

Static Private Attributes

static const unsigned int _layers = 4
 
static const unsigned int _units = 3
 

Detailed Description

Definition at line 9 of file PhiMemoryImage.h.

Member Typedef Documentation

◆ value_type

typedef uint64_t PhiMemoryImage::value_type

Definition at line 11 of file PhiMemoryImage.h.

Constructor & Destructor Documentation

◆ PhiMemoryImage() [1/3]

PhiMemoryImage::PhiMemoryImage ( )

Definition at line 10 of file PhiMemoryImage.cc.

10 { reset(); }

References reset().

◆ ~PhiMemoryImage()

PhiMemoryImage::~PhiMemoryImage ( )

Definition at line 12 of file PhiMemoryImage.cc.

12 {}

◆ PhiMemoryImage() [2/3]

PhiMemoryImage::PhiMemoryImage ( const PhiMemoryImage other)

Definition at line 14 of file PhiMemoryImage.cc.

14  {
15  std::copy(&(other._buffer[0][0]), &(other._buffer[0][0]) + (_layers * _units), &(_buffer[0][0]));
16 
17  _straightness = other._straightness;
18 }

References _buffer, _layers, _straightness, _units, filterCSVwithJSON::copy, and trackingPlots::other.

◆ PhiMemoryImage() [3/3]

PhiMemoryImage::PhiMemoryImage ( PhiMemoryImage &&  other)
noexcept

Definition at line 20 of file PhiMemoryImage.cc.

20 : PhiMemoryImage() { swap(other); }

References trackingPlots::other, and edm::swap().

Member Function Documentation

◆ check_input()

void PhiMemoryImage::check_input ( unsigned int  layer,
unsigned int  bit 
) const
private

Definition at line 71 of file PhiMemoryImage.cc.

71  {
72  if (layer >= _layers) {
73  char what[128];
74  snprintf(what, sizeof(what), "layer (which is %u) >= _layers (which is %u)", layer, _layers);
75  throw std::out_of_range(what);
76  }
77 
78  unsigned int unit = bit / UINT64_BITS;
79  if (unit >= _units) {
80  char what[128];
81  snprintf(what, sizeof(what), "unit (which is %u) >= _units (which is %u)", unit, _units);
82  throw std::out_of_range(what);
83  }
84 }

References _layers, _units, UINT64_BITS, and unit().

Referenced by clear_bit(), get_word(), set_bit(), set_word(), and test_bit().

◆ clear_bit()

void PhiMemoryImage::clear_bit ( unsigned int  layer,
unsigned int  bit 
)

Definition at line 47 of file PhiMemoryImage.cc.

47  {
48  check_input(layer, bit);
49  value_type unit = bit / UINT64_BITS;
50  value_type mask = (1ul << (bit % UINT64_BITS));
51  _buffer[layer][unit] &= ~mask;
52 }

References _buffer, check_input(), UINT64_BITS, and unit().

◆ get_straightness()

int PhiMemoryImage::get_straightness ( ) const
inline

Definition at line 37 of file PhiMemoryImage.h.

37 { return _straightness; }

References _straightness.

◆ get_word()

PhiMemoryImage::value_type PhiMemoryImage::get_word ( unsigned int  layer,
unsigned int  unit 
) const

Definition at line 66 of file PhiMemoryImage.cc.

66  {
67  check_input(layer, unit * UINT64_BITS);
68  return _buffer[layer][unit];
69 }

References _buffer, check_input(), UINT64_BITS, and unit().

◆ op_and()

unsigned int PhiMemoryImage::op_and ( const PhiMemoryImage other) const

Definition at line 144 of file PhiMemoryImage.cc.

144  {
145  static_assert((_layers == 4 && _units == 3), "This function assumes (_layers == 4 && _units == 3)");
146 
147  // Unroll
148  bool b_st1 = (_buffer[0][0] & other._buffer[0][0]) || (_buffer[0][1] & other._buffer[0][1]) ||
149  (_buffer[0][2] & other._buffer[0][2]);
150  bool b_st2 = (_buffer[1][0] & other._buffer[1][0]) || (_buffer[1][1] & other._buffer[1][1]) ||
151  (_buffer[1][2] & other._buffer[1][2]);
152  bool b_st3 = (_buffer[2][0] & other._buffer[2][0]) || (_buffer[2][1] & other._buffer[2][1]) ||
153  (_buffer[2][2] & other._buffer[2][2]);
154  bool b_st4 = (_buffer[3][0] & other._buffer[3][0]) || (_buffer[3][1] & other._buffer[3][1]) ||
155  (_buffer[3][2] & other._buffer[3][2]);
156 
157  // bit 0: st3 or st4 hit
158  // bit 1: st2 hit
159  // bit 2: st1 hit
160  unsigned int ly = (b_st1 << 2) | (b_st2 << 1) | (b_st3 << 0) | (b_st4 << 0);
161  return ly;
162 }

References _buffer, _layers, _units, and trackingPlots::other.

◆ operator=()

PhiMemoryImage & PhiMemoryImage::operator= ( PhiMemoryImage  other)

Definition at line 23 of file PhiMemoryImage.cc.

23  {
24  swap(other);
25  return *this;
26 }

References trackingPlots::other, and swap().

◆ print()

void PhiMemoryImage::print ( std::ostream &  out) const

Definition at line 164 of file PhiMemoryImage.cc.

164  {
165  constexpr int N = 160;
166  out << std::bitset<N - 128>(_buffer[3][2]) << std::bitset<128 - 64>(_buffer[3][1]) << std::bitset<64>(_buffer[3][0])
167  << std::endl;
168  out << std::bitset<N - 128>(_buffer[2][2]) << std::bitset<128 - 64>(_buffer[2][1]) << std::bitset<64>(_buffer[2][0])
169  << std::endl;
170  out << std::bitset<N - 128>(_buffer[1][2]) << std::bitset<128 - 64>(_buffer[1][1]) << std::bitset<64>(_buffer[1][0])
171  << std::endl;
172  out << std::bitset<N - 128>(_buffer[0][2]) << std::bitset<128 - 64>(_buffer[0][1]) << std::bitset<64>(_buffer[0][0]);
173 }

References _buffer, N, and MillePedeFileConverter_cfg::out.

◆ reset()

void PhiMemoryImage::reset ( void  )

Definition at line 34 of file PhiMemoryImage.cc.

34  {
35  std::fill(&(_buffer[0][0]), &(_buffer[0][0]) + (_layers * _units), 0);
36 
37  _straightness = 0;
38 }

References _buffer, _layers, _straightness, _units, and ntuplemaker::fill.

Referenced by PhiMemoryImage().

◆ rotl()

void PhiMemoryImage::rotl ( unsigned int  n)

Definition at line 88 of file PhiMemoryImage.cc.

88  {
89  if (n >= _units * UINT64_BITS)
90  return;
91 
93  std::copy(&(_buffer[0][0]), &(_buffer[0][0]) + (_layers * _units), &(tmp[0][0]));
94 
95  const unsigned int mask = UINT64_BITS - 1;
96  const unsigned int n1 = n % UINT64_BITS;
97  const unsigned int n2 = _units - (n / UINT64_BITS);
98  const unsigned int n3 = (n1 == 0) ? n2 + 1 : n2;
99 
100  unsigned int i = 0, j = 0, j_curr = 0, j_next = 0;
101  for (i = 0; i < _layers; ++i) {
102  for (j = 0; j < _units; ++j) {
103  // if n2 == 0:
104  // j_curr = 0, 1, 2
105  // j_next = 2, 0, 1
106  // if n2 == 1:
107  // j_curr = 2, 0, 1
108  // j_next = 1, 2, 0
109  j_curr = (n2 + j) % _units;
110  j_next = (n3 + j + _units - 1) % _units;
111  _buffer[i][j] = (tmp[i][j_curr] << n1) | (tmp[i][j_next] >> (-n1 & mask));
112  }
113  }
114 }

References _buffer, _layers, _units, filterCSVwithJSON::copy, mps_fire::i, dqmiolumiharvest::j, dqmiodumpmetadata::n, createJobs::tmp, and UINT64_BITS.

Referenced by PatternRecognition::process_single_zone().

◆ rotr()

void PhiMemoryImage::rotr ( unsigned int  n)

Definition at line 116 of file PhiMemoryImage.cc.

116  {
117  if (n >= _units * UINT64_BITS)
118  return;
119 
121  std::copy(&(_buffer[0][0]), &(_buffer[0][0]) + (_layers * _units), &(tmp[0][0]));
122 
123  const unsigned int mask = UINT64_BITS - 1;
124  const unsigned int n1 = n % UINT64_BITS;
125  const unsigned int n2 = n / UINT64_BITS;
126  const unsigned int n3 = (n1 == 0) ? n2 + _units - 1 : n2;
127 
128  unsigned int i = 0, j = 0, j_curr = 0, j_next = 0;
129  for (i = 0; i < _layers; ++i) {
130  for (j = 0; j < _units; ++j) {
131  // if n2 == 0:
132  // j_curr = 0, 1, 2
133  // j_next = 1, 2, 0
134  // if n2 == 1:
135  // j_curr = 2, 0, 1
136  // j_next = 0, 1, 2
137  j_curr = (n2 + j) % _units;
138  j_next = (n3 + j + 1) % _units;
139  _buffer[i][j] = (tmp[i][j_curr] >> n1) | (tmp[i][j_next] << (-n1 & mask));
140  }
141  }
142 }

References _buffer, _layers, _units, filterCSVwithJSON::copy, mps_fire::i, dqmiolumiharvest::j, dqmiodumpmetadata::n, createJobs::tmp, and UINT64_BITS.

Referenced by PatternRecognition::process_single_zone().

◆ set_bit()

void PhiMemoryImage::set_bit ( unsigned int  layer,
unsigned int  bit 
)

Definition at line 40 of file PhiMemoryImage.cc.

40  {
41  check_input(layer, bit);
42  value_type unit = bit / UINT64_BITS;
43  value_type mask = (1ul << (bit % UINT64_BITS));
44  _buffer[layer][unit] |= mask;
45 }

References _buffer, check_input(), UINT64_BITS, and unit().

Referenced by PatternRecognition::make_zone_image().

◆ set_straightness()

void PhiMemoryImage::set_straightness ( int  s)
inline

Definition at line 35 of file PhiMemoryImage.h.

35 { _straightness = s; }

References _straightness, and alignCSCRings::s.

◆ set_word()

void PhiMemoryImage::set_word ( unsigned int  layer,
unsigned int  unit,
value_type  value 
)

Definition at line 61 of file PhiMemoryImage.cc.

61  {
62  check_input(layer, unit * UINT64_BITS);
63  _buffer[layer][unit] = value;
64 }

References _buffer, check_input(), UINT64_BITS, unit(), and relativeConstraints::value.

◆ swap()

void PhiMemoryImage::swap ( PhiMemoryImage other)

Definition at line 28 of file PhiMemoryImage.cc.

28  {
29  std::swap_ranges(&(other._buffer[0][0]), &(other._buffer[0][0]) + (_layers * _units), &(_buffer[0][0]));
30 
31  std::swap(other._straightness, _straightness);
32 }

References _buffer, _layers, _straightness, _units, trackingPlots::other, and std::swap().

Referenced by operator=().

◆ test_bit()

bool PhiMemoryImage::test_bit ( unsigned int  layer,
unsigned int  bit 
) const

Definition at line 54 of file PhiMemoryImage.cc.

54  {
55  check_input(layer, bit);
56  value_type unit = bit / UINT64_BITS;
57  value_type mask = (1ul << (bit % UINT64_BITS));
58  return _buffer[layer][unit] & mask;
59 }

References _buffer, check_input(), UINT64_BITS, and unit().

Member Data Documentation

◆ _buffer

value_type PhiMemoryImage::_buffer[_layers][_units]
private

◆ _layers

const unsigned int PhiMemoryImage::_layers = 4
staticprivate

Definition at line 59 of file PhiMemoryImage.h.

Referenced by check_input(), op_and(), PhiMemoryImage(), reset(), rotl(), rotr(), and swap().

◆ _straightness

int PhiMemoryImage::_straightness
private

Definition at line 68 of file PhiMemoryImage.h.

Referenced by get_straightness(), PhiMemoryImage(), reset(), set_straightness(), and swap().

◆ _units

const unsigned int PhiMemoryImage::_units = 3
staticprivate

Definition at line 63 of file PhiMemoryImage.h.

Referenced by check_input(), op_and(), PhiMemoryImage(), reset(), rotl(), rotr(), and swap().

mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
PhiMemoryImage::_buffer
value_type _buffer[_layers][_units]
Definition: PhiMemoryImage.h:66
PhiMemoryImage::_units
static const unsigned int _units
Definition: PhiMemoryImage.h:63
PhiMemoryImage::swap
void swap(PhiMemoryImage &other)
Definition: PhiMemoryImage.cc:28
PhiMemoryImage::value_type
uint64_t value_type
Definition: PhiMemoryImage.h:11
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
PhiMemoryImage::_straightness
int _straightness
Definition: PhiMemoryImage.h:68
alignCSCRings.s
s
Definition: alignCSCRings.py:92
PhiMemoryImage::check_input
void check_input(unsigned int layer, unsigned int bit) const
Definition: PhiMemoryImage.cc:71
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
PhiMemoryImage::reset
void reset()
Definition: PhiMemoryImage.cc:34
N
#define N
Definition: blowfish.cc:9
trackingPlots.other
other
Definition: trackingPlots.py:1465
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
UINT64_BITS
#define UINT64_BITS
Definition: PhiMemoryImage.cc:8
unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:162
relativeConstraints.value
value
Definition: relativeConstraints.py:53
PhiMemoryImage::PhiMemoryImage
PhiMemoryImage()
Definition: PhiMemoryImage.cc:10
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
PhiMemoryImage::_layers
static const unsigned int _layers
Definition: PhiMemoryImage.h:59