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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download)
Mon Mar 3 14:10:36 2008 UTC (16 years, 9 months ago) by mocchiut
Branch: MAIN
Changes since 1.12: +272 -0 lines
R2-D2 new feature

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

  ViewVC Help
Powered by ViewVC 1.1.23