#!/bin/sh # # ======================================================================== # # * # * This file is part of MARS, the MAGIC Analysis and Reconstruction # * Software. It is distributed to you in the hope that it can be a useful # * and timesaving tool in analysing Data of imaging Cerenkov telescopes. # * It is distributed WITHOUT ANY WARRANTY. # * # * Permission to use, copy, modify and distribute this software and its # * documentation for any purpose is hereby granted without fee, # * provided that the above copyright notice appear in all copies and # * that both that copyright notice and this permission notice appear # * in supporting documentation. It is provided "as is" without express # * or implied warranty. # * # # # Author(s): Daniel Hoehne 06/2008 # # Copyright: MAGIC Software Development, 2000-2008 # # # ======================================================================== # # This script launches the inserting of mc parameters into the db by # starting fillcamera.C # source `dirname $0`/sourcefile printprocesslog "INFO starting $0" program=fillcamera set -C scriptlog=$runlogpath/$program-$datetime.log date >> $scriptlog 2>&1 # check if script is already running lockfile=$lockpath/lock-$program.txt checklock >> $scriptlog 2>&1 #mccampath=$mcpath/camera mccampath=/magic/montecarlo/camera #workaround cameradirs=`find /magic/montecarlo/camera -maxdepth 4 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton ! -name Spot_?.?` #cameradirs=`find /magic/montecarlo/camera -maxdepth 3 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton` #cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d` echo "camera dirs: "${cameradirs[@]} >> $scriptlog 2>&1 echo "" >> $scriptlog 2>&1 cd $mars # process directories for cameradir in ${cameradirs[@]} do printprocesslog "INFO inserting information for all root camera files in $cameradir" cam=`basename $cameradir` spot=`echo $cameradir | cut -d/ -f7` #spotsize par=`echo $cameradir | cut -d/ -f6` #particle name if [ $cam = "Cal_and_Ped" ] then par="" spot="" fi epo=`echo $cameradir | cut -d/ -f5` #epoch echo "dir: "$cameradir >> $scriptlog 2>&1 fillcamerapath=$logpath/$program makedir $fillcamerapath >> $scriptlog 2>&1 fillcameralog=$fillcamerapath/$program-$epo-$par-$spot-$cam.log check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kFALSE\) | tee $fillcameralog | intgrep` # check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kTRUE\) | tee $fillcameralog | intgrep` case $check0 in 1) echo "check0=$check0 -> everything ok " >> $scriptlog 2>&1 printprocesslog "INFO fillcamera run successfully for dir $cameradir" ;; 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1 printprocesslog "WARN connection to DB failed" check="no" ;; *) echo "check0=$check0 -> ERROR " >> $scriptlog 2>&1 printprocesslog "ERROR $program.C failed for dir $cameradir" ;; esac printprocesslog "INFO linking cal and ped files" echo "linking cal and ped files" >> $scriptlog 2>&1 if [ $cam = "Cal_and_Ped" ]; then echo "Cal_and_Ped folder, no cal and ped files will be linked" >> $scriptlog 2>&1 else epo=`echo $cameradir | cut -d/ -f5` #filename #epo=`basename $cameradir` #filename pedfile=`find $mccampath/$epo/Cal_and_Ped -name *_P_*.root` calfile=`find $mccampath/$epo/Cal_and_Ped -name *_C_*.root` echo "calfile for epoch $epo : " $calfile >> $scriptlog 2>&1 echo "pedfile for epoch $epo : " $pedfile >> $scriptlog 2>&1 #check number of files numfiles=`echo $pedfile $calfile | wc -w` if [ "$numfiles" != "2" ] then echo "too many or too less files in the directory $epo/Cal_and_Ped -> exit" >> $scriptlog 2>&1 rm -v $lockfile >> $scriptlog 2>&1 exit printprocesslog "ERROR too many ped and cal files found in $epo/Cal_and_Ped" finish >> $scriptlog 2>&1 fi # user="test" # db="TestMonteCarlo" # pw="Ics+eaTD" user="operator" db="MyMagicMonteCarlo" pw="Ics+eMM!" cquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$calfile\" " pquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$pedfile\" " crun=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $cquery "` prun=`mysql -ss -u $user --password=$pw --host=$ho $db -e " $pquery "` cnum=`printf %08d $crun` pnum=`printf %08d $prun` echo "calrun number: " $cnum >> $scriptlog 2>&1 echo "pedrun number: " $pnum >> $scriptlog 2>&1 #get all directories in the linked structure for the epoch #dirs=`find $mcrawpath/ -mindepth 3 -maxdepth 3 -type d` files=`find $mcrawpath/ -lname *$epo*.root` for file in ${files[@]} do dir=`dirname $file` #datacenter date=`echo $file | cut -c 28-31,33,34,36,37` #for tests #date=`echo $file | cut -c 57-60,62,63,65,66` newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root" newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root" pupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newpedfile\" where fRunNumber=\"$prun\" " cupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newcalfile\" where fRunNumber=\"$crun\" " if ls $dir | grep MonteCarlo | grep $pnum then echo "P run already there, do mysql update" >> $scriptlog 2>&1 # continue mysql -ss -u $user --password=$pw --host=$ho $db -e " $pupdate " else echo "linking P run for epoch $epo" >> $scriptlog 2>&1 ln -sv $pedfile $newpedfile >> $scriptlog 2>&1 mysql -ss -u $user --password=$pw --host=$ho $db -e " $pupdate " fi if ls $dir | grep MonteCarlo | grep $cnum then echo "C run already there, do mysql update" >> $scriptlog 2>&1 # continue mysql -ss -u $user --password=$pw --host=$ho $db -e " $cupdate " else echo "linking C run for epoch $epo" >> $scriptlog 2>&1 ln -sv $calfile $newcalfile >> $scriptlog 2>&1 mysql -ss -u $user --password=$pw --host=$ho $db -e " $cupdate " fi done fi done readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation # observation epochs epochs=("" "After January 07 (MUX FADCs)," "From April 06 to January 07 (Siegen FADCs with splitters)," "Before April 06 (Siegen FADCs)") # print information and explanation of structure into README.txt date >| $readme 2>&1 echo "" >> $readme 2>&1 echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1 echo "--------------------------------------------------------------" >> $readme 2>&1 echo "" >> $readme 2>&1 echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1 echo "YYYY represents 19zbin" >> $readme 2>&1 echo "MM represents the epoch" >> $readme 2>&1 echo "DD represents the additional spot size in mm" >> $readme 2>&1 echo "" >> $readme 2>&1 echo "explanation of the epochs" >> $readme 2>&1 echo "epochs: "${epochs[@]} >> $readme 2>&1 echo "" >> $readme 2>&1 for (( i=1 ; i <= 3 ; i++ )) do if [ "${epochs[i]}" != "" ] then numofepoch=`printf %02d $i` echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1 fi done echo "" >> $readme 2>&1 echo "the epoch is indicating " >> $readme 2>&1 echo " - the time for which the MCs are produced" >> $readme 2>&1 echo " the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1 echo "" >> $readme 2>&1 echo "----------------" >> $readme 2>&1 echo "" >> $readme 2>&1 echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1 echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD__

__E.root" >> $readme 2>&1 echo "

indicates the run type" >> $readme 2>&1 echo ": Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1 echo ": 'empty' or HE, depending on the simulated MC spectrum" >> $readme 2>&1 echo ": 'empty' (On), W1/W2 (Wobble), FW (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1 echo "" >> $readme 2>&1 finish >> $scriptlog 2>&1