コード例 #1
0
 def fromXML( cls, element ):
     ## Constructor from an XML element
     #  <Variable name="VariableName" command="DrawCommand" title="AxisTitle" unit="Unit" nBins="nBins" low="min" up="max">
     #    <Cut>DefaultCut</Cut>
     #  </Variable>
     #  @param element    the XML element
     #  @return the Variable object
     attributes = element.attrib
     name = attributes[ 'name' ]
     variable = cls( name )
     if attributes.has_key( 'command' ):
         variable.treeName = attributes['command']
     if attributes.has_key( 'title' ):
         variable.title = attributes['title']
     if attributes.has_key( 'unit' ):
         variable.unit = attributes['unit']
     if attributes.has_key( 'nBins' ):
         variable.binning.nBins = int(attributes['nBins'])
     if attributes.has_key( 'low' ):
         variable.binning.low = float(attributes['low'])
     if attributes.has_key( 'up' ):
         variable.binning.up = float(attributes['up'])
     for cutElement in element.findall( 'Cut' ):
         variable.defaultCut += Cut.fromXML( cutElement )
     return variable
コード例 #2
0
 def parse( self, fileName ):
     ## Read all known elements from an input XML
     #  @param fileName       input XML
     self.logger.debug( 'parse(): reading "%s"' % fileName )
     tree = ElementTree.parse( self, fileName )
     
     # read the CrossSectionDB elements
     for element in tree.findall('CrossSectionDB'):
         self.crossSectionDB = CrossSectionDB.fromXML( element )
     
     # read the HistogramStore elements
     for element in tree.findall('HistogramStore'):
         self.histogramStore = HistogramStore.fromXML( element )
     
     # read all Cut elements
     for element in tree.findall('Cut'):
         self.cuts.append( Cut.fromXML( element ) )
         
     # read all Dataset elements
     for element in tree.findall('Dataset'):
         self.datasets.append( Dataset.fromXML( element ) )
         
     # read all PhysicsProcess elements
     for element in tree.findall('PhysicsProcess'):
         self.physicsProcesses.append( PhysicsProcess.fromXML( element ) )
     
     # read all Systematics elements
     for element in tree.findall('Systematics'):
         self.systematicsSet.add( Systematics.fromXML( element ) )
コード例 #3
0
    def datasetsFromXML(cls, element):
        ## Constructor from an XML element
        #  <Datasets basepath="" treeName="" isData="" isSignal="" weightExpression="">
        #    <Style color="5"/>
        #    <DSIDS> 1234, 4321, 3412 </DSIDS>
        #    <AddCuts>
        #      <Cut> Cut1 </Cut>
        #      <Cut> Cut2 </Cut>
        #    </AddCuts>
        #    <IgnoreCuts>
        #      <Cut> Cut3 </Cut>
        #      <Cut> Cut4 </Cut>
        #    </IgnoreCuts>
        #  </Dataset>
        #  @param element    the XML element
        #  @return a list of Dataset objects
        attributes = element.attrib

        datasets = []
        treeName = None
        isData = False
        isSignal = False
        isBSMSignal = False
        weighExpression = None
        if attributes.has_key('basePath'):
            basePath = attributes['basePath']
        else:
            cls.logger.warning(
                'datasetsFromXML(): Datasets XML element is missing "basePath" attribute. No datasets created.'
            )
            return datasets
        if attributes.has_key('treeName'):
            treeName = attributes['treeName']
        if attributes.has_key('isData'):
            isData = string2bool(attributes['isData'])
        if attributes.has_key('isSignal'):
            isSignal = string2bool(attributes['isSignal'])
        if attributes.has_key('isBSMSignal'):
            isBSMSignal = string2bool(attributes['isBSMSignal'])
        if attributes.has_key('weightExpression'):
            weightExpression = attributes['weightExpression']
        style = Style.fromXML(element.find('Style')) if element.find(
            'Style') is not None else None
        addCuts = []
        ignoreCuts = []
        if element.find('AddCuts'):
            for cutElement in element.find('AddCuts').findall('Cut'):
                addCuts.append(Cut.fromXML(cutElement))
        if element.find('IgnoreCuts'):
            for cutElement in element.find('IgnoreCuts').findall('Cut'):
                ignoreCuts.append(Cut.fromXML(cutElement))
        if element.find('DSIDS') is not None:
            dsids = element.text.split(',')
            for dsid in dsids:
                dataset = cls.datasetFromDSID(basePath, int(dsid),
                                              dsid.strip(), treeName, style,
                                              weightExpression)
                dataset.isData = isData
                dataset.isSignal = isSignal
                dataset.isBSMSignal = isBSMSignal
                dataset.addCuts += addCuts
                dataset.ignoreCuts += ignoreCuts
        else:
            cls.logger.warning(
                'datasetsFromXML(): Datasets XML element is missing "DSIDS" element. No datasets created.'
            )
            return datasets
        return datasets