Skip to content

Commit 22aa469

Browse files
committed
make it work on macos
1 parent 4560f68 commit 22aa469

File tree

1 file changed

+67
-17
lines changed

1 file changed

+67
-17
lines changed

bin/run-clara

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,79 @@
11
#!/usr/bin/env bash
22

3-
usage="Usage: run-clara -y YAML [-i INP] [-o OUT] [-c CLARA] [-t #] [-n #]"
3+
ulimit -u 49152 >& /dev/null
4+
export JAVA_OPTS="${JAVA_OPTS} -XX:+IgnoreUnrecognizedVMOptions"
5+
6+
usage="Usage: run-clara [-i IN] [-o OUT] [-c CLARA] [-t #] [-n #] YAML"
47
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
8+
YAML path to CLARA YAML steering file\n
9+
-i input HIPO file or directory of *.hipo files (default=.)\n
10+
-o output directory (default=.)\n
11+
-c CLARA installation (default=\$CLARA_HOME)\n
12+
-t number of threads (default=2)\n
13+
-n number of events (default=-1)\n\n
1114
Defaults will use \$CLARA_HOME to read all *.hipo files in \$PWD,\n
1215
with all output written to \$PWD."
1316

1417
function error() {
1518
echo -e "\n$usage\n\nERROR: $@." && exit 1
1619
}
17-
1820
function abspath() {
1921
[ -d $1 ] && echo $(cd $1 && pwd) && return 0
2022
[ -r $1 ] && echo $(cd $(dirname $1) && pwd)/$(basename $1) && return 0
2123
return 1
2224
}
25+
function get_host_ip() {
26+
if command -v ip >/dev/null 2>&1
27+
then
28+
ip route get 1 | awk '{print $7; exit}' && return 0
29+
elif command -v ifconfig >/dev/null 2>&1
30+
then
31+
while IFS=$': \t' read -r -a line
32+
do
33+
[ -z "${line%inet}" ] &&
34+
ip=${line[${#line[1]}>4?1:2]} &&
35+
[ "${ip#127.0.0.1}" ] && echo $ip && return 0
36+
done< <(LANG=C ifconfig)
37+
fi
38+
return 1
39+
}
40+
function get_dpe_port() {
41+
local ports
42+
ports=$(seq 7000 20 8000)
43+
if command -v shuf >/dev/null 2>&1; then
44+
ports=$(echo "$ports" | shuf)
45+
fi
46+
for port in $ports; do
47+
local ctrl_port=$((port + 2))
48+
if ! eval "exec 6<>/dev/tcp/127.0.0.1/$ctrl_port" 2> /dev/null; then
49+
echo $port
50+
return 0
51+
fi
52+
done
53+
return 1
54+
}
2355

24-
ulimit -u 49152 >& /dev/null
2556
set -e
2657

2758
# Check user command-line options:
2859
input=.
2960
output=.
3061
threads=2
31-
while getopts i:o:c:y:t:n:h opt
62+
while getopts i:o:c:t:n:h opt
3263
do
3364
case $opt in
3465
i) input=$OPTARG ;;
3566
o) output=$OPTARG ;;
3667
c) CLARA_HOME=$OPTARG ;;
37-
y) yaml=$OPTARG && [ -r $yaml ] || error "-y must be a YAML file" ;;
3868
t) threads=$OPTARG && [[ $threads =~ '^[0-9]+$' ]] || error "-t must be an integer, threads" ;;
3969
n) nevents="-e $OPTARG" && [[ $nevents =~ '^[0-9]+$' ]] || error "-n must be an integer, events" ;;
4070
h) echo -e $usage && echo -e $info && exit 0 ;;
4171
esac
4272
done
4373
shift $((OPTIND-1))
44-
[ $# -gt 0 ] && error "Unknown arguments: $@"
45-
[ -z ${yaml+x} ] && error "-y YAML must be specified"
74+
[ $# -gt 1 ] && error "Extra arguments: ${@:2} (options must come before positionals)"
75+
[ $# -lt 1 ] && error "YAML file argument is required"
76+
[ -r $1 ] && yaml=$1 || error "YAML file does not exist: $yaml"
4677
[ -z ${CLARA_HOME+x} ] && error "-c must be specified or \$CLARA_HOME set"
4778
[ -d $CLARA_HOME ] || error "Invalid CLARA_HOME: $CLARA_HOME"
4879
[ $threads -eq 0 ] && threads=`grep -c ^processor /proc/cpuinfo`
@@ -60,21 +91,40 @@ input=$(abspath $input)
6091
output=$(abspath $output)
6192
yaml=$(abspath $yaml)
6293
export CLARA_HOME=$(abspath $CLARA_HOME)
94+
export CLAS12DIR=$CLARA_HOME/plugins/clas12
6395

6496
# 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
97+
test -d $input && find $input -maxdepth 1 -name '*.hipo' \( -type f \) -o \( -type l \) -exec basename {} \; > $CLARA_USER_DATA/filelist.txt
6698
test -f $input && echo $(basename $input) > $CLARA_USER_DATA/filelist.txt
6799
[ $(cat $CLARA_USER_DATA/filelist.txt | wc -l) -gt 0 ] || error "Found no input files."
68100

69101
# Finally, run CLARA:
70-
$CLARA_HOME/lib/clara/run-clara \
102+
[ -f $input ] || [ -h $input ] && input=$(dirname $input)
103+
if [ $(uname) == "Darwin" ]
104+
then
105+
ip=$(get_host_ip) || error "Unknown IP address"
106+
port=$(get_dpe_port) || error "Unknown DPE port"
107+
$CLARA_HOME/bin/j_dpe \
108+
--host $ip --port $port \
109+
--session recon --max-cores $threads \
110+
--max-sockets 5120 --report 5 \
111+
2>&1 | tee $CLARA_USER_DATA/log/dpe.log &
112+
echo "Sleeping 7 ......." && sleep 7
113+
unset JAVA_OPTS
114+
$CLARA_HOME/bin/clara-orchestrator \
115+
-F -f ${ip}%${port}_java -s recon \
116+
-i $input -o $output -z rec_ \
117+
-p $threads -t $threads \
118+
$yaml $CLARA_USER_DATA/filelist.txt
119+
else
120+
$CLARA_HOME/lib/clara/run-clara \
71121
-i $input \
72122
-o $CLARA_USER_DATA \
73123
-z rec_ \
74124
-x $CLARA_USER_DATA/log \
75125
-t $threads \
76126
$nevents \
77127
-s recon \
78-
$yaml \
79-
./$CLARA_USER_DATA/filelist.txt
128+
$yaml $CLARA_USER_DATA/filelist.txt
129+
fi
80130

0 commit comments

Comments
 (0)