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