CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtVhdlWriterBitManager.cc
Go to the documentation of this file.
1 
18 // this class header
20 
22 
26 
27 // system include files
28 #include <iostream>
29 #include <fstream>
30 #include <map>
31 #include <string>
32 #include <sstream>
33 #include <vector>
34 #include <iomanip>
35 
37 {
38  hex2binMap_["0"]="0000";
39  hex2binMap_["1"]="0001";
40  hex2binMap_["2"]="0010";
41  hex2binMap_["3"]="0011";
42  hex2binMap_["4"]="0100";
43  hex2binMap_["5"]="0101";
44  hex2binMap_["6"]="0110";
45  hex2binMap_["7"]="0111";
46  hex2binMap_["8"]="1000";
47  hex2binMap_["9"]="1001";
48 
49  hex2binMap_["A"]="1010";
50  hex2binMap_["B"]="1011";
51  hex2binMap_["C"]="1100";
52  hex2binMap_["D"]="1101";
53  hex2binMap_["E"]="1110";
54  hex2binMap_["F"]="1111";
55 
56  hex2binMap_["a"]="1010";
57  hex2binMap_["b"]="1011";
58  hex2binMap_["c"]="1100";
59  hex2binMap_["d"]="1101";
60  hex2binMap_["e"]="1110";
61  hex2binMap_["f"]="1111";
62 }
63 
64 
65 std::string L1GtVhdlWriterBitManager::readMapInverse(std::map<std::string,std::string> map,std::string value)
66 {
67  std::map<std::string,std::string>::iterator iter = map.begin();
68  while (iter!=map.end())
69  {
70  if ((*iter).second == value)
71  return (*iter).first;
72  iter++;
73  }
74  return "";
75 }
76 
77 
78 std::string L1GtVhdlWriterBitManager::hex2bin(std::string hexString)
79 {
80 
81  std::string temp;
82  for (unsigned int i=0; i<hexString.length(); i++)
83  {
84  std::string str;
85  str=hexString[i];
86 
87  temp+=hex2binMap_[str];
88  }
89 
90  return temp;
91 }
92 
93 
94 std::string L1GtVhdlWriterBitManager::bin2hex(std::string binString)
95 {
96 
97  std::string temp;
98  for (unsigned int i=1; i<=binString.length(); i++)
99  {
100  //std::cout<<i%4<<std::endl;
101  if(i%4==0)
102  {
103  //std::cout<<"I'm here!"<<std::endl;
104  std::string str;
105  str = binString.substr(i-4,4);
106  //std::cout<<str<<std::cout<<std::endl;
107  temp+=readMapInverse(hex2binMap_,str);
108  }
109  }
110 
111  return temp;
112 }
113 
114 
115 std::string L1GtVhdlWriterBitManager::mirror(unsigned int offset, std::string hexString, bool hexOutput)
116 {
117  std::string temp,binString;
118 
119  char digit;
120  bool hexInput=false;
121 
122  // check weather input hex or binary
123  for(unsigned int i = 0; i<hexString.length(); i++)
124  {
125  if (hexString[i]!='0' || hexString[i]!='1' )
126  {
127  hexInput=true;
128  break;
129  }
130  }
131 
132  if (hexInput)
133  binString = hex2bin(hexString);
134  else binString=hexString;
135 
136  unsigned int i=0, len=0;
137  len = binString.length();
138 
139  if(offset > len)
140  return binString;
141 
142  for(i = 0; i < (len - offset)/2; i++)
143  {
144  digit = binString[i + offset];
145 
146  binString[i + offset] = binString[len - 1 - i];
147  binString[len - 1 - i] = digit;
148 
149  }
150 
151  if (hexOutput)
152  return bin2hex(binString);
153  else return binString;
154 
155 }
156 
157 
158 std::string L1GtVhdlWriterBitManager::capitalLetters(std::string hexString)
159 {
160 
161  unsigned int i = 0;
162  while(i<hexString.length())
163  {
164  if(hexString[i] == 'a') hexString[i] = 'A';
165  else if(hexString[i] == 'b') hexString[i] = 'B';
166  else if(hexString[i] == 'c') hexString[i] = 'C';
167  else if(hexString[i] == 'd') hexString[i] = 'D';
168  else if(hexString[i] == 'e') hexString[i] = 'E';
169  else if(hexString[i] == 'f') hexString[i] = 'F';
170  i++;
171  }
172 
173  return hexString;
174 }
175 
176 
177 std::string L1GtVhdlWriterBitManager::shiftLeft(std::string hexString)
178 {
179  std::string binString = hex2bin(hexString);
180 
181  binString.erase(0,1);
182  binString+="0";
183 
184  return bin2hex(binString);
185 }
186 
187 
188 std::string L1GtVhdlWriterBitManager::buildEtaMuon(const std::vector<L1GtMuonTemplate::ObjectParameter>* op, const unsigned int &num, const unsigned int &counter)
189 {
190  std::ostringstream ossEta;
191 
192  ossEta
193  <<counter
194  <<" => X\"";
195 
196  for (unsigned int i =0; i<num; i++)
197  {
198  std::ostringstream ossEtaRange;
199  ossEtaRange << std::hex<< std::setw(16)<<std::setfill('0')<<(*op).at(i).etaRange<<std::dec;
200 
201  /*
202  ossEta
203  <<mirror(32,ossEtaRange.str());
204  */
205 
206  ossEta << ossEtaRange.str();
207 
208  if (num>0 && i!=num-1) ossEta <<"_";
209 
210  }
211 
212  ossEta<<"\",\n";
213  return ossEta.str();
214 
215 }
216 
217 
218 std::string L1GtVhdlWriterBitManager::buildEtaCalo(const std::vector<L1GtCaloTemplate::ObjectParameter>* op, const unsigned int &num, const unsigned int &counter)
219 {
220  std::ostringstream ossEta;
221 
222  ossEta
223  <<counter
224  <<" => X\"";
225 
226  // loop over all relevant components of object parameters
227 
228  for (unsigned int i =0; i<num; i++)
229  {
230  std::ostringstream ossEtaRange;
231 
232  ossEtaRange << std::hex <<std::setw(4)<<std::setfill('0')<< (*op).at(i).etaRange<<std::dec;
233 
234  /*
235  std::string tempstr=hex2bin(ossEtaRange.str());
236  tempstr[0]='0';
237  tempstr[15]='0';
238  */
239 
240  //ossEta<<std::setw(4)<<std::setfill('0')<<mirror(8,bin2hex(tempstr));
241 
242  ossEta << ossEtaRange.str();
243 
244  if (num>0 && i!=num-1) ossEta <<"_";
245 
246  }
247 
248  ossEta<<"\",\n";
249  return ossEta.str();
250 }
251 
252 
253 std::string L1GtVhdlWriterBitManager::buildPhiCalo(const std::vector<L1GtCaloTemplate::ObjectParameter>* op, const unsigned int &num, const unsigned int &counter)
254 {
255  std::ostringstream ossPhi;
256 
257  ossPhi
258  <<counter
259  <<" => X\"";
260 
261  for (unsigned int i =0; i<num; i++)
262  {
263  ossPhi << std::hex<< std::setw(8)<<std::setfill('0')<<(*op).at(i).phiRange<<std::dec;
264 
265  if (num>0 && i!=num-1) ossPhi <<"_";
266  }
267 
268  ossPhi<<"\",\n";
269  return capitalLetters(ossPhi.str());
270 }
271 
272 
273 std::string L1GtVhdlWriterBitManager::buildPhiEnergySum(const std::vector<L1GtEnergySumTemplate::ObjectParameter>* op, const unsigned int &num, const unsigned int &counter)
274 {
275  std::ostringstream ossPhi,count;
276 
277  if ((*op).at(0).phiRange0Word!=0)
278  {
279  ossPhi << "000000000000000000"<<std::hex<<(*op).at(0).phiRange1Word<<(*op).at(0).phiRange0Word<<std::dec;
280 
281  count<<counter;
282 
283  return (count.str()+" => X\""+capitalLetters(ossPhi.str())+"\",\n");
284 
285  } else
286  return "";
287 }
288 
289 
290 std::string L1GtVhdlWriterBitManager::buildPhiMuon(const std::vector<L1GtMuonTemplate::ObjectParameter>* op, const unsigned int &num, const unsigned int &counter,bool high)
291 {
292  std::ostringstream ossPhi;
293 
294  ossPhi
295  <<counter
296  <<" => X\"";
297 
298  for (unsigned int i =0; i<num; i++)
299  {
300  if (high)
301  ossPhi << std::hex<< std::setw(2)<<std::setfill('0')<<(*op).at(i).phiHigh<<std::dec;
302  else
303  ossPhi << std::hex<< std::setw(2)<<std::setfill('0')<<(*op).at(i).phiLow<<std::dec;
304 
305  if (num>0 && i!=num-1) ossPhi <<"_";
306  }
307 
308  ossPhi<<"\",\n";
309  return capitalLetters(ossPhi.str());
310 
311 }
312 
313 
315 {
316  std::ostringstream deltaEtaRange, dEta,res;
317 
318  //std::cout<<"b:"<<.hex2bin("00383800")<<std::endl;
319 
320  deltaEtaRange << std::hex<< std::setw(4)<<std::setfill('0')<<(*cp).deltaEtaRange<<std::dec;
321 
322  // mirror deltaEtaRang and shift the mirrored value to the left by one bit;
323  // add the original value to the calculated value
324  dEta<<hex2bin(shiftLeft(mirror(0,deltaEtaRange.str())))<<hex2bin(deltaEtaRange.str());
325 
326  std::string result = capitalLetters(bin2hex(dEta.str()));
327 
328  res<<counter<<" => X\""<<result<<"\",\n";
329 
330  return res.str();
331 
332 }
333 
334 
336 {
337  std::ostringstream deltaEtaRange, dEta;
338  deltaEtaRange << std::hex<< std::setw(16)<<std::setfill('0')<<(*cp).deltaEtaRange<<std::dec;
339 
340  // mirror deltaEtaRang and shift the mirrored value to the left by one bit;
341  // add the original value to the calculated value
342 
343  std::string result = capitalLetters((shiftLeft(mirror(0,deltaEtaRange.str()))+deltaEtaRange.str()));
344 
345  dEta<<counter<<" => X\""<<result<<"\",\n";
346 
347  return dEta.str();
348 
349 }
350 
351 
353 {
354  std::ostringstream dPhi,deltaPhiRange, result;
355  //std::cout<<.hex2bin("03E0000000000F81")<<std::endl;
356  //std::cout<<.hex2bin("0080000000000200")<<std::endl;
357 
358  deltaPhiRange << std::hex<<std::setw(3)<<std::setfill('0')<<(*cp).deltaPhiRange<<std::dec;
359 
360  std::string binString = hex2bin(deltaPhiRange.str());
361 
362  //std::cout <<"========================" <<std::endl;
363 
364  std::string help2 = binString.substr(2,binString.length()-2);
365  std::string help1 = help2.substr(1);
366  help1 = mirror(0,bin2hex(help1),false);
367 
368  // here delta phi is built
369  result<<help1;
370 
371  // might be wrong - has to be tested with more reference values!
372  result<<help2.substr(0,8);
373  result<<"0";
374 
375  result<<"00000000000000000000000000000";
376 
377  result<<help1;
378 
379  result<<binString.substr(2,binString.length()-2);
380 
381  dPhi<<counter<<" => X\""<<bin2hex(result.str())<<"\",\n";
382 
383  //std::cout<<result<<std::endl;
384 
385  /*
386  * Code from old GTS:
387  bm_dphi = bm_dphi.Get(2);
388  BitMngr help1, help2 = bm_dphi;
389  help2.SetAt(9, '\0');
390  help1 = help2.Get(1);
391  help1.Mirror();
392  BitMngr nuller;
393  nuller.InitBin("00 00 00 00 00 00 00 00 00 00 00 00 00 00 0");
394  BitMngr result;
395  result = result + help1 + help2 + nuller + help1 + bm_dphi;
396  dphi = result.GetHex();
397  */
398 
399  return capitalLetters(dPhi.str());
400 }
401 
402 
404 {
405  std::ostringstream dPhi,deltaPhiRange0,deltaPhiRange1,temp,result ;
406  std::string tempstr;
407 
408  deltaPhiRange0 << std::hex<< std::setw(16)<<std::setfill('0')<<(*cp).deltaPhiRange0Word<<std::dec;
409  //deltaPhiRange1 /*<< std::hex<< std::setw(3)<<std::setfill('0')*/<<(*cp).deltaPhiRange1Word<<std::dec;
410 
411  //mirror deltaPhiRange, shift the mirrored value left and convert it to binary format
412  temp<<hex2bin(shiftLeft(mirror(0,deltaPhiRange0.str())));
413  tempstr=temp.str();
414  // set last bit of tempstr to one;
415  tempstr[tempstr.length()-1]='1';
416 
417  // build delta eta as stringstreamtau
418  result
419  <<tempstr
420  // insert 16 ones
421  <<hex2bin("FFFF")
422  <<hex2bin(deltaPhiRange0.str());
423 
424  dPhi<<counter<<" => X\""<<bin2hex(result.str())<<"\",\n";
425 
426  return dPhi.str();
427 
428 }
int i
Definition: DBlmapReader.cc:9
std::string buildEtaCalo(const std::vector< L1GtCaloTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
std::string buildDeltaEtaCalo(const L1GtCaloTemplate::CorrelationParameter *&cp, const unsigned int &counter)
std::string capitalLetters(std::string hexString)
std::map< std::string, std::string > hex2binMap_
dictionary map
Definition: Association.py:205
std::string buildDeltaPhiCalo(const L1GtCaloTemplate::CorrelationParameter *&cp, const unsigned int &counter)
std::string hex2bin(std::string hexString)
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
std::string buildPhiCalo(const std::vector< L1GtCaloTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
tuple result
Definition: query.py:137
std::string readMapInverse(std::map< std::string, std::string > map, std::string value)
std::string buildDeltaPhiMuon(const L1GtMuonTemplate::CorrelationParameter *&cp, const unsigned int &counter)
typedef for correlation parameters
std::string mirror(unsigned int offset, std::string hexString, bool hexOutput=true)
unsigned int offset(bool)
std::string shiftLeft(std::string hexString)
std::string buildDeltaEtaMuon(const L1GtMuonTemplate::CorrelationParameter *&cp, const unsigned int &counter)
long long int num
Definition: procUtils.cc:71
std::string buildPhiEnergySum(const std::vector< L1GtEnergySumTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
std::string buildEtaMuon(const std::vector< L1GtMuonTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
std::string buildPhiMuon(const std::vector< L1GtMuonTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter, bool high)
std::string bin2hex(std::string binString)