Skip to content

Commit e7838d0

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. - isActive() is false for modules the list does not build, and they are dropped from --readoutDetectors, which o2-sim rejects otherwise. - A requested ITS is mapped to IT3 when the list builds IT3, before the skip options are applied. - The ITS/IT3 choice in the task setup follows the list instead of its name. - An empty set of active detectors is now an error instead of enabling all. - Without a readable list the workflow warns and behaves as before. https://its.cern.ch/jira/browse/O2-7267
1 parent dc51651 commit e7838d0

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎MC/bin/o2dpg_sim_workflow.py‎

Lines changed: 22 additions & 8 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, read_detector_list, restrict_to_built
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
4747
from o2dpg_dpl_config_tools import dpl_option_from_config, TaskFinalizer, quote_if_needed
@@ -310,8 +310,22 @@ 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+
builtModules = read_detector_list(args.detectorList)
315+
requested = [det for det in activeDetectors.split(',') if det]
316+
if builtModules is None:
317+
print(f"Warning: cannot read detector list {args.detectorList}; active detectors are not checked against it")
318+
else:
319+
restrict_to_built(builtModules)
320+
if 'IT3' in builtModules and 'ITS' not in builtModules:
321+
requested = ['IT3' if det == 'ITS' else det for det in requested]
322+
requested = [det for det in requested if det == 'all' or det in builtModules]
323+
activeDetectors = { det:1 for det in requested if det not in args.skipModules and det not in args.skipReadout}
324+
# IT3 replaces ITS when the detector list builds it
325+
useIT3 = ('IT3' in builtModules) if builtModules is not None else args.detectorList == 'ALICE2.1'
326+
if not activeDetectors:
327+
print(f"Error: no active detector left after applying detector list {args.detectorList} and the skip options")
328+
sys.exit(1)
315329
for det in activeDetectors:
316330
activate_detector(det)
317331
for det in args.skipModules:
@@ -832,7 +846,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
832846

833847
# a list of smaller sensors (used to construct digitization tasks in a parametrized way)
834848
smallsensorlist = [ "ITS", "TOF", "FDD", "MCH", "MID", "MFT", "HMP", "PHS", "CPV", "ZDC" ]
835-
if args.detectorList == 'ALICE2.1':
849+
if useIT3:
836850
smallsensorlist = ['IT3' if sensor == 'ITS' else sensor for sensor in smallsensorlist]
837851

838852
# a list of detectors that serve as input for the trigger processor CTP --> these need to be processed together for now
@@ -893,7 +907,7 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True, runcommand=True):
893907
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.;"
894908
QEDCONFKEY = constructConfigKeyArg(create_geant_config(args, QEDBaseConfig + args.confKeyQED))
895909
qed_detectorlist = ' ITS MFT FT0 FV0 FDD '
896-
if args.detectorList == 'ALICE2.1':
910+
if useIT3:
897911
qed_detectorlist = qed_detectorlist.replace('ITS', 'IT3')
898912
QED_task['cmd'] = 'o2-sim -e TGeant3 --field ccdb -j ' + str('1') + ' -o qed' \
899913
+ ' -n ' + str(NEventsQED) + ' -m ' + qed_detectorlist \
@@ -1221,7 +1235,7 @@ def createRestDigiTask(name, det='ALLSMALLER'):
12211235
tneeds += [QED_task['name']]
12221236
commondigicmd = '${O2_ROOT}/bin/o2-sim-digitizer-workflow ' + getDPL_global_options() + ' -n ' + str(args.ns) + simsoption \
12231237
+ ' --interactionRate ' + str(INTRATE) + ' --incontext ' + str(CONTEXTFILE) + ' --disable-write-ini' \
1224-
+ putConfigValues(["MFTAlpideParam", "ITSAlpideParam", "ITSDigitizerParam" if args.detectorList == 'ALICE2' else "IT3DigitizerParam"],
1238+
+ putConfigValues(["MFTAlpideParam", "ITSAlpideParam", "IT3DigitizerParam" if useIT3 else "ITSDigitizerParam"],
12251239
localCF={"DigiParams.seed" : str(TFSEED), "MCHDigitizer.seed" : str(TFSEED)}) + QEDdigiargs
12261240

12271241
if det=='ALLSMALLER': # here we combine all smaller digits in one DPL workflow
@@ -1449,10 +1463,10 @@ def getDigiTaskName(det):
14491463

14501464
#<--------- ITS reco task
14511465
ITSMemEstimate = 12000 if havePbPb else 2000 # PbPb has much large mem requirement for now (in worst case)
1452-
ITSRECOtask=createTask(name='itsreco_'+str(tf), needs=[getDigiTaskName("ITS" if args.detectorList == 'ALICE2' else "IT3")],
1466+
ITSRECOtask=createTask(name='itsreco_'+str(tf), needs=[getDigiTaskName("IT3" if useIT3 else "ITS")],
14531467
tf=tf, cwd=timeframeworkdir, lab=["RECO"], cpu='1', mem=str(ITSMemEstimate))
14541468
ITSRECOtask['cmd'] = task_finalizer([
1455-
"${O2_ROOT}/bin/o2-its-reco-workflow" if args.detectorList == 'ALICE2' else "${O2_ROOT}/bin/o2-its3-reco-workflow",
1469+
"${O2_ROOT}/bin/o2-its3-reco-workflow" if useIT3 else "${O2_ROOT}/bin/o2-its-reco-workflow",
14561470
getDPL_global_options(bigshm=havePbPb),
14571471
staggITS,
14581472
'--tracking-mode async',

‎MC/bin/o2dpg_workflow_utils.py‎

Lines changed: 18 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,15 +23,30 @@ def activate_detector(det):
2123
def deactivate_detector(det):
2224
INACTIVE_DETECTORS.append(det)
2325

26+
def restrict_to_built(modules):
27+
global BUILT_DETECTORS
28+
BUILT_DETECTORS = set(modules)
29+
2430
def isActive(det):
2531
def check(detector):
26-
return detector not in INACTIVE_DETECTORS and ("all" in ACTIVE_DETECTORS or detector in ACTIVE_DETECTORS)
32+
built = BUILT_DETECTORS is None or detector == "all" or detector in BUILT_DETECTORS
33+
return built and detector not in INACTIVE_DETECTORS and ("all" in ACTIVE_DETECTORS or detector in ACTIVE_DETECTORS)
2734

2835
if det == "ITS": # special remapping for upgrade only needed in one direction since IT3 output pretends to be ITS
2936
return check("ITS") or check("IT3")
3037
else:
3138
return check(det)
3239

40+
def read_detector_list(detector_list):
41+
"""Modules of an o2-sim detector list, resolved like o2-sim --detectorList (name, or name:path to a custom file); None if unreadable."""
42+
name, sep, path = detector_list.partition(':')
43+
try:
44+
path = path if sep else f"{environ['O2_ROOT']}/share/config/o2simdefaultdetectorlist.json"
45+
with open(path) as f:
46+
return set(json.load(f)[name])
47+
except (OSError, ValueError, KeyError, TypeError):
48+
return None
49+
3350
def compute_n_workers(interaction_rate, collision_system, n_workers_user=8, n_workers_min=1, interaction_rate_linear_below=300000):
3451
"""
3552
Compute number of workers

0 commit comments

Comments
 (0)