1- #! /bin/bash
1+ #! /usr/ bin/env bash
22
3- usage=" Usage: run-clara -y yamlfile [-i dirorfile] [-o dir] [-t threads] [-n nevents] [-c CLARA_HOME]"
3+ usage=" Usage: run-clara -y YAML [-i INP] [-o OUT] [-c CLARA] [-t #] [-n #]"
4+ info=" \nOptions:\n
5+ -y path to CLARA YAML steering file\n
6+ -i input HIPO file or directory of *.hipo files (default=.)\n
7+ -o output directory (default=.)\n
8+ -c CLARA installation (default=\$ CLARA_HOME)\n
9+ -t number of threads (default=2)\n
10+ -n number of events (default=-1)\n\n
11+ Defaults will use \$ CLARA_HOME to read all *.hipo files in \$ PWD,\n
12+ with all output written to \$ PWD."
413
514function error() {
6- echo -e " \n$usage \n\nERROR: $@ " && exit 1
15+ echo -e " \n$usage \n\nERROR: $@ . " && exit 1
716}
817
918function abspath() {
1019 [ -d $1 ] && echo $( cd $1 && pwd) && return 0
11- [ -f $1 ] && echo $( cd $( dirname $1 ) && pwd) /$1 && return 0
20+ [ -r $1 ] && echo $( cd $( dirname $1 ) && pwd) /$( basename $1 ) && return 0
1221 return 1
1322}
1423
1524ulimit -u 49152 >& /dev/null
1625set -e
1726
18- # Check user options:
27+ # Check user command-line options:
1928input=.
2029output=.
2130threads=2
22- while getopts i:o:y:t:n:c :h opt
31+ while getopts i:o:c: y:t:n:h opt
2332do
2433 case $opt in
2534 i) input=$OPTARG ;;
2635 o) output=$OPTARG ;;
27- y) yaml=$OPTARG ;;
28- t) threads=$OPTARG ;;
29- n) nevents=" -e $OPTARG " ;;
3036 c) CLARA_HOME=$OPTARG ;;
31- h) echo $usage && exit 0 ;;
32- ? ) error " Unknown option: $1 " ;;
37+ y) yaml=$OPTARG && [ -r $yaml ] || error " -y must be a YAML file" ;;
38+ t) threads=$OPTARG && [[ $threads =~ ' ^[0-9]+$' ]] || error " -t must be an integer, threads" ;;
39+ n) nevents=" -e $OPTARG " && [[ $nevents =~ ' ^[0-9]+$' ]] || error " -n must be an integer, events" ;;
40+ h) echo -e $usage && echo -e $info && exit 0 ;;
3341 esac
3442done
35- [ -z ${CLARA_HOME+x} ] && error " CLARA_HOME must be specified."
36- [ -d $CLARA_HOME ] || error " CLARA_HOME is missing: $CLARA_HOME "
37- [ -z ${yaml+x} ] && error " -y YAML must be specified."
38- [ -r $yaml ] || error " YAML file does not exist."
43+ shift $(( OPTIND- 1 ))
44+ [ $# -gt 0 ] && error " Unknown arguments: $@ "
45+ [ -z ${yaml+x} ] && error " -y YAML must be specified"
46+ [ -z ${CLARA_HOME+x} ] && error " -c must be specified or \$ CLARA_HOME set"
47+ [ -d $CLARA_HOME ] || error " Invalid CLARA_HOME: $CLARA_HOME "
3948[ $threads -eq 0 ] && threads=` grep -c ^processor /proc/cpuinfo`
49+ test -e $input && test -r $input || error " Invalid inputs -i: $input "
4050
41- # Normalize all user paths:
42- export CLARA_HOME=$( abspath $CLARA_HOME )
51+ # Create the environment variables and directories required by CLARA:
52+ [ -e $output ] && echo " WARNING: Using existing directory: $output ."
53+ mkdir -p -v $output || error " Cannot create -o output directory: $output "
54+ mkdir -p $output /log $output /config $output /data/output
55+ export CLARA_USER_DATA=$output
56+ unset CLARA_MONITOR_FE
57+
58+ # Normalize all paths:
4359input=$( abspath $input )
4460output=$( abspath $output )
4561yaml=$( abspath $yaml )
62+ export CLARA_HOME=$( abspath $CLARA_HOME )
4663
47- # Set the environment variables and directories required by CLARA:
48- unset CLARA_MONITOR_FE
49- export CLARA_USER_DATA=$( mktemp -d $output /run-clara.tmp.XXXXXX)
50- cd $CLARA_USER_DATA
51- mkdir -p $CLARA_USER_DATA /log
52- mkdir -p $CLARA_USER_DATA /config
53- mkdir -p $CLARA_USER_DATA /data/output
54-
55- # Generate the required file containing a file list for CLARA:
56- # (Note, that file list must contain relative paths, not absolute.)
57- test -e $input || eror " Invalid inputs: $input "
58- test -d $input && find $input -maxdepth 1 -type f -name ' *.hipo' -exec basename {} \; > filelist.txt
59- test -f $input && echo $( basename $input ) > filelist.txt
60- [ $( cat filelist.txt | wc -l) -gt 0 ] || error " Found no input files."
64+ # Generate the file for CLARA containing a file list (of relative paths, not absolute):
65+ test -d $input && find $input -maxdepth 1 -type f -name ' *.hipo' -exec basename {} \; > $CLARA_USER_DATA /filelist.txt
66+ test -f $input && echo $( basename $input ) > $CLARA_USER_DATA /filelist.txt
67+ [ $( cat $CLARA_USER_DATA /filelist.txt | wc -l) -gt 0 ] || error " Found no input files."
6168
6269# Finally, run CLARA:
6370$CLARA_HOME /lib/clara/run-clara \
@@ -69,5 +76,5 @@ $CLARA_HOME/lib/clara/run-clara \
6976 $nevents \
7077 -s recon \
7178 $yaml \
72- ./filelist.txt
79+ ./$CLARA_USER_DATA / filelist.txt
7380
0 commit comments