ATLAS Offline Software
Loading...
Searching...
No Matches
common.CaloClusterCorrSetup Class Reference
Collaboration diagram for common.CaloClusterCorrSetup:

Public Member Functions

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

Public Attributes

 name
 geom_versions

Protected Member Functions

 _geom_match1 (self, geom)

Detailed Description

Definition at line 161 of file common.py.

Member Function Documentation

◆ _geom_match1()

common.CaloClusterCorrSetup._geom_match1 ( self,
geom )
protected

Definition at line 344 of file common.py.

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

◆ add_dummies()

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

Definition at line 464 of file common.py.

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

◆ config_for_pool()

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

Definition at line 490 of file common.py.

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

◆ geom_match()

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

Definition at line 349 of file common.py.

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

◆ get_generation()

common.CaloClusterCorrSetup.get_generation ( cls,
flags )

Definition at line 365 of file common.py.

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

◆ lookup_version()

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

Definition at line 330 of file common.py.

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

◆ make_corrections()

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

Definition at line 190 of file common.py.

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

◆ make_ForPool()

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 379 of file common.py.

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

◆ maybe_make_correction_for_pool()

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

Definition at line 442 of file common.py.

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

Member Data Documentation

◆ geom_versions

common.CaloClusterCorrSetup.geom_versions

Definition at line 345 of file common.py.

◆ name

common.CaloClusterCorrSetup.name

Definition at line 255 of file common.py.


The documentation for this class was generated from the following file: