source: trunk/MagicSoft/Mars/datacenter/scripts/linkmc@ 7448

Last change on this file since 7448 was 7448, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 6.1 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 12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2004
23#
24#
25# ========================================================================
26#
27#
28
29user=`whoami`
30source /home/$user/Mars/datacenter/scripts/sourcefile
31
32set -C
33
34scriptlogpath=$logpath/run/linkmc/`date +%Y/%m/%d`
35makedir $scriptlogpath
36scriptlog=$scriptlogpath/linkmc`date +%F`.log
37
38date >> $scriptlog 2>&1
39
40lockfile=$lockpath/lock-mclinks.txt
41date > $lockfile >> $scriptlog 2>&1
42checklock0=$?
43case $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;;
50esac
51
52
53mccampath=/montecarlo/camera
54mcpath=/montecarlo/rawfiles
55next=$mcpath/.next
56processed=$mcpath/.processed
57processeddir=$mcpath/.processed.dir
58readme=$mcpath/README.txt
59
60if ! ls $next >> $scriptlog 2>&1
61then
62 echo "file $next not found -> no start-runno -> exit" >> $scriptlog 2>&1
63 rm -v $lockfile >> $scriptlog 2>&1
64 exit
65fi
66
67date >| $readme 2>&1
68
69
70modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Proton" "DiffuseGamma" )
71
72echo "" >> $readme 2>&1
73echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
74echo "--------------------------------------------------------------" >> $readme 2>&1
75echo "" >> $readme 2>&1
76echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
77echo "YYYY represents 19zbin" >> $readme 2>&1
78echo "MM represents the mode" >> $readme 2>&1
79echo "DD represents the psf in mm" >> $readme 2>&1
80echo "" >> $readme 2>&1
81echo "explanation of the modes" >> $readme 2>&1
82echo "modes: "${modes[@]} >> $readme 2>&1
83echo "" >> $readme 2>&1
84for (( i=1 ; i <= 12 ; i++ ))
85do
86 if [ "${modes[i]}" != "" ]
87 then
88 numofmode=`printf %02d $i`
89 echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
90 fi
91done
92echo "" >> $readme 2>&1
93echo "the mode is indicating " >> $readme 2>&1
94echo " - the particle type" >> $readme 2>&1
95echo " - wobble/nowobble" >> $readme 2>&1
96echo " - HE" >> $readme 2>&1
97echo " - w+/w0 (as +/0)" >> $readme 2>&1
98echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
99echo " (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
100echo "" >> $readme 2>&1
101
102
103runno=`cat $next`
104
105camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
106
107for camfile in ${camfiles[@]}
108do
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
162done
163
164echo "linking cal and ped file" >> $scriptlog 2>&1
165pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
166calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
167echo "calfile"$calfile >> $scriptlog 2>&1
168echo "pedfile"$pedfile >> $scriptlog 2>&1
169numfiles=`echo $pedfile $calfile | wc -w`
170if [ "$numfiles" != "2" ]
171then
172 "too many files in the directory $mccampath/Cal_and_Ped -> exit" >> $scriptlog 2>&1
173 rm -v $lockfile >> $scriptlog 2>&1
174 exit
175fi
176
177dirs=`find $mcpath -type d`
178
179for dir in ${dirs[@]}
180do
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
195done
196
197
198rm -v $lockfile >> $scriptlog 2>&1
199
200set +C
201
202date >> $scriptlog 2>&1
203
204
Note: See TracBrowser for help on using the repository browser.