35 |
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
36 |
printf("\n -user username for the DB [default = anonymous] \n"); |
printf("\n -user username for the DB [default = anonymous] \n"); |
37 |
printf("\n -psw password for the DB [default = \"\"]\n"); |
printf("\n -psw password for the DB [default = \"\"]\n"); |
38 |
|
printf("\n -convert [ -tzone timezone -dbtime dbtime ] \n"); |
39 |
|
printf("\n convert the dbtime given in seconds (from the DB) to a string for\n"); |
40 |
|
printf("\n the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n"); |
41 |
|
printf("\n -runat [ -tzone timezone -time \"yyyy-mm-dd hh:mm:ss\" ] \n"); |
42 |
|
printf("\n returns run number which contains the given date in the given time zone \n"); |
43 |
printf("\nExamples: \n"); |
printf("\nExamples: \n"); |
44 |
printf("\n R2-D2 -idRun 1085 \n"); |
printf("\n R2-D2 -idRun 1085 \n"); |
45 |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
53 |
// Variables booking |
// Variables booking |
54 |
// |
// |
55 |
TString message; |
TString message; |
|
int nul = 0; |
|
56 |
Int_t error = 0; |
Int_t error = 0; |
57 |
// |
// |
58 |
ULong64_t run = 0ULL; |
UInt_t run = 0ULL; |
59 |
// |
// |
60 |
TString filename = ""; |
TString filename = ""; |
61 |
// |
// |
63 |
TString host = "mysql://localhost/pamelaprod"; |
TString host = "mysql://localhost/pamelaprod"; |
64 |
TString user = "anonymous"; |
TString user = "anonymous"; |
65 |
TString psw = ""; |
TString psw = ""; |
66 |
// |
TString tzone = "MSK"; |
67 |
|
TString tzone2 = "MSK"; |
68 |
|
TString runtime = "1970-01-01 00:00:00"; |
69 |
|
UInt_t dbti = 0; |
70 |
|
Bool_t convert = false; |
71 |
|
Bool_t ruti = false; |
72 |
|
// |
73 |
|
TSQLResult *pResult; |
74 |
|
TSQLRow *Row; |
75 |
|
int t; |
76 |
|
int r; |
77 |
|
stringstream myquery; |
78 |
// |
// |
79 |
// Checking input parameters |
// Checking input parameters |
80 |
// |
// |
94 |
r2d2usage(); |
r2d2usage(); |
95 |
exit(-3); |
exit(-3); |
96 |
}; |
}; |
97 |
char *pEnd; |
run = (UInt_t)atoll(inps[i+1]); |
|
run = strtoull(inps[i+1],&pEnd,0); |
|
98 |
}; |
}; |
99 |
if ( !strcmp(inps[i],"-filename") ) { |
if ( !strcmp(inps[i],"-filename") ) { |
100 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
124 |
}; |
}; |
125 |
psw = (TString)inps[i+1]; |
psw = (TString)inps[i+1]; |
126 |
}; |
}; |
127 |
|
// |
128 |
|
if ( !strcmp(inps[i],"-convert") ) { |
129 |
|
convert = true; |
130 |
|
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
131 |
|
if ( numinp < i+2 ){ |
132 |
|
r2d2usage(); |
133 |
|
throw -3; |
134 |
|
}; |
135 |
|
i += 2; |
136 |
|
while ( strcmp(inps[i],"]") ){ |
137 |
|
if ( !strcmp(inps[i],"-tzone") ) { |
138 |
|
if ( numinp-1 < i+1 ){ |
139 |
|
r2d2usage(); |
140 |
|
exit(-3); |
141 |
|
}; |
142 |
|
tzone = (TString)inps[i+1]; |
143 |
|
}; |
144 |
|
if ( !strcmp(inps[i],"-dbtime") ) { |
145 |
|
if ( numinp-1 < i+1 ){ |
146 |
|
r2d2usage(); |
147 |
|
exit(-3); |
148 |
|
}; |
149 |
|
dbti = (UInt_t)atoll(inps[i+1]); |
150 |
|
}; |
151 |
|
i++; |
152 |
|
if ( i > numinp-1 ){ |
153 |
|
r2d2usage(); |
154 |
|
throw -3; |
155 |
|
}; |
156 |
|
}; |
157 |
|
}; |
158 |
|
}; |
159 |
|
// |
160 |
|
if ( !strcmp(inps[i],"-runat") ) { |
161 |
|
ruti = true; |
162 |
|
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
163 |
|
if ( numinp < i+2 ){ |
164 |
|
r2d2usage(); |
165 |
|
throw -3; |
166 |
|
}; |
167 |
|
i += 2; |
168 |
|
while ( strcmp(inps[i],"]") ){ |
169 |
|
if ( !strcmp(inps[i],"-tzone") ) { |
170 |
|
if ( numinp-1 < i+1 ){ |
171 |
|
r2d2usage(); |
172 |
|
exit(-3); |
173 |
|
}; |
174 |
|
tzone2 = (TString)inps[i+1]; |
175 |
|
}; |
176 |
|
if ( !strcmp(inps[i],"-time") ) { |
177 |
|
if ( numinp-1 < i+1 ){ |
178 |
|
r2d2usage(); |
179 |
|
exit(-3); |
180 |
|
}; |
181 |
|
runtime = (TString)inps[i+1]; |
182 |
|
}; |
183 |
|
i++; |
184 |
|
if ( i > numinp-1 ){ |
185 |
|
r2d2usage(); |
186 |
|
throw -3; |
187 |
|
}; |
188 |
|
}; |
189 |
|
}; |
190 |
|
}; |
191 |
|
// |
192 |
i++; |
i++; |
193 |
}; |
}; |
194 |
// |
// |
214 |
// |
// |
215 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
216 |
GL_RUN *glrun = new GL_RUN(); |
GL_RUN *glrun = new GL_RUN(); |
217 |
|
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
218 |
|
// |
219 |
|
// At which date correspond the DB time "dbti"? |
220 |
|
// |
221 |
|
if ( convert ){ |
222 |
|
printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone.Data(),dbti).Data(),tzone.Data()); |
223 |
|
}; |
224 |
|
// |
225 |
|
// Which run contains the date "runtime"? |
226 |
|
// |
227 |
|
if ( ruti ){ |
228 |
|
// |
229 |
|
TDatime *time = new TDatime(runtime.Data()); |
230 |
|
UInt_t dbti = time->Convert(); |
231 |
|
// |
232 |
|
TString thetime = dbtime->UnConvertTime(tzone2.Data(),dbti); |
233 |
|
// |
234 |
|
TDatime *time2 = new TDatime(thetime.Data()); |
235 |
|
UInt_t mytime = time2->Convert(); |
236 |
|
// |
237 |
|
myquery.str(""); |
238 |
|
myquery << "select "; |
239 |
|
myquery << " ID "; |
240 |
|
myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " |
241 |
|
<< " RUNTRAILER_TIME>=" << mytime << " ;"; |
242 |
|
// printf("myquery is %s \n",myquery.str().c_str()); |
243 |
|
pResult = dbc->Query(myquery.str().c_str()); |
244 |
|
for( r=0; r < 1000; r++){ |
245 |
|
Row = pResult->Next(); |
246 |
|
if ( !r && !Row ){ |
247 |
|
printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone2.Data(),mytime); |
248 |
|
}; |
249 |
|
if( Row == NULL ) break; |
250 |
|
printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone2.Data(),mytime,(UInt_t)atoll(Row->GetField(0))); |
251 |
|
}; |
252 |
|
}; |
253 |
|
// |
254 |
|
// To which file the run "run" belongs? |
255 |
// |
// |
256 |
if ( run != 0ULL ){ |
if ( run != 0 ){ |
257 |
|
glrun->Clear(); |
258 |
error = glrun->Query_GL_RUN(run,dbc); |
error = glrun->Query_GL_RUN(run,dbc); |
259 |
error = glroot->Query_GL_ROOT(glrun->ID_REG_RUN,dbc); |
glroot->Clear(); |
260 |
|
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
261 |
if ( error ){ |
if ( error ){ |
262 |
printf(" Error querying the DB! \n"); |
printf(" Error querying the DB! \n"); |
263 |
exit(-4); |
exit(-4); |
264 |
}; |
}; |
265 |
printf("\n Run %llu belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
if ( !glrun->ID ){ |
266 |
|
printf("\n No run with ID=%u in the DB!\n",run); |
267 |
|
} else { |
268 |
|
printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
269 |
|
}; |
270 |
}; |
}; |
271 |
|
// |
272 |
|
// Which runs are contained in the file "filename"? |
273 |
|
// |
274 |
if ( strcmp(filename.Data(),"") ){ |
if ( strcmp(filename.Data(),"") ){ |
|
TSQLResult *pResult; |
|
|
TSQLRow *Row; |
|
|
int t; |
|
|
int r; |
|
|
stringstream myquery; |
|
275 |
// ---------------- |
// ---------------- |
276 |
Int_t ID = 0; |
Int_t ID = 0; |
277 |
Int_t ID_RAW = 0; |
Int_t ID_RAW = 0; |
278 |
// |
// |
279 |
const char *rawpath; |
const char *rawpath = ""; |
280 |
const char *rawname; |
const char *rawname = ""; |
281 |
// |
// |
282 |
myquery.str(""); |
myquery.str(""); |
283 |
myquery << "select "; |
myquery << "select "; |
287 |
myquery << ",NAME"; |
myquery << ",NAME"; |
288 |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
289 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
290 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
291 |
Row = pResult->Next(); |
Row = pResult->Next(); |
292 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
296 |
}; |
}; |
297 |
}; |
}; |
298 |
delete pResult; |
delete pResult; |
299 |
printf("\n File %s contains the following runs: \n",filename.Data()); |
if ( !ID && !ID_RAW ){ |
300 |
myquery.str(""); |
printf("\n No file with name %s in the DB!\n",filename.Data()); |
301 |
myquery << "select "; |
} else { |
302 |
myquery << " ID"; |
myquery.str(""); |
303 |
myquery << " from GL_RUN where ID_REG_RUN=" << ID << ";"; |
myquery << "select "; |
304 |
pResult = dbc->Query(myquery.str().c_str()); |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
305 |
if(!pResult->GetRowCount()) return (-51); |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
306 |
for( r=0; r < 1000; r++){ |
pResult = dbc->Query(myquery.str().c_str()); |
307 |
Row = pResult->Next(); |
for( r=0; r < 1000; r++){ |
308 |
if( Row == NULL ) break; |
Row = pResult->Next(); |
309 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
if ( !r && !Row ){ |
310 |
if (t==0) printf(" => %i \n",atoi(Row->GetField(t))); |
printf("\n No run associated to the file %s \n",filename.Data()); |
311 |
|
}; |
312 |
|
if( Row == NULL ) break; |
313 |
|
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
314 |
|
printf(" => ID = %i _-_-_ the run started at %s UTC ended at %s UTC \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime("UTC",(UInt_t)atoll(Row->GetField(1))).Data(),dbtime->ConvertTime("UTC",(UInt_t)atoll(Row->GetField(2))).Data()); |
315 |
}; |
}; |
316 |
}; |
delete pResult; |
317 |
delete pResult; |
myquery.str(""); |
318 |
myquery.str(""); |
myquery << "select "; |
319 |
myquery << "select "; |
myquery << " PATH,NAME"; |
320 |
myquery << " PATH,NAME"; |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
321 |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
pResult = dbc->Query(myquery.str().c_str()); |
322 |
pResult = dbc->Query(myquery.str().c_str()); |
for( r=0; r < 1000; r++){ |
323 |
if(!pResult->GetRowCount()) return (-51); |
Row = pResult->Next(); |
324 |
for( r=0; r < 1000; r++){ |
if( Row == NULL ) break; |
325 |
Row = pResult->Next(); |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
326 |
if( Row == NULL ) break; |
if(t==0) rawpath = Row->GetField(t); |
327 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
if(t==1) rawname = Row->GetField(t); |
328 |
if(t==0) rawpath = Row->GetField(t); |
}; |
|
if(t==1) rawname = Row->GetField(t); |
|
329 |
}; |
}; |
330 |
|
delete pResult; |
331 |
|
printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
332 |
}; |
}; |
|
delete pResult; |
|
|
printf(" and belongs to raw data file %s/%s \n",rawpath,rawname); |
|
333 |
}; |
}; |
334 |
// |
// |
335 |
// Close the DB connection |
// Close the DB connection |