CMS 3D CMS Logo

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