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

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