source: trunk/Mars/datacenter/macros/insertdataset.C@ 13248

Last change on this file since 13248 was 9278, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 3.8 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// insertdataset.C
28// ===============
29//
30// This macro inserts datasets into the database.
31// If a new dataset file has been stored in the dataset directory, the
32// information file is read by a script and the information is inserted with
33// this macro into the database in the tables DataSets and
34// DataSetProcessStatus, where in the information about datasets is stored.
35//
36// Usage:
37// .x insertdataset.C+("number","source,"wobble","comment",kTRUE)
38// The first argument is the dataset number, the second is giving the source
39// name, the third the observation mode (wobble/on-off), the fourth a comment
40// about the dataset. This arguments are extracted by a script from the
41// dataset file.
42// The last argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
43// switched on and nothing will be written into the database. This is usefull
44// for tests.
45//
46// Make sure, that database and password are corretly set in a resource
47// file called sql.rc and the resource file is found.
48//
49// Returns 0 in case of failure and 1 in case of success.
50//
51/////////////////////////////////////////////////////////////////////////////
52
53#include <iostream>
54#include <iomanip>
55
56#include "MSQLMagic.h"
57
58using namespace std;
59
60int insertdataset(TString number, TString source, TString wobble, TString comment, Bool_t dummy=kTRUE)
61{
62 MSQLMagic serv("sql.rc");
63 if (!serv.IsConnected())
64 {
65 cout << "ERROR - Connection to database failed." << endl;
66 return 0;
67 }
68
69 serv.SetIsDummy(dummy);
70
71 cout << "insertdataset" << endl;
72 cout << "-------------" << endl;
73 cout << endl;
74 cout << "Connected to " << serv.GetName() << endl;
75 cout << endl;
76
77 //get source key
78 Int_t sourcekey = serv.QueryKeyOfName("Source", source.Data(), kFALSE);
79 if (sourcekey<0)
80 {
81 cout << "Error - could not get sourcename from DB -> " << flush;
82 cout << "maybe you have the wrong sourcename in your datasetfile" << endl;
83 return 2;
84 }
85
86 cout << "no:" << number << endl;
87
88 //if dataset is not yet in database, insert the information
89 if (serv.ExistStr("fDataSetNumber", "DataSets", number.Data())) // Form("%d", number)
90 {
91 cout << number << " already exists... " << endl;
92 return 3;
93 }
94
95 TString vals = Form("fDataSetNumber='%s', fSourceKEY=%d, "
96 "fWobble='%s', fComment='%s' ", number.Data(),
97 sourcekey, wobble.Data(), comment.Data());
98
99 Int_t rc = serv.Insert("DataSets", vals);
100
101 if (rc<=0) // dummy mode or failed
102 return 0;
103
104 vals = Form("fDataSetNumber='%s', fPriority='%s', fDataSetInserted=Now()",
105 number.Data(), number.Data());
106 rc = serv.Insert("DataSetProcessStatus", vals);
107
108 if (rc<=0) // dummy mode or failed
109 return 0;
110
111 return 1;
112}
113
114
Note: See TracBrowser for help on using the repository browser.