Skip to content

Commit 78619ca

Browse files
committed
build: default to --lfs and remove --xrootd
- make `--lfs` the default - remove `--xrootd` since no longer available - add `--clasweb` to support `wget`/`curl` for field maps - refactored a bit, replacing `if $useLfs` etc. with `case $dataRetrieval in`
1 parent c93dc8a commit 78619ca

File tree

1 file changed

+126
-113
lines changed

1 file changed

+126
-113
lines changed

build-coatjava.sh

Lines changed: 126 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ set -e
55
set -u
66
set -o pipefail
77

8+
################################################################################
9+
# default options
10+
################################################################################
11+
12+
cleanBuild=false
13+
anaDepends=false
14+
runSpotBugs=false
15+
downloadMaps=true
16+
downloadNets=true
17+
runUnitTests=false
18+
dataRetrieval=lfs
19+
installClara=false
20+
downloadData=false
21+
22+
################################################################################
23+
# usage
24+
################################################################################
25+
826
usage='''build-coatjava.sh [OPTIONS]...
927
1028
GENERAL OPTIONS
@@ -15,11 +33,11 @@ GENERAL OPTIONS
1533
--help show this message
1634
1735
DATA RETRIEVAL OPTIONS
18-
How to retrieve magnetic field maps, neural network models, etc.;
19-
choose only one, e.g., if the automated default choice fails:
36+
How to retrieve magnetic field maps, neural network models, etc.
37+
Choose only one; default is `--'$dataRetrieval'`
2038
--lfs use Git Large File Storage (requires `git-lfs`)
2139
--cvmfs use CernVM-FS (requires `/cvfms`)
22-
--xrootd use XRootD (requires `xrootd`)
40+
--clasweb use clasweb (only works for field maps)
2341
Options to disable data retrieval:
2442
--nomaps do not download/overwrite field maps
2543
--nonets do not download/overwrite neural networks
@@ -40,17 +58,6 @@ MAVEN OPTIONS
4058
# parse arguments
4159
################################################################################
4260

43-
cleanBuild=false
44-
anaDepends=false
45-
runSpotBugs=false
46-
downloadMaps=true
47-
downloadNets=true
48-
runUnitTests=false
49-
useXrootd=false
50-
useCvmfs=false
51-
useLfs=false
52-
installClara=false
53-
downloadData=false
5461
mvnArgs=()
5562
wgetArgs=()
5663
for xx in $@
@@ -71,11 +78,11 @@ do
7178
mvnArgs+=(--no-transfer-progress)
7279
wgetArgs+=(--no-verbose)
7380
;;
74-
--xrootd) useXrootd=true ;;
75-
--cvmfs) useCvmfs=true ;;
76-
--lfs) useLfs=true ;;
77-
--clara) installClara=true ;;
78-
--data) downloadData=true ;;
81+
--cvmfs) dataRetrieval=cvmfs ;;
82+
--lfs) dataRetrieval=lfs ;;
83+
--clasweb) dataRetrieval=clasweb ;;
84+
--clara) installClara=true ;;
85+
--data) downloadData=true ;;
7986
-h|--help)
8087
echo "$usage"
8188
exit 2
@@ -84,41 +91,6 @@ do
8491
esac
8592
done
8693

87-
# check if a command exists
88-
command_exists () {
89-
type "$1" &> /dev/null
90-
}
91-
92-
# count how many data-retrieval options are set
93-
count_download_opts() {
94-
local n=0
95-
for o in $useLfs $useCvmfs $useXrootd; do
96-
$o && ((n++))
97-
done
98-
echo $n
99-
}
100-
101-
# if the user did not choose a data retrieval method, choose a reasonable one
102-
if [[ $(count_download_opts) -eq 0 ]]; then
103-
echo 'INFO: no data-retrieval option set; choosing a default...'
104-
if ! [[ $(hostname) == *.jlab.org ]] && command_exists git-lfs ; then
105-
echo 'INFO: ... using `--lfs` since you are likely offsite and have git-lfs installed'
106-
useLfs=true
107-
elif [ -d /cvmfs/oasis.opensciencegrid.org/jlab ]; then
108-
echo 'INFO: ... using `--cvmfs` since you appear to have /cvmfs/oasis.opensciencegrid.org'
109-
useCvmfs=true
110-
else
111-
echo 'WARNING: default data-retrieval option cannot be determined; use `--help` for guidance' >&2
112-
sleep 1
113-
fi
114-
fi
115-
116-
# if they chose too many, fail
117-
if [[ $(count_download_opts) -gt 1 ]]; then
118-
echo 'ERROR: more than one data-retrieval option is set' >&2
119-
exit 1
120-
fi
121-
12294

12395
################################################################################
12496
# setup
@@ -141,15 +113,6 @@ wget="wget ${wgetArgs[@]:-}"
141113
# environment
142114
source libexec/env.sh --no-classpath
143115

144-
# install LFS
145-
if $useLfs; then
146-
if ! command_exists git-lfs ; then
147-
echo 'ERROR: `git-lfs` not found; please install it, or use a different option other than `--lfs`' >&2
148-
exit 1
149-
fi
150-
git lfs install
151-
fi
152-
153116
################################################################################
154117
# cleaning, dependency analysis, etc.
155118
################################################################################
@@ -189,94 +152,144 @@ fi
189152
# download field maps, NN models, etc.
190153
################################################################################
191154

155+
# check if a command exists
156+
command_exists () {
157+
type "$1" &> /dev/null
158+
}
159+
192160
# print retrieval notice
193161
notify_retrieval() {
194162
echo "Retrieving $1 from $2 ..."
195163
}
196164

197165
# update an LFS submodule
198166
download_lfs() {
199-
if ! $useLfs; then
200-
echo 'ERROR: attempted to use LFS, but option `--lfs` not set' >&2
201-
exit 1
202-
fi
203167
cd $src_dir > /dev/null
204168
git submodule update --init $1
205169
cd - > /dev/null
206170
}
207171

208172
# download a magnetic field map
209173
download_map () {
210-
ret=0
211-
if $useXrootd; then
212-
notify_retrieval 'field map' 'xrootd'
213-
xrdcp $1 ./
214-
ret=$?
215-
elif $useCvmfs; then
216-
notify_retrieval 'field map' 'cvmfs'
217-
cp $1 ./
218-
ret=$?
219-
elif command_exists wget ; then
174+
ret=0
175+
case $dataRetrieval in
176+
cvmfs)
177+
notify_retrieval 'field map' 'cvmfs'
178+
cp $1 ./
179+
ret=$?
180+
;;
181+
clasweb)
182+
if command_exists wget ; then
220183
notify_retrieval 'field map' 'clasweb via wget'
221184
$wget $1
222185
ret=$?
223-
elif command_exists curl ; then
186+
elif command_exists curl ; then
224187
notify_retrieval 'field map' 'clasweb via curl'
225188
if ! [ -e ${1##*/} ]; then
226189
curl $1 -o ${1##*/}
227190
ret=$?
228191
fi
229-
else
192+
else
230193
ret=1
231194
echo "ERROR::::::::::: Could not find wget nor curl." >&2
232-
fi
233-
return $ret
195+
fi
196+
;;
197+
*)
198+
ret=1
199+
echo "ERROR::::::::::: called 'download_map' with bad 'dataRetrieval'." >&2
200+
;;
201+
esac
202+
return $ret
234203
}
235204

205+
# check data-retrieval options, and prepare accordingly
206+
case $dataRetrieval in
207+
lfs)
208+
if ! command_exists git-lfs ; then
209+
echo 'ERROR: `git-lfs` not found; please install it, or use a different data-retrieval option other than `--lfs`' >&2
210+
exit 1
211+
fi
212+
git lfs install
213+
;;
214+
cvmfs)
215+
path=/cvmfs/oasis.opensciencegrid.org/jlab
216+
if [ ! -d $path ]; then
217+
echo "ERROR: cannot find CVMFS path '$path'; data retrieval option \`--cvmfs\` failed" >&2
218+
exit 1
219+
fi
220+
;;
221+
clasweb)
222+
;;
223+
*)
224+
echo "ERROR: data retrieval option '$dataRetrieval' is not supported" >&2
225+
exit 1
226+
;;
227+
esac
228+
236229
# download the default field maps, as defined in libexec/env.sh:
237230
# (and duplicated in etc/services/reconstruction.yaml):
238231
if $downloadMaps; then
239-
if $useLfs; then
240-
notify_retrieval 'field maps' 'lfs'
241-
download_lfs etc/data/magfield
242-
else
243-
webDir=https://clasweb.jlab.org/clas12offline/magfield
244-
if $useXrootd; then webDir=xroot://sci-xrootd.jlab.org//osgpool/hallb/clas12/coatjava/magfield; fi
245-
if $useCvmfs; then webDir=/cvmfs/oasis.opensciencegrid.org/jlab/hallb/clas12/sw/noarch/data/magfield; fi
246-
mkdir -p $magfield_dir
247-
cd $magfield_dir
248-
for map in $COAT_MAGFIELD_SOLENOIDMAP $COAT_MAGFIELD_TORUSMAP $COAT_MAGFIELD_TORUSSECONDARYMAP
249-
do
250-
download_map $webDir/$map
251-
if [ $? -ne 0 ]; then
252-
echo "ERROR::::::::::: Could not download field map:" >&2
253-
echo "$webDir/$map" >&2
254-
echo "One option is to download manually into etc/data/magfield and then run this build script with --nomaps" >&2
255-
exit 1
232+
case $dataRetrieval
233+
lfs)
234+
notify_retrieval 'field maps' 'lfs'
235+
download_lfs etc/data/magfield
236+
;;
237+
cvmfs|clasweb)
238+
webDir=https://clasweb.jlab.org/clas12offline/magfield
239+
if [ "$dataRetrieval" = "cvmfs" ]; then
240+
webDir=/cvmfs/oasis.opensciencegrid.org/jlab/hallb/clas12/sw/noarch/data/magfield
256241
fi
257-
done
258-
cd -
259-
fi
242+
mkdir -p $magfield_dir
243+
cd $magfield_dir
244+
for map in $COAT_MAGFIELD_SOLENOIDMAP $COAT_MAGFIELD_TORUSMAP $COAT_MAGFIELD_TORUSSECONDARYMAP
245+
do
246+
download_map $webDir/$map
247+
if [ $? -ne 0 ]; then
248+
echo "ERROR::::::::::: Could not download field map:" >&2
249+
echo "$webDir/$map" >&2
250+
echo "One option is to download manually into etc/data/magfield and then run this build script with --nomaps" >&2
251+
exit 1
252+
fi
253+
done
254+
cd -
255+
;;
256+
*)
257+
echo "ERROR: data retrieval option '$dataRetrieval' not supported for field maps" >&2
258+
exit 1
259+
;;
260+
esac
260261
fi
261262

262263
# download neural networks
263264
if $downloadNets; then
264-
if $useLfs; then
265-
notify_retrieval 'neural networks' 'lfs'
266-
download_lfs etc/data/nnet
267-
elif $useCvmfs; then
268-
notify_retrieval 'neural networks' 'cvmfs'
269-
cp -r /cvmfs/oasis.opensciencegrid.org/jlab/hallb/clas12/sw/noarch/data/networks/* etc/data/nnet/
270-
else
271-
echo 'WARNING: neural networks not downloaded; run with `--help` for guidance' >&2
272-
sleep 1
273-
fi
265+
case $dataRetrieval in
266+
lfs)
267+
notify_retrieval 'neural networks' 'lfs'
268+
download_lfs etc/data/nnet
269+
;;
270+
cvmfs)
271+
notify_retrieval 'neural networks' 'cvmfs'
272+
cp -r /cvmfs/oasis.opensciencegrid.org/jlab/hallb/clas12/sw/noarch/data/networks/* etc/data/nnet/
273+
;;
274+
*)
275+
echo 'WARNING: neural networks not downloaded; run with `--help` for guidance' >&2
276+
sleep 1
277+
;;
278+
esac
274279
fi
275280

276281
# download validation data
277282
if $downloadData; then
278-
notify_retrieval 'validation data' 'lfs'
279-
download_lfs validation/advanced-tests/data
283+
case $dataRetrieval in
284+
lfs)
285+
notify_retrieval 'validation data' 'lfs'
286+
download_lfs validation/advanced-tests/data
287+
;;
288+
*)
289+
echo 'ERROR: option `--lfs` must be used when using `--data`' >&2
290+
exit 1
291+
;;
292+
esac
280293
fi
281294

282295

0 commit comments

Comments
 (0)