source: trunk/MagicSoft/Mars/datacenter/macros/insertdataset.C@ 8657

Last change on this file since 8657 was 8108, checked in by tbretz, 18 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 <TEnv.h>
57
58#include "MSQLMagic.h"
59
60using namespace std;
61
62int insertdataset(TString number, TString source, TString wobble, TString comment, Bool_t dummy=kTRUE)
63{
64 TEnv env("sql.rc");
65
66 MSQLMagic serv(env);
67 if (!serv.IsConnected())
68 {
69 cout << "ERROR - Connection to database failed." << endl;
70 return 0;
71 }
72
73 serv.SetIsDummy(dummy);
74
75 cout << "insertdataset" << endl;
76 cout << "-------------" << endl;
77 cout << endl;
78 cout << "Connected to " << serv.GetName() << endl;
79 cout << endl;
80
81 //get source key
82 Int_t sourcekey = serv.QueryKeyOfName("Source", source.Data(), kFALSE);
83 if (sourcekey<0)
84 {
85 cout << "Error - could not get sourcename from DB -> " << flush;
86 cout << "maybe you have the wrong sourcename in your datasetfile" << endl;
87 return 2;
88 }
89
90 cout << "no:" << number << endl;
91
92 //if dataset is not yet in database, insert the information
93 if (serv.ExistStr("fDataSetNumber", "DataSets", number.Data())) // Form("%d", number)
94 {
95 cout << number << " already exists... " << endl;
96 return 3;
97 }
98
99 TString vals = Form("fDataSetNumber='%s', fSourceKEY=%d, "
100 "fWobble='%s', fComment='%s' ", number.Data(),
101 sourcekey, wobble.Data(), comment.Data());
102
103 Int_t rc = serv.Insert("DataSets", vals);
104
105 if (rc<=0) // dummy mode or failed
106 return 0;
107
108 vals = Form("fDataSetNumber='%s', fDataSetInserted=Now()", number.Data());
109 rc = serv.Insert("DataSetProcessStatus", vals);
110
111 if (rc<=0) // dummy mode or failed
112 return 0;
113
114 return 1;
115}
116
117
Note: See TracBrowser for help on using the repository browser.