ATLAS Offline Software
Public Member Functions | Private Member Functions | List of all members
common.CaloClusterCorrSetup Class Reference
Collaboration diagram for common.CaloClusterCorrSetup:

Public Member Functions

def make_corrections (self, flags, corrclass, key=None, suffix='', version=None, corrlist=None, cells_name=None, source=None, **kw)
 
def lookup_version (self, flags, version, corrclass)
 
def geom_match (self, datasource, geom)
 
def get_generation (cls, flags)
 
def make_ForPool (self, flags, keys, corrclass)
 Code for writing to pool. More...
 
def maybe_make_correction_for_pool (self, flags, sgkeys, tool_names, key, cspec, corrclass)
 
def add_dummies (self, sgkeys, valid_keys, generation)
 
def config_for_pool (self, flags, keys, corrclass)
 

Private Member Functions

def _geom_match1 (self, geom)
 

Detailed Description

Definition at line 162 of file common.py.

Member Function Documentation

◆ _geom_match1()

def common.CaloClusterCorrSetup._geom_match1 (   self,
  geom 
)
private

Definition at line 345 of file common.py.

345  def _geom_match1 (self, geom):
346  for (pat, v) in self.geom_versions:
347  if fnmatchcase (geom, pat):
348  return v
349  return None

◆ add_dummies()

def common.CaloClusterCorrSetup.add_dummies (   self,
  sgkeys,
  valid_keys,
  generation 
)

Definition at line 465 of file common.py.

465  def add_dummies (self, sgkeys, valid_keys, generation):
466  CaloDummyCorrection = CompFactory.CaloDummyCorrection # CaloClusterCorrection
467  toolnames = {}
468  for sgkey in sgkeys.keys():
469  ll = sgkey.split ('-')
470  if len(ll) == 1:
471  name = ll[0]
472  else:
473  (name, ver) = ll
474  toolnames[name] = 1
475  for name in toolnames.keys():
476  (corrclass, basename) = name.split ('.')
477  sgkey = name + '-dummy'
478  tagname = "%s.%s%s-dummy" % (corrclass, generation, basename)
479  folder = '/CALO/%s/%s' % (corrclass, basename)
480  sgkeys[sgkey] = []
481  for key in valid_keys:
482  toolname = basename + key + '-dummy'
483  tool = CaloDummyCorrection (toolname)
484  tool.prefix = key + '.'
485  sgkeys[sgkey].append (tool)
486  _alltools[toolname] = (folder, tagname, sgkey)
487  return
488 
489 

◆ config_for_pool()

def common.CaloClusterCorrSetup.config_for_pool (   self,
  flags,
  keys,
  corrclass 
)

Definition at line 491 of file common.py.

491  def config_for_pool (self, flags, keys, corrclass):
492  result = ComponentAccumulator()
493 
494  corr_output_list = []
495  tag_list = []
496 
497  generation = self.get_generation (flags)
498 
499  (sgkeys, ca) = self.make_ForPool (flags, keys, corrclass)
500  ca.popPrivateTools()
501  result.merge (ca)
502  self.add_dummies (sgkeys, keys, generation)
503 
504  for (sgkey, tools) in sgkeys.items():
505  if len (tools) == 0: continue
506  name = 'write_' + sgkey
507  name = name.replace ('.', '_')
508 
509  # In CaloRec
510  alg = CompFactory.CaloClusterCorrDBWriter (name,
511  key = sgkey,
512  ClusterCorrectionTools = tools)
513  result.addEventAlgo (alg)
514 
515 
516  corr_output_list.append ('CaloRec::ToolConstants#' +
517  sgkey + '#' +
518  folder (tools[0]))
519  tag_list.append (tag (tools[0]))
520 
521  print ("Final OutputList:")
522  print (corr_output_list)
523  print (tag_list)
524 
525  return (corr_output_list, tag_list, result)
526 
527 

◆ geom_match()

def common.CaloClusterCorrSetup.geom_match (   self,
  datasource,
  geom 
)

Definition at line 350 of file common.py.

350  def geom_match (self, datasource, geom):
351  if not geom: geom = ''
352  vv = self._geom_match1 (datasource + '-' + geom)
353  if not vv:
354  vv = self._geom_match1 (geom)
355  if not vv:
356  vv = self.newest_version
357  tryhier = True
358  if vv.startswith ('NOHIER#'):
359  tryhier = False
360  vv = vv[7:]
361  return (vv, tryhier)
362 
363 

◆ get_generation()

def common.CaloClusterCorrSetup.get_generation (   cls,
  flags 
)

