CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhiMemoryImage.cc
Go to the documentation of this file.
1 #include <iostream>
3 
4 PhiMemoryImage::PhiMemoryImage():_keyStationOffset(0){
5  for (int i = 0; i < PhiMemoryImage::TOTAL_UNITS; i++) _buffer[i] = 0;
6 }
7 
8 PhiMemoryImage::PhiMemoryImage(PhiMemoryImage::value_ptr buffer, int offset):_keyStationOffset(offset){
9 
10  CopyFromBuffer( buffer, offset );
11 
12 }
13 
15 
17 
18  for (int i = 0; i < PhiMemoryImage::TOTAL_UNITS; i++){
19  _buffer[i] = rhs[i];
20 
21  }
22 
23 }
24 
25 //void SetBuff(int chunk, int value){
26 
27  //_buffer[chunk] = value;
28 //}
29 
30 
31 void PhiMemoryImage::SetBit( int station, int bitNumber ,bool bitValue ){
32 
33  //std::cout<<"bitnumber = "<<bitNumber<<std::endl;
34  // std::cout<<"station = "<<station<<std::endl;
35 
36  PhiMemoryImage::value_type tmp = 1;//64 bit word
37  int size = sizeof (PhiMemoryImage::value_type) * 8;//64
38 
39  if (bitNumber > size * PhiMemoryImage::TOTAL_UNITS){
40  // complain in some way .. to be implemented..
41  return;
42  }
43 
44  station = station-1;
45  bitNumber = bitNumber-1;
46 
47 
48  // std::cout<<"bitnumber = "<<bitNumber<<std::endl;
49  // std::cout<<"station = "<<station<<std::endl;
50 
51  int chunkNumber = station*2 + (bitNumber-1) / size;
52  int bitOffset = bitNumber % size;
53  if(bitNumber == 64){chunkNumber += 1;}
54 
55 
56  // std::cout<<"chunknumber = "<<chunkNumber<<std::endl;
57  // std::cout<<"bitOffset = "<<bitOffset<<std::endl;
58 
59  //std::cout<<"tmp = "<<tmp<<std::endl;
60  tmp = tmp << bitOffset;//
61  //std::cout<<"tmp = "<<tmp<<std::endl;
62 
63  if (bitValue)
64  _buffer[chunkNumber] |= tmp;
65  else{
66  tmp = ~tmp;
67  _buffer[chunkNumber] &= tmp;
68  }
69 
70  //std::cout<<"buffer["<<chunkNumber<<"] = "<<_buffer[chunkNumber]<<std::endl;
71  //std::cout<<"buffer["<<chunkNumber + 1<<"] = "<<_buffer[chunkNumber+1]<<std::endl;
72 
73 }
74 
75 bool PhiMemoryImage::GetBit( int station, int bitNumber) const {
76 
78  int size = sizeof (PhiMemoryImage::value_type) * 8;
79 
80  if (bitNumber > (size * PhiMemoryImage::TOTAL_UNITS)){
81  // complain in some way .. to be implemented..
82  return false;
83  }
84 
85  bitNumber -= 1;
86  station -=1;
87 
88  int chunkNumber = station*2 + ((bitNumber-1) / size);
89  int bitOffset = bitNumber % size;
90  if(bitNumber == 64){chunkNumber += 1;}
91 
92  tmp <<= bitOffset;
93 
94  // std::cout << "chunkNumber: " << chunkNumber << "bitOffset:"
95  // << bitOffset << "tmp: " << tmp << std::endl;
96  //std::cout<<"buffer["<<chunkNumber<<"] = "<<_buffer[chunkNumber]<<std::endl;
97  // std::cout<<"buffer["<<chunkNumber + 1<<"] = "<<_buffer[chunkNumber+1]<<std::endl;
98 
99  return ((_buffer[chunkNumber] & tmp) != 0);
100 
101 }
102 
103 
104 
105 void PhiMemoryImage::BitShift(int nBits){
106 
107  if (nBits == 0) return;
108 
109  bool negShift = (nBits < 0);
110 
111  if (negShift) nBits = -nBits;
112 
113  PhiMemoryImage::value_type transferBits;
114  int value_size = sizeof(transferBits)*8;
115 
116  for (int i = 0; i < PhiMemoryImage::STATIONS; i++){
117 
118  if (negShift){
119 
120  transferBits = (0x1 << nBits) - 1;
121  transferBits &= _buffer[2*i+1];
122 
123  _buffer[2*i+1] >>= nBits;
124  _buffer[2*i] >>= nBits;
125 
126  transferBits <<= (value_size - nBits);
127 
128  _buffer[2*i] |= transferBits;
129 
130  } else {
131 
132  transferBits = (0x1 << nBits) - 1;
133  transferBits <<= (value_size - nBits);
134 
135  transferBits &= _buffer[2*i];
136  transferBits >>= (value_size - nBits);
137 
138  _buffer[2*i] <<= nBits;
139  _buffer[2*i+1] <<= nBits;
140 
141  _buffer[2*i+1] |= transferBits;
142  }
143  }
144 
145 }
146 
148 
150 
151  for (int i = 1; i <= PhiMemoryImage::STATIONS; i++){
152 
153  // std::cout << _buffer[(i-1)*2] << " " << _buffer [(i-1)*2+1] << std::endl;
154 
155  for (int j = size; j > 0; j--){
156 
157  if ((j%(sizeof(PhiMemoryImage::value_type)*8)) == 0)
158  std::cout << std::endl;
159 
160 
161  if ((j%8)==0) std::cout << " ";
162  if(GetBit(i,j)) std::cout << "1";
163  else std::cout << "0";
164 
165  }
166  std::cout << std::endl;
167  }
168 
169 }
170 
172 
173  for(int i=0;i<PhiMemoryImage::TOTAL_UNITS;i++){
174  std::cout<<"buffer["<<i<<"] = "<<_buffer[i]<<std::endl;
175  }
176  std::cout<<std::endl;
177 }
178 
179 
int i
Definition: DBlmapReader.cc:9
void CopyFromBuffer(PhiMemoryImage::value_ptr rhs, int offset)
functions///
void SetBit(int station, int bitNumber, bool value=true)
static const int STATIONS
int j
Definition: DBlmapReader.cc:9
void BitShift(int nBits)
static const int UNITS
bool GetBit(int station, int bitNumber) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
PhiMemoryImage()
constructors///
PhiMemoryImage::value_type _buffer[PhiMemoryImage::TOTAL_UNITS]
unsigned long int value_type
Definition: PhiMemoryImage.h:8
tuple cout
Definition: gather_cfg.py:145
PhiMemoryImage::value_type * value_ptr
Definition: PhiMemoryImage.h:9
static const int TOTAL_UNITS
tuple size
Write out results.