32 |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
printf("\n -v | --verbose be verbose [default: print nothing on STDOUT]\n"); |
33 |
printf("\n -idRun ID_RUN: ID number of the run \n"); |
printf("\n -idRun ID_RUN: ID number of the run \n"); |
34 |
printf("\n -filename output yoda filename \n"); |
printf("\n -filename output yoda filename \n"); |
35 |
printf("\n -host name for the host [default = mysql://localhost/pamelaprod]\n"); |
printf("\n -host name for the host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n"); |
36 |
printf("\n -user username for the DB [default = anonymous] \n"); |
printf("\n -user username for the DB [default = $PAM_DBUSER or \"anonymous\"] \n"); |
37 |
printf("\n -psw password for the DB [default = \"\"]\n"); |
printf("\n -psw password for the DB [default = $PAM_DBPSW or \"\"]\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"); |
55 |
TString message; |
TString message; |
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 |
// |
// |
64 |
TString user = "anonymous"; |
TString user = "anonymous"; |
65 |
TString psw = ""; |
TString psw = ""; |
66 |
// |
// |
67 |
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
68 |
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
69 |
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
70 |
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
71 |
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
72 |
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
73 |
|
// |
74 |
|
// printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); |
75 |
|
// |
76 |
|
TString tzone = "MSK"; |
77 |
|
TString tzone2 = "MSK"; |
78 |
|
TString runtime = "1970-01-01 00:00:00"; |
79 |
|
UInt_t dbti = 0; |
80 |
|
Bool_t convert = false; |
81 |
|
Bool_t ruti = false; |
82 |
|
// |
83 |
|
TSQLResult *pResult; |
84 |
|
TSQLRow *Row; |
85 |
|
int t; |
86 |
|
int r; |
87 |
|
stringstream myquery; |
88 |
// |
// |
89 |
// Checking input parameters |
// Checking input parameters |
90 |
// |
// |
104 |
r2d2usage(); |
r2d2usage(); |
105 |
exit(-3); |
exit(-3); |
106 |
}; |
}; |
107 |
char *pEnd; |
run = (UInt_t)atoll(inps[i+1]); |
|
run = strtoull(inps[i+1],&pEnd,0); |
|
108 |
}; |
}; |
109 |
if ( !strcmp(inps[i],"-filename") ) { |
if ( !strcmp(inps[i],"-filename") ) { |
110 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
134 |
}; |
}; |
135 |
psw = (TString)inps[i+1]; |
psw = (TString)inps[i+1]; |
136 |
}; |
}; |
137 |
|
// |
138 |
|
if ( !strcmp(inps[i],"-convert") ) { |
139 |
|
convert = true; |
140 |
|
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
141 |
|
if ( numinp < i+2 ){ |
142 |
|
r2d2usage(); |
143 |
|
throw -3; |
144 |
|
}; |
145 |
|
i += 2; |
146 |
|
while ( strcmp(inps[i],"]") ){ |
147 |
|
if ( !strcmp(inps[i],"-tzone") ) { |
148 |
|
if ( numinp-1 < i+1 ){ |
149 |
|
r2d2usage(); |
150 |
|
exit(-3); |
151 |
|
}; |
152 |
|
tzone = (TString)inps[i+1]; |
153 |
|
}; |
154 |
|
if ( !strcmp(inps[i],"-dbtime") ) { |
155 |
|
if ( numinp-1 < i+1 ){ |
156 |
|
r2d2usage(); |
157 |
|
exit(-3); |
158 |
|
}; |
159 |
|
dbti = (UInt_t)atoll(inps[i+1]); |
160 |
|
}; |
161 |
|
i++; |
162 |
|
if ( i > numinp-1 ){ |
163 |
|
r2d2usage(); |
164 |
|
throw -3; |
165 |
|
}; |
166 |
|
}; |
167 |
|
}; |
168 |
|
}; |
169 |
|
// |
170 |
|
if ( !strcmp(inps[i],"-runat") ) { |
171 |
|
ruti = true; |
172 |
|
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
173 |
|
if ( numinp < i+2 ){ |
174 |
|
r2d2usage(); |
175 |
|
throw -3; |
176 |
|
}; |
177 |
|
i += 2; |
178 |
|
while ( strcmp(inps[i],"]") ){ |
179 |
|
if ( !strcmp(inps[i],"-tzone") ) { |
180 |
|
if ( numinp-1 < i+1 ){ |
181 |
|
r2d2usage(); |
182 |
|
exit(-3); |
183 |
|
}; |
184 |
|
tzone2 = (TString)inps[i+1]; |
185 |
|
}; |
186 |
|
if ( !strcmp(inps[i],"-time") ) { |
187 |
|
if ( numinp-1 < i+1 ){ |
188 |
|
r2d2usage(); |
189 |
|
exit(-3); |
190 |
|
}; |
191 |
|
runtime = (TString)inps[i+1]; |
192 |
|
}; |
193 |
|
i++; |
194 |
|
if ( i > numinp-1 ){ |
195 |
|
r2d2usage(); |
196 |
|
throw -3; |
197 |
|
}; |
198 |
|
}; |
199 |
|
}; |
200 |
|
}; |
201 |
|
// |
202 |
i++; |
i++; |
203 |
}; |
}; |
204 |
// |
// |
224 |
// |
// |
225 |
GL_ROOT *glroot = new GL_ROOT(); |
GL_ROOT *glroot = new GL_ROOT(); |
226 |
GL_RUN *glrun = new GL_RUN(); |
GL_RUN *glrun = new GL_RUN(); |
227 |
|
GL_TIMESYNC *dbtime = new GL_TIMESYNC(); |
228 |
|
// |
229 |
|
// At which date correspond the DB time "dbti"? |
230 |
|
// |
231 |
|
if ( convert ){ |
232 |
|
printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone.Data(),dbti).Data(),tzone.Data()); |
233 |
|
}; |
234 |
|
// |
235 |
|
// Which run contains the date "runtime"? |
236 |
// |
// |
237 |
if ( run != 0ULL ){ |
if ( ruti ){ |
238 |
|
// |
239 |
|
TDatime *time = new TDatime(runtime.Data()); |
240 |
|
UInt_t dbti = time->Convert(); |
241 |
|
// |
242 |
|
TString thetime = dbtime->UnConvertTime(tzone2.Data(),dbti); |
243 |
|
// |
244 |
|
TDatime *time2 = new TDatime(thetime.Data()); |
245 |
|
UInt_t mytime = time2->Convert(); |
246 |
|
// |
247 |
|
myquery.str(""); |
248 |
|
myquery << "select "; |
249 |
|
myquery << " ID "; |
250 |
|
myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " |
251 |
|
<< " RUNTRAILER_TIME>=" << mytime << " ;"; |
252 |
|
// printf("myquery is %s \n",myquery.str().c_str()); |
253 |
|
pResult = dbc->Query(myquery.str().c_str()); |
254 |
|
for( r=0; r < 1000; r++){ |
255 |
|
Row = pResult->Next(); |
256 |
|
if ( !r && !Row ){ |
257 |
|
printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone2.Data(),mytime); |
258 |
|
}; |
259 |
|
if( Row == NULL ) break; |
260 |
|
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))); |
261 |
|
}; |
262 |
|
}; |
263 |
|
// |
264 |
|
// To which file the run "run" belongs? |
265 |
|
// |
266 |
|
if ( run != 0 ){ |
267 |
|
glrun->Clear(); |
268 |
error = glrun->Query_GL_RUN(run,dbc); |
error = glrun->Query_GL_RUN(run,dbc); |
269 |
error = glroot->Query_GL_ROOT(glrun->ID_REG_RUN,dbc); |
glroot->Clear(); |
270 |
|
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
271 |
if ( error ){ |
if ( error ){ |
272 |
printf(" Error querying the DB! \n"); |
printf(" Error querying the DB! \n"); |
273 |
exit(-4); |
exit(-4); |
274 |
}; |
}; |
275 |
printf("\n Run %llu belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
if ( !glrun->ID ){ |
276 |
|
printf("\n No run with ID=%u in the DB!\n",run); |
277 |
|
} else { |
278 |
|
printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
279 |
|
}; |
280 |
}; |
}; |
281 |
|
// |
282 |
|
// Which runs are contained in the file "filename"? |
283 |
|
// |
284 |
if ( strcmp(filename.Data(),"") ){ |
if ( strcmp(filename.Data(),"") ){ |
|
TSQLResult *pResult; |
|
|
TSQLRow *Row; |
|
|
int t; |
|
|
int r; |
|
|
stringstream myquery; |
|
285 |
// ---------------- |
// ---------------- |
286 |
Int_t ID = 0; |
Int_t ID = 0; |
287 |
Int_t ID_RAW = 0; |
Int_t ID_RAW = 0; |
297 |
myquery << ",NAME"; |
myquery << ",NAME"; |
298 |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
299 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
300 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
301 |
Row = pResult->Next(); |
Row = pResult->Next(); |
302 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
306 |
}; |
}; |
307 |
}; |
}; |
308 |
delete pResult; |
delete pResult; |
309 |
printf("\n File %s contains the following runs: \n",filename.Data()); |
if ( !ID && !ID_RAW ){ |
310 |
myquery.str(""); |
printf("\n No file with name %s in the DB!\n",filename.Data()); |
311 |
myquery << "select "; |
} else { |
312 |
myquery << " ID"; |
myquery.str(""); |
313 |
myquery << " from GL_RUN where ID_REG_RUN=" << ID << ";"; |
myquery << "select "; |
314 |
pResult = dbc->Query(myquery.str().c_str()); |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
315 |
if(!pResult->GetRowCount()) return (-51); |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
316 |
for( r=0; r < 1000; r++){ |
pResult = dbc->Query(myquery.str().c_str()); |
317 |
Row = pResult->Next(); |
for( r=0; r < 1000; r++){ |
318 |
if( Row == NULL ) break; |
Row = pResult->Next(); |
319 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
if ( !r && !Row ){ |
320 |
if (t==0) printf(" => %i \n",atoi(Row->GetField(t))); |
printf("\n No run associated to the file %s \n",filename.Data()); |
321 |
|
}; |
322 |
|
if( Row == NULL ) break; |
323 |
|
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
324 |
|
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()); |
325 |
}; |
}; |
326 |
}; |
delete pResult; |
327 |
delete pResult; |
myquery.str(""); |
328 |
myquery.str(""); |
myquery << "select "; |
329 |
myquery << "select "; |
myquery << " PATH,NAME"; |
330 |
myquery << " PATH,NAME"; |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
331 |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
pResult = dbc->Query(myquery.str().c_str()); |
332 |
pResult = dbc->Query(myquery.str().c_str()); |
for( r=0; r < 1000; r++){ |
333 |
if(!pResult->GetRowCount()) return (-51); |
Row = pResult->Next(); |
334 |
for( r=0; r < 1000; r++){ |
if( Row == NULL ) break; |
335 |
Row = pResult->Next(); |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
336 |
if( Row == NULL ) break; |
if(t==0) rawpath = Row->GetField(t); |
337 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
if(t==1) rawname = Row->GetField(t); |
338 |
if(t==0) rawpath = Row->GetField(t); |
}; |
|
if(t==1) rawname = Row->GetField(t); |
|
339 |
}; |
}; |
340 |
|
delete pResult; |
341 |
|
printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
342 |
}; |
}; |
|
delete pResult; |
|
|
printf(" and belongs to raw data file %s/%s \n",rawpath,rawname); |
|
343 |
}; |
}; |
344 |
// |
// |
345 |
// Close the DB connection |
// Close the DB connection |