ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper Class Reference
Inheritance diagram for LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper:
Collaboration diagram for LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper:

Public Member Functions

def __init__ (self, flags, algClassOrObj=None, name=None, *args, **kwargs)
 
def defineDQAlgorithm (self, name, hanConfig, thresholdConfig=None)
 
def defineHistogram (self, *args, fillGroup=None, hanConfig={}, paths=[], **kwargs)
 
def defineTree (self, *args, fillGroup=None, **kwargs)
 
def result (self)
 

Static Public Member Functions

def printHanConfig (filename="collisions_run.config")
 

Public Attributes

 helper
 
 alg
 
 fillGroups
 
 dqEnv
 

Static Public Attributes

 hanConfigs
 
 hanAlgConfigs
 
 hanThresholdConfigs
 
 SIGNATURES
 
 HELPURL
 

Detailed Description

This class is designed to handle registering all of L1Calo's monitoring histograms and trees in a
coherent way. It will also generate the han config file for all the histograms.

Definition at line 5 of file LVL1CaloMonitoringConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.__init__ (   self,
  flags,
  algClassOrObj = None,
  name = None,
args,
**  kwargs 
)
Create the configuration helper.

Arguments:
flags -- the configuration flag object
algClassOrObj -- the name you want to assign the family of algorithms

Definition at line 116 of file LVL1CaloMonitoringConfig.py.

116  def __init__(self, flags, algClassOrObj = None, name = None, *args, **kwargs):
117  '''
118  Create the configuration helper.
119 
120  Arguments:
121  flags -- the configuration flag object
122  algClassOrObj -- the name you want to assign the family of algorithms
123  '''
124  from AthenaMonitoring import AthMonitorCfgHelper
125  self.helper = AthMonitorCfgHelper(flags,name)
126  self.alg = self.helper.addAlgorithm(algClassOrObj,name,*args, **kwargs) if algClassOrObj is not None else None
127  self.fillGroups = {}
128  self.dqEnv = flags.DQ.Environment # used to decide if should defineTree or not ...
129 

Member Function Documentation

◆ defineDQAlgorithm()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.defineDQAlgorithm (   self,
  name,
  hanConfig,
  thresholdConfig = None 
)
:param name: name of algorithm
:param hanConfig: dict of algo properties
:param thresholdConfig: dict of thresholds, keys in form of ParName.level
:return:

Definition at line 130 of file LVL1CaloMonitoringConfig.py.

130  def defineDQAlgorithm(self,name,hanConfig,thresholdConfig=None):
131 
132  """
133 
134  :param name: name of algorithm
135  :param hanConfig: dict of algo properties
136  :param thresholdConfig: dict of thresholds, keys in form of ParName.level
137  :return:
138  """
139 
140  # note: this method will replace any existing alg definition
141 
142  #thresNum = len(self.hanThresholdConfigs)
143  if thresholdConfig is not None:
144  hanConfig["thresholds"] = f"{name}Thresholds"
145  threshDict = {}
146  for parName,limVals in thresholdConfig.items():
147  if len(limVals) != 2:
148  raise Exception("must specify two limits: warning and error")
149  if parName not in threshDict: threshDict[parName] = {}
150  threshDict[parName]["warning"] = limVals[0]
151  threshDict[parName]["error"] = limVals[1]
152  # see if any existing thresholds are identical, if so we can reuse
153  for threshName,thresh in self.hanThresholdConfigs.items():
154  if str(thresh)==str(threshDict):
155  threshDict = None
156  hanConfig["thresholds"] = threshName
157  break
158  if threshDict is not None: self.hanThresholdConfigs[hanConfig["thresholds"]] = threshDict
159  self.hanAlgConfigs[name] = hanConfig
160 
161  return
162 
163 

◆ defineHistogram()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.defineHistogram (   self,
args,
  fillGroup = None,
  hanConfig = {},
  paths = [],
**  kwargs 
)
:param path:
:param fillGroup:
:param args:
:param kwargs:
:return:

Definition at line 164 of file LVL1CaloMonitoringConfig.py.

