Skip to content

Commit 0bdcfa1

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. - Detectors outside the list are deactivated and dropped from --readoutDetectors, which o2-sim rejects otherwise. - With ALICE2.1 a requested ITS is mapped to IT3. - Without a readable list the workflow warns and behaves as before. https://its.cern.ch/jira/browse/O2-7267
1 parent dc51651 commit 0bdcfa1

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎MC/bin/o2dpg_sim_workflow.py‎

Lines changed: 17 additions & 1 deletion
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
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
@@ -312,11 +312,27 @@ def load_external_config(configfile):
312312

313313
# convert to set/hashmap
314314
activeDetectors = { det:1 for det in activeDetectors.split(',') if det not in args.skipModules and det not in args.skipReadout}
315+
316+
# keep only detectors that the chosen detector list builds (e.g. no TRD in ALICE2.1)
317+
builtModules, allModules = read_detector_list(args.detectorList)
318+
if builtModules is None:
319+
print(f"Warning: cannot read detector list {args.detectorList}; active detectors are not checked against it")
320+
else:
321+
if 'ITS' in activeDetectors and 'ITS' not in builtModules and 'IT3' in builtModules:
322+
del activeDetectors['ITS']
323+
activeDetectors['IT3'] = 1
324+
for det in [d for d in activeDetectors if d != 'all' and d not in builtModules]:
325+
print(f"Detector {det} is not part of detector list {args.detectorList}; disabled")
326+
del activeDetectors[det]
327+
315328
for det in activeDetectors:
316329
activate_detector(det)
317330
for det in args.skipModules:
318331
print(f"Skipping detector {det} in simulation")
319332
deactivate_detector(det)
333+
if builtModules is not None:
334+
for det in allModules - builtModules:
335+
deactivate_detector(det)
320336

321337
# function to finalize detector source lists based on activeDetectors
322338
# detector source lists are comma separated lists of DET1, DET2, DET1-DET2, ...

‎MC/bin/o2dpg_workflow_utils.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
from os import environ, getcwd
4+
from os.path import join
45
from copy import deepcopy
56
import json
67

@@ -30,6 +31,27 @@ def check(detector):
3031
else:
3132
return check(det)
3233

34+
def read_detector_list(detector_list):
35+
"""Modules of an o2-sim detector list and all modules of its JSON file, resolved like o2-sim --detectorList.
36+
37+
detector_list is a name from $O2_ROOT/share/config/o2simdefaultdetectorlist.json or name:path to a custom file.
38+
Returns (None, None) when the list cannot be read.
39+
"""
40+
name, _, path = detector_list.partition(':')
41+
if not path:
42+
o2root = environ.get('O2_ROOT')
43+
if not o2root:
44+
return None, None
45+
path = join(o2root, 'share', 'config', 'o2simdefaultdetectorlist.json')
46+
try:
47+
with open(path) as f:
48+
lists = json.load(f)
49+
except (OSError, ValueError):
50+
return None, None
51+
if name not in lists:
52+
return None, None
53+
return set(lists[name]), set(m for modules in lists.values() for m in modules)
54+
3355
def compute_n_workers(interaction_rate, collision_system, n_workers_user=8, n_workers_min=1, interaction_rate_linear_below=300000):
3456
"""
3557
Compute number of workers

0 commit comments

Comments
 (0)