source: trunk/MagicSoft/Mars/datacenter/macros/getdolist.C@ 7112

Last change on this file since 7112 was 7112, checked in by Daniela Dorner, 19 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): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// GetDoList.C
28// ===========
29//
30/////////////////////////////////////////////////////////////////////////////
31
32#include <iostream>
33#include <iomanip>
34#include <fstream>
35
36#include <TEnv.h>
37#include <TObjString.h>
38#include <TList.h>
39
40#include <MSQLServer.h>
41#include <TSQLRow.h>
42#include <TSQLResult.h>
43
44using namespace std;
45
46
47int getdolist(TString table, TString column, TString date)
48{
49 TEnv env("sql.rc");
50
51 MSQLServer serv(env);
52 if (!serv.IsConnected())
53 {
54 cout << "ERROR - Connection to database failed." << endl;
55 return 0;
56 }
57 cout << "getstatus" << endl;
58 cout << "---------" << endl;
59 cout << endl;
60 cout << "Connected to " << serv.GetName() << endl;
61 cout << endl;
62
63 TEnv rc("steps.rc");
64
65 TString needs = rc.GetValue(table+"."+column+".Needs", "");
66 cout << "Needs: " << needs << endl;
67
68 TList l;
69
70 while (!needs.IsNull())
71 {
72 needs = needs.Strip(TString::kBoth);
73
74 Int_t idx = needs.First(' ');
75 if (idx<0)
76 idx = needs.Length();
77
78 TString need = needs(0, idx);
79 needs.Remove(0, idx);
80 l.Add(new TObjString(need));
81 }
82
83 TString query(Form("SELECT %s.%s FROM %s",
84 table.Data(), rc.GetValue(table+".Primary", ""),
85 table.Data()));
86
87 if (date!="NULL" && rc.GetValue(table+".TimerTable", "")!="")
88 query+=Form(" left join %s on %s.%s=%s.%s ",
89 rc.GetValue(table+".TimerTable", ""), table.Data(),
90 rc.GetValue(table+".Primary", ""),
91 rc.GetValue(table+".TimerTable", ""),
92 rc.GetValue(table+".Primary", ""));
93 query+=Form(" WHERE ISNULL(%s)", column.Data());
94
95 TIter Next(&l);
96 TObject *o=0;
97 while ((o=Next()))
98 query+=Form(" AND NOT ISNULL(%s)", o->GetName());
99
100 if (date!="NULL")
101 {
102 if (rc.GetValue(table+".TimerTable", "")!="")
103 {
104 TString day=date+" 13:00:00";
105 query+=Form(" AND (fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
106 day.Data(), day.Data());
107 }
108 else
109 query+=Form(" AND %s=%s ", rc.GetValue(table+".Primary", ""), date.Data());
110 }
111
112 cout << "query: " << query << endl;
113
114 TSQLResult *res = serv.Query(query);
115 if (!res)
116 return 0;
117
118 ofstream fout("/magic/datacenter/lists/ToDo-"+table+"-"+column+".txt", ios::app);
119// ofstream fout("/data/MAGIC/datacenter/"+table+"-"+column+".txt", ios::app);
120
121 TSQLRow *row=0;
122 while ((row = res->Next()))
123 fout << (*row)[0] << endl;
124
125 delete res;
126
127 return 1;
128}
129
130
Note: See TracBrowser for help on using the repository browser.