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

Last change on this file since 7967 was 7967, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.5 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
44source `dirname $0`/sourcefile
45printprocesslog "INFO starting $0"
46program=linkmc
47
48set -C
49
50scriptlog=$runlogpath/$progam-`date +%F`.log
51date >> $scriptlog 2>&1
52
53# check if script is already running
54lockfile=$lockpath/lock-$program.txt
55checklock >> $scriptlog 2>&1
56
57mccampath=/montecarlo/camera
58mcpath=/montecarlo/rawfiles
59next=$mcpath/.next #in .next the next runno is stored
60processed=$mcpath/.processed #in .processed the linked files are stored
61readme=$mcpath/README.txt #file in which the information about the modes is redirected to have always an updated explanation
62
63# check if file with next runnumber is available
64if ! ls $next >> $scriptlog 2>&1
65then
66 echo "file $next not found -> no start-runno -> exit" >> $scriptlog 2>&1
67 printprocesslog "ERROR file $next (last runno) not found"
68 finish >> $scriptlog 2>&1
69fi
70
71
72# observation modes
73modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Gammadiffuse0" "Protonnowobble0" )
74#be carful:
75# w- not yet foreseen in this script
76
77# print information and explanation of structure into README.txt
78date >| $readme 2>&1
79echo "" >> $readme 2>&1
80echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
81echo "--------------------------------------------------------------" >> $readme 2>&1
82echo "" >> $readme 2>&1
83echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
84echo "YYYY represents 19zbin" >> $readme 2>&1
85echo "MM represents the mode" >> $readme 2>&1
86echo "DD represents the psf in mm" >> $readme 2>&1
87echo "" >> $readme 2>&1
88echo "explanation of the modes" >> $readme 2>&1
89echo "modes: "${modes[@]} >> $readme 2>&1
90echo "" >> $readme 2>&1
91for (( i=1 ; i <= 12 ; i++ ))
92do
93 if [ "${modes[i]}" != "" ]
94 then
95 numofmode=`printf %02d $i`
96 echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
97 fi
98done
99echo "" >> $readme 2>&1
100echo "the mode is indicating " >> $readme 2>&1
101echo " - the particle type" >> $readme 2>&1
102echo " - wobble/nowobble" >> $readme 2>&1
103echo " - HE" >> $readme 2>&1
104echo " - w+/w0 (as +/0)" >> $readme 2>&1
105echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
106echo " (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
107echo "" >> $readme 2>&1
108
109
110#get runnumber
111runno=`cat $next`
112
113#get files, which have to be linked
114camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
115
116printprocesslog "INFO linking new camerafiles starting with runno $runno"
117for camfile in ${camfiles[@]}
118do
119 #continue, if file is already linked
120 if grep $camfile $processed >> $scriptlog 2>&1
121 then
122 continue
123 fi
124 printprocesslog "INFO linking $file"
125 file=`basename $camfile` #filename
126 no=`printf %08d $runno | cut -c 0-5` #first 5 digits of a 8digit runno -> for path
127# no2=`printf %08d $runno` #runno with 8 digits
128# workaround due to 5digit runnumber for data with runnumber < 35487
129 no2=`printf %05d $runno`
130 zbin=`echo $file | cut -d_ -f2 | cut -c 5-6` #zbin from filename
131 zbin=`printf %02d $zbin` #2digit
132 wobble=`echo $file | cut -d_ -f6 | cut -c 2` #mode from filename
133 particle=`echo $file | cut -d_ -f1` #particle type from filename
134 psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8` #psf from path
135
136 particledir=`echo $camfile | cut -d/ -f4` #particletype from path
137 wobbledir=`echo $camfile | cut -d/ -f6` #mode from path
138
139 #build mode name
140 testmode=$particle$wobbledir$wobble
141
142 #get mode extension for filename
143 case $wobble in
144 0) wobblemode="";;
145 +) wobblemode="W1";;
146 -) wobblemode="W2";;
147 *) echo "couldn't find any indication for mode (wobble)" >> $scriptlog 2>&1
148 ;;
149 esac
150
151 #get no of mode from array $modes
152 for (( i=1 ; i <= 12 ; i++ ))
153 do
154 if [ "${modes[$i]}" == "$testmode" ]
155 then
156 totalmode=$i
157 break
158 fi
159 done
160
161 totalmode=`printf %02d $totalmode` #2 digits
162
163 project=${particle}${zbin}${wobblemode} #build project name
164 #create new filename
165 newfile="$mcpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
166 newdir=`dirname $newfile`
167 makedir $newdir >> $scriptlog 2>&1
168
169 runno=`expr $runno + 1` #next runnumber
170 echo $runno >| $next
171
172 #link file
173 ln -sv $camfile $newfile >> $scriptlog 2>&1
174 #add filename to processed file
175 echo $camfile >> $processed
176
177done
178
179printprocesslog "INFO linking cal and ped files"
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 printprocesslog "ERROR too many ped and cal files found in $mccampath/Cal_and_Ped"
192 finish >> $scriptlog 2>&1
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 2>/dev/null | 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
228finish >> $scriptlog 2>&1
229
Note: See TracBrowser for help on using the repository browser.