CMS 3D CMS Logo

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