Skip to content

Commit

Permalink
[SimWF,WIP] Fetch MaterialManager file from CCDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Volkel committed May 24, 2024
1 parent d66f838 commit 03cf234
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
8 changes: 4 additions & 4 deletions MC/bin/o2dpg_sim_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def constructConfigKeyArg(config):
# and constructs the --configKeyValues options for simulation
if len(config) == 0:
return ''
arg = '--configKeyValues "'

arg_tokens = []
for mainkey in config:
for subkey in config[mainkey]:
arg = arg + mainkey + '.' + subkey + '=' + config[mainkey][subkey] + ';'
arg = arg + '"'
return arg
arg_tokens.append(mainkey + '.' + subkey + '=' + config[mainkey][subkey])
return '--configKeyValues "' + ';'.join(arg_tokens) + '"'
50 changes: 48 additions & 2 deletions MC/bin/o2dpg_sim_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import importlib.util
import argparse
from os import environ, mkdir
from os.path import join, dirname, isdir, isabs
from os.path import join, dirname, isdir, isabs, abspath
import random
import json
import itertools
Expand Down Expand Up @@ -257,6 +257,19 @@ def retrieve_sor(run_number):
return int(SOR)


def get_medium_params_from_ccdb(target_path, timestamp='1716541100245'):
url = f'http://ccdb-test.cern.ch:8080/SIM_TEST/ALIBI/SIM_CUTS/{timestamp}'
resp_medium_params = requests.get(url)
if (status := resp_medium_params.status_code) != 200:
print(f'ERROR: Could not fetch medium parameters for timestamp {timestamp}; status code is {status}')
return False

with open(target_path, 'w') as f:
json.dump(resp_medium_params.json(), f, indent=2)

return True


# check and sanitize config-key values (extract and remove diamond vertex arguments into finalDiamondDict)
def extractVertexArgs(configKeyValuesStr, finalDiamondDict):
# tokenize configKeyValueStr on ;
Expand Down Expand Up @@ -362,9 +375,42 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True):
if (includeLocalQC or includeFullQC) and not isdir(qcdir):
mkdir(qcdir)

# adjust material manager params
confKeysSgn = create_geant_config(args, args.confKey)
confKeysBkg = create_geant_config(args, args.confKeyBkg)

# MaterialManagerParam only has an effect when given to signal confKey
mat_mgr_params = confKeysSgn.get("MaterialManagerParam", {}).get('inputFile', None)
ccdb_path = 'SIM_TEST/ALIBI/SIM_CUTS'
mat_mgr_file_name = 'material_manager_params.json'
ccdb_path = 'SIM_TEST/ALIBI/SIM_CUTS'
mat_mgr_file_path = f'${{ALICEO2_CCDB_LOCALCACHE}}/{ccdb_path}/{mat_mgr_file_name}'

if mat_mgr_params is None:
cmat_mgr_cmdmmat_mgr_cmdd = 'echo "placeholder / dummy task"'
mat_mgr_file_path = None
elif mat_mgr_params == 'ccdb':
mat_mgr_cmd = f'${{O2_ROOT}}/bin/o2-ccdb-downloadccdbfile --host http://ccdb-test.cern.ch:8080 -p {ccdb_path} --timestamp -1 -d ${{ALICEO2_CCDB_LOCALCACHE}} -o {mat_mgr_file_name}'
else:
mat_mgr_cmd = f'[[ ! -d ${{ALICEO2_CCDB_LOCALCACHE}}/{ccdb_path} ]] && {{mkdir ${{ALICEO2_CCDB_LOCALCACHE}}/{ccdb_path} ; cp {mat_mgr_params} ${{ALICEO2_CCDB_LOCALCACHE}}/{ccdb_path} ; }}'

if mat_mgr_params:
confKeysSgn['MaterialManagerParam']['inputFile'] = mat_mgr_file_path
bkg = confKeysBkg.get('MaterialManager', {})
bkg['inputFile'] = mat_mgr_file_path
confKeysBkg['MaterrialManager'] = bkg


args.confKey = constructConfigKeyArg(confKeysSgn)
args.confKeyBkg = constructConfigKeyArg(confKeysBkg)

MATMGR_TASK = createTask(name='downloadMatMgrParams', cpu=0)
MATMGR_TASK['cmd'] = mat_mgr_cmd
workflow['stages'].append(MATMGR_TASK)

# create/publish the GRPs and other GLO objects for consistent use further down the pipeline
orbitsPerTF=int(args.orbitsPerTF)
GRP_TASK = createTask(name='grpcreate', cpu='0')
GRP_TASK = createTask(name='grpcreate', cpu='0', needs=[MATMGR_TASK['name']])
GRP_TASK['cmd'] = 'o2-grp-simgrp-tool createGRPs --timestamp ' + str(args.timestamp) + ' --run ' + str(args.run) + ' --publishto ${ALICEO2_CCDB_LOCALCACHE:-.ccdb} -o grp --hbfpertf ' + str(orbitsPerTF) + ' --field ' + args.field
GRP_TASK['cmd'] += ' --readoutDets ' + " ".join(activeDetectors) + ' --print ' + ('','--lhcif-CCDB')[args.run_anchored]
if (not args.run_anchored == True) and len(args.bcPatternFile) > 0:
Expand Down

0 comments on commit 03cf234

Please sign in to comment.