Skip to content

Commit 2c93bd3

Browse files
committed
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
1 parent dec980e commit 2c93bd3

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎MC/bin/o2dpg_sim_workflow.py‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
sys.path.append(join(dirname(__file__), '.', 'o2dpg_workflow_utils'))
4343

44-
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts
44+
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
4545
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
4646
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available, overwrite_config, qed_included
4747
from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed
@@ -310,8 +310,23 @@ def load_external_config(configfile):
310310
activeDetectors = ','.join(r & a)
311311
# the last case: simply take what comes from the anchored config
312312

313-
# convert to set/hashmap
314-
activeDetectors = { det:1 for det in activeDetectors.split(',') if det not in args.skipModules and det not in args.skipReadout}
313+
# convert to set/hashmap, keeping only detectors that the chosen detector list builds (e.g. no TRD in ALICE2.1)
314+
try:
315+
builtModules = restrict_to_detector_list(args.detectorList)
316+
except (OSError, ValueError, KeyError, TypeError) as e:
317+
print(f"Error: cannot read detector list {args.detectorList}: {e!r}")
318+
sys.exit(1)
319+
# IT3 replaces ITS when the detector list builds it
320+
useIT3 = 'IT3' in builtModules
321+
skipped = {det for det in args.skipModules + args.skipReadout + ([] if args.with_ZDC else ['ZDC'])}
322+
requested = [det for det in activeDetectors.split(',') if det]
323+
dropped = [det for det in requested if det != 'all' and det not in builtModules]
324+
if dropped:
325+
print(f"Detectors {dropped} are not built by detector list {args.detectorList}; dropped")
326+
activeDetectors = { det:1 for det in requested if det not in dropped and det not in skipped }
327+
if not activeDetectors:
328+
print(f"Error: no active detector left after applying detector list {args.detectorList} and the skip options")
329+
sys.exit(1)
315330
for det in activeDetectors:
316331
activate_detector(det)
317332
for det in args.skipModules:
@@ -834,7 +849,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
834849

835850
# a list of smaller sensors (used to construct digitization tasks in a parametrized way)
836851
smallsensorlist = [ "ITS", "TOF", "FDD", "MCH", "MID", "MFT", "HMP", "PHS", "CPV", "ZDC" ]
837-
if args.detectorList == 'ALICE2.1':
852+
if useIT3:
838853
smallsensorlist = ['IT3' if sensor == 'ITS' else sensor for sensor in smallsensorlist]
839854

