source: trunk/MagicSoft/Mars/datacenter/macros/resetcolumn.C@ 7459

Last change on this file since 7459 was 7459, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 3.8 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, 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// resetcolumn.C
28// =============
29//
30// This macro is used to reset values in the DB.
31//
32// If a step in the automatic analysis chain has to be repeated, the value
33// for this step in the DB has to be reset. This can be done with this macro.
34//
35// As arguments you have to give the column, the table and from which
36// to which Date/Sequence/Run/Dataset you want to reset the value.
37//
38// The last argument is the 'dummy-mode'. If it is kTRUE dummy-mode is
39// switched on and nothing will be written into the database. This is usefull
40// for tests (i.e. if you want to see if the query is correct).
41//
42// Usage:
43// .x resetcolumn.C("fStar","SequenceProcessStatus","45114","49329",kTRUE)
44//
45// Make sure, that database and password are corretly set in a resource
46// file called sql.rc and the resource file is found.
47//
48// Returns 0 in case of failure and 1 in case of success.
49//
50/////////////////////////////////////////////////////////////////////////////
51
52#include <iostream>
53#include <iomanip>
54#include <fstream>
55
56#include <TEnv.h>
57#include <TObjString.h>
58#include <TList.h>
59
60#include <MSQLServer.h>
61#include <TSQLRow.h>
62#include <TSQLResult.h>
63
64using namespace std;
65
66
67int resetcolumn(TString column, TString table, TString from, TString to, Bool_t dummy=kTRUE)
68{
69 TEnv env("sql.rc");
70
71 MSQLServer serv(env);
72 if (!serv.IsConnected())
73 {
74 cout << "ERROR - Connection to database failed." << endl;
75 return 0;
76 }
77 cout << "resetcolumn" << endl;
78 cout << "-----------" << endl;
79 cout << endl;
80 cout << "Connected to " << serv.GetName() << endl;
81 cout << endl;
82
83 TEnv rc("steps.rc");
84 //get steps which are influenced by the step, which is resetted
85 TString influences = rc.GetValue(table+"."+column+".Influences", "");
86
87 cout << "resetting column " << column << flush;
88 cout << " and the columns it influences(" << influences << ") from " << flush;
89 cout << from << " to " << to << "..." << endl;
90
91 TList l;
92 while (!influences.IsNull())
93 {
94 influences = influences.Strip(TString::kBoth);
95
96 Int_t idx = influences.First(' ');
97 if (idx<0)
98 idx = influences.Length();
99
100 TString influence = influences(0, idx);
101 influences.Remove(0, idx);
102 l.Add(new TObjString(influence));
103 }
104
105 //build query and reset columns
106 TString query(Form("Update %s SET %s=NULL ", table.Data(), column.Data()));
107
108 TIter Next(&l);
109 TObject *o=0;
110 while ((o=Next()))
111 query+=Form(", %s=NULL ", o->GetName());
112
113 query+=Form(" WHERE %s between '%s' and '%s'", rc.GetValue(table+".Primary", ""), from.Data(), to.Data());
114
115 if (dummy)
116 {
117 cout << "query: " << query << endl;
118 return 1;
119 }
120
121 TSQLResult *res = serv.Query(query);
122 if (!res)
123 return 0;
124
125 delete res;
126
127 return 1;
128}
129
130
Note: See TracBrowser for help on using the repository browser.