CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
helpers.py
Go to the documentation of this file.
1 import os
2 from RecoBTag.CTagging.trainingvars import get_var_pset
3 import xml.etree.ElementTree as ET
4 from pdb import set_trace
5 
6 def get_path(file_in_path):
7  'mimics edm.FileInPath behavior'
8  search_env = os.environ.get('CMSSW_SEARCH_PATH', '')
9  if not search_env:
10  raise RuntimeError('The environmental variable CMSSW_SEARCH_PATH must be set')
11  search_paths = search_env.split(':')
12  for spath in search_paths:
13  full_path = os.path.join(spath, file_in_path)
14  if os.path.isfile(full_path):
15  return full_path
16  raise RuntimeError('No suitable path found for %s' % file_in_path)
17 
18 def get_vars(xml_path, useFileInPath=True):
19  full_path = get_path(xml_path) if useFileInPath else xml_path
20  xml_tree = ET.parse(full_path)
21  root = xml_tree.getroot()
22  variables = None
23  for i in root:
24  if i.tag == 'Variables':
25  variables = i
26 
27  if i is None:
28  raise RuntimeError('Could not find Variables inside the xml weights')
29 
30  var_names = [i.attrib['Title'] for i in variables]
31  return [get_var_pset(i) for i in var_names]
32 
def get_path
Definition: helpers.py:6
def get_vars
Definition: helpers.py:18