840855
# a list of detectors that serve as input for the trigger processor CTP --> these need to be processed together for now
@@ -894,9 +909,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
894909
# determine final conf key for QED simulation
895910
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.;"
896911
QEDCONFKEY = constructConfigKeyArg(create_geant_config(args, QEDBaseConfig + args.confKeyQED))
897-
qed_detectorlist = ' ITS MFT FT0 FV0 FDD '
898-
if args.detectorList == 'ALICE2.1':
899-
qed_detectorlist = qed_detectorlist.replace('ITS', 'IT3')
912+
qed_detectorlist = ' ' + ' '.join(det for det in ['IT3' if useIT3 else 'ITS', 'MFT', 'FT0', 'FV0', 'FDD'] if det in builtModules) + ' '
900913
QED_task['cmd'] = 'o2-sim -e TGeant3 --field ccdb -j ' + str('1') + ' -o qed' \
901914
+ ' -n ' + str(NEventsQED) + ' -m ' + qed_detectorlist \
902915
+ ('', ' --timestamp ' + str(args.timestamp))[args.timestamp!=-1] + ' --run ' + str(args.run) \
@@ -1223,7 +1236,7 @@ def createRestDigiTask(name, det='ALLSMALLER'):
12231236
tneeds += [QED_task['name']]
12241237
commondigicmd = '${O2_ROOT}/bin/o2-sim-digitizer-workflow ' + getDPL_global_options() + ' -n ' + str(args.ns) + simsoption \
12251238
+ ' --interactionRate ' + str(INTRATE) + ' --incontext ' + str(CONTEXTFILE) + ' --disable-write-ini' \
1226-
+ putConfigValues(["MFTAlpideParam", "ITSAlpideParam", "ITSDigitizerParam" if args.detectorList == 'ALICE2' else "IT3DigitizerParam"],
1239+
+ putConfigValues(["MFTAlpideParam", "ITSAlpideParam", "IT3DigitizerParam" if useIT3 else "ITSDigitizerParam"],
12271240
localCF={"DigiParams.seed" : str(TFSEED), "MCHDigitizer.seed" : str(TFSEED)}) + QEDdigiargs
12281241

12291242
if det=='ALLSMALLER': # here we combine all smaller digits in one DPL workflow
@@ -1451,10 +1464,10 @@ def getDigiTaskName(det):
14511464

14521465
#<--------- ITS reco task
14531466
ITSMemEstimate = 12000 if havePbPb else 2000 # PbPb has much large mem requirement for now (in worst case)
1454-
ITSRECOtask=createTask(name='itsreco_'+str(tf), needs=[getDigiTaskName("ITS" if args.detectorList == 'ALICE2' else "IT3")],
1467+
ITSRECOtask=createTask(name='itsreco_'+str(tf), needs=[getDigiTaskName("IT3" if useIT3 else "ITS")],
14551468
tf=tf, cwd=timeframeworkdir, lab=["RECO"], cpu='1', mem=str(ITSMemEstimate))
14561469
ITSRECOtask['cmd'] = task_finalizer([
1457-
"${O2_ROOT}/bin/o2-its-reco-workflow" if args.detectorList == 'ALICE2' else "${O2_ROOT}/bin/o2-its3-reco-workflow",
1470+
"${O2_ROOT}/bin/o2-its3-reco-workflow" if useIT3 else "${O2_ROOT}/bin/o2-its-reco-workflow",
14581471
getDPL_global_options(bigshm=havePbPb),
14591472
staggITS,
14601473
'--tracking-mode async',

‎MC/bin/o2dpg_workflow_utils.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# List of active detectors
99
ACTIVE_DETECTORS = ["all"]
1010
INACTIVE_DETECTORS = []
11+
# Modules built by the o2-sim detector list, None if unknown
12+
BUILT_DETECTORS = None
1113

1214
def activate_detector(det):
1315
try:
@@ -21,9 +23,21 @@ def activate_detector(det):
2123
def deactivate_detector(det):
2224
INACTIVE_DETECTORS.append(det)
2325

26+
def restrict_to_detector_list(detector_list):
27+
"""Restricts isActive() to the modules of an o2-sim detector list (name, or name:path to a custom file) and returns them."""
28+
global BUILT_DETECTORS
29+
name, sep, path = detector_list.partition(':')
30+
with open(path if sep else f"{environ['O2_ROOT']}/share/config/o2simdefaultdetectorlist.json") as f:
31+
modules = json.load(f)[name]
32+
if not isinstance(modules, list) or not all(isinstance(m, str) for m in modules):
33+
raise ValueError(f"detector list {name} is not a list of module names")
34+
BUILT_DETECTORS = set(modules)
35+
return BUILT_DETECTORS
36+
2437
def isActive(det):
2538
def check(detector):
26-
return detector not in INACTIVE_DETECTORS and ("all" in ACTIVE_DETECTORS or detector in ACTIVE_DETECTORS)
39+
built = BUILT_DETECTORS is None or detector == "all" or detector in BUILT_DETECTORS
40+
return built and detector not in INACTIVE_DETECTORS and ("all" in ACTIVE_DETECTORS or detector in ACTIVE_DETECTORS)
2741

2842
if det == "ITS": # special remapping for upgrade only needed in one direction since IT3 output pretends to be ITS
2943
return check("ITS") or check("IT3")

0 commit comments

Comments
 (0)