|
def | __init__ (self, tabsize=4, **args) |
|
def | convertFile (self, inputfilename, jsonfilename=None) |
|
def | parseXMLFile (self, filename) |
|
def | loadRules (self, docname) |
|
def | renameKey (self, key) |
|
def | createJsonStruct (self, node) |
|
def | writeJsonFile (self, filename=None) |
|
def | checkJsonConformity (self, filename) |
|
Definition at line 6 of file MenuXML2JSONConverter.py.
◆ __init__()
def python.MenuXML2JSONConverter.XML2JsonConverter.__init__ |
( |
|
self, |
|
|
|
tabsize = 4 , |
|
|
** |
args |
|
) |
| |
◆ checkJsonConformity()
def python.MenuXML2JSONConverter.XML2JsonConverter.checkJsonConformity |
( |
|
self, |
|
|
|
filename |
|
) |
| |
Definition at line 203 of file MenuXML2JSONConverter.py.
203 def checkJsonConformity(self, filename):
204 print(
"Checking json conformity", end=
' ')
206 FH =
open(filename,
"rb")
210 except ValueError
as e:
◆ convertFile()
def python.MenuXML2JSONConverter.XML2JsonConverter.convertFile |
( |
|
self, |
|
|
|
inputfilename, |
|
|
|
jsonfilename = None |
|
) |
| |
Definition at line 16 of file MenuXML2JSONConverter.py.
16 def convertFile(self, inputfilename, jsonfilename = None ):
17 if not inputfilename.endswith(
".xml"):
18 print(
"judging by the suffix, %s is not an xml file" % inputfilename)
20 self.parseXMLFile( inputfilename )
21 self.writeJsonFile( jsonfilename )
◆ createJsonStruct()
def python.MenuXML2JSONConverter.XML2JsonConverter.createJsonStruct |
( |
|
self, |
|
|
|
node |
|
) |
| |
Definition at line 146 of file MenuXML2JSONConverter.py.
146 def createJsonStruct(self, node):
147 if node.tag
in self.rules[
'asArray']:
148 return [ {element.tag : self.createJsonStruct(element)}
for element
in node ]
151 from collections
import OrderedDict
155 for attr
in sorted(node.attrib.keys()):
156 if (node.tag, attr)
in self.rules[
'ignoreAttrib']:
158 if node.tag
in self.rules[
'asInt']
and attr
in self.rules[
'asInt'][node.tag]:
159 d[self.renameKey(attr)] =
int(node.attrib[attr])
161 d[self.renameKey(attr)] = node.attrib[attr]
164 if element.tag
in self.rules[
'ignoreElement']:
166 if (node.tag, element.tag)
in self.rules[
'asMultiArray']:
168 key = self.renameKey(element.tag)
169 if key
not in d: d[key] =
list()
170 d[key] += [ self.createJsonStruct(element) ]
174 raise RuntimeError(
"element %s already attached to node %s and not declared as MultiArray" % (element.tag, node.tag))
176 if element.tag
in self.rules[
'promote']:
177 obj = self.createJsonStruct(element)
178 promoted = self.renameKey( self.rules[
'promote'][element.tag])
179 d[promoted] = obj[promoted]
181 d[self.renameKey(element.tag)] = self.createJsonStruct(element)
◆ loadRules()
def python.MenuXML2JSONConverter.XML2JsonConverter.loadRules |
( |
|
self, |
|
|
|
docname |
|
) |
| |
Definition at line 31 of file MenuXML2JSONConverter.py.
31 def loadRules(self,docname):
32 self.rules = {
'asInt' : {},
41 if docname ==
"LVL1Config":
42 self.rules[
'asInt'] = {
43 "TriggerItem" : [
"partition",
"complex_deadtime",
"ctpid"],
44 "TriggerThreshold" : [
"bitnum",
"mapping",
"version",
"active",
"id"],
45 "TriggerThresholdValue" : [
"thresholdval",
"etamin",
"etamax",
"phimin",
"phimax",
46 "em_isolation",
"window",
"priority",
"had_veto",
"had_isolation"],
47 "Signal" : [
"range_end",
"range_begin" ],
48 "Random" : [
"cut0",
"cut1",
"cut2",
"cut3"],
49 "PrescaleSet" : [
"menuPartition"],
50 "Prescale" : [
"ctpid"],
51 "TriggerCondition" : [
"multi"],
52 "METSignificance" : [
"xeMax",
"teSqrtMax",
"xsSigmaOffset",
"teSqrtMin",
"xsSigmaScale",
"xeMin"],
53 "MinimumTOBPt" : [
"priority",
"etamin",
"ptmin",
"etamax",
"window" ],
54 "Parametrization" : [
"slope",
"isobit",
"priority",
"etamin",
"offset",
"mincut",
"etamax",
"upperlimit"],
55 "CaloInfo" : [
"global_em_scale",
"global_jet_scale"],
56 "BunchGroupSet" : [
"menuPartition" ],
57 "BunchGroup" : [
"internalNumber" ],
58 "MuctpiInfo" : [
"high_pt",
"max_cand",
"low_pt" ],
59 "PrescaledClock" : [
"clock1",
"clock2" ],
60 "LVL1Config" : [
"l1Version",
"ctpVersion" ]
62 self.rules[
'asArray'] = [
'AND',
'OR' ]
63 self.rules[
'asMultiArray'] = [ (
'PrescaleSet',
'Prescale'),
64 (
'TriggerThreshold',
'TriggerThresholdValue'),
65 (
'TriggerCounterList',
'TriggerCounter'),
66 (
'Isolation',
'Parametrization'),
67 (
'TriggerMenu',
'TriggerItem'),
68 (
'CaloInfo',
'MinimumTOBPt'),
69 (
'CaloInfo',
'Isolation'),
70 (
'BunchGroupSet',
'BunchGroup'),
71 (
'OR',
'TriggerCondition'),
72 (
'TriggerThresholdList',
'TriggerThreshold'),
73 (
'AND',
'TriggerCondition'),
75 (
'AND',
'InternalTrigger')
77 self.rules[
'ignoreElement'] = []
78 self.rules[
'promote'] = {
"TriggerThresholdList" :
"TriggerThreshold"}
79 self.rules[
'rename'] = {
"TriggerItem" :
"items",
"TriggerMenu" :
"menu",
"l1Version" :
"version",
"ctpid" :
"ctpId",
80 "complex_deadtime" :
"complexDeadtime",
"trigger_type" :
"triggerType",
"TriggerThreshold" :
"thresholds",
81 "triggerthreshold" :
"triggerThreshold",
"TriggerCondition" :
"triggerCondition",
"InternalTrigger" :
"internalTrigger",
82 "Cable" :
"cable",
"Signal" :
"signal",
"range_begin" :
"rangeBegin",
"range_end" :
"rangeEnd",
83 "TriggerThresholdValue" :
"thresholdValues" }
85 elif docname ==
"HLT_MENU":
87 self.rules[
'asInt'] = {
88 "CHAIN": [
"EBstep",
"chain_counter"],
89 "SIGNATURE": [
"signature_counter"]
91 self.rules[
'asMultiArray'] = [ (
'SEQUENCE_LIST',
'SEQUENCE'),
92 (
'GROUP_LIST',
'GROUP'),
93 (
'SIGNATURE_LIST',
'SIGNATURE'),
94 (
'CHAIN_LIST',
'CHAIN'),
95 (
'STREAMTAG_LIST',
'STREAMTAG'),
96 (
'SIGNATURE',
'TRIGGERELEMENT')
98 self.rules[
'ignoreElement'] = [
"SEQUENCE_LIST",
"SIGNATURE_LIST",
"TRIGGERTYPE_LIST" ]
99 self.rules[
'ignoreAttrib'] = [ (
"CHAIN",
"level"),
101 (
"CHAIN",
"pass_through"),
102 (
"CHAIN",
"prescale"),
103 (
"CHAIN",
"rerun_prescale"),
104 (
"HLT_MENU",
"prescale_set_name")]
105 self.rules[
'promote'] = {
"GROUP_LIST" :
"GROUP",
"STREAMTAG_LIST" :
"STREAMTAG",
"CHAIN_LIST" :
"CHAIN"}
106 self.rules[
'rename'] = {
"GROUP" :
"groups",
"STREAMTAG" :
"streams",
"CHAIN" :
"chains",
107 "menu_name" :
"name",
108 "chain_name" :
"name",
"chain_counter" :
"counter",
"lower_chain_name" :
"l1item",
111 elif docname ==
"TOPO_MENU":
113 self.rules[
'asInt'] = {
114 "Parameter": [
"pos",
"value"],
115 "Bit": [
"selection"],
116 "Input": [
"position"],
117 "Output": [
"bits",
"fpga",
"clock",
"algoId",
"module",
"firstbit"],
118 "SortAlgo": [
"algoId"],
119 "DecisionAlgo": [
"algoId"],
121 self.rules[
'asMultiArray'] = [ (
'OutputList',
'Output'),
122 (
'Fixed',
'Generic'),
124 (
'TOPO_MENU',
'SortAlgo'),
125 (
'TOPO_MENU',
'DecisionAlgo'),
126 (
'Variable',
'Parameter'),
128 (
'SIGNATURE',
'TRIGGERELEMENT')
130 self.rules[
'promote'] = {
"OutputList" :
"Output" }
131 self.rules[
'rename'] = {
"menu_name" :
"name",
"menu_version" :
"version",
132 "algname" :
"algName",
"algoId" :
"algId",
"firstbit" :
"firstBit",
"module" :
"board",
"triggerline" :
"triggerLines",
133 "SortAlgo" :
"sortingAlgorithms",
"DecisionAlgo" :
"decisionAlgorithms",
134 "Fixed" :
"fixedParameters",
"Input" :
"inputs",
"Output" :
"outputs",
"Generic" :
"generics",
135 "Variable" :
"variableParameters",
"Parameter" :
"parameters"}
137 print(
"Unknown document with root element %s" % docname)
◆ parseXMLFile()
def python.MenuXML2JSONConverter.XML2JsonConverter.parseXMLFile |
( |
|
self, |
|
|
|
filename |
|
) |
| |
Definition at line 23 of file MenuXML2JSONConverter.py.
23 def parseXMLFile(self,filename):
24 self.xmlfilename = filename
25 import xml.etree.cElementTree
as ET
26 self.doc = ET.parse(filename)
27 self.root = self.doc.getroot()
28 print(
"Parsed file %s" % filename)
◆ renameKey()
def python.MenuXML2JSONConverter.XML2JsonConverter.renameKey |
( |
|
self, |
|
|
|
key |
|
) |
| |
Definition at line 142 of file MenuXML2JSONConverter.py.
142 def renameKey(self,key):
143 return self.rules[
'rename'][key]
if key
in self.rules[
'rename']
else key
◆ writeJsonFile()
def python.MenuXML2JSONConverter.XML2JsonConverter.writeJsonFile |
( |
|
self, |
|
|
|
filename = None |
|
) |
| |
Definition at line 187 of file MenuXML2JSONConverter.py.
187 def writeJsonFile(self, filename = None):
191 filename = self.xmlfilename.rstrip(
".xml")+
".json"
192 elif os.path.isdir(filename):
193 filename = filename.rstrip(
"/") +
"/" + self.xmlfilename.
split(
"/")[-1].rstrip(
".xml")+
".json"
194 self.loadRules(self.root.tag)
195 d = self.createJsonStruct(self.root)
196 FH =
open(filename,
"w")
197 json.dump(d, FH, indent=self.tabsize, separators=(
',',
': '))
199 print(
"Wrote file %s" % filename)
◆ __doc
python.MenuXML2JSONConverter.XML2JsonConverter.__doc |
|
private |
◆ __root
python.MenuXML2JSONConverter.XML2JsonConverter.__root |
|
private |
◆ __rules
python.MenuXML2JSONConverter.XML2JsonConverter.__rules |
|
private |
◆ doc
python.MenuXML2JSONConverter.XML2JsonConverter.doc |
◆ root
python.MenuXML2JSONConverter.XML2JsonConverter.root |
◆ rules
python.MenuXML2JSONConverter.XML2JsonConverter.rules |
◆ tabsize
python.MenuXML2JSONConverter.XML2JsonConverter.tabsize |
◆ xmlfilename
python.MenuXML2JSONConverter.XML2JsonConverter.xmlfilename |
The documentation for this class was generated from the following file: