1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # ========================================================================
|
---|
4 | #
|
---|
5 | # *
|
---|
6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
7 | # * Software. It is distributed to you in the hope that it can be a useful
|
---|
8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
9 | # * It is distributed WITHOUT ANY WARRANTY.
|
---|
10 | # *
|
---|
11 | # * Permission to use, copy, modify and distribute this software and its
|
---|
12 | # * documentation for any purpose is hereby granted without fee,
|
---|
13 | # * provided that the above copyright notice appear in all copies and
|
---|
14 | # * that both that copyright notice and this permission notice appear
|
---|
15 | # * in supporting documentation. It is provided "as is" without express
|
---|
16 | # * or implied warranty.
|
---|
17 | # *
|
---|
18 | #
|
---|
19 | #
|
---|
20 | # Author(s): Daniela Dorner 08/2008 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2008
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script produces the plots from all root-files in the web directory
|
---|
28 | #
|
---|
29 | # After checking, if the script is already running, the plots are produced:
|
---|
30 | # With the programm showplot a ps-file is written, from which the png
|
---|
31 | # files are produced.
|
---|
32 | #
|
---|
33 | # The files from which plots are created can be devided into two categories:
|
---|
34 | # general: plots needed only once per telescope
|
---|
35 | # individual: plots done for each sequence / dataset
|
---|
36 | #
|
---|
37 | # For 'general' first the rootfiles are created with a macro from the
|
---|
38 | # database, then from this the ps via showplot, from this the pdf and the
|
---|
39 | # png files.
|
---|
40 | # For 'individual' running the macro is only needed for the plotdb for
|
---|
41 | # ganymed. The other steps are done accordingly.
|
---|
42 | #
|
---|
43 | # Via command line options the plots can be selected. For more information
|
---|
44 | # execute the script with the -h option.
|
---|
45 | #
|
---|
46 |
|
---|
47 | source `dirname $0`/sourcefile
|
---|
48 | printprocesslog "INFO starting $0"
|
---|
49 | program=dowebplots
|
---|
50 |
|
---|
51 | set -C
|
---|
52 |
|
---|
53 |
|
---|
54 | scriptlog=$runlogpath/$program-$datetime.log
|
---|
55 | date >> $scriptlog 2>&1
|
---|
56 |
|
---|
57 | echo $@ >> $scriptlog 2>&1
|
---|
58 |
|
---|
59 | # definition of the plots to be created
|
---|
60 | generals=( plotdb optical condor status )
|
---|
61 | individuals=( calib signal star ganymed gplotdb )
|
---|
62 | # definition of the variables needed and varying for the plots
|
---|
63 | names=( plotdb optical condor status calib signal star ganymed gplotdb )
|
---|
64 | pathnames=( plotdb optical condor status callisto callisto star ganymed ganymed )
|
---|
65 | macros=( plotdb plotoptical plotusage plotstat no no no no no )
|
---|
66 | filenames=( plotdb plotoptical plotusage plotstat calib signal star ganymed plotdb )
|
---|
67 | columns=( no no no no fWebCalib fWebSignal fWebStar fWebGanymed fWebPlotDBGanymed )
|
---|
68 | digits=( 0 0 0 0 4 4 4 5 5 )
|
---|
69 |
|
---|
70 | # function to print the usage of the script
|
---|
71 | function usage()
|
---|
72 | {
|
---|
73 | echo "Usage: $0 [options]"
|
---|
74 | echo "options:"
|
---|
75 | echo -n " --general name "
|
---|
76 | echo " where 'name' can be 'all' or one of the following: ${generals[@]} "
|
---|
77 | echo -n " --individual name "
|
---|
78 | echo " where 'name' can be 'all' or one of the following: ${individuals[@]} "
|
---|
79 | echo -n " -h "
|
---|
80 | echo " print this usage "
|
---|
81 | echo ""
|
---|
82 | echo "Remark: if no commandline option is given the plots are produced for everything."
|
---|
83 | echo ""
|
---|
84 | exit
|
---|
85 | }
|
---|
86 |
|
---|
87 | # reading in the command line options
|
---|
88 | general=( )
|
---|
89 | individual=( )
|
---|
90 | while [ "$1" ]
|
---|
91 | do
|
---|
92 | case $1 in
|
---|
93 | --general) shift
|
---|
94 | if [ "$1" = "all" ]
|
---|
95 | then
|
---|
96 | general=( ${generals[@]} )
|
---|
97 | else
|
---|
98 | general=( ${general[@]} $1 )
|
---|
99 | fi
|
---|
100 | ;;
|
---|
101 | --individual) shift
|
---|
102 | if [ "$1" = "all" ]
|
---|
103 | then
|
---|
104 | individual=( ${individuals[@]} )
|
---|
105 | else
|
---|
106 | individual=( ${individual[@]} $1 )
|
---|
107 | fi
|
---|
108 | ;;
|
---|
109 | -h) usage
|
---|
110 | exit
|
---|
111 | ;;
|
---|
112 | *) echo "unknown option $1 " >> $scriptlog 2>&1
|
---|
113 | usage >> $scriptlog 2>&1
|
---|
114 | exit
|
---|
115 | ;;
|
---|
116 | esac
|
---|
117 | shift
|
---|
118 | done
|
---|
119 |
|
---|
120 | if [ ${#general[@]} -eq 0 ] && [ ${#individual[@]} -eq 0 ]
|
---|
121 | then
|
---|
122 | all=( ${names[@]} )
|
---|
123 | else
|
---|
124 | all=( ${general[@]} ${individual[@]} )
|
---|
125 | fi
|
---|
126 |
|
---|
127 | echo "For the following plots will be produced: "${all[@]} >> $scriptlog 2>&1
|
---|
128 |
|
---|
129 |
|
---|
130 | # rsync subsystemdata, sequence and dataset files
|
---|
131 | echo "do rsync for subsystem files" >> $scriptlog 2>&1
|
---|
132 | rsync -av --delete $subsystempath/ $webpath/subsystemdata >> $scriptlog 2>&1
|
---|
133 |
|
---|
134 | echo "do rsync for sequence files" >> $scriptlog 2>&1
|
---|
135 | rsync -av --delete $sequencepath/ $webpath/sequences >> $scriptlog 2>&1
|
---|
136 |
|
---|
137 | echo "do rsync for dataset files" >> $scriptlog 2>&1
|
---|
138 | rsync -av --delete $datasetpath/ $webpath/datasets >> $scriptlog 2>&1
|
---|
139 |
|
---|
140 |
|
---|
141 | # using hour for lock => after 24 no new script is
|
---|
142 | # started in case the previous is still running
|
---|
143 | hour=`date +%H`
|
---|
144 | lockfile=$lockpath/${program}-${hour}h.txt
|
---|
145 | checklock >> $scriptlog 2>&1
|
---|
146 |
|
---|
147 | count=0
|
---|
148 | # loop over all scripts in $names
|
---|
149 | while [ 1 -gt 0 ]
|
---|
150 | do
|
---|
151 | check="ok"
|
---|
152 | # get needed variables from the arrays
|
---|
153 | name=${names[$count]}
|
---|
154 | macro=${macros[$count]}
|
---|
155 | pathname=${pathnames[$count]}
|
---|
156 | filename=${filenames[$count]}
|
---|
157 | column=${columns[$count]}
|
---|
158 | digit=${digits[$count]}
|
---|
159 |
|
---|
160 | count=`expr $count + 1`
|
---|
161 | if [ $count -gt ${#names[@]} ]
|
---|
162 | then
|
---|
163 | count=0
|
---|
164 | continue
|
---|
165 | fi
|
---|
166 | # find out if these plots have to be created
|
---|
167 | # by looping over the complete array $all and comparing the entries to those of the array $names
|
---|
168 | for (( a=0 ; a <= ${#all[@]} ; a++ ))
|
---|
169 | do
|
---|
170 | # exit the loop if the entries agree
|
---|
171 | # i.e. produce plots for this entry
|
---|
172 | if [ "${all[$a]}" = "$name" ]
|
---|
173 | then
|
---|
174 | break
|
---|
175 | fi
|
---|
176 | # continue if the end of array is not yet reached
|
---|
177 | if [ $a -lt ${#all[@]} ]
|
---|
178 | then
|
---|
179 | continue
|
---|
180 | fi
|
---|
181 | # exit both loops if no entry in the array is left
|
---|
182 | # i.e. there is nothing to do anymore
|
---|
183 | if [ ${#all[@]} -eq 0 ]
|
---|
184 | then
|
---|
185 | break 2
|
---|
186 | fi
|
---|
187 | # continue with the next entry in the array $names
|
---|
188 | # in case the end of the array $all is reached without agreement
|
---|
189 | continue 2
|
---|
190 | done
|
---|
191 |
|
---|
192 | # do things specific to 'general' and 'individual'
|
---|
193 | if [ "$macro" = "no" ]
|
---|
194 | then
|
---|
195 | # 'individual'
|
---|
196 | # remove name from list in case there is nothing left to do
|
---|
197 | getstatus >> $scriptlog 2>&1
|
---|
198 | if [ "$numproc" = "" ]
|
---|
199 | then
|
---|
200 | unset all[$a]
|
---|
201 | all=( ${all[@]} )
|
---|
202 | continue
|
---|
203 | fi
|
---|
204 | # get one sequence or dataset from the database for which plots have to be produced
|
---|
205 | gettodo "1" >> $scriptlog 2>&1
|
---|
206 | num=${primaries[0]}
|
---|
207 | echo "executing $name for number "$num >> $scriptlog 2>&1
|
---|
208 | # lock the process
|
---|
209 | lockfile=$lockpath/$program-$name-$num.txt
|
---|
210 | checklock continue >> $scriptlog 2>&1
|
---|
211 | setstatus "start" >> $scriptlog 2>&1
|
---|
212 | # set needed file and path names
|
---|
213 | pathpart=$pathname/`printf %08d $num | cut -c 0-${digit}`/`printf %08d $num`
|
---|
214 | inpath=$datapath/$pathpart
|
---|
215 | outpath=$webpath/$pathpart
|
---|
216 | tmppath=/tmp/pstoimg$pathpart
|
---|
217 | rootfile=$inpath/$filename`printf %08d $num`.root
|
---|
218 | psfile=$inpath/$filename`printf %08d $num`.ps
|
---|
219 | csvfile=$outpath/$filename`printf %08d $num`.csv
|
---|
220 | pdffile=$outpath/$filename`printf %08d $num`.pdf
|
---|
221 | # rsync
|
---|
222 | makedir $outpath >> $scriptlog 2>&1
|
---|
223 | rsync -aLv --exclude=20[01][0-9]*_[YI]_*[.]root $inpath/ $outpath >> $scriptlog 2>&1
|
---|
224 |
|
---|
225 | # for ganymed not only the ganymed*.root is processed but also a plotdb.root for the
|
---|
226 | # dataset. therefore the macro plotdb.C has to be run in this case
|
---|
227 | if [ "$name" = "gplotdb" ]
|
---|
228 | then
|
---|
229 | # overwrite needed file and path names
|
---|
230 | rootfile=$inpath/$filename.root
|
---|
231 | psfile=$inpath/$filename.ps
|
---|
232 | csvfile=$outpath/$filename.csv
|
---|
233 | pdffile=$outpath/$filename.pdf
|
---|
234 | datasetfile=$datasetpath/`printf %08d $num | cut -c 0-${digit}`/dataset`printf %08d $num`.txt
|
---|
235 |
|
---|
236 | echo "check1=root -q -b $macrospath/plotdb.C+\(\"$datasetfile\"\,\"$inpath/\"\) 2>|/dev/null | tee -a $scriptlog | intgrep" >> $scriptlog 2>&1
|
---|
237 | check1=`root -q -b $macrospath/plotdb.C+\("\"$datasetfile\""\,"\"$inpath/\""\) 2>|/dev/null | tee -a $scriptlog | intgrep`
|
---|
238 | case $check1 in
|
---|
239 | 1) echo " check1=$check1 -> everything ok" >> $scriptlog 2>&1
|
---|
240 | printprocesslog "INFO rootfile $rootfile successfully produced"
|
---|
241 | ;;
|
---|
242 | *) echo " check1=$check1 -> ERROR -> couldn't create plots -> exit" >> $scriptlog 2>&1
|
---|
243 | printprocesslog "ERROR producing rootfile $rootfile failed"
|
---|
244 | com=$Fdowebplots
|
---|
245 | check=$check1
|
---|
246 | ;;
|
---|
247 | esac
|
---|
248 | fi
|
---|
249 | else
|
---|
250 | # 'general'
|
---|
251 | echo "executing $name " >> $scriptlog 2>&1
|
---|
252 | # remove 'general' from list as they need to be executed only once
|
---|
253 | unset all[$a]
|
---|
254 | all=( ${all[@]} )
|
---|
255 | # lock process
|
---|
256 | lockfile=$lockpath/$program-$name.txt
|
---|
257 | checklock continue >> $scriptlog 2>&1
|
---|
258 | # set needed file and path names
|
---|
259 | outpath=$webpath/$pathname
|
---|
260 | tmppath=/tmp/$pathname
|
---|
261 | rootfile=$outpath/$filename.root
|
---|
262 | psfile=$outpath/$filename.ps
|
---|
263 | csvfile=$outpath/$filename.csv
|
---|
264 | pdffile=$outpath/$filename.pdf
|
---|
265 | txtfile=$outpath/$filename.txt
|
---|
266 |
|
---|
267 | echo "check2=root -q -b $macrospath/$macro.C+\(\"$outpath/\"\) 2>| $txtfile | tee -a $scriptlog | intgrep" >> $scriptlog 2>&1
|
---|
268 | check2=`root -q -b $macrospath/$macro.C+\("\"$outpath/\""\) 2>| $txtfile | tee -a $scriptlog | intgrep`
|
---|
269 | case $check2 in
|
---|
270 | 1) echo " check2=$check2 -> everything ok" >> $scriptlog 2>&1
|
---|
271 | printprocesslog "INFO rootfile $rootfile successfully produced"
|
---|
272 | ;;
|
---|
273 | *) echo " check2=$check2 -> ERROR -> couldn't produce root file $rootfile -> exit" >> $scriptlog 2>&1
|
---|
274 | printprocesslog "ERROR producing rootfile $rootfile failed"
|
---|
275 | com=$Fdowebplots
|
---|
276 | check=$check2
|
---|
277 | ;;
|
---|
278 | esac
|
---|
279 | fi
|
---|
280 |
|
---|
281 | # in case no error occured, the plots are produced from the rootfile
|
---|
282 | if [ "$check" = "ok" ]
|
---|
283 | then
|
---|
284 | printprocesslog "INFO procduing plots (psfile and png) for $rootfile"
|
---|
285 | if ! ls $rootfile >/dev/null 2>&1
|
---|
286 | then
|
---|
287 | echo "rootfile $rootfile does not exist" >> $scriptlog 2>&1
|
---|
288 | printprocesslog "ERROR rootfile $rootfile does not exist"
|
---|
289 | com=$Fdowebplots
|
---|
290 | check=3
|
---|
291 | else
|
---|
292 | echo "producing psfile and csvfile..." >> $scriptlog 2>&1
|
---|
293 | if ! ./showplot -b --save-as-ps=$psfile --save-as-csv=$csvfile $rootfile >> $scriptlog 2>&1
|
---|
294 | then
|
---|
295 | com=$Fdowebplots
|
---|
296 | check=4
|
---|
297 | else
|
---|
298 | echo "creating temporary directory for pstoimg..." >> $scriptlog 2>&1
|
---|
299 | makedir $tmppath >> $scriptlog 2>&1
|
---|
300 |
|
---|
301 | echo "converting plots to png..." >> $scriptlog 2>&1
|
---|
302 | if ! pstoimg -antialias -aaliastext -interlaced -flip r270 -density 100 -tmp $tmppath -out=$outpath/$name -type png -multipage $psfile >> $scriptlog 2>&1
|
---|
303 | then
|
---|
304 | printprocesslog "WARN could not create png files for $psfile "
|
---|
305 | com=$Fdowebplots
|
---|
306 | check=5
|
---|
307 | fi
|
---|
308 |
|
---|
309 | echo "removing temporary directory..." >> $scriptlog 2>&1
|
---|
310 | rmdir -pv $tmppath >> $scriptlog 2>&1
|
---|
311 |
|
---|
312 | echo "converting $psfile to pdf..." >> $scriptlog 2>&1
|
---|
313 | fi
|
---|
314 |
|
---|
315 | if ps2pdf $psfile $pdffile >> $scriptlog 2>&1
|
---|
316 | then
|
---|
317 | rm -v $psfile >> $scriptlog 2>&1
|
---|
318 | else
|
---|
319 | printprocesslog "WARN could not convert $psfile to $pdffile"
|
---|
320 | com=$Fdowebplots
|
---|
321 | check=6
|
---|
322 | fi
|
---|
323 | fi
|
---|
324 | fi
|
---|
325 |
|
---|
326 | setstatus "stop" >> $scriptlog 2>&1
|
---|
327 |
|
---|
328 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
329 |
|
---|
330 | sleep 2
|
---|
331 | done
|
---|
332 |
|
---|
333 | # rsync for complete directory delete removed sequences
|
---|
334 | echo "do rsync for callisto, star and ganymed files" >> $scriptlog 2>&1
|
---|
335 | rsync -aLv --delete --exclude=*/*/20[01][0-9]*_[YI]_*[.]root --exclude=*/*.ps $datapath/{callisto,star,ganymed}/ $webpath/callisto >> $scriptlog 2>&1
|
---|
336 |
|
---|
337 | lockfile=$lockpath/${program}-${hour}h.txt
|
---|
338 | finish >> $scriptlog 2>&1
|
---|
339 |
|
---|
340 |
|
---|