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/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2006
|
---|
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 |
|
---|
34 | program=dowebplots
|
---|
35 | source /home/`whoami`/Mars/datacenter/scripts/sourcefile
|
---|
36 |
|
---|
37 | set -C
|
---|
38 |
|
---|
39 | cd $mars
|
---|
40 |
|
---|
41 | datetime=`date +%F-%H-%M-%S`
|
---|
42 | webdir=/www/htdocs/datacenter
|
---|
43 |
|
---|
44 | scriptlogpath=$logpath/run/dowebplots/`date +%Y/%m/%d`
|
---|
45 | makedir $scriptlogpath
|
---|
46 |
|
---|
47 | scriptlog=$scriptlogpath/dowebplots-$datetime.log
|
---|
48 |
|
---|
49 | date >> $scriptlog 2>&1
|
---|
50 |
|
---|
51 |
|
---|
52 | while getopts p: opts
|
---|
53 | do
|
---|
54 | case $opts in
|
---|
55 | p) type=$OPTARG
|
---|
56 | echo "got programname: $type" >> $scriptlog 2>&1
|
---|
57 | ;;
|
---|
58 | ?) echo "usage: $(basename $0) -p programname" >> $scriptlog 2>&1
|
---|
59 | ;;
|
---|
60 | esac
|
---|
61 | done
|
---|
62 |
|
---|
63 | if [ "$type" = "" ]
|
---|
64 | then
|
---|
65 | echo "no program name given -> exit" >> $scriptlog 2>&1
|
---|
66 | echo "usage: $(basename $0) -p programname" >> $scriptlog 2>&1
|
---|
67 | date >> $scriptlog 2>&1
|
---|
68 | exit
|
---|
69 | fi
|
---|
70 |
|
---|
71 | # check if script is already running
|
---|
72 | lockfile=$lockpath/lock-dowebplots-$type.txt
|
---|
73 | checklock >> $scriptlog 2>&1
|
---|
74 |
|
---|
75 |
|
---|
76 | #finding all rootfiles in the webdirectory, that were modified in the last 3 days
|
---|
77 | #this are all statusdisplays
|
---|
78 | rootfiles=`find $webdir/$type/ -maxdepth 10 -name '*.root' -mtime -3 | grep -v '_I_' | grep -v '_Y_' | grep -v 'subsystemdata' | grep -v 'star_lapalma' | grep -v 'summary'`
|
---|
79 |
|
---|
80 | #exit if no rootfiles are found
|
---|
81 | if [ "$rootfiles" = "" ]
|
---|
82 | then
|
---|
83 | echo "nothing to do -> exit" >> $scriptlog 2>&1
|
---|
84 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
85 | date >> $scriptlog 2>&1
|
---|
86 | exit
|
---|
87 | fi
|
---|
88 |
|
---|
89 |
|
---|
90 | #produce plots for each rootfile
|
---|
91 | for rootfile in ${rootfiles[@]}
|
---|
92 | do
|
---|
93 | date >> $scriptlog 2>&1
|
---|
94 | #get names of the psfile and the
|
---|
95 | #pngfiles (1 per tab in the statusdiplay)
|
---|
96 | psfile=`echo $rootfile | sed -e 's/.root$/.ps/g'`
|
---|
97 | tabfile=`echo $rootfile | sed -e 's/.root$/-tab/g'`
|
---|
98 | echo "rootfile: $rootfile" >> $scriptlog 2>&1
|
---|
99 | echo "psfile: $psfile" >> $scriptlog 2>&1
|
---|
100 | echo "tabfile: $tabfile" >> $scriptlog 2>&1
|
---|
101 |
|
---|
102 | #get date of root- and psfile
|
---|
103 | daterootfile=`date +%Y%m%d -r $rootfile` >> $scriptlog 2>&1
|
---|
104 | datepsfile=`date +%Y%m%d -r $psfile` >> $scriptlog 2>&1
|
---|
105 | if [ "$datepsfile" = "" ]
|
---|
106 | then
|
---|
107 | echo "date of psfile is empty -> the file $psfile doesn't exist" >> $scriptlog 2>&1
|
---|
108 | echo " -> setting date to 0 and producing psfile..." >> $scriptlog 2>&1
|
---|
109 | datepsfile=0
|
---|
110 | fi
|
---|
111 |
|
---|
112 | echo "checking date..." >> $scriptlog 2>&1
|
---|
113 | echo "date of rootfile: $daterootfile" >> $scriptlog 2>&1
|
---|
114 | echo "date of psfile: $datepsfile" >> $scriptlog 2>&1
|
---|
115 |
|
---|
116 | #if the psfile is newer than the rootfile
|
---|
117 | #no plots have to be done -> continue
|
---|
118 | if [ "$datepsfile" -gt "$daterootfile" ] >> $scriptlog 2>&1
|
---|
119 | then
|
---|
120 | echo "psfile is older than rootfile -> continue " >> $scriptlog 2>&1
|
---|
121 | continue
|
---|
122 | fi
|
---|
123 |
|
---|
124 | echo "producing psfile..." >> $scriptlog 2>&1
|
---|
125 | ./showplot -b --save-as-ps=$psfile $rootfile >> $scriptlog 2>&1
|
---|
126 |
|
---|
127 | echo "creating temporary dir for pstoimg..." >> $scriptlog 2>&1
|
---|
128 | temppath=`dirname $rootfile`
|
---|
129 | tempwebplotspath=$temppath/tempwebplots
|
---|
130 | makedir $tempwebplotspath >> $scriptlog 2>&1
|
---|
131 |
|
---|
132 | echo "converting plots to png..." >> $scriptlog 2>&1
|
---|
133 | pstoimg -antialias -flip r270 -density 100 -tmp $tempwebplotspath -type png -multipage -out=$tabfile $psfile >> $scriptlog 2>&1
|
---|
134 |
|
---|
135 | echo "removing temporary dir..." >> $scriptlog 2>&1
|
---|
136 | rmdir -v $tempwebplotspath >> $scriptlog 2>&1
|
---|
137 | done
|
---|
138 |
|
---|
139 | echo "removing old files" >> $scriptlog 2>&1
|
---|
140 | #make sure, that old plots of files, that are already removed from disk,
|
---|
141 | # are deleted also in the webdirectory
|
---|
142 | #this has to be done, as ps and png files are excluded from rsync, and
|
---|
143 | #as rsync is done with --delete option (script /home/operator/condor/webupdate)
|
---|
144 |
|
---|
145 | #find all directories with plots
|
---|
146 | dirs=`find $webdir/$type/* -type d | grep -v merpplogs`
|
---|
147 |
|
---|
148 | for dir in ${dir[@]}
|
---|
149 | do
|
---|
150 | #find psfiles in directory
|
---|
151 | psfiles=`ls $dir/*.ps`
|
---|
152 | #continue, if there are no psfiles
|
---|
153 | if [ "$psfiles" == "" ]
|
---|
154 | then
|
---|
155 | continue
|
---|
156 | fi
|
---|
157 |
|
---|
158 | for psfile in ${psfiles[@]}
|
---|
159 | do
|
---|
160 | #create name of corresponding rootfile
|
---|
161 | rootfile=`echo $psfile | sed -e 's/.ps$/.root/g'`
|
---|
162 | #delete ps and pngfiles if rootfile is not existing
|
---|
163 | if ! ls $rootfile >> $scriptlog 2>&1
|
---|
164 | then
|
---|
165 | echo "deleting old plots for $rootfile..." >> $scriptlog 2>&1
|
---|
166 | path=`dirname $psfile`
|
---|
167 | rm -v $psfile >> $scriptlog 2>&1
|
---|
168 | rm -v $path/*.png >> $scriptlog 2>&1
|
---|
169 | fi
|
---|
170 | done
|
---|
171 | done
|
---|
172 |
|
---|
173 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
174 |
|
---|
175 | set +C
|
---|
176 |
|
---|
177 | date >> $scriptlog 2>&1
|
---|
178 |
|
---|