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"); |
printf("\n -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n"); |
39 |
printf("\n convert the dbtime given in seconds (from the DB) to a string for\n"); |
printf("\n -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n"); |
40 |
printf("\n the given time zone (UTC,GMT,MSK,MSD,CET,CEST are accepted) \n"); |
printf("\n -runat time returns run number which contains the given date,\n"); |
41 |
printf("\n -runat \"yyyy-mm-dd hh:mm:ss\" \n"); |
printf("\n for time use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n"); |
|
printf("\n returns run number which contain the given date in MSK (if any)\n"); |
|
42 |
printf("\nExamples: \n"); |
printf("\nExamples: \n"); |
43 |
printf("\n R2-D2 -idRun 1085 \n"); |
printf("\n R2-D2 -idRun 1085 \n"); |
44 |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
printf("\n R2-D2 -filename DW_050208_00900.root \n"); |
62 |
TString host = "mysql://localhost/pamelaprod"; |
TString host = "mysql://localhost/pamelaprod"; |
63 |
TString user = "anonymous"; |
TString user = "anonymous"; |
64 |
TString psw = ""; |
TString psw = ""; |
65 |
|
// |
66 |
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
67 |
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
68 |
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
69 |
|
if ( !pamdbhost ) pamdbhost = ""; |
70 |
|
if ( !pamdbuser ) pamdbuser = ""; |
71 |
|
if ( !pamdbpsw ) pamdbpsw = ""; |
72 |
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
73 |
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
74 |
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
75 |
|
// |
76 |
|
// printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data()); |
77 |
|
// |
78 |
TString tzone = "MSK"; |
TString tzone = "MSK"; |
79 |
TString runtime = "1970-01-01 00:00:00"; |
TString runtime = "1970-01-01 00:00:00"; |
80 |
UInt_t dbti = 0; |
UInt_t dbti = 0; |
81 |
Bool_t convert = false; |
Bool_t convert = false; |
82 |
Bool_t ruti = false; |
Bool_t ruti = false; |
83 |
// |
// |
84 |
|
TSQLResult *pResult; |
85 |
|
TSQLRow *Row; |
86 |
|
int t; |
87 |
|
int r; |
88 |
|
stringstream myquery; |
89 |
// |
// |
90 |
// Checking input parameters |
// Checking input parameters |
91 |
// |
// |
136 |
psw = (TString)inps[i+1]; |
psw = (TString)inps[i+1]; |
137 |
}; |
}; |
138 |
// |
// |
139 |
if ( !strcmp(inps[i],"-runat") ) { |
if ( !strcmp(inps[i],"-tzone") ) { |
|
ruti = true; |
|
140 |
if ( numinp-1 < i+1 ){ |
if ( numinp-1 < i+1 ){ |
141 |
r2d2usage(); |
r2d2usage(); |
142 |
exit(-3); |
exit(-3); |
143 |
}; |
}; |
144 |
runtime = (TString)inps[i+1]; |
tzone = (TString)inps[i+1]; |
145 |
}; |
}; |
146 |
// |
// |
147 |
if ( !strcmp(inps[i],"-convert") ) { |
if ( !strcmp(inps[i],"-convert") ) { |
148 |
convert = true; |
convert = true; |
149 |
if ( numinp >= i+2 && !strcmp(inps[i+1],"[") ){ |
if ( numinp-1 < i+1 ){ |
150 |
if ( numinp < i+2 ){ |
r2d2usage(); |
151 |
r2d2usage(); |
exit(-3); |
|
throw -3; |
|
|
}; |
|
|
i += 2; |
|
|
while ( strcmp(inps[i],"]") ){ |
|
|
if ( !strcmp(inps[i],"-tzone") ) { |
|
|
if ( numinp-1 < i+1 ){ |
|
|
r2d2usage(); |
|
|
exit(-3); |
|
|
}; |
|
|
tzone = (TString)inps[i+1]; |
|
|
}; |
|
|
if ( !strcmp(inps[i],"-dbtime") ) { |
|
|
if ( numinp-1 < i+1 ){ |
|
|
r2d2usage(); |
|
|
exit(-3); |
|
|
}; |
|
|
dbti = (UInt_t)atoll(inps[i+1]); |
|
|
}; |
|
|
i++; |
|
|
if ( i > numinp-1 ){ |
|
|
r2d2usage(); |
|
|
throw -3; |
|
|
}; |
|
|
}; |
|
152 |
}; |
}; |
153 |
|
dbti = (UInt_t)atoll(inps[i+1]); |
154 |
|
}; |
155 |
|
// |
156 |
|
if ( !strcmp(inps[i],"-runat") ) { |
157 |
|
ruti = true; |
158 |
|
if ( numinp-1 < i+1 ){ |
159 |
|
r2d2usage(); |
160 |
|
exit(-3); |
161 |
|
}; |
162 |
|
runtime = (TString)inps[i+1]; |
163 |
}; |
}; |
164 |
// |
// |
165 |
i++; |
i++; |
192 |
// At which date correspond the DB time "dbti"? |
// At which date correspond the DB time "dbti"? |
193 |
// |
// |
194 |
if ( convert ){ |
if ( convert ){ |
195 |
printf("\n Time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone.Data(),dbti).Data(),tzone.Data()); |
printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data()); |
196 |
}; |
}; |
197 |
// |
// |
198 |
// Which run contains the date "runtime"? |
// Which run contains the date "runtime"? |
199 |
// |
// |
200 |
if ( ruti ){ |
if ( ruti ){ |
201 |
|
// |
202 |
|
TDatime *time = new TDatime(runtime.Data()); |
203 |
|
UInt_t dbti = time->Convert(); |
204 |
|
// |
205 |
|
TString thetime = dbtime->UnConvertTime(tzone,dbti); |
206 |
|
// |
207 |
|
TDatime *time2 = new TDatime(thetime.Data()); |
208 |
|
UInt_t mytime = time2->Convert(); |
209 |
|
// |
210 |
|
myquery.str(""); |
211 |
|
myquery << "select "; |
212 |
|
myquery << " ID "; |
213 |
|
myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND " |
214 |
|
<< " RUNTRAILER_TIME>=" << mytime << " ;"; |
215 |
|
// printf("myquery is %s \n",myquery.str().c_str()); |
216 |
|
pResult = dbc->Query(myquery.str().c_str()); |
217 |
|
for( r=0; r < 1000; r++){ |
218 |
|
Row = pResult->Next(); |
219 |
|
if ( !r && !Row ){ |
220 |
|
printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime); |
221 |
|
}; |
222 |
|
if( Row == NULL ) break; |
223 |
|
printf("\n Date %s %s (DB time %u ) is contained in run %u \n",runtime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0))); |
224 |
|
}; |
225 |
}; |
}; |
226 |
// |
// |
227 |
// To which file the run "run" belongs? |
// To which file the run "run" belongs? |
231 |
error = glrun->Query_GL_RUN(run,dbc); |
error = glrun->Query_GL_RUN(run,dbc); |
232 |
glroot->Clear(); |
glroot->Clear(); |
233 |
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc); |
234 |
if ( error ){ |
if ( !glrun->ID_ROOT_L0 ){ |
|
printf(" Error querying the DB! \n"); |
|
|
exit(-4); |
|
|
}; |
|
|
if ( !glrun->ID ){ |
|
235 |
printf("\n No run with ID=%u in the DB!\n",run); |
printf("\n No run with ID=%u in the DB!\n",run); |
236 |
} else { |
} else { |
237 |
|
if ( error ){ |
238 |
|
printf(" Error querying the DB! \n"); |
239 |
|
exit(-4); |
240 |
|
}; |
241 |
printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data()); |
242 |
}; |
}; |
243 |
}; |
}; |
245 |
// Which runs are contained in the file "filename"? |
// Which runs are contained in the file "filename"? |
246 |
// |
// |
247 |
if ( strcmp(filename.Data(),"") ){ |
if ( strcmp(filename.Data(),"") ){ |
|
TSQLResult *pResult; |
|
|
TSQLRow *Row; |
|
|
int t; |
|
|
int r; |
|
|
stringstream myquery; |
|
248 |
// ---------------- |
// ---------------- |
249 |
Int_t ID = 0; |
Int_t ID = 0; |
250 |
Int_t ID_RAW = 0; |
Int_t ID_RAW = 0; |
260 |
myquery << ",NAME"; |
myquery << ",NAME"; |
261 |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";"; |
262 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
263 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
264 |
Row = pResult->Next(); |
Row = pResult->Next(); |
265 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
277 |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME "; |
278 |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";"; |
279 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
280 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
281 |
Row = pResult->Next(); |
Row = pResult->Next(); |
282 |
if ( !r && !Row ){ |
if ( !r && !Row ){ |
283 |
printf(" No run associated to the file %s \n",filename.Data()); |
printf("\n No run associated to the file %s \n",filename.Data()); |
284 |
}; |
}; |
285 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
286 |
if ( !r ) printf("\n File %s contains the following runs: \n",filename.Data()); |
if ( !r ) printf("\n File %s contains the following runs: \n\n",filename.Data()); |
287 |
printf(" => %i -> Start at %s UTC end at %s UTC \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()); |
TString UTC="UTC"; |
288 |
|
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()); |
289 |
}; |
}; |
290 |
delete pResult; |
delete pResult; |
291 |
myquery.str(""); |
myquery.str(""); |
293 |
myquery << " PATH,NAME"; |
myquery << " PATH,NAME"; |
294 |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
myquery << " from GL_RAW where ID=" << ID_RAW << ";"; |
295 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
|
if(!pResult->GetRowCount()) return (-51); |
|
296 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
297 |
Row = pResult->Next(); |
Row = pResult->Next(); |
298 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
302 |
}; |
}; |
303 |
}; |
}; |
304 |
delete pResult; |
delete pResult; |
305 |
printf(" File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname); |
306 |
}; |
}; |
307 |
}; |
}; |
308 |
// |
// |