164  def defineHistogram(self,*args,fillGroup=None,hanConfig={},paths=[],**kwargs):
165  '''
166 
167  :param path:
168  :param fillGroup:
169  :param args:
170  :param kwargs:
171  :return:
172  '''
173 
174  hanConfig = dict(hanConfig) # create a copy since will modify below (otherwise we end up modifying the default empty dict)
175 
176  if paths != []:
177  for path in paths:
178  # create a copy of the histogram in each of the extra locations
179  self.defineHistogram(*args,fillGroup=fillGroup,hanConfig=hanConfig,paths=[],path=path,**kwargs)
180  return None
181 
182  argsCopy = list(args) # need to convert tuple to list to convert it
183  if ";" not in args[0]:
184  argsCopy[0] += ";h_" + argsCopy[0].replace(":","_")
185 
186  if kwargs.get("path",None) is None:
187  # put in the Developer path, under the name of the algorithm
188  kwargs["path"] = "Developer/" + self.alg.name
189  elif kwargs["path"][-1] == '/':
190  kwargs["path"] = kwargs["path"][:-1] # strip trailing slash
191  # verify path obeys convention
192  splitPath = kwargs["path"].split("/")
193  if splitPath[0] not in ["Shifter","Expert","Developer"]:
194  raise Exception("Path of histogram invalid, does not start with one of the allowed audiences (Shifter,Expert,Developer)")
195 
196  # require a hanConfig not in Developer or a detail dir
197  if splitPath[0] != "Developer" and splitPath[-1] != "detail" and ("algorithm" not in hanConfig):
198  # will default to using GatherData as long as there is a description
199  if "description" not in hanConfig:
200  raise Exception("Must specify a hanConfig for a Shifter or Expert (non-detail) histogram")
201  else:
202  hanConfig["algorithm"] = "GatherData" # must have an algo, otherwise wont be valid han config
203 
204 
205  if fillGroup is None: fillGroup = self.alg.name + "_fillGroup"
206  if fillGroup not in self.fillGroups:
207  self.fillGroups[fillGroup] = self.helper.addGroup(self.alg,fillGroup,topPath="L1Calo")
208 
209  if "merge" not in kwargs and kwargs.get("type","") !="TEfficiency":
210  kwargs["merge"] = "merge" # ensures we don't get a warning about not specifying merge method
211  out = self.fillGroups[fillGroup].defineHistogram(*argsCopy,**kwargs)
212  histName = argsCopy[0].split(";")[-1]
213 
214  # add help link for all expert plots
215  if splitPath[0] == "Expert":
216  linkUrl = self.HELPURL + "#" + "".join(splitPath[1:]+[histName])
217  linkUrl = f"<a href=\"{linkUrl}\">Help</a>"
218  if "description" not in hanConfig: hanConfig["description"] = linkUrl
219  else: hanConfig["description"] += " - " + linkUrl
220 
221  # only add to hanConfig if in Expert folder ... perhaps need to allow exception if doing local testing!
222  if splitPath[0] == "Expert":
223  splitPathWithHist = splitPath + [histName]
224  x = L1CaloMonitorCfgHelper.hanConfigs
225  for i,p in enumerate(splitPathWithHist):
226  key = ("dir " if i!=len(splitPathWithHist)-1 else "hist ") + p
227  if key not in x:
228  x[key] = {}
229  x = x[key]
230  hanConfig["output"] = "/".join(["L1Calo"]+splitPath)
231  x.update(hanConfig)
232 
233  return out
234 

◆ defineTree()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.defineTree (   self,
args,
  fillGroup = None,
**  kwargs 
)

Definition at line 235 of file LVL1CaloMonitoringConfig.py.

