272 def defineHistogram(self,*args,fillGroup=None,hanConfig={},paths=[],**kwargs):
273 '''
274
275 :param path:
276 :param fillGroup:
277 :param args:
278 :param kwargs:
279 :return:
280 '''
281
282 hanConfig = dict(hanConfig)
283
284 if paths != []:
285 for path in paths:
286 if self.dqEnv=='online' and any([x.startswith("Shifter/") for x in paths]) and not path.startswith("Shifter/"): continue
287
288 self.defineHistogram(*args,fillGroup=fillGroup,hanConfig=hanConfig,paths=[],path=path,**kwargs)
289 return None
290
291 argsCopy = list(args)
292 if ";" not in args[0]:
293 argsCopy[0] +=
";h_" + argsCopy[0].
replace(
":",
"_")
294
295 if kwargs.get("path",None) is None:
296
297 kwargs["path"] = "Developer/" + self.alg.name
298 elif kwargs["path"][-1] == '/':
299 kwargs["path"] = kwargs["path"][:-1]
300
301 splitPath = kwargs[
"path"].
split(
"/")
302 if splitPath[0] not in ["Shifter","Expert","Developer"]:
303 raise Exception("Path of histogram invalid, does not start with one of the allowed audiences (Shifter,Expert,Developer)")
304
305
306 if splitPath[0]=="Shifter" and self.dqEnv == 'tier0':
307 return None
308
309
310 if splitPath[0] != "Developer" and splitPath[-1] != "detail" and ("algorithm" not in hanConfig) and (splitPath[0]+"/algorithm" not in hanConfig):
311
312 if "description" not in hanConfig and splitPath[0]+"/description" not in hanConfig:
313 raise Exception("Must specify a hanConfig for a Shifter or Expert (non-detail) histogram")
314 else:
315 hanConfig["algorithm"] = "GatherData"
316 elif "algorithm" in hanConfig and hanConfig["algorithm"] not in self.hanAlgConfigs and hanConfig["algorithm"] not in ["All_Bins_Filled","Histogram_Effective_Empty","Histogram_Empty","Histogram_Not_Empty","No_OverFlows","No_UnderFlows"]:
317
318 raise Exception(f'DQ Algorithm {hanConfig["algorithm"]} for histogram {args[0]} not defined. Please use defineDQAlgorithm method to define it')
319 elif splitPath[0]+"/algorithm" in hanConfig and hanConfig[splitPath[0]+"/algorithm"] not in self.hanAlgConfigs and hanConfig[splitPath[0]+"/algorithm"] not in ["All_Bins_Filled","Histogram_Effective_Empty","Histogram_Empty","Histogram_Not_Empty","No_OverFlows","No_UnderFlows"]:
320
321 raise Exception(f'{splitPath[0]} DQ Algorithm {hanConfig[splitPath[0]+"/algorithm"]} for histogram {args[0]} not defined. Please use defineDQAlgorithm method to define it')
322
323 if fillGroup is None: fillGroup = self.alg.name + "_fillGroup"
324 if fillGroup not in self.fillGroups:
325 self.fillGroups[fillGroup] = self.helper.addGroup(self.alg,fillGroup,topPath="L1Calo")
326
327
328 if "merge" not in kwargs and kwargs.get("type","") !="TEfficiency":
329 kwargs["merge"] = "merge"
330 out = self.fillGroups[fillGroup].defineHistogram(*argsCopy,**kwargs)
331 histName = argsCopy[0].
split(
";")[-1]
332
333
334 if splitPath[0] == "Expert" and self.HELPURL!="":
335 linkUrl = self.HELPURL + "#" + "".join(splitPath[1:]+[histName])
336 linkUrl = f"<a href=\"{linkUrl}\">Help</a>"
337 if "description" not in hanConfig and "Expert/descripton" not in hanConfig: hanConfig["description"] = linkUrl
338 elif "description" in hanConfig: hanConfig["description"] += " - " + linkUrl
339 else: hanConfig["Expert/description"] += " - " + linkUrl
340
341
342 if splitPath[0] == "Expert" or splitPath[0] == "Developer":
343 splitPathWithHist = splitPath + [histName]
344
345 embargo = ("/".join(splitPathWithHist) in L1CaloMonitorCfgHelper.embargoed)
346 if embargo:
347 if "Expert/description" not in hanConfig: hanConfig["description"] = "<b>EMBARGOED PLOT</b> - " + (hanConfig.get("description",""))
348 else: hanConfig["Expert/description"] = "<b>EMBARGOED PLOT</b> - " + (hanConfig.get("Expert/description",""))
349 if "description" in hanConfig and hanConfig["description"]=="":
350 del hanConfig["description"]
351 if splitPath[0]+"/description" in hanConfig and hanConfig[splitPath[0]+"/description"]=="":
352 del hanConfig[splitPath[0]+"/description"]
353 x = L1CaloMonitorCfgHelper.hanConfigs
354 for i,p in enumerate(splitPathWithHist):
355 key = ("dir " if i!=len(splitPathWithHist)-1 else "hist ") + p
356 if key not in x:
357 x[key] = {}
358 x = x[key]
359 hanConfig["output"] = "/".join(["L1Calo"]+[splitPath[0] if not embargo else "Developer"]+splitPath[1:])
360
361 myConfig = {}
362 for k,v in hanConfig.items():
363 if k.startswith("Shifter/"): continue
364
365 myConfig[str(k).
replace(
"Expert/",
"")] = v
366 if "algorithm" in myConfig and myConfig["algorithm"] in self.hanAlgConfigs:
367
368
369 for pName,pVal in self.hanAlgConfigs[myConfig["algorithm"]].items():
370 if len(str(pVal))>0 and str(pVal)[0]=="\"":
371 myConfig["description"] += f"<br>{pName} : {pVal[1:-1]}"
372 x.update(myConfig)
373 elif splitPath[0] == "Shifter":
374
375 myConfig = {}
376 for k,v in hanConfig.items():
377 if k.startswith("Expert/"): continue
378
379 myConfig[str(k).
replace(
"Shifter/",
"")] = v
380 L1CaloMonitorCfgHelper.xmlConfigs["/".join(["L1Calo"]+splitPath+[histName])] = {}
381 L1CaloMonitorCfgHelper.xmlConfigs["/".join(["L1Calo"]+splitPath+[histName])].update(myConfig)
382
383 return out
384
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::vector< std::string > split(const std::string &s, const std::string &t=":")