| 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): Daniel Hoehne-Moench 03/2009 <mailto:hoehne@astro.uni-wuerzburg.de>
|
|---|
| 21 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2009
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | # This script launches the inserting of mc parameters into the db by
|
|---|
| 28 | # starting fillcamera.C
|
|---|
| 29 | #
|
|---|
| 30 |
|
|---|
| 31 | source `dirname $0`/sourcefile
|
|---|
| 32 | printprocesslog "INFO starting $0"
|
|---|
| 33 | program=fillcamera
|
|---|
| 34 |
|
|---|
| 35 | set -C
|
|---|
| 36 |
|
|---|
| 37 | # check if script is already running
|
|---|
| 38 | lockfile=$lockpath/lock-$program.txt
|
|---|
| 39 | checklock
|
|---|
| 40 |
|
|---|
| 41 | getdbsetup
|
|---|
| 42 |
|
|---|
| 43 | #mccampath=$mcpath/camera
|
|---|
| 44 | mccampath=/magic/montecarlo/camera
|
|---|
| 45 | #workaround
|
|---|
| 46 | cameradirs=`find /magic/montecarlo/camera -maxdepth 4 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton ! -name Spot_?.?`
|
|---|
| 47 | printprocesslog "INFO camera dirs: "${cameradirs[@]}
|
|---|
| 48 |
|
|---|
| 49 | cd $mars
|
|---|
| 50 |
|
|---|
| 51 | # process directories
|
|---|
| 52 | for cameradir in ${cameradirs[@]}
|
|---|
| 53 | do
|
|---|
| 54 | printprocesslog "INFO inserting information for all root camera files in $cameradir"
|
|---|
| 55 | cam=`basename $cameradir`
|
|---|
| 56 | spot=`echo $cameradir | cut -d/ -f7` #spotsize
|
|---|
| 57 | par=`echo $cameradir | cut -d/ -f6` #particle name
|
|---|
| 58 | if [ $cam = "Cal_and_Ped" ]
|
|---|
| 59 | then
|
|---|
| 60 | par=""
|
|---|
| 61 | spot=""
|
|---|
| 62 | fi
|
|---|
| 63 | epo=`echo $cameradir | cut -d/ -f5` #epoch
|
|---|
| 64 | printprocesslog "INFO dir: "$cameradir
|
|---|
| 65 | fillcamerapath=$logpath/$program
|
|---|
| 66 | makedir $fillcamerapath
|
|---|
| 67 | fillcameralog=$fillcamerapath/$program-$epo-$par-$spot-$cam.log
|
|---|
| 68 |
|
|---|
| 69 | check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kFALSE\) | tee $fillcameralog | intgrep`
|
|---|
| 70 | # check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kTRUE\) | tee $fillcameralog | intgrep`
|
|---|
| 71 | case $check0 in
|
|---|
| 72 | 1) printprocesslog "INFO fillcamera run successfully for dir $cameradir (check0=$check0)"
|
|---|
| 73 | ;;
|
|---|
| 74 | 0) printprocesslog "WARN connection to DB failed (check0=$check0)"
|
|---|
| 75 | check="no"
|
|---|
| 76 | ;;
|
|---|
| 77 | *) printprocesslog "ERROR $program.C failed for dir $cameradir (check0=$check0)"
|
|---|
| 78 | ;;
|
|---|
| 79 | esac
|
|---|
| 80 |
|
|---|
| 81 | printprocesslog "INFO linking cal and ped files"
|
|---|
| 82 |
|
|---|
| 83 | if [ $cam = "Cal_and_Ped" ];
|
|---|
| 84 | then
|
|---|
| 85 | printprocesslog "INFO Cal_and_Ped folder, no cal and ped files will be linked"
|
|---|
| 86 | else
|
|---|
| 87 |
|
|---|
| 88 | epo=`echo $cameradir | cut -d/ -f5` #filename
|
|---|
| 89 | #epo=`basename $cameradir` #filename
|
|---|
| 90 | pedfile=`find $mccampath/$epo/Cal_and_Ped -name *_P_*.root`
|
|---|
| 91 | calfile=`find $mccampath/$epo/Cal_and_Ped -name *_C_*.root`
|
|---|
| 92 |
|
|---|
| 93 | printprocesslog "INFO calfile for epoch $epo : " $calfile
|
|---|
| 94 | printprocesslog "INFO pedfile for epoch $epo : " $pedfile
|
|---|
| 95 |
|
|---|
| 96 | #check number of files
|
|---|
| 97 | numfiles=`echo $pedfile $calfile | wc -w`
|
|---|
| 98 |
|
|---|
| 99 | if [ "$numfiles" != "2" ]
|
|---|
| 100 | then
|
|---|
| 101 | printprocesslog "ERROR too many or too less ped and cal files found in $epo/Cal_and_Ped"
|
|---|
| 102 | finish
|
|---|
| 103 | fi
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | cquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$calfile\" "
|
|---|
| 107 | pquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$pedfile\" "
|
|---|
| 108 |
|
|---|
| 109 | crun=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $cquery "`
|
|---|
| 110 | prun=`mysql -ss -u $us --password=$pw --host=$ho $db -e " $pquery "`
|
|---|
| 111 | cnum=`printf %08d $crun`
|
|---|
| 112 | pnum=`printf %08d $prun`
|
|---|
| 113 | printprocesslog "INFO calrun number: " $cnum
|
|---|
| 114 | printprocesslog "INFO pedrun number: " $pnum
|
|---|
| 115 | #get all directories in the linked structure for the epoch
|
|---|
| 116 | #dirs=`find $mcrawpath/ -mindepth 3 -maxdepth 3 -type d`
|
|---|
| 117 | files=`find $mcrawpath/ -lname *$epo*.root`
|
|---|
| 118 |
|
|---|
| 119 | for file in ${files[@]}
|
|---|
| 120 | do
|
|---|
| 121 | dir=`dirname $file`
|
|---|
| 122 | #datacenter
|
|---|
| 123 | date=`echo $file | cut -c 28-31,33,34,36,37`
|
|---|
| 124 | #for tests
|
|---|
| 125 | #date=`echo $file | cut -c 57-60,62,63,65,66`
|
|---|
| 126 |
|
|---|
| 127 | newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root"
|
|---|
| 128 | newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root"
|
|---|
| 129 | pupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newpedfile\" where fRunNumber=\"$prun\" "
|
|---|
| 130 | cupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newcalfile\" where fRunNumber=\"$crun\" "
|
|---|
| 131 | if ls $dir | grep MonteCarlo | grep $pnum
|
|---|
| 132 | then
|
|---|
| 133 | printprocesslog "INFO P run already there, do mysql update"
|
|---|
| 134 | # continue
|
|---|
| 135 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $pupdate "
|
|---|
| 136 | else
|
|---|
| 137 | printprocesslog "INFO linking P run for epoch $epo"
|
|---|
| 138 | ln -sv $pedfile $newpedfile
|
|---|
| 139 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $pupdate "
|
|---|
| 140 | fi
|
|---|
| 141 |
|
|---|
| 142 | if ls $dir | grep MonteCarlo | grep $cnum
|
|---|
| 143 | then
|
|---|
| 144 | printprocesslog "INFO C run already there, do mysql update"
|
|---|
| 145 | # continue
|
|---|
| 146 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $cupdate "
|
|---|
| 147 | else
|
|---|
| 148 | printprocesslog "INFO linking C run for epoch $epo"
|
|---|
| 149 | ln -sv $calfile $newcalfile
|
|---|
| 150 | mysql -ss -u $us --password=$pw --host=$ho $db -e " $cupdate "
|
|---|
| 151 | fi
|
|---|
| 152 |
|
|---|
| 153 | done
|
|---|
| 154 |
|
|---|
| 155 | fi
|
|---|
| 156 |
|
|---|
| 157 | done
|
|---|
| 158 |
|
|---|
| 159 | readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation
|
|---|
| 160 |
|
|---|
| 161 | # observation epochs
|
|---|
| 162 | epochs=("" "After January 07 (MUX FADCs)," "From April 06 to January 07 (Siegen FADCs with splitters)," "Before April 06 (Siegen FADCs)")
|
|---|
| 163 |
|
|---|
| 164 | # print information and explanation of structure into README.txt
|
|---|
| 165 | date >| $readme 2>&1
|
|---|
| 166 | echo "" >> $readme 2>&1
|
|---|
| 167 | echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
|
|---|
| 168 | echo "--------------------------------------------------------------" >> $readme 2>&1
|
|---|
| 169 | echo "" >> $readme 2>&1
|
|---|
| 170 | echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
|
|---|
| 171 | echo "YYYY represents 19zbin" >> $readme 2>&1
|
|---|
| 172 | echo "MM represents the epoch" >> $readme 2>&1
|
|---|
| 173 | echo "DD represents the additional spot size in mm" >> $readme 2>&1
|
|---|
| 174 | echo "" >> $readme 2>&1
|
|---|
| 175 | echo "explanation of the epochs" >> $readme 2>&1
|
|---|
| 176 | echo "epochs: "${epochs[@]} >> $readme 2>&1
|
|---|
| 177 | echo "" >> $readme 2>&1
|
|---|
| 178 | for (( i=1 ; i <= 3 ; i++ ))
|
|---|
| 179 | do
|
|---|
| 180 | if [ "${epochs[i]}" != "" ]
|
|---|
| 181 | then
|
|---|
| 182 | numofepoch=`printf %02d $i`
|
|---|
| 183 | echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
|
|---|
| 184 | fi
|
|---|
| 185 | done
|
|---|
| 186 | echo "" >> $readme 2>&1
|
|---|
| 187 | echo "the epoch is indicating " >> $readme 2>&1
|
|---|
| 188 | echo " - the time for which the MCs are produced" >> $readme 2>&1
|
|---|
| 189 | echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
|
|---|
| 190 | echo "" >> $readme 2>&1
|
|---|
| 191 | echo "----------------" >> $readme 2>&1
|
|---|
| 192 | echo "" >> $readme 2>&1
|
|---|
| 193 | echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
|
|---|
| 194 | echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
|
|---|
| 195 | echo "<P/C/D> indicates the run type" >> $readme 2>&1
|
|---|
| 196 | echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
|
|---|
| 197 | echo "<Spectrum>: 'empty' or HE, depending on the simulated MC spectrum" >> $readme 2>&1
|
|---|
| 198 | echo "<ObservationMode>: 'empty' (On), W1/W2 (Wobble), FW (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
|
|---|
| 199 | echo "" >> $readme 2>&1
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | finish
|
|---|
| 203 |
|
|---|