forked from gemc/clas12Tags
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_geometry.sh
More file actions
executable file
·128 lines (102 loc) · 3.41 KB
/
create_geometry.sh
File metadata and controls
executable file
·128 lines (102 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/zsh
cdir=$(pwd)
export COATJAVA=$cdir/geometry_source/coatjava
export PATH=$PATH:$COATJAVA/bin
# CLAS12
all_dets="alert band beamline bst cnd ctof dc ddvcs ec fluxDets ft ftof ftofShield htcc ltcc magnets micromegas pcal rich rtpc targets uRwell upstream"
function printHelp() {
cat <<EOF
Usage: create_geometry.sh [coatjava release options] [detector]
Coatjava options (optional – at most one of -d|-l|-t|-g):
-l use latest tag (default)
-t <tag> use specific tag, like 12.0.4t
-g <github_url> use custom github URL
-h show this help
If a detector is given, only that detector will be built; otherwise every detector below is processed:
$all_dets
EOF
}
coatjava_args=("-l") # default behaviour = latest tag
explicit_coatjava=0 # did the user pass a coatjava flag?
while getopts ":lt:g:h" opt; do
case "$opt" in
l) coatjava_args=("-l"); explicit_coatjava=1 ;;
t) coatjava_args=("-t" "$OPTARG"); explicit_coatjava=1 ;;
g) coatjava_args=("-g" "$OPTARG"); explicit_coatjava=1 ;;
h) printHelp; exit 0 ;;
:) echo "Error: -$OPTARG requires an argument." >&2; exit 1 ;;
\?) echo "Error: unknown option -$OPTARG" >&2; printHelp; exit 1 ;;
esac
done
shift $((OPTIND - 1)) # drop parsed options
# Positional argument = detector (optional)
if [[ $# -gt 0 ]]; then
detector="$1"
if [[ ! " $all_dets " =~ " $detector " ]]; then
echo "Error: '$detector' is not a recognised detector." >&2
exit 1
fi
all_dets="$detector"
fi
function find_subdirs_with_file() {
local subdirs_with_file=() # Initialize an empty array to store matching subdirs
for file in $(find . -name "cad*.gxml"); do
# subdir is the full path of the directory containing the file
subdir=$(dirname $file)
subdirs_with_file+=($subdir) # Add the directory to the array
done
# remove duplicates
subdirs_with_file=($(echo "${(@u)subdirs_with_file}"))
echo "${subdirs_with_file[@]}" # Return the array by echoing it
}
function copyFilesAndCadDirsTo() {
destination=$1
rm -rf $destination
mkdir -p $destination
cp *.txt "$destination/"
cp *.gcard "$destination/"
cadDirs=$(find_subdirs_with_file)
for cadDir in $=cadDirs; do
echo Copying CAD Subdirs: $cadDir to $destination
# copy $cadDir preserving full path. Notice it needs the relative path.
rsync -aR "./$cadDir" "$destination/"
done
}
# Creating new clas12.sqlite DB
if [ ! -f "clas12.sqlite" ]; then
$cdir/api/perl/sqlite.py -n clas12.sqlite
fi
cd geometry_source
# if the directory coatjava does not exist, run the script to create it
if [[ ! -d coatjava || $explicit_coatjava -eq 1 ]]; then
[[ -d coatjava ]] && echo "Re‑installing coatjava with specified options..."
./install_coatjava.sh "${coatjava_args[@]}"
if [[ $? -ne 0 ]]; then
echo "Error: coatjava build failed. See ../build_coatjava.log for details."
exit 1
fi
fi
# loop over all dets
for dete in $=all_dets; do
cd $dete
echo
echo " > Removing $cdir/experiments/clas12/$dete"
echo " > And building $dete"
echo
rm -rf "$cdir/experiments/clas12/$dete"
# pre-requirements
if [ $dete = "ltcc" ]; then
echo " > Running LTCC mirrors.C"
root -q -b mirrors.C
fi
# main run
if [[ -f "./$dete.pl" ]]; then
./"$dete.pl" config.dat
if [[ $? -ne 0 ]]; then
echo "Error: building $dete failed. Check the geometry build log for details."
exit 1
fi
fi
copyFilesAndCadDirsTo "$cdir/experiments/clas12/$dete"
cd ..
done