Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
archive-put-online-detectors.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 script=${0##*/}
3 
4 if [ -z $JPP_DIR ]; then
5  echo "Variable JPP_DIR undefined."
6  exit
7 fi
8 
9 source $JPP_DIR/setenv.sh $JPP_DIR >& /dev/null
10 
11 set_variable: DEBUG ARCHIVE_DEBUG 2
12 set_variable: WORKDIR ARCHIVE_WORKDIR ${TMPDIR:-/tmp}/
13 set_variable TYPE online
14 
15 if do_usage $*; then
16  usage "$script <archive> <version> <detector identifier> (run[-run])+"\
17  "\nAuxiliary script to download online detector files from database and to store these in archive."
18 fi
19 
20 if (( $# > 3 )); then
21  set_variable ARCHIVE $argv[1]
22  set_variable VERSION $argv[2]
23  set_variable DETECTOR_ID $argv[3]
24  set_array RUNS $argv[4,-1]
25 else
26  fatal "Wrong number of arguments."
27 fi
28 
29 JCookie.sh
30 
31 set_variable DETECTOR_ID $(getDetector -D $DETECTOR_ID -O int)
32 set_variable DETECTOR $WORKDIR/detector.detx
33 
34 for RANGE in $RUNS[*]; do
35 
36  let "MINRUN = ${RANGE%%-*}"
37  let "MAXRUN = ${RANGE##*-}"
38 
39  for (( i0 = $MINRUN; $i0 <= $MAXRUN; )); do
40 
41  JRuns \
42  -D $DETECTOR_ID \
43  -@ "run = $i0" \
44  -F T0_CALIBSETID \
45  -F POS_CALIBSETID \
46  -F ROT_CALIBSETID \
47  -F RUN | read TCAL_0 PCAL_0 RCAL_0 RUN_0
48 
49  if (( $? != 0 )) || [[ "$RUN_0" == "" ]] || (( $RUN_0 != $i0 )); then
50 
51  let "i0 = $i0 + 1"
52 
53  continue
54  fi
55 
56  notice "Run $RUN_0 $TCAL_0 $PCAL_0 $RCAL_0"
57 
58  for (( i1 = $i0 + 1; $i1 <= $MAXRUN; i1 += 1 )); do
59 
60  JRuns \
61  -D $DETECTOR_ID \
62  -@ "run = $i1" \
63  -F T0_CALIBSETID \
64  -F POS_CALIBSETID \
65  -F ROT_CALIBSETID \
66  -F RUN | read TCAL_1 PCAL_1 RCAL_1 RUN_1
67 
68  if (( $? != 0 )) || [[ "$RUN_1" == "" ]] || (( $RUN_1 != $i1 )); then
69  continue
70  fi
71 
72  notice "Run $RUN_1 $TCAL_1 $PCAL_1 $RCAL_1"
73 
74  if [[ "$TCAL_0" != "$TCAL_1" || "$PCAL_0" != "$PCAL_1" || "$RCAL_0" != "$RCAL_1" ]] then
75  break
76  fi
77  done
78 
79  JDetectorDB \
80  -D $DETECTOR_ID \
81  -@ "tcal = $TCAL_0" \
82  -@ "pcal = $PCAL_0" \
83  -@ "rcal = $RCAL_0" \
84  -V "" \
85  -o $DETECTOR --!
86 
87  if (( $? == 0 )); then
88  putFile.sh $DETECTOR $ARCHIVE $DETECTOR_ID $i0 $(($i1 - 1)) $TYPE $VERSION
89  else
90  error "Failure in downloading detector from database."
91  fi
92 
93  if (( $? == 0 )); then
94  rm -f $DETECTOR
95  else
96  fatal "$DETECTOR not stored in archive $ARCHIVE."
97  fi
98 
99  let "i0 = $i1"
100  done
101 done