source: trunk/Mars/datacenter/macros/resetallruns.C@ 18403

Last change on this file since 18403 was 9007, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.1 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-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#include <iostream>
47#include <iomanip>
48#include <fstream>
49
50#include <TPRegexp.h>
51
52#include "MSQLMagic.h"
53
54using namespace std;
55
56int resetallruns(TString filename, TString column, Bool_t dummy=kTRUE)
57{
58 MSQLMagic serv("sql.rc");
59 if (!serv.IsConnected())
60 {
61 cout << "ERROR - Connection to database failed." << endl;
62 return 0;
63 }
64
65 cout << "resetallruns" << endl;
66 cout << "------------" << endl;
67 cout << endl;
68 cout << "Connected to " << serv.GetName() << endl;
69 cout << endl;
70 cout << "File: " << filename << endl;
71 cout << "Column: " << column << endl;
72 cout << endl;
73
74 serv.SetIsDummy(dummy);
75
76 //reset column to NULL, if the column is fCaCoFileAvail,
77 //reset also the column fCaCoFileFound
78 TString vars(column);
79 vars += "=NULL";
80 if (column.Contains("CaCo"))
81 vars += ", fCaCoFileFound=NULL";
82
83 if (serv.Update("RunProcessStatus", vars)==kFALSE)
84 return 2;
85
86 //read in file
87 ifstream fin(filename);
88 if (!fin)
89 {
90 cout << "ERROR - File " << filename << " missing!" << endl;
91 return 2;
92 }
93
94 TPRegexp regtel("^_M[0-9]_");
95 TPRegexp regrun("_[0-9]{5,8}");
96 TPRegexp regfile("[.][0-9]{3,5}_$");
97 while (1)
98 {
99 //get runnumber
100 TString str;
101 str.ReadLine(fin);
102 if (!fin)
103 break;
104
105 const TString tel = str(regtel);
106 const TString run = str(regrun);
107 const TString file = str(regfile);
108
109 const UInt_t ntel = tel.IsNull() ? 1 : atoi(tel.Data()+2);
110 const UInt_t nfile = file.IsNull() ? 0 : atoi(file.Data()+1);
111 const UInt_t nrun = atoi(run.Data()+1);
112
113 if (nrun>999999 && (tel.IsNull() || file.IsNull()))
114 {
115 cout << "ERROR - Run number " << nrun << ">999999 and telescope and/or run-number missing!" << endl;
116 cout << str << endl;
117 continue;
118 }
119
120 const UInt_t id = nrun*1000+nfile;
121
122 //build query and set status for this run to Now()
123 TString vars2(column);
124 vars2 += "=Now()";
125 if (column.Contains("CaCo"))
126 vars2 += Form(", fCaCoFileFound=%d", id);
127
128 TString where = Form("fTelescopeNumber=%d AND fRunNumber=%d AND fFileNumber=%d ",
129 ntel, nrun, nfile);
130
131 if (serv.Update("RunProcessStatus", vars2, where)==kFALSE)
132 return 2;
133 }
134
135 return 1;
136}
Note: See TracBrowser for help on using the repository browser.