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

Last change on this file since 7352 was 7324, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 4.7 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#include <TSystem.h>
40
41#include <MSQLServer.h>
42#include <TSQLRow.h>
43#include <TSQLResult.h>
44
45using namespace std;
46
47
48int getdolist(TString table, TString column, TString date, TString listpath)
49{
50 TEnv env("sql.rc");
51
52 MSQLServer serv(env);
53 if (!serv.IsConnected())
54 {
55 cout << "ERROR - Connection to database failed." << endl;
56 return 0;
57 }
58 cout << "getstatus" << endl;
59 cout << "---------" << endl;
60 cout << endl;
61 cout << "Connected to " << serv.GetName() << endl;
62 cout << endl;
63
64 TEnv rc("steps.rc");
65
66 TString needs = rc.GetValue(table+"."+column+".Needs", "");
67 cout << "Needs: " << needs << endl;
68
69 TList l;
70
71 while (!needs.IsNull())
72 {
73 needs = needs.Strip(TString::kBoth);
74
75 Int_t idx = needs.First(' ');
76 if (idx<0)
77 idx = needs.Length();
78
79 TString need = needs(0, idx);
80 needs.Remove(0, idx);
81 l.Add(new TObjString(need));
82 }
83
84 TString query(Form("SELECT %s.%s FROM %s",
85 table.Data(), rc.GetValue(table+".Primary", ""),
86 table.Data()));
87
88 if (date!="NULL" && rc.GetValue(table+".TimerTable", "")!="")
89 query+=Form(" left join %s on %s.%s=%s.%s ",
90 rc.GetValue(table+".TimerTable", ""), table.Data(),
91 rc.GetValue(table+".Primary", ""),
92 rc.GetValue(table+".TimerTable", ""),
93 rc.GetValue(table+".Primary", ""));
94 query+=Form(" WHERE ISNULL(%s)", column.Data());
95
96 TIter Next(&l);
97 TObject *o=0;
98 while ((o=Next()))
99 query+=Form(" AND NOT ISNULL(%s)", o->GetName());
100
101 if (date!="NULL")
102 {
103 if (rc.GetValue(table+".TimerTable", "")!="")
104 {
105 TString day=date+" 13:00:00";
106 query+=Form(" AND (fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\")",
107 day.Data(), day.Data());
108 }
109 else
110 query+=Form(" AND %s=%s ", rc.GetValue(table+".Primary", ""), date.Data());
111 }
112
113 query+=Form(" ORDER BY %s.%s DESC ", table.Data(), rc.GetValue(table+".Primary", ""));
114
115 if (table=="RunProcessStatus")
116 query+="LIMIT 0, 500";
117
118 cout << "query: " << query << endl;
119
120 TSQLResult *res = serv.Query(query);
121 if (!res)
122 {
123 cout << "ERROR - Query failed: " << query << endl;
124 return 0;
125 }
126
127
128 TString filename;
129 TSQLRow *row=0;
130
131 if ((table=="SequenceProcessStatus" && column=="fCallisto") ||
132 (table=="SequenceProcessStatus" && column=="fStar") ||
133 (table=="RunProcessStatus" && column=="fDataCheckDone") ||
134 (table=="DataSetProcessStatus" && column=="fGanymed"))
135 {
136 while ((row = res->Next()))
137 {
138 filename=Form("%s/ToDo-%s-%s-%s.txt", listpath.Data(), table.Data(), column.Data(), (*row)[0]);
139 gSystem->Unlink(filename);
140 ofstream fout(filename, ios::app);
141 if (!fout)
142 {
143 cout << "ERROR - Cannot open file " << filename << endl;
144 return 0;
145 }
146 fout << (*row)[0] << endl;
147 }
148 }
149 else
150 {
151 filename=Form("%s/ToDo-%s-%s.txt", listpath.Data(), table.Data(), column.Data());
152 ofstream fout(filename, ios::app);
153 if (!fout)
154 {
155 cout << "ERROR - Cannot open file " << filename << endl;
156 return 0;
157 }
158
159 while ((row = res->Next()))
160 fout << (*row)[0] << endl;
161 }
162
163 delete res;
164
165 return 1;
166}
167
168
Note: See TracBrowser for help on using the repository browser.