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