test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
relval_machine.py
Go to the documentation of this file.
1 from Configuration.PyReleaseValidation.relval_steps import Matrix, InputInfo, Steps
2 import os
3 import json
4 import collections
5 
6 
7 workflows = Matrix()
8 steps = Steps()
9 
10 
12  cwd = os.path.join(os.getcwd(), "json_data")
13  if not os.path.exists(cwd):
14  return []
15 
16  json_files = []
17  for f in os.listdir(cwd):
18  full_path = os.path.join(cwd, f)
19  if os.path.isfile(full_path) and f.endswith(".json"):
20  json_files.append(full_path)
21  return json_files
22 
23 
24 def fix_run(run):
25  runs = run.replace(" ", "").replace("[", "").replace("]", "").split(",")
26  int_runs = []
27  for item in runs:
28  if item.isdigit():
29  int_runs.append(int(item))
30  else:
31  print "WARNING: run is in bad format: {0}".format(run)
32  return int_runs
33 
34 def convert_keys_to_string(dictionary):
35  """ Recursively converts dictionary keys to strings.
36  Utility to help deal with unicode keys in dictionaries created from json requests.
37  In order to pass dict to function as **kwarg we should transform key/value to str.
38  """
39  if isinstance(dictionary, basestring):
40  return str(dictionary)
41  elif isinstance(dictionary, collections.Mapping):
42  return dict(map(convert_keys_to_string, dictionary.iteritems()))
43  elif isinstance(dictionary, collections.Iterable):
44  return type(dictionary)(map(convert_keys_to_string, dictionary))
45  else:
46  return dictionary
47 
49  data_files = get_json_files()
50  for index, data_file in enumerate(data_files):
51  with open(data_file, "r") as f:
52  data = json.load(f)
53  data = convert_keys_to_string(data)
54  label = data["label"]
55  steps_names = []
56  for step_name, step in data["steps"].items():
57  steps_names.append((step_name, step["sequence_number"]))
58  if step_name in steps:
59  continue # this step was inserted already
60 
61  # inputInfo case
62  if "inputInfo" in step:
63  input_info = step["inputInfo"]
64  if "run" in input_info:
65  input_info["run"] = fix_run(input_info["run"])
66 
67  steps[step_name] = {
68  'INPUT': InputInfo(**input_info)
69  }
70  # step with parameters
71  elif "parameters" in step:
72  steps[step_name] = step["parameters"]
73  else:
74  raise Exception("Wrong step format in {0} file".format(data_file))
75 
76  sorted_steps = sorted(steps_names, key=lambda step: step[1]) # sort steps by sequence number
77  sorted_steps_names = [step_name[0] for step_name in sorted_steps] # filter only step names
78 
79  workflows[1000000.0 + 0.1*index] = [label, sorted_steps_names]
80 
81 
83 
CLHEP::HepMatrix Matrix
Definition: matutil.h:65
def load_steps_and_workflows
def convert_keys_to_string
double split
Definition: MVATrainer.cc:139