4# ------------------------------------------------------------------------------------------
6# Auxiliary script to test consistency of geometry of optical modules from database.
8# ------------------------------------------------------------------------------------------
10if [ -z $JPP_DIR ]; then
11 echo "Variable JPP_DIR undefined."
15source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
18set_variable: WORKDIR TEST_WORKDIR ${TMPDIR:-/tmp}
19set_array FILTER P0ARCW016
21if ( do_usage $* ); then
22 usage "$script (detector identifier)*"
32 if [[ "$D[1]" == "D" ]]; then
33 DETECTORS[$D]=$(getDetector -D $D -O int)
35 DETECTORS[$(getDetector -D $D -O string)]=$D
40 # list of detectors deployed in the sea
44 DETECTORS=($(JPrintDB \
47 -W 1 | awk -F "$CSV" '{ if ($4 ~ ".*Deployment.*") { print $1, $2 }}'))
50# dependencies of pre-calibration of detectors
52typeset -A DEPENDENCIES
54DEPENDENCIES[D0ARCA009]=D0ARCA006
55DEPENDENCIES[D0ARCA021]=D0ARCA009
56DEPENDENCIES[D0ARCA020]=D0ARCA021
57#DEPENDENCIES[D0ARCA028]=D0ARCA021 # optical module anomalies already implemented in database for this detector
59DEPENDENCIES[D0ORCA018]=D1ORCA015
60DEPENDENCIES[D1ORCA015]=D0ORCA015
61DEPENDENCIES[D0ORCA015]=D1ORCA011
62DEPENDENCIES[D1ORCA011]=D0ORCA010
63DEPENDENCIES[D0ORCA010]=D_ORCA006
64DEPENDENCIES[D0ORCA023]=D0ORCA018
66# future modificatons per detector
69D0ARCA051+=("-M \"805631219 swap 23 25\"")
70D0ARCA051+=("-M \"805631219 swap 24 30\"")
71D0ARCA051+=("-M \"805536812 lower \$((+60.0 * \$PI / 180.0))\"")
72D0ARCA051+=("-M \"810310870 swap 12 15\"")
73#D0ARCA051+=("-R \"805536976 D1\"") # anomalies of this optical module already implemented in database
75D0ARCW021=($D0ARCA051) # copy modifications
79for DETID DETOID in ${(kv)DETECTORS}; do
81 if (( $FILTER[(I)$DETID] != 0)); then
85 printf "Checking detector %s/%4d\n" $DETID $DETOID
87 RUNS=($(JRuns -D $DETID -F RUN))
89 if (( ${#RUNS} != 0 )); then
91 JDetectorDB -D $DETID -@ "tcal = ?" -@ "pcal = ?" -@ "rcal = ?" -@ "acal = ?" -@ "ccal = ?" -@ "scal = ?" -o $WORKDIR/detector.datx
93 # future modifications
95 MODIFICATIONS=(${(P)DETID})
97 # recursively collect previous modifications
101 while [[ "$D" != "" ]]; do
103 ACOUSTICS_SCRIPT=$(which pre-calibration_$D.sh)
105 if (( $? == 0 )); then
106 MODIFICATIONS+=("$(grep -- swap $ACOUSTICS_SCRIPT | tr '\\' ' ')")
107 MODIFICATIONS+=("$(grep -- lower $ACOUSTICS_SCRIPT | tr '\\' ' ')")
108 MODIFICATIONS+=("$(grep -- -R $ACOUSTICS_SCRIPT | tr '\\' ' ')")
111 if [[ "$DEPENDENCIES[$D]" != "" ]]; then
112 echo "$D -> $DEPENDENCIES[$D]"
120 for (( i = 1; $i <= ${#MODIFICATIONS}; )); do
121 if [[ "$MODIFICATIONS[$i]" == "" ]]; then
128 # apply mofifications
130 if (( ${#MODIFICATIONS} != 0 )); then
132 echo "Applying modifications:"
134 for M in $MODIFICATIONS[*]; do
139 -a $WORKDIR/detector.datx \
140 -o $WORKDIR/detector.datx \
146 $JPP_DIR/software/JDetector/JDestructDetector -a $WORKDIR/detector.datx -o $WORKDIR/test_%.txt
148 if (( $? != 0 )); then
152 echo "${RED}Detector $DETID is incompatible with database.${RESET}"
154 echo "${GREEN}Detector $DETID is compatible with database after ${#MODIFICATIONS} modifications.${RESET}"
159rm -f $WORKDIR/detector.datx
160rm -f $WORKDIR/test_*.txt
162if (( ${#ERRORS} != 0 )); then
163 fatal "Failing detectors $ERRORS[*]."