source: trunk/MagicSoft/Mars/datacenter/scripts/dowebplots@ 9539

Last change on this file since 9539 was 9539, checked in by snruegam, 12 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 11.8 KB
Line 
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
47source `dirname $0`/sourcefile
48printprocesslog "INFO starting $0"
49program=dowebplots
50
51set -C
52
53
54scriptlog=$runlogpath/$program-$datetime.log
55date >> $scriptlog 2>&1
56
57echo $@ >> $scriptlog 2>&1
58
59# definition of the plots to be created
60generals=( plotdb optical condor status )
61individuals=( calib signal star ganymed gplotdb )
62# definition of the variables needed and varying for the plots
63names=( plotdb optical condor status calib signal star ganymed gplotdb )
64pathnames=( plotdb optical condor status callisto callisto star ganymed ganymed )
65macros=( plotdb plotoptical plotusage plotstat no no no no no )
66filenames=( plotdb plotoptical plotusage plotstat calib signal star ganymed plotdb )
67columns=( no no no no fWebCalib fWebSignal fWebStar fWebGanymed fWebPlotDBGanymed )
68digits=( 0 0 0 0 4 4 4 5 5 )
69
70# function to print the usage of the script
71function 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
88general=( )
89individual=( )
90while [ "$1" ]
91do
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
118done
119
120if [ ${#general[@]} -eq 0 ] && [ ${#individual[@]} -eq 0 ]
121then
122 all=( ${names[@]} )
123else
124 all=( ${general[@]} ${individual[@]} )
125fi
126
127echo "For the following plots will be produced: "${all[@]} >> $scriptlog 2>&1
128
129# using hour for lock => after 24 no new script is
130# started in case the previous is still running
131hour=`date +%H`
132lockfile=$lockpath/${program}-${hour}h.txt
133checklock >> $scriptlog 2>&1
134
135# make sure that ./showplot is executed from the right directory
136cd $mars
137
138count=0
139# loop over all scripts in $names
140while [ 1 -gt 0 ]
141do
142 check="ok"
143 # get needed variables from the arrays
144 name=${names[$count]}
145 macro=${macros[$count]}
146 pathname=${pathnames[$count]}
147 filename=${filenames[$count]}
148 column=${columns[$count]}
149 digit=${digits[$count]}
150
151 count=`expr $count + 1`
152 if [ $count -gt ${#names[@]} ]
153 then
154 count=0
155 continue
156 fi
157 # find out if these plots have to be created
158 # by looping over the complete array $all and comparing the entries to those of the array $names
159 for (( a=0 ; a <= ${#all[@]} ; a++ ))
160 do
161 # exit the loop if the entries agree
162 # i.e. produce plots for this entry
163 if [ "${all[$a]}" = "$name" ]
164 then
165 break
166 fi
167 # continue if the end of array is not yet reached
168 if [ $a -lt ${#all[@]} ]
169 then
170 continue
171 fi
172 # exit both loops if no entry in the array is left
173 # i.e. there is nothing to do anymore
174 if [ ${#all[@]} -eq 0 ]
175 then
176 break 2
177 fi
178 # continue with the next entry in the array $names
179 # in case the end of the array $all is reached without agreement
180 continue 2
181 done
182
183 # do things specific to 'general' and 'individual'
184 if [ "$macro" = "no" ]
185 then
186 # 'individual'
187 # remove name from list in case there is nothing left to do
188 getstatus >> $scriptlog 2>&1
189 if [ "$numproc" = "0" ]
190 then
191 unset all[$a]
192 all=( ${all[@]} )
193 continue
194 fi
195 # get one sequence or dataset from the database for which plots have to be produced
196 gettodo "1" >> $scriptlog 2>&1
197 num=${primaries[0]}
198 echo "executing $name for number "$num >> $scriptlog 2>&1
199 # lock the process
200 lockfile=$lockpath/$program-$name-$num.txt
201 checklock continue >> $scriptlog 2>&1
202 setstatus "start" >> $scriptlog 2>&1
203 # set needed file and path names
204 pathpart=$pathname/`printf %08d $num | cut -c 0-${digit}`/`printf %08d $num`
205 inpath=$datapath/$pathpart
206 outpath=$webpath/$pathpart
207 tmppath=/tmp/pstoimg$pathpart
208 rootfile=$inpath/$filename`printf %08d $num`.root
209 psfile=$inpath/$filename`printf %08d $num`.ps
210 csvfile=$outpath/$filename.csv
211 pdffile=$outpath/$filename`printf %08d $num`.pdf
212 # rsync
213 makedir $outpath >> $scriptlog 2>&1
214 rsync -aLv --exclude=20[01][0-9]*_[YI]_*[.]root $inpath/ $outpath >> $scriptlog 2>&1
215
216 # for ganymed not only the ganymed*.root is processed but also a plotdb.root for the
217 # dataset. therefore the macro plotdb.C has to be run in this case
218 if [ "$name" = "gplotdb" ]
219 then
220 # overwrite needed file and path names
221 rootfile=$inpath/$filename.root
222 psfile=$inpath/$filename.ps
223 csvfile=$outpath/$filename.csv
224 pdffile=$outpath/$filename.pdf
225 datasetfile=$datasetpath/`printf %08d $num | cut -c 0-${digit}`/dataset`printf %08d $num`.txt
226
227 echo "check1=root -q -b $macrospath/plotdb.C+\(\"$datasetfile\"\,\"$inpath/\"\) 2>|/dev/null | tee -a $scriptlog | intgrep" >> $scriptlog 2>&1
228 check1=`root -q -b $macrospath/plotdb.C+\("\"$datasetfile\""\,"\"$inpath/\""\) 2>|/dev/null | tee -a $scriptlog | intgrep`
229 case $check1 in
230 1) echo " check1=$check1 -> everything ok" >> $scriptlog 2>&1
231 printprocesslog "INFO rootfile $rootfile successfully produced"
232 ;;
233 *) echo " check1=$check1 -> ERROR -> couldn't create plots -> exit" >> $scriptlog 2>&1
234 printprocesslog "ERROR producing rootfile $rootfile failed"
235 com=$Fdowebplots
236 check=$check1
237 ;;
238 esac
239 fi
240 else
241 # 'general'
242 echo "executing $name " >> $scriptlog 2>&1
243 # remove 'general' from list as they need to be executed only once
244 unset all[$a]
245 all=( ${all[@]} )
246 # lock process
247 lockfile=$lockpath/$program-$name.txt
248 checklock continue >> $scriptlog 2>&1
249 # set needed file and path names
250 outpath=$webpath/$pathname
251 tmppath=/tmp/$pathname
252 rootfile=$outpath/$filename.root
253 psfile=$outpath/$filename.ps
254 csvfile=$outpath/$filename.csv
255 pdffile=$outpath/$filename.pdf
256 txtfile=$outpath/$filename.txt
257
258 echo "check2=root -q -b $macrospath/$macro.C+\(\"$outpath/\"\) 2>| $txtfile | tee -a $scriptlog | intgrep" >> $scriptlog 2>&1
259 check2=`root -q -b $macrospath/$macro.C+\("\"$outpath/\""\) 2>| $txtfile | tee -a $scriptlog | intgrep`
260 case $check2 in
261 1) echo " check2=$check2 -> everything ok" >> $scriptlog 2>&1
262 printprocesslog "INFO rootfile $rootfile successfully produced"
263 ;;
264 *) echo " check2=$check2 -> ERROR -> couldn't produce root file $rootfile -> exit" >> $scriptlog 2>&1
265 printprocesslog "ERROR producing rootfile $rootfile failed"
266 com=$Fdowebplots
267 check=$check2
268 ;;
269 esac
270 fi
271
272 # in case no error occured, the plots are produced from the rootfile
273 if [ "$check" = "ok" ]
274 then
275 printprocesslog "INFO producing plots (psfile and png) for $rootfile"
276 if ! ls $rootfile >/dev/null 2>&1
277 then
278 echo "rootfile $rootfile does not exist" >> $scriptlog 2>&1
279 printprocesslog "ERROR rootfile $rootfile does not exist"
280 com=$Fdowebplots
281 check=3
282 else
283 echo "producing psfile and csvfile..." >> $scriptlog 2>&1
284 if ! ./showplot -b --save-as-ps=$psfile --save-as-csv=$csvfile $rootfile >> $scriptlog 2>&1
285 then
286 com=$Fdowebplots
287 check=4
288 else
289 echo "creating temporary directory for pstoimg..." >> $scriptlog 2>&1
290 makedir $tmppath >> $scriptlog 2>&1
291
292 echo "converting plots to png..." >> $scriptlog 2>&1
293 if ! pstoimg -antialias -aaliastext -interlaced -flip r270 -density 100 -tmp $tmppath -out=$outpath/$name -type png -multipage $psfile >> $scriptlog 2>&1
294 then
295 printprocesslog "WARN could not create png files for $psfile "
296 com=$Fdowebplots
297 check=5
298 fi
299
300 echo "removing temporary directory..." >> $scriptlog 2>&1
301 rmdir -pv $tmppath >> $scriptlog 2>&1
302
303 echo "converting $psfile to pdf..." >> $scriptlog 2>&1
304 fi
305
306 if ps2pdf $psfile $pdffile >> $scriptlog 2>&1
307 then
308 rm -v $psfile >> $scriptlog 2>&1
309 else
310 printprocesslog "WARN could not convert $psfile to $pdffile"
311 com=$Fdowebplots
312 check=6
313 fi
314 fi
315 fi
316
317 setstatus "stop" >> $scriptlog 2>&1
318
319 rm -v $lockfile >> $scriptlog 2>&1
320
321 sleep 2
322done
323
324# rsync subsystemdata, sequence and dataset files
325echo "do rsync for subsystem files" >> $scriptlog 2>&1
326rsync -av --delete $subsystempath/ $webpath/subsystemdata >> $scriptlog 2>&1
327
328echo "do rsync for sequence files" >> $scriptlog 2>&1
329rsync -av --delete $sequpath/ $webpath/sequences >> $scriptlog 2>&1
330
331echo "do rsync for dataset files" >> $scriptlog 2>&1
332rsync -av --delete $datasetpath/ $webpath/datasets >> $scriptlog 2>&1
333
334
335lockfile=$lockpath/${program}-${hour}h.txt
336finish >> $scriptlog 2>&1
337
338
Note: See TracBrowser for help on using the repository browser.