Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:24

0001 import os
0002 from RecoBTag.CTagging.trainingvars import get_var_pset
0003 import xml.etree.ElementTree as ET
0004 from pdb import set_trace
0005 
0006 def get_path(file_in_path):
0007    'mimics edm.FileInPath behavior'
0008    search_env = os.environ.get('CMSSW_SEARCH_PATH', '')
0009    if not search_env:
0010       raise RuntimeError('The environmental variable CMSSW_SEARCH_PATH must be set')
0011    search_paths = search_env.split(':')
0012    for spath in search_paths:
0013       full_path = os.path.join(spath, file_in_path)
0014       if os.path.isfile(full_path):
0015          return full_path
0016    raise RuntimeError('No suitable path found for %s' % file_in_path)
0017 
0018 def get_vars(xml_path, useFileInPath=True):
0019    full_path = get_path(xml_path) if useFileInPath else xml_path
0020    xml_tree = ET.parse(full_path)
0021    root = xml_tree.getroot()
0022    variables = None
0023    for i in root:
0024       if i.tag == 'Variables':
0025          variables = i
0026 
0027    if i is None:
0028       raise RuntimeError('Could not find Variables inside the xml weights')
0029    
0030    var_names = [i.attrib['Title'] for i in variables]
0031    return [get_var_pset(i) for i in var_names]
0032