From 4f9710f6c1683a8328f3bc40b9c81f6ee994ee42 Mon Sep 17 00:00:00 2001 From: Paul Buehler Date: Fri, 16 Aug 2024 14:10:53 +0200 Subject: [PATCH] Added possibility to define a general HEPMCOFFSET. Is usefull when simulating different SPLITIDs of a run in separate jobs. --- MC/bin/o2dpg_sim_workflow.py | 14 +++++++++++--- UTILS/InitHepMCEventSkip.sh | 12 ++++++++++++ UTILS/ReadHepMCEventSkip.sh | 19 ++++++++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100755 UTILS/InitHepMCEventSkip.sh diff --git a/MC/bin/o2dpg_sim_workflow.py b/MC/bin/o2dpg_sim_workflow.py index 31a709185..a86ce7b1c 100755 --- a/MC/bin/o2dpg_sim_workflow.py +++ b/MC/bin/o2dpg_sim_workflow.py @@ -724,9 +724,17 @@ def getDPL_global_options(bigshm=False, ccdbbackend=True): cpu=1, mem=1000) SGNGENtask['cmd']='' - if GENERATOR=="hepmc" and tf > 1: - # determine the skip number - cmd = 'export HEPMCEVENTSKIP=$(${O2DPG_ROOT}/UTILS/ReadHepMCEventSkip.sh ../HepMCEventSkip.json ' + str(tf) + ');' + if GENERATOR=="hepmc": + if tf == 1: + # determine the offset number + eventOffset = environ.get('HEPMCOFFSET') + print("HEPMCOFFSET: ", eventOffset) + if eventOffset == None: + eventOffset = 0 + cmd = 'export HEPMCEVENTSKIP=$(${O2DPG_ROOT}/UTILS/InitHepMCEventSkip.sh ../HepMCEventSkip.json ' + str(eventOffset) + ');' + elif tf > 1: + # determine the skip number + cmd = 'export HEPMCEVENTSKIP=$(${O2DPG_ROOT}/UTILS/ReadHepMCEventSkip.sh ../HepMCEventSkip.json ' + str(tf) + ');' SGNGENtask['cmd'] = cmd SGNGENtask['cmd'] +='${O2_ROOT}/bin/o2-sim --noGeant -j 1 --field ccdb --vertexMode kCCDB' \ + ' --run ' + str(args.run) + ' ' + str(CONFKEY) + str(TRIGGER) \ diff --git a/UTILS/InitHepMCEventSkip.sh b/UTILS/InitHepMCEventSkip.sh new file mode 100755 index 000000000..a7d45273b --- /dev/null +++ b/UTILS/InitHepMCEventSkip.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Path to the JSON file +JSON_FILE=${1:-HepMC_EventSkip_ALT.json} +EVENTS=$2 + +# insert event count offset +echo "[]" > ${JSON_FILE} # init json file +JQ_COMMAND="jq '. + [{"HepMCEventOffset": ${EVENTS}}]' ${JSON_FILE} > tmp_123.json; mv tmp_123.json ${JSON_FILE}" +eval ${JQ_COMMAND} + +echo ${EVENTS} diff --git a/UTILS/ReadHepMCEventSkip.sh b/UTILS/ReadHepMCEventSkip.sh index f242eafd7..2fc548b09 100755 --- a/UTILS/ReadHepMCEventSkip.sh +++ b/UTILS/ReadHepMCEventSkip.sh @@ -3,5 +3,22 @@ # Path to the JSON file JSON_FILE=$1 tf=$2 + +# get event offset +JQCOMMAND="jq '.[] | select(.HepMCEventOffset) | .HepMCEventOffset' ${JSON_FILE}" +offset=`eval ${JQCOMMAND}` +if [ ! $offset ] +then + offset=0 +fi + +# count generated events JQCOMMAND="jq '[.[] | select(.tf < ${tf}) | .HepMCEventCount] | add' ${JSON_FILE}" -eval ${JQCOMMAND} \ No newline at end of file +events=`eval ${JQCOMMAND}` +if [ ! $events ] +then + events=0 +fi + +# total number of events to skip +echo $((offset + events))