CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtVmeWriterCore.cc
Go to the documentation of this file.
1 
19 // this class header
21 
22 // system include files
23 #include <iostream>
24 #include <sstream>
25 #include <bitset>
26 
27 // user include files
28 // base class
34 
39 
40 // constructor
42  const std::string& vmeXmlFile) :
43  m_outputDir(outputDir), m_vmeXmlFile(vmeXmlFile)
44 {
45 
46  object2reg_[Mu]=0x00A0000;
47  object2reg_[NoIsoEG]=0x0020000;
48  object2reg_[IsoEG]=0x0000000;
49  object2reg_[ForJet]=0x0080000;
50  object2reg_[TauJet]=0x0060000;
51  object2reg_[CenJet]=0x0040000;
52  object2reg_[HTT]=0x0100000;
53  object2reg_[ETT]=0x0100000;
54  object2reg_[ETM]=0x0100000;
55 
56  type2reg_[Type1s]=0x000C000;
57  type2reg_[Type2s]=0x0004000;
58  type2reg_[Type2wsc]=0x0008000;
59  type2reg_[Type3s]=0x0010000;
60  type2reg_[Type4s]=0x0000000;
61  type2reg_[TypeETM]=0x0004000;
62  type2reg_[TypeETT]=0x0000000;
63  type2reg_[TypeHTT]=0x0008000;
64 
65  reg2hex_[m_xmlTagEtThreshold+"_1"]=0x0000000;
66  reg2hex_[m_xmlTagEtThreshold+"_2"]=0x0000002;
67  reg2hex_[m_xmlTagEtThreshold+"_3"]=0x0000004;
68  reg2hex_[m_xmlTagEtThreshold+"_4"]=0x0000006;
69  reg2hex_[m_xmlTagPtHighThreshold+"_1"]=0x0000000;
70  reg2hex_[m_xmlTagPtHighThreshold+"_2"]=0x0000002;
71  reg2hex_[m_xmlTagPtHighThreshold+"_3"]=0x0000004;
72  reg2hex_[m_xmlTagPtHighThreshold+"_4"]=0x0000006;
73  reg2hex_[m_xmlTagQuality+"_1"]=0x0000050;
74  reg2hex_[m_xmlTagQuality+"_2"]=0x0000052;
75  reg2hex_[m_xmlTagQuality+"_3"]=0x0000054;
76  reg2hex_[m_xmlTagQuality+"_4"]=0x0000056;
77  reg2hex_[m_xmlTagPtLowThreshold+"_1"]=0x0000058;
78  reg2hex_[m_xmlTagPtLowThreshold+"_2"]=0x000005A;
79  reg2hex_[m_xmlTagPtLowThreshold+"_3"]=0x000005C;
80  reg2hex_[m_xmlTagPtLowThreshold+"_4"]=0x000005E;
82  reg2hex_["jet_cnt_threshold"]=0x0000000;
83  reg2hex_["threshold_lsb"]=0x0000000;
84  reg2hex_["threshold_msb"]=0x0000002;
85 
86  // sepcial maps for jet counts
87  jetType2reg_[0]=0x0000000;
88  jetType2reg_[1]=0x0004000;
89  jetType2reg_[2]=0x0008000;
90  jetType2reg_[3]=0x000C000;
91  jetType2reg_[4]=0x0010000;
92  jetType2reg_[5]=0x0014000;
93 
94  jetObj2reg_[0]=0x00C0000;
95  jetObj2reg_[1]=0x00E0000;
96 
97  spacesPerLevel_ = 2;
98 
99 }
100 
101 // destructor
103 {
104 
105  // empty now
106 
107 }
108 
109 int L1GtVmeWriterCore::condIndex2reg(const unsigned int &index)
110 {
111  int indexcp = index;
112 
113  return (indexcp << 8);
114 
115 }
116 
117 std::string L1GtVmeWriterCore::calculateJetsAddress(const int &countIndex,
118  const int &obj, const int &index)
119 {
120  int result = jetType2reg_[countIndex] + jetObj2reg_[obj]
121  + reg2hex_["jet_cnt_threshold"] +condIndex2reg(index);
122 
123  std::bitset<24> bs(result);
124 
125  std::ostringstream buffer;
126  buffer<<bs;
127 
128  return buffer.str();
129 }
130 
132  const L1GtConditionType &type, const std::string &reg, const int &index)
133 {
134 
136  +condIndex2reg(index);
137 
138  std::bitset<25> bs(result);
139 
140  std::ostringstream buffer;
141  buffer<<bs;
142  return buffer.str();
143 
144 }
145 
146 // destructor
147 std::string L1GtVmeWriterCore::openTag(const std::string &tag)
148 {
149  return "<"+tag+">\n";
150 }
151 
152 std::string L1GtVmeWriterCore::closeTag(const std::string &tag)
153 {
154  return "</"+tag+">\n";
155 }
156 
157 std::string L1GtVmeWriterCore::vmeAddrValueBlock(const std::string &addr,
158  const int &val, const int &spaceLevel, const bool setMsb)
159 {
160  std::ostringstream buffer;
161 
162  std::bitset<8> bsVal(val);
163 
164  if (setMsb)
165  bsVal.set(7);
166 
167  buffer << spaces(spaceLevel) << openTag(m_xmlTagVmeAddress)
168  << spaces(spaceLevel+1) << addr << std::endl
169  << spaces(spaceLevel+1) << openTag(m_xmlTagValue)
170  << spaces(spaceLevel+1) << bsVal <<std::endl
171  << spaces(spaceLevel+1) << closeTag(m_xmlTagValue)
172  << spaces(spaceLevel) << closeTag(m_xmlTagVmeAddress);
173 
174  return buffer.str();
175 
176 }
177 
178 std::string L1GtVmeWriterCore::spaces(const unsigned int &level)
179 {
180  std::ostringstream buffer;
181 
182  for (unsigned int i=0; i<(level*spacesPerLevel_); i++)
183  {
184  buffer<<" ";
185  }
186 
187  return buffer.str();
188 
189 }
190 
191 void L1GtVmeWriterCore::writeVME(const std::vector<ConditionMap> &conditionMap,
192  std::map<std::string,int> cond2intMap, L1GtVhdlTemplateFile header, const int spacesPerLevel)
193 {
194 
195  L1GtVhdlDefinitions maps;
196 
197  // define appearance
198  spacesPerLevel_ = spacesPerLevel;
199 
200  std::string fileName = m_outputDir+m_vmeXmlFile;
201 
202  // open output file
203  std::ofstream outputFile(fileName.c_str());
204 
205  // begin of VME XML
206  outputFile << "<" << m_xmlTagVme << ">" << std::endl;
207 
208  // insert header
210  header.substitute("vhdl_file_name", m_vmeXmlFile);
211  header.removeEmptyLines();
212 
213  std::vector<std::string> lines = header.returnLines();
214 
215  for (unsigned int i = 0; i< lines.size(); i++)
216  {
217  outputFile << spaces(2)<<lines.at(i);
218  //if (i!=lines.size()-1)
219  outputFile<<std::endl;
220  }
221 
223 
224  // loop over chips
225  for (unsigned int index=1; index<=2; index++)
226  {
227  outputFile << spaces(1) <<"<" << m_xmlTagChip << index <<">"
228  << std::endl;
229 
230  // loop over condition map
231  for (ConditionMap::const_iterator iterCond = conditionMap.at(index-1).begin(); iterCond != conditionMap.at(index-1).end(); iterCond++)
232  {
233 
234  // open a condition
235  outputFile << spaces(2) << "<" << iterCond->first << " "
236  << m_xmlConditionAttrObject <<"=\"" << maps.obj2str((iterCond->second->objectType())[0])<<"\" " <<m_xmlConditionAttrType <<"=\""
237  << maps.type2str(iterCond->second->condType())<< "\">"
238  <<std::endl;
239 
240  switch ((iterCond->second)->condCategory())
241  {
242 
243  case CondMuon:
244  {
245 
246  L1GtMuonTemplate* muonTemplate =
247  static_cast<L1GtMuonTemplate*>(iterCond->second);
248  const std::vector<L1GtMuonTemplate::ObjectParameter>* op =
249  muonTemplate->objectParameter();
250 
251  // get the number of objects
252  unsigned int nObjects = iterCond->second->nrObjects();
253 
254  for (unsigned int i =0; i<nObjects; i++)
255  {
256 
257  std::string opi = L1GtVhdlWriterCore::int2str(i);
258 
259  // ptHighTreshold
260  std::string address = calculateAddress(Mu, (iterCond->second)->condType(),
261  (m_xmlTagPtHighThreshold+"_"+opi),
262  cond2intMap[iterCond->first]);
263 
265  <<vmeAddrValueBlock(address, (*op).at(i).ptHighThreshold, 4,iterCond->second->condGEq()) << spaces(3)
267 
268  // ptLow Threshold
269  address = calculateAddress(Mu, (iterCond->second)->condType(),
270  (m_xmlTagPtLowThreshold+"_"+opi),
271  cond2intMap[iterCond->first]);
272 
274  <<vmeAddrValueBlock(address, (*op).at(i).ptLowThreshold, 4, iterCond->second->condGEq()) << spaces(3)
276 
277  // Quality
278  address = calculateAddress(Mu, (iterCond->second)->condType(), (m_xmlTagQuality+"_"
279  +opi), cond2intMap[iterCond->first]);
280 
282  << vmeAddrValueBlock(address, (*op).at(i).qualityRange, 4) << spaces(3)
284 
285  }
286 
288  muonTemplate->correlationParameter();
289 
290  // Charage correlation - occurs only one time
292 
293  std::string address = calculateAddress(Mu, (iterCond->second)->condType(),
295  cond2intMap[iterCond->first]);
296 
297  outputFile << vmeAddrValueBlock(address, (*cp).chargeCorrelation, 4) << spaces(3)
299 
300  }
301  break;
302 
303  case CondCalo:
304  {
305 
306  L1GtCaloTemplate* m_gtCaloTemplate =
307  static_cast<L1GtCaloTemplate*>(iterCond->second);
308  const std::vector<L1GtCaloTemplate::ObjectParameter>* op =
309  m_gtCaloTemplate->objectParameter();
310 
311  // get the number of objects
312  unsigned int nObjects = iterCond->second->nrObjects();
313 
314  for (unsigned int i =0; i<nObjects; i++)
315  {
316 
317  std::string opi = L1GtVhdlWriterCore::int2str(i);
318  std::string address = calculateAddress((iterCond->second->objectType()).at(0), (iterCond->second)->condType(),
319  (m_xmlTagPtHighThreshold+"_"+opi),
320  cond2intMap[iterCond->first]);
321 
322  // insert Address/Value Tag
323  outputFile<<vmeAddrValueBlock(address, (*op).at(i).etThreshold, 3, iterCond->second->condGEq());
324 
325  }
326 
327  }
328  break;
329 
330  case CondEnergySum:
331  {
332 
333  L1GtEnergySumTemplate* energySumTempl =
334  static_cast<L1GtEnergySumTemplate*>(iterCond->second);
335 
336  const std::vector<L1GtEnergySumTemplate::ObjectParameter>* op =
337  energySumTempl->objectParameter();
338 
339  // get the number of objects
340  unsigned int nObjects = iterCond->second->nrObjects();
341 
342  for (unsigned int i =0; i<nObjects; i++)
343  {
344 
345  std::string opi = L1GtVhdlWriterCore::int2str(i);
346 
347  std::string address = calculateAddress((iterCond->second->objectType()).at(0), (iterCond->second)->condType(),
348  (m_xmlTagPtHighThreshold+"_"+opi),
349  cond2intMap[iterCond->first]);
350 
351  // insert Address/Value Tag
352  outputFile<<vmeAddrValueBlock(address, (*op).at(i).etThreshold, 3,iterCond->second->condGEq());
353 
354  }
355 
356  }
357 
358  break;
359 
360  case CondJetCounts:
361  {
362 
363  L1GtJetCountsTemplate* jetsTemplate =
364  static_cast<L1GtJetCountsTemplate*>(iterCond->second);
365  const std::vector<L1GtJetCountsTemplate::ObjectParameter>* op =
366  jetsTemplate->objectParameter();
367 
368  // get the number of objects
369  // unsigned int nObjects = iterCond->second->nrObjects();
370 
371  // count index
372  int ci = (*op)[0].countIndex;
373 
374  // 0 for count index 0-5 and 1 for count index 6 - 11
375  int obj;
376 
377  if (ci<=5)
378  obj=0;
379  else
380  obj=1;
381 
382  std::string address = calculateJetsAddress(ci, obj,
383  cond2intMap[iterCond->first]);
384 
385  outputFile<<vmeAddrValueBlock(address, (*op).at(0).countThreshold, 3, iterCond->second->condGEq());
386 
387  }
388  break;
389  case CondCorrelation:
390  {
391  // empty
392  }
393  break;
394 
395  case CondNull:
396  {
397  // empty
398  }
399  break;
400 
401  default:
402  {
403  // empty
404  }
405  break;
406 
407  }
408 
409  // close the condition
410  outputFile << spaces(2)<< closeTag(iterCond->first);
411 
412  }
413 
414  outputFile << spaces(1) << "</" << m_xmlTagChip << index<<">"
415  <<std::endl;
416 
417  }
418 
419  // end of vme XML
421 
422  // close output file
423  outputFile.close();
424 
425  std::cout << std::endl <<"******* VME XML File: "<< m_outputDir
426  << m_vmeXmlFile << " written sucessfully! *******"<<std::endl;
427 
428 }
type
Definition: HCALResponse.h:22
std::string obj2str(const L1GtObject &type)
converts object type to firmware string
int i
Definition: DBlmapReader.cc:9
std::map< L1GtConditionType, int > type2reg_
std::string type2str(const L1GtConditionType &type)
converts a condition type to firmware string
char * address
Definition: mlp_lapack.h:14
bool substitute(const std::string &searchString, const std::string &replaceString)
replaces searchString with replaceString
const CorrelationParameter * correlationParameter() const
std::string m_outputDir
output directory
L1GtVmeWriterCore(const std::string &outputDir, const std::string &vmeXmlFile)
constructor
static const std::string m_xmlTagHeader
Definition: L1GtObject.h:38
static const std::string m_xmlConditionAttrObject
virtual ~L1GtVmeWriterCore()
destructor
static const std::string m_xmlTagEtThreshold
static const std::string m_xmlTagVmeAddress
static const std::string m_xmlConditionAttrType
static const std::string m_xmlTagVme
L1GtConditionType
static std::string int2str(const int &integerValue)
converts a integer into a string
Definition: L1GtObject.h:40
std::map< int, int > jetObj2reg_
static const std::string m_xmlTagChargeCorrelation
void writeVME(const std::vector< ConditionMap > &conditionMap, std::map< std::string, int > cond2intMap, L1GtVhdlTemplateFile header, const int spacesPerLevel=2)
const std::vector< ObjectParameter > * objectParameter() const
const std::vector< ObjectParameter > * objectParameter() const
tuple result
Definition: query.py:137
const std::vector< ObjectParameter > * objectParameter() const
std::vector< std::string > returnLines()
returns a string vector with the current content of the VHDL File
static const std::string m_xmlTagPtHighThreshold
std::string m_vmeXmlFile
output file
std::string closeTag(const std::string &tag)
closes xml tag
std::string calculateJetsAddress(const int &countIndex, const int &obj, const int &index)
calculates addresses for jets counts
std::map< int, int > jetType2reg_
std::string openTag(const std::string &tag)
opens a new xml tag
static const std::string m_xmlTagPtLowThreshold
Definition: L1GtObject.h:32
std::map< std::string, int > reg2hex_
std::string spaces(const unsigned int &level)
returns a string containing spaces dependant on level
Definition: L1GtObject.h:39
std::map< L1GtObject, int > object2reg_
int condIndex2reg(const unsigned int &index)
static const std::string m_xmlTagChip
tuple cout
Definition: gather_cfg.py:121
const std::vector< ObjectParameter > * objectParameter() const
static const std::string m_xmlTagQuality
tuple level
Definition: testEve_cfg.py:34
std::string vmeAddrValueBlock(const std::string &addr, const int &val, const int &spaceLevel, const bool setMsb=false)
builds a address value block
static const std::string m_xmlTagValue
bool removeEmptyLines()
deletes all empty lines in a template file
std::string calculateAddress(const L1GtObject &obj, const L1GtConditionType &type, const std::string &reg, const int &index)
calculates address
list at
Definition: asciidump.py:428