CMS 3D CMS Logo

PV.py
Go to the documentation of this file.
1 import copy
2 import os
3 import pprint
4 
5 def PV(config, validationDir):
6 
7  jobs, singleJobs = [], []
8  pvType = "single"
9 
10 
11  IOVs = {}
12 
13 
14  isDataMerged = {}
15 
16 
17  if not pvType in config["validations"]["PV"]:
18  raise Exception("No 'single' key word in config for PV")
19 
20  for singleName in config["validations"]["PV"][pvType]:
21  #print("Reading singleName = {}".format(singleName))
22  aux_IOV = config["validations"]["PV"][pvType][singleName]["IOV"]
23  if not isinstance(aux_IOV, list) and aux_IOV.endswith(".txt"):
24  config["validations"]["PV"][pvType][singleName]["IOV"] = []
25  with open(aux_IOV, 'r') as IOVfile: for line in IOVfile.readlines():
26  if len(line) != 0: config["validations"]["PV"][pvType][singleName]["IOV"].append(int(line))
27  for IOV in config["validations"]["PV"][pvType][singleName]["IOV"]:
28 
29  if singleName not in IOVs.keys():
30  IOVs[singleName] = []
31  if IOV not in IOVs[singleName]:
32  IOVs[singleName].append(IOV)
33 
34  for alignment in config["validations"]["PV"][pvType][singleName]["alignments"]:
35 
36  workDir = "{}/PV/{}/{}/{}/{}".format(validationDir, pvType, singleName, alignment, IOV)
37 
38 
39  local = {}
40  local["output"] = "{}/{}/PV/{}/{}/{}/{}".format(config["LFS"], config["name"], pvType, alignment, singleName, IOV)
41  local["alignment"] = copy.deepcopy(config["alignments"][alignment])
42  local["alignment"]["name"] = alignment
43  local["validation"] = copy.deepcopy(config["validations"]["PV"][pvType][singleName])
44  local["validation"].pop("alignments")
45  local["validation"]["IOV"] = IOV
46  if "dataset" in local["validation"]:
47  local["validation"]["dataset"] = local["validation"]["dataset"].format(IOV)
48  if "goodlumi" in local["validation"]:
49  local["validation"]["goodlumi"] = local["validation"]["goodlumi"].format(IOV)
50 
51 
52  job = {
53  "name": "PV_{}_{}_{}_{}".format(pvType, alignment, singleName, IOV),
54  "dir": workDir,
55  "exe": "cmsRun",
56  "cms-config": "{}/src/Alignment/OfflineValidation/python/TkAlAllInOneTool/PV_cfg.py".format(os.environ["CMSSW_BASE"]),
57  "run-mode": "Condor",
58  "dependencies": [],
59  "config": local,
60  }
61 
62  #jobs.append(job)
63  singleJobs.append(job)
64 
65  jobs.extend(singleJobs)
66 
67 
68  if "merge" in config["validations"]["PV"]:
69 
70  mergeJobs = []
71  pvType = "merge"
72 
73 
74  for mergeName in config["validations"]["PV"][pvType]:
75 
76  singlesMC = []
77  for singleName in config["validations"]["PV"][pvType][mergeName]['singles']:
78  if len(IOVs[singleName]) == 1 and int(IOVs[singleName][0]) == 1: singlesMC.append(singleName)
79  isMConly = (len(singlesMC) == len(config["validations"]["PV"][pvType][mergeName]['singles']))
80  if isMConly:
81  isDataMerged[mergeName] = 0
82  elif len(singlesMC) == 0:
83  isDataMerged[mergeName] = 1
84  else:
85  isDataMerged[mergeName] = -1
86 
87 
88  for iname,singleName in enumerate(config["validations"]["PV"][pvType][mergeName]['singles']):
89  isMC = (singleName in singlesMC)
90  if isMConly and iname > 0: continue #special case for MC only comparison
91  elif isMConly: singlesMC.pop(singlesMC.index(singleName))
92 
93  for IOV in IOVs[singleName]:
94  if isMC and not isMConly: continue #ignore IOV=1 as it is automatically added to each DATA IOV unless MC only comparison
95  #print("mergeName = {}".format(mergeName))
96 
97 
98  workDir = "{}/PV/{}/{}/{}".format(validationDir, pvType, mergeName, IOV) #Different (DATA) single jobs must contain different set of IOVs
99 
100 
101  local = {}
102 
103  job = {
104  "name": "PV_{}_{}_{}".format(pvType, mergeName, IOV),
105  "dir": workDir,
106  "exe": "PVmerge",
107  "run-mode": "Condor",
108  "dependencies": [],
109  "config": local,
110  }
111 
112 
113  for alignment in config["alignments"]:
114  idxIncrement = 0
115  local.setdefault("alignments", {})
116  if alignment in config["validations"]["PV"]["single"][singleName]["alignments"]: #Cover all DATA validations
117  local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
118  local["alignments"][alignment]['index'] = config["validations"]["PV"]["single"][singleName]["alignments"].index(alignment)
119  local["alignments"][alignment]['isMC'] = False
120  for singleMCname in singlesMC:
121  if alignment in config["validations"]["PV"]["single"][singleMCname]["alignments"]: #Add MC objects
122  local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
123  local["alignments"][alignment]['index'] = len(config["validations"]["PV"]["single"][singleName]["alignments"])
124  local["alignments"][alignment]['index'] += idxIncrement + config["validations"]["PV"]["single"][singleMCname]["alignments"].index(alignment)
125  local["alignments"][alignment]['isMC'] = True
126  idxIncrement += len(config["validations"]["PV"]["single"][singleMCname]["alignments"])
127  local["validation"] = copy.deepcopy(config["validations"]["PV"][pvType][mergeName])
128  local["validation"]["IOV"] = IOV
129  if "customrighttitle" in local["validation"].keys():
130  if "IOV" in local["validation"]["customrighttitle"]:
131  local["validation"]["customrighttitle"] = local["validation"]["customrighttitle"].replace("IOV",str(IOV))
132  local["output"] = "{}/{}/PV/{}/{}/{}".format(config["LFS"], config["name"], pvType, mergeName, IOV)
133 
134 
135  if "style" in config.keys():
136  if "PV" in config['style'].keys():
137  if pvType in config['style']['PV'].keys():
138  local["style"] = copy.deepcopy(config["style"]["PV"][pvType])
139  if "Rlabel" in local["style"] and "customrighttitle" in local["validation"].keys():
140  print("WARNING: custom right label is overwritten by global settings")
141 
142 
143  for singleJob in jobs:
144 
145  _alignment, _singleName, _singleIOV = singleJob["name"].split("_")[2:]
146  if _singleName in config["validations"]["PV"][pvType][mergeName]["singles"]:
147  if int(_singleIOV) == IOV or (int(_singleIOV) == 1 and _singleName in singlesMC): #matching DATA job or any MC single job
148  local["alignments"][_alignment]["file"] = singleJob["config"]["output"]
149  job["dependencies"].append(singleJob["name"])
150 
151  mergeJobs.append(job)
152 
153  jobs.extend(mergeJobs)
154 
155  if "trends" in config["validations"]["PV"]:
156 
157 
158  trendJobs = []
159  pvType = "trends"
160 
161  for trendName in config["validations"]["PV"][pvType]:
162  #print("trendName = {}".format(trendName))
163 
164 
165  workDir = "{}/PV/{}/{}".format(validationDir, pvType, trendName)
166 
167 
168  local = {}
169 
170  job = {
171  "name": "PV_{}_{}".format(pvType, trendName),
172  "dir": workDir,
173  "exe": "PVtrends",
174  "run-mode": "Condor",
175  "dependencies": [],
176  "config": local,
177  }
178 
179 
180  if 'merges' in config["validations"]["PV"][pvType][trendName].keys()\
181  or 'singles' not in config["validations"]["PV"][pvType][trendName].keys():
182  raise Exception("Specify list of \'singles\' to run PV trends.")
183  #TODO: possible also to run over merges for consistency with DMR jobs
184  trendIOVs = [] #TODO: allow different IOV list for each single job?
185  alignmentList = []
186  for iname, singleName in enumerate(config["validations"]["PV"][pvType][trendName]["singles"]):
187  isMC = (len(IOVs[singleName]) == 1 and int(IOVs[singleName][0]) == 1)
188  if isMC:
189  raise Exception("Trend jobs are not implemented for treating MC.")
190  if iname == 0:
191  trendIOVs = IOVs[singleName]
192  else:
193  for IOV in IOVs[singleName]:
194  if IOV not in trendIOVs or (len(IOVs[singleName]) != len(trendIOVs)):
195  raise Exception("List of IOVs must be the same for each single job.")
196  for alignment in config["validations"]["PV"]["single"][singleName]["alignments"]:
197  if alignment not in alignmentList and alignment in config["alignments"]:
198  local.setdefault("alignments", {})
199  alignmentList.append(alignment)
200  local["alignments"][alignment] = copy.deepcopy(config["alignments"][alignment])
201  local["alignments"][alignment]["file"] = "{}/{}/PV/{}/{}/{}/{}".format(config["LFS"], config["name"], "single", alignment, singleName, "{}")
202  trendIOVs.sort()
203  local["validation"] = copy.deepcopy(config["validations"]["PV"][pvType][trendName])
204  local["validation"]["IOV"] = trendIOVs
205  if "label" in config["validations"]["PV"][pvType][trendName]:
206  local["validation"]["label"] = copy.deepcopy(config["validations"]["PV"][pvType][trendName]["label"])
207  local["output"] = "{}/{}/PV/{}/{}/".format(config["LFS"], config["name"], pvType, trendName)
208  if "style" in config.keys() and "trends" in config["style"].keys():
209  local["style"] = copy.deepcopy(config["style"])
210  if "PV" in local["style"].keys(): local["style"].pop("PV")
211  if "CMSlabel" in config["style"]["trends"].keys(): local["style"]["CMSlabel"] = config["style"]["trends"]["CMSlabel"]
212  if "Rlabel" in config["style"]["trends"].keys():
213  local["style"]["trends"].pop("Rlabel")
214  local["style"]["trends"]["TitleCanvas"] = config["style"]["trends"]["Rlabel"]
215  else:
216  raise Exception("You want to create 'trends' jobs, but there are no 'lines' section in the config for pixel updates!")
217 
218  #Loop over all single jobs
219  for singleJob in singleJobs:
220  #Get single job info and append to job if requirements fullfilled
221  alignment, singleName, singleIOV = singleJob["name"].split("_")[2:]
222 
223  if singleName in config["validations"]["PV"][pvType][trendName]["singles"]\
224  and int(singleIOV) in trendIOVs:
225  job["dependencies"].append(singleJob["name"])
226 
227  trendJobs.append(job)
228 
229  jobs.extend(trendJobs)
230 
231  return jobs
232 
def replace(string, replacements)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def PV(config, validationDir)
Definition: PV.py:5
#define str(s)