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 |
|
---|
44 | using namespace std;
|
---|
45 |
|
---|
46 |
|
---|
47 | int getdolist(TString table, TString column, TString date, TString listpath)
|
---|
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 | query+=Form(" ORDER BY %s.%s DESC ", table.Data(), rc.GetValue(table+".Primary", ""));
|
---|
113 |
|
---|
114 | if (table=="RunProcessStatus")
|
---|
115 | query+="LIMIT 0, 500";
|
---|
116 |
|
---|
117 | cout << "query: " << query << endl;
|
---|
118 |
|
---|
119 | TSQLResult *res = serv.Query(query);
|
---|
120 | if (!res)
|
---|
121 | {
|
---|
122 | cout << "ERROR - Query failed: " << query << endl;
|
---|
123 | return 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | TString filename;
|
---|
128 | TSQLRow *row=0;
|
---|
129 |
|
---|
130 | if ((table=="SequenceProcessStatus" && column=="fCallisto") ||
|
---|
131 | (table=="SequenceProcessStatus" && column=="fStar") ||
|
---|
132 | (table=="DataSetProcessStatus" && column=="fGanymed"))
|
---|
133 | {
|
---|
134 | while ((row = res->Next()))
|
---|
135 | {
|
---|
136 | filename=Form("%s/ToDo-%s-%s-%s.txt", listpath.Data(), table.Data(), column.Data(), (*row)[0]);
|
---|
137 | ofstream fout(filename, ios::app);
|
---|
138 | if (!fout)
|
---|
139 | {
|
---|
140 | cout << "ERROR - Cannot open file " << filename << endl;
|
---|
141 | return 0;
|
---|
142 | }
|
---|
143 | fout << (*row)[0] << endl;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | else
|
---|
147 | {
|
---|
148 | filename=Form("%s/ToDo-%s-%s.txt", listpath.Data(), table.Data(), column.Data());
|
---|
149 | ofstream fout(filename, ios::app);
|
---|
150 | if (!fout)
|
---|
151 | {
|
---|
152 | cout << "ERROR - Cannot open file " << filename << endl;
|
---|
153 | return 0;
|
---|
154 | }
|
---|
155 |
|
---|
156 | while ((row = res->Next()))
|
---|
157 | fout << (*row)[0] << endl;
|
---|
158 | }
|
---|
159 |
|
---|
160 | delete res;
|
---|
161 |
|
---|
162 | return 1;
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|