source: trunk/Mars/datacenter/macros/checkfileavail.C@ 16889

Last change on this file since 16889 was 9036, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 3.4 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-2008
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+(100002)
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, 3 in case of error.
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#include <iostream>
48#include <iomanip>
49
50#include <TSQLRow.h>
51#include <TSQLResult.h>
52
53#include "MSQLServer.h"
54
55using namespace std;
56
57int checkfileavail(Int_t num, Int_t tel)
58{
59 MSQLServer serv("sql.rc");
60 if (!serv.IsConnected())
61 {
62 cout << "ERROR - Connection to database failed." << endl;
63 return 0;
64 }
65
66 cout << "checkfileavail" << endl;
67 cout << "--------------" << endl;
68 cout << endl;
69 cout << "Connected to " << serv.GetName() << endl;
70 cout << endl;
71 cout << "Sequence: " << num << endl;
72 cout << "Telecope: " << tel << endl;
73 cout << endl;
74
75 // -------------------------------------------
76
77 TString query = "SELECT MIN( NOT ("
78 "ISNULL(fRawFileAvail) OR "
79 "ISNULL(fCCFileAvail) OR "
80 // "ISNULL(fCaCoFileAvail) OR "
81 // "ISNULL(fCaCoFileFound) OR "
82 "ISNULL(fTimingCorrection) OR "
83 "ISNULL(fCompmux) "
84 ")) "
85 "FROM RunProcessStatus "
86 "LEFT JOIN RunData USING (fTelescopeNumber,fRunNumber,fFileNumber) ";
87 query += Form("WHERE fSequenceFirst=%d AND fTelescopeNumber=%d", num, tel);
88
89 TSQLResult *res = serv.Query(query);
90 if (!res)
91 return 3;
92
93 if (res->GetRowCount()!=1)
94 {
95 cout << "ERROR - Unexpected number of returned rows (" << res->GetRowCount() << ")" << endl;
96 cout << query << endl;
97 delete res;
98 return 3;
99 }
100
101 TSQLRow *row = res->Next();
102
103 if (!row || !(*row)[0])
104 {
105 cout << "ERROR - Unexpected result." << endl;
106 cout << query << endl;
107 delete res;
108 return 3;
109 }
110
111 const Int_t rc = atoi((*row)[0]);
112
113 delete res;
114
115 return rc==1 ? 1 : 2;
116}
Note: See TracBrowser for help on using the repository browser.