source: trunk/Mars/datacenter/tools/fillobjects2.C@ 12667

Last change on this file since 12667 was 9131, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
File size: 3.5 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): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2006
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// fillobjects2.C
28// ==============
29//
30// read file with coordinates for the objects (only the blazars)
31// File resources/TeVsources.txt
32//
33///////////////////////////////////////////////////////////////////////////
34#include <iostream>
35#include <iomanip>
36#include <fstream>
37
38#include <TEnv.h>
39#include <TRegexp.h>
40
41#include <TSQLRow.h>
42#include <TSQLResult.h>
43
44#include "MAstro.h"
45#include "MDirIter.h"
46#include "MSQLServer.h"
47#include "MSQLMagic.h"
48
49using namespace std;
50
51// --------------------------------------------------------------------------
52//
53// loop over all files in this path
54//
55int fillobjects2(TString fname, Bool_t dummy=kTRUE)
56{
57 TEnv env("sql.rc");
58
59 MSQLMagic serv(env);
60 if (!serv.IsConnected())
61 {
62 cout << "ERROR - Connection to database failed." << endl;
63 return 0;
64 }
65
66 serv.SetIsDummy(dummy);
67
68 cout << endl;
69 cout << "fillobjects" << endl;
70 cout << "-----------" << endl;
71 cout << endl;
72 cout << "Connected to " << serv.GetName() << endl;
73 cout << endl;
74
75 ifstream fin(fname);
76 if (!fin)
77 {
78 cout << "Could not open file " << fname << endl;
79 return 0;
80 }
81
82 Int_t num=0;
83 TString object;
84 TString query;
85 TString where;
86 TString RA;
87 TString DEC;
88 Double_t ra;
89 Double_t dec;
90 while (1)
91 {
92 TString line;
93 line.ReadLine(fin);
94 if (!fin)
95 break;
96
97 if (line.IsNull())
98 continue;
99
100 TObjArray *arr = line.Tokenize(" ");
101 if (arr->GetEntries()!=10)
102 {
103 cout << "WARNING: line with less or more than 11 arguments found " << endl;
104 cout << line << endl;
105 continue;
106 }
107 object=Form("%s/BL",(*arr)[0]->GetName());
108 RA=Form("%s:%s:%s", (*arr)[2]->GetName(), (*arr)[3]->GetName(), (*arr)[4]->GetName());
109 DEC=Form("%s:%s:%s", (*arr)[5]->GetName(), (*arr)[6]->GetName(), (*arr)[7]->GetName());
110 delete arr;
111// cout << "RA: " << RA << " - DEC " << DEC << endl;
112 MAstro::Coordinate2Angle(RA, ra);
113 MAstro::Coordinate2Angle(DEC, dec);
114// cout << "ra: " << ra << " - dec " << dec << endl;
115
116 query=Form("fRightAscension=%.7f, fDeclination=%.7f, fEpoche=2000",
117 ra, dec);
118
119 query+=Form(", fObjectName='%s'", object.Data());
120 where=Form(" fObjectName='%s'", object.Data());
121
122 if (serv.InsertUpdate("Object", query, where)==kFALSE)
123 return 2;
124 num +=1;
125
126 }
127
128 cout << fname << " <" << num << "> " << endl;
129
130 return 1;
131}
Note: See TracBrowser for help on using the repository browser.