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

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