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-2006
|
---|
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 | user=`whoami`
|
---|
35 | program=insertdatasets
|
---|
36 | source /home/$user/Mars/datacenter/scripts/sourcefile
|
---|
37 |
|
---|
38 | set -C
|
---|
39 |
|
---|
40 | cd $mars
|
---|
41 |
|
---|
42 | datetime=`date +%F-%H-%M-%S`
|
---|
43 | lockfile=$lockpath/lock-insertdatasets.txt
|
---|
44 |
|
---|
45 | scriptlogpath=$logpath/run/insertdatasets/`date +%Y/%m`
|
---|
46 | makedir $scriptlogpath
|
---|
47 |
|
---|
48 | scriptlog=$scriptlogpath/insertdatasets-$datetime.log
|
---|
49 |
|
---|
50 | date >> $scriptlog 2>&1
|
---|
51 |
|
---|
52 | # check if script is already running
|
---|
53 | checklock >> $scriptlog 2>&1
|
---|
54 |
|
---|
55 | # get all datasetfiles
|
---|
56 | datasetfiles=(`ls $datasetpath/*/*`)
|
---|
57 | echo "datasetfiles: "${datasetfiles[@]} >> $scriptlog 2>&1
|
---|
58 | echo "" >> $scriptlog 2>&1
|
---|
59 |
|
---|
60 | # extract information from dataset file and insert it into db with the macro insertdataset.C
|
---|
61 | for datasetfile in ${datasetfiles[@]}
|
---|
62 | do
|
---|
63 | # get datasetnumber from filename
|
---|
64 | no=`echo $datasetfile | cut -d/ -f5 | cut -c8-99 | cut -d. -f1`
|
---|
65 | # get datasetnumber from file and get it with 8 digits
|
---|
66 | no2=`grep 'AnalysisNumber:' $datasetfile | sed -e 's/AnalysisNumber://g' | sed -e 's/ //g'`
|
---|
67 | no3=`printf %08d $no2`
|
---|
68 | # compare the two datasetnumber
|
---|
69 | # continue only if number is the same
|
---|
70 | if [ "$no" = "$no3" ]
|
---|
71 | then
|
---|
72 | echo "number in filename and in file are the same -> continue" >> $scriptlog 2>&1
|
---|
73 | else
|
---|
74 | echo "number in filename and in file are not the same " >> $scriptlog 2>&1
|
---|
75 | echo " -> continue with next dataset" >> $scriptlog 2>&1
|
---|
76 | continue
|
---|
77 | fi
|
---|
78 | # get source name, comment and observation mode from dataset file
|
---|
79 | source=`grep 'SourceName:' $datasetfile | sed -e 's/SourceName://g' | sed -e 's/ //g' | sed -e 's/#//g'` >> $scriptlog 2>&1
|
---|
80 | comment=`grep 'Comment:' $datasetfile | sed -e 's/Comment://g'` >> $scriptlog 2>&1
|
---|
81 | mode=`grep 'WobbleMode:' $datasetfile` >> $scriptlog 2>&1
|
---|
82 | mode2=`echo $mode | grep ^\#` >> $scriptlog 2>&1
|
---|
83 | if [ "$mode2" = "" ]
|
---|
84 | then
|
---|
85 | wobble="Y" >> $scriptlog 2>&1
|
---|
86 | else
|
---|
87 | wobble="N" >> $scriptlog 2>&1
|
---|
88 | fi
|
---|
89 | echo "file: "$datasetfile >> $scriptlog 2>&1
|
---|
90 | echo " datasetno: "$no2 >> $scriptlog 2>&1
|
---|
91 | echo " sourcename: "$source >> $scriptlog 2>&1
|
---|
92 | echo " wobble: "$wobble >> $scriptlog 2>&1
|
---|
93 | echo " comment: "$comment >> $scriptlog 2>&1
|
---|
94 | echo " " >> $scriptlog 2>&1
|
---|
95 |
|
---|
96 | insertdatasetpath=$logpath/insertdataset/$no3
|
---|
97 | makedir $insertdatasetpath >> $scriptlog 2>&1
|
---|
98 | insertdatasetlog=$insertdatasetpath/insertdataset-$no3.log
|
---|
99 |
|
---|
100 | # insert information into db
|
---|
101 | check0=`root -q -b $macrospath/insertdataset.C+\("\"$no2\""\,"\"$source\""\,"\"$wobble\""\,"\"$comment\""\,kFALSE\) | tee $insertdatasetlog | grep int | sed -e 's/(int)//'`
|
---|
102 | case $check0 in
|
---|
103 | 1) echo "check0=$check0 -> everything ok " >> $scriptlog 2>&1 ;;
|
---|
104 | *) echo "check0=$check0 -> ERROR " >> $scriptlog 2>&1 ;;
|
---|
105 | esac
|
---|
106 | done
|
---|
107 |
|
---|
108 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
109 |
|
---|
110 | set +C
|
---|
111 |
|
---|
112 | date >> $scriptlog 2>&1
|
---|
113 |
|
---|