| # Gaudi Framework, version v23r0 |

Home |  | Generated: Mon Jan 30 2012

Classes | Functions

# GaudiProfiling::GenerateGaudiOpts Namespace Reference

## Classes
class | XmlDictObject
## Functions
def | generateOptions
def | _ConvertDictToXmlRecurse
def | ConvertDictToXml
def | _ConvertXmlToDictRecurse
def | ConvertXmlToDict

## Function Documentation

def GaudiProfiling::GenerateGaudiOpts::_ConvertDictToXmlRecurse | ( |  | parent,
|  |  | dictitem
| ) |  | `[private]`

Definition at line 93 of file GenerateGaudiOpts.py.

    00094                                               :
    00095     assert type(dictitem) is not type([])
    00096
    00097     if isinstance(dictitem, dict):
    00098         for (tag, child) in dictitem.iteritems():
    00099             if str(tag) == '_text':
    00100                 parent.text = str(child)
    00101             elif type(child) is type([]):
    00102                 # iterate through the array and convert
    00103                 for listchild in child:
    00104                     elem = ElementTree.Element(tag)
    00105                     parent.append(elem)
    00106                     _ConvertDictToXmlRecurse(elem, listchild)
    00107             else:
    00108                 elem = ElementTree.Element(tag)
    00109                 parent.append(elem)
    00110                 _ConvertDictToXmlRecurse(elem, child)
    00111     else:
    00112         parent.text = str(dictitem)

def GaudiProfiling::GenerateGaudiOpts::_ConvertXmlToDictRecurse | ( |  | node,
|  |  | dictclass
| ) |  | `[private]`

Definition at line 123 of file GenerateGaudiOpts.py.

    00124                                              :
    00125     nodedict = dictclass()
    00126
    00127     if len(node.items()) > 0:
    00128         # if we have attributes, set them
    00129         nodedict.update(dict(node.items()))
    00130
    00131     for child in node:
    00132         # recursively add the element's children
    00133         newitem = _ConvertXmlToDictRecurse(child, dictclass)
    00134         if nodedict.has_key(child.tag):
    00135             # found duplicate tag, force a list
    00136             if type(nodedict[child.tag]) is type([]):
    00137                 # append to existing list
    00138                 nodedict[child.tag].append(newitem)
    00139             else:
    00140                 # convert to list
    00141                 nodedict[child.tag] = [nodedict[child.tag], newitem]
    00142         else:
    00143             # only one, directly set the dictionary
    00144             nodedict[child.tag] = newitem
    00145
    00146     if node.text is None:
    00147         text = ''
    00148     else:
    00149         text = node.text.strip()
    00150
    00151     if len(nodedict) > 0:
    00152         # if we have a dictionary add the text as a dictionary value (if there is any)
    00153         if len(text) > 0:
    00154             nodedict['_text'] = text
    00155     else:
    00156         # if we don't have child nodes or attributes, just set the text
    00157         nodedict = text
    00158
    00159     return nodedict

def GaudiProfiling::GenerateGaudiOpts::ConvertDictToXml | ( |  | xmldict ) |

    Converts a dictionary to an XML ElementTree Element

Definition at line 113 of file GenerateGaudiOpts.py.

    00114                              :
    00115     """
    00116     Converts a dictionary to an XML ElementTree Element
    00117     """
    00118
    00119     roottag = xmldict.keys()[0]
    00120     root = ElementTree.Element(roottag)
    00121     _ConvertDictToXmlRecurse(root, xmldict[roottag])
    00122     return root

def GaudiProfiling::GenerateGaudiOpts::ConvertXmlToDict | ( |  | root,
|  |  | dictclass = `XmlDictObject`
| ) |  |

    Converts an XML file or ElementTree Element to a dictionary

Definition at line 160 of file GenerateGaudiOpts.py.

    00161                                                    :
    00162     """
    00163     Converts an XML file or ElementTree Element to a dictionary
    00164     """
    00165
    00166     # If a string is passed in, try to open it as a file
    00167     if type(root) == type(''):
    00168         root = ElementTree.parse(root).getroot()
    00169     elif not isinstance(root, ElementTree.Element):
    00170         raise TypeError, 'Expected ElementTree.Element or file path string'
    00171
    00172     return dictclass({root.tag: _ConvertXmlToDictRecurse(root, dictclass)})

def GaudiProfiling::GenerateGaudiOpts::generateOptions | ( |  | counter,
|  |  | cmask,
|  |  | invmask,
|  |  | sampling_period,
|  |  | startatevent,
|  |  | storeresultsat,
|  |  | family
| ) |  |

Definition at line 4 of file GenerateGaudiOpts.py.

    00005                                                                                                    :
    00006     cmask = map(int, cmask)
    00007     invmask = map(int, invmask)
    00008     sampling_period = map(int, sampling_period)
    00009     startatevent = int(startatevent)
    00010
    00011     from Configurables import ApplicationMgr, AuditorSvc, PerfMonAuditor
    00012     app = ApplicationMgr()
    00013     app.AuditAlgorithms = 1
    00014     pfaud = PerfMonAuditor()
    00015     try:
    00016         pfaud.EVENT0 = counter[0]
    00017         pfaud.SP0 = sampling_period[0]
    00018         pfaud.INV0 = int(invmask[0])
    00019         pfaud.CMASK0 = int(cmask[0])
    00020         pfaud.EVENT1 = counter[1]
    00021         pfaud.SP1 = sampling_period[1]
    00022         pfaud.INV1 = int(invmask[1])
    00023         pfaud.CMASK1 = int(cmask[1])
    00024         pfaud.EVENT2 = counter[2]
    00025         pfaud.SP2 = sampling_period[2]
    00026         pfaud.INV2 = int(invmask[2])
    00027         pfaud.CMASK2 = int(cmask[2])
    00028         pfaud.EVENT3 = counter[3]
    00029         pfaud.SP3 = sampling_period[3]
    00030         pfaud.INV3 = int(invmask[3])
    00031         pfaud.CMASK3 = int(cmask[3])
    00032     except IndexError:
    00033         pass
    00034     pfaud.FAMILY = family
    00035     pfaud.PREFIX = "%s_%s" % (storeresultsat, "S" if sampling_period[0] > 0 else "C") # for <2.5 Python use: test and true_value or false_value
    00036     pfaud.SAMPLE = int(sampling_period[0] > 0)
    00037     pfaud.START_AT_EVENT = startatevent
    00038     #pfaud.LEVEL = 5
    00039     AuditorSvc().Auditors.append(pfaud)
    00040     print pfaud
    00041

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines