source: trunk/MagicSoft/Mars/datacenter/scripts/insertdatasets@ 9131

Last change on this file since 9131 was 8482, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.4 KB
Line 
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
34source `dirname $0`/sourcefile
35printprocesslog "INFO starting $0"
36program=insertdatasets
37
38set -C
39
40scriptlog=$runlogpath/$program-$datetime.log
41date >> $scriptlog 2>&1
42
43# check if script is already running
44lockfile=$lockpath/lock-$program.txt
45checklock >> $scriptlog 2>&1
46
47# get all datasetfiles
48datasetfiles=(`ls $datasetpath/*/*.txt`)
49echo "datasetfiles: "${datasetfiles[@]} >> $scriptlog 2>&1
50echo "" >> $scriptlog 2>&1
51
52cd $mars
53
54# extract information from dataset file and insert it into db with the macro insertdataset.C
55printprocesslog "INFO inserting dataset information into db"
56for datasetfile in ${datasetfiles[@]}
57do
58 # get datasetnumber from filename
59 no=`echo $datasetfile | cut -d/ -f5 | cut -c8-99 | cut -d. -f1`
60 # get datasetnumber from file and get it with 8 digits
61 no2=`grep 'AnalysisNumber:' $datasetfile | sed -e 's/AnalysisNumber://g' | sed -e 's/ //g'`
62 no3=`printf %08d $no2`
63 no4=`printf %08d $no2 | cut -c 1-5`
64 # compare the two datasetnumber
65 # continue only if number is the same
66 if [ "$no" = "$no3" ]
67 then
68 echo "number in filename and in file are the same -> continue" >> $scriptlog 2>&1
69 else
70 echo "number in filename and in file are not the same " >> $scriptlog 2>&1
71 echo " -> continue with next dataset" >> $scriptlog 2>&1
72 printprocesslog "ERROR number in filename ($no) and file ($no3) are not the same for dataset $no2"
73 continue
74 fi
75 # get source name, comment and observation mode from dataset file
76 source=`grep 'SourceName:' $datasetfile | sed -e 's/SourceName://g' | sed -e 's/ //g' | sed -e 's/#//g'` >> $scriptlog 2>&1
77 comment=`grep 'Comment:' $datasetfile | sed -e 's/Comment://g'` >> $scriptlog 2>&1
78 mode=`grep 'WobbleMode:' $datasetfile` >> $scriptlog 2>&1
79 mode2=`echo $mode | grep ^\#` >> $scriptlog 2>&1
80 if [ "$mode2" = "" ]
81 then
82 wobble="Y" >> $scriptlog 2>&1
83 else
84 wobble="N" >> $scriptlog 2>&1
85 fi
86 echo "file: "$datasetfile >> $scriptlog 2>&1
87 echo " datasetno: "$no2 >> $scriptlog 2>&1
88 echo " sourcename: "$source >> $scriptlog 2>&1
89 echo " wobble: "$wobble >> $scriptlog 2>&1
90 echo " comment: "$comment >> $scriptlog 2>&1
91 echo " " >> $scriptlog 2>&1
92
93 insertdatasetpath=$logpath/insertdataset/$no4
94 makedir $insertdatasetpath >> $scriptlog 2>&1
95 insertdatasetlog=$insertdatasetpath/insertdataset-$no3.log
96
97 printprocesslog "INFO inserting dataset $no2"
98 # insert information into db
99 check0=`root -q -b $macrospath/insertdataset.C+\("\"$no2\""\,"\"$source\""\,"\"$wobble\""\,"\"$comment\""\,kFALSE\) | tee $insertdatasetlog | intgrep`
100 case $check0 in
101 1) echo " check0=$check0 -> everything ok " >> $scriptlog 2>&1
102 printprocesslog "INFO dataset $no2 successfully inserted"
103 ;;
104 3) echo " check0=$check0 -> everything ok " >> $scriptlog 2>&1
105 printprocesslog "INFO dataset $no2 exists already"
106 ;;
107 0) echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1
108 printprocesslog "WARN connection to DB failed"
109 check="no"
110 ;;
111 *) echo " check0=$check0 -> ERROR " >> $scriptlog 2>&1
112 printprocesslog "ERROR $program.C failed for dataset $no2"
113 ;;
114 esac
115done
116
117finish >> $scriptlog 2>&1
118
Note: See TracBrowser for help on using the repository browser.