source: tags/Mars-V0.9.4.1/datacenter/macros/setstatus.C

Last change on this file was 7112, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
File size: 4.3 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// SetStatus.C
28// ===========
29//
30/////////////////////////////////////////////////////////////////////////////
31
32#include <iostream>
33#include <iomanip>
34#include <fstream>
35
36#include <TEnv.h>
37
38#include <MTime.h>
39
40#include <MSQLServer.h>
41#include <TSQLRow.h>
42#include <TSQLResult.h>
43
44using namespace std;
45
46
47Bool_t CheckReset(TEnv &rc, TString table, TString column, TString value)
48{
49 if (value!="NULL")
50 {
51 cout << "everything ok - no reset needed" << endl;
52 return kTRUE;
53 }
54
55 TString reset=rc.GetValue(table+"."+column+".Reset", "no");
56 if (reset.Contains("no"))
57 {
58 cout << "you can't reset " << column << "." << endl;
59 return kFALSE;
60 }
61
62 cout << "reset is possible" << endl;
63 return kTRUE;
64}
65
66TString CheckDefault(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString influence)
67{
68 TString query(Form("SELECT %s FROM %s WHERE %s=%s",
69 influence.Data(), table.Data(),
70 rc.GetValue(table+".Primary", ""), primary.Data()));
71
72 TSQLResult *res = serv.Query(query);
73 if (!res)
74 cout << "Error - no run to check" << endl;
75
76 MTime t, t0;
77 //set time t to 'no-version-value',
78 //which is in this case equivalent to NULL
79 t.Set(1970,1,1,0,0,0);
80 t0.Set(1970,1,1,0,0,0);
81
82 TSQLRow *row=0;
83 while ((row = res->Next()))
84 {
85 if (row && (*row)[0])
86 t.SetSqlDateTime((*row)[0]);
87
88 cout << "t : " << t << endl;
89 cout << "t0: " << t0 << endl;
90
91 return t()-t0()>0 ? "no" : "yes";
92 }
93}
94
95Int_t SetInfluences(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column, TString value, Bool_t resetall)
96{
97 cout << "set influenes for " << table << "." << column << endl;
98
99 TString influences = rc.GetValue(table+"."+column+".Influences", "");
100
101 TString query(Form("UPDATE %s SET %s=%s",
102 table.Data(), column.Data(), value.Data()));
103
104 while (!influences.IsNull() && resetall)
105 {
106 influences = influences.Strip(TString::kBoth);
107
108 Int_t idx = influences.First(' ');
109 if (idx<0)
110 idx = influences.Length();
111
112 TString influence = influences(0, idx);
113 influences.Remove(0, idx);
114
115 TString deflt = rc.GetValue(influence+".Default", "");
116
117 if (deflt=="check")
118 deflt=CheckDefault(serv, rc, primary, table, influence);
119
120 if (deflt=="yes")
121 continue;
122
123 query+=Form(", %s=NULL", influence.Data());
124 }
125
126 query+=Form(" WHERE %s='%s'", rc.GetValue(table+".Primary", ""), primary.Data());
127
128// cout << "query: " << query << endl;
129
130 TSQLResult *res = serv.Query(query);
131 if (!res)
132 return 0;
133
134 return 1;
135}
136
137int setstatus(TString primary, TString table, TString column, TString value, Bool_t resetall=kTRUE)
138{
139 TEnv env("sql.rc");
140
141 MSQLServer serv(env);
142 if (!serv.IsConnected())
143 {
144 cout << "ERROR - Connection to database failed." << endl;
145 return 0;
146 }
147 cout << "setstatus" << endl;
148 cout << "---------" << endl;
149 cout << endl;
150 cout << "Connected to " << serv.GetName() << endl;
151 cout << endl;
152
153 TEnv rc("steps.rc");
154
155 return !CheckReset(rc, table, column, value) ? 0 : SetInfluences(serv, rc, primary, table, column, value, resetall);
156
157}
158
Note: See TracBrowser for help on using the repository browser.