CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtVhdlWriterCore.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iostream>
20 #include <fstream>
21 #include <map>
22 #include <string>
23 #include <sstream>
24 #include <vector>
25 #include <sys/stat.h>
26 #include <algorithm>
27 
28 // CMSSW headers
30 
33 
39 
41 
45 
47 
48 // constructor(s)
50  const std::string &outputDirectory, const bool &debug)
51 {
52 
53  // set templates directory
54  vhdlDir_=templatesDirectory;
55 
56  // set output directory
57  outputDir_=outputDirectory;
58 
59  // Get maps
61 
65 
66  // fill calo object vector
67  caloObjects_.push_back(IsoEG);
68  caloObjects_.push_back(NoIsoEG);
69  caloObjects_.push_back(CenJet);
70  caloObjects_.push_back(ForJet);
71  caloObjects_.push_back(TauJet);
72 
73  esumObjects_.push_back(HTT);
74  esumObjects_.push_back(ETT);
75  esumObjects_.push_back(ETM);
76 
77  // prepare number of condition vector with two empty string vectors for the two condition chips
78  std::vector<std::string> temp;
79  numberOfConditions_.push_back(temp);
80  numberOfConditions_.push_back(temp);
81 
82  // set debug mode
84 
85 }
86 
87 // destructor
89 {
90  // empty
91 }
92 
95  const L1GtObject &object,
96  const ConditionMap &map,
97  ConditionMap &outputMap)
98 {
99  bool status = false;
100 
101  ConditionMap::const_iterator condIter = map.begin();
102  while (condIter!=map.end())
103  {
104  if (condIter->second->condCategory()==category
105  && condIter->second->condType()==type && (condIter->second->objectType())[0]==object)
106  {
107  outputMap[condIter->first]=condIter->second;
108  status = true;
109  }
110  condIter++;
111  }
112 
113  return status;
114 }
115 
117  ConditionMap &map)
118 {
119  bool status = false;
120 
121  ConditionMap::iterator condIter = map.begin();
122  while (condIter!=map.end())
123  {
124  for (unsigned int i=0; i<(condIter->second->objectType()).size(); i++)
125  {
126  if (condIter->second->objectType()[i]==object)
127  {
128  status = true;
129  break;
130  }
131  }
132 
133  if (status)
134  break;
135  condIter++;
136  }
137 
138  return status;
139 }
140 
142  const unsigned short int &condChip,
143  std::map<std::string,std::string> &muonParameters)
144 {
145  // vector containing all relevant types for muon conditions
146  std::vector<L1GtConditionType> muonConditionTypes;
147 
148  muonConditionTypes.push_back(Type1s);
149  muonConditionTypes.push_back(Type2s);
150  muonConditionTypes.push_back(Type2wsc);
151  muonConditionTypes.push_back(Type3s);
152  muonConditionTypes.push_back(Type4s);
153 
154  for (unsigned int i = 0; i<muonConditionTypes.size(); i++)
155  {
156  //std::cout<<i<<std::endl;
157 
158  ConditionMap MuonConditions1s;
159 
160  countCondsAndAdd2NumberVec(muonConditionTypes.at(i), CondMuon, Mu,
161  (*conditionMap_).at(condChip-1), MuonConditions1s, condChip);
162 
163  /*
164  // Get the absoloute amount of conditions
165  std::string initstr="CONSTANT nr_"+objType2Str_[Mu]+"_"+condType2Str_[muonConditionTypes.at(i)]+" : integer := ";
166 
167  if (returnConditionsOfOneClass(muonConditionTypes.at(i),CondMuon,Mu,conditionMap_.at(condChip-1), MuonConditions1s))
168  initstr+=(int2str(MuonConditions1s.size())+";");
169  else
170  initstr+=("0;");
171 
172  numberOfConditions_.at(condChip-1).push_back(initstr);
173 
174  */
175 
176  //std::cout<< std::hex << (*myObjectParameter).at(0).etThreshold << std::endl;
177  unsigned int counter=0;
178 
179  for (ConditionMap::const_iterator iterCond = MuonConditions1s.begin(); iterCond
180  != MuonConditions1s.end(); iterCond++)
181  {
182 
183  // add this condition to name -> integer conversion map
184  conditionToIntegerMap_[iterCond->first]=counter;
185 
186  L1GtMuonTemplate* m_gtMuonTemplate =
187  static_cast<L1GtMuonTemplate*>(iterCond->second);
188  const std::vector<L1GtMuonTemplate::ObjectParameter>* op =
189  m_gtMuonTemplate->objectParameter();
190 
191  if (muonConditionTypes.at(i)==Type1s)
192  {
193 
194  // build eta
195  muonParameters["eta_1_s"] += (bm_.buildEtaMuon(op, 1, counter));
196 
197  // add the parameters to parameter map
198  muonParameters["phi_h_1_s"]+= bm_.buildPhiMuon(op, 1, counter,
199  true);
200  muonParameters["phi_l_1_s"]+=bm_.buildPhiMuon(op, 1, counter,
201  false);
202 
203  if (debugMode_)
204  {
205  muonParameters["phi_l_1_s"]+=("--"+iterCond->first+"\n");
206  muonParameters["phi_h_1_s"]+=("--"+iterCond->first+"\n");
207  muonParameters["eta_1_s"] +=("--"+iterCond->first+"\n");
208  }
209 
210  } else
211 
212  if (muonConditionTypes.at(i)==Type2s)
213  {
214 
215  // build eta
216  muonParameters["eta_2_s"] += (bm_.buildEtaMuon(op, 2, counter));
217 
218  // add the parameters to parameter map
219  muonParameters["phi_h_2_s"]+= bm_.buildPhiMuon(op, 2, counter,
220  true);
221  muonParameters["phi_l_2_s"]+=bm_.buildPhiMuon(op, 2, counter,
222  false);
223 
224  if (debugMode_)
225  {
226  muonParameters["phi_l_2_s"]+=("--"+iterCond->first+"\n");
227  muonParameters["phi_h_2_s"]+=("--"+iterCond->first+"\n");
228  muonParameters["eta_2_s"] +=("--"+iterCond->first+"\n");
229  }
230 
231  } else
232  //m_gtMuonTemplate->print(std::cout);
233 
234  if (muonConditionTypes.at(i)==Type3s)
235  {
236 
237  // build eta
238  muonParameters["eta_3"] += (bm_.buildEtaMuon(op, 3, counter));
239 
240  // add the parameters to parameter map
241  muonParameters["phi_h_3"]+= bm_.buildPhiMuon(op, 3, counter,
242  true);
243  muonParameters["phi_l_3"]+=bm_.buildPhiMuon(op, 3, counter,
244  false);
245 
246  if (debugMode_)
247  {
248  muonParameters["phi_l_3"]+=("--"+iterCond->first+"\n");
249  muonParameters["phi_h_3"]+=("--"+iterCond->first+"\n");
250  muonParameters["eta_3"] +=("--"+iterCond->first+"\n");
251  }
252 
253  }
254 
255  if (muonConditionTypes.at(i)==Type4s)
256  {
257 
258  // build eta
259  muonParameters["eta_4"] += (bm_.buildEtaMuon(op, 4, counter));
260 
261  // add the parameters to parameter map
262  muonParameters["phi_h_4"]+= bm_.buildPhiMuon(op, 4, counter,
263  true);
264  muonParameters["phi_l_4"]+=bm_.buildPhiMuon(op, 4, counter,
265  false);
266 
267  if (debugMode_)
268  {
269  muonParameters["phi_l_4"]+=("--"+iterCond->first+"\n");
270  muonParameters["phi_h_4"]+=("--"+iterCond->first+"\n");
271  muonParameters["eta_4"] +=("--"+iterCond->first+"\n");
272  }
273 
274  }
275 
276  if (muonConditionTypes.at(i)==Type2wsc)
277  {
279  m_gtMuonTemplate->correlationParameter();
280 
281  // build eta
282  muonParameters["eta_2_wsc"]
283  += (bm_.buildEtaMuon(op, 2, counter));
284 
285  // build phi
286  muonParameters["phi_h_2_wsc"]+= bm_.buildPhiMuon(op, 2,
287  counter, true);
288  muonParameters["phi_l_2_wsc"]+=bm_.buildPhiMuon(op, 2, counter,
289  false);
290 
291  // build delta_eta
292  std::ostringstream dEta;
293  muonParameters["delta_eta"] += bm_.buildDeltaEtaMuon(cp,
294  counter);
295 
296  // build delta_phi
297  muonParameters["delta_phi"] += bm_.buildDeltaPhiMuon(cp,
298  counter);
299 
300  if (debugMode_)
301  {
302  muonParameters["eta_2_wsc"]+=("--"+iterCond->first+"\n");
303  muonParameters["phi_h_2_wsc"]+=("--"+iterCond->first+"\n");
304  muonParameters["phi_l_2_wsc"] +=("--"+iterCond->first+"\n");
305  muonParameters["delta_eta"]+=("--"+iterCond->first+"\n");
306  muonParameters["delta_phi"] +=("--"+iterCond->first+"\n");
307  }
308 
309  }
310  counter++;
311  }
312  }
313 
314 }
315 
317  const unsigned short int &condChip,
318  std::map<std::string,std::string> &caloParameters,
319  const L1GtObject &caloObject)
320 {
321  // vector containing all relevant types for calo conditions
322  std::vector<L1GtConditionType> caloConditionTypes;
323 
324  caloConditionTypes.push_back(Type1s);
325  caloConditionTypes.push_back(Type2s);
326  caloConditionTypes.push_back(Type2wsc);
327  caloConditionTypes.push_back(Type4s);
328 
329  for (unsigned int i = 0; i<caloConditionTypes.size(); i++)
330  {
331  unsigned int counter=0;
332 
333  ConditionMap caloConditions;
334 
335  // stores all conditions of type given in the first three parameters
336  countCondsAndAdd2NumberVec(caloConditionTypes.at(i), CondCalo,
337  caloObject, (*conditionMap_).at(condChip-1), caloConditions,
338  condChip);
339 
340  for (ConditionMap::const_iterator iterCond = caloConditions.begin(); iterCond
341  != caloConditions.end(); iterCond++)
342  {
343 
344  // add this condition to name -> integer conversion map
345  conditionToIntegerMap_[iterCond->first]=counter;
346 
347  L1GtCaloTemplate* m_gtCaloTemplate =
348  static_cast<L1GtCaloTemplate*>(iterCond->second);
349  const std::vector<L1GtCaloTemplate::ObjectParameter>* op =
350  m_gtCaloTemplate->objectParameter();
351 
352  if (caloConditionTypes.at(i)==Type1s)
353  {
354 
355  //= static_cast<std::vector<L1GtCaloTemplate::ObjectPaenergySumParameter+=rameter*> >(op);
356 
357  // build eta
358  caloParameters["eta_1_s"] += (bm_.buildEtaCalo(op, 1, counter));
359 
360  caloParameters["phi_1_s"]+= bm_.buildPhiCalo(op, 1, counter);
361 
362  if (debugMode_)
363  {
364  caloParameters["eta_1_s"]+=("--"+iterCond->first+"\n");
365  caloParameters["phi_1_s"]+=("--"+iterCond->first+"\n");
366  }
367 
368  } else if (caloConditionTypes.at(i)==Type2s)
369  {
370 
371  // build eta
372  caloParameters["eta_2_s"] += (bm_.buildEtaCalo(op, 2, counter));
373 
374  // add the parameters to parameter map
375  caloParameters["phi_2_s"]+= bm_.buildPhiCalo(op, 2, counter);
376 
377  if (debugMode_)
378  {
379  caloParameters["eta_2_s"]+=("--"+iterCond->first+"\n");
380  caloParameters["phi_2_s"]+=("--"+iterCond->first+"\n");
381  }
382 
383  } else if (caloConditionTypes.at(i)==Type4s)
384  {
385  // build eta
386  caloParameters["eta_4"] += (bm_.buildEtaCalo(op, 4, counter));
387 
388  // add the parameters to parameter map
389  caloParameters["phi_4"]+= bm_.buildPhiCalo(op, 4, counter);
390 
391  if (debugMode_)
392  {
393  caloParameters["eta_4"]+=("--"+iterCond->first+"\n");
394  caloParameters["phi_4"]+=("--"+iterCond->first+"\n");
395  }
396 
397  } else if (caloConditionTypes.at(i)==Type2wsc)
398  {
400  m_gtCaloTemplate->correlationParameter();
401 
402  // build eta
403  caloParameters["eta_2_wsc"]
404  += (bm_.buildEtaCalo(op, 2, counter));
405 
406  // build phi
407  caloParameters["phi_2_wsc"]+= bm_.buildPhiCalo(op, 2, counter);
408 
409  // build delta_eta
410  caloParameters["delta_eta"] += bm_.buildDeltaEtaCalo(cp,
411  counter);
412 
413  // build delta_phi
414  caloParameters["delta_phi"] += bm_.buildDeltaPhiCalo(cp,
415  counter);
416 
417  if (debugMode_)
418  {
419  caloParameters["eta_2_wsc"]+=("--"+iterCond->first+"\n");
420  caloParameters["phi_2_wsc"]+=("--"+iterCond->first+"\n");
421  caloParameters["delta_eta"]+=("--"+iterCond->first+"\n");
422  caloParameters["delta_phi"]+=("--"+iterCond->first+"\n");
423  }
424 
425  }
426 
427  counter++;
428 
429  }
430 
431  }
432 
433  return true;
434 }
435 
437  const unsigned short int &condChip, const L1GtObject &object,
438  std::string &energySumParameter)
439 {
440 
442 
443  unsigned int counter=0;
444 
445  if (object==HTT)
446  type= TypeHTT;
447  else if (object==ETM)
448  type= TypeETM;
449  else if (object==ETT)
450  type= TypeETT;
451 
452  ConditionMap esumsConditions;
453  // stores all conditions of type given in the first three parameters
455  (*conditionMap_).at(condChip-1), esumsConditions, condChip);
456 
457  for (ConditionMap::const_iterator iterCond = esumsConditions.begin(); iterCond
458  != esumsConditions.end(); iterCond++)
459  {
460  L1GtEnergySumTemplate* energySumTempl =
461  static_cast<L1GtEnergySumTemplate*>(iterCond->second);
462  const std::vector<L1GtEnergySumTemplate::ObjectParameter>* op =
463  energySumTempl->objectParameter();
464 
465  if (bm_.buildPhiEnergySum(op, 1, counter)!="")
466  energySumParameter+=bm_.buildPhiEnergySum(op, 1, counter);
467 
468  if (debugMode_)
469  {
470  energySumParameter+=("--"+iterCond->first+"\n");
471  }
472 
473  conditionToIntegerMap_[(iterCond->first)]=counter;
474 
475  counter++;
476  }
477 
478  return true;
479 
480 }
481 
482 bool L1GtVhdlWriterCore::getSubstParamCommonFromTriggerMenu(const unsigned short int &condChip, L1GtVhdlTemplateFile &particle,
483  const L1GtObject &object, const L1GtConditionCategory &category,
484  std::string &parameterStr)
485 {
486 
487  std::map<L1GtConditionType,std::string> condType2Strcopy = condType2Str_;
488 
489  // make a copy since types will deleted later after they are processed
490  std::map<L1GtConditionType,std::string>::iterator typeIterator =
491  condType2Strcopy.begin();
492 
493  while (typeIterator != condType2Strcopy.end())
494  {
495 
496  ConditionMap outputMap;
497 
498  if (returnConditionsOfOneClass((*typeIterator).first, category, object, (*conditionMap_).at(condChip-1), outputMap))
499  {
500 
501  // special treatment for jet counts in buildCodChipParameters
502  if (object !=JetCounts)
503  {
505  while (particle.findAndReplaceString(tempStr2,
507  ;
508  while (particle.findAndReplaceString(tempStr2,
509  sp(substParamType_), condType2Str_[(*typeIterator).first]))
510  ;
511  parameterStr+=(tempStr2+"\n\n");
512 
513  //parameterStr+=(tempStr2+"<= '0';\n");
514 
515  // remove this type since it was already processed
516  condType2Strcopy.erase(typeIterator);
517  }
518 
519  }
520 
521  typeIterator++;
522 
523  }
524 
525  return true;
526 }
527 
529  const unsigned short int &condChip,
530  std::map<std::string, L1GtVhdlTemplateFile> &templates,
531  std::map<std::string, std::string> &commonParams)
532 {
533 
534  // open the necessary internal templates
535  L1GtVhdlTemplateFile muon, calo, esums, jet;
536 
537  muon.open(vhdlDir_+"InternalTemplates/muon", true);
538  muon.substitute("particle", "muon");
539 
540  calo.open(vhdlDir_+"InternalTemplates/calo", true);
541  esums.open(vhdlDir_+"InternalTemplates/esums", true);
542  jet.open(vhdlDir_+"InternalTemplates/jet_cnts", true);
543 
544  /*
545  charge1s.open(vhdlDir_+"InternalTemplates/charge_1s",false);
546  charge2s.open(vhdlDir_+"InternalTemplates/charge_2s",false);
547  charge2wsc.open(vhdlDir_+"InternalTemplates/charge_2_wsc",false);
548  charge3s.open(vhdlDir_+"InternalTemplates/charge_3",false);
549  charge4s.open(vhdlDir_+"InternalTemplates/charge_4",false);
550  */
551 
552  // only for jet_cnts common parameter relevant since common parameter is build in this routine
553  std::vector<unsigned int> processedTypes;
554 
555  //-------------------------------------build the common parameters-------------------------------------------
556 
557  // build $(muon_common)
558  getSubstParamCommonFromTriggerMenu(condChip,muon, Mu, CondMuon, commonParams["muon_common"]);
559 
560  // build $(calo_common) - loop over all calo objects
561  std::vector<L1GtObject>::iterator caloObjIter = caloObjects_.begin();
562 
563  while (caloObjIter != caloObjects_.end())
564  {
565 
566  getSubstParamCommonFromTriggerMenu(condChip, muon, (*caloObjIter), CondCalo,
567  commonParams["calo_common"]);
568  caloObjIter++;
569 
570  }
571 
572  // build $(esums_common) - loop over all esums objects
573  std::vector<L1GtObject>::iterator esumObjIter = esumObjects_.begin();
574 
575  while (esumObjIter != esumObjects_.end())
576  {
577 
578  getSubstParamCommonFromTriggerMenu(condChip, esums, (*esumObjIter), CondEnergySum,
579  commonParams["esums_common"]);
580  esumObjIter++;
581 
582  }
583 
584  //--------------------------------------build the parameter maps----------------------------------------------
585 
586  // loop over condition map
587  for (ConditionMap::const_iterator iterCond = (*conditionMap_).at(condChip-1).begin(); iterCond != (*conditionMap_).at(condChip-1).end(); iterCond++)
588  {
589 
590  switch ((iterCond->second)->condCategory())
591  {
592 
593  case CondMuon:
594  {
595 
596  int cond2int;
597  if (!getIntVal(conditionToIntegerMap_, (iterCond->first), cond2int))
598  {
599  msg("Panik! Condition "+(iterCond->first)
600  +" does not have a integer equivalent!");
601  break;
602  }
603 
604  std::string intVal = index4CondChipVhd(cond2int);
605 
606  L1GtVhdlTemplateFile muoncopy = muon;
607 
608  muoncopy.substitute("type", condType2Str_[(iterCond->second)->condType()]);
609 
610  muoncopy.substitute("ser_no", intVal);
611 
612  muoncopy.substitute("name", iterCond->first);
613 
614  if ((iterCond->second)->condType() == Type1s)
615  {
616  muoncopy.substitute(substParamCharge_,
618  } else if ((iterCond->second)->condType() == Type2s)
619  {
620  muoncopy.substitute(substParamCharge_,
622  } else if ((iterCond->second)->condType() == Type2wsc)
623  {
624  muoncopy.substitute(substParamCharge_,
626  } else if ((iterCond->second)->condType() == Type3s)
627  {
628  muoncopy.substitute(substParamCharge_,
630  } else if ((iterCond->second)->condType() == Type4s)
631  {
632  muoncopy.substitute(substParamCharge_,
634  }
635 
636  std::string tempStr = muoncopy.returnParameterMap()["PREALGO"];
637 
638  muoncopy.findAndReplaceString(tempStr, "$(particle)", "muon");
639  muoncopy.findAndReplaceString(tempStr, "$(ser_no)", intVal);
640  muoncopy.findAndReplaceString(tempStr, "$(type)", condType2Str_[(iterCond->second)->condType()]);
641 
642  muoncopy.append(tempStr);
643 
644  muoncopy.removeEmptyLines();
645 
646  // add the processed internal template to parameter map
647  templates["muon"].append(muoncopy);
648 
649  }
650  break;
651 
652  case CondCalo:
653  {
654  int cond2int;
655 
656  if (!getIntVal(conditionToIntegerMap_, (iterCond->first), cond2int))
657  {
658  msg("Panik! Condition "+(iterCond->first)
659  +" does not have a integer equivalent!");
660  break;
661  }
662 
663  std::string intVal = index4CondChipVhd(cond2int);
664 
665  L1GtVhdlTemplateFile calocopy = calo;
666 
667  calocopy.substitute("type", condType2Str_[(iterCond->second)->condType()]);
668  calocopy.substitute("particle", objType2Str_[((iterCond->second)->objectType()).at(0)]);
669  calocopy.substitute("name", iterCond->first);
670  calocopy.substitute("ser_no", intVal);
671  calocopy.substitute("calo_nr", caloType2Int_[((iterCond->second)->objectType()).at(0)]);
672 
673  // builds something like tau_1_s(20));
674  calocopy.append(objType2Str_[((iterCond->second)->objectType()).at(0)] +"_"+condType2Str_[(iterCond->second)->condType()]+"("+intVal+"));");
675 
676  templates["calo"].append(calocopy);
677 
678  }
679  break;
680 
681  case CondEnergySum:
682  {
683 
684  int cond2int;
685 
686  if (!getIntVal(conditionToIntegerMap_, (iterCond->first), cond2int))
687  {
688  msg("Panik! Condition "+(iterCond->first)
689  +" does not have a integer equivalent!");
690  break;
691  }
692 
693  std::string intVal = index4CondChipVhd(cond2int);
694 
695  L1GtVhdlTemplateFile esumscopy = esums;
696 
697  esumscopy.substitute("type", condType2Str_[(iterCond->second)->condType()]);
698  esumscopy.substitute("particle", objType2Str_[((iterCond->second)->objectType()).at(0)]);
699  esumscopy.substitute("name", iterCond->first);
700  esumscopy.substitute("ser_no", intVal);
701 
702  if (((iterCond->second)->objectType()).at(0)==ETM)
703  esumscopy.substitute("if_etm_then_1_else_0", "1");
704  else
705  esumscopy.substitute("if_etm_then_1_else_0", "0");
706 
707  // builds something like htt_cond(4));
708  esumscopy.append(objType2Str_[((iterCond->second)->objectType()).at(0)] +"_"+condType2Str_[(iterCond->second)->condType()]+"("+ intVal+"));");
709 
710  templates["esums"].append(esumscopy);
711  }
712 
713  break;
714 
715  case CondJetCounts:
716  {
717 
718  // build the common parameter for the jet counts
719 
720  L1GtJetCountsTemplate* jetsTemplate =
721  static_cast<L1GtJetCountsTemplate*>(iterCond->second);
722 
723  int nObjects = iterCond->second->nrObjects();
724 
725  const std::vector<L1GtJetCountsTemplate::ObjectParameter>* op =
726  jetsTemplate->objectParameter();
727 
728  for (int i = 0; i < nObjects; i++)
729  {
730 
731  std::vector<unsigned int>::iterator p = find(
732  processedTypes.begin(), processedTypes.end(), (*op)[i].countIndex);
733 
734  // check, weather this count index was already processed
735  // and process it if not
736  if (p==processedTypes.end())
737  {
738  std::ostringstream indStr;
739  indStr<<(*op)[i].countIndex;
740 
742  while (jet.findAndReplaceString(tempStr2,
744  ;
745  while (jet.findAndReplaceString(tempStr2,
746  sp(substParamType_), indStr.str()))
747  ;
748  commonParams[substParamJetCntsCommon_]+=tempStr2+"\n"; // +"<= '0';\n");
749  processedTypes.push_back((*op)[i].countIndex);
750  }
751 
752  }
753 
754  int cond2int;
755 
756  if (!getIntVal(conditionToIntegerMap_, (iterCond->first), cond2int))
757  {
758  msg("Panik! Condition "+(iterCond->first)
759  +" does not have a integer equivalent!");
760  break;
761  }
762 
763  std::string intVal = index4CondChipVhd(cond2int);
764 
765  L1GtVhdlTemplateFile jetcopy = jet;
766 
767  jetcopy.substitute("particle", condType2Str_[(iterCond->second)->condType()]);
768  jetcopy.substitute("type", int2str((*op)[0].countIndex));
769  jetcopy.substitute("name", iterCond->first);
770 
771  jetcopy.substitute("ser_no", intVal);
772 
773  // builds the final string
774  std::string tempStr = jetcopy.returnParameterMap()["PREALGO"];
775 
776  jetcopy.findAndReplaceString(tempStr, "$(particle)", "jet_cnt");
777  jetcopy.findAndReplaceString(tempStr, "$(ser_no)", intVal);
778  jetcopy.findAndReplaceString(tempStr, "$(type)", int2str((*op)[0].countIndex));
779 
780  jetcopy.append(tempStr);
781  jetcopy.removeEmptyLines();
782 
783  templates["jet_cnts"].append(jetcopy);
784  }
785 
786  break;
787 
788  case CondCorrelation:
789  {
790  //empty
791  }
792  break;
793 
794  case CondNull:
795  {
796  //empty
797  }
798  break;
799 
800  default:
801  {
802  //empty
803  }
804  break;
805  }
806  }
807 
808  // delete superfluous newlines at the end of common parameters
809  std::map<std::string,std::string>::iterator pIt = commonParams.begin();
810 
811  while (pIt!=commonParams.end())
812  {
813  if ((pIt->second)[((pIt->second).length()-1)] == '\n')
814  (pIt->second) = (pIt->second).substr(0, (pIt->second).length()-1);
815  pIt++;
816  }
817 
818  return true;
819 
820 }
821 
822 bool L1GtVhdlWriterCore::processAlgorithmMap(std::vector< std::map<int, std::string> > &algoStrings)
823 {
824  std::map<int, std::string> algorithmsChip1;
825  std::map<int, std::string> algorithmsChip2;
826 
827  AlgorithmMap::const_iterator algoIter=(*algorithmMap_).begin();
828 
829  // loop over algorithm map
830  while (algoIter!=(*algorithmMap_).end())
831  {
832  // msg(algoIter->first);
833 
834  L1GtVhdlTemplateFile dummy;
835 
836  // get the logical expression
837  std::string logicalExpr = (algoIter->second).algoLogicalExpression();
838  std::vector<std::string> conditions;
839 
840  dummy.getConditionsFromAlgo(logicalExpr, conditions);
841 
842  std::string logicalExprCopy= logicalExpr;
843 
844  // loop over all condition names appearing in algorithm and replace them by type and integer value
845  for (unsigned int i=0; i<conditions.size(); i++)
846  {
847  std::ostringstream newExpr;
848 
849  // look for the condition on correct chip
850  ConditionMap const& chip = conditionMap_->at(algoIter->second.algoChipNumber());
851  L1GtCondition const* cond = (chip.find(conditions.at(i)) == chip.end()) ? nullptr : chip.at(conditions.at(i));
852 
853  // check weather condition exists
854  if (cond!=NULL)
855  {
856  newExpr << objType2Str_[(cond->objectType()).at(0)];
857  newExpr << "_" << condType2Str_[cond->condType()] << "(";
858  newExpr << conditionToIntegerMap_[conditions.at(i)] << ")";
859  dummy.findAndReplaceString(logicalExpr, conditions.at(i),
860  newExpr.str());
861  } else
862  msg("Panik! Didn't find Condition "+conditions.at(i));
863  }
864 
865  // has to be checked!
866  std::vector<int> orderConditionChip;
867  orderConditionChip.push_back(2);
868  orderConditionChip.push_back(1);
869 
870  int pin = (algoIter->second).algoOutputPin(2, 96, orderConditionChip);
871 
872  //msg(int2str(pin));
873 
874  if (pin<0)
875  pin*=-1;
876 
877  if ((algoIter->second).algoChipNumber()==0)
878  {
879  algorithmsChip1[pin]=logicalExpr;
880  if (debugMode_)
881  algorithmsChip1[pin]+=("-- "+logicalExprCopy);
882  } else if ((algoIter->second).algoChipNumber()==1)
883  {
884  algorithmsChip2[pin]=logicalExpr;
885  if (debugMode_)
886  algorithmsChip2[pin]+=("-- "+logicalExprCopy);
887  } else
888  ;
889 
890  algoIter++;
891  }
892 
893  algoStrings.push_back(algorithmsChip1);
894  algoStrings.push_back(algorithmsChip2);
895 
896  return true;
897 
898 }
899 
901 {
902  if (chip==1)
903  return outputDir_+"/"+outputSubDir1_+"/";
904  if (chip==2)
905  return outputDir_+"/"+outputSubDir2_+"/";
906 
907  return "";
908 }
909 
910 
911 bool L1GtVhdlWriterCore::makeFirmware(const std::vector<ConditionMap> &conditionMap,
912  const AlgorithmMap &algorithmMap)
913 {
914  conditionMap_ = &conditionMap;
915 
916  algorithmMap_ = &algorithmMap;
917 
920 
921  if (!mkdir(subDir1.c_str(), 666));
922  if (!mkdir(subDir2.c_str(), 666));
923 
924  chmod(subDir1.c_str(), 0777);
925  chmod(subDir2.c_str(), 0777);
926 
927  /*
928  subDirs_.push_back(subDir1);
929  subDirs_.push_back(subDir2);
930  */
931 
933 
934 
935  //--------------------------------------build setups-------------------------------------------------------
936 
937  // loop over the two condition chips
938  for (unsigned short int i =1; i<=2; i++)
939  {
940  // ----------------------- muon setup -------------------------------------------------------
941 
942  std::map<std::string,std::string> muonParameters;
943  getMuonSetupContentFromTriggerMenu(i, muonParameters);
944  writeMuonSetupVhdl(muonParameters, "muon", i);
945 
946  // ----------------------- calo setup -------------------------------------------------------
947 
948  // map containing all calo object types correlated with the strings
949  // under which they appear in the firmware
950  std::vector<L1GtObject>::iterator caloObjIter = caloObjects_.begin();
951 
952  // loop over all calo objectsbuildMuonSetupVhdl
953  while (caloObjIter != caloObjects_.end())
954  {
955  std::map<std::string,std::string> caloParameters;
956  getCaloSetupContentFromTriggerMenu(i, caloParameters,
957  (*caloObjIter));
958  writeMuonSetupVhdl(caloParameters, objType2Str_[(*caloObjIter)], i);
959 
960  caloObjIter++;
961  }
962 
963  // ----------------------- etm setup ---------------------------------------------------------
964 
965  // map containing all calo object types correlated with the strings
966  // under which they appear in the firmware
967  std::vector<L1GtObject>::iterator esumObjIter = esumObjects_.begin();
968 
969  while (esumObjIter != esumObjects_.end())
970  {
971  std::string etmParameter;
972 
973  getEsumsSetupContentFromTriggerMenu(i, (*esumObjIter),
974  etmParameter);
975  writeEtmSetup(etmParameter, i);
976 
977  esumObjIter++;
978 
979  }
980 
981  // add jet counts to condition 2 integer map
983 
984  // --------------------cond chip setup---------------------------------------------------------
985  // Important: all other setups have to be build BEFORE this one because it needs a
986  // complete condition2integer map !!!
987 
988  std::map<std::string, L1GtVhdlTemplateFile> templates;
989  std::map<std::string, std::string> common;
990  getCondChipVhdContentFromTriggerMenu(i, templates, common);
991  writeConditionChipSetup(templates, common, i);
992 
993  // despite yet not existing they have to appear in cond_chip_pkg vhds
995 
996  // --------------------cond chip pkg------------------------------------------------------------
997 
999 
1000  // -----------------------def val pkg -------------------------------------------------
1001 
1003 
1004  // debug
1005  if (debugMode_)
1006  {
1007  //printConditionsOfCategory(CondEnergySum, (*conditionMap_).at(i-1));
1008  }
1009 
1010  }
1011 
1012  if (debugMode_)
1014 
1015  //-------------------------------process algorithms----------------------------------------------------------
1016 
1017  std::vector< std::map<int, std::string> > algoStrings;
1018 
1019  processAlgorithmMap(algoStrings);
1020 
1021  writeAlgoSetup(algoStrings);
1022 
1023  return true;
1024 }
1025 
1027 {
1028  return vhdlDir_;
1029 }
1030 
1032 {
1033  std::ostringstream oss;
1034  oss<<integerValue;
1035  return oss.str();
1036 
1037 }
1038 
1040  std::map<std::string,std::string> &headerParameters,
1041  const std::vector<std::string> &connectedChannels)
1042 {
1043  commonHeader_.open(vhdlDir_+"InternalTemplates/header");
1044 
1045  std::map<std::string,std::string>::iterator iter = headerParameters.begin();
1046 
1047  // loop over the header parameter map and replace all subsitution
1048  // parameters with their values
1049  while (iter != headerParameters.end() )
1050  {
1051  commonHeader_.substitute((*iter).first, (*iter).second);
1052  iter++;
1053  }
1054 
1055  commonHeader_.insert("$(connected_channels_1)", connectedChannels);
1056  commonHeader_.insert("$(connected_channels_2)", connectedChannels);
1057 
1058  //---------------------build the Quartus configuration files----------------------------------------
1059 
1060  //writeQsfSetupFiles(headerParameters["version"]);
1061 
1062  version_=headerParameters["version"];
1063 
1064  msg("Build Common header and Quartus setup files sucessuflly!");
1065 
1066 }
1067 
1069  const std::string &filename, const std::string &outputFilename)
1070 {
1071  L1GtVhdlTemplateFile commonHeaderCp;
1072  commonHeaderCp = commonHeader_;
1073 
1074  commonHeaderCp.substitute("vhdl_file_name", outputFilename);
1075 
1076  L1GtVhdlTemplateFile myTemplate(vhdlDir_+"Templates/"+filename);
1077  myTemplate.insert("$(header)", commonHeaderCp);
1078 
1079  return myTemplate;
1080 }
1081 
1083  std::map<std::string,std::string> &muonParameters,
1084  const std::string &particle, unsigned short int &condChip)
1085 {
1087 
1088  L1GtVhdlTemplateFile muonTemplate, internalTemplate, internalTemplateCopy;
1089 
1090  // choose the correct template file name
1091  if (particle=="muon")
1092  {
1093  filename = vhdlTemplateMuonSetup_;
1094  internalTemplate.open(vhdlDir_+"InternalTemplates/muonsetup", true);
1095  } else
1096  {
1097  filename = vhdlTemplateCaloSetup_;
1098  internalTemplate.open(vhdlDir_+"InternalTemplates/calosetup", true);
1099  }
1100 
1102  outputFile = filename;
1103 
1104  // modify filename
1105  if (particle!="muon")
1106  muonTemplate.findAndReplaceString(outputFile, "calo", particle);
1107 
1108  // add condition chip index to output filename
1109  //muonTemplate.findAndReplaceString(outputFile, ".", int2str(condChip)+".");
1110 
1111  // open the template file and insert header
1112  muonTemplate = openVhdlFileWithCommonHeader(filename, outputFile);
1113 
1114  std::map<std::string,std::string> parameterMap =
1115  internalTemplate.returnParameterMap();
1116 
1117  std::vector<std::string> substitutionParameters;
1118 
1119  // fills the map with all substitution parameters of the template file
1120  substitutionParameters=muonTemplate.getSubstitutionParametersFromTemplate();
1121 
1122  // insert a emty line at the end of each block
1123  internalTemplate.append("");
1124 
1125  std::map<std::string, std::string>::iterator iter;
1126 
1127  // loop over all substitution parameters that have been extracted from the template file
1128  for (unsigned int i=0; i<substitutionParameters.size(); i++)
1129  {
1130  // make a working copy of the template file
1131  internalTemplateCopy = internalTemplate;
1132 
1133  // choose which of the three constant template strings to take - only for calo!
1134  if (particle!="muon")
1135  {
1136 
1137  if (substitutionParameters.at(i).substr(0, 3) == "eta")
1138  internalTemplateCopy.substitute("constant", parameterMap["eta"]);
1139  else if (substitutionParameters.at(i).substr(0, 3) == "phi")
1140  internalTemplateCopy.substitute("constant", parameterMap["phi"]);
1141  else if (substitutionParameters.at(i).substr(0, 3) == "del"/*ta*/)
1142  {
1143  internalTemplateCopy.substitute("constant",
1144  parameterMap["delta"]);
1145  while (internalTemplateCopy.substitute("delta",
1146  substitutionParameters[i]))
1147  internalTemplateCopy.substitute("delta",
1148  substitutionParameters[i]);
1149 
1150  }
1151  }
1152 
1153  if (particle=="muon")
1154  {
1155  // final preparation of the internal template before it is inserted in the actual template file
1156  internalTemplateCopy.substitute("type", substitutionParameters[i]);
1157  } else
1158 
1159  {
1160  internalTemplateCopy.substitute("type", substitutionParameters[i].substr(4));
1161  }
1162 
1163  // subsitute the second occurance of type without "_l" and "_h"
1164 
1165  std::string paramCopy = substitutionParameters[i];
1166 
1167  internalTemplateCopy.findAndReplaceString(paramCopy, "_l", "");
1168  internalTemplateCopy.findAndReplaceString(paramCopy, "_h", "");
1169 
1170  internalTemplateCopy.substitute("type2", paramCopy);
1171 
1172  internalTemplateCopy.substitute("others",
1173  parameterMap[substitutionParameters[i]]);
1174 
1175  // replace all the occurances of "particle"
1176  while (muonTemplate.substitute("particle", particle))
1177  muonTemplate.substitute("particle", particle);
1178 
1179  // remove the the parameter $(content) if its empty
1180  iter=muonParameters.find(substitutionParameters[i]);
1181 
1182  // check weather this parameter exists
1183  if (iter!=muonParameters.end())
1184  {
1185  if ((*iter).second[(*iter).second.length()-1]=='\n')
1186  (*iter).second[(*iter).second.length()-1]=' ';
1187  internalTemplateCopy.substitute("content", (*iter).second);
1188  } else
1189  internalTemplateCopy.removeLineWithContent("$(content)");
1190 
1191  // insert the processed internal template in the muon template file
1192  muonTemplate.insert("$("+substitutionParameters[i]+")",
1193  internalTemplateCopy);
1194  }
1195 
1196  // save the muon template file
1197  muonTemplate.save(chip2OutputSubDir(condChip)+outputFile);
1198  chmod((chip2OutputSubDir(condChip)+outputFile).c_str(), 0666);
1199 
1200 }
1201 
1203  const std::map<std::string, L1GtVhdlTemplateFile>& templates,
1204  const std::map<std::string, std::string> &common,
1205  const unsigned short int &chip)
1206 {
1207 
1208  // get filename
1210 
1211  // build output filename
1213  L1GtVhdlTemplateFile::findAndReplaceString(outputFileName, ".",
1214  int2str(chip)+".");
1215 
1216  L1GtVhdlTemplateFile myTemplate = openVhdlFileWithCommonHeader(filename,
1217  outputFileName);
1218 
1219  // map containing the subsitution parameters with their content (as L1GtVhdlTemplateFile file object)
1220  std::map<std::string, L1GtVhdlTemplateFile>::const_iterator iter=
1221  templates.begin();
1222 
1223  while (iter != templates.end())
1224  {
1225 
1226  myTemplate.insert("$("+(iter->first)+")", iter->second);
1227 
1228  iter++;
1229  }
1230 
1231  // subsitutes common parameters
1232  std::map<std::string, std::string>::const_iterator iter2= common.begin();
1233 
1234  while (iter2 != common.end())
1235  {
1236 
1237  myTemplate.substitute((iter2->first), iter2->second);
1238 
1239  iter2++;
1240  }
1241 
1242  myTemplate.save(chip2OutputSubDir(chip)+filename);
1243  chmod((chip2OutputSubDir(chip)+filename).c_str(), 0666);
1244 
1245 }
1246 
1247 void L1GtVhdlWriterCore::writeAlgoSetup(std::vector< std::map<int, std::string> > &algoStrings)
1248 {
1249  // loop over the two condition chips
1250  for (unsigned int i=1; i<=2; i++)
1251  {
1253 
1254  // output file name
1256  L1GtVhdlTemplateFile::findAndReplaceString(outputFileName, ".",
1257  int2str(i)+".");
1258 
1260  filename, outputFileName);
1261 
1262  std::ostringstream buffer;
1263 
1264  unsigned int algoPinsPerChip = 96;
1265 
1266  for (unsigned int k=1; k<=algoPinsPerChip; k++)
1267  {
1268 
1269  buffer<< stringConstantAlgo_<<"("<<k<<")";
1270  if (algoStrings.at(i-1)[k]!="")
1271  buffer<<" <= "<<algoStrings.at(i-1)[k]<<";"<<std::endl;
1272  else
1273  buffer<<" <= '0';"<<std::endl;
1274  }
1275 
1276  templateFile.substitute(substParamAlgos_, buffer.str());
1277  templateFile.save(chip2OutputSubDir(i)+filename);
1278  chmod((chip2OutputSubDir(i)+filename).c_str(), 0666);
1279  }
1280 
1281 }
1282 
1284  const int &condChip)
1285 {
1286 
1287  // get filename
1290 
1291  L1GtVhdlTemplateFile myTemplate;
1292 
1293  // modify output filename
1294  myTemplate.findAndReplaceString(outputFile, ".", int2str(condChip)+".");
1295 
1296  myTemplate = openVhdlFileWithCommonHeader(filename, filename);
1297 
1298  // replace all occurances of $(particle)
1299  while (myTemplate.substitute("particle", "etm"))
1300  while (myTemplate.substitute("particle", "etm"))
1301  ;
1302 
1303  // delete last char if it is \n
1304  if (etmString[etmString.length()-1] == '\n')
1305  etmString = etmString.substr(0, etmString.length()-1);
1306 
1307  myTemplate.substitute("phi", etmString);
1308 
1309  myTemplate.save(chip2OutputSubDir(condChip)+filename);
1310  chmod((chip2OutputSubDir(condChip)+filename).c_str(), 0666);
1311 
1312 }
1313 
1315 {
1316  commonHeader_.print();
1317 }
1318 
1320 {
1321  return commonHeader_;
1322 }
1323 
1325 {
1326 
1327  std::vector<std::string> filenames;
1328  filenames.push_back(quartusSetupFileChip1_);
1329  filenames.push_back(quartusSetupFileChip2_);
1330 
1331  for (unsigned int i=0; i<filenames.size(); i++)
1332  {
1333  L1GtVhdlTemplateFile myTemplate;
1334 
1335  myTemplate.open(vhdlDir_+"Templates/"+filenames.at(i));
1336  myTemplate.substitute("version", version);
1337 
1338  std::string tempStr = filenames.at(i);
1339 
1340  if (i==0)
1341  L1GtVhdlTemplateFile::findAndReplaceString(tempStr , "cond1","cond");
1342  if (i==1)
1343  L1GtVhdlTemplateFile::findAndReplaceString(tempStr , "cond2","cond");
1344 
1345  myTemplate.save(chip2OutputSubDir(i+1)+tempStr);
1346  chmod((chip2OutputSubDir(i+1)+tempStr).c_str(), 0666);
1347  }
1348 
1349 }
1350 
1352 {
1353  internMessageBuf_.push_back(message);
1354 }
1355 
1356 std::vector<std::string> L1GtVhdlWriterCore::getMsgBuf()
1357 {
1358  return internMessageBuf_;
1359 }
1360 
1361 bool L1GtVhdlWriterCore::getIntVal(const std::map<std::string,int> &map,
1362  const std::string &searchValue, int &intVal)
1363 {
1364  std::map<std::string,int>::const_iterator iter = map.find(searchValue);
1365  if (iter == map.end() )
1366  return false;
1367  intVal = (*iter).second;
1368  return true;
1369 }
1370 
1372 {
1373  intval++;
1374  return int2str(intval);
1375 }
1376 
1378  const std::vector<ConditionMap> &conditionMap,
1379  std::map<std::string,int> &conditionToIntegerMap_)
1380 {
1381  ConditionMap jetConditions;
1382 
1384  conditionMap.at(chip-1), jetConditions);
1385  /*
1386  int counter = 0;
1387 
1388  for (ConditionMap::const_iterator iterCond = jetConditions.begin(); iterCond != jetConditions.end(); iterCond++)
1389  {
1390  conditionToIntegerMap_[iterCond->first]=counter;
1391  counter++;
1392  msg(iterCond->first);
1393  }
1394 
1395  */
1396 
1397  unsigned int maxJetsCountsIndex = 11;
1398 
1399  for (unsigned int i= 0; i<=maxJetsCountsIndex; i++)
1400  {
1401  int counter = 0;
1402 
1403  for (ConditionMap::const_iterator iterCond = jetConditions.begin(); iterCond
1404  != jetConditions.end(); iterCond++)
1405  {
1406 
1407  L1GtJetCountsTemplate* jetsTemplate =
1408  static_cast<L1GtJetCountsTemplate*>(iterCond->second);
1409  const std::vector<L1GtJetCountsTemplate::ObjectParameter>* op =
1410  jetsTemplate->objectParameter();
1411 
1412  conditionToIntegerMap_[iterCond->first]=counter;
1413  if ((*op)[0].countIndex==i)
1414  counter++;
1415 
1416  //msg(int2str((*op)[0].countIndex));
1417 
1418  }
1419 
1420  numberOfConditions_.at(chip-1).push_back(retNumberOfConditionsString("jet_cnts_"
1421  +int2str(i)+"_cond", counter));
1422 
1423  }
1424 
1425 }
1426 
1428 {
1429 
1430 
1431  for (unsigned int i=0; i<=1;i++)
1432  {
1433  ConditionMap::const_iterator iterCond =
1434  conditionMap_->at(i).begin();
1435 
1436  std::string filename=chip2OutputSubDir(i+1)+"cond_names_integer.txt";
1437 
1438  std::ofstream outputFile(filename.c_str());
1439 
1440  while (iterCond!=conditionMap_->at(i).end())
1441  {
1442  conditionToIntegerMap_[(*iterCond).first];
1443 
1444  outputFile<<(iterCond->first)<<": "<<conditionToIntegerMap_[(*iterCond).first]<<std::endl;
1445  iterCond++;
1446  }
1447 
1448  outputFile.close();
1449 
1450  chmod(filename.c_str(), 0666);
1451 
1452 
1453  }
1454 
1455  /*
1456 
1457 
1458  const std::vector<ConditionMap> * conditionMap_;
1459 
1460  std::string filename=outputDir_+"cond_names_integer.txt";
1461  std::ofstream outputFile(filename.c_str());
1462 
1463  for (std::map<std::string,int>::const_iterator iterCond =
1464  conditionToIntegerMap_.begin(); iterCond
1465  != conditionToIntegerMap_.end(); iterCond++)
1466  {
1467  outputFile<<(iterCond->first)<<": "<<(iterCond->second)<<std::endl;
1468  }
1469 
1470  */
1471 
1472 }
1473 
1475  const std::vector<int> &values)
1476 {
1477  // has to produce something like 1 => ("00000000", "00000000")
1478 
1479  return "1 => (\"00000000\", \"00000000\")";
1480 }
1481 
1483  const L1GtConditionType &type, const L1GtObject &object,
1484  const VmeRegister &reg)
1485 {
1487 
1488  // get condition category from object
1489 
1490  category = getCategoryFromObject(object);
1491 
1492  ConditionMap conditions;
1493  returnConditionsOfOneClass(type, category, object, (*conditionMap_).at(0),
1494  conditions);
1495 
1497 
1498  if (category==CondCalo)
1499  {
1500  for (ConditionMap::const_iterator iterCond =conditions.begin(); iterCond
1501  != conditions.end(); iterCond++)
1502  {
1503  L1GtCaloTemplate* caloTemplate =
1504  static_cast<L1GtCaloTemplate*>(iterCond->second);
1505  const std::vector<L1GtCaloTemplate::ObjectParameter>* op =
1506  caloTemplate->objectParameter();
1507 
1508  unsigned int nObjects = iterCond->second->nrObjects();
1509 
1510  for (unsigned int i =0; i<nObjects; i++)
1511  {
1512  if (i==0)
1513  result+="(";
1514  result +="\"";
1515  result += int2str((*op).at(i).etThreshold);
1516  result +="\"";
1517  if (i!=nObjects-1)
1518  result +=",";
1519  else
1520  result+=")\n";
1521 
1522  }
1523  }
1524  }
1525 
1526  return "-- 0 => (\"00000000\", \"00000000\" ... )";
1527  return result;
1528 }
1529 
1531  const std::vector<ConditionMap> &conditionMap, const int &chip)
1532 {
1533  // open internal template file
1534  L1GtVhdlTemplateFile internalTemplate;
1535  internalTemplate.open(vhdlDir_+"InternalTemplates/defvalpkg", true);
1536 
1537  // to write the def_value_pkg file it has to be looped over all POSSIBLE types of conditions
1538  // POSSIBLE: calo_3 eg. does not exist and therefore makes no sense..
1539 
1540  // Process muon conditions first
1541 
1542  // temporary buffers for the default value blocks (see internal templates) of the different types.
1543  // in the end those buffers are simply appended to the actual template!
1544  L1GtVhdlTemplateFile muonDefValuesBuffer, caloDefValuesBuffer,
1545  jetCountsDefValuesBuffer, esumsDefValBuffer;
1546 
1547  // Get the default value type strings from internal template
1548  std::vector<std::string> muonDefValTypes;
1549  muonDefValTypes.push_back(internalTemplate.getInternalParameter(stringConstantPtl_));
1550  muonDefValTypes.push_back(internalTemplate.getInternalParameter(stringConstantPth_));
1551  muonDefValTypes.push_back(internalTemplate.getInternalParameter(stringConstantQuality_));
1552  muonDefValTypes.push_back(internalTemplate.getInternalParameter(substParamCharge_));
1553 
1554  int jetCountsMaxIndex = 11;
1555 
1556  // fill jet counts vector (from 1 to 11)
1557  std::vector<std::string> jetCountsDefValTypes;
1558  for (int i = 0; i<=jetCountsMaxIndex; i++)
1559  {
1560  jetCountsDefValTypes.push_back(int2str(i));
1561  }
1562 
1563  // only one default value for calo objects therefore only a empty string
1564  std::vector<std::string> caloDefValTypes;
1565  caloDefValTypes.push_back("");
1566 
1567  // get types of esums defvalues (as firmware strings) from the internal templates
1568  std::vector<std::string> esumsDefValTypes;
1569  esumsDefValTypes.push_back(internalTemplate.getInternalParameter(stringConstantEsumsLow_));
1570  esumsDefValTypes.push_back(internalTemplate.getInternalParameter(stringConstantEsumsHigh_));
1571 
1572  std::map<L1GtConditionType,std::string>::iterator typeIter;
1573 
1574  // prepare a map with all muon relevant types by removing
1575  // obsolete types from a copy of condType2Str_ map
1576  // should be improved
1577  std::map<L1GtConditionType,std::string> muonTypes = condType2Str_;
1578 
1579  typeIter=muonTypes.find(Type2cor);
1580  muonTypes.erase(typeIter);
1581  typeIter=muonTypes.find(TypeETM);
1582  muonTypes.erase(typeIter);
1583  typeIter=muonTypes.find(TypeETT);
1584  muonTypes.erase(typeIter);
1585  typeIter=muonTypes.find(TypeHTT);
1586  muonTypes.erase(typeIter);
1587  typeIter=muonTypes.find(TypeJetCounts);
1588  muonTypes.erase(typeIter);
1589 
1590  std::map<L1GtConditionType,std::string> caloTypes = muonTypes;
1591  typeIter=caloTypes.find(Type3s);
1592  caloTypes.erase(typeIter);
1593 
1594  // dummy type in order to be able to use the same code as for calo and muon
1595  // this map is also used for esums since there is no difference in treatment
1596  std::map<L1GtConditionType,std::string> jetCountsTypes;
1597  jetCountsTypes[TypeJetCounts] = "";
1598 
1599  // here the DefValuesBuffer are build (=objects of the class L1GtVhdlTemplateFile
1600  // that are containing all default values and finally can be inserted into the
1601  // def_val_pkg.vhd template
1602 
1603  buildDefValuesBuffer(muonDefValuesBuffer, muonTypes, muonDefValTypes, Mu);
1604 
1605  // loop over all possible calo objects here
1606  for (unsigned int i=0; i<caloObjects_.size(); i++)
1607  {
1608  buildDefValuesBuffer(caloDefValuesBuffer, caloTypes, caloDefValTypes,
1609  caloObjects_.at(i));
1610  }
1611 
1612  // loop over all possible esums objects here
1613  for (unsigned int i=0; i<esumObjects_.size(); i++)
1614  {
1615  buildDefValuesBuffer(esumsDefValBuffer, jetCountsTypes,
1616  esumsDefValTypes, esumObjects_.at(i));
1617  }
1618 
1619  // same procedure for jet counts
1620  buildDefValuesBuffer(esumsDefValBuffer, jetCountsTypes,
1621  jetCountsDefValTypes, JetCounts);
1622 
1623  //----------------------In this section the actual output file is written----------------
1624 
1625  // now open the actual template file:
1626 
1628 
1630 
1631  // modify output filename
1633  +".");
1635  filename, outputFile);
1636 
1637  // insert the temporary buffers to the template
1638 
1639  // muon default values
1640  defValTemplate.insert(sp(substParamMuonDefVals_), muonDefValuesBuffer);
1641 
1642  // calo default values
1643  defValTemplate.insert(sp(substParamCaloDefVals_), caloDefValuesBuffer);
1644 
1645  // esums default values
1646  defValTemplate.insert(sp(substParamEsumsDefVals_), esumsDefValBuffer);
1647 
1648  // jet counts default values
1649  defValTemplate.insert(sp(substParamJetsDefVals_), jetCountsDefValuesBuffer);
1650 
1651  // close and save the file
1652 
1653  L1GtVhdlTemplateFile::findAndReplaceString(outputFile, "1","");
1654  L1GtVhdlTemplateFile::findAndReplaceString(outputFile, "2","");
1655 
1656  defValTemplate.save(chip2OutputSubDir(chip)+outputFile);
1657  chmod((chip2OutputSubDir(chip)+outputFile).c_str(), 0666);
1658 
1659 }
1660 
1662  const std::map<L1GtConditionType,std::string> &typeList,
1663  const std::vector<std::string> &defValuesList, const L1GtObject &object)
1664 {
1665  // type iterator
1666  std::map<L1GtConditionType,std::string>::const_iterator typeIter;
1667 
1668  for (typeIter=typeList.begin(); typeIter!=typeList.end(); typeIter++)
1669  {
1670 
1671  for (unsigned int i = 0; i<defValuesList.size(); i++)
1672  {
1673 
1674  // open a new internale template
1675  L1GtVhdlTemplateFile internalTemplate;
1676  internalTemplate.open(vhdlDir_+"InternalTemplates/defvalpkg", true);
1677 
1678  std::string
1679  idString =
1681 
1682  // The following three steps convert "$(particle)_$(type)_$(defvaltype)_def_val"
1683  // to e.g. "muon_1s_et_def_val"
1684 
1685  // replace the substiution parameter particle with muon - thereby parameterString is a
1686  // reference and therefore changed.
1688  sp(substParamParticle_), objType2Str_[object]);
1689 
1690  // replace the substiution parameter particle with muon
1692  sp(substParamType_), typeIter->second);
1693 
1694  // replace the substiution parameter defvaltype with muon
1696  sp(substParamDefValType_), defValuesList.at(i));
1697 
1698  // usage of the subsitute routine:
1699  // first the substitution parameter, then the content
1700  internalTemplate.substitute(substParamDefValId_, idString);
1701 
1702  // !here the body of the internale template is build - almost done!
1703 
1704  // The body looks as follows $(def_val), $(max_nr), $(content) and
1705  // $(others) have to be subsituted
1706 
1707  /*
1708  * CONSTANT $(def_val) : $(calo_or_muon)_maxnr$(max_nr)vector8_arr :=
1709  * (
1710  * $(content)
1711  * $(others)
1712  * );
1713  */
1714 
1715  // substitute the particle
1716  internalTemplate.substitute(substParamParticle_,
1717  objType2Str_[object]);
1718 
1719  // go on with max number - get the correct expression for max number from the internal template
1720  internalTemplate.substitute(substParamMaxNr_,
1721  internalTemplate.getInternalParameter(substParamMaxNr_+"_"
1722  +condType2Str_[typeIter->first]));
1723 
1724  // now we have to choose the correct OTHERS string for the
1725  // internal template. The identifier for the OTHERS string
1726  // is the condition type (as firmware string) therefore:
1727 
1728  // we get it as follows
1729  std::string othersString;
1730 
1731  // jet_cnts are a special case
1732  if (object==JetCounts || object==HTT || object==ETM || object==ETT )
1733  othersString
1734  = internalTemplate.getInternalParameter(objType2Str_[JetCounts]);
1735  else
1736  othersString
1737  = internalTemplate.getInternalParameter(typeIter->second);
1738 
1739  internalTemplate.substitute(substParamOthers_, othersString);
1740 
1741  // the actual content, taken from the trigger menu
1742 
1743  std::string content = getDefValsFromTriggerMenu(typeIter->first,
1744  object, RegEtThreshold);
1745 
1746  internalTemplate.substitute(substParamContent_, content);
1747 
1748  // Finally the parameter $(calo_or_muon) is left open
1749  std::string caloOrMuonStr = stringConstantCalo_;
1750 
1751  if (object == Mu)
1752  caloOrMuonStr = objType2Str_[Mu];
1753 
1754  internalTemplate.substitute(substParamCaloOrMuon_, caloOrMuonStr);
1755 
1756  // The internal template has been processed and now can be added to the buffer..
1757  buffer.append(internalTemplate);
1758 
1759  }
1760 
1761  }
1762 
1763  return true;
1764 }
1765 
1768  const L1GtObject &object, const ConditionMap &map,
1769  ConditionMap &outputMap, const int &condChip)
1770 {
1771 
1772  // Get the absoloute amount of conditions
1773 
1774  int number;
1775 
1776  if (returnConditionsOfOneClass(type, category, object, map, outputMap))
1777  number=outputMap.size();
1778  else
1779  number=0;
1780 
1782  +condType2Str_[type], number);
1783 
1784  numberOfConditions_.at(condChip-1).push_back(initstr);
1785 
1786 }
1787 
1789 {
1790 
1791  for (unsigned int k=0; k<=1; k++)
1792  {
1793 
1794  // combine muon with calo particles
1795  for (unsigned int i=0; i<caloObjects_.size(); i++)
1796  {
1798  +"_"+objType2Str_[caloObjects_.at(i)], 0));
1799  }
1800 
1801  // combine etm with muon
1803  +objType2Str_[Mu], 0));
1804 
1805  // combine etm with calo particles
1806  for (unsigned int i=0; i<caloObjects_.size(); i++)
1807  {
1809  +"_"+objType2Str_[caloObjects_.at(i)], 0));
1810  }
1811 
1812  std::vector<L1GtObject> caloObjectsCp = caloObjects_;
1813 
1814  while (caloObjectsCp.size()>0)
1815  {
1816  std::vector<L1GtObject>::iterator iter=caloObjectsCp.begin();
1817  L1GtObject firstPartner = (*iter);
1818  caloObjectsCp.erase(iter);
1819 
1820  iter=caloObjectsCp.begin();
1821  while (iter!=caloObjectsCp.end())
1822  {
1824  objType2Str_[firstPartner]+"_"+objType2Str_[(*iter)], 0));
1825  iter++;
1826  }
1827 
1828  }
1829 
1830  }
1831 }
1832 
1834  const L1GtObject &object)
1835 {
1836 
1838 
1839  if (object==Mu)
1840  category = CondMuon;
1841  else if (object==ETM || object==HTT || object==ETT)
1842  category = CondEnergySum;
1843  else if (object==IsoEG|| object==NoIsoEG || object==CenJet || object
1844  ==ForJet || object==TauJet)
1845  category = CondCalo;
1846  else if (object==IsoEG|| object==NoIsoEG || object==CenJet || object
1847  ==ForJet || object==TauJet)
1848  category = CondCalo;
1849  else if (object==JetCounts)
1850  category = CondJetCounts;
1851  else
1852  category=CondNull;
1853 
1854  return category;
1855 
1856 }
1857 
1860 {
1861  int counter =0;
1862  for (ConditionMap::const_iterator iterCond = map.begin(); iterCond
1863  != map.end(); iterCond++)
1864  {
1865  msg(iterCond->first);
1866  counter++;
1867  }
1868 
1869  msg("Total Occurances: "+int2str(counter));
1870 
1871 }
1872 
1874 {
1875 
1876  // build filename
1877 
1879 
1880  if (chip==1)
1881  filename = vhdlTemplateCondChipPkg1_;
1882  else if (chip==2)
1883  filename = vhdlTemplateCondChipPkg2_;
1884 
1885  // write the output
1886  L1GtVhdlTemplateFile myTemplate = openVhdlFileWithCommonHeader(filename,
1887  filename);
1888 
1889  myTemplate.substitute("version",version_);
1890 
1891  myTemplate.insert("$(conditions_nr)", numberOfConditions_.at(chip-1));
1892 
1895 
1896  myTemplate.save(chip2OutputSubDir(chip)+filename);
1897  chmod((chip2OutputSubDir(chip)+filename).c_str(), 0666);
1898 }
1899 
1901  const std::string &typeStr, const int &number)
1902 {
1903  std::string initstr=stringConstantConstantNr_+typeStr+" : integer := "+int2str(number)
1904  +";";
1905 
1906  return initstr;
1907 }
1908 
1909 std::map<std::string,int> L1GtVhdlWriterCore::getCond2IntMap()
1910 {
1911  return conditionToIntegerMap_;
1912 }
1913 
1915 {
1916  return "$("+name+")";
1917 }
1918 
static const std::string substParamMuonDefVals_
static const std::string vhdlTemplateAlgoAndOr_
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
std::string vhdlDir_
templates directory
std::string sp(const std::string &name)
converts string name to substiution parameter synthax; name –&gt;
static const bool findAndReplaceString(std::string &paramString, const std::string &searchString, const std::string &replaceString)
replaces searchString with replaceString at it&#39;s first occurance in string
std::string buildEtaCalo(const std::vector< L1GtCaloTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
static const std::string substParamCaloDefVals_
const int nrObjects() const
get number of trigger objects
bool substitute(const std::string &searchString, const std::string &replaceString)
replaces searchString with replaceString
static const std::string stringConstantCharge2wsc_
const std::map< L1GtConditionType, std::string > getCond2StrMap()
const CorrelationParameter * correlationParameter() const
static const std::string quartusSetupFileChip2_
static const std::string stringConstantDefValId_
void writeQsfSetupFiles(const std::string &version)
builds the two quartus setup files. This routine is called in buildCommonHeader!
std::vector< L1GtObject > esumObjects_
list of all possible esums objects
bool save(const std::string &fileName)
saves the content of the template file to a local file (the content of parameterMap_ will not be save...
static const std::string stringConstantEsumsLow_
std::map< L1GtObject, std::string > caloType2Int_
converts L1GtObject to calo_nr
std::map< std::string, L1GtCondition * > ConditionMap
map containing the conditions
Definition: L1GtObject.h:36
std::map< std::string, L1GtAlgorithm > AlgorithmMap
map containing the algorithms
void writeDefValPkg(const std::vector< ConditionMap > &conditionMap, const int &chip)
writes def_val_pkg.vhd
std::map< L1GtConditionType, std::string > condType2Str_
converts L1GtConditionType to firmware string
static const std::string substParamJetsDefVals_
string templateFile
Definition: indexGen.py:50
bool getCaloSetupContentFromTriggerMenu(const unsigned short int &condChip, std::map< std::string, std::string > &caloParameters, const L1GtObject &caloObject)
L1GtVhdlWriterBitManager bm_
bit manager for bit operations
std::string getDefValsFromTriggerMenu(const L1GtConditionType &type, const L1GtObject &object, const VmeRegister &reg)
std::vector< std::string > getSubstitutionParametersFromTemplate() const
returns a vector with all substitution parameters that are found in the template file ...
std::string buildDeltaEtaCalo(const L1GtCaloTemplate::CorrelationParameter *&cp, const unsigned int &counter)
L1GtVhdlWriterCore(const std::string &templatesDirectory, const std::string &outputDirectory, const bool &debug)
constructor
static const std::string substParamDefValType_
#define NULL
Definition: scimark2.h:8
std::vector< L1GtObject > caloObjects_
list of all possible calo objects
const std::vector< L1GtObject > & objectType() const
get / set the trigger object type(s) in the condition
Definition: L1GtCondition.h:90
static const std::string substParamJetCntsCommon_
std::string index4CondChipVhd(int intval)
L1GtConditionType
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static const std::string stringConstantCommon_
std::vector< std::vector< std::string > > numberOfConditions_
vector containing the initialization of all conditions
bool getIntVal(const std::map< std::string, int > &map, const std::string &searchValue, int &intVal)
checks weather value searchValue exists in a &lt;string,int&gt; map, saves it in &amp;intVal if it exists and r...
static std::string int2str(const int &integerValue)
converts a integer into a string
bool returnConditionsOfOneClass(const L1GtConditionType &type, const L1GtConditionCategory &category, const L1GtObject &object, const ConditionMap &map, ConditionMap &outputMap)
bool getEsumsSetupContentFromTriggerMenu(const unsigned short int &condChip, const L1GtObject &object, std::string &energySumParameter)
contains only one subsitution parameter which is stored in reference energySumParameter ...
bool removeLineWithContent(const std::string &str)
removes all lines that contain the str
L1GtConditionCategory getCategoryFromObject(const L1GtObject &object)
gets condition category from object
static const std::string substParamAlgos_
static const std::string vhdlTemplateCondChipPkg2_
def chmod
Definition: eostools.py:293
else
Definition: XrdSource.cc:104
std::string buildDeltaPhiCalo(const L1GtCaloTemplate::CorrelationParameter *&cp, const unsigned int &counter)
const AlgorithmMap * algorithmMap_
algorithm map
Definition: L1GtObject.h:38
~L1GtVhdlWriterCore()
destructor
static const std::string stringConstantCharge4s_
std::vector< std::string > getMsgBuf()
returns intern message buffer
static const std::string stringConstantAlgo_
void writeEtmSetup(std::string &etmString, const int &condChip)
builds etm setup files
static const std::string stringConstantEsumsHigh_
bool makeFirmware(const std::vector< ConditionMap > &conditionMap, const AlgorithmMap &algorithmMap)
produces the firmware code
const std::vector< ObjectParameter > * objectParameter() const
std::string buildPhiCalo(const std::vector< L1GtCaloTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
const std::vector< ObjectParameter > * objectParameter() const
static const std::string substParamType_
void writeCond2intMap2File()
produces a control output file for condition to integer conversion
bool getSubstParamCommonFromTriggerMenu(const unsigned short int &condChip, L1GtVhdlTemplateFile &particle, const L1GtObject &object, const L1GtConditionCategory &category, std::string &parameterStr)
builds the parameters particle_common for the cond_chip.vhd&#39;s
void printCommonHeader()
prints the common header
static const std::string vhdlTemplateCaloSetup_
L1GtVhdlTemplateFile commonHeader_
common header for all files
const L1GtConditionType & condType() const
get / set the type of the condition (1s, etc)
Definition: L1GtCondition.h:79
tuple result
Definition: query.py:137
void append(const std::string &str)
adds a line at the end of the the file with the content of str
static const std::string substParamDefValId_
const std::vector< ObjectParameter > * objectParameter() const
L1GtConditionCategory
condition categories
std::string buildDeltaPhiMuon(const L1GtMuonTemplate::CorrelationParameter *&cp, const unsigned int &counter)
typedef for correlation parameters
std::string getInternalParameter(const std::string &indentifier)
returns a parameter of a internal template file
bool insert(const std::string &atLine, const std::vector< std::string > &content)
replaces the whole line containing atLine and inserts content instead of it
void writeCondChipPkg(const int &chip)
static const std::string vhdlTemplateEtmSetup_
static const std::string stringConstantCharge3s_
static const std::string vhdlTemplateMuonSetup_
L1GtVhdlTemplateFile retrunCommonHeader()
returns the common header
static const std::string vhdlTemplateCondChipPkg1_
void countCondsAndAdd2NumberVec(const L1GtConditionType &type, const L1GtConditionCategory &category, const L1GtObject &object, const ConditionMap &map, ConditionMap &outputMap, const int &condChip)
const std::vector< ConditionMap > * conditionMap_
condition map
std::string retNumberOfConditionsString(const std::string &typeStr, const int &number)
std::string gtTemplatesPath()
returns the templates path
std::string buildDeltaEtaMuon(const L1GtMuonTemplate::CorrelationParameter *&cp, const unsigned int &counter)
static const std::string quartusSetupFileChip1_
static const std::string outputSubDir1_
#define debug
Definition: HDRShower.cc:19
void getMuonSetupContentFromTriggerMenu(const unsigned short int &condChip, std::map< std::string, std::string > &muonParameters)
void msg(const std::string &message)
adds a string to intern message buffer
Definition: L1GtObject.h:30
static const std::string stringConstantCalo_
std::vector< std::string > internMessageBuf_
static const std::string outputSubDir2_
std::string outputDir_
output directory
static const std::string stringConstantPth_
bool getCondChipVhdContentFromTriggerMenu(const unsigned short int &condChip, std::map< std::string, L1GtVhdlTemplateFile > &templates, std::map< std::string, std::string > &commonParams)
void writeConditionChipSetup(const std::map< std::string, L1GtVhdlTemplateFile > &templates, const std::map< std::string, std::string > &common, const unsigned short int &chip)
builds cond_chip.vhds
static const std::string substParamContent_
static const std::string substParamParticle_
std::map< std::string, int > getCond2IntMap()
list object
Definition: dbtoconf.py:77
const CorrelationParameter * correlationParameter() const
std::string chip2OutputSubDir(const int &chip)
def mkdir
Definition: eostools.py:250
std::string buildDefValString(const int &conditionIndex, const std::vector< int > &values)
Definition: L1GtObject.h:37
static const std::string stringConstantPtl_
static const std::string substParamOthers_
static const std::string vhdlTemplateDefValPkg_
static std::atomic< unsigned int > counter
void addJetCountsToCond2IntMap(const int chip, const std::vector< ConditionMap > &conditionMap, std::map< std::string, int > &conditionToIntegerMap)
static const std::string substParamCaloOrMuon_
L1GtVhdlTemplateFile openVhdlFileWithCommonHeader(const std::string &filename, const std::string &outputFilename)
opens a new template file and inserts the common header
void writeMuonSetupVhdl(std::map< std::string, std::string > &muonParameters, const std::string &particle, unsigned short int &condChip)
builds muon setup files
tuple filename
Definition: lut2db_cfg.py:20
std::string buildPhiEnergySum(const std::vector< L1GtEnergySumTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
std::map< std::string, int > conditionToIntegerMap_
stores to condition name to integer conversion table
static const std::string stringConstantQuality_
static const std::string substParamMaxNr_
std::string buildEtaMuon(const std::vector< L1GtMuonTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter)
void printConditionsOfCategory(const L1GtConditionCategory &category, const ConditionMap &map)
for debuggin
bool findObjectType(const L1GtObject &object, ConditionMap &map)
std::string buildPhiMuon(const std::vector< L1GtMuonTemplate::ObjectParameter > *op, const unsigned int &num, const unsigned int &counter, bool high)
static const std::string stringConstantCharge1s_
const std::vector< ObjectParameter > * objectParameter() const
const std::map< L1GtObject, std::string > getObj2StrMap()
void buildCommonHeader(std::map< std::string, std::string > &headerParameters, const std::vector< std::string > &connectedChannels)
builds the common header for all files
tuple status
Definition: ntuplemaker.py:245
void writeAlgoSetup(std::vector< std::map< int, std::string > > &algoStrings)
builds the prealgo_and_or setup
static const std::string substParamCharge_
static const std::string stringConstantConstantNr_
bool processAlgorithmMap(std::vector< std::map< int, std::string > > &algoStrings)
bool removeEmptyLines()
deletes all empty lines in a template file
std::map< L1GtObject, std::string > objType2Str_
converts L1GtObject to string
static const std::string vhdlTemplateCondChip_
bool buildDefValuesBuffer(L1GtVhdlTemplateFile &buffer, const std::map< L1GtConditionType, std::string > &typeList, const std::vector< std::string > &defValuesList, const L1GtObject &object)
tuple size
Write out results.
bool open(const std::string &fileName, bool internal=false)
opens a template file. If the header information shall be parsed intern has to be set to true ...
bool debugMode_
class will produce some additional debugging output if set
static const std::string stringConstantCharge2s_
std::map< std::string, std::string > returnParameterMap() const
returns parameter map
void getConditionsFromAlgo(std::string condString, std::vector< std::string > &result) const
extracts all conditions from a algorithm
void print() const
prints the content of the VHDL File (only lines_)
static const std::string substParamEsumsDefVals_
const std::map< L1GtObject, std::string > getCalo2IntMap()