CMS 3D CMS Logo

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 
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 // <- should be hard coded total units?
38 
39  if (bitNumber > size * PhiMemoryImage::TOTAL_UNITS){
40  // complain in some way .. to be implemented..
41 
42  std::cout<<"bit number is greater than total size. Don't do that!\n";
43  return;
44  }
45 
46  station = station-1;
47  bitNumber = bitNumber-1;
48 
49  // std::cout<<"bitnumber = "<<bitNumber<<std::endl;
50  // std::cout<<"station = "<<station<<std::endl;
51 
52  int chunkNumber = station*PhiMemoryImage::UNITS + (bitNumber-1) / size;
53  int bitOffset = bitNumber % size;
54  if(bitNumber == 64 || bitNumber == 128){chunkNumber += 1;}
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;// should be hardcoded total units?
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*PhiMemoryImage::UNITS + ((bitNumber-1) / size);
89  int bitOffset = bitNumber % size;
90  if(bitNumber == 64 || bitNumber == 128){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 void PhiMemoryImage::BitShift(int nBits){
104 
105  if (nBits == 0) return;
106 
107  bool negShift = (nBits < 0);
108 
109  if (negShift) nBits = -nBits;
110 
111  PhiMemoryImage::value_type transferBits, transferBits2;
112  int value_size = sizeof(transferBits)*8;//should be hardcoded total units?
113 
114  //std::cout<<"value_size = "<<value_size<<"\n";
115 
116  for (int i = 0; i < PhiMemoryImage::STATIONS; i++){
117 
118  if (negShift){
119 
120  transferBits = (0x1 << nBits) - 1;
121  transferBits &= _buffer[3*i+1];
122 
123  transferBits2 = (0x1 << nBits) - 1;
124  transferBits2 &= _buffer[3*i+2];
125 
126  _buffer[3*i+2] >>= nBits;
127  _buffer[3*i+1] >>= nBits;
128  _buffer[3*i] >>= nBits;
129 
130  transferBits <<= (value_size - nBits);
131  transferBits2 <<= (value_size - nBits);
132 
133  _buffer[3*i] |= transferBits;
134  _buffer[3*i+1] |= transferBits2;
135 
136  } else {
137 
138  transferBits = (0x1 << nBits) - 1;
139  transferBits <<= (value_size - nBits);
140 
141  transferBits2 = (0x1 << nBits) - 1;
142  transferBits2 <<= (value_size - nBits);
143 
144  // if(!i){
145 
146  // std::cout<<"tb = "<<transferBits<<"\n";
147  //std::cout<<"tb2 = "<<transferBits2<<"\n";
148 
149  // std::cout<<"buf+0 = "<<_buffer[3*i]<<"\n";
150  // std::cout<<"buf+1 = "<<_buffer[3*i+1]<<"\n";
151  // std::cout<<"buf+2 = "<<_buffer[3*i+2]<<"\n";
152  // }
153 
154  transferBits &= _buffer[3*i];
155  transferBits >>= (value_size - nBits);
156 
157  transferBits2 &= _buffer[3*i+1];
158  transferBits2 >>= (value_size - nBits);
159 
160  //if(!i){
161  // std::cout<<"tb = "<<transferBits<<"\n";
162  // std::cout<<"tb2 = "<<transferBits2<<"\n";
163  // }
164  _buffer[3*i] <<= nBits;
165  _buffer[3*i+1] <<= nBits;
166  _buffer[3*i+2] <<= nBits;
167 
168  // if(!i){
169  // std::cout<<"buf+0 = "<<_buffer[3*i]<<"\n";
170  // std::cout<<"buf+1 = "<<_buffer[3*i+1]<<"\n";
171  // std::cout<<"buf+2 = "<<_buffer[3*i+2]<<"\n";
172  // }
173 
174  _buffer[3*i+1] |= transferBits;
175  _buffer[3*i+2] |= transferBits2;
176 
177  // if(!i){
178 
179  // std::cout<<"tb = "<<transferBits<<"\n";
180  // std::cout<<"tb2 = "<<transferBits2<<"\n";
181  //
182  // std::cout<<"buf+0 = "<<_buffer[3*i]<<"\n";
183  // std::cout<<"buf+1 = "<<_buffer[3*i+1]<<"\n";
184  // std::cout<<"buf+2 = "<<_buffer[3*i+2]<<"\n";
185  //}
186  }
187  }
188 
189 }
190 
192 
193  int size = PhiMemoryImage::UNITS * sizeof(PhiMemoryImage::value_type)*8;//should be hardcoded total units>?
194 
195  for (int i = 1; i <= PhiMemoryImage::STATIONS; i++){
196 
197  // std::cout << _buffer[(i-1)*2] << " " << _buffer [(i-1)*2+1] << std::endl;
198 
199  for (int j = size; j > 0; j--){
200 
201  if ((j%(sizeof(PhiMemoryImage::value_type)*8)) == 0)//should be hardcoded total units>? ->no
202  std::cout << std::endl;
203 
204 
205  if ((j%8)==0) std::cout << " ";
206  if(GetBit(i,j)) std::cout << "1";
207  else std::cout << "0";
208 
209  }
210  std::cout << std::endl;
211  }
212 
213 }
214 
216 
217  for(int i=0;i<PhiMemoryImage::TOTAL_UNITS;i++){
218  std::cout<<"buffer["<<i<<"] = "<<_buffer[i]<<std::endl;
219  }
220  std::cout<<std::endl;
221 }
222 
size
Write out results.
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
PhiMemoryImage::value_type * value_ptr
Definition: PhiMemoryImage.h:9
static const int TOTAL_UNITS