source: trunk/MagicSoft/Mars/datacenter/macros/findcacofiles.C@ 8065

Last change on this file since 8065 was 7460, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 3.6 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// findcacofiles.C
28// ===============
29//
30// Macro to get from the database the number of the runs, for which no caco
31// file is available.
32//
33// Sometimes the DAQ aborts a run and starts itself a new one. In this cases
34// the camera controll doesn't start a new file, as the command to
35// start a new run was not sent by the central control. So the caco
36// information is stored in the previous caco file, which has a different
37// runnumber. To be able to merpp the information into the calibrated data
38// file, the runnumber of the file containing the information has to be found.
39// This is done by a script.
40// findcacofiles.C produces the input for this script. It queries from the
41// database, for which runs no caco file with the same runnumber is available
42// and writes the runnumbers into an txt file.
43//
44// Usage:
45// .x findcacofiles.C+("date", "logpath")
46// date and logpath are needed only for the output file
47//
48// Make sure, that database and password are corretly set in a resource
49// file called sql.rc and the resource file is found.
50//
51// Returns 0 in case of failure and 1 in case of success.
52//
53/////////////////////////////////////////////////////////////////////////////
54
55#include <iostream>
56#include <iomanip>
57#include <fstream>
58
59#include <TEnv.h>
60#include <TSystem.h>
61
62#include <MSQLServer.h>
63#include <TSQLRow.h>
64#include <TSQLResult.h>
65
66using namespace std;
67
68
69int findcacofiles(TString date, TString logpath)
70{
71 TEnv env("sql.rc");
72
73 MSQLServer serv(env);
74 if (!serv.IsConnected())
75 {
76 cout << "ERROR - Connection to database failed." << endl;
77 return 0;
78 }
79 cout << "findcacofiles" << endl;
80 cout << "-------------" << endl;
81 cout << endl;
82 cout << "Connected to " << serv.GetName() << endl;
83 cout << endl;
84
85 //get runnumbers from database
86 TString query="SELECT RunProcessStatus.fRunNumber FROM RunProcessStatus ";
87 query+=" LEFT JOIN RunData on RunData.fRunNumber=RunProcessStatus.fRunNumber ";
88 query+=" WHERE IsNull(fCaCoFileFound) and fExcludedFDAKEY=1 ";
89 query+=" and RunProcessStatus.fRunNumber > 10000 and not IsNull(fCCFileAvail)";
90
91 TSQLResult *res = serv.Query(query);
92 if (!res)
93 {
94 cout << "Error." << endl;
95 return 0;
96 }
97
98 //create output file
99 TString filename(Form("%s/findcacofiles-%s.txt", logpath.Data(), date.Data()));
100 ofstream fout(filename, ios::app);
101 if (!fout)
102 {
103 cout << "ERROR - Cannot open file " << filename << endl;
104 return 0;
105 }
106
107 //write runnumbers into output file
108 TSQLRow *row=0;
109 while ((row = res->Next()))
110 fout << (*row)[0] << endl;
111
112 delete res;
113 return 1;
114}
115
116
Note: See TracBrowser for help on using the repository browser.