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

Last change on this file since 8085 was 8085, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
File size: 4.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-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 = res->Next();
80
81 TString ret = row ? (*row)[0] : "";
82
83 delete res;
84
85 return ret;
86}
87
88int checkfileavail(TString sequencefile)
89{
90 TEnv env("sql.rc");
91
92 MSQLServer serv(env);
93 if (!serv.IsConnected())
94 {
95 cout << "ERROR - Connection to database failed." << endl;
96 return 0;
97 }
98 cout << "checkfileavail" << endl;
99 cout << "--------------" << endl;
100 cout << endl;
101 cout << "Connected to " << serv.GetName() << endl;
102 cout << endl;
103
104 TEnv rc("steps.rc");
105
106 //reading runnumbers from Sequencefile
107 TEnv sequ(sequencefile);
108 cout << "sequ file: " << sequencefile.Data() << endl;
109 TString runs;
110 runs = sequ.GetValue("Runs", "");
111 runs.ReplaceAll(" ", ",");
112 if (runs.IsNull())
113 {
114 cout << "ERROR - No runs in file " << sequencefile << " found." << endl;
115 return 0;
116 }
117
118 //getting runnumbers from database
119 //(not neccessary anymore -> can be changed)
120 TString query="SELECT fRunNumber FROM RunData WHERE fRunNumber in (";
121 query +=runs.Data();
122 query +=")";
123
124 TSQLResult *res = serv.Query(query);
125 if (!res)
126 cout << "Error - no run to check" << endl;
127
128 //check for each run the availability of files from the table RunProcessStatus
129 //the following columns have to be checked:
130 //fCCFileAvail, fCaCoFileAvail, fCaCoFileFound, fRawFileAvail, fTimingCorrection
131 //fTimingCorrection has to be checked, as only rawfiles with correct timing should be calibrated
132 TSQLRow *row=0;
133 while ((row = res->Next()))
134 {
135 TString runno=(*row)[0];
136 cout << "run#: " << runno << endl;
137 //if one value returns "" (i.e. column is NULL), 0 is returned
138 if (GetStatus(serv, rc, runno, "RunProcessStatus", "fCCFileAvail").IsNull()
139 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileAvail").IsNull()
140 || GetStatus(serv, rc, runno, "RunProcessStatus", "fCaCoFileFound").IsNull()
141 || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection").IsNull()
142// || GetStatus(serv, rc, runno, "RunProcessStatus", "fTimingCorrection")=="1970-01-01 00:00:00"
143 || GetStatus(serv, rc, runno, "RunProcessStatus", "fRawFileAvail").IsNull())
144 return 2;
145 }
146 //if all values are okay (i.e. files are availabel), 1 is returned
147 return 1;
148
149}
150
Note: See TracBrowser for help on using the repository browser.