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