120 cppBaseStartstring =
"/*\n*This file was automatically created by XMLtoHeader.py\n* Created on: {creationTime}\n* Created with config: {xmlFile}\n*\n* Author: Ruth Poettgen\n* Contact: ruth.poettgen@cern.ch\n**Brief: Defines class for different CTP versions.\n*/\n\n\n#include <inttypes.h>\n#include <assert.h>\n#include <iostream>\n#include <stdlib.h>\n#include <map>\n#include <iomanip>\n#include <sstream>\n\n"
121 start = cppBaseStartstring.format(creationTime = time, xmlFile = inputXMLname)
123 baseNameRoot = os.path.basename(outputNames)
124 baseName = baseNameRoot +
'Version'
125 fileName = outputNames +
'Version'
126 baseHeader =
open(fileName+
'.h',
'w')
127 baseHeader.write(start)
130 baseHeader.write(
'#ifndef '+baseName.upper() +
'_H\n')
131 baseHeader.write(
'#define '+baseName.upper() +
'_H\n')
132 baseHeader.write(
'\nclass '+baseName +
'{\n\n')
134 protectedString =
"\nprotected:\n"
135 protectedString +=
" //---------------------------------------------------------------------------------------------------\n"
136 protectedString +=
" // For explanation of the variables and there values in different versions see config XML file.\n"
137 protectedString +=
" //---------------------------------------------------------------------------------------------------\n"
141 publicString =
"\npublic: \n"
142 publicString +=
'\n ' + baseName +
'(unsigned int version) {\n'
144 dumpString =
'\n std::string dump() const {\n';
145 dumpString +=
'\n std::ostringstream s;\n';
146 dumpString +=
'\n std::ostringstream tmp;\n\n';
147 dumpString +=
' s << \"For a description of the parameters for different CTP version, see schema/L1CoreSpecifications.xml in L1CommonCore.\" << std::endl;\n\n';
148 dumpString +=
' s << \"|-------------------------------------------------------------|\" << std::endl;\n';
149 dumpString +=
' s << \"| Name | Value |\" << std::endl;\n';
150 dumpString +=
' s << \"|-------------------------------------------------------------|\" << std::endl;\n';
156 changedValuesDict = {}
162 pyStartstring =
"#!/usr/bin/env python\n\n#This file was automatically created by XMLtoHeader.py\n# Created on: {creationTime}\n# Created with config: {xmlFile}\n# \n# Author: Ruth Poettgen\n# Contact: ruth.poettgen@cern.ch\n\n\n\nimport sys\n\nclass {classname}(object):\n def __init__(self):\n"
170 for v
in versionDict:
173 changedValuesDict[v] = []
175 pyStartstring = pyStartstring.format(creationTime = time,version = versionDict[v], xmlFile = inputXMLname, classname=baseNameRoot)
176 headerName = outputNames +
"_" + v +
".py"
177 pyHeader =
open(headerName,
'w')
178 pyHeader.write(pyStartstring)
191 childIndex=childIndex+1
194 if child.attrib[
'ns']
not in versionDict:
199 if child.find(
'name')
is None:
202 if child.find(
'type')
is None:
205 if child.find(
'value')
is None:
211 if child.find(
'name').text[1:-1]
in nameList:
227 while tmp_v
not in nameVersionsDict[child.find(
'name').text[1:-1]]:
230 tmp_v =
list(versionDict)[index-1]
236 if child.attrib[
'ns']!=tmp_v:
245 typeText = child.find(
'type').text
246 nameText = child.find(
'name').text[1:-1]
247 valueText = child.find(
'value').text
250 pyHeader.write(
' self.'+nameText.ljust(30)+
'= ')
252 if 'mult' in typeText:
258 pyHeader.write( (
'[ ' + valueText +
' ]').ljust(50) )
261 listOfElements = valueText.split(
',')
262 numberOfElements = len(listOfElements)
266 protectedString +=
' '
267 protectedString += typeDictCpp[typeText[0:-5]] +
' '
268 protectedString += (nameText+
'['+
str(numberOfElements) +
']').ljust(20)+
'='
269 protectedString +=
'{ ' + valueText +
'};'
272 functionString +=
'\n const '+typeDictCpp[typeText[0:-5]] +
'* get'
273 functionString += nameText +
'() const { return ' + nameText +
'; }'
276 dumpString +=
'\n s << \"|\" << std::left << std::setw(40) << \" ' + nameText +
'\" << \" | \";\n'
277 dumpString +=
' tmp.clear(); tmp.str(\"\");\n tmp<< \"[\";\n'
278 dumpString +=
' for (int i=0; i <' +
str(numberOfElements) +
'; i++) {\n'
279 dumpString +=
' if (i) tmp<<\",\";\n'
280 dumpString +=
' tmp << this->' + nameText +
'[i];\n }\n tmp<<\"]\";\n'
281 dumpString +=
' s << std::right << std::setw(17) << tmp.str() << \" | \" << std::endl;\n\n'
291 changedValuesDict[v].
append([nameText,valueText])
298 if (valueText)[0]
not in [
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9']:
300 pyHeader.write( (
'self.' + val.replace(
'+',
' + self.')).ljust(10))
302 pyHeader.write(valueText.ljust(10))
306 functionString +=
'\n '+typeDictCpp[typeText] +
' get'
307 functionString += nameText +
'() const { return ' + nameText +
'; }'
309 protectedString +=
' ' + typeDictCpp[typeText] +
' '
310 protectedString += nameText
311 protectedString +=
' = ' + valueText +
';'
313 dumpString +=
' s << \"|\" << std::left << std::setw(40) << \" ' + nameText +
'\" << \" | \";\n'
314 dumpString +=
' s << std::right << std::setw(17) << this->' + nameText +
' << \" | \" << std::endl;\n\n'
323 changedValuesDict[v].
append([nameText,valueText])
328 if child.find(
'comment')
is None:
332 pyHeader.write(
' # ' + child.find(
'comment').text[1:-1] +
'\n')
334 protectedString +=
'\n'
336 nameList.append(nameText)
345 pyHeader.write(
'\n\n' + baseNameRoot +
'_' + v +
' = ' + baseNameRoot +
'()'+
'\n\n' +
'del ' + baseNameRoot)
348 dumpString +=
' s << \"|-------------------------------------------------------------|\" << std::endl;\n\n';
350 dumpString +=
' return s.str();\n\n }'
352 nVersions = len(versionDict)
355 selection=
' if (version>=' +
str(nVersions)+
') {\n';
356 selection+=
' std::cerr << \"ERROR: invalid CTP version requested (\" << version << \"). Should be in [0,'+
str(nVersions-1)+
'].Setting it to the latest version ('+
str(nVersions-1)+
'). \" << std::endl;\n'
357 selection +=
' version='+
str(nVersions-1)+
';\n'
362 for v
in changedValuesDict:
363 selection +=
' if (version==' +
str(versionInt) +
' ) {\n'
364 for pair
in changedValuesDict[v]:
366 listOfValues = pair[1].
split(
',')
367 numValues = len(listOfElements)
370 for val
in listOfValues:
371 selection+=
' ' + pair[0] +
'[' +
str(valIndex) +
'] = ' + val +
';\n'
374 selection+=
' ' + pair[0] +
' = ' + pair[1] +
';\n'
376 selection +=
' }\n\n'
378 numberOfChanges = len(changedValuesDict)
381 baseHeader.write(protectedString+
'\n\n')
382 baseHeader.write(publicString +
'\n\n')
383 baseHeader.write(selection)
384 baseHeader.write(
' };\n\n')
385 baseHeader.write(functionString+
'\n\n')
386 baseHeader.write(dumpString+
'\n\n')
387 baseHeader.write(
'\n};\n\n')
388 baseHeader.write(
'#endif //' + baseName.upper() +
'_H')