|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# This is a simple simulation example showing how to |
| 4 | +# start JETSCAPE generation automatically using cmd with hepmc output on FIFO |
| 5 | +# and simultaneosly use o2-sim for transport |
| 6 | + |
| 7 | +# JETSCAPE and O2 must be loaded |
| 8 | +set -x |
| 9 | +if [ ! "${JETSCAPE_ROOT}" ]; then |
| 10 | + echo "This needs JETSCAPE loaded; alienv enter ..." |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 2 |
| 15 | + |
| 16 | +cmd="$PWD/jetscape.sh" |
| 17 | +NEV=-1 |
| 18 | +more="" |
| 19 | +xml="example" |
| 20 | +JOBS=2 |
| 21 | + |
| 22 | +usage() |
| 23 | +{ |
| 24 | + cat <<EOF |
| 25 | +Usage: $0 [OPTIONS] |
| 26 | +
|
| 27 | +Options: |
| 28 | +
|
| 29 | + -m,--more CONFIG More configurations ($more) |
| 30 | + -n,--nevents EVENTS Number of events ($nev) |
| 31 | + -i,--input INPUT XML configuration file fed to JETSCAPE ($xml) |
| 32 | + -j,--jobs JOBS Number of jobs ($JOBS) |
| 33 | + -h,--help Print these instructions |
| 34 | + -- Rest of command line sent to o2-sim |
| 35 | +
|
| 36 | +COMMAND must be quoted if it contains spaces or other special |
| 37 | +characters |
| 38 | +
|
| 39 | +Below follows the help output of o2-sim |
| 40 | +
|
| 41 | +EOF |
| 42 | +} |
| 43 | + |
| 44 | +if [ "$#" -lt 2 ]; then |
| 45 | + echo "Running with default values" |
| 46 | +fi |
| 47 | + |
| 48 | +while test $# -gt 0 ; do |
| 49 | + case $1 in |
| 50 | + -m|--more) more="$2" ; shift ;; |
| 51 | + -n|--nevents) NEV=$2 ; shift ;; |
| 52 | + -i|--input) xml=$2 ; shift ;; |
| 53 | + -j|--jobs) JOBS=$2 ; shift ;; |
| 54 | + -h|--help) usage; o2-sim --help full ; exit 0 ;; |
| 55 | + --) shift ; break ;; |
| 56 | + *) echo "Unknown option '$1', did you forget '--'?" >/dev/stderr |
| 57 | + exit 3 |
| 58 | + ;; |
| 59 | + esac |
| 60 | + shift |
| 61 | +done |
| 62 | + |
| 63 | +echo "XML User file: $xml" |
| 64 | + |
| 65 | +if [ ! -f $xml.xml ]; then |
| 66 | + echo "Error: Options file $xml.xml not found" |
| 67 | + exit 4 |
| 68 | +fi |
| 69 | + |
| 70 | +# Set number of events in the XML file |
| 71 | +if [ ! $NEV -eq -1 ]; then |
| 72 | + echo "Setting number of events to $NEV" |
| 73 | + if grep -Fq "<nEvents>" $xml.xml; then |
| 74 | + sed -i "/<nEvents>/c\ <nEvents>$NEV</nEvents>" $xml.xml |
| 75 | + else |
| 76 | + sed -i "/<jetscape>/a\ <nEvents>$NEV</nEvents>" $xml.xml |
| 77 | + fi |
| 78 | +else |
| 79 | + echo "Number of events not set, checking xml file..." |
| 80 | + if grep -Fq "<nEvents>" $xml.xml; then |
| 81 | + NEV=$(grep -F "<nEvents>" $xml.xml | awk '{print $2}') |
| 82 | + echo "Number of events set to $NEV" |
| 83 | + else |
| 84 | + echo "Error: Number of events not set in JETSCAPE" |
| 85 | + exit 5 |
| 86 | + fi |
| 87 | +fi |
| 88 | + |
| 89 | +# Starting simulation |
| 90 | +o2-sim -j $JOBS -n ${NEV} -g hepmc --seed $RANDOM \ |
| 91 | + --configKeyValues "GeneratorFileOrCmd.cmd=$cmd -i $xml;GeneratorFileOrCmd.fileNames=test_out.hepmc;GeneratorFileOrCmd.outputSwitch=-o;GeneratorFileOrCmd.bMaxSwitch=none;GeneratorFileOrCmd.nEventsSwitch=none;${more}" |
0 commit comments