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 |
|
---|
65 | using namespace std;
|
---|
66 |
|
---|
67 |
|
---|
68 | int resetcolumn(TString column, TString table, TString from, TString to, Bool_t dummy=kTRUE)
|
---|
69 | {
|
---|
70 | cout << "This macro has not yet been adapted to the new data structure (Magic II)." << endl;
|
---|
71 | return 0;
|
---|
72 |
|
---|
73 | TEnv env("sql.rc");
|
---|
74 |
|
---|
75 | MSQLServer serv(env);
|
---|
76 | if (!serv.IsConnected())
|
---|
77 | {
|
---|
78 | cout << "ERROR - Connection to database failed." << endl;
|
---|
79 | return 0;
|
---|
80 | }
|
---|
81 | cout << "resetcolumn" << endl;
|
---|
82 | cout << "-----------" << endl;
|
---|
83 | cout << endl;
|
---|
84 | cout << "Connected to " << serv.GetName() << endl;
|
---|
85 | cout << endl;
|
---|
86 |
|
---|
87 | TEnv rc("steps.rc");
|
---|
88 | //get steps which are influenced by the step, which is resetted
|
---|
89 | TString influences = rc.GetValue(table+"."+column+".Influences", "");
|
---|
90 |
|
---|
91 | cout << "resetting column " << column << flush;
|
---|
92 | cout << " and the columns it influences(" << influences << ") from " << flush;
|
---|
93 | cout << from << " to " << to << "..." << endl;
|
---|
94 |
|
---|
95 | TList l;
|
---|
96 | while (!influences.IsNull())
|
---|
97 | {
|
---|
98 | influences = influences.Strip(TString::kBoth);
|
---|
99 |
|
---|
100 | Int_t idx = influences.First(' ');
|
---|
101 | if (idx<0)
|
---|
102 | idx = influences.Length();
|
---|
103 |
|
---|
104 | TString influence = influences(0, idx);
|
---|
105 | influences.Remove(0, idx);
|
---|
106 | l.Add(new TObjString(influence));
|
---|
107 | }
|
---|
108 |
|
---|
109 | //build query and reset columns
|
---|
110 | TString query(Form("Update %s SET %s=NULL ", table.Data(), column.Data()));
|
---|
111 | query+=", fStartTime=NULL, fFailedTime=NULL, fReturnCode=NULL, fProgramId=NULL ";
|
---|
112 |
|
---|
113 | TIter Next(&l);
|
---|
114 | TObject *o=0;
|
---|
115 | while ((o=Next()))
|
---|
116 | query+=Form(", %s=NULL ", o->GetName());
|
---|
117 |
|
---|
118 | query+=Form(" WHERE %s between '%s' and '%s'", rc.GetValue(table+".Primary", ""), from.Data(), to.Data());
|
---|
119 |
|
---|
120 | if (dummy)
|
---|
121 | {
|
---|
122 | cout << "query: " << query << endl;
|
---|
123 | return 1;
|
---|
124 | }
|
---|
125 |
|
---|
126 | TSQLResult *res = serv.Query(query);
|
---|
127 | if (!res)
|
---|
128 | return 2;
|
---|
129 |
|
---|
130 | delete res;
|
---|
131 |
|
---|
132 | return 1;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|