source: branches/AddingGoogleTestEnvironment/datacenter/tools/fillobjects.C@ 18297

Last change on this file since 18297 was 9131, checked in by Daniela Dorner, 16 years ago
*** empty log message ***
File size: 3.6 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// fillobjects.C
28// ==============
29//
30// read file with magnitudes and colour for the objects
31// File: resources/good_compstars_R.txt
32//
33// In resources also the file compstars_R.txt can be found, which contains
34// more stars. As the value for the magnitude for these stars is not good
35// enough, they are not inserted into the database, as the values there are
36// used for the calculation of the extinction.
37// E.g. resources/good_compstars_R.txt does not contain the blazars itself.
38//
39///////////////////////////////////////////////////////////////////////////
40#include <iostream>
41#include <iomanip>
42#include <fstream>
43
44#include <TEnv.h>
45#include <TRegexp.h>
46
47#include <TSQLRow.h>
48#include <TSQLResult.h>
49
50#include "MAstro.h"
51#include "MDirIter.h"
52#include "MSQLServer.h"
53#include "MSQLMagic.h"
54
55using namespace std;
56
57// --------------------------------------------------------------------------
58//
59// loop over all files in this path
60//
61int fillobjects(TString fname, Bool_t dummy=kTRUE)
62{
63 TEnv env("sql.rc");
64
65 MSQLMagic serv(env);
66 if (!serv.IsConnected())
67 {
68 cout << "ERROR - Connection to database failed." << endl;
69 return 0;
70 }
71
72 serv.SetIsDummy(dummy);
73
74 cout << endl;
75 cout << "fillobjects" << endl;
76 cout << "-----------" << endl;
77 cout << endl;
78 cout << "Connected to " << serv.GetName() << endl;
79 cout << endl;
80
81 ifstream fin(fname);
82 if (!fin)
83 {
84 cout << "Could not open file " << fname << endl;
85 return 0;
86 }
87
88 Int_t num=0;
89 TString object;
90 TString query;
91 TString where;
92 TString comment;
93 while (1)
94 {
95 TString line;
96 line.ReadLine(fin);
97 if (!fin)
98 break;
99
100 if (line.IsNull())
101 continue;
102
103 line.ReplaceAll("\t", " ");
104 TObjArray *arr = line.Tokenize(" ");
105 if (arr->GetEntries()!=5)
106 {
107 cout << "WARNING: line with less or more than 5 arguments found " << endl;
108 cout << line << endl;
109 return 2;
110 }
111 query=Form("fMagnitude=%s, fVRColour=%s, fObject=",
112 (*arr)[2]->GetName(), (*arr)[3]->GetName());
113 comment=(*arr)[4]->GetName();
114 if (comment=="-")
115 query+="NULL";
116 else
117 query+=Form("'%s'", comment.Data());
118
119 query+=Form(", fObjectName='%s/%s'", (*arr)[0]->GetName(), (*arr)[1]->GetName());
120 where=Form(" fObjectName='%s/%s'", (*arr)[0]->GetName(), (*arr)[1]->GetName());
121 delete arr;
122
123 if (serv.InsertUpdate("Object", query, where)==kFALSE)
124 return 2;
125 num +=1;
126
127 }
128
129 cout << fname << " <" << num << "> " << endl;
130
131 return 1;
132}
Note: See TracBrowser for help on using the repository browser.