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