source: tags/Mars-V0.9.5.1/datacenter/macros/resetcolumn.C

Last change on this file was 7572, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 3.9 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-2006
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 2 in case of failure, 1 in case of success and 0 if the connection
49// to the database is not working.
50//
51/////////////////////////////////////////////////////////////////////////////
52
53#include <iostream>
54#include <iomanip>
55#include <fstream>
56
57#include <TEnv.h>
58#include <TObjString.h>
59#include <TList.h>
60
61#include <MSQLServer.h>
62#include <TSQLRow.h>
63#include <TSQLResult.h>
64
65using namespace std;
66
67
68int resetcolumn(TString column, TString table, TString from, TString to, Bool_t dummy=kTRUE)
69{
70 TEnv env("sql.rc");
71
72 MSQLServer serv(env);
73 if (!serv.IsConnected())
74 {
75 cout << "ERROR - Connection to database failed." << endl;
76 return 0;
77 }
78 cout << "resetcolumn" << endl;
79 cout << "-----------" << endl;
80 cout << endl;
81 cout << "Connected to " << serv.GetName() << endl;
82 cout << endl;
83
84 TEnv rc("steps.rc");
85 //get steps which are influenced by the step, which is resetted
86 TString influences = rc.GetValue(table+"."+column+".Influences", "");
87
88 cout << "resetting column " << column << flush;
89 cout << " and the columns it influences(" << influences << ") from " << flush;
90 cout << from << " to " << to << "..." << endl;
91
92 TList l;
93 while (!influences.IsNull())
94 {
95 influences = influences.Strip(TString::kBoth);
96
97 Int_t idx = influences.First(' ');
98 if (idx<0)
99 idx = influences.Length();
100
101 TString influence = influences(0, idx);
102 influences.Remove(0, idx);
103 l.Add(new TObjString(influence));
104 }
105
106 //build query and reset columns
107 TString query(Form("Update %s SET %s=NULL ", table.Data(), column.Data()));
108 query+=", fStartTime=NULL, fFailedTime=NULL, fReturnCode=NULL, fFailedCode=NULL, fFailedCodeAdd=NULL ";
109
110 TIter Next(&l);
111 TObject *o=0;
112 while ((o=Next()))
113 query+=Form(", %s=NULL ", o->GetName());
114
115 query+=Form(" WHERE %s between '%s' and '%s'", rc.GetValue(table+".Primary", ""), from.Data(), to.Data());
116
117 if (dummy)
118 {
119 cout << "query: " << query << endl;
120 return 1;
121 }
122
123 TSQLResult *res = serv.Query(query);
124 if (!res)
125 return 2;
126
127 delete res;
128
129 return 1;
130}
131
132
Note: See TracBrowser for help on using the repository browser.