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

Annotation of /chewbacca/YodaProfiler/src/R2-D2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Tue Oct 14 13:19:34 2014 UTC (10 years, 1 month ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, HEAD
Changes since 1.4: +3 -2 lines
10RED: NO_UNSIGNED_SUBTRACTION bug in MySQL >=5.5.5 fixed

1 mocchiut 1.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 mocchiut 1.5 myquery << "SET time_zone='+0:00';";
301     delete dbc->Query(myquery.str().c_str());
302     delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");
303 mocchiut 1.1 //
304     GL_ROOT *glroot = new GL_ROOT();
305     GL_RUN *glrun = new GL_RUN();
306     GL_TIMESYNC *dbtime = new GL_TIMESYNC();
307     UInt_t nr = 0;
308     UInt_t rlist[500];
309     //
310     // At which date correspond the DB time "dbti"?
311     //
312     if ( convert ){
313     printf("\n DB time %u is %s %s \n",dbti,dbtime->ConvertTime(tzone,dbti).Data(),tzone.Data());
314     };
315     //
316     // convert OBT to date
317     //
318     if ( convobt && convobtts ){
319     UInt_t id = 0;
320     myquery.str("");
321     myquery << "select ";
322     myquery << " ID";
323     myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";";
324     pResult = dbc->Query(myquery.str().c_str());
325     if ( pResult ){
326     Row = pResult->Next();
327     if ( Row ){
328     id = (UInt_t)atoll(Row->GetField(0));
329     delete pResult;
330     GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
331     UInt_t abtime = ctime->DBabsTime(obt);
332     TString thetime = dbtime->ConvertTime(tzone,abtime);
333     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());
334     delete ctime;
335     };
336     };
337     };
338     if ( (convobt && !convobtts) ){
339     printf("\n To convert a OBT to a date you must provide both OBT and file to be used for time sync \n");
340     };
341     //
342     // convert OBT to Resurs seconds
343     //
344     if ( convres && convobtts ){
345     UInt_t id = 0;
346     myquery.str("");
347     myquery << "select ";
348     myquery << " ID";
349     myquery << " from GL_ROOT where NAME=\"" << tsfile.Data() << "\";";
350     pResult = dbc->Query(myquery.str().c_str());
351     if ( pResult ){
352     Row = pResult->Next();
353     if ( Row ){
354     id = (UInt_t)atoll(Row->GetField(0));
355     delete pResult;
356     GL_TIMESYNC *ctime = new GL_TIMESYNC(id,"ID",dbc);
357     UInt_t restime = ctime->ResursTime(res);
358     //UInt_t abtime = ctime->DBabsTime(obt);
359     //
360     // TString thetime = dbtime->ConvertTime(tzone,abtime);
361     printf("\n OBT %u in the file %s corresponds to Resurs time %u \n",res,tsfile.Data(),restime);
362     delete ctime;
363     };
364     };
365     };
366     if ( (convres && !convobtts) ){
367     printf("\n To convert a OBT to the Resurs time you must provide both OBT and file to be used for time sync \n");
368     };
369     //
370     // Which run contains the date "runtime"?
371     //
372     if ( ruti ){
373     //
374     TDatime ti = TDatime(runtime.Data());
375     //
376     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);
377     //
378     UInt_t dbti = time->GetSec();
379     //
380     TString thetime = dbtime->UnConvertTime(tzone,dbti);
381     //
382     ti = TDatime(thetime.Data());
383     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);
384     //
385     UInt_t mytime = time2->GetSec();
386     //
387     Bool_t found = false;
388     //
389     myquery.str("");
390     myquery << "select ";
391     myquery << " ID ";
392     myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
393     << " RUNTRAILER_TIME>=" << mytime << " ;";
394     // printf("myquery is %s \n",myquery.str().c_str());
395     pResult = dbc->Query(myquery.str().c_str());
396     for( r=0; r < 1000; r++){
397     Row = pResult->Next();
398     if( Row == NULL ) break;
399     found = true;
400     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)));
401     };
402     myquery.str("");
403     myquery << "select ";
404     myquery << " ID ";
405     myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND RUNHEADER_TIME<=" << mytime << " AND "
406     << " RUNTRAILER_TIME>=" << mytime << " ;";
407     // printf("myquery is %s \n",myquery.str().c_str());
408     pResult = dbc->Query(myquery.str().c_str());
409     for( r=0; r < 1000; r++){
410     Row = pResult->Next();
411     if( Row == NULL ) break;
412     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)));
413     found = true;
414     };
415     //
416     if ( !found ){
417     printf("\n No run contains date %s %s (DB time %u )\n",runtime.Data(),tzone.Data(),mytime);
418     };
419     //
420     };
421     //
422     // Which tle must be used for the date "tletime"?
423     //
424     if ( dtle ){
425     //
426     //
427     TDatime ti = TDatime(tletime.Data());
428     //
429     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);
430     //
431     UInt_t dbti = time->GetSec();
432     //
433     TString thetime = dbtime->UnConvertTime(tzone,dbti);
434     //
435     ti = TDatime(thetime.Data());
436     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);
437     //
438     UInt_t mytime = time2->GetSec();
439     //
440     myquery.str("");
441     myquery << " select ID,TLE1,TLE2,TLE3 from GL_TLE where FROM_TIME<='" << time2->AsString("s") << "' ORDER BY FROM_TIME DESC LIMIT 1;";
442     // myquery << " from GL_TLE where FROM_TIME>=" << mytime << " ORDER BY FROM_TIME ASC LIMIT 1;";
443     // printf("myquery is %s \n",myquery.str().c_str());
444     pResult = dbc->Query(myquery.str().c_str());
445     Row = pResult->Next();
446     if ( !Row ){
447     printf("\n No TLE in the DB for date %s %s (DB time %u )\n",tletime.Data(),tzone.Data(),mytime);
448     };
449     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)));
450     printf("\n%s\n",Row->GetField(1));
451     printf("%s\n",Row->GetField(2));
452     printf("%s\n",Row->GetField(3));
453     //
454     FILE *tlefile;
455     tlefile = fopen("tle.txt","w");
456     fprintf(tlefile,"%s\n",Row->GetField(1));
457     fprintf(tlefile,"%s\n",Row->GetField(2));
458     fprintf(tlefile,"%s\n",Row->GetField(3));
459     fclose (tlefile);
460     //
461     printf("\n TLE has been dumped in file tle.txt \n");
462     };
463     //
464     // Which run contains the dbtime "runtime2"?
465     //
466     if ( ruti2 ){
467     //
468     UInt_t mytime = runtime2;
469     //
470     Bool_t found = false;
471     myquery.str("");
472     myquery << "select ";
473     myquery << " ID ";
474     myquery << " from GL_RUN where RUNHEADER_TIME<=" << mytime << " AND "
475     << " RUNTRAILER_TIME>=" << mytime << " ;";
476     // printf("myquery is %s \n",myquery.str().c_str());
477     pResult = dbc->Query(myquery.str().c_str());
478     for( r=0; r < 1000; r++){
479     Row = pResult->Next();
480     if( Row == NULL ) break;
481     printf("\n DB time %u is contained in run %u \n",mytime,(UInt_t)atoll(Row->GetField(0)));
482     found = true;
483     };
484     //
485     myquery.str("");
486     myquery << "select ";
487     myquery << " ID ";
488     myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND RUNHEADER_TIME<=" << mytime << " AND "
489     << " RUNTRAILER_TIME>=" << mytime << " ;";
490     // printf("myquery is %s \n",myquery.str().c_str());
491     pResult = dbc->Query(myquery.str().c_str());
492     for( r=0; r < 1000; r++){
493     Row = pResult->Next();
494     if( Row == NULL ) break;
495     printf("\n DB time %u is contained in run %u in the GL_RUN_TRASH table \n",mytime,(UInt_t)atoll(Row->GetField(0)));
496     found = true;
497     };
498     //
499     if ( !found ){
500     printf("\n No run contains DB time %u \n",mytime);
501     };
502     //
503     };
504     //
505     // To which file the run "run" belongs?
506     //
507     if ( run != 0 ){
508     Bool_t found = false;
509     glrun->Clear();
510     error = glrun->Query_GL_RUN(run,dbc);
511     glroot->Clear();
512     error = glroot->Query_GL_ROOT(glrun->ID_ROOT_L0,dbc);
513     if ( glrun->ID_ROOT_L0 ){
514     if ( error ){
515     printf(" Error querying the DB! \n");
516     exit(-4);
517     };
518     printf("\n Run %u belongs to file %s \n",run,(glroot->PATH+glroot->NAME).Data());
519     //filename = glroot->NAME;
520     found = true;
521     };
522     //
523     myquery.str("");
524     myquery << "select ";
525     myquery << " ID,FILENAMEL0,FILENAMEL2 ";
526     myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND ID=" << run << "; ";
527     pResult = dbc->Query(myquery.str().c_str());
528     for( r=0; r < 1000; r++){
529     Row = pResult->Next();
530     if( Row == NULL ) break;
531     printf("\n RUN %u has been deleted and now is contained in the GL_RUN_TRASH table \n",run);
532     printf("\n RUN %u belonged to L0 file %s and L2 file %s \n",run,Row->GetField(1),Row->GetField(2));
533     found = true;
534     };
535     //
536     if ( !found ) printf("\n No run with ID=%u in the DB!\n",run);
537     };
538     //
539     // Which runs are contained in the file "filename"?
540     //
541     if ( strcmp(filename.Data(),"") ){
542     // ----------------
543     Bool_t found = false;
544     Int_t ID = 0;
545     Int_t ID_RAW = 0;
546     //
547     const char *rawpath = "";
548     const char *rawname = "";
549     //
550     myquery.str("");
551     myquery << "select ";
552     myquery << " ID";
553     myquery << ",ID_RAW";
554     myquery << ",PATH";
555     myquery << ",NAME";
556     myquery << " from GL_ROOT where NAME=\"" << filename.Data() << "\";";
557     pResult = dbc->Query(myquery.str().c_str());
558     for( r=0; r < 1000; r++){
559     Row = pResult->Next();
560     if( Row == NULL ) break;
561     for( t = 0; t < pResult->GetFieldCount(); t++){
562     if(t==0) ID = atoi(Row->GetField(t));
563     if(t==1) ID_RAW = atoi(Row->GetField(t));
564     };
565     };
566     delete pResult;
567     if ( !ID && !ID_RAW ){
568     if ( !neat ) printf("\n No file with name %s in the DB!\n",filename.Data());
569     } else {
570     myquery.str("");
571     myquery << "select ";
572     myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS ";
573     myquery << " from GL_RUN where ID_ROOT_L0=" << ID << ";";
574     pResult = dbc->Query(myquery.str().c_str());
575     for( r=0; r < 1000; r++){
576     Row = pResult->Next();
577     if( Row == NULL ) break;
578     found = true;
579     if ( !r && !neat ) printf("\n File %s contains the following runs: \n\n",filename.Data());
580     TString UTC=tzone.Data();
581     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)));
582     if ( neat ) printf("%u\n",(UInt_t)atoll(Row->GetField(0)));
583     };
584     delete pResult;
585     myquery.str("");
586     myquery << "select ";
587     myquery << " ID,RUNHEADER_TIME,RUNTRAILER_TIME ";
588     myquery << " from GL_RUN_TRASH where BELONGED_TO='GL_RUN' AND FILENAMEL0='" << filename.Data() << "' ;";
589     pResult = dbc->Query(myquery.str().c_str());
590     for( r=0; r < 1000; r++){
591     Row = pResult->Next();
592     if( Row == NULL ) break;
593     if ( !r && !neat ) printf("\n File %s contains the following DELETED runs: \n\n",filename.Data());
594     TString UTC=tzone.Data();
595     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());
596     };
597     //
598     if ( !found ){
599     if ( !neat ) printf("\n No run associated to the file %s \n",filename.Data());
600     };
601     myquery.str("");
602     myquery << "select ";
603     myquery << " PATH,NAME";
604     myquery << " from GL_RAW where ID=" << ID_RAW << ";";
605     pResult = dbc->Query(myquery.str().c_str());
606     for( r=0; r < 1000; r++){
607     Row = pResult->Next();
608     if( Row == NULL ) break;
609     for( t = 0; t < pResult->GetFieldCount(); t++){
610     if(t==0) rawpath = Row->GetField(t);
611     if(t==1) rawname = Row->GetField(t);
612     };
613     };
614     delete pResult;
615     if ( !neat ) printf("\n File %s belongs to raw data file %s/%s \n",filename.Data(),rawpath,rawname);
616     };
617     };
618     //
619     // Which runs are contained in the file "l2filename"?
620     //
621     if ( strcmp(l2filename.Data(),"") ){
622     // ----------------
623 mocchiut 1.3 // Bool_t found = false;
624 mocchiut 1.1 Int_t ID = 0;
625 mocchiut 1.3 // Int_t ID_RAW = 0;
626 mocchiut 1.1 //
627     const char *rawpath = "";
628     const char *rawname = "";
629     //
630     myquery.str("");
631     myquery << "select ";
632     myquery << " ID";
633     myquery << ",ID_RAW";
634     myquery << ",PATH";
635     myquery << ",NAME";
636     myquery << " from GL_ROOT where NAME=\"" << l2filename.Data() << "\" order by INSERT_TIME desc limit 1;";
637     pResult = dbc->Query(myquery.str().c_str());
638     for( r=0; r < 1000; r++){
639     Row = pResult->Next();
640     if( Row == NULL ) break;
641     for( t = 0; t < pResult->GetFieldCount(); t++){
642     if(t==0) ID = atoi(Row->GetField(t));
643 mocchiut 1.3 // if(t==1) ID_RAW = atoi(Row->GetField(t));
644 mocchiut 1.1 };
645     };
646     delete pResult;
647     if ( !ID ){
648     printf("\n No file with name %s in the DB!\n",l2filename.Data());
649     } else {
650     nr = 0;
651     rlist[0] = 0;
652     myquery.str("");
653     myquery << "select ";
654     myquery << " ID,ID_ROOT_L0 ";
655     myquery << " from GL_RUN where ID_ROOT_L2=" << ID << ";";
656     pResult = dbc->Query(myquery.str().c_str());
657     for( r=0; r < pResult->GetRowCount(); r++){
658     Row = pResult->Next();
659     if( Row == NULL ) break;
660 mocchiut 1.3 // found = true;
661 mocchiut 1.1 if ( !r ) printf("\n File %s contains the following runs: \n\n",l2filename.Data());
662     printf(" %u ",(UInt_t)atoll(Row->GetField(0)));
663     if ( r < (pResult->GetRowCount()-1) ){
664     printf("-");
665     } else {
666     printf("\n\n");
667     };
668     if ( (UInt_t)atoll(Row->GetField(1)) != rlist[nr] ){
669     nr++;
670     rlist[nr] = (UInt_t)atoll(Row->GetField(1));
671     };
672     };
673     delete pResult;
674     //
675     printf("\n File %s contains runs from L0 files: \n\n",l2filename.Data());
676     for (UInt_t l=1; l<nr+1; l++){
677     myquery.str("");
678     myquery << "select ";
679     myquery << " PATH,NAME";
680     myquery << " from GL_ROOT where ID=" << rlist[l] << ";";
681     pResult = dbc->Query(myquery.str().c_str());
682     for( r=0; r < pResult->GetRowCount(); r++){
683     Row = pResult->Next();
684     if( Row == NULL ) break;
685     for( t = 0; t < pResult->GetFieldCount(); t++){
686     if(t==0) rawpath = Row->GetField(t);
687     if(t==1) rawname = Row->GetField(t);
688     };
689     printf(" %s/%s \n",rawpath,rawname);
690     };
691     delete pResult;
692     };
693     };
694     };
695     //
696     //
697     // Show relationship between files around file "splitat"
698     //
699     if ( strcmp(splitat.Data(),"") ){
700     // ----------------
701     Int_t ID = 0;
702     Int_t IDR = 0;
703     TString PATH;
704     TString NAME;
705     UInt_t atime1 = 0;
706     UInt_t atime2 = 0;
707     UInt_t minid = 0;
708     UInt_t maxid = 0;
709     //
710     myquery.str("");
711     myquery << " select ID,PATH,NAME from GL_ROOT where NAME>=\"" << splitat.Data() << "\" order by NAME asc limit " << nsplit << ";";
712     // printf(" myquery is %s \n",myquery.str().c_str());
713     pResult = dbc->Query(myquery.str().c_str());
714     GL_TIMESYNC *dbtime;
715     GL_S4_CALIB *glS4calib;
716     GL_ROOT *glroot;
717     for( r=0; r < 1000; r++){
718     Row = pResult->Next();
719     if( Row == NULL ) break;
720     printf("\n\n#################################################\n");
721     Int_t s=0;
722     Int_t t=0;
723     Int_t c=0;
724     TString *s4files[500];
725     TString *tfiles[500];
726     TString *cfiles[2000];
727     ID = atoi(Row->GetField(0));
728     PATH = Row->GetField(1);
729     NAME = Row->GetField(2);
730     printf("\n FILE: %s/%s \n",PATH.Data(),NAME.Data());
731     myquery.str("");
732     myquery << " select ID,RUNHEADER_OBT,RUNTRAILER_OBT from GL_RUN where ID_ROOT_L0=" << ID << " order by ID;";
733     pResult2 = dbc->Query(myquery.str().c_str());
734     for( Int_t run=0; run < pResult2->GetRowCount(); run++){
735     Row2 = pResult2->Next();
736     if( Row2 == NULL ) break;
737     IDR = atoi(Row2->GetField(0));
738     if ( run == 0 ) minid = IDR;
739     if ( run == pResult2->GetRowCount()-1 ) maxid = IDR;
740     //
741     // here we make queries to DB looking for needed files and print results
742     //
743     dbtime = new GL_TIMESYNC(ID,"ID",dbc);
744     //
745     atime1 = dbtime->DBabsTime((UInt_t)atoll(Row2->GetField(1)));
746     atime2 = dbtime->DBabsTime((UInt_t)atoll(Row2->GetField(2)));
747     // printf(" atime1 %u atime2 %u field 1 %s field2 %s \n",atime1,atime2,Row2->GetField(1),Row2->GetField(2));
748     //
749     // S4
750     //
751     glS4calib = new GL_S4_CALIB();
752     glS4calib->Query_GL_S4_CALIB(atime1, dbc);
753     glroot = new GL_ROOT();
754     glroot->Query_GL_ROOT(glS4calib->ID_ROOT_L0,dbc);
755     //
756     if ( s > 0 ){
757     Bool_t found = false;
758     for (Int_t g=0; g<s; g++){
759     if ( !strcmp(glroot->NAME.Data(),s4files[g]->Data()) ){
760     found = true;
761     };
762     };
763     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
764     s4files[s] = new TString(glroot->NAME.Data());
765     s++;
766     };
767     } else {
768     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
769     s4files[s] = new TString(glroot->NAME.Data());
770     s++;
771     };
772     };
773     //
774     delete glS4calib;
775     delete dbtime;
776     delete glroot;
777     //
778     // TRACKER
779     //
780     GL_TRK_CALIB q2;
781     q2.Query_GL_TRK_CALIB(atime1,dbc);
782     GL_ROOT q3;
783     q3.Query_GL_ROOT(q2.ID_ROOT_L0,dbc);
784     //
785     if ( t > 0 ){
786     Bool_t found = false;
787     for (Int_t gt=0; gt<t; gt++){
788     if ( !strcmp(q3.NAME.Data(),tfiles[gt]->Data()) ){
789     found = true;
790     };
791     };
792     if ( !found && strcmp(q3.NAME.Data(),NAME.Data()) ){
793     tfiles[t] = new TString(q3.NAME.Data());
794     t++;
795     };
796     } else {
797     if ( strcmp(q3.NAME.Data(),NAME.Data()) ){
798     tfiles[t] = new TString(q3.NAME.Data());
799     t++;
800     };
801     };
802     //
803     // CALO
804     //
805     GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();
806     GL_CALOPULSE_CALIB *glp = new GL_CALOPULSE_CALIB();
807     GL_ROOT *glroot = new GL_ROOT();
808     //
809     for (Int_t sc=0; sc<4; sc++){
810     //
811     UInt_t pampli = 0;
812     glcalo->Query_GL_CALO_CALIB(atime1,pampli,sc,dbc);
813     glroot->Query_GL_ROOT(glcalo->ID_ROOT_L0,dbc);
814     if ( c > 0 ){
815     Bool_t found = false;
816     for (Int_t gt=0; gt<c; gt++){
817     if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
818     found = true;
819     };
820     };
821     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
822     cfiles[c] = new TString(glroot->NAME.Data());
823     c++;
824     };
825     } else {
826     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
827     cfiles[c] = new TString(glroot->NAME.Data());
828     c++;
829     };
830     };
831     //
832     pampli = 0;
833     glcalo->Query_GL_CALO_CALIB(atime2,pampli,sc,dbc);
834     glroot->Query_GL_ROOT(glcalo->ID_ROOT_L0,dbc);
835     if ( c > 0 ){
836     Bool_t found = false;
837     for (Int_t gt=0; gt<c; gt++){
838     if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
839     found = true;
840     };
841     };
842     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
843     cfiles[c] = new TString(glroot->NAME.Data());
844     c++;
845     };
846     } else {
847     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
848     cfiles[c] = new TString(glroot->NAME.Data());
849     c++;
850     };
851     };
852     //
853     pampli = 2;
854     glp->Query_GL_CALOPULSE_CALIB(atime1,sc,pampli,dbc);
855     glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
856     if ( c > 0 ){
857     Bool_t found = false;
858     for (Int_t gt=0; gt<c; gt++){
859     if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
860     found = true;
861     };
862     };
863     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
864     cfiles[c] = new TString(glroot->NAME.Data());
865     c++;
866     };
867     } else {
868     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
869     cfiles[c] = new TString(glroot->NAME.Data());
870     c++;
871     };
872     };
873     //
874     pampli = 0;
875     glp->Query_GL_CALOPULSE_CALIB(atime1,sc,pampli,dbc);
876     glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
877     if ( c > 0 ){
878     Bool_t found = false;
879     for (Int_t gt=0; gt<c; gt++){
880     if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
881     found = true;
882     };
883     };
884     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
885     cfiles[c] = new TString(glroot->NAME.Data());
886     c++;
887     };
888     } else {
889     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
890     cfiles[c] = new TString(glroot->NAME.Data());
891     c++;
892     };
893     };
894     //
895     pampli = 2;
896     glp->Query_GL_CALOPULSE_CALIB(atime2,sc,pampli,dbc);
897     glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
898     if ( c > 0 ){
899     Bool_t found = false;
900     for (Int_t gt=0; gt<c; gt++){
901     if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
902     found = true;
903     };
904     };
905     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
906     cfiles[c] = new TString(glroot->NAME.Data());
907     c++;
908     };
909     } else {
910     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
911     cfiles[c] = new TString(glroot->NAME.Data());
912     c++;
913     };
914     };
915     //
916     pampli = 0;
917     glp->Query_GL_CALOPULSE_CALIB(atime2,sc,pampli,dbc);
918     glroot->Query_GL_ROOT(glp->ID_ROOT_L0,dbc);
919     if ( c > 0 ){
920     Bool_t found = false;
921     for (Int_t gt=0; gt<c; gt++){
922     if ( !strcmp(glroot->NAME.Data(),cfiles[gt]->Data()) ){
923     found = true;
924     };
925     };
926     if ( !found && strcmp(glroot->NAME.Data(),NAME.Data()) ){
927     cfiles[c] = new TString(glroot->NAME.Data());
928     c++;
929     };
930     } else {
931     if ( strcmp(glroot->NAME.Data(),NAME.Data()) ){
932     cfiles[c] = new TString(glroot->NAME.Data());
933     c++;
934     };
935     };
936     //
937     };
938     };
939     printf(" S4 requires:");
940     for (Int_t f=0;f<s; f++){
941     printf(" %s",s4files[f]->Data());
942     delete s4files[f];
943     };
944     printf("\n");
945     printf(" Tracker requires:");
946     for (Int_t f=0;f<t; f++){
947     printf(" %s",tfiles[f]->Data());
948     delete tfiles[f];
949     };
950     printf("\n");
951     printf(" Calorimeter requires:");
952     for (Int_t f=0;f<c; f++){
953     printf(" %s",cfiles[f]->Data());
954     delete cfiles[f];
955     };
956     printf("\n\n");
957     printf(" Minimum ID number in the file: %u \n",minid);
958     printf(" Maximum ID number in the file: %u \n",maxid);
959     printf("\n#################################################\n");
960     //
961     };
962     delete pResult;
963     if ( pResult2 ) delete pResult2;
964     };
965     //
966     // Close the DB connection
967     //
968 pam-fi 1.2 if ( dbc ){
969     dbc->Close();
970     delete dbc;
971     dbc = 0;
972     }
973 mocchiut 1.1 //
974     if ( !neat ) printf("\n");
975     //
976     exit(0);
977     }

  ViewVC Help
Powered by ViewVC 1.1.23