| 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 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
|---|
| 21 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | # This script launches the inserting of the datasets into the db.
|
|---|
| 28 | #
|
|---|
| 29 | # Extract information (dataset number, source name, comment, observation
|
|---|
| 30 | # mode) from dataset file and insert it into the database in the table
|
|---|
| 31 | # DataSets using the macro insertdataset.C
|
|---|
| 32 | #
|
|---|
| 33 |
|
|---|
| 34 | source `dirname $0`/sourcefile
|
|---|
| 35 | printprocesslog "INFO starting $0"
|
|---|
| 36 | program=insertdatasets
|
|---|
| 37 |
|
|---|
| 38 | set -C
|
|---|
| 39 |
|
|---|
| 40 | # check if script is already running
|
|---|
| 41 | lockfile=$lockpath/lock-$program.txt
|
|---|
| 42 | checklock
|
|---|
| 43 |
|
|---|
| 44 | # get all datasetfiles
|
|---|
| 45 | datasetfiles=(`ls $datasetpath/*/*.txt`)
|
|---|
| 46 | printprocesslog "INFO datasetfiles: "${datasetfiles[@]}
|
|---|
| 47 |
|
|---|
| 48 | cd $mars
|
|---|
| 49 |
|
|---|
| 50 | # extract information from dataset file and insert it into db with the macro insertdataset.C
|
|---|
| 51 | printprocesslog "INFO inserting dataset information into db"
|
|---|
| 52 | for datasetfile in ${datasetfiles[@]}
|
|---|
| 53 | do
|
|---|
| 54 | # get datasetnumber from filename
|
|---|
| 55 | no=`echo $datasetfile | cut -d/ -f5 | cut -c8-99 | cut -d. -f1`
|
|---|
| 56 | # get datasetnumber from file and get it with 8 digits
|
|---|
| 57 | no2=`grep 'AnalysisNumber:' $datasetfile | sed -e 's/AnalysisNumber://g' | sed -e 's/ //g'`
|
|---|
| 58 | no3=`printf %08d $no2`
|
|---|
| 59 | no4=`printf %08d $no2 | cut -c 1-5`
|
|---|
| 60 | # compare the two datasetnumber
|
|---|
| 61 | # continue only if number is the same
|
|---|
| 62 | if [ "$no" = "$no3" ]
|
|---|
| 63 | then
|
|---|
| 64 | printprocesslog "INFO number in filename and in file are the same -> continue"
|
|---|
| 65 | else
|
|---|
| 66 | printprocesslog "ERROR number in filename ($no) and file ($no3) are not the same for dataset $no2"
|
|---|
| 67 | continue
|
|---|
| 68 | fi
|
|---|
| 69 | # get source name, comment and observation mode from dataset file
|
|---|
| 70 | source=`grep 'SourceName:' $datasetfile | sed -e 's/SourceName://g' | sed -e 's/ //g' | sed -e 's/#//g'`
|
|---|
| 71 | comment=`grep 'Comment:' $datasetfile | sed -e 's/Comment://g'`
|
|---|
| 72 | mode=`grep 'WobbleMode:' $datasetfile`
|
|---|
| 73 | mode2=`echo $mode | grep ^\#`
|
|---|
| 74 | if [ "$mode2" = "" ]
|
|---|
| 75 | then
|
|---|
| 76 | wobble="Y"
|
|---|
| 77 | else
|
|---|
| 78 | wobble="N"
|
|---|
| 79 | fi
|
|---|
| 80 |
|
|---|
| 81 | insertdatasetpath=$logpath/insertdataset/$no4
|
|---|
| 82 | makedir $insertdatasetpath
|
|---|
| 83 | insertdatasetlog=$insertdatasetpath/insertdataset-$no3.log
|
|---|
| 84 |
|
|---|
| 85 | printprocesslog "INFO inserting dataset $no2"
|
|---|
| 86 | # insert information into db
|
|---|
| 87 | check0=`root -q -b $macrospath/insertdataset.C+\("\"$no2\""\,"\"$source\""\,"\"$wobble\""\,"\"$comment\""\,kFALSE\) | tee $insertdatasetlog | intgrep`
|
|---|
| 88 | case $check0 in
|
|---|
| 89 | 1) printprocesslog "INFO dataset $no2 successfully inserted (check0=$check0)"
|
|---|
| 90 | ;;
|
|---|
| 91 | 3) printprocesslog "INFO dataset $no2 exists already (check0=$check0)"
|
|---|
| 92 | ;;
|
|---|
| 93 | 0) printprocesslog "WARN connection to DB failed (check0=$check0)"
|
|---|
| 94 | check="no"
|
|---|
| 95 | ;;
|
|---|
| 96 | *) printprocesslog "ERROR $program.C failed for dataset $no2 (check0=$check0)"
|
|---|
| 97 | ;;
|
|---|
| 98 | esac
|
|---|
| 99 | done
|
|---|
| 100 |
|
|---|
| 101 | finish
|
|---|
| 102 |
|
|---|