Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (f31105fd)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GenerateGaudiOpts Namespace Reference

Classes

class  XmlDictObject
 

Functions

def generateOptions (counter, cmask, invmask, sampling_period, startatevent, storeresultsat, family)
 
def _ConvertDictToXmlRecurse (parent, dictitem)
 
def ConvertDictToXml (xmldict)
 
def _ConvertXmlToDictRecurse (node, dictclass)
 
def ConvertXmlToDict (root, dictclass=XmlDictObject)
 

Function Documentation

◆ _ConvertDictToXmlRecurse()

def GenerateGaudiOpts._ConvertDictToXmlRecurse (   parent,
  dictitem 
)
private

Definition at line 109 of file GenerateGaudiOpts.py.

109 def _ConvertDictToXmlRecurse(parent, dictitem):
110  assert not isinstance(dictitem, list)
111 
112  if isinstance(dictitem, dict):
113  for tag, child in dictitem.iteritems():
114  if str(tag) == "_text":
115  parent.text = str(child)
116  elif isinstance(child, list):
117  # iterate through the array and convert
118  for listchild in child:
119  elem = ElementTree.Element(tag)
120  parent.append(elem)
121  _ConvertDictToXmlRecurse(elem, listchild)
122  else:
123  elem = ElementTree.Element(tag)
124  parent.append(elem)
125  _ConvertDictToXmlRecurse(elem, child)
126  else:
127  parent.text = str(dictitem)
128 
129 

◆ _ConvertXmlToDictRecurse()

def GenerateGaudiOpts._ConvertXmlToDictRecurse (   node,
  dictclass 
)
private

Definition at line 141 of file GenerateGaudiOpts.py.

141 def _ConvertXmlToDictRecurse(node, dictclass):
142  nodedict = dictclass()
143 
144  if len(node.items()) > 0:
145  # if we have attributes, set them
146  nodedict.update(dict(node.items()))
147 
148  for child in node:
149  # recursively add the element's children
150  newitem = _ConvertXmlToDictRecurse(child, dictclass)
151  if child.tag in nodedict:
152  # found duplicate tag, force a list
153  if isinstance(nodedict[child.tag], list):
154  # append to existing list
155  nodedict[child.tag].append(newitem)
156  else:
157  # convert to list
158  nodedict[child.tag] = [nodedict[child.tag], newitem]
159  else:
160  # only one, directly set the dictionary
161  nodedict[child.tag] = newitem
162 
163  if node.text is None:
164  text = ""
165  else:
166  text = node.text.strip()
167 
168  if len(nodedict) > 0:
169  # if we have a dictionary add the text as a dictionary value (if there is any)
170  if len(text) > 0:
171  nodedict["_text"] = text
172  else:
173  # if we don't have child nodes or attributes, just set the text
174  nodedict = text
175 
176  return nodedict
177 
178 

◆ ConvertDictToXml()

def GenerateGaudiOpts.ConvertDictToXml (   xmldict)
Converts a dictionary to an XML ElementTree Element

Definition at line 130 of file GenerateGaudiOpts.py.

130 def ConvertDictToXml(xmldict):
131  """
132  Converts a dictionary to an XML ElementTree Element
133  """
134 
135  roottag = xmldict.keys()[0]
136  root = ElementTree.Element(roottag)
137  _ConvertDictToXmlRecurse(root, xmldict[roottag])
138  return root
139 
140 

◆ ConvertXmlToDict()

def GenerateGaudiOpts.ConvertXmlToDict (   root,
  dictclass = XmlDictObject 
)
Converts an XML file or ElementTree Element to a dictionary

Definition at line 179 of file GenerateGaudiOpts.py.

179 def ConvertXmlToDict(root, dictclass=XmlDictObject):
180  """
181  Converts an XML file or ElementTree Element to a dictionary
182  """
183 
184  # If a string is passed in, try to open it as a file
185  if isinstance(root, str):
186  root = ElementTree.parse(root).getroot()
187  elif not isinstance(root, ElementTree.Element):
188  raise TypeError("Expected ElementTree.Element or file path string")
189 
190  return dictclass({root.tag: _ConvertXmlToDictRecurse(root, dictclass)})

◆ generateOptions()

def GenerateGaudiOpts.generateOptions (   counter,
  cmask,
  invmask,
  sampling_period,
  startatevent,
  storeresultsat,
  family 
)

Definition at line 15 of file GenerateGaudiOpts.py.

15 def generateOptions(
16  counter, cmask, invmask, sampling_period, startatevent, storeresultsat, family
17 ):
18  cmask = map(int, cmask)
19  invmask = map(int, invmask)
20  sampling_period = map(int, sampling_period)
21  startatevent = int(startatevent)
22 
23  from Configurables import ApplicationMgr, AuditorSvc, PerfMonAuditor
24 
25  app = ApplicationMgr()
26  app.AuditAlgorithms = 1
27  pfaud = PerfMonAuditor()
28  try:
29  pfaud.EVENT0 = counter[0]
30  pfaud.SP0 = sampling_period[0]
31  pfaud.INV0 = int(invmask[0])
32  pfaud.CMASK0 = int(cmask[0])
33  pfaud.EVENT1 = counter[1]
34  pfaud.SP1 = sampling_period[1]
35  pfaud.INV1 = int(invmask[1])
36  pfaud.CMASK1 = int(cmask[1])
37  pfaud.EVENT2 = counter[2]
38  pfaud.SP2 = sampling_period[2]
39  pfaud.INV2 = int(invmask[2])
40  pfaud.CMASK2 = int(cmask[2])
41  pfaud.EVENT3 = counter[3]
42  pfaud.SP3 = sampling_period[3]
43  pfaud.INV3 = int(invmask[3])
44  pfaud.CMASK3 = int(cmask[3])
45  except IndexError:
46  pass
47  pfaud.FAMILY = family
48  # for <2.5 Python use: test and true_value or false_value
49  pfaud.PREFIX = "%s_%s" % (storeresultsat, "S" if sampling_period[0] > 0 else "C")
50  pfaud.SAMPLE = int(sampling_period[0] > 0)
51  pfaud.START_AT_EVENT = startatevent
52  # pfaud.LEVEL = 5
53  AuditorSvc().Auditors.append(pfaud)
54  print(pfaud)
55 
56 
GenerateGaudiOpts.generateOptions
def generateOptions(counter, cmask, invmask, sampling_period, startatevent, storeresultsat, family)
Definition: GenerateGaudiOpts.py:15
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:35
PerfMonAuditor
Definition: PerfMonAuditor.cpp:208
AuditorSvc
Definition: AuditorSvc.h:27
GenerateGaudiOpts.ConvertDictToXml
def ConvertDictToXml(xmldict)
Definition: GenerateGaudiOpts.py:130
GenerateGaudiOpts._ConvertXmlToDictRecurse
def _ConvertXmlToDictRecurse(node, dictclass)
Definition: GenerateGaudiOpts.py:141
GenerateGaudiOpts.ConvertXmlToDict
def ConvertXmlToDict(root, dictclass=XmlDictObject)
Definition: GenerateGaudiOpts.py:179
ApplicationMgr
Definition: ApplicationMgr.h:57
GenerateGaudiOpts._ConvertDictToXmlRecurse
def _ConvertDictToXmlRecurse(parent, dictitem)
Definition: GenerateGaudiOpts.py:109