1 |
mocchiut |
1.1 |
// |
2 |
|
|
// C/C++ headers |
3 |
|
|
// |
4 |
|
|
#include <iostream> |
5 |
|
|
#include <sstream> |
6 |
|
|
// |
7 |
|
|
// ROOT headers |
8 |
|
|
// |
9 |
|
|
#include <TString.h> |
10 |
|
|
#include <TSQLServer.h> |
11 |
|
|
#include <TFile.h> |
12 |
|
|
#include <TSystem.h> |
13 |
|
|
// |
14 |
|
|
// Detector's package headers |
15 |
|
|
// |
16 |
|
|
#include <GLTables.h> |
17 |
|
|
// |
18 |
|
|
using namespace std; |
19 |
|
|
// |
20 |
|
|
// |
21 |
|
|
// |
22 |
|
|
#include <DarthVaderVerl2.h> |
23 |
|
|
// |
24 |
|
|
// Usage subroutine |
25 |
|
|
// |
26 |
|
|
void r2d2usage(){ |
27 |
|
|
printf("\nUsage:\n"); |
28 |
|
|
printf("\n DarthVader [-h | --help] [--version] [-idRun ID_RUN] [-filename filename]\n"); |
29 |
|
|
printf("\n [-host host] [-user username] [-psw password] \n"); |
30 |
|
|
printf("\n --version print informations about compilation and exit\n"); |
31 |
|
|
printf("\n -h | --help print this help and exit \n"); |
32 |
|
|
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
33 |
|
|
printf("\n -idRun ID_RUN: ID number of the run \n"); |
34 |
|
|
printf("\n -filename output yoda filename \n"); |
35 |
|
|
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
36 |
|
|
printf("\n -user username for the DB [default = anonymous] \n"); |
37 |
|
|
printf("\n -psw password for the DB [default = \"\"]\n"); |
38 |
|
|
printf("\nExamples: \n"); |
39 |
|
|
printf("\n R2-D2 -idRun 1085 \n"); |
40 |
|
|
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
41 |
|
|
printf("\n R2-D2 -idRun 1085 -filename DW_050208_00900.root \n"); |
42 |
|
|
}; |
43 |
|
|
// |
44 |
|
|
// Here the main |
45 |
|
|
// |
46 |
|
|
int main(int numinp, char *inps[]){ |
47 |
|
|
// |
48 |
|
|
// Variables booking |
49 |
|
|
// |
50 |
|
|
TString message; |
51 |
|
|
int nul = 0; |
52 |
|
|
Int_t error = 0; |
53 |
|
|
// |
54 |
|
|
ULong64_t run = 0ULL; |
55 |
|
|
// |
56 |
|
|
TString filename = ""; |
57 |
|
|
// |
58 |
|
|
TSQLServer *dbc = 0; |
59 |
|
|
TString host = "mysql://localhost/pamelaprod"; |
60 |
|
|
TString user = "anonymous"; |
61 |
|
|
TString psw = ""; |
62 |
|
|
// |
63 |
|
|
// |
64 |
|
|
// Checking input parameters |
65 |
|
|
// |
66 |
|
|
Int_t i = 0; |
67 |
|
|
if ( numinp > 1 ){ |
68 |
|
|
while ( i < numinp ){ |
69 |
|
|
if ( !strcmp(inps[i],"--version") ){ |
70 |
|
|
DarthVaderInfo(true); |
71 |
|
|
exit(0); |
72 |
|
|
}; |
73 |
|
|
if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){ |
74 |
|
|
r2d2usage(); |
75 |
|
|
exit(0); |
76 |
|
|
}; |
77 |
|
|
if ( !strcmp(inps[i],"-idRun") ) { |
78 |
|
|
if ( numinp-1 < i+1 ) { |
79 |
|
|
r2d2usage(); |
80 |
|
|
exit(-3); |
81 |
|
|
}; |
82 |
|
|
char *pEnd; |
83 |
|
|
run = strtoull(inps[i+1],&pEnd,0); |
84 |
|
|
}; |
85 |
|
|
if ( !strcmp(inps[i],"-filename") ) { |
86 |
|
|
if ( numinp-1 < i+1 ){ |
87 |
|
|
r2d2usage(); |
88 |
|
|
exit(-3); |
89 |
|
|
}; |
90 |
|
|
filename = (TString)inps[i+1]; |
91 |
|
|
}; |
92 |
|
|
if ( !strcmp(inps[i],"-host") ) { |
93 |
|
|
if ( numinp-1 < i+1 ){ |
94 |
|
|
r2d2usage(); |
95 |
|
|
exit(-3); |
96 |
|
|
}; |
97 |
|
|
host = (TString)inps[i+1]; |
98 |
|
|
}; |
99 |
|
|
if ( !strcmp(inps[i],"-user") ) { |
100 |
|
|
if ( numinp-1 < i+1 ){ |
101 |
|
|
r2d2usage(); |
102 |
|
|
exit(-3); |
103 |
|
|
}; |
104 |
|
|
user = (TString)inps[i+1]; |
105 |
|
|
}; |
106 |
|
|
if ( !strcmp(inps[i],"-psw") ) { |
107 |
|
|
if ( numinp-1 < i+1 ){ |
108 |
|
|
r2d2usage(); |
109 |
|
|
exit(-3); |
110 |
|
|
}; |
111 |
|
|
psw = (TString)inps[i+1]; |
112 |
|
|
}; |
113 |
|
|
i++; |
114 |
|
|
}; |
115 |
|
|
// |
116 |
|
|
} else { |
117 |
|
|
// |
118 |
|
|
// no input parameters exit with error, we need at least the run id. |
119 |
|
|
// |
120 |
|
|
r2d2usage(); |
121 |
|
|
exit(-2); |
122 |
|
|
}; |
123 |
|
|
// |
124 |
|
|
// Connect to the DB |
125 |
|
|
// |
126 |
|
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
127 |
|
|
if( !dbc ) throw -2; |
128 |
|
|
// |
129 |
|
|
bool connect = dbc->IsConnected(); |
130 |
|
|
// |
131 |
|
|
if( !connect ){ |
132 |
|
|
printf(" Error, not connected to DB\n"); |
133 |
|
|
exit(-1); |
134 |
|
|
}; |
135 |
|
|
// |
136 |
|
|
GL_ROOT *glroot = new GL_ROOT(); |
137 |
|
|
GL_RUN *glrun = new GL_RUN(); |
138 |
|
|
// |
139 |
|
|
if ( run != 0ULL ){ |
140 |
|
|
error = glrun->Query_GL_RUN(run,dbc); |
141 |
|
|
error = glroot->Query_GL_ROOT(glrun->ID_REG_RUN,dbc); |
142 |
|
|
if ( error ){ |
143 |
|
|
printf(" Error querying the DB! \n"); |
144 |
|
|
exit(-4); |
145 |
|
|
}; |
146 |
|
|
printf("\n Run %llu belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
147 |
|
|
}; |
148 |
|
|
if ( strcmp(filename.Data(),"") ){ |
149 |
|
|
TSQLResult *pResult; |
150 |
|
|
TSQLRow *Row; |
151 |
|
|
int t; |
152 |
|
|
int r; |
153 |
|
|
stringstream myquery; |
154 |
|
|
// ---------------- |
155 |
|
|
Int_t ID = 0; |
156 |
|
|
Int_t ID_RAW = 0; |
157 |
|
|
// |
158 |
|
|
const char *rawpath; |
159 |
|
|
const char *rawname; |
160 |
|
|
// |
161 |
|
|
myquery.str(""); |
162 |
|
|
myquery << "select "; |
163 |
|
|
myquery << " ID"; |
164 |
|
|
myquery << ",ID_RAW"; |
165 |
|
|
myquery << ",PATH"; |
166 |
|
|
myquery << ",NAME"; |
167 |
|
|
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
168 |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
169 |
|
|
if(!pResult->GetRowCount()) return (-51); |
170 |
|
|
for( r=0; r < 1000; r++){ |
171 |
|
|
Row = pResult->Next(); |
172 |
|
|
if( Row == NULL ) break; |
173 |
|
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
174 |
|
|
if(t==0) ID = atoi(Row->GetField(t)); |
175 |
|
|
if(t==1) ID_RAW = atoi(Row->GetField(t)); |
176 |
|
|
}; |
177 |
|
|
}; |
178 |
|
|
delete pResult; |
179 |
|
|
printf("\n File %s contains the following runs: \n",filename.Data()); |
180 |
|
|
myquery.str(""); |
181 |
|
|
myquery << "select "; |
182 |
|
|
myquery << " ID"; |
183 |
|
|
myquery << " from GL_RUN where ID_REG_RUN=" << ID << ";"; |
184 |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
185 |
|
|
if(!pResult->GetRowCount()) return (-51); |
186 |
|
|
for( r=0; r < 1000; r++){ |
187 |
|
|
Row = pResult->Next(); |
188 |
|
|
if( Row == NULL ) break; |
189 |
|
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
190 |
|
|
if (t==0) printf(" => %i \n",atoi(Row->GetField(t))); |
191 |
|
|
}; |
192 |
|
|
}; |
193 |
|
|
delete pResult; |
194 |
|
|
myquery.str(""); |
195 |
|
|
myquery << "select "; |
196 |
|
|
myquery << " PATH,NAME"; |
197 |
|
|
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
198 |
|
|
pResult = dbc->Query(myquery.str().c_str()); |
199 |
|
|
if(!pResult->GetRowCount()) return (-51); |
200 |
|
|
for( r=0; r < 1000; r++){ |
201 |
|
|
Row = pResult->Next(); |
202 |
|
|
if( Row == NULL ) break; |
203 |
|
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
204 |
|
|
if(t==0) rawpath = Row->GetField(t); |
205 |
|
|
if(t==1) rawname = Row->GetField(t); |
206 |
|
|
}; |
207 |
|
|
}; |
208 |
|
|
delete pResult; |
209 |
|
|
printf(" and belongs to raw data file %s/%s \n",rawpath,rawname); |
210 |
|
|
}; |
211 |
|
|
// |
212 |
|
|
// Close the DB connection |
213 |
|
|
// |
214 |
|
|
if ( dbc ) dbc->Close(); |
215 |
|
|
// |
216 |
|
|
printf("\n"); |
217 |
|
|
// |
218 |
|
|
exit(0); |
219 |
|
|
} |