From 5a7e465016127bd7dbceb24b7fc92ab9e0b1b3d5 Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Mon, 16 Nov 2026 18:21:18 +0100 Subject: [PATCH] Restrict the active detectors to the chosen detector list This makes the MC workflow take only detectors that the o2-sim detector list builds. - The detector list is read like o2-sim --detectorList does, from O2_ROOT or a name:path custom file; an unreadable list is an error, as in o2-sim. - isActive() is false for modules the list does not build, and they are dropped from --readoutDetectors with a message, since o2-sim rejects them. - The ITS/IT3 choice in the task setup and the QED module list follow the list instead of its name. - An empty set of active detectors, also after removing ZDC, is now an error instead of enabling all. https://its.cern.ch/jira/browse/O2-7267 --- MC/bin/o2dpg_sim_workflow.py | 33 +++++++++++++++++++++++---------- MC/bin/o2dpg_workflow_utils.py | 16 +++++++++++++++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/MC/bin/o2dpg_sim_workflow.py b/MC/bin/o2dpg_sim_workflow.py index b1c44b7d2..3ff2d2a7e 100755 --- a/MC/bin/o2dpg_sim_workflow.py +++ b/MC/bin/o2dpg_sim_workflow.py @@ -41,7 +41,7 @@ sys.path.append(join(dirname(__file__), '.', 'o2dpg_workflow_utils')) -from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts +from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts, restrict_to_detector_list from o2dpg_qc_finalization_workflow import include_all_QC_finalization from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed @@ -310,8 +310,23 @@ def load_external_config(configfile): activeDetectors = ','.join(r & a) # the last case: simply take what comes from the anchored config -# convert to set/hashmap -activeDetectors = { det:1 for det in activeDetectors.split(',') if det not in args.skipModules and det not in args.skipReadout} +# convert to set/hashmap, keeping only detectors that the chosen detector list builds (e.g. no TRD in ALICE2.1) +try: + builtModules = restrict_to_detector_list(args.detectorList) +except (OSError, ValueError, KeyError, TypeError) as e: + print(f"Error: cannot read detector list {args.detectorList}: {e!r}") + sys.exit(1) +# IT3 replaces ITS when the detector list builds it +useIT3 = 'IT3' in builtModules +skipped = {det for det in args.skipModules + args.skipReadout + ([] if args.with_ZDC else ['ZDC'])} +requested = [det for det in activeDetectors.split(',') if det] +dropped = [det for det in requested if det != 'all' and det not in builtModules] +if dropped: + print(f"Detectors {dropped} are not built by detector list {args.detectorList}; dropped") +activeDetectors = { det:1 for det in requested if det not in dropped and det not in skipped } +if not activeDetectors: + print(f"Error: no active detector left after applying detector list {args.detectorList} and the skip options") + sys.exit(1) for det in activeDetectors: activate_detector(det) for det in args.skipModules: @@ -832,7 +847,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True): # a list of smaller sensors (used to construct digitization tasks in a parametrized way) smallsensorlist = [ "ITS", "TOF", "FDD", "MCH", "MID", "MFT", "HMP", "PHS", "CPV", "ZDC" ] -if args.detectorList == 'ALICE2.1': +if useIT3: smallsensorlist = ['IT3' if sensor == 'ITS' else sensor for sensor in smallsensorlist] # a list of detectors that serve as input for the trigger processor CTP --> these need to be processed together for now @@ -892,9 +907,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True): # determine final conf key for QED simulation QEDBaseConfig = "GeneratorExternal.fileName=$O2_ROOT/share/Generators/external/QEDLoader.C;QEDGenParam.yMin=-7;QEDGenParam.yMax=7;QEDGenParam.ptMin=0.001;QEDGenParam.ptMax=1.;QEDGenParam.xSectionHad="+str(XSecSys[COLTYPE])+";QEDGenParam.Z="+str(Zsys[COLTYPE])+";QEDGenParam.cmEnergy="+str(ECMS)+";Diamond.width[2]=6.;" QEDCONFKEY = constructConfigKeyArg(create_geant_config(args, QEDBaseConfig + args.confKeyQED)) - qed_detectorlist = ' ITS MFT FT0 FV0 FDD ' - if args.detectorList == 'ALICE2.1': - qed_detectorlist = qed_detectorlist.replace('ITS', 'IT3') + qed_detectorlist = ' ' + ' '.join(det for det in ['IT3' if useIT3 else 'ITS', 'MFT', 'FT0', 'FV0', 'FDD'] if det in builtModules) + ' ' QED_task['cmd'] = 'o2-sim -e TGeant3 --field ccdb -j ' + str('1') + ' -o qed' \ + ' -n ' + str(NEventsQED) + ' -m ' + qed_detectorlist \ + ('', ' --timestamp ' + str(args.timestamp))[args.timestamp!=-1] + ' --run ' + str(args.run) \ @@ -1221,7 +1234,7 @@ def createRestDigiTask(name, det='ALLSMALLER'): tneeds += [QED_task['name']] commondigicmd = '${O2_ROOT}/bin/o2-sim-digitizer-workflow ' + getDPL_global_options() + ' -n ' + str(args.ns) + simsoption \ + ' --interactionRate ' + str(INTRATE) + ' --incontext ' + str(CONTEXTFILE) + ' --disable-write-ini' \ - + putConfigValues(["MFTAlpideParam", "ITSAlpideParam", "ITSDigitizerParam" if args.detectorList == 'ALICE2' else "IT3DigitizerParam"], + + putConfigValues(["MFTAlpideParam", "ITSAlpideParam", "IT3DigitizerParam" if useIT3 else "ITSDigitizerParam"], localCF={"DigiParams.seed" : str(TFSEED), "MCHDigitizer.seed" : str(TFSEED)}) + QEDdigiargs if det=='ALLSMALLER': # here we combine all smaller digits in one DPL workflow @@ -1449,10 +1462,10 @@ def getDigiTaskName(det): #<--------- ITS reco task ITSMemEstimate = 12000 if havePbPb else 2000 # PbPb has much large mem requirement for now (in worst case) - ITSRECOtask=createTask(name='itsreco_'+str(tf), needs=[getDigiTaskName("ITS" if args.detectorList == 'ALICE2' else "IT3")], + ITSRECOtask=createTask(name='itsreco_'+str(tf), needs=[getDigiTaskName("IT3" if useIT3 else "ITS")], tf=tf, cwd=timeframeworkdir, lab=["RECO"], cpu='1', mem=str(ITSMemEstimate)) ITSRECOtask['cmd'] = task_finalizer([ - "${O2_ROOT}/bin/o2-its-reco-workflow" if args.detectorList == 'ALICE2' else "${O2_ROOT}/bin/o2-its3-reco-workflow", + "${O2_ROOT}/bin/o2-its3-reco-workflow" if useIT3 else "${O2_ROOT}/bin/o2-its-reco-workflow", getDPL_global_options(bigshm=havePbPb), staggITS, '--tracking-mode async', diff --git a/MC/bin/o2dpg_workflow_utils.py b/MC/bin/o2dpg_workflow_utils.py index 763c472ab..0eb395871 100755 --- a/MC/bin/o2dpg_workflow_utils.py +++ b/MC/bin/o2dpg_workflow_utils.py @@ -8,6 +8,8 @@ # List of active detectors ACTIVE_DETECTORS = ["all"] INACTIVE_DETECTORS = [] +# Modules built by the o2-sim detector list, None if unknown +BUILT_DETECTORS = None def activate_detector(det): try: @@ -21,9 +23,21 @@ def activate_detector(det): def deactivate_detector(det): INACTIVE_DETECTORS.append(det) +def restrict_to_detector_list(detector_list): + """Restricts isActive() to the modules of an o2-sim detector list (name, or name:path to a custom file) and returns them.""" + global BUILT_DETECTORS + name, sep, path = detector_list.partition(':') + with open(path if sep else f"{environ['O2_ROOT']}/share/config/o2simdefaultdetectorlist.json") as f: + modules = json.load(f)[name] + if not isinstance(modules, list) or not all(isinstance(m, str) for m in modules): + raise ValueError(f"detector list {name} is not a list of module names") + BUILT_DETECTORS = set(modules) + return BUILT_DETECTORS + def isActive(det): def check(detector): - return detector not in INACTIVE_DETECTORS and ("all" in ACTIVE_DETECTORS or detector in ACTIVE_DETECTORS) + built = BUILT_DETECTORS is None or detector == "all" or detector in BUILT_DETECTORS + return built and detector not in INACTIVE_DETECTORS and ("all" in ACTIVE_DETECTORS or detector in ACTIVE_DETECTORS) if det == "ITS": # special remapping for upgrade only needed in one direction since IT3 output pretends to be ITS return check("ITS") or check("IT3")