source: branches/Mars_McMismatchStudy/datacenter/macros/fillsources.C@ 18454

Last change on this file since 18454 was 9327, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 2.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
37#include <fstream>
38
39#include <TSQLRow.h>
40#include <TSQLResult.h>
41
42#include "MSQLMagic.h"
43
44using namespace std;
45
46int fillsources(TString catalog, Bool_t dummy=kTRUE)
47{
48 MSQLMagic serv("sql.rc");
49 if (!serv.IsConnected())
50 {
51 cout << "ERROR - Connection to database failed." << endl;
52 return 0;
53 }
54 cout << "insertsources" << endl;
55 cout << "-------------" << endl;
56 cout << endl;
57 cout << "Connected to " << serv.GetName() << endl;
58 cout << "Catalog file: " << catalog << endl;
59 cout << endl;
60
61 serv.SetIsDummy(dummy);
62
63 ifstream fin(catalog);
64 if (!fin)
65 {
66 cout << "Could not open file " << catalog << endl;
67 return 1;
68 }
69
70 while (1)
71 {
72 TString src, ra, de, dum, epoch;
73
74 src.ReadToDelim(fin, ',');
75 dum.ReadToDelim(fin, ',');
76 ra.ReadToDelim(fin, ',');
77 de.ReadToDelim(fin, ',');
78 dum.ReadToDelim(fin, ',');
79 epoch.ReadToDelim(fin, '\n');
80
81 if (!fin)
82 break;
83/*
84 Double_t r,d;
85 if (!MAstro::Coordinate2Angle(ra, r))
86 {
87 cout << "ERROR - Interpreting right ascension: " << ra << endl;
88 return 2;
89 }
90 if (!MAstro::Coordinate2Angle(de, d))
91 {
92 cout << "ERROR - Interpreting declination: " << de << endl;
93 return 2;
94 }
95 */
96 TString vars(Form("fRightAscension='%s', fDeclination='%s', fEpoch='%s'",
97 ra.Data(), de.Data(), epoch.Data()));
98
99 TString where(Form("fSourceName='%s'", src.Data()));
100
101 if (!serv.InsertUpdate("Source", vars, where))
102 return 2;
103 }
104
105 return 1;
106}
Note: See TracBrowser for help on using the repository browser.