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 // <- 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 
50  // std::cout<<"bitnumber = "<<bitNumber<<std::endl;
51  // std::cout<<"station = "<<station<<std::endl;
52 
53  int chunkNumber = station*PhiMemoryImage::UNITS + (bitNumber-1) / size;
54  int bitOffset = bitNumber % size;
55  if(bitNumber == 64 || bitNumber == 128){chunkNumber += 1;}
56 
57 
58  // std::cout<<"chunknumber = "<<chunkNumber<<std::endl;
59  // std::cout<<"bitOffset = "<<bitOffset<<std::endl;
60 
61  //std::cout<<"tmp = "<<tmp<<std::endl;
62  tmp = tmp << bitOffset;//
63  //std::cout<<"tmp = "<<tmp<<std::endl;
64 
65  if (bitValue)
66  _buffer[chunkNumber] |= tmp;
67  else{
68  tmp = ~tmp;
69  _buffer[chunkNumber] &= tmp;
70  }
71 
72  //std::cout<<"buffer["<<chunkNumber<<"] = "<<_buffer[chunkNumber]<<std::endl;
73  //std::cout<<"buffer["<<chunkNumber + 1<<"] = "<<_buffer[chunkNumber+1]<<std::endl;
74 
75 }
76 
77 bool PhiMemoryImage::GetBit( int station, int bitNumber) const {
78 
80  int size = sizeof (PhiMemoryImage::value_type) * 8;// should be hardcoded total units?
81 
82  if (bitNumber > (size * PhiMemoryImage::TOTAL_UNITS)){
83  // complain in some way .. to be implemented..
84  return false;
85  }
86 
87  bitNumber -= 1;
88  station -=1;
89 
90  int chunkNumber = station*PhiMemoryImage::UNITS + ((bitNumber-1) / size);
91  int bitOffset = bitNumber % size;
92  if(bitNumber == 64 || bitNumber == 128){chunkNumber += 1;}
93 
94  tmp <<= bitOffset;
95 
96  // std::cout << "chunkNumber: " << chunkNumber << "bitOffset:"
97  // << bitOffset << "tmp: " << tmp << std::endl;
98  //std::cout<<"buffer["<<chunkNumber<<"] = "<<_buffer[chunkNumber]<<std::endl;
99  // std::cout<<"buffer["<<chunkNumber + 1<<"] = "<<_buffer[chunkNumber+1]<<std::endl;
100 
101  return ((_buffer[chunkNumber] & tmp) != 0);
102 
103 }
104 
105 
106 
107 void PhiMemoryImage::BitShift(int nBits){
108 
109  if (nBits == 0) return;
110 
111  bool negShift = (nBits < 0);
112 
113  if (negShift) nBits = -nBits;
114 
115  PhiMemoryImage::value_type transferBits, transferBits2;
116  int value_size = sizeof(transferBits)*8;//should be hardcoded total units?
117 
118  //std::cout<<"value_size = "<<value_size<<"\n";
119 
120  for (int i = 0; i < PhiMemoryImage::STATIONS; i++){
121 
122  if (negShift){
123 
124  transferBits = (0x1 << nBits) - 1;
125  transferBits &= _buffer[3*i+1];
126 
127  transferBits2 = (0x1 << nBits) - 1;
128  transferBits2 &= _buffer[3*i+2];
129 
130  _buffer[3*i+2] >>= nBits;
131  _buffer[3*i+1] >>= nBits;
132  _buffer[3*i] >>= nBits;
133 
134  transferBits <<= (value_size - nBits);
135  transferBits2 <<= (value_size - nBits);
136 
137  _buffer[3*i] |= transferBits;
138  _buffer[3*i+1] |= transferBits2;
139 
140  } else {
141 
142  transferBits = (0x1 << nBits) - 1;
143  transferBits <<= (value_size - nBits);
144 
145  transferBits2 = (0x1 << nBits) - 1;
146  transferBits2 <<= (value_size - nBits);
147 
148  // if(!i){
149 
150  // std::cout<<"tb = "<<transferBits<<"\n";
151  //std::cout<<"tb2 = "<<transferBits2<<"\n";
152 
153 
154  // std::cout<<"buf+0 = "<<_buffer[3*i]<<"\n";
155  // std::cout<<"buf+1 = "<<_buffer[3*i+1]<<"\n";
156  // std::cout<<"buf+2 = "<<_buffer[3*i+2]<<"\n";
157  // }
158 
159  transferBits &= _buffer[3*i];
160  transferBits >>= (value_size - nBits);
161 
162  transferBits2 &= _buffer[3*i+1];
163  transferBits2 >>= (value_size - nBits);
164 
165  //if(!i){
166  // std::cout<<"tb = "<<transferBits<<"\n";
167  // std::cout<<"tb2 = "<<transferBits2<<"\n";
168  // }
169  _buffer[3*i] <<= nBits;
170  _buffer[3*i+1] <<= nBits;
171  _buffer[3*i+2] <<= nBits;
172 
173  // if(!i){
174  // std::cout<<"buf+0 = "<<_buffer[3*i]<<"\n";
175  // std::cout<<"buf+1 = "<<_buffer[3*i+1]<<"\n";
176  // std::cout<<"buf+2 = "<<_buffer[3*i+2]<<"\n";
177  // }
178 
179  _buffer[3*i+1] |= transferBits;
180  _buffer[3*i+2] |= transferBits2;
181 
182  // if(!i){
183 
184  // std::cout<<"tb = "<<transferBits<<"\n";
185  // std::cout<<"tb2 = "<<transferBits2<<"\n";
186  //
187  // std::cout<<"buf+0 = "<<_buffer[3*i]<<"\n";
188  // std::cout<<"buf+1 = "<<_buffer[3*i+1]<<"\n";
189  // std::cout<<"buf+2 = "<<_buffer[3*i+2]<<"\n";
190  //}
191  }
192  }
193 
194 }
195 
197 
198  int size = PhiMemoryImage::UNITS * sizeof(PhiMemoryImage::value_type)*8;//should be hardcoded total units>?
199 
200  for (int i = 1; i <= PhiMemoryImage::STATIONS; i++){
201 
202  // std::cout << _buffer[(i-1)*2] << " " << _buffer [(i-1)*2+1] << std::endl;
203 
204  for (int j = size; j > 0; j--){
205 
206  if ((j%(sizeof(PhiMemoryImage::value_type)*8)) == 0)//should be hardcoded total units>? ->no
207  std::cout << std::endl;
208 
209 
210  if ((j%8)==0) std::cout << " ";
211  if(GetBit(i,j)) std::cout << "1";
212  else std::cout << "0";
213 
214  }
215  std::cout << std::endl;
216  }
217 
218 }
219 
221 
222  for(int i=0;i<PhiMemoryImage::TOTAL_UNITS;i++){
223  std::cout<<"buffer["<<i<<"] = "<<_buffer[i]<<std::endl;
224  }
225  std::cout<<std::endl;
226 }
227 
228 
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.