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():
157 alg = CompFactory.getComp(f
"GlobalSim::{type}")(
160 except AttributeError:
161 props_nokey = {k.replace(
'Key',
''):v
for k,v
in props.items()}
162 alg = CompFactory.getComp(f
"GlobalSim::{type}")(
165 cfg.addEventAlgo(alg)
170 return cfg, vector_outputs
178 cfg = ComponentAccumulator()
186 props[i[0]+
'Key'] = i[1]
191 props[o[0]+
'Key'] = o[1]
193 for prop, val
in params.items():
198 algtool = CompFactory.getComp(f
"GlobalSim::{type}")(
201 alg = CompFactory.GlobalSim.GlobalSimulationAlg(
202 name.replace(
"AlgTool",
"Alg"),
203 globalsim_algs = [algtool]
205 cfg.addEventAlgo(alg)
208 return cfg, vector_outputs
217 modulename, cfgname = name.rsplit(
'.',1)
218 module = importlib.import_module(modulename)
219 return lambda flags, **params: (getattr(module,cfgname)(flags, **params),
set())
220 elif name.endswith(
'AlgTool'):
221 return GenericTOBProducerAlgToolCfg
222 elif name.endswith(
'Alg')
or name
in [
'TOBTextWriter',
'TOBTextReader']:
223 return GenericTOBProducerAlgCfg
234 if isinstance(io,str):
235 expanded.append((io,io))
237 if isinstance(io,list):
238 expanded += [(el,el)
for el
in io]
239 elif isinstance(io,dict):
240 expanded += [(ttype,tname)
for ttype,tname
in io.items()]
242 raise TypeError(f
"Unhandled type {type(io)} for I/O definition")
243 return tuple(expanded)
258 'L1_jFexSRJetRoI_ReSim',
263 all_vector_outputs =
set()
265 upstream_deps =
set()
266 input_list = list(input)
267 while len(input_list)>0:
268 tob = input_list.pop()
271 if tob
in inputs_to_gsim:
273 assert tob
in tobs_to_providers, f
"Configuration for {tob} provider not specified in L0 menu!"
274 provider = tobs_to_providers[tob]
276 assert cfg_fn
is not None, f
"No configuration available for {provider['type']}"
277 params = dict(provider[
'parameters'])
278 if '.' not in provider[
'type']:
280 name = provider[
'name'],
281 type = provider[
'type'],
282 input = provider[
'input'],
283 output = provider[
'output'],
285 TOB_cfg, vector_outputs = cfg_fn(flags,**params)
286 TOB_CAs.append(TOB_cfg)
287 all_vector_outputs |= vector_outputs
288 log.debug(f
"{provider['name']} needs:")
289 log.debug(pformat(provider[
'input']))
290 upstream_deps |=
set(i[1]
for i
in provider[
'input'])
299 TOB_CAs += upstream_CAs
300 all_vector_outputs |= upstream_vecs
302 return TOB_CAs, all_vector_outputs
308def L0HypoCfg(flags, threshold, hypo_specs, tobs_to_providers, triggerlines):
310 cfg = ComponentAccumulator()
315 for hypo_type, hypo_type_dict
in hypo_specs.items():
316 if threshold
in hypo_type_dict[
'thresholds']:
317 this_thr = hypo_type_dict[
'thresholds'][threshold]
318 hypo_dict = dict(this_thr)
319 hypo_dict[
'type'] = hypo_type
320 hypo_dict[
'input'] = hypo_type_dict[
'input']
321 log.info(f
" Menu contains specs for {threshold}: {this_thr}")
322 if 'workingPoint' in hypo_dict:
323 hypo_dict[
'workingPoint'] = hypo_type_dict[
'workingPoints'][this_thr[
'workingPoint']]
325 for line
in triggerlines:
326 if threshold == line[
'name']:
327 hypo_dict[
'startbit'] = line[
'startbit']
328 hypo_dict[
'nbits'] = line[
'nbits']
331 assert hypo_dict
is not None, f
"Threshold {threshold} not in L0 menu"
332 assert 'startbit' in hypo_dict, f
"Threshold {threshold} missing TIP position"
334 log.debug(pformat(hypo_dict))
337 cfg.addSequence(CompFactory.AthSequencer(
'GlobalSimulationInputs'))
340 seqname = f
"GlobalSimulationInputs_{hypo_dict['type']}"
341 cfg.addSequence(CompFactory.AthSequencer(seqname),parentName=
'GlobalSimulationInputs')
343 all_vector_outputs =
set()
347 all_vector_outputs |= vector_outputs
356 all_input_CAs, input_vector_outputs =
config_TOB_providers(flags, tobs_to_providers, [i[1]
for i
in inputs])
357 all_vector_outputs |= input_vector_outputs
359 for ca
in reversed(all_input_CAs):
360 cfg.merge(ca,seqname)
366 return cfg, all_vector_outputs, hypo_dict
372 ignore_menu_items=False,
373 force_config_TOBs=[],
376 print_detailed_config=False
378 menu = json.load(open(json_name))
380 gsim_alg_prefix =
"GlobalSim_"
382 cfg = ComponentAccumulator()
385 cfg.addSequence(CompFactory.AthSequencer(
'GlobalSimPrereqs'))
387 cfg.addSequence(CompFactory.AthSequencer(
'LArPreprocessing'), parentName=
'GlobalSimPrereqs')
388 from GlobalSimulation.LArCellPreparationAlgConfig
import LArCellPreparationAlgCfg
389 cfg.merge( LArCellPreparationAlgCfg(
391 name = gsim_alg_prefix+
'LArCellPreparationAlg',
392 GlobalLArCellsKey=
'GlobalLArCells',
394 sequenceName=
'LArPreprocessing'
397 cfg.addSequence(CompFactory.AthSequencer(
'GlobalSimulation'))
399 cfg.addService( CompFactory.GlobalSim.GraphSvc(SequenceNameFilter=
'GlobalSimulation'), create=
True )
401 all_vector_outputs =
set()
407 tobs_to_providers = {}
408 for pname, provider
in menu[
'algorithms'].items():
409 log.debug(f
"{pname} --> {provider}")
411 log.debug(
'Outputs:')
412 log.debug(pformat(output))
413 _provider = dict(provider)
415 _provider[
'type'], _provider[
'name'] = pname.split(
'/',1)
417 _provider[
'type'] = _provider[
'name'] = pname
419 _provider[
'name'] = gsim_alg_prefix + _provider[
'name']
420 _provider[
'input'] =
expand_io(provider[
'input'])
421 _provider[
'output'] = output
422 _provider[
'parameters'] = {}
423 _provider[
'parameters'].update(provider.get(
'parameters',{}))
424 for otuple
in output:
425 assert otuple[1]
not in tobs_to_providers, f
"Duplicate provider for {otuple}"
426 tobs_to_providers[otuple[1]] = _provider
428 log.debug(pformat(tobs_to_providers))
432 for key, (bitspec, filepath)
in txt_inputs.items():
433 if key
in tobs_to_providers:
434 log.warning(f
"Replacing {key} algorithm of type {tobs_to_providers[key]} with text reader")
436 log.info(f
"Inserting text reader to provide {key}")
437 tobs_to_providers[key] = {
438 'type':
'TOBTextReader',
439 'name': f
'{key}_{bitspec}_from_txt',
441 'output': [(
'Output',key)],
444 'InputFile': filepath
450 active_thresholds =
set()
452 if not ignore_menu_items:
453 for item, item_dict
in menu[
'items'].items():
454 for threshold
in item_dict[
'thresholds']:
455 active_thresholds.add(threshold)
457 for threshold
in active_thresholds:
458 hypo_ca, vector_outputs, hypo_dict =
L0HypoCfg(
461 hypo_specs = menu[
'hypotheses'],
462 tobs_to_providers = tobs_to_providers,
463 triggerlines = menu[
'connectors'][
'L0Global'][
'triggerlines']
465 cfg.merge(hypo_ca,
'GlobalSimulation')
466 all_vector_outputs |= vector_outputs
469 hypo_bits = sum([1<<i
for i
in range(hypo_dict[
'startbit'],hypo_dict[
'startbit']+hypo_dict[
'nbits'])])
470 assert TIP_bits & hypo_bits == 0, f
"TIP bits for {threshold} overlap other thresholds"
471 TIP_bits = TIP_bits + hypo_bits
474 for tob
in force_config_TOBs:
475 log.info(f
"Explicitly configuring {tob} from menu")
478 for ca
in reversed(tob_cfgs):
479 cfg.merge(ca,
'GlobalSimulation')
480 all_vector_outputs |= vector_outputs
485 for key, (bitspec, filepath)
in txt_outputs.items():
486 log.info(f
"Inserting text writer to record {key}")
488 CompFactory.GlobalSim.TOBTextWriter(
489 f
'{key}_{bitspec}_to_txt',
497 from OutputStreamAthenaPool.OutputStreamConfig
import addToAOD
498 cfg.merge(addToAOD(flags,all_vector_outputs))
500 if print_detailed_config:
501 cfg.printConfig(summariseProps=
True)
507 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
508 flags = initConfigFlags()
511 parser = flags.getArgumentParser(
512 prog=
'GlobalSimJsonConfig',
513 description=
'Prototype Global Simulation steering from json menu',
514 epilog=
'Give us 25Gbps or give us ...'
517 '-j',
'--config-json',
518 default=
'GlobalSimulation/L0GlobalTestMenuv1_Khoo.json',
519 help=
'The input json config (L0 menu prototype)'
522 '--ignore-menu-items',
524 help=
'Skip the L1 item thresholds for dependency resolution -- requires force-TOBs'
530 help=
'List of TOBs to force on'
537 List of text files to be read to provide inputs.
538 These will replace the standard prereq chains.
539 Format is bitspec:key:path.
547 List of text files into which containers should be written.
548 Format is bitspec:key:path.
553 args = flags.fillFromArgs(parser=parser)
556 if args.ignore_menu_items:
557 assert args.force_TOBs,
"Ignored menu without force-TOBs list -- nothing to do!"
559 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
560 cfg = MainServicesCfg(flags)
562 from AthenaConfiguration.Enums
import Format
563 if flags.Input.Format==Format.POOL:
564 from AthenaPoolCnvSvc.PoolReadConfig
import PoolReadCfg
565 cfg.merge(PoolReadCfg(flags))
566 elif flags.Input.Format==Format.BS:
567 from ByteStreamCnvSvc.ByteStreamConfig
import ByteStreamReadCfg
568 cfg.merge(ByteStreamReadCfg(flags))
570 from TrigConfigSvc.TrigConfigSvcCfg
import L1ConfigSvcCfg
571 cfg.merge(L1ConfigSvcCfg(flags))
573 from L1CaloFEXByteStream.L1CaloFEXByteStreamConfig
import eFexByteStreamToolCfg, jFexRoiByteStreamToolCfg, gFexByteStreamToolCfg
575 if flags.Trigger.L1.doeFex: decoderTools += [cfg.popToolsAndMerge(eFexByteStreamToolCfg(flags=flags,name=
'eFexBSDecoderTool',writeBS=
False))]
576 if flags.Trigger.L1.dojFex: decoderTools += [cfg.popToolsAndMerge(jFexRoiByteStreamToolCfg(flags=flags,name=
"jFexBSDecoderTool",writeBS=
False))]
577 if flags.Trigger.L1.dogFex: decoderTools += [cfg.popToolsAndMerge(gFexByteStreamToolCfg(flags=flags,name=
"gFexBSDecoderTool",writeBS=
False))]
578 cfg.addEventAlgo(CompFactory.L1TriggerByteStreamDecoderAlg(
579 name=
"L1TriggerByteStreamDecoder",
580 DecoderTools=decoderTools
583 raise RuntimeError(f
'Unrecognised input file format {flags.Input.Format} for {flags.Input.Files}')
589 k:(t,v)
for t,k,v
in [s.split(
':')
for s
in args.txt_inputs]
592 raise RuntimeError(f
'Failed to interpret text input list {args.txt_inputs}')
598 k:(t,v)
for t,k,v
in [s.split(
':')
for s
in args.txt_outputs]
601 raise RuntimeError(f
'Failed to interpret text output list {args.txt_inputs}')
603 from TrigValTools.TrigValSteering.Common
import find_file_in_path
604 jsonpath = find_file_in_path(args.config_json,
'DATAPATH')
608 args.ignore_menu_items,
612 print_detailed_config=
True
619if __name__==
"__main__":
eEmEg1MultCfg(flags, thrname, input, et_low, workingPoint, startbit, nbits, **kwargs)
GenericTOBProducerAlgToolCfg(flags, name, type, input, output, **params)
forward_to_subtool(substr, subval, props)
GlobalSimJsonCfg(flags, json_name, ignore_menu_items=False, force_config_TOBs=[], txt_inputs={}, txt_outputs={}, print_detailed_config=False)
threshold_type_to_hypo_config(threshold)
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)
config_TOB_providers(flags, tobs_to_providers, input)
L0HypoCfg(flags, threshold, hypo_specs, tobs_to_providers, triggerlines)