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

Last change on this file since 7453 was 7453, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.0 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 #in .next the next runno is stored
56processed=$mcpath/.processed #in .processed the linked files are stored
57readme=$mcpath/README.txt #file in which the information about the modes is redirected to have always an updated explanation
58
59if ! ls $next >> $scriptlog 2>&1
60then
61 echo "file $next not found -> no start-runno -> exit" >> $scriptlog 2>&1
62 rm -v $lockfile >> $scriptlog 2>&1
63 exit
64fi
65
66date >| $readme 2>&1
67
68
69modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Gammadiffuse0" "Protonnowobble0" )
70
71#be carful:
72# w- not yet foreseen in this script
73
74echo "" >> $readme 2>&1
75echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
76echo "--------------------------------------------------------------" >> $readme 2>&1
77echo "" >> $readme 2>&1
78echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
79echo "YYYY represents 19zbin" >> $readme 2>&1
80echo "MM represents the mode" >> $readme 2>&1
81echo "DD represents the psf in mm" >> $readme 2>&1
82echo "" >> $readme 2>&1
83echo "explanation of the modes" >> $readme 2>&1
84echo "modes: "${modes[@]} >> $readme 2>&1
85echo "" >> $readme 2>&1
86for (( i=1 ; i <= 12 ; i++ ))
87do
88 if [ "${modes[i]}" != "" ]
89 then
90 numofmode=`printf %02d $i`
91 echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
92 fi
93done
94echo "" >> $readme 2>&1
95echo "the mode is indicating " >> $readme 2>&1
96echo " - the particle type" >> $readme 2>&1
97echo " - wobble/nowobble" >> $readme 2>&1
98echo " - HE" >> $readme 2>&1
99echo " - w+/w0 (as +/0)" >> $readme 2>&1
100echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
101echo " (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
102echo "" >> $readme 2>&1
103
104
105#get runnumber
106runno=`cat $next`
107
108#get files, which have to be linked
109camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
110
111for camfile in ${camfiles[@]}
112do
113 #continue, if file is already linked
114 if grep $camfile $processed >> $scriptlog 2>&1
115 then
116 continue
117 fi
118 file=`basename $camfile` #filename
119 no=`printf %08d $runno | cut -c 0-5` #first 5 digits of a 8digit runno -> for path
120# no2=`printf %08d $runno` #runno with 8 digits
121# workaround due to 5digit runnumber for data with runnumber < 35487
122 no2=`printf %05d $runno`
123 zbin=`echo $file | cut -d_ -f2 | cut -c 5-6` #zbin from filename
124 zbin=`printf %02d $zbin` #2digit
125 wobble=`echo $file | cut -d_ -f6 | cut -c 2` #mode from filename
126 particle=`echo $file | cut -d_ -f1` #particle type from filename
127 psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8` #psf from path
128
129 particledir=`echo $camfile | cut -d/ -f4` #particletype from path
130 wobbledir=`echo $camfile | cut -d/ -f6` #mode from path
131
132 #build mode name
133 testmode=$particle$wobbledir$wobble
134
135 #get mode extension for filename
136 case $wobble in
137 0) wobblemode="";;
138 +) wobblemode="W1";;
139 -) wobblemode="W2";;
140 *) echo "couldn't find any indication for mode (wobble)" >> $scriptlog 2>&1
141 ;;
142 esac
143
144 #get no of mode from array $modes
145 for (( i=1 ; i <= 12 ; i++ ))
146 do
147 if [ "${modes[$i]}" == "$testmode" ]
148 then
149 totalmode=$i
150 break
151 fi
152 done
153
154 totalmode=`printf %02d $totalmode` #2 digits
155
156 project=${particle}${zbin}${wobblemode} #build project name
157 #create new filename
158 newfile="$mcpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
159 newdir=`dirname $newfile`
160 makedir $newdir >> $scriptlog 2>&1
161
162 runno=`expr $runno + 1` #next runnumber
163 echo $runno >| $next
164
165 #link file
166 ln -sv $camfile $newfile >> $scriptlog 2>&1
167 #add filename to processed file
168 echo $camfile >> $processed
169
170done
171
172echo "linking cal and ped file" >> $scriptlog 2>&1
173#get files
174pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
175calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
176echo "calfile"$calfile >> $scriptlog 2>&1
177echo "pedfile"$pedfile >> $scriptlog 2>&1
178#check number of files
179numfiles=`echo $pedfile $calfile | wc -w`
180if [ "$numfiles" != "2" ]
181then
182 "too many files in the directory $mccampath/Cal_and_Ped -> exit" >> $scriptlog 2>&1
183 rm -v $lockfile >> $scriptlog 2>&1
184 exit
185fi
186
187#get all directories in the linked structure
188dirs=`find $mcpath -type d`
189
190for dir in ${dirs[@]}
191do
192 #continue, if directory has already linked C and P run
193 $cont=`ls $dir/*_0000[12]_[CP]_MonteCarlo_E.root | wc -w`
194 if [ "$cont" == "2" ] >> $scriptlog 2>&1
195 then
196 continue
197 fi
198
199 #continue, if directory is not at the lowest level of the structure
200 cont=`echo $dir | cut -d/ -f6`
201 if [ "$cont" == "" ]
202 then
203 continue
204 fi
205
206 #get date for filename from directory name
207 date=`echo $dir | cut -c 22-25,27,28,30,31`
208
209 #create new filenames and link files
210# workaround due to 5digit runnumber for data with runnumber < 35487
211# newcalfile="${dir}/${date}_00000001_C_MonteCarlo_E.root"
212 newcalfile="${dir}/${date}_00001_C_MonteCarlo_E.root"
213 ln -sv $calfile $newcalfile >> $scriptlog 2>&1
214# workaround due to 5digit runnumber for data with runnumber < 35487
215# newpedfile="${dir}/${date}_00000002_P_MonteCarlo_E.root"
216 newpedfile="${dir}/${date}_00002_P_MonteCarlo_E.root"
217 ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
218done
219
220
221rm -v $lockfile >> $scriptlog 2>&1
222
223set +C
224
225date >> $scriptlog 2>&1
226
227
Note: See TracBrowser for help on using the repository browser.