235  def defineTree(self,*args,fillGroup=None,**kwargs):
236 
237  if ";" not in args[0]:
238  raise Exception("Must specify a tree name using ';name' suffix")
239  treeName = args[0].split(";")[-1]
240 
241  if "," in args[1]: # catch a subtle typo that can screw up monitoring
242  raise Exception("Should not have comma in list of branch names and types")
243 
244  if kwargs.get("path",None) is None:
245  # put in the Developer path, under the name of the algorithm
246  kwargs["path"] = "Developer/" + self.alg.name
247 
248  # verify path obeys convention
249  splitPath = kwargs["path"].split("/")
250  if splitPath[0] not in ["Developer"]:
251  raise Exception("Path of tree invalid, must be in the audience=Developer directory")
252 
253 
254  if fillGroup is None: fillGroup = self.alg.name + "_fillGroup"
255  if fillGroup not in self.fillGroups:
256  self.fillGroups[fillGroup] = self.helper.addGroup(self.alg,fillGroup,topPath="L1Calo")
257 
258  # always define a histogram to go with the tree, which will indicate how many entries there are
259  # this also ensures we satisfy the requirement that every fillGroup has an object defined
260  # (in the cases of running online/tier0 the defineTrees are blocked, but we still need a hist then)
261  histName = "h_" + treeName + "_entries"
262  argsCopy = list(args)
263  argsCopy[0] = argsCopy[0].replace(";"+treeName,";"+histName)
264  kwargsCopy = dict(kwargs)
265  kwargsCopy["title"] = f"Number of Entries in {treeName} TTree" + ";" + ";".join(kwargsCopy.get("title","").split(";")[1:])
266  kwargsCopy["opt"] = ['kCanRebin','kAddBinsDynamically']
267  kwargsCopy["merge"] = "merge"
268  is2d = (kwargsCopy["title"].count(";")>1)
269  self.defineHistogram(argsCopy[0],type="TH2I" if is2d else "TH1I",xbins=1,xmin=0,xmax=1,ybins=1 if is2d else None,ymin=0,ymax=1,fillGroup=fillGroup,**kwargsCopy)
270  if not any([x in self.dqEnv for x in ['tier0','online']]):
271  out = self.fillGroups[fillGroup].defineTree(*args,**kwargs)
272  else:
273  out = None
274  return out
275 

◆ printHanConfig()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.printHanConfig (   filename = "collisions_run.config")
static

Definition at line 23 of file LVL1CaloMonitoringConfig.py.

23  def printHanConfig(filename="collisions_run.config"):
24  from contextlib import redirect_stdout
25  from PathResolver import PathResolver
26  header = PathResolver.FindCalibFile("TrigT1CaloMonitoring/hanConfig_header.txt")
27  with open(filename,'w') as f:
28  # copy the header if we have one
29  if header != "":
30  with open(header,'r') as fh:
31  for line in fh: f.write(line)
32  with redirect_stdout(f):
33  # Note: common configs (see common dir in DataQualityConfiguration) provides following algorithms by default:
34  # algorithm All_Bins_Filled
35  # algorithm Histogram_Effective_Empty
36  # algorithm Histogram_Empty
37  # algorithm Histogram_Not_Empty
38  # algorithm No_OverFlows
39  # algorithm No_UnderFlows
40 
41  outputs = set()
42  def printConf(d,prefix=""):
43  for key,value in d.items():
44  if type(value)==dict:
45  print(prefix,key,"{")
46  if(key=="dir detail" or key=="dir Developer"):
47  print(prefix+" algorithm = GatherData") # define GatherData as default algo for all of these hists
48  if key.startswith("dir ") and any([x.startswith("hist ") for x in value.keys()]):
49  # this is a dir with hists, so specify output as the path .. take from the first hist child
50  for childKey,childVal in value.items():
51  if childKey.startswith("hist ") and "output" in childVal:
52  print(prefix+" output = "+childVal["output"])
53  break
54  printConf(value,prefix + " ")
55  print(prefix,"}")
56  else:
57  # save all output paths to add to output block (don't need to print here b.c. specified at dir level
58  if key == "output": outputs.add(value)
59  else: print(prefix,key,"=",value)
60 
61 
62  print("#inputs")
63  print("dir L1Calo {")
64  printConf(L1CaloMonitorCfgHelper.hanConfigs," ")
65  print("}")
66  print("#outputs")
67  print("output top_level {")
68  def printOutputs(d,prefix=""):
69  for key,value in d.items():
70  if(key.startswith("hist ")):
71  pass # do nothing
72  elif type(value)==dict:
73  print(prefix,key.replace("dir ","output "),"{")
74  printOutputs(value,prefix + " ")
75  print(prefix,"}")
76  print(" output L1Calo {")
77  printOutputs(L1CaloMonitorCfgHelper.hanConfigs," ")
78  print(" }")
79  print("}")
80  # include example of adding algorithms and thresholds
81  print("""
82 #algorithms
83 algorithm AnyNonZeroBinIsError {
84  # Use this algo if want error on any non-zero bin content
85  libname = libdqm_summaries.so
86  name = Bins_NotEqual_Threshold
87  BinThreshold = 0.
88  thresholds = th_AnyBinIsError
89 }
90 """)
91  for algName,algProps in L1CaloMonitorCfgHelper.hanAlgConfigs.items():
92  print(f"algorithm {algName} {{")
93  for propName,propVal in algProps.items():
94  print(f" {propName} = {propVal}")
95  print(" }")
96  print("""
97 #thresholds
98 thresholds th_AnyBinIsError {
99  limits NBins {
100  warning = 0
101  error = 1
102  }
103 }
104 """)
105  for threshName,threshProps in L1CaloMonitorCfgHelper.hanThresholdConfigs.items():
106  print(f"thresholds {threshName} {{")
107  for parName,parLims in threshProps.items():
108  print(f" limits {parName} {{")
109  for limName,limVal in parLims.items():
110  print(f" {limName} = {limVal}")
111  print(" }")
112  print("}")
113 
114 
115 

