10def getHistogramDefinitions(fileName, usage, use_group):
11 import os.path
12 import json
13
14
15 requiredKeys = ['title', 'xtitle', 'ytitle', 'path', 'xbins', 'xmin', 'xmax', 'type']
16
17 position = {'name': 0, 'title': 1, 'path': 2, 'xbins': 3, 'xmin': 4, 'xmax': 5, 'type': 6, 'ymin': 7, 'ymax': 8}
18
19
20 if not os.path.isfile(fileName):
21 raise IOError("This path to the file does not exist:" + fileName)
22
23
24 file_dict = {}
25 with open(fileName) as json_file:
26 file_dict = json.load(json_file)
27
28
29 for group in file_dict:
30 for var in file_dict[group]:
31 for required_key in requiredKeys:
32 if required_key not in file_dict[group][var]:
33 raise IOError("The key " + required_key + " is missing in the dict for the variable " + var + ".")
34
35
36 list = []
37
38 for group in file_dict:
39
40 if not (use_group == 'ALL' or group == use_group) or group == 'template':
41 continue
42
43 for var in file_dict[group]:
44
45 if usage in file_dict[group][var]['path']:
46
47 if 'forEach' in file_dict[group][var]:
48 for type in file_dict[group][var]['forEach']:
49 var_list = ['', '', '', '', '', '', '', '', '']
50
51 new_var_name = var + '_' + type
52
53 var_list[position['name']] = str(new_var_name)
54
55 var_list[position['title']] = str(file_dict[group][var]['title'] + ' ' + type + ';' + file_dict[group][var]['xtitle'] + ';' + file_dict[group][var]['ytitle'])
56
57 var_list[position['path']] = str(file_dict[group][var]['path'][usage])
58
59 for key in ['xbins', 'xmin', 'xmax', 'type']:
60 var_list[position[key]] = str(file_dict[group][var][key])
61 if(file_dict[group][var][
'type'] ==
'TProfile'):
62 var_list[position['ymin']] = str(file_dict[group][var]['ymin'])
63 var_list[position['ymax']] = str(file_dict[group][var]['ymax'])
64
65 list.append(var_list)
66 else:
67 var_list = ['', '', '', '', '', '', '', '', '']
68
69 var_list[position['name']] = str(var)
70
71 var_list[position['title']] = str(file_dict[group][var]['title'] + ';' + file_dict[group][var]['xtitle'] + ';' + file_dict[group][var]['ytitle'])
72
73 var_list[position['path']] = str(file_dict[group][var]['path'][usage])
74
75 for key in ['xbins', 'xmin', 'xmax', 'type']:
76 var_list[position[key]] = str(file_dict[group][var][key])
77 if(file_dict[group][var][
'type'] ==
'TProfile'):
78 var_list[position['ymin']] = str(file_dict[group][var]['ymin'])
79 var_list[position['ymax']] = str(file_dict[group][var]['ymax'])
80
81 list.append(var_list)
82
83 return list
84
85
86