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 <TSQLRow.h>
|
---|
52 | #include <TSQLResult.h>
|
---|
53 |
|
---|
54 | #include "MSQLServer.h"
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 |
|
---|
59 | int resetallruns(TString filename, TString column)
|
---|
60 | {
|
---|
61 | MSQLServer serv("sql.rc");
|
---|
62 | if (!serv.IsConnected())
|
---|
63 | {
|
---|
64 | cout << "ERROR - Connection to database failed." << endl;
|
---|
65 | return 0;
|
---|
66 | }
|
---|
67 | cout << "resetallruns" << endl;
|
---|
68 | cout << "------------" << endl;
|
---|
69 | cout << endl;
|
---|
70 | cout << "Connected to " << serv.GetName() << endl;
|
---|
71 | cout << endl;
|
---|
72 |
|
---|
73 | //reset column to NULL
|
---|
74 | TString query(Form("UPDATE RunProcessStatus SET %s=NULL",
|
---|
75 | column.Data()));
|
---|
76 | //if the column is fCaCoFileAvail, reset also the column fCaCoFileFound
|
---|
77 | if (column.Contains("CaCo"))
|
---|
78 | query+=", fCaCoFileFound=NULL";
|
---|
79 |
|
---|
80 | cout << "q: " << query << endl;
|
---|
81 |
|
---|
82 | TSQLResult *res = serv.Query(query);
|
---|
83 | if (!res)
|
---|
84 | {
|
---|
85 | cout << "updating (setting " << column.Data() << "= NULL) didn't work " << endl;
|
---|
86 | return 0;
|
---|
87 | }
|
---|
88 | delete res;
|
---|
89 |
|
---|
90 |
|
---|
91 | //read in file
|
---|
92 | ifstream fin(filename);
|
---|
93 | if (!fin)
|
---|
94 | {
|
---|
95 | cout << "file: " << filename << " missing!" << endl;
|
---|
96 | return 0;
|
---|
97 | }
|
---|
98 | while (1)
|
---|
99 | {
|
---|
100 | //get runnumber
|
---|
101 | TString runnumber;
|
---|
102 | runnumber.ReadLine(fin);
|
---|
103 | if (!fin)
|
---|
104 | break;
|
---|
105 |
|
---|
106 | //build query and set status for this run to Now()
|
---|
107 | TString query(Form("UPDATE RunProcessStatus SET %s=Now()", column.Data()));
|
---|
108 |
|
---|
109 | if (column.Contains("CaCo"))
|
---|
110 | query+=Form(", fCaCoFileFound=%d", atoi(runnumber));
|
---|
111 |
|
---|
112 | query+=Form(" WHERE fRunNumber=%d ", atoi(runnumber));
|
---|
113 |
|
---|
114 | cout << "q2: " << query << endl;
|
---|
115 |
|
---|
116 | res = serv.Query(query);
|
---|
117 | if (!res)
|
---|
118 | {
|
---|
119 | cout << "updating (setting " << column.Data() << " = Now()) for run# " << atoi(runnumber) << ") didn't work " << endl;
|
---|
120 | return 0;
|
---|
121 | }
|
---|
122 | delete res;
|
---|
123 | }
|
---|
124 |
|
---|
125 | return 1;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|