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

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