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 12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2004
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | #
|
---|
28 |
|
---|
29 | user=`whoami`
|
---|
30 | source /home/$user/Mars/datacenter/scripts/sourcefile
|
---|
31 |
|
---|
32 | set -C
|
---|
33 |
|
---|
34 | scriptlogpath=$logpath/run/linkmc/`date +%Y/%m/%d`
|
---|
35 | makedir $scriptlogpath
|
---|
36 | scriptlog=$scriptlogpath/linkmc`date +%F`.log
|
---|
37 |
|
---|
38 | date >> $scriptlog 2>&1
|
---|
39 |
|
---|
40 | lockfile=$lockpath/lock-mclinks.txt
|
---|
41 | date > $lockfile >> $scriptlog 2>&1
|
---|
42 | checklock0=$?
|
---|
43 | case $checklock0 in
|
---|
44 | 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
|
---|
45 | 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
|
---|
46 | echo "-> linkmc is running -> exit" >> $scriptlog 2>&1
|
---|
47 | date >> $scriptlog 2>&1
|
---|
48 | exit;;
|
---|
49 | *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
|
---|
50 | esac
|
---|
51 |
|
---|
52 |
|
---|
53 | mccampath=/montecarlo/camera
|
---|
54 | mcpath=/montecarlo/rawfiles
|
---|
55 | next=$mcpath/.next
|
---|
56 | processed=$mcpath/.processed
|
---|
57 | processeddir=$mcpath/.processed.dir
|
---|
58 | readme=$mcpath/README.txt
|
---|
59 |
|
---|
60 | if ! ls $next >> $scriptlog 2>&1
|
---|
61 | then
|
---|
62 | echo "file $next not found -> no start-runno -> exit" >> $scriptlog 2>&1
|
---|
63 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
64 | exit
|
---|
65 | fi
|
---|
66 |
|
---|
67 | date >| $readme 2>&1
|
---|
68 |
|
---|
69 |
|
---|
70 | modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Proton" "DiffuseGamma" )
|
---|
71 |
|
---|
72 | echo "" >> $readme 2>&1
|
---|
73 | echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
|
---|
74 | echo "--------------------------------------------------------------" >> $readme 2>&1
|
---|
75 | echo "" >> $readme 2>&1
|
---|
76 | echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
|
---|
77 | echo "YYYY represents 19zbin" >> $readme 2>&1
|
---|
78 | echo "MM represents the mode" >> $readme 2>&1
|
---|
79 | echo "DD represents the psf in mm" >> $readme 2>&1
|
---|
80 | echo "" >> $readme 2>&1
|
---|
81 | echo "explanation of the modes" >> $readme 2>&1
|
---|
82 | echo "modes: "${modes[@]} >> $readme 2>&1
|
---|
83 | echo "" >> $readme 2>&1
|
---|
84 | for (( i=1 ; i <= 12 ; i++ ))
|
---|
85 | do
|
---|
86 | if [ "${modes[i]}" != "" ]
|
---|
87 | then
|
---|
88 | numofmode=`printf %02d $i`
|
---|
89 | echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
|
---|
90 | fi
|
---|
91 | done
|
---|
92 | echo "" >> $readme 2>&1
|
---|
93 | echo "the mode is indicating " >> $readme 2>&1
|
---|
94 | echo " - the particle type" >> $readme 2>&1
|
---|
95 | echo " - wobble/nowobble" >> $readme 2>&1
|
---|
96 | echo " - HE" >> $readme 2>&1
|
---|
97 | echo " - w+/w0 (as +/0)" >> $readme 2>&1
|
---|
98 | echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
|
---|
99 | echo " (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
|
---|
100 | echo "" >> $readme 2>&1
|
---|
101 |
|
---|
102 |
|
---|
103 | runno=`cat $next`
|
---|
104 |
|
---|
105 | camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
|
---|
106 |
|
---|
107 | for camfile in ${camfiles[@]}
|
---|
108 | do
|
---|
109 | if grep $camfile $processed >> $scriptlog 2>&1
|
---|
110 | then
|
---|
111 | continue
|
---|
112 | fi
|
---|
113 | file=`basename $camfile`
|
---|
114 | no=`printf %08d $runno | cut -c 0-5`
|
---|
115 | # no2=`printf %08d $runno`
|
---|
116 | # workaround due to 5digit runnumber for data with runnumber < 35487
|
---|
117 | no2=`printf %05d $runno`
|
---|
118 | zbin=`echo $file | cut -d_ -f2 | cut -c 5-6`
|
---|
119 | zbin=`printf %02d $zbin`
|
---|
120 | wobble=`echo $file | cut -d_ -f6 | cut -c 2`
|
---|
121 | particle=`echo $file | cut -d_ -f1`
|
---|
122 | psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8`
|
---|
123 |
|
---|
124 | particledir=`echo $camfile | cut -d/ -f4`
|
---|
125 | wobbledir=`echo $camfile | cut -d/ -f6`
|
---|
126 |
|
---|
127 | testmode=$particle$wobbledir$wobble
|
---|
128 | # echo "testmode:"$testmode >> $scriptlog 2>&1
|
---|
129 |
|
---|
130 | case $wobble in
|
---|
131 | 0) wobblemode="";;
|
---|
132 | +) wobblemode="W1";;
|
---|
133 | -) wobblemode="W2";;
|
---|
134 | *) echo "couldn't find any indication for mode (wobble)" >> $scriptlog 2>&1
|
---|
135 | ;;
|
---|
136 | esac
|
---|
137 |
|
---|
138 | for (( i=1 ; i <= 12 ; i++ ))
|
---|
139 | do
|
---|
140 | if [ "${modes[$i]}" == "$testmode" ]
|
---|
141 | then
|
---|
142 | # echo "modes[$i]=${modes[$i]}" >> $scriptlog 2>&1
|
---|
143 | totalmode=$i
|
---|
144 | break
|
---|
145 | fi
|
---|
146 | done
|
---|
147 |
|
---|
148 | totalmode=`printf %02d $totalmode`
|
---|
149 | # echo "totalmode: "$totalmode >> $scriptlog 2>&1
|
---|
150 |
|
---|
151 | project=${particle}${zbin}${wobblemode}
|
---|
152 | newfile="$mcpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
|
---|
153 | newdir=`dirname $newfile`
|
---|
154 | makedir $newdir >> $scriptlog 2>&1
|
---|
155 |
|
---|
156 | runno=`expr $runno + 1`
|
---|
157 | echo $runno >| $next
|
---|
158 |
|
---|
159 | ln -sv $camfile $newfile >> $scriptlog 2>&1
|
---|
160 | echo $camfile >> $processed
|
---|
161 |
|
---|
162 | done
|
---|
163 |
|
---|
164 | echo "linking cal and ped file" >> $scriptlog 2>&1
|
---|
165 | pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
|
---|
166 | calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
|
---|
167 | echo "calfile"$calfile >> $scriptlog 2>&1
|
---|
168 | echo "pedfile"$pedfile >> $scriptlog 2>&1
|
---|
169 | numfiles=`echo $pedfile $calfile | wc -w`
|
---|
170 | if [ "$numfiles" != "2" ]
|
---|
171 | then
|
---|
172 | "too many files in the directory $mccampath/Cal_and_Ped -> exit" >> $scriptlog 2>&1
|
---|
173 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
174 | exit
|
---|
175 | fi
|
---|
176 |
|
---|
177 | dirs=`find $mcpath -type d`
|
---|
178 |
|
---|
179 | for dir in ${dirs[@]}
|
---|
180 | do
|
---|
181 | if grep $dir $processeddir >> $scriptlog 2>&1
|
---|
182 | then
|
---|
183 | continue
|
---|
184 | fi
|
---|
185 | date=`echo $dir | cut -c 22-25,27,28,30,31`
|
---|
186 | # workaround due to 5digit runnumber for data with runnumber < 35487
|
---|
187 | # newcalfile="${dir}/${date}_00000001_C_MonteCarlo_E.root"
|
---|
188 | newcalfile="${dir}/${date}_00001_C_MonteCarlo_E.root"
|
---|
189 | ln -sv $calfile $newcalfile >> $scriptlog 2>&1
|
---|
190 | # workaround due to 5digit runnumber for data with runnumber < 35487
|
---|
191 | # newpedfile="${dir}/${date}_00000002_P_MonteCarlo_E.root"
|
---|
192 | newpedfile="${dir}/${date}_00002_P_MonteCarlo_E.root"
|
---|
193 | ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
|
---|
194 | echo $dir >> $processeddir
|
---|
195 | done
|
---|
196 |
|
---|
197 |
|
---|
198 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
199 |
|
---|
200 | set +C
|
---|
201 |
|
---|
202 | date >> $scriptlog 2>&1
|
---|
203 |
|
---|
204 |
|
---|