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

Last change on this file since 7669 was 7528, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
File size: 5.0 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// checkfileavail.C
28// ================
29//
30// check the availability of the files of one sequence:
31// the script filesondisk has inserted the information (which files are on
32// disk into the database) and with this macro this information is checked
33// for the runs of one sequence
34//
35// executing the macro:
36// .x checkfileavail.C+("sequencefile")
37// the sequencefile (including path) has to be given, as the macro retrieves
38// from there the runnumbers
39//
40// the macro returns 0, if there's no connection to the database, 2, if a
41// file is missing, and 1 if all files are there
42// the return value is checked by the script, that executes the macro
43//
44// this macro is very similar to the macro checkstardone.C
45//
46/////////////////////////////////////////////////////////////////////////////
47
48#include <iostream>
49#include <iomanip>
50#include <fstream>
51
52#include <TEnv.h>
53
54#include <MSQLServer.h>
55#include <TSQLRow.h>
56#include <TSQLResult.h>
57
58using namespace std;
59
60
61//check the value of a column for a run
62//if a file is not available, the column contains nothing (NULL) - this value is returned
63TString GetStatus(MSQLServer &serv, TEnv &rc, TString primary, TString table, TString column)
64{
65 TString query(Form("SELECT %s FROM %s WHERE %s=%s",
66 column.Data(), table.Data(),
67 rc.GetValue(table+".Primary", ""),
68 primary.Data()));
69
70 cout << "Query: " << query << endl;
71
72 TSQLResult *res = serv.Query(query);
73 if (!res)
74 {
75 cout << "Error - no run to check" << endl;
76 return "";
77 }
78
79 TSQLRow *row=0;
80 while ((row = res->Next()))
81 {
82// TString entry=(*row)[0];
83// if (entry=="1970-01-01 00:00:00")
84// return "";
85 return (*row)[0];
86 }
87
88 return "";
89}
90
91int checkfileavail(TString sequencefile)
92{
93 TEnv env("sql.rc");
94
95 MSQLServer serv(env);
96 if (!serv.IsConnected())
97 {
98 cout << "ERROR - Connection to database failed." << endl;
99 return 0;
100 }
101 cout << "checkfileavail" << endl;
102 cout << "--------------" << endl;
103 cout << endl;
104 cout << "Connected to " << serv.GetName() << endl;
105 cout << endl;
106
107 TEnv rc("steps.rc");
108
109 //reading runnumbers from Sequencefile
110 TEnv sequ(sequencefile);
111 cout << "sequ file: " << sequencefile.Data() << endl;
112 TString runs;
113 runs = sequ.GetValue("Runs", "");
114 runs.ReplaceAll(" ", ",");
115 if (runs.IsNull())
116 {
117 cout << "ERROR - No runs in file " << sequencefile << " found." << endl;
118 return 0;
119 }
120
121 //getting runnumbers from database
122 //(not neccessary anymore -> can be changed)
123 TString query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber in (%s)",
124 runs.Data()));
125
126 TSQLResult *res = serv.Query(query);
127 if (!res)
128 cout << "Error - no run to check" << endl;
129
130 //check for each run the availability of files from the table RunProcessStatus
131 //the following columns have to be checked:
132 //fCCFileAvail, fCaCoFileAvail, fCaCoFileFound, fRawFileAvail, fTimingCorrection
133 //fTimingCorrection has to be checked, as only rawfiles with correct timing should be calibrated
134 TSQLRow *row=0;
135 while ((row = res->Next()))
136 {
137 TString runno=(*row)[0];
138 cout << "run#: " << runno << endl;
139 //if one value returns "" (i.e. column is NULL), 0 is returned
140 if (GetStatus(serv, rc, runno, "RunProcessStatus", "fCCFileAvail")==""
141 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileAvail")==""
142 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileFound")==""
143 || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")==""
144// || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")=="1970-01-01 00:00:00"
145 || GetStatus(serv, rc, runno, "RunProcessStatus", "fRawFileAvail")=="")
146 return 2;
147 }
148 //if all values are okay (i.e. files are availabel), 1 is returned
149 return 1;
150
151}
152
Note: See TracBrowser for help on using the repository browser.