Skip to content

Commit 3af34b0

Browse files
sawenzelalcaliva
authored andcommitted
O2DPG-MC: Possibility to pass additional external user settings
This commit provides the possibility to inject external choices for configurable params into the MC workflow construction. This is done by setting up a JSON file, e.g. local_config.json, an by passing this file to the workflow construction with the new `--overwrite-config local_config.json` command line option. This new option allows to conveniently set configurable params from the outside (without having to specify the global list of configurations). The motivation for this development came from the wish to set the busy time for EMC digitization. This is now possible with the following local_config.json: ``` { "EMCSimParam": { "mBusyTime": 0 } } ``` Overall, this development scales to all such external settings and avoids adding specific detector-specific command line options in o2dpg_sim_workflow.py. (cherry picked from commit dd1ded7)
1 parent acd0a73 commit 3af34b0

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

MC/bin/o2dpg_sim_workflow.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
sys.path.append(join(dirname(__file__), '.', 'o2dpg_workflow_utils'))
3737

38-
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers
38+
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts
3939
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
4040
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg
4141

@@ -52,8 +52,9 @@
5252
parser.add_argument('--conditionDB',help="CCDB url for QC workflows", default='http://alice-ccdb.cern.ch')
5353
parser.add_argument('--qcdbHost',help="QCDB url for QC object uploading", default='http://ali-qcdbmc-gpn.cern.ch:8083')
5454
parser.add_argument('--condition-not-after', type=int, help="only consider CCDB objects not created after this timestamp (for TimeMachine)", default=3385078236000)
55-
parser.add_argument('--orbitsPerTF', type=int, help="Timeframe size in number of LHC orbits", default=128)
56-
parser.add_argument('--anchor-config',help="JSON file to contextualise workflow with external configs (config values etc.) for instance comping from data reco workflows.", default='')
55+
parser.add_argument('--orbitsPerTF', type=int, help="Timeframe size in number of LHC orbits", default=32)
56+
parser.add_argument('--anchor-config',help="JSON file to contextualise workflow with external configs (config values etc.) for instance coming from data reco workflows.", default='')
57+
parser.add_argument('--overwrite-config',help="extra JSON file with configs (config values etc.) overwriting defaults or the config coming from --anchor-config", default='')
5758
parser.add_argument('--dump-config',help="Dump JSON file with all settings used in workflow", default='user_config.json')
5859
parser.add_argument('-ns',type=int,help='number of signal events / timeframe', default=20)
5960
parser.add_argument('-gen',help='generator: pythia8, extgen', default='')
@@ -199,6 +200,13 @@ def load_external_config(configfile):
199200
# we load a generic config
200201
print ("** Using generic config **")
201202
anchorConfig = create_sim_config(args)
203+
# we apply additional external user choices for the configuration
204+
# this will overwrite config from earlier stages
205+
if args.overwrite_config != '':
206+
# apply final JSON overwrite
207+
config_overwrite = load_external_config(args.overwrite_config)
208+
# merge the dictionaries into anchorConfig, the latter takes precedence
209+
merge_dicts(anchorConfig, config_overwrite)
202210

203211
# write this config
204212
config_key_param_path = args.dump_config
@@ -1073,7 +1081,7 @@ def createRestDigiTask(name, det='ALLSMALLER'):
10731081
FT0FV0EMCCTPDIGItask['cmd'] = ('','ln -nfs ../bkg_HitsFT0.root . ; ln -nfs ../bkg_HitsFV0.root . ; ln -nfs ../bkg_HitsEMC.root; ln -nfs ../bkg_Kine.root; ')[doembedding]
10741082
FT0FV0EMCCTPDIGItask['cmd'] += '${O2_ROOT}/bin/o2-sim-digitizer-workflow ' + getDPL_global_options() + ' -n ' + str(args.ns) + simsoption \
10751083
+ ' --onlyDet FT0,FV0,EMC,CTP --interactionRate ' + str(INTRATE) + ' --incontext ' + str(CONTEXTFILE) \
1076-
+ ' --disable-write-ini' + putConfigValuesNew(localCF={"DigiParams.seed" : str(TFSEED)}) \
1084+
+ ' --disable-write-ini' + putConfigValuesNew(listOfMainKeys=['EMCSimParam'], localCF={"DigiParams.seed" : str(TFSEED)}) \
10771085
+ (' --combine-devices','')[args.no_combine_dpl_devices] + ('',' --disable-mc')[args.no_mc_labels] + QEDdigiargs \
10781086
+ ' --forceSelectedDets'
10791087
workflow['stages'].append(FT0FV0EMCCTPDIGItask)

MC/bin/o2dpg_workflow_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,15 @@ def matches_or_inherits_label(taskid, label, cache):
308308
if (matches_or_inherits_label(taskid, "RECO", matches_label)):
309309
# now we do the final adjust (as annotation) in the workflow itself
310310
workflowspec['stages'][taskid]["alternative_alienv_package"] = package
311+
312+
def merge_dicts(dict1, dict2):
313+
"""
314+
merges dict2 into dict1 (potentially overwriting values)
315+
"""
316+
for key, value in dict2.items():
317+
if key in dict1 and isinstance(dict1[key], dict) and isinstance(value, dict):
318+
# If both are dictionaries, merge them recursively
319+
merge_dicts(dict1[key], value)
320+
else:
321+
# Otherwise, overwrite dict1's value with dict2's value
322+
dict1[key] = value

0 commit comments

Comments
 (0)