source: trunk/MagicSoft/Mars/datacenter/macros/resetallruns.C@ 7352

Last change on this file since 7352 was 7274, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 2.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, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// ResetAllRuns.C
28// ==============
29//
30/////////////////////////////////////////////////////////////////////////////
31
32#include <iostream>
33#include <iomanip>
34#include <fstream>
35
36#include <TEnv.h>
37
38#include <MSQLServer.h>
39#include <TSQLRow.h>
40#include <TSQLResult.h>
41
42using namespace std;
43
44
45int resetallruns(TString filename, TString column)
46{
47 TEnv env("sql.rc");
48
49 MSQLServer serv(env);
50 if (!serv.IsConnected())
51 {
52 cout << "ERROR - Connection to database failed." << endl;
53 return 0;
54 }
55 cout << "resetallruns" << endl;
56 cout << "------------" << endl;
57 cout << endl;
58 cout << "Connected to " << serv.GetName() << endl;
59 cout << endl;
60
61 TString query(Form("UPDATE RunProcessStatus SET %s=NULL",
62 column.Data()));
63 if (column.Contains("CaCo"))
64 query+=", fCaCoFileFound=NULL";
65
66
67 cout << "q: " << query << endl;
68
69 TSQLResult *res = serv.Query(query);
70 if (!res)
71 {
72 cout << "updating (setting " << column.Data() << "= NULL) didn't work " << endl;
73 return 0;
74 }
75 delete res;
76
77
78 ifstream fin(filename);
79 if (!fin)
80 {
81 cout << "file: " << filename << " missing!" << endl;
82 return 0;
83 }
84
85 while (1)
86 {
87 TString runnumber;
88 runnumber.ReadLine(fin);
89 if (!fin)
90 break;
91
92 TString query(Form("UPDATE RunProcessStatus SET %s=Now()", column.Data()));
93
94 if (column.Contains("CaCo"))
95 query+=Form(", fCaCoFileFound=%d", atoi(runnumber));
96
97 query+=Form(" WHERE fRunNumber=%d ", atoi(runnumber));
98
99 cout << "q2: " << query << endl;
100
101 res = serv.Query(query);
102 if (!res)
103 {
104 cout << "updating (setting " << column.Data() << " = Now()) for run# " << atoi(runnumber) << ") didn't work " << endl;
105 return 0;
106 }
107 delete res;
108 }
109
110 return 1;
111}
112
113
Note: See TracBrowser for help on using the repository browser.