5from AthenaConfiguration.ComponentAccumulator
import (ComponentAccumulator,)
6from AthenaConfiguration.AccumulatorCache
import AccumulatorCache
7from AthenaConfiguration.ComponentFactory
import CompFactory
9from AthenaCommon.Logging
import log
11from pprint
import pformat
16 vector_outputs =
set()
17 for pname,pdef
in conf.getDefaultProperties().items():
18 if pname.endswith(
'Key'):
21 prop = getattr(conf,key)
22 if prop.type().startswith(
'std::vector')
and \
24 vector_outputs.add(f
'{prop.type()}#{prop.path}')
36 cfg = ComponentAccumulator()
37 alg = CompFactory.GlobalSim.GlobalSimulationAlg(
'GlobalSimulationAlg')
41 tool = CompFactory.GlobalSim.eEmEg1BDTMultAlgTool(
42 f
'Egamma1BDTAlgTool_{thrname}',
44 Eg1BDT=workingPoint[
'value'],
45 Eg1BDT_op=workingPoint[
'compOp'],
46 eEmEg1BDTTOBContainerKey=input[
'eEmEg1BDTTOBContainer'],
51 alg.TIPwriters = [tool]
55 return cfg, vector_outputs
58def eEmEg1MultCfg(flags,thrname,input,et_low,workingPoint,startbit,nbits,**kwargs):
59 cfg = ComponentAccumulator()
60 alg = CompFactory.GlobalSim.GlobalSimulationAlg(
'GlobalSimulationAlg')
64 tool = CompFactory.GlobalSim.eEmMultAlgTool(
65 f
'eEmMultAlgTool_{thrname}',
67 rhad=workingPoint[
'rhad'],
68 rhad_op=workingPoint[
'rhad_op'],
69 reta=workingPoint[
'reta'],
70 reta_op=workingPoint[
'reta_op'],
71 wstot=workingPoint[
'wstot'],
72 wstot_op=workingPoint[
'wstot_op'],
73 eEmTOBs=input[
'eEmTOBContainer'],
78 alg.TIPwriters = [tool]
82 return cfg, vector_outputs
86 cfg = ComponentAccumulator()
87 alg = CompFactory.GlobalSim.GlobalSimulationAlg(
'GlobalSimulationAlg')
88 tool = CompFactory.GlobalSim.CommonMultAlgTool(
89 f
'commonMult_{thrname}',
94 CommonTOBsKey = list(input.values())[0],
98 alg.TIPwriters = [tool]
102 return cfg, vector_outputs
106threshold_type_configs = {
107 'eEMBDT': eEmEg1BDTMultCfg,
108 'eEMBeeDeeTee': eEmEg1BDTMultCfg,
109 'eEMEg1': eEmEg1MultCfg,
112 return threshold_type_configs.get(threshold,commonMultCfg)
118 subname, subprop = substr.split(
'.')
120 subtype, subname = subname.split(
'/')
123 if subname
not in props:
124 props[subname] = CompFactory.getComp(f
"GlobalSim::{subtype}")(
129 props[subname][subprop] = subval
136 cfg = ComponentAccumulator()
143 props[i[0]+
'Key'] = i[1]
148 props[o[0]+
'Key'] = o[1]
150 for prop, val
in params.items():
155 alg = CompFactory.getComp(f
"GlobalSim::{type}")(
158 cfg.addEventAlgo(alg)
163 return cfg, vector_outputs
171 cfg = ComponentAccumulator()
179 props[i[0]+
'Key'] = i[1]
184 props[o[0]+
'Key'] = o[1]
186 for prop, val
in params.items():
191 algtool = CompFactory.getComp(f
"GlobalSim::{type}")(
194 alg = CompFactory.GlobalSim.GlobalSimulationAlg(
195 name.replace(
"AlgTool",
"Alg"),
196 globalsim_algs = [algtool]
198 cfg.addEventAlgo(alg)
201 return cfg, vector_outputs
210 modulename, cfgname = name.rsplit(
'.',1)
211 module = importlib.import_module(modulename)
212 return lambda flags, **params: (getattr(module,cfgname)(flags, **params),
set())
213 elif name.endswith(
'AlgTool'):
214 return GenericTOBProducerAlgToolCfg
215 elif name.endswith(
'Alg'):
216 return GenericTOBProducerAlgCfg
227 if isinstance(io,str):
228 expanded.append((io,io))
230 if isinstance(io,list):
231 expanded += [(el,el)
for el
in io]
232 elif isinstance(io,dict):
233 expanded += [(ttype,tname)
for ttype,tname
in io.items()]
235 raise TypeError(f
"Unhandled type {type(io)} for I/O definition")
236 return tuple(expanded)
251 'L1_jFexSRJetRoI_ReSim',
256 all_vector_outputs =
set()
258 upstream_deps =
set()
259 input_list = list(input)
260 while len(input_list)>0:
261 tob = input_list.pop()
264 if tob
in inputs_to_gsim:
266 assert tob
in tobs_to_providers, f
"Configuration for {tob} provider not specified in L0 menu!"
267 provider = tobs_to_providers[tob]
269 assert cfg_fn
is not None, f
"No configuration available for {provider['type']}"
270 params = dict(provider[
'parameters'])
271 if '.' not in provider[
'type']:
273 name = provider[
'name'],
274 type = provider[
'type'],
275 input = provider[
'input'],
276 output = provider[
'output'],
278 TOB_cfg, vector_outputs = cfg_fn(flags,**params)
279 TOB_CAs.append(TOB_cfg)
280 all_vector_outputs |= vector_outputs
281 log.debug(f
"{provider['name']} needs:")
282 log.debug(pformat(provider[
'input']))
283 upstream_deps |=
set(i[1]
for i
in provider[
'input'])
290 if recurse
and upstream_deps:
291 upstream_CAs, upstream_vecs =
config_TOB_providers(flags, tobs_to_providers, upstream_deps, recurse=
True)
292 TOB_CAs += upstream_CAs
293 all_vector_outputs |= upstream_vecs
295 return TOB_CAs, all_vector_outputs
301def L0HypoCfg(flags, threshold, hypo_specs, tobs_to_providers, triggerlines):
303 cfg = ComponentAccumulator()
308 for hypo_type, hypo_type_dict
in hypo_specs.items():
309 if threshold
in hypo_type_dict[
'thresholds']:
310 this_thr = hypo_type_dict[
'thresholds'][threshold]
311 hypo_dict = dict(this_thr)
312 hypo_dict[
'type'] = hypo_type
313 hypo_dict[
'input'] = hypo_type_dict[
'input']
314 log.info(f
" Menu contains specs for {threshold}: {this_thr}")
315 if 'workingPoint' in hypo_dict:
316 hypo_dict[
'workingPoint'] = hypo_type_dict[
'workingPoints'][this_thr[
'workingPoint']]
318 for line
in triggerlines:
319 if threshold == line[
'name']:
320 hypo_dict[
'startbit'] = line[
'startbit']
321 hypo_dict[
'nbits'] = line[
'nbits']
324 assert hypo_dict
is not None, f
"Threshold {threshold} not in L0 menu"
325 assert 'startbit' in hypo_dict, f
"Threshold {threshold} missing TIP position"
327 log.debug(pformat(hypo_dict))
330 cfg.addSequence(CompFactory.AthSequencer(
'GlobalSimulationInputs'))
333 seqname = f
"GlobalSimulationInputs_{hypo_dict['type']}"
334 cfg.addSequence(CompFactory.AthSequencer(seqname),parentName=
'GlobalSimulationInputs')
336 all_vector_outputs =
set()
340 all_vector_outputs |= vector_outputs
349 all_input_CAs, input_vector_outputs =
config_TOB_providers(flags, tobs_to_providers, [i[1]
for i
in inputs])
350 all_vector_outputs |= input_vector_outputs
352 for ca
in reversed(all_input_CAs):
353 cfg.merge(ca,seqname)
359 return cfg, all_vector_outputs, hypo_dict
365 force_config_TOBs=[],
367 print_detailed_config=False
369 menu = json.load(open(json_name))
372 gsim_alg_prefix =
"GlobalSim_"
374 cfg = ComponentAccumulator()
377 cfg.addSequence(CompFactory.AthSequencer(
'GlobalSimPrereqs'))
379 cfg.addSequence(CompFactory.AthSequencer(
'LArPreprocessing'), parentName=
'GlobalSimPrereqs')
380 from GlobalSimulation.LArCellPreparationAlgConfig
import LArCellPreparationAlgCfg
381 cfg.merge( LArCellPreparationAlgCfg(
383 name = gsim_alg_prefix+
'LArCellPreparationAlg',
384 GlobalLArCellsKey=
'GlobalLArCells',
386 sequenceName=
'LArPreprocessing'
389 cfg.addSequence(CompFactory.AthSequencer(
'GlobalSimulation'))
391 all_vector_outputs =
set()
397 tobs_to_providers = {}
398 for pname, provider
in menu[
'algorithms'].items():
399 log.debug(f
"{pname} --> {provider}")
401 log.debug(
'Outputs:')
402 log.debug(pformat(output))
403 _provider = dict(provider)
405 _provider[
'type'], _provider[
'name'] = pname.split(
'/',1)
407 _provider[
'type'] = _provider[
'name'] = pname
409 _provider[
'name'] = gsim_alg_prefix + _provider[
'name']
410 _provider[
'input'] =
expand_io(provider[
'input'])
411 _provider[
'output'] = output
412 _provider[
'parameters'] = {}
413 _provider[
'parameters'].update(provider.get(
'parameters',{}))
414 for otuple
in output:
415 assert otuple[1]
not in tobs_to_providers, f
"Duplicate provider for {otuple}"
416 tobs_to_providers[otuple[1]] = _provider
418 log.debug(pformat(tobs_to_providers))
422 active_thresholds =
set()
424 for item, item_dict
in menu[
'items'].items():
425 for threshold
in item_dict[
'thresholds']:
426 active_thresholds.add(threshold)
428 for threshold
in active_thresholds:
429 hypo_ca, vector_outputs, hypo_dict =
L0HypoCfg(
432 hypo_specs = menu[
'hypotheses'],
433 tobs_to_providers = tobs_to_providers,
434 triggerlines = menu[
'connectors'][
'L0Global'][
'triggerlines']
436 cfg.merge(hypo_ca,
'GlobalSimulation')
437 all_vector_outputs |= vector_outputs
440 hypo_bits = sum([1<<i
for i
in range(hypo_dict[
'startbit'],hypo_dict[
'startbit']+hypo_dict[
'nbits'])])
441 assert TIP_bits & hypo_bits == 0, f
"TIP bits for {threshold} overlap other thresholds"
442 TIP_bits = TIP_bits + hypo_bits
445 for tob
in force_config_TOBs:
446 recurse = tob
not in ignore_prereqs
447 log.info(f
"Explicitly configuring {tob} from menu {'with' if recurse else 'without'} prereqs")
450 for ca
in reversed(tob_cfgs):
451 cfg.merge(ca,
'GlobalSimulation')
452 all_vector_outputs |= vector_outputs
455 from OutputStreamAthenaPool.OutputStreamConfig
import addToAOD
456 cfg.merge(addToAOD(flags,all_vector_outputs))
458 if print_detailed_config:
459 cfg.printConfig(summariseProps=
True)
465 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
466 flags = initConfigFlags()
469 parser = flags.getArgumentParser(
470 prog=
'GlobalSimJsonConfig',
471 description=
'Prototype Global Simulation steering from json menu',
472 epilog=
'Give us 25Gbps or give us ...'
475 '-j',
'--config-json',
476 default=
'GlobalSimulation/L0GlobalTestMenuv1_Khoo.json',
477 help=
'The input json config (L0 menu prototype)'
483 help=
'List of TOBs to force on'
489 help=
'List of forced TOBs for which prerequisites should be ignored'
492 args = flags.fillFromArgs(parser=parser)
495 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
496 cfg = MainServicesCfg(flags)
498 from AthenaConfiguration.Enums
import Format
499 if flags.Input.Format==Format.POOL:
500 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
501 cfg.merge(PoolReadCfg(flags))
502 elif flags.Input.Format==Format.BS:
503 from ByteStreamCnvSvc.ByteStreamConfig
import ByteStreamReadCfg
504 cfg.merge(ByteStreamReadCfg(flags))
506 from TrigConfigSvc.TrigConfigSvcCfg
import L1ConfigSvcCfg
507 cfg.merge(L1ConfigSvcCfg(flags))
509 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig
import eFexByteStreamToolCfg, jFexRoiByteStreamToolCfg, gFexByteStreamToolCfg
511 if flags.Trigger.L1.doeFex: decoderTools += [cfg.popToolsAndMerge(eFexByteStreamToolCfg(flags=flags,name=
'eFexBSDecoderTool',writeBS=
False))]
512 if flags.Trigger.L1.dojFex: decoderTools += [cfg.popToolsAndMerge(jFexRoiByteStreamToolCfg(flags=flags,name=
"jFexBSDecoderTool",writeBS=
False))]
513 if flags.Trigger.L1.dogFex: decoderTools += [cfg.popToolsAndMerge(gFexByteStreamToolCfg(flags=flags,name=
"gFexBSDecoderTool",writeBS=
False))]
514 cfg.addEventAlgo(CompFactory.L1TriggerByteStreamDecoderAlg(
515 name=
"L1TriggerByteStreamDecoder",
516 DecoderTools=decoderTools
519 raise RuntimeError(f
'Unrecognised input file format {flags.Input.Format} for {flags.Input.Files}')
521 from TrigValTools.TrigValSteering.Common
import find_file_in_path
522 jsonpath = find_file_in_path(args.config_json,
'DATAPATH')
523 cfg.merge(
GlobalSimJsonCfg(flags, jsonpath, args.force_TOBs, args.ignore_prereqs, print_detailed_config=
True) )
529if __name__==
"__main__":
config_TOB_providers(flags, tobs_to_providers, input, recurse=True)
eEmEg1MultCfg(flags, thrname, input, et_low, workingPoint, startbit, nbits, **kwargs)
GenericTOBProducerAlgToolCfg(flags, name, type, input, output, **params)
forward_to_subtool(substr, subval, props)
threshold_type_to_hypo_config(threshold)
GlobalSimJsonCfg(flags, json_name, force_config_TOBs=[], ignore_prereqs=[], print_detailed_config=False)
get_all_vector_keys(conf)
commonMultCfg(flags, thrname, input, et_low, startbit, nbits, **kwargs)
GenericTOBProducerAlgCfg(flags, name, type, input, output, **params)
eEmEg1BDTMultCfg(flags, thrname, input, et_low, workingPoint, startbit, nbits, **kwargs)
L0HypoCfg(flags, threshold, hypo_specs, tobs_to_providers, triggerlines)