Definition at line 366 of file common.py.

366  def get_generation (cls, flags):
367  generation = cls.correction_generation_default
368  gen2 = getattr (flags.Calo.ClusterCorrection, cls.correction_generation_flag_name)
369  if gen2:
370  generation = gen2
371  if generation != '':
372  generation = generation + '-'
373  return generation
374 
375 

◆ lookup_version()

def common.CaloClusterCorrSetup.lookup_version (   self,
  flags,
  version,
  corrclass 
)

Definition at line 331 of file common.py.

331  def lookup_version (self, flags, version, corrclass):
332  vcorrlist = self.versions.get (version)
333  if vcorrlist is None and version.startswith ('@'):
334  findvers = _find_version_from_cool_tag (flags, version[1:], corrclass)
335  vcorrlist = self.versions.get (findvers)
336  if vcorrlist is None:
337  vcorrlist = self.versions.get ('@')
338  if vcorrlist is None:
339  raise CaloCorrectionConfigError\
340  ("Can't find global correction version %s." % version)
341  return (vcorrlist, version)
342 
343 

◆ make_corrections()

def common.CaloClusterCorrSetup.make_corrections (   self,
  flags,
  corrclass,
  key = None,
  suffix = '',
  version = None,
  corrlist = None,
  cells_name = None,
  source = None,
**  kw 
)

Definition at line 191 of file common.py.

191  def make_corrections (self,
192  flags,
193  corrclass,
194  key = None,
195  suffix = '',
196  version = None,
197  corrlist = None,
198  cells_name = None,
199  source = None,
200  **kw):
201 
202  # Make a logger.
203  log = logging.getLogger ('CaloClusterCorrection')
204 
205  tryhier = False
206 
207  # First, find the appropriate overall version string to use,
208  # if it wasn't specified explicitly.
209  if version is None:
210  # First see if the flag was set to override the version.
211  # at the top-level.
212  v = getattr (flags.Calo.ClusterCorrection, self.version_override_flag_name)
213  if v:
214  version = v
215 
216  if version is None:
217  # No explicitly specified version.
218  # Try to guess it from the data source + geometry string.
219  # Otherwise, use the latest version.
220  geom = flags.GeoModel.AtlasVersion
221  datasource = 'geant4' if flags.Input.isMC else 'data'
222  (version, tryhier) = self.geom_match (datasource, geom)
223 
224  # Get the correction generation.
225  generation = self.get_generation(flags)
226 
227  # Use the default source if one wasn't specified.
228  if source is None:
229  source = flags.Calo.ClusterCorrection.defaultSource
230 
231  if not isinstance (source, list):
232  source = [source]
233  if CALOCORR_COOL not in source:
234  tryhier = False
235 
236  if tryhier and version[0] != '@':
237  cl = corrclass
238  if flags.Input.isMC:
239  cl = cl[0:4] + 'Ofl' + cl[4:]
240  version = "@%s-%s%s" % (cl, generation, version)
241 
242  # Only use COOL if we're actually trying to resolve a COOL tag.
243  # Otherwise we can run into problems: it looks like `ununsed'
244  # COOL tags are removed in DB replicas.
245  if version[0] != '@' and len(source) > 0:
246  if CALOCORR_COOL in source:
247  source.remove (CALOCORR_COOL)
248 
249  (vcorrlist, version) = self.lookup_version (flags, version, corrclass)
250 
251  # Default to the standard list if no explicit correction list.
252  if corrlist is None:
253  corrlist = vcorrlist
254 
255  log.info ("%s corrections for %s (%s) using version %s" %
256  (self.name, key, suffix, version))
257 
258  # Now, walk through the list of corrections.
259  out = ComponentAccumulator()
260  tools = []
261  for cspec in corrlist:
262  (func, this_version, this_order, extra_args) = \
263  split_version_spec (cspec)
264 
265  # If the version or extra args isn't specified here,
266  # look in the internal corrlist to see if we find it there.
267  if this_version == '' or extra_args == []:
268  for vcspec in vcorrlist:
269  if vcspec[0] == func:
270  (vfunc, vversion, vorder, vextra_args) = \
271  split_version_spec (vcspec)
272  if this_version == '':
273  this_version = vversion
274  if extra_args == []:
275  extra_args = vextra_args
276  if this_order == 0:
277  this_order = vorder
278  break
279 
280  elif version[0] == '@' and not corrlist:
281  this_version = version #pragma: NO COVER
282 
283  if this_version == '@':
284  this_version = version
285 
286  # Start building the other variables to use in the call.
287  this_args = dict (extra_args)
288  this_key = key
289  this_suffix = suffix
290  this_cells_name = cells_name
291  this_source = source
292 
293  corrname = func.__name__
294 
295  # Look for any overriders in our keyword list.
296  for (k, v) in kw.items():
297  if k == corrname + '_suffix':
298  this_suffix = v
299  elif k == corrname + '_key':
300  this_key = v
301  elif k == corrname + '_cells_name':
302  this_cells_name = v
303  elif k == corrname + '_source':
304  this_source = v
305  elif k == corrname + '_version':
306  this_version = v
307  elif k == corrname + '_order':
308  this_order = v
309  elif k.startswith (corrname + '_'):
310  this_args[k[len(corrname)+1:]] = v
311 
312  # Make the tool.
313  ca = func (flags,
314  this_cells_name,
315  this_suffix,
316  this_version,
317  this_key,
318  this_source,
319  generation = generation,
320  order = this_order,
321  **this_args)
322  tools.append (out.popToolsAndMerge (ca))
323 
324  out.setPrivateTools (tools)
325  return out
326 
327 

◆ make_ForPool()

def common.CaloClusterCorrSetup.make_ForPool (   self,
  flags,
  keys,
  corrclass 
)

Code for writing to pool.

Make a set of corrections for writing to pool.

Definition at line 380 of file common.py.

380  def make_ForPool (self, flags, keys, corrclass):
381  # Map from SG key to a list of tool instances.
382  sgkeys = {}
383 
384  # Names of all tools made so far
385  tool_names = set()
386 
387  # Map from (func, version) to (order, globversion).
388  # For consistency checking.
389  ordermap = {}
390 
391  result = ComponentAccumulator()
392  tools = []
393 
394  # Go through each version, and make corrections.
395  for (v,l) in self.versions.items():
396  if v.startswith ('@'): continue
397  last_order = 0
398  last_funcname = '(none)'
399  for c in l:
400  # Consistency check: tool lists should be sorted in order.
401  (func, version, order, extra_args) = split_version_spec (c)
402  if order <= last_order:
403  raise CaloCorrectionConfigError\
404  ("Tools for global version %s are not in order!"
405  " %d(%s) < %d(%s)" % (v, order, func.__name__,
406  last_order, last_funcname))
407  last_order = order
408  last_funcname = func.__name__
409 
410  # Consistency check: a given tool func/version should
411  # always have the same order setting.
412  okey = (func, version)
413  if okey not in ordermap:
414  ordermap[okey] = (order, v)
415  elif ordermap[okey][0] != order:
416  raise CaloCorrectionConfigError\
417  ("Tool %s has order %d in %s but order %d in %s!" %
418  (func.__name__, order, v,
419  ordermap[okey][0], ordermap[okey][1]))
420 
421  # Find the list of valid keys for this tool.
422  valid_keys = func (flags,
423  None,
424  version = version,
425  key = '@VALID_KEYS')
426  if valid_keys is None:
427  valid_keys = keys
428  for key in valid_keys:
429  ca = self.maybe_make_correction_for_pool (flags,
430  sgkeys,
431  tool_names,
432  key, c,
433  corrclass)
434  if ca:
435  tools.append (ca.popPrivateTools())
436  result.merge (ca)
437 
438  result.setPrivateTools (tools)
439 
440  return (sgkeys, result)
441 
442 

◆ maybe_make_correction_for_pool()

def common.CaloClusterCorrSetup.maybe_make_correction_for_pool (   self,
  flags,
  sgkeys,
  tool_names,
  key,
  cspec,
  corrclass 
)

Definition at line 443 of file common.py.

443  def maybe_make_correction_for_pool (self, flags,
444  sgkeys, tool_names, key, cspec,
445  corrclass):
446  (func, version, order, extra_args) = split_version_spec (cspec)
447  name = func.__name__ + '_' + version + '_' + key
448  if name in tool_names:
449  return None
450  ca = func (flags,
451  None, '', version, key, CALOCORR_TOPOOL,
452  generation = self.get_generation (flags),
453  order = order)
454  if ca is None:
455  return None
456  tool = ca.popPrivateTools()
457  if tool is not None and folder(tool).find ('/' + corrclass + '/') >= 0:
458  tool_names.add (name)
459  sgkeys.setdefault (sgkey(tool), []).append (tool)
460  ca.setPrivateTools (tool)
461  return ca
462 
463 

The documentation for this class was generated from the following file:
common.sgkey
def sgkey(tool)
Definition: common.py:1028
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
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:224
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
common.folder
def folder(tool)
Definition: common.py:1018