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 /home/operator/Documents/optical/good_compstars_R.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 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // loop over all files in this path
|
---|
54 | //
|
---|
55 | int fillobjects(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 comment;
|
---|
87 | while (1)
|
---|
88 | {
|
---|
89 | TString line;
|
---|
90 | line.ReadLine(fin);
|
---|
91 | if (!fin)
|
---|
92 | break;
|
---|
93 |
|
---|
94 | if (line.IsNull())
|
---|
95 | continue;
|
---|
96 |
|
---|
97 | line.ReplaceAll("\t", " ");
|
---|
98 | TObjArray *arr = line.Tokenize(" ");
|
---|
99 | if (arr->GetEntries()!=5)
|
---|
100 | {
|
---|
101 | cout << "WARNING: line with less or more than 5 arguments found " << endl;
|
---|
102 | cout << line << endl;
|
---|
103 | return 2;
|
---|
104 | }
|
---|
105 | query=Form("fMagnitude=%s, fVRColour=%s, fObject=",
|
---|
106 | (*arr)[2]->GetName(), (*arr)[3]->GetName());
|
---|
107 | comment=(*arr)[4]->GetName();
|
---|
108 | if (comment=="-")
|
---|
109 | query+="NULL";
|
---|
110 | else
|
---|
111 | query+=Form("'%s'", comment.Data());
|
---|
112 |
|
---|
113 | query+=Form(", fObjectName='%s/%s'", (*arr)[0]->GetName(), (*arr)[1]->GetName());
|
---|
114 | delete arr;
|
---|
115 |
|
---|
116 | if (serv.Insert("Object", query)==kFALSE)
|
---|
117 | return 2;
|
---|
118 | num +=1;
|
---|
119 |
|
---|
120 | }
|
---|
121 |
|
---|
122 | cout << fname << " <" << num << "> " << endl;
|
---|
123 |
|
---|
124 | return 1;
|
---|
125 | }
|
---|