/[PAMELA software]/YodaProfiler/src/R2-D2.cpp
ViewVC logotype

Contents of /YodaProfiler/src/R2-D2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations) (download)
Tue Mar 4 15:21:56 2008 UTC (16 years, 8 months ago) by mocchiut
Branch: MAIN
CVS Tags: v5r00, v5r01, HEAD
Changes since 1.14: +32 -5 lines
More changes to R2-D2

1 //
2 // C/C++ headers
3 //
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <sstream>
8 //
9 // ROOT headers
10 //
11 #include <TString.h>
12 #include <TTimeStamp.h>
13 #include <TSQLServer.h>
14 #include <TFile.h>
15 #include <TSystem.h>
16 //
17 // Detector's package headers
18 //
19 #include <GLTables.h>
20 //
21 using namespace std;
22 //
23 //
24 //
25 #include <YodaProfilerVerl2.h>
26 //
27 // Usage subroutine
28 //
29 void r2d2usage(){
30 printf("\nUsage:\n");
31 printf("\n R2-D2 [ options ]\n");
32 printf("\n Options are:\n\n");
33 printf(" --version print informations about compilation and exit\n");
34 printf(" -h | --help print this help and exit \n");
35 printf(" -v | --verbose be verbose [default]\n");
36 printf(" -n | --neat used with '-filename' returns only the run ID number\n");
37 printf(" -idRun run ID_RUN: ID number of the run \n");
38 printf(" -filename file output yoda filename \n");
39 printf(" -l2filename file output amidala filename \n");
40 printf(" -host name of the DB host [default = $PAM_DBHOST or mysql://localhost/pamelaprod]\n");
41 printf(" -user username for the DB connection [default = $PAM_DBUSER or \"anonymous\"] \n");
42 printf(" -psw password for the DB connection [default = $PAM_DBPSW or \"\"]\n");
43 printf(" -deps file shows dependencies of the given file\n");
44 printf(" -splitat file shows dependenices of the given file and the following files (given by -nsplit)\n");
45 printf(" -nsplit number number of files to be shown by -splitat [default 20]\n");
46 printf(" -tzone timezone the time zone: UTC,GMT,MSK,MSD,CET,CEST are accepted \n");
47 printf(" -convert dbtime convert the dbtime given in seconds (from the DB) to a string\n");
48 printf(" -runat date returns run number which contains the given date,\n");
49 printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
50 printf(" -runatDB time returns run number which contains the given DB time\n");
51 printf(" -tsfile file yoda filename for the time sync (to be used with -obt)\n");
52 printf(" -obt OBT OBT in ms returns a date (to be used with -tsfile)\n");
53 printf(" -getRTime OBT OBT in ms returns Resurs time (to be used with -tsfile)\n");
54 printf(" -dumpTLEfor date save into file tle.txt the TLE for the given date,\n");
55 printf(" for date use the SQL format \"yyyy-mm-dd hh:mm:ss\" \n");
56 printf("\nExamples: \n");
57 printf(" R2-D2 -idRun 1085 \n");
58 printf(" R2-D2 -filename DW_050208_00900.root \n");
59 printf(" R2-D2 -idRun 1085 -filename DW_050208_00900.root \n\n");
60 };
61 //
62 // Here the main
63 //
64 int main(int numinp, char *inps[]){
65 //
66 // Variables booking
67 //
68 TString message;
69 Int_t error = 0;
70 //
71 UInt_t run = 0ULL;
72 //
73 TString filename = "";
74 TString l2filename = "";
75 TString splitat = "";
76 UInt_t nsplit = 20;
77 //
78 TSQLServer *dbc = 0;
79 TString host = "mysql://localhost/pamelaprod";
80 TString user = "anonymous";
81 TString psw = "";
82 //
83 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
84 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
85 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
86 if ( !pamdbhost ) pamdbhost = "";
87 if ( !pamdbuser ) pamdbuser = "";
88 if ( !pamdbpsw ) pamdbpsw = "";
89 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
90 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
91 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
92 //
93 // printf(" host %s user %s psw %s \n",host.Data(),user.Data(),psw.Data());
94 //
95 TString tzone = "UTC";
96 TString runtime = "1970-01-01 00:00:00";
97 TString tletime = "1970-01-01 00:00:00";
98 UInt_t dbti = 0;
99 Bool_t convert = false;
100 Bool_t convres = false;
101 Bool_t ruti = false;
102 Bool_t dtle = false;
103 Bool_t ruti2 = false;
104 Bool_t convobt = false;
105 Bool_t convobtts = false;
106 Bool_t neat = false;
107 //
108 UInt_t runtime2 = 0;
109 UInt_t obt = 0;
110 UInt_t res = 0;
111 TString tsfile = "";
112 //
113 TSQLResult *pResult;
114 TSQLRow *Row;
115 TSQLResult *pResult2 = 0;
116 TSQLRow *Row2;
117 int t;
118 int r;
119 stringstream myquery;
120 //
121 // Checking input parameters
122 //
123 Int_t i = 0;
124 if ( numinp > 1 ){
125 while ( i < numinp ){
126 if ( !strcmp(inps[i],"--version") ){
127 YodaProfilerInfo(true);
128 exit(0);
129 };
130 if ( !strcmp(inps[i],"-h") || !strcmp(inps[i],"--help") ){
131 r2d2usage();
132 exit(0);
133 };
134 if ( !strcmp(inps[i],"-n") || !strcmp(inps[i],"--neat") ){
135 neat = true;
136 };
137 if ( !strcmp(inps[i],"-idRun") ) {
138 if ( numinp-1 < i+1 ) {
139 r2d2usage();
140 exit(-3);
141 };
142 run = (UInt_t)atoll(inps[i+1]);
143 };
144 if ( !strcmp(inps[i],"-filename") ) {
145 if ( numinp-1 < i+1 ){
146 r2d2usage();
147 exit(-3);
148 };
149 filename = (TString)inps[i+1];
150 };
151 if ( !strcmp(inps[i],"-splitat") ) {
152 if ( numinp-1 < i+1 ){
153 r2d2usage();
154 exit(-3);
155 };
156 splitat = (TString)inps[i+1];
157 };
158 //
159 if ( !strcmp(inps[i],"-nsplit") ) {
160 if ( numinp-1 < i+1 ){
161 r2d2usage();
162 exit(-3);
163 };
164 nsplit = (UInt_t)atoll(inps[i+1]);
165 };
166 if ( !strcmp(inps[i],"-deps") ) {
167 if ( numinp-1 < i+1 ){
168 r2d2usage();
169 exit(-3);
170 };
171 nsplit = 1;
172 splitat = (TString)inps[i+1];
173 };
174 if ( !strcmp(inps[i],"-l2filename") ) {
175 if ( numinp-1 < i+1 ){
176 r2d2usage();
177 exit(-3);
178 };
179 l2filename = (TString)inps[i+1];
180 };
181 if ( !strcmp(inps[i],"-host") ) {
182 if ( numinp-1 < i+1 ){
183 r2d2usage();
184 exit(-3);
185 };
186 host = (TString)inps[i+1];
187 };
188 if ( !strcmp(inps[i],"-user") ) {
189 if ( numinp-1 < i+1 ){
190 r2d2usage();
191 exit(-3);
192 };
193 user = (TString)inps[i+1];
194 };
195 if ( !strcmp(inps[i],"-psw") ) {
196 if ( numinp-1 < i+1 ){
197 r2d2usage();
198 exit(-3);
199 };
200 psw = (TString)inps[i+1];
201 };
202 //
203 if ( !strcmp(inps[i],"-tsfile") ) {
204 convobtts = true;
205 if ( numinp-1 < i+1 ){
206 r2d2usage();
207 exit(-3);
208 };
209 tsfile = (TString)inps[i+1];
210 };
211 //
212 if ( !strcmp(inps[i],"-obt") ) {
213 convobt = true;
214 if ( numinp-1 < i+1 ){
215 r2d2usage();
216 exit(-3);
217 };
218 obt = (UInt_t)atoll(inps[i+1]);
219 };
220 //
221 if ( !strcmp(inps[i],"-getRTime") ) {
222 convres = true;
223 if ( numinp-1 < i+1 ){
224 r2d2usage();
225 exit(-3);
226 };
227 res = (UInt_t)atoll(inps[i+1]);
228 };
229 //
230 //
231 if ( !strcmp(inps[i],"-tzone") ) {
232 if ( numinp-1 < i+1 ){
233 r2d2usage();
234 exit(-3);
235 };
236 tzone = (TString)inps[i+1];
237 };
238 //
239 if ( !strcmp(inps[i],"-convert") ) {
240 convert = true;
241 if ( numinp-1 < i+1 ){
242 r2d2usage();
243 exit(-3);
244 };
245 dbti = (UInt_t)atoll(inps[i+1]);
246 };
247 //
248 if ( !strcmp(inps[i],"-runat") ) {
249 ruti = true;
250 if ( numinp-1 < i+1 ){
251 r2d2usage();
252 exit(-3);
253 };
254 runtime = (TString)inps[i+1];
255 };
256 //
257 if ( !strcmp(inps[i],"-dumpTLEfor") ) {
258 dtle = true;
259 if ( numinp-1 < i+1 ){
260 r2d2usage();
261 exit(-3);
262 };
263 tletime = (TString)inps[i+1];
264 };
265 //
266 //
267 if ( !strcmp(inps[i],"-runatDB") ) {
268 ruti2 = true;
269 if ( numinp-1 < i+1 ){
270 r2d2usage();
271 exit(-3);
272 };
273 runtime2 = (UInt_t)atoll(inps[i+1]);
274 };
275 //
276 i++;
277 };
278 //
279 } else {
280 //
281 // no input parameters exit with error, we need at least the run id.
282 //
283 r2d2usage();
284 exit(-2);
285 };
286 //
287 // Connect to the DB
288 //
289 dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
290 if( !dbc ) throw -2;
291 //
292 bool connect = dbc->IsConnected();
293 //
294 if( !connect ){
295 printf(" Error, not connected to DB\n");
296 exit(-1);
297 };
298 //
299 myquery.str("");
300 myquery << "SET time_zone='+0:00'";
301 dbc->Query(myquery.str().c_str());
302 //
303 GL_ROOT *glroot = new GL_ROOT();
304 GL_RUN *glrun = new GL_RUN();
305 GL_TIMESYNC *dbtime = new GL_TIMESYNC();
306 UInt_t nr = 0;
307 UInt_t rlist[500];
308 //
309 // At which date correspond the DB time "dbti"?
310 //
311 if ( convert ){
312 printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data());
313 };
314 //
315 // convert OBT to date
316 //
317 if ( convobt && convobtts ){
318 UInt_t id = 0;
319 myquery.str("");
320 myquery << "select ";
321 myquery << " ID";
322 myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";";
323 pResult = dbc->Query(myquery.str().c_str());
324 if ( pResult ){
325 Row = pResult->Next();
326 if ( Row ){
327 id = (UInt_t)atoll(Row->GetField(0));
328 delete pResult;
329 GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
330 UInt_t abtime = ctime->DBabsTime(obt);
331 TString thetime = dbtime->ConvertTime(tzone,abtime);
332 printf("\n OBT %u in the file %s corresponds to DBtime %u and date %s %s \n",obt,tsfile.Data(),abtime,thetime.Data(),tzone.Data());
333 delete ctime;
334 };
335 };
336 };
337 if ( (convobt && !convobtts) ){
338 printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n");
339 };
340 //
341 // convert OBT to Resurs seconds
342 //
343 if ( convres && convobtts ){
344 UInt_t id = 0;
345 myquery.str("");
346 myquery << "select ";
347 myquery << " ID";
348 myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";";
349 pResult = dbc->Query(myquery.str().c_str());
350 if ( pResult ){
351 Row = pResult->Next();
352 if ( Row ){
353 id = (UInt_t)atoll(Row->GetField(0));
354 delete pResult;
355 GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
356 UInt_t restime = ctime->ResursTime(res);
357 //UInt_t abtime = ctime->DBabsTime(obt);
358 //
359 // TString thetime = dbtime->ConvertTime(tzone,abtime);
360 printf("\n OBT %u in the file %s corresponds to Resurs time %u \n",res,tsfile.Data(),restime);
361 delete ctime;
362 };
363 };
364 };
365 if ( (convres && !convobtts) ){
366 printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n");
367 };
368 //
369 // Which run contains the date "runtime"?
370 //
371 if ( ruti ){
372 //
373 TDatime ti = TDatime(runtime.Data());
374 //
375 TTimeStamp *time = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0);
376 //
377 UInt_t dbti = time->GetSec();
378 //
379 TString thetime = dbtime->UnConvertTime(tzone,dbti);
380 //
381 ti = TDatime(thetime.Data());
382 TTimeStamp *time2 = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0);
383 //
384 UInt_t mytime = time2->GetSec();
385 //
386 Bool_t found = false;
387 //
388 myquery.str("");
389 myquery << "select ";
390 myquery << " ID ";
391 myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
392 << " RUNTRAILER_TIME>=" << mytime << " ;";
393 // printf("myquery is %s \n",myquery.str().c_str());
394 pResult = dbc->Query(myquery.str().c_str());
395 for( r=0; r < 1000; r++){
396 Row = pResult->Next();
397 if( Row == NULL ) break;
398 found = true;
399 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)));
400 };
401 myquery.str("");
402 myquery << "select ";
403 myquery << " ID ";
404 myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND RUNHEADER_TIME<=" << mytime << " AND "
405 << " RUNTRAILER_TIME>=" << mytime << " ;";
406 // printf("myquery is %s \n",myquery.str().c_str());
407 pResult = dbc->Query(myquery.str().c_str());
408 for( r=0; r < 1000; r++){
409 Row = pResult->Next();
410 if( Row == NULL ) break;
411 printf("\n Date %s %s (DB time %u ) is contained in run %u in the GL_RUN_TRASH table \n",runtime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0)));
412 found = true;
413 };
414 //
415 if ( !found ){
416 printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime);
417 };
418 //
419 };
420 //
421 // Which tle must be used for the date "tletime"?
422 //
423 if ( dtle ){
424 //
425 //
426 TDatime ti = TDatime(tletime.Data());
427 //
428 TTimeStamp *time = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0);
429 //
430 UInt_t dbti = time->GetSec();
431 //
432 TString thetime = dbtime->UnConvertTime(tzone,dbti);
433 //
434 ti = TDatime(thetime.Data());
435 TTimeStamp *time2 = new TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0);
436 //
437 UInt_t mytime = time2->GetSec();
438 //
439 myquery.str("");
440 myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsString("s") << "' ORDER BY FROM_TIME DESC LIMIT 1;";
441 // myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;";
442 // printf("myquery is %s \n",myquery.str().c_str());
443 pResult = dbc->Query(myquery.str().c_str());
444 Row = pResult->Next();
445 if ( !Row ){
446 printf("\n No TLE in the DB for date %s %s (DB time %u )\n",tletime.Data(),tzone.Data(),mytime);
447 };
448 printf("\n Date %s %s (DB time %u ) is contained in TLE %u \n",tletime.Data(),tzone.Data(),mytime,(UInt_t)atoll(Row->GetField(0)));
449 printf("\n%s\n",Row->GetField(1));
450 printf("%s\n",Row->GetField(2));
451 printf("%s\n",Row->GetField(3));
452 //
453 FILE *tlefile;
454 tlefile = fopen("tle.txt","w");
455 fprintf(tlefile,"%s\n",Row->GetField(1));
456 fprintf(tlefile,"%s\n",Row->GetField(2));
457 fprintf(tlefile,"%s\n",Row->GetField(3));
458 fclose (tlefile);
459 //
460 printf("\n TLE has been dumped in file tle.txt \n");
461 };
462 //
463 // Which run contains the dbtime "runtime2"?
464 //
465 if ( ruti2 ){
466 //
467 UInt_t mytime = runtime2;
468 //
469 Bool_t found = false;
470 myquery.str("");
471 myquery << "select ";
472 myquery << " ID ";
473 myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
474 << " RUNTRAILER_TIME>=" << mytime << " ;";
475 // printf("myquery is %s \n",myquery.str().c_str());
476 pResult = dbc->Query(myquery.str().c_str());
477 for( r=0; r < 1000; r++){
478 Row = pResult->Next();
479 if( Row == NULL ) break;
480 printf("\n DB time %u is contained in run %u \n",mytime,(UInt_t)atoll(Row->GetField(0)));
481 found = true;
482 };
483 //
484 myquery.str("");
485 myquery << "select ";
486 myquery << " ID ";
487 myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND RUNHEADER_TIME<=" << mytime << " AND "
488 << " RUNTRAILER_TIME>=" << mytime << " ;";
489 // printf("myquery is %s \n",myquery.str().c_str());
490 pResult = dbc->Query(myquery.str().c_str());
491 for( r=0; r < 1000; r++){
492 Row = pResult->Next();
493 if( Row == NULL ) break;
494 printf("\n DB time %u is contained in run %u in the GL_RUN_TRASH table \n",mytime,(UInt_t)atoll(Row->GetField(0)));
495 found = true;
496 };
497 //
498 if ( !found ){
499 printf("\n No run contains DB time %u \n",mytime);
500 };
501 //
502 };
503 //
504 // To which file the run "run" belongs?
505 //
506 if ( run != 0 ){
507 Bool_t found = false;
508 glrun->Clear();
509 error = glrun->Query_GL_RUN(run,dbc);
510 glroot->Clear();
511 error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc);
512 if ( glrun->ID_ROOT_L0 ){
513 if ( error ){
514 printf(" Error querying the DB! \n");
515 exit(-4);
516 };
517 printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
518 //filename = glroot->NAME;
519 found = true;
520 };
521 //
522 myquery.str("");
523 myquery << "select ";
524 myquery << " ID,FILENAMEL0,FILENAMEL2 ";
525 myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND ID=" << run << "; ";
526 pResult = dbc->Query(myquery.str().c_str());
527 for( r=0; r < 1000; r++){
528 Row = pResult->Next();
529 if( Row == NULL ) break;
530 printf("\n RUN %u has been deleted and now is contained in the GL_RUN_TRASH table \n",run);
531 printf("\n RUN %u belonged to L0 file %s and L2 file %s \n",run,Row->GetField(1),Row->GetField(2));
532 found = true;
533 };
534 //
535 if ( !found ) printf("\n No run with ID=%u in the DB!\n",run);
536 };
537 //
538 // Which runs are contained in the file "filename"?
539 //
540 if ( strcmp(filename.Data(),"") ){
541 // ----------------
542 Bool_t found = false;
543 Int_t ID = 0;
544 Int_t ID_RAW = 0;
545 //
546 const char *rawpath = "";
547 const char *rawname = "";
548 //
549 myquery.str("");
550 myquery << "select ";
551 myquery << " ID";
552 myquery << ",ID_RAW";
553 myquery << ",PATH";
554 myquery << ",NAME";
555 myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";
556 pResult = dbc->Query(myquery.str().c_str());
557 for( r=0; r < 1000; r++){
558 Row = pResult->Next();
559 if( Row == NULL ) break;
560 for( t = 0; t < pResult->GetFieldCount(); t++){
561 if(t==0) ID = atoi(Row->GetField(t));
562 if(t==1) ID_RAW = atoi(Row->GetField(t));
563 };
564 };
565 delete pResult;
566 if ( !ID && !ID_RAW ){
567 if ( !neat ) printf("\n No file with name %s in the DB!\n",filename.Data());
568 } else {
569 myquery.str("");
570 myquery << "select ";
571 myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS ";
572 myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";
573 pResult = dbc->Query(myquery.str().c_str());
574 for( r=0; r < 1000; r++){
575 Row = pResult->Next();
576 if( Row == NULL ) break;
577 found = true;
578 if ( !r && !neat ) printf("\n File %s contains the following runs: \n\n",filename.Data());
579 TString UTC=tzone.Data();
580 if ( !neat ) printf(" => ID = %u --> the run started at %s %s ended at %s %s NEV = %u \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(1))).Data(),tzone.Data(),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(2))).Data(),tzone.Data(),(UInt_t)atoll(Row->GetField(3)));
581 if ( neat ) printf("%u\n",(UInt_t)atoll(Row->GetField(0)));
582 };
583 delete pResult;
584 myquery.str("");
585 myquery << "select ";
586 myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
587 myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND FILENAMEL0='" << filename.Data() << "' ;";
588 pResult = dbc->Query(myquery.str().c_str());
589 for( r=0; r < 1000; r++){
590 Row = pResult->Next();
591 if( Row == NULL ) break;
592 if ( !r && !neat ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data());
593 TString UTC=tzone.Data();
594 if ( !neat ) printf(" => ID = %i --> the run started at %s %s ended at %s %s \n\n",(UInt_t)atoll(Row->GetField(0)),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(1))).Data(),tzone.Data(),dbtime->ConvertTime(UTC,(UInt_t)atoll(Row->GetField(2))).Data(),tzone.Data());
595 };
596 //
597 if ( !found ){
598 if ( !neat ) printf("\n No run associated to the file %s \n",filename.Data());
599 };
600 myquery.str("");
601 myquery << "select ";
602 myquery << " PATH,NAME";
603 myquery << " from GL_RAW where ID=" << ID_RAW << ";";
604 pResult = dbc->Query(myquery.str().c_str());
605 for( r=0; r < 1000; r++){
606 Row = pResult->Next();
607 if( Row == NULL ) break;
608 for( t = 0; t < pResult->GetFieldCount(); t++){
609 if(t==0) rawpath = Row->GetField(t);
610 if(t==1) rawname = Row->GetField(t);
611 };
612 };
613 delete pResult;
614 if ( !neat ) printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);
615 };
616 };
617 //
618 // Which runs are contained in the file "l2filename"?
619 //
620 if ( strcmp(l2filename.Data(),"") ){
621 // ----------------
622 Bool_t found = false;
623 Int_t ID = 0;
624 Int_t ID_RAW = 0;
625 //
626 const char *rawpath = "";
627 const char *rawname = "";
628 //
629 myquery.str("");
630 myquery << "select ";
631 myquery << " ID";
632 myquery << ",ID_RAW";
633 myquery << ",PATH";
634 myquery << ",NAME";
635 myquery << " from GL_ROOT where NAME=\"" << l2filename.Data() << "\" order by INSERT_TIME desc limit 1;";
636 pResult = dbc->Query(myquery.str().c_str());
637 for( r=0; r < 1000; r++){
638 Row = pResult->Next();
639 if( Row == NULL ) break;
640 for( t = 0; t < pResult->GetFieldCount(); t++){
641 if(t==0) ID = atoi(Row->GetField(t));
642 if(t==1) ID_RAW = atoi(Row->GetField(t));
643 };
644 };
645 delete pResult;
646 if ( !ID ){
647 printf("\n No file with name %s in the DB!\n",l2filename.Data());
648 } else {
649 nr = 0;
650 rlist[0] = 0;
651 myquery.str("");
652 myquery << "select ";
653 myquery << " ID,ID_ROOT_L0 ";
654 myquery << " from GL_RUN where ID_ROOT_L2=" << ID << ";";
655 pResult = dbc->Query(myquery.str().c_str());
656 for( r=0; r < pResult->GetRowCount(); r++){
657 Row = pResult->Next();
658 if( Row == NULL ) break;
659 found = true;
660 if ( !r ) printf("\n File %s contains the following runs: \n\n",l2filename.Data());
661 printf(" %u ",(UInt_t)atoll(Row->GetField(0)));
662 if ( r < (pResult->GetRowCount()-1) ){
663 printf("-");
664 } else {
665 printf("\n\n");
666 };
667 if ( (UInt_t)atoll(Row->GetField(1)) != rlist[nr] ){
668 nr++;
669 rlist[nr] = (UInt_t)atoll(Row->GetField(1));
670 };
671 };
672 delete pResult;
673 //
674 printf("\n File %s contains runs from L0 files: \n\n",l2filename.Data());
675 for (UInt_t l=1; l<nr+1; l++){
676 myquery.str("");
677 myquery << "select ";
678 myquery << " PATH,NAME";
679 myquery << " from GL_ROOT where ID=" << rlist[l] << ";";
680 pResult = dbc->Query(myquery.str().c_str());
681 for( r=0; r < pResult->GetRowCount(); r++){
682 Row = pResult->Next();
683 if( Row == NULL ) break;
684 for( t = 0; t < pResult->GetFieldCount(); t++){
685 if(t==0) rawpath = Row->GetField(t);
686 if(t==1) rawname = Row->GetField(t);
687 };
688 printf(" %s/%s \n",rawpath,rawname);
689 };
690 delete pResult;
691 };
692 };
693 };
694 //
695 //
696 // Show relationship between files around file "splitat"
697 //
698 if ( strcmp(splitat.Data(),"") ){
699 // ----------------
700 Int_t ID = 0;
701 Int_t IDR = 0;
702 TString PATH;
703 TString NAME;
704 UInt_t atime1 = 0;
705 UInt_t atime2 = 0;
706 UInt_t minid = 0;
707 UInt_t maxid = 0;
708 //
709 myquery.str("");
710 myquery << " select ID,PATH,NAME from GL_ROOT where NAME>=\"" << splitat.Data() << "\" order by NAME asc limit " << nsplit << ";";
711 // printf(" myquery is %s \n",myquery.str().c_str());
712 pResult = dbc->Query(myquery.str().c_str());
713 GL_TIMESYNC *dbtime;
714 GL_S4_CALIB *glS4calib;
715 GL_ROOT *glroot;
716 for( r=0; r < 1000; r++){
717 Row = pResult->Next();
718 if( Row == NULL ) break;
719 printf("\n\n#################################################\n");
720 Int_t s=0;
721 Int_t t=0;
722 Int_t c=0;
723 TString *s4files[500];
724 TString *tfiles[500];
725 TString *cfiles[2000];
726 ID = atoi(Row->GetField(0));
727 PATH = Row->GetField(1);
728 NAME = Row->GetField(2);
729 printf("\n FILE: %s/%s \n",PATH.Data(),NAME.Data());
730 myquery.str("");
731 myquery << " select ID,RUNHEADER_OBT,RUNTRAILER_OBT from GL_RUN where ID_ROOT_L0=" << ID << " order by ID;";
732 pResult2 = dbc->Query(myquery.str().c_str());
733 for( Int_t run=0; run < pResult2->GetRowCount(); run++){
734 Row2 = pResult2->Next();
735 if( Row2 == NULL ) break;
736 IDR = atoi(Row2->GetField(0));
737 if ( run == 0 ) minid = IDR;
738 if ( run == pResult2->GetRowCount()-1 ) maxid = IDR;
739 //
740 // here we make queries to DB looking for needed files and print results
741 //
742 dbtime = new GL_TIMESYNC(ID,"ID",dbc);
743 //
744 atime1 = dbtime->DBabsTime((UInt_t)atoll(Row2->GetField(1)));
745 atime2 = dbtime->DBabsTime((UInt_t)atoll(Row2->GetField(2)));
746 // printf(" atime1 %u atime2 %u field 1 %s field2 %s \n",atime1,atime2,Row2->GetField(1),Row2->GetField(2));
747 //
748 // S4
749 //
750 glS4calib = new GL_S4_CALIB();
751 glS4calib->Query_GL_S4_CALIB(atime1, dbc);
752 glroot = new GL_ROOT();
753 glroot->Query_GL_ROOT(glS4calib->ID_ROOT_L0,dbc);
754 //
755 if ( s > 0 ){
756 Bool_t found = false;
757 for (Int_t g=0; g<s; g++){
758 if ( !strcmp(glroot->NAME.Data(),s4files[g]->Data()) ){
759 found = true;
760 };
761 };
762 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
763 s4files[s] = new TString(glroot->NAME.Data());
764 s++;
765 };
766 } else {
767 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
768 s4files[s] = new TString(glroot->NAME.Data());
769 s++;
770 };
771 };
772 //
773 delete glS4calib;
774 delete dbtime;
775 delete glroot;
776 //
777 // TRACKER
778 //
779 GL_TRK_CALIB q2;
780 q2.Query_GL_TRK_CALIB(atime1,dbc);
781 GL_ROOT q3;
782 q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc);
783 //
784 if ( t > 0 ){
785 Bool_t found = false;
786 for (Int_t gt=0; gt<t; gt++){
787 if ( !strcmp(q3.NAME.Data(),tfiles[gt]->Data()) ){
788 found = true;
789 };
790 };
791 if ( !found && strcmp(q3.NAME.Data(),NAME.Data()) ){
792 tfiles[t] = new TString(q3.NAME.Data());
793 t++;
794 };
795 } else {
796 if ( strcmp(q3.NAME.Data(),NAME.Data()) ){
797 tfiles[t] = new TString(q3.NAME.Data());
798 t++;
799 };
800 };
801 //
802 // CALO
803 //
804 GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();
805 GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB();
806 GL_ROOT *glroot = new GL_ROOT();
807 //
808 for (Int_t sc=0; sc<4; sc++){
809 //
810 UInt_t pampli = 0;
811 glcalo->Query_GL_CALO_CALIB(atime1,pampli,sc,dbc);
812 glroot->Query_GL_ROOT(glcalo->ID_ROOT_L0,dbc);
813 if ( c > 0 ){
814 Bool_t found = false;
815 for (Int_t gt=0; gt<c; gt++){
816 if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
817 found = true;
818 };
819 };
820 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
821 cfiles[c] = new TString(glroot->NAME.Data());
822 c++;
823 };
824 } else {
825 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
826 cfiles[c] = new TString(glroot->NAME.Data());
827 c++;
828 };
829 };
830 //
831 pampli = 0;
832 glcalo->Query_GL_CALO_CALIB(atime2,pampli,sc,dbc);
833 glroot->Query_GL_ROOT(glcalo->ID_ROOT_L0,dbc);
834 if ( c > 0 ){
835 Bool_t found = false;
836 for (Int_t gt=0; gt<c; gt++){
837 if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
838 found = true;
839 };
840 };
841 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
842 cfiles[c] = new TString(glroot->NAME.Data());
843 c++;
844 };
845 } else {
846 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
847 cfiles[c] = new TString(glroot->NAME.Data());
848 c++;
849 };
850 };
851 //
852 pampli = 2;
853 glp->Query_GL_CALOPULSE_CALIB(atime1,sc,pampli,dbc);
854 glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
855 if ( c > 0 ){
856 Bool_t found = false;
857 for (Int_t gt=0; gt<c; gt++){
858 if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
859 found = true;
860 };
861 };
862 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
863 cfiles[c] = new TString(glroot->NAME.Data());
864 c++;
865 };
866 } else {
867 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
868 cfiles[c] = new TString(glroot->NAME.Data());
869 c++;
870 };
871 };
872 //
873 pampli = 0;
874 glp->Query_GL_CALOPULSE_CALIB(atime1,sc,pampli,dbc);
875 glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
876 if ( c > 0 ){
877 Bool_t found = false;
878 for (Int_t gt=0; gt<c; gt++){
879 if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
880 found = true;
881 };
882 };
883 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
884 cfiles[c] = new TString(glroot->NAME.Data());
885 c++;
886 };
887 } else {
888 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
889 cfiles[c] = new TString(glroot->NAME.Data());
890 c++;
891 };
892 };
893 //
894 pampli = 2;
895 glp->Query_GL_CALOPULSE_CALIB(atime2,sc,pampli,dbc);
896 glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
897 if ( c > 0 ){
898 Bool_t found = false;
899 for (Int_t gt=0; gt<c; gt++){
900 if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
901 found = true;
902 };
903 };
904 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
905 cfiles[c] = new TString(glroot->NAME.Data());
906 c++;
907 };
908 } else {
909 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
910 cfiles[c] = new TString(glroot->NAME.Data());
911 c++;
912 };
913 };
914 //
915 pampli = 0;
916 glp->Query_GL_CALOPULSE_CALIB(atime2,sc,pampli,dbc);
917 glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
918 if ( c > 0 ){
919 Bool_t found = false;
920 for (Int_t gt=0; gt<c; gt++){
921 if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
922 found = true;
923 };
924 };
925 if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
926 cfiles[c] = new TString(glroot->NAME.Data());
927 c++;
928 };
929 } else {
930 if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
931 cfiles[c] = new TString(glroot->NAME.Data());
932 c++;
933 };
934 };
935 //
936 };
937 };
938 printf(" S4 requires:");
939 for (Int_t f=0;f<s; f++){
940 printf(" %s",s4files[f]->Data());
941 delete s4files[f];
942 };
943 printf("\n");
944 printf(" Tracker requires:");
945 for (Int_t f=0;f<t; f++){
946 printf(" %s",tfiles[f]->Data());
947 delete tfiles[f];
948 };
949 printf("\n");
950 printf(" Calorimeter requires:");
951 for (Int_t f=0;f<c; f++){
952 printf(" %s",cfiles[f]->Data());
953 delete cfiles[f];
954 };
955 printf("\n\n");
956 printf(" Minimum ID number in the file: %u \n",minid);
957 printf(" Maximum ID number in the file: %u \n",maxid);
958 printf("\n#################################################\n");
959 //
960 };
961 delete pResult;
962 if ( pResult2 ) delete pResult2;
963 };
964 //
965 // Close the DB connection
966 //
967 if ( dbc ) dbc->Close();
968 //
969 if ( !neat ) printf("\n");
970 //
971 exit(0);
972 }

  ViewVC Help
Powered by ViewVC 1.1.23