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-2006
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // resetallruns.C
|
---|
28 | // ==============
|
---|
29 | //
|
---|
30 | // This macro resets the values of a column in the table RunProcessStatus. It
|
---|
31 | // is used by the script filesondisk to reset the values for the columns,
|
---|
32 | // which indicate the availability of the files.
|
---|
33 | //
|
---|
34 | // Usage:
|
---|
35 | // .x resetallrun.C+("filename", "column")
|
---|
36 | // The first argument is giving a file, in which a list of runs can be found
|
---|
37 | // for which the column will be set to Now() by this macro. The second
|
---|
38 | // argument is giving the column, which has to be reset.
|
---|
39 | //
|
---|
40 | // Make sure, that database and password are corretly set in a resource
|
---|
41 | // file called sql.rc and the resource file is found.
|
---|
42 | //
|
---|
43 | // Returns 0 in case of failure and 1 in case of success.
|
---|
44 | //
|
---|
45 | /////////////////////////////////////////////////////////////////////////////
|
---|
46 |
|
---|
47 | #include <iostream>
|
---|
48 | #include <iomanip>
|
---|
49 | #include <fstream>
|
---|
50 |
|
---|
51 | #include <TEnv.h>
|
---|
52 |
|
---|
53 | #include <MSQLServer.h>
|
---|
54 | #include <TSQLRow.h>
|
---|
55 | #include <TSQLResult.h>
|
---|
56 |
|
---|
57 | using namespace std;
|
---|
58 |
|
---|
59 |
|
---|
60 | int resetallruns(TString filename, TString column)
|
---|
61 | {
|
---|
62 | TEnv env("sql.rc");
|
---|
63 |
|
---|
64 | MSQLServer serv(env);
|
---|
65 | if (!serv.IsConnected())
|
---|
66 | {
|
---|
67 | cout << "ERROR - Connection to database failed." << endl;
|
---|
68 | return 0;
|
---|
69 | }
|
---|
70 | cout << "resetallruns" << endl;
|
---|
71 | cout << "------------" << endl;
|
---|
72 | cout << endl;
|
---|
73 | cout << "Connected to " << serv.GetName() << endl;
|
---|
74 | cout << endl;
|
---|
75 |
|
---|
76 | //reset column to NULL
|
---|
77 | TString query(Form("UPDATE RunProcessStatus SET %s=NULL",
|
---|
78 | column.Data()));
|
---|
79 | //if the column is fCaCoFileAvail, reset also the column fCaCoFileFound
|
---|
80 | if (column.Contains("CaCo"))
|
---|
81 | query+=", fCaCoFileFound=NULL";
|
---|
82 |
|
---|
83 | cout << "q: " << query << endl;
|
---|
84 |
|
---|
85 | TSQLResult *res = serv.Query(query);
|
---|
86 | if (!res)
|
---|
87 | {
|
---|
88 | cout << "updating (setting " << column.Data() << "= NULL) didn't work " << endl;
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 | delete res;
|
---|
92 |
|
---|
93 |
|
---|
94 | //read in file
|
---|
95 | ifstream fin(filename);
|
---|
96 | if (!fin)
|
---|
97 | {
|
---|
98 | cout << "file: " << filename << " missing!" << endl;
|
---|
99 | return 0;
|
---|
100 | }
|
---|
101 | while (1)
|
---|
102 | {
|
---|
103 | //get runnumber
|
---|
104 | TString runnumber;
|
---|
105 | runnumber.ReadLine(fin);
|
---|
106 | if (!fin)
|
---|
107 | break;
|
---|
108 |
|
---|
109 | //build query and set status for this run to Now()
|
---|
110 | TString query(Form("UPDATE RunProcessStatus SET %s=Now()", column.Data()));
|
---|
111 |
|
---|
112 | if (column.Contains("CaCo"))
|
---|
113 | query+=Form(", fCaCoFileFound=%d", atoi(runnumber));
|
---|
114 |
|
---|
115 | query+=Form(" WHERE fRunNumber=%d ", atoi(runnumber));
|
---|
116 |
|
---|
117 | cout << "q2: " << query << endl;
|
---|
118 |
|
---|
119 | res = serv.Query(query);
|
---|
120 | if (!res)
|
---|
121 | {
|
---|
122 | cout << "updating (setting " << column.Data() << " = Now()) for run# " << atoi(runnumber) << ") didn't work " << endl;
|
---|
123 | return 0;
|
---|
124 | }
|
---|
125 | delete res;
|
---|
126 | }
|
---|
127 |
|
---|
128 | return 1;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|