source: trunk/MagicSoft/Mars/datacenter/macros/checkfileavail.C@ 7426

Last change on this file since 7426 was 7426, 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-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// checkfileavail.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
45TString GetStatus(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column)
46{
47 TString query(Form("SELECT %s FROM %s WHERE %s=%s",
48 column.Data(), table.Data(),
49 rc.GetValue(table+".Primary", ""),
50 primary.Data()));
51
52 cout << "Query: " << query << endl;
53
54 TSQLResult *res = serv.Query(query);
55 if (!res)
56 {
57 cout << "Error - no run to check" << endl;
58 return "";
59 }
60
61 TSQLRow *row=0;
62 while ((row = res->Next()))
63 {
64// TString entry=(*row)[0];
65// if (entry=="1970-01-01 00:00:00")
66// return "";
67 return (*row)[0];
68 }
69
70 return "";
71}
72
73int checkfileavail(TString sequencefile)
74{
75 TEnv env("sql.rc");
76
77 MSQLServer serv(env);
78 if (!serv.IsConnected())
79 {
80 cout << "ERROR - Connection to database failed." << endl;
81 return 0;
82 }
83 cout << "checkfileavail" << endl;
84 cout << "--------------" << endl;
85 cout << endl;
86 cout << "Connected to " << serv.GetName() << endl;
87 cout << endl;
88
89 TEnv rc("steps.rc");
90
91 TEnv sequ(sequencefile);
92
93 TString runs;
94 runs = sequ.GetValue("Runs", "");
95 runs.ReplaceAll(" ", ",");
96 if (runs.IsNull())
97 {
98 cout << "ERROR - No runs in file " << sequencefile << " found." << endl;
99 return 0;
100 }
101
102 cout << "sequ file: " << sequencefile.Data() << endl;
103 TString query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber in (%s)",
104 sequencefile.Data()));
105
106 TSQLResult *res = serv.Query(query);
107 if (!res)
108 cout << "Error - no run to check" << endl;
109
110 TSQLRow *row=0;
111 while ((row = res->Next()))
112 {
113 TString runno=(*row)[0];
114 cout << "run#: " << runno << endl;
115 if (GetStatus(serv, rc, runno, "RunProcessStatus", "fCCFileAvail")==""
116 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileAvail")==""
117 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileFound")==""
118 || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")==""
119// || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")=="1970-01-01 00:00:00"
120 || GetStatus(serv, rc, runno, "RunProcessStatus", "fRawFileAvail")=="")
121 return 0;
122 }
123 return 1;
124
125}
126
Note: See TracBrowser for help on using the repository browser.