source: trunk/MagicSoft/Mars/datacenter/macros/fillsources.C@ 8272

Last change on this file since 8272 was 7518, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 3.9 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// fillsources.C
28// ============
29//
30// Returns 0 in case of failure and 1 in case of success.
31//
32/////////////////////////////////////////////////////////////////////////////
33
34#include <iostream>
35#include <iomanip>
36#include <fstream>
37
38#include <TEnv.h>
39
40#include <MSQLServer.h>
41#include <TSQLRow.h>
42#include <TSQLResult.h>
43
44using namespace std;
45
46Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test)
47{
48 TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test));
49
50 cout << "query: " << query << endl;
51
52 TSQLResult *res = serv.Query(query);
53 if (!res)
54 return kFALSE;
55
56 Bool_t rc = kFALSE;
57
58 TSQLRow *row=res->Next();
59 if (row && (*row)[0])
60 rc=kTRUE;
61
62 delete res;
63 return rc;
64}
65
66
67int fillsources(TString catalog)
68{
69 TEnv env("sql.rc");
70
71 MSQLServer serv(env);
72 if (!serv.IsConnected())
73 {
74 cout << "ERROR - Connection to database failed." << endl;
75 return 0;
76 }
77 cout << "insertdate" << endl;
78 cout << "----------" << endl;
79 cout << endl;
80 cout << "Connected to " << serv.GetName() << endl;
81 cout << endl;
82
83 TString source;
84 TString RA;
85 TString Dec;
86 TString waste;
87 ifstream fin(catalog);
88 if (!fin)
89 {
90 cout << "Could not open file " << catalog << endl;
91 return 0;
92 }
93
94 while (1)
95 {
96 if (!fin)
97 break;
98
99 source.ReadToDelim(fin, ',');
100 waste.ReadToDelim(fin, ',');
101 RA.ReadToDelim(fin, ',');
102 Dec.ReadToDelim(fin, ',');
103 waste.ReadToDelim(fin, '\n');
104
105 cout << "source: " << source << endl;
106 cout << "RA: " << RA << endl;
107 cout << "Dec: " << Dec << endl;
108
109 //insert entry for date into the table SequenceBuildStatus,
110 // if entry is not yet existing
111 if (!ExistStr(serv, "fSourceName", "Source", source))
112 {
113 TString query(Form("INSERT Source SET fSourceName='%s', fRightAscension='%s', fDeclination='%s' ",
114 source.Data(), RA.Data(), Dec.Data()));
115
116 cout << "query: " << query << endl;
117 /*
118 TSQLResult *res = serv.Query(query);
119 if (!res)
120 {
121 cout << "Error - could not insert entry" << endl;
122 return 0;
123 }
124 delete res;
125 */
126 }
127 else
128 {
129 cout << source << " already exists... do update. " << endl;
130
131 TString query(Form("Update Source SET fRightAscension='%s', fDeclination='%s' WHERE fSourceName='%s',",
132 RA.Data(), Dec.Data(), source.Data()));
133
134 cout << "query: " << query << endl;
135 /*
136 TSQLResult *res = serv.Query(query);
137 if (!res)
138 {
139 cout << "Error - could not update entry" << endl;
140 return 0;
141 }
142 delete res;*/
143 }
144 }
145
146 return 1;
147}
148
149
Note: See TracBrowser for help on using the repository browser.