◆ result()

def LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.result (   self)

Definition at line 276 of file LVL1CaloMonitoringConfig.py.

276  def result(self):
277  return self.helper.result()
278 
279 

Member Data Documentation

◆ alg

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.alg

Definition at line 126 of file LVL1CaloMonitoringConfig.py.

◆ dqEnv

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.dqEnv

Definition at line 128 of file LVL1CaloMonitoringConfig.py.

◆ fillGroups

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.fillGroups

Definition at line 127 of file LVL1CaloMonitoringConfig.py.

◆ hanAlgConfigs

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.hanAlgConfigs
static

Definition at line 16 of file LVL1CaloMonitoringConfig.py.

◆ hanConfigs

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.hanConfigs
static

Definition at line 15 of file LVL1CaloMonitoringConfig.py.

◆ hanThresholdConfigs

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.hanThresholdConfigs
static

Definition at line 17 of file LVL1CaloMonitoringConfig.py.

◆ helper

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.helper

Definition at line 125 of file LVL1CaloMonitoringConfig.py.

◆ HELPURL

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.HELPURL
static

Definition at line 20 of file LVL1CaloMonitoringConfig.py.

◆ SIGNATURES

LVL1CaloMonitoringConfig.L1CaloMonitorCfgHelper.SIGNATURES
static

Definition at line 19 of file LVL1CaloMonitoringConfig.py.


The documentation for this class was generated from the following file:
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.h:108
get_generator_info.result
result
Definition: get_generator_info.py:21
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
LVL1CaloMonitoringConfig.type
type
Definition: LVL1CaloMonitoringConfig.py:437
GenericMonitoringTool.defineTree
def defineTree(flags, varname, treedef, path=None, title=None, opt='', convention=None, cutmask=None)
Generate tree definition string for the GenericMonitoringTool.Histograms property.
Definition: GenericMonitoringTool.py:491
GenericMonitoringTool.defineHistogram
def defineHistogram(flags, varname, type='TH1F', path=None, title=None, weight=None, xbins=100, xmin=0, xmax=1, xlabels=None, ybins=None, ymin=None, ymax=None, ylabels=None, zmin=None, zmax=None, zlabels=None, opt=None, convention=None, cutmask=None, treedef=None, merge=None)
Generate histogram definition string for the GenericMonitoringTool.Histograms property.
Definition: GenericMonitoringTool.py:306
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
Trk::split
@ split
Definition: LayerMaterialProperties.h:38