/[PAMELA software]/YodaProfiler/src/GLTables.cpp
ViewVC logotype

Annotation of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (hide annotations) (download)
Sun Sep 9 18:59:41 2007 UTC (17 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: v4r01, v4r00
Changes since 1.30: +6 -0 lines
Methods added to GL_TABLES

1 mocchiut 1.1 /**
2     * \file GLTables.cpp
3     * \author Elena Vannuccini
4     *
5     * The file contains implementation of the methods to query the DB.
6     */
7     //
8     #include <sstream>
9 mocchiut 1.12 #include <iostream>
10 mocchiut 1.1 //
11     #include <TFile.h>
12     #include <TTree.h>
13 mocchiut 1.16 #include <TTimeStamp.h>
14 mocchiut 1.1 #include <EventHeader.h>
15     #include <PscuHeader.h>
16     //
17     #include <GLTables.h>
18 mocchiut 1.13 #include <sgp4.h>
19 mocchiut 1.1 //
20 mocchiut 1.22 ClassImp(GL_TABLES);
21 mocchiut 1.1 ClassImp(GL_TRK_CALIB);
22     ClassImp(GL_RUN);
23     ClassImp(GL_ROOT);
24     ClassImp(GL_PARAM);
25     ClassImp(GL_S4_CALIB);
26     ClassImp(GL_CALO_CALIB);
27     ClassImp(GL_TIMESYNC);
28 mocchiut 1.12 ClassImp(GL_TLE);
29 mocchiut 1.1 //
30     using namespace std;
31    
32 mocchiut 1.22 GL_TABLES::GL_TABLES(){
33     };
34    
35     GL_TABLES::GL_TABLES(TString host, TString user, TString psw){
36     fHost = new TString(host.Data());
37     fUser = new TString(user.Data());
38     fPsw = new TString(psw.Data());
39     fSet = true;
40     fNquery = 0;
41 mocchiut 1.31 mh = host.Data();
42     mu = user.Data();
43     mp = psw.Data();
44 mocchiut 1.22 };
45    
46    
47     void GL_TABLES::Set(TString host, TString user, TString psw){
48     fHost = new TString(host.Data());
49     fUser = new TString(user.Data());
50     fPsw = new TString(psw.Data());
51     fSet = true;
52     fNquery = 0;
53 mocchiut 1.31 mh = host.Data();
54     mu = user.Data();
55     mp = psw.Data();
56 mocchiut 1.22 };
57    
58 mocchiut 1.30 Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){
59 mocchiut 1.22 //
60     //
61     //
62     if ( !fSet ){
63     return true;
64     };
65     //
66     //
67     //
68 mocchiut 1.30 // printf(" host is %s \n",fHost->Data());
69 mocchiut 1.22 //
70     stringstream myquery;
71     myquery.str("");
72     myquery << "show databases;";
73 mocchiut 1.30 if ( dbc ){
74     if ( dbc->IsConnected() ){
75     dbc->Query(myquery.str().c_str());
76     fNquery++;
77     if ( !(dbc->GetErrorCode()) ){
78     // printf("ok\n");
79     //
80     // if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){
81     // if ( !(dbc->GetErrorCode()) ){
82     // is connected
83     return true;
84     // };
85     };
86     };
87     };
88     // printf("porca di quella \n");
89     if ( true ) {
90 mocchiut 1.22 //
91     printf(" WARNING: Lost connection to DB! try to recover... \n");
92     //
93     TString host = fHost->Data();
94     TString user = fUser->Data();
95     TString psw = fPsw->Data();
96     delete dbc;
97     dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
98     //
99     myquery.str("");
100     myquery << "show databases;";
101     dbc->Query(myquery.str().c_str());
102     fNquery++;
103 mocchiut 1.30 // printf(" e riporca di quella \n");
104 mocchiut 1.22 //
105 mocchiut 1.30 // if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){
106     if ( !(dbc->GetErrorCode()) ){
107 mocchiut 1.22 //
108     printf(" ...connection recovered, I can continue! \n");
109     //
110     myquery.str("");
111     myquery << "SET time_zone='+0:00'";
112     dbc->Query(myquery.str().c_str());
113     fNquery++;
114     myquery.str("");
115     myquery << "SET wait_timeout=173000;";
116     dbc->Query(myquery.str().c_str());
117     fNquery++;
118     return true;
119     };
120     };
121     //
122     printf(" GLTABLES: connection is gone away, query will fail\n");
123     //
124     return false;
125     //
126     };
127    
128     void GL_TABLES::ResetCounters(){
129     fNquery = 0;
130     };
131    
132     void GL_TABLES::AddQ(){
133     if ( fSet ) fNquery++;
134     };
135    
136     UInt_t GL_TABLES::GetNqueries(){
137     UInt_t rn = 0;
138     rn += (UInt_t&)fNquery;
139     return(rn);
140     };
141    
142 mocchiut 1.1 GL_RUN::GL_RUN() {
143     ID = 0;
144     ID_RUN_FRAG = 0;
145     ID_ROOT_L0 = 0;
146     ID_ROOT_L2 = 0;
147     RUNHEADER_TIME = 0;
148     RUNTRAILER_TIME = 0;
149     EV_FROM = 0;
150     EV_TO = 0;
151     TRK_CALIB_USED = 0;
152     EFF_WRK_SCHEDULE = 0;
153     PRH_VAR_TRG_MODE_A = 0;
154     PRH_VAR_TRG_MODE_B = 0;
155     ACQ_BUILD_INFO = 0;
156     ACQ_VAR_INFO = 0;
157     RUNHEADER_OBT = 0;
158     RUNTRAILER_OBT = 0;
159     RUNHEADER_PKT = 0;
160     RUNTRAILER_PKT = 0;
161     NEVENTS = 0;
162     LAST_TIMESYNC = 0;
163     OBT_TIMESYNC = 0;
164     COMPILATIONTIMESTAMP = 0;
165     FAV_WRK_SCHEDULE = 0;
166     RM_ACQ_AFTER_CALIB = 0;
167     RM_ACQ_SETTING_MODE = 0;
168     PKT_COUNTER = 0;
169     PKT_READY_COUNTER = 0;
170     TRK_CALIB_USED = 0;
171     CAL_DSP_MASK = 0;
172     BOOT_NUMBER = 0;
173     VALIDATION = 0;
174     }
175    
176 pam-fi 1.9
177 mocchiut 1.1 void GL_RUN::Clear() {
178     ID = 0;
179     ID_RUN_FRAG = 0;
180     ID_ROOT_L0 = 0;
181     ID_ROOT_L2 = 0;
182     RUNHEADER_TIME = 0;
183     RUNTRAILER_TIME = 0;
184     EV_FROM = 0;
185     EV_TO = 0;
186     TRK_CALIB_USED = 0;
187     EFF_WRK_SCHEDULE = 0;
188     PRH_VAR_TRG_MODE_A = 0;
189     PRH_VAR_TRG_MODE_B = 0;
190     ACQ_BUILD_INFO = 0;
191     ACQ_VAR_INFO = 0;
192     RUNHEADER_OBT = 0;
193     RUNTRAILER_OBT = 0;
194     RUNHEADER_PKT = 0;
195     RUNTRAILER_PKT = 0;
196     NEVENTS = 0;
197     LAST_TIMESYNC = 0;
198     OBT_TIMESYNC = 0;
199     COMPILATIONTIMESTAMP = 0;
200     FAV_WRK_SCHEDULE = 0;
201     RM_ACQ_AFTER_CALIB = 0;
202     RM_ACQ_SETTING_MODE = 0;
203     PKT_COUNTER = 0;
204     PKT_READY_COUNTER = 0;
205     TRK_CALIB_USED = 0;
206     CAL_DSP_MASK = 0;
207     BOOT_NUMBER = 0;
208     VALIDATION = 0;
209     }
210    
211     GL_ROOT::GL_ROOT(){
212     ID = 0;
213     ID_RAW = 0;
214     ID_TIMESYNC = 0;
215     PATH = "";
216     NAME = "";
217     }
218    
219     GL_PARAM::GL_PARAM(){
220     ID = 0;
221     PATH = "";
222     NAME = "";
223     DESCR = "";
224     FROM_TIME = 0;
225     TO_TIME = 0;
226     TYPE = 0;
227     }
228    
229    
230     GL_TRK_CALIB::GL_TRK_CALIB(){
231     ID = 0;
232     ID_ROOT_L0 = 0;
233     EV_ROOT_CALIBTRK1 = 0;
234     EV_ROOT_CALIBTRK2 = 0;
235     FROM_TIME = 0;
236     TO_TIME = 0;
237     OBT1 = 0;
238     OBT2 = 0;
239     PKT1 = 0;
240     PKT2 = 0;
241 pam-fi 1.9 BOOT_NUMBER = 0;
242     VALIDATION = 0;
243 mocchiut 1.1 }
244    
245     GL_CALO_CALIB::GL_CALO_CALIB(){
246     ID = 0;
247     ID_ROOT_L0 = 0;
248     EV_ROOT = 0;
249     FROM_TIME = 0;
250     TO_TIME = 0;
251     SECTION = 0;
252     }
253    
254     GL_S4_CALIB::GL_S4_CALIB(){
255     ID = 0;
256     ID_ROOT_L0 = 0;
257     EV_ROOT = 0;
258     FROM_TIME = 0;
259     TO_TIME = 0;
260     PARAM_FIT0 = 0.;
261     PARAM_FIT1 = 0.;
262     }
263    
264     GL_TIMESYNC::GL_TIMESYNC(){
265     obtfirst = 0;
266     pktfirst = 0;
267     toffset = 0;
268 mocchiut 1.17 // ID = 0;
269     // ID_RAW = 0;
270 mocchiut 1.1 OBT0 = 0;
271     TIMESYNC = 0;
272     TYPE = 0;
273 mocchiut 1.12 }
274    
275     // ****************************************************
276 mocchiut 1.1
277     void GL_RUN::SetEV_FROM(UInt_t evfrom){
278     EV_FROM = evfrom;
279     };
280    
281     void GL_RUN::SetEV_TO(UInt_t evto){
282     EV_TO = evto;
283     };
284    
285     void GL_RUN::SetNEVENTS(UInt_t nev){
286     NEVENTS = nev;
287     };
288    
289     void GL_RUN::SetBOOTNUMBER(UInt_t boot){
290     BOOT_NUMBER = boot;
291     };
292    
293     void GL_RUN::SetRUNHEADER_TIME(UInt_t absth){
294     RUNHEADER_TIME = absth;
295     };
296    
297     void GL_RUN::SetRUNTRAILER_TIME(UInt_t abstt){
298     RUNTRAILER_TIME = abstt;
299     };
300    
301     void GL_RUN::SetRUNHEADER_PKT(UInt_t absth){
302     RUNHEADER_PKT = absth;
303     };
304    
305     void GL_RUN::SetRUNTRAILER_PKT(UInt_t abstt){
306     RUNTRAILER_PKT = abstt;
307     };
308    
309     void GL_RUN::SetRUNHEADER_OBT(UInt_t absth){
310     RUNHEADER_OBT = absth;
311     };
312    
313     void GL_RUN::SetRUNTRAILER_OBT(UInt_t abstt){
314     RUNTRAILER_OBT = abstt;
315     };
316    
317     void GL_RUN::SetID_ROOT_L2(UInt_t idl2){
318     ID_ROOT_L2 = idl2;
319     };
320    
321     void GL_RUN::SetID_ROOT_L0(UInt_t idroot){
322     ID_ROOT_L0 = idroot;
323     };
324    
325     void GL_RUN::SetID_RUN_FRAG(UInt_t idfrag){
326     ID_RUN_FRAG = idfrag;
327     };
328    
329     void GL_RUN::SetVALIDATION(UInt_t valid){
330     VALIDATION = valid;
331     };
332    
333     void GL_RUN::SetLAST_TIMESYNC(UInt_t ts){
334     LAST_TIMESYNC = ts;
335     };
336    
337     void GL_RUN::SetOBT_TIMESYNC(UInt_t ts){
338     OBT_TIMESYNC = ts;
339     };
340    
341     void GL_RUN:: SetPKT_COUNTER(UInt_t value){
342     PKT_COUNTER = value;
343     };
344    
345     void GL_RUN:: SetPKT_READY_COUNTER(UInt_t value){
346     PKT_READY_COUNTER = value;
347     };
348    
349     void GL_RUN:: SetCOMPILATIONTIMESTAMP(UInt_t value){
350     COMPILATIONTIMESTAMP = value;
351     };
352    
353     void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){
354     FAV_WRK_SCHEDULE = value;
355     };
356    
357     void GL_RUN:: SetEFF_WRK_SCHEDULE(UInt_t value){
358     EFF_WRK_SCHEDULE = value;
359     };
360    
361     void GL_RUN:: SetPRH_VAR_TRG_MODE_A(UInt_t value){
362     PRH_VAR_TRG_MODE_A = value;
363     };
364    
365     void GL_RUN:: SetPRH_VAR_TRG_MODE_B(UInt_t value){
366     PRH_VAR_TRG_MODE_B = value;
367     };
368    
369     void GL_RUN:: SetACQ_BUILD_INFO(UInt_t value){
370     ACQ_BUILD_INFO = value;
371     };
372    
373     void GL_RUN:: SetACQ_VAR_INFO(UInt_t value){
374     ACQ_VAR_INFO = value;
375     };
376    
377     void GL_RUN:: SetRM_ACQ_AFTER_CALIB(UInt_t value){
378     RM_ACQ_AFTER_CALIB = value;
379     };
380    
381     void GL_RUN:: SetRM_ACQ_SETTING_MODE(UInt_t value){
382     RM_ACQ_SETTING_MODE = value;
383     };
384    
385     void GL_RUN:: SetTRK_CALIB_USED(UInt_t value){
386     TRK_CALIB_USED = value;
387     };
388    
389     void GL_RUN:: SetCAL_DSP_MASK(UInt_t value){
390     CAL_DSP_MASK = value;
391     };
392    
393     void GL_RUN:: SetID(UInt_t value){
394     ID = value;
395     };
396    
397     void GL_RUN::Set_GL_RUNT(RunTrailerEvent *runt, PscuHeader *pht){
398     PKT_COUNTER = runt->PKT_COUNTER;
399     PKT_READY_COUNTER = runt->PKT_ReadyCounter;
400     RUNTRAILER_OBT = pht->GetOrbitalTime();
401     RUNTRAILER_PKT = pht->GetCounter();
402     };
403    
404     void GL_RUN::Set_GL_RUNH(RunHeaderEvent *runh, PscuHeader *phh){
405     TRK_CALIB_USED = runh->TRK_CALIB_USED;
406     PRH_VAR_TRG_MODE_A = runh->PRH_VAR_TRIGGER_MODE_A;
407     PRH_VAR_TRG_MODE_B = runh->PRH_VAR_TRIGGER_MODE_B;
408     ACQ_BUILD_INFO = runh->ACQ_BUILD_INFO;
409     ACQ_VAR_INFO = runh->ACQ_VAR_INFO;
410     RUNHEADER_OBT = phh->GetOrbitalTime();
411     RUNHEADER_PKT = phh->GetCounter();
412     LAST_TIMESYNC = runh->LAST_TIME_SYNC_INFO;
413     OBT_TIMESYNC = runh->OBT_TIME_SYNC;
414     COMPILATIONTIMESTAMP = runh->COMPILATIONTIMESTAMP;
415     FAV_WRK_SCHEDULE = runh->FAVOURITE_WORKING_SCHEDULE;
416     EFF_WRK_SCHEDULE = runh->EFFECTIVE_WORKING_SCHEDULE;
417     RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB;
418     RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE;
419     TRK_CALIB_USED = runh->TRK_CALIB_USED;
420     CAL_DSP_MASK = runh->CAL_DSP_MASK;
421     };
422    
423     void GL_RUN::Set_GL_RUNT0(){
424     PKT_COUNTER = 0;
425     PKT_READY_COUNTER = 0;
426     RUNTRAILER_OBT = 0;
427     RUNTRAILER_PKT = 0;
428     };
429    
430     void GL_RUN::Set_GL_RUNH0(){
431     TRK_CALIB_USED = 0;
432     PRH_VAR_TRG_MODE_A = 0;
433     PRH_VAR_TRG_MODE_B = 0;
434     ACQ_BUILD_INFO = 0;
435     ACQ_VAR_INFO = 0;
436     RUNHEADER_OBT = 0;
437     RUNHEADER_PKT = 0;
438     LAST_TIMESYNC = 0;
439     OBT_TIMESYNC = 0;
440     COMPILATIONTIMESTAMP = 0;
441     FAV_WRK_SCHEDULE = 0;
442     EFF_WRK_SCHEDULE = 0;
443     RM_ACQ_AFTER_CALIB = 0;
444     RM_ACQ_SETTING_MODE = 0;
445     TRK_CALIB_USED = 0;
446     CAL_DSP_MASK = 0;
447     };
448    
449 pam-fi 1.9 void GL_RUN::Set_GL_RUN(TSQLRow *Row){
450     for( Int_t t = 0; t < 30; t++){
451     if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
452     if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
453     if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
454     if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
455     if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
456     if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
457     if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
458     if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
459     if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
460     if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
461     if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
462     if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t));
463     if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t));
464     if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t));
465     if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
466     if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
467     if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
468     if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
469     if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
470     if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
471     if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
472     if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
473     if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
474     if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
475     if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
476     if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
477     if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
478     if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
479     if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
480     if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
481     };
482    
483     }
484    
485 mocchiut 1.14 /**
486 mocchiut 1.15 * This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table
487     * If IDRUN is 0 "this->ID" run is used.
488 mocchiut 1.14 *
489     **/
490     Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){
491     // MySQL variables
492     TSQLResult *pResult;
493     TSQLRow *Row;
494     stringstream myquery;
495     //
496     if ( !IDRUN ) IDRUN = ID;
497     if ( !IDRUN ) return 1;
498     // ----------------
499     myquery.str("");
500     myquery << " INSERT INTO GL_RUN_TRASH (";
501     myquery << "ID";
502     myquery << ",ID_RUN_FRAG";
503     myquery << ",ID_ROOT_L0";
504     myquery << ",ID_ROOT_L2";
505     myquery << ",RUNHEADER_TIME";
506     myquery << ",RUNTRAILER_TIME";
507     myquery << ",RUNHEADER_OBT";
508     myquery << ",RUNTRAILER_OBT";
509     myquery << ",RUNHEADER_PKT";
510     myquery << ",RUNTRAILER_PKT";
511     myquery << ",BOOT_NUMBER";
512     myquery << ",EV_FROM";
513     myquery << ",EV_TO";
514     myquery << ",NEVENTS";
515     myquery << ",PKT_COUNTER";
516     myquery << ",PKT_READY_COUNTER";
517     myquery << ",COMPILATIONTIMESTAMP";
518     myquery << ",FAV_WRK_SCHEDULE";
519     myquery << ",EFF_WRK_SCHEDULE";
520     myquery << ",PRH_VAR_TRG_MODE_A";
521     myquery << ",PRH_VAR_TRG_MODE_B";
522     myquery << ",ACQ_BUILD_INFO";
523     myquery << ",ACQ_VAR_INFO";
524     myquery << ",RM_ACQ_AFTER_CALIB";
525     myquery << ",RM_ACQ_SETTING_MODE";
526     myquery << ",TRK_CALIB_USED";
527     myquery << ",CAL_DSP_MASK";
528     myquery << ",LAST_TIMESYNC";
529     myquery << ",OBT_TIMESYNC";
530     myquery << ",VALIDATION";
531     myquery << ",INSERT_TIME";
532     myquery << ") SELECT * FROM ";
533     myquery << FromTable.Data();
534     myquery << " WHERE ID=";
535     myquery << (UInt_t)IDRUN << ";";
536     //
537     // printf("1myquery is %s \n",myquery.str().c_str());
538     //
539 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
540     this->GetGLTABLES()->AddQ();
541 mocchiut 1.14 dbc->Query(myquery.str().c_str());
542     //
543 mocchiut 1.15 // retrieve this ID_TRASH
544     //
545     myquery.str("");
546     myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1";
547 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
548     this->GetGLTABLES()->AddQ();
549 mocchiut 1.15 pResult = dbc->Query(myquery.str().c_str());
550     //
551     UInt_t idtrash = 0;
552     UInt_t idl0 = 0;
553     UInt_t idl2 = 0;
554     //
555     Row = pResult->Next();
556     if( Row != NULL ){
557     idtrash = (UInt_t)atoll(Row->GetField(0));
558     idl0 = (UInt_t)atoll(Row->GetField(1));
559     idl2 = (UInt_t)atoll(Row->GetField(2));
560     };
561     //
562 mocchiut 1.14 TString fileL0 = "";
563     TString fileL2 = "";
564     myquery.str("");
565     myquery << " SELECT NAME FROM GL_ROOT WHERE ID=";
566 mocchiut 1.15 myquery << idl0 << ";";
567 mocchiut 1.14 //
568     // printf("2myquery is %s \n",myquery.str().c_str());
569     //
570 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
571     this->GetGLTABLES()->AddQ();
572 mocchiut 1.14 pResult = dbc->Query(myquery.str().c_str());
573     //
574     Row = pResult->Next();
575     if( Row != NULL ){
576     fileL0 = (TString)Row->GetField(0);
577     };
578     //
579     //
580     //
581     myquery.str("");
582     myquery << " SELECT NAME FROM GL_ROOT WHERE ID=";
583 mocchiut 1.15 myquery << idl2 << ";";
584 mocchiut 1.14 //
585     // printf("3myquery is %s \n",myquery.str().c_str());
586     //
587 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
588     this->GetGLTABLES()->AddQ();
589 mocchiut 1.14 pResult = dbc->Query(myquery.str().c_str());
590     //
591     Row = pResult->Next();
592     if( Row != NULL ){
593     fileL2 = (TString)Row->GetField(0);
594     };
595     //
596     //
597     //
598     myquery.str("");
599     myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='";
600 mocchiut 1.15 myquery << fileL0.Data() << "' where ID_TRASH=";
601     myquery << idtrash << ";";
602 mocchiut 1.14 //
603     // printf("4myquery is %s \n",myquery.str().c_str());
604     //
605 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
606     this->GetGLTABLES()->AddQ();
607 mocchiut 1.14 dbc->Query(myquery.str().c_str());
608     //
609     myquery.str("");
610     myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='";
611 mocchiut 1.15 myquery << fileL2.Data() << "' where ID_TRASH=";
612     myquery << idtrash << ";";
613 mocchiut 1.14 //
614     // printf("4myquery is %s \n",myquery.str().c_str());
615     //
616 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
617     this->GetGLTABLES()->AddQ();
618 mocchiut 1.14 dbc->Query(myquery.str().c_str());
619     //
620     myquery.str("");
621     myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='";
622 mocchiut 1.15 myquery << FromTable.Data() << "' where ID_TRASH=";
623     myquery << idtrash << ";";
624 mocchiut 1.14 //
625     // printf("4myquery is %s \n",myquery.str().c_str());
626     //
627     //
628 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
629     this->GetGLTABLES()->AddQ();
630 mocchiut 1.14 dbc->Query(myquery.str().c_str());
631     //
632     myquery.str("");
633     myquery << " DELETE FROM ";
634     myquery << FromTable.Data() << " where ID=";
635     myquery << IDRUN << ";";
636     //
637     // printf("5myquery is %s \n",myquery.str().c_str());
638     //
639     //
640 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
641     this->GetGLTABLES()->AddQ();
642 mocchiut 1.14 dbc->Query(myquery.str().c_str());
643     //
644     return 0;
645     };
646    
647    
648    
649     /**
650 mocchiut 1.15 * This method restore a run from the GL_RUN_TRASH table.
651     * If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used.
652 mocchiut 1.14 *
653     **/
654 mocchiut 1.15 Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){
655 mocchiut 1.14 // insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11;
656     //insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11;
657 mocchiut 1.15 // MySQL variables
658     TSQLResult *pResult;
659     TSQLRow *Row;
660     stringstream myquery;
661     //
662     if ( !IDRUN ) IDRUN = ID;
663     if ( !IDRUN ) return 1;
664     //
665     if ( !strcmp(ToTable.Data(),"") ){
666     //
667     myquery.str("");
668     myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID=";
669     myquery << (UInt_t)IDRUN << ";";
670     //
671     printf(" qui? myquery is %s \n",myquery.str().c_str());
672     //
673 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
674     this->GetGLTABLES()->AddQ();
675 mocchiut 1.15 pResult = dbc->Query(myquery.str().c_str());
676     //
677     Row = pResult->Next();
678     if( Row != NULL ){
679     ToTable = (TString)Row->GetField(0);
680     } else {
681     return 1;
682     };
683     };
684     // ----------------
685     myquery.str("");
686     myquery << " INSERT INTO ";
687     myquery << ToTable.Data();
688     myquery << " (";
689     myquery << "ID";
690     myquery << ",ID_RUN_FRAG";
691     myquery << ",ID_ROOT_L0";
692     myquery << ",ID_ROOT_L2";
693     myquery << ",RUNHEADER_TIME";
694     myquery << ",RUNTRAILER_TIME";
695     myquery << ",RUNHEADER_OBT";
696     myquery << ",RUNTRAILER_OBT";
697     myquery << ",RUNHEADER_PKT";
698     myquery << ",RUNTRAILER_PKT";
699     myquery << ",BOOT_NUMBER";
700     myquery << ",EV_FROM";
701     myquery << ",EV_TO";
702     myquery << ",NEVENTS";
703     myquery << ",PKT_COUNTER";
704     myquery << ",PKT_READY_COUNTER";
705     myquery << ",COMPILATIONTIMESTAMP";
706     myquery << ",FAV_WRK_SCHEDULE";
707     myquery << ",EFF_WRK_SCHEDULE";
708     myquery << ",PRH_VAR_TRG_MODE_A";
709     myquery << ",PRH_VAR_TRG_MODE_B";
710     myquery << ",ACQ_BUILD_INFO";
711     myquery << ",ACQ_VAR_INFO";
712     myquery << ",RM_ACQ_AFTER_CALIB";
713     myquery << ",RM_ACQ_SETTING_MODE";
714     myquery << ",TRK_CALIB_USED";
715     myquery << ",CAL_DSP_MASK";
716     myquery << ",LAST_TIMESYNC";
717     myquery << ",OBT_TIMESYNC";
718     myquery << ",VALIDATION";
719     myquery << ",INSERT_TIME";
720     myquery << ") SELECT ";
721     myquery << "ID";
722     myquery << ",ID_RUN_FRAG";
723     myquery << ",ID_ROOT_L0";
724     myquery << ",ID_ROOT_L2";
725     myquery << ",RUNHEADER_TIME";
726     myquery << ",RUNTRAILER_TIME";
727     myquery << ",RUNHEADER_OBT";
728     myquery << ",RUNTRAILER_OBT";
729     myquery << ",RUNHEADER_PKT";
730     myquery << ",RUNTRAILER_PKT";
731     myquery << ",BOOT_NUMBER";
732     myquery << ",EV_FROM";
733     myquery << ",EV_TO";
734     myquery << ",NEVENTS";
735     myquery << ",PKT_COUNTER";
736     myquery << ",PKT_READY_COUNTER";
737     myquery << ",COMPILATIONTIMESTAMP";
738     myquery << ",FAV_WRK_SCHEDULE";
739     myquery << ",EFF_WRK_SCHEDULE";
740     myquery << ",PRH_VAR_TRG_MODE_A";
741     myquery << ",PRH_VAR_TRG_MODE_B";
742     myquery << ",ACQ_BUILD_INFO";
743     myquery << ",ACQ_VAR_INFO";
744     myquery << ",RM_ACQ_AFTER_CALIB";
745     myquery << ",RM_ACQ_SETTING_MODE";
746     myquery << ",TRK_CALIB_USED";
747     myquery << ",CAL_DSP_MASK";
748     myquery << ",LAST_TIMESYNC";
749     myquery << ",OBT_TIMESYNC";
750     myquery << ",VALIDATION";
751     myquery << ",INSERT_TIME";
752     myquery << " FROM GL_RUN_TRASH ";
753     myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID=";
754     myquery << (UInt_t)IDRUN << ";";
755     //
756     // printf("5myquery is %s \n",myquery.str().c_str());
757     //
758 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
759     this->GetGLTABLES()->AddQ();
760 mocchiut 1.15 dbc->Query(myquery.str().c_str());
761     //
762     //
763     myquery.str("");
764     myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID=";
765     myquery << IDRUN << ";";
766     //
767 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
768     this->GetGLTABLES()->AddQ();
769 mocchiut 1.15 dbc->Query(myquery.str().c_str());
770     //
771 mocchiut 1.14 return 0;
772     };
773 mocchiut 1.1
774     /**
775     * Function to fill the GL_RUN table of the DB.
776     *
777     * \param
778     *
779     */
780     Int_t GL_RUN::Fill_GL_RUN(TSQLServer *dbc){
781     // MySQL variables
782     stringstream myquery;
783     // ----------------
784     myquery.str("");
785     myquery << " INSERT INTO GL_RUN (";
786     myquery << "ID";
787     myquery << ",ID_RUN_FRAG";
788     myquery << ",ID_ROOT_L0";
789     myquery << ",ID_ROOT_L2";
790     myquery << ",RUNHEADER_TIME";
791     myquery << ",RUNTRAILER_TIME";
792     myquery << ",RUNHEADER_OBT";
793     myquery << ",RUNTRAILER_OBT";
794     myquery << ",RUNHEADER_PKT";
795     myquery << ",RUNTRAILER_PKT";
796     myquery << ",EV_FROM";
797     myquery << ",EV_TO";
798     myquery << ",NEVENTS";
799     myquery << ",LAST_TIMESYNC";
800     myquery << ",OBT_TIMESYNC";
801     myquery << ",COMPILATIONTIMESTAMP";
802     myquery << ",FAV_WRK_SCHEDULE";
803     myquery << ",EFF_WRK_SCHEDULE";
804     myquery << ",PRH_VAR_TRG_MODE_A";
805     myquery << ",PRH_VAR_TRG_MODE_B";
806     myquery << ",ACQ_BUILD_INFO";
807     myquery << ",ACQ_VAR_INFO";
808     myquery << ",RM_ACQ_AFTER_CALIB";
809     myquery << ",RM_ACQ_SETTING_MODE";
810     myquery << ",PKT_COUNTER";
811     myquery << ",PKT_READY_COUNTER";
812     myquery << ",TRK_CALIB_USED";
813     myquery << ",CAL_DSP_MASK";
814     myquery << ",BOOT_NUMBER";
815     myquery << ",VALIDATION";
816     myquery << ") VALUES ('";
817    
818     myquery << (UInt_t)ID << "','";
819     myquery << (UInt_t)ID_RUN_FRAG << "','";
820     myquery << (UInt_t)ID_ROOT_L0 << "','";
821     myquery << (UInt_t)ID_ROOT_L2 << "','";
822     myquery << (UInt_t)RUNHEADER_TIME << "','";
823     myquery << (UInt_t)RUNTRAILER_TIME << "','";
824     myquery << (UInt_t)RUNHEADER_OBT << "','";
825     myquery << (UInt_t)RUNTRAILER_OBT << "','";
826     myquery << (UInt_t)RUNHEADER_PKT << "','";
827     myquery << (UInt_t)RUNTRAILER_PKT << "','";
828     myquery << (UInt_t)EV_FROM << "','";
829     myquery << (UInt_t)EV_TO << "','";
830     myquery << (UInt_t)NEVENTS << "','";
831     myquery << (UInt_t)LAST_TIMESYNC << "','";
832     myquery << (UInt_t)OBT_TIMESYNC << "','";
833     myquery << (UInt_t)COMPILATIONTIMESTAMP << "','";
834     myquery << (UInt_t)FAV_WRK_SCHEDULE << "','";
835     myquery << (UInt_t)EFF_WRK_SCHEDULE << "','";
836     myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','";
837     myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','";
838     myquery << (UInt_t)ACQ_BUILD_INFO << "','";
839     myquery << (UInt_t)ACQ_VAR_INFO << "','";
840     myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','";
841     myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','";
842     myquery << (UInt_t)PKT_COUNTER << "','";
843     myquery << (UInt_t)PKT_READY_COUNTER << "','";
844     myquery << (UInt_t)TRK_CALIB_USED << "','";
845     myquery << (UInt_t)CAL_DSP_MASK << "','";
846     myquery << (UInt_t)BOOT_NUMBER << "','";
847     myquery << (UInt_t)VALIDATION << "');";
848     //
849 mocchiut 1.2 // printf("myquery is %s \n",myquery.str().c_str());
850 mocchiut 1.1 //
851 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
852     this->GetGLTABLES()->AddQ();
853 mocchiut 1.1 dbc->Query(myquery.str().c_str());
854     //
855     return 0;
856    
857     };// ****************************************************
858    
859     /**
860     * Function to fill the GL_RUN table of the DB.
861     *
862     * \param
863     *
864     */
865     Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQLServer *dbc){
866     // MySQL variables
867     stringstream myquery;
868     // ----------------
869     myquery.str("");
870     myquery << " INSERT INTO GL_RUN_FRAGMENTS (";
871     myquery << "ID";
872     myquery << ",ID_ROOT_L0";
873     myquery << ",RUNHEADER_TIME";
874     myquery << ",RUNTRAILER_TIME";
875     myquery << ",RUNHEADER_OBT";
876     myquery << ",RUNTRAILER_OBT";
877     myquery << ",RUNHEADER_PKT";
878     myquery << ",RUNTRAILER_PKT";
879     myquery << ",EV_FROM";
880     myquery << ",EV_TO";
881     myquery << ",NEVENTS";
882     myquery << ",LAST_TIMESYNC";
883     myquery << ",OBT_TIMESYNC";
884     myquery << ",COMPILATIONTIMESTAMP";
885     myquery << ",FAV_WRK_SCHEDULE";
886     myquery << ",EFF_WRK_SCHEDULE";
887     myquery << ",PRH_VAR_TRG_MODE_A";
888     myquery << ",PRH_VAR_TRG_MODE_B";
889     myquery << ",ACQ_BUILD_INFO";
890     myquery << ",ACQ_VAR_INFO";
891     myquery << ",RM_ACQ_AFTER_CALIB";
892     myquery << ",RM_ACQ_SETTING_MODE";
893     myquery << ",PKT_COUNTER";
894     myquery << ",PKT_READY_COUNTER";
895     myquery << ",TRK_CALIB_USED";
896     myquery << ",CAL_DSP_MASK";
897     myquery << ",BOOT_NUMBER";
898     myquery << ") VALUES ('";
899     myquery << (UInt_t)ID << "','";
900     myquery << (UInt_t)ID_ROOT_L0 << "','";
901     myquery << (UInt_t)RUNHEADER_TIME << "','";
902     myquery << (UInt_t)RUNTRAILER_TIME << "','";
903     myquery << (UInt_t)RUNHEADER_OBT << "','";
904     myquery << (UInt_t)RUNTRAILER_OBT << "','";
905     myquery << (UInt_t)RUNHEADER_PKT << "','";
906     myquery << (UInt_t)RUNTRAILER_PKT << "','";
907     myquery << (UInt_t)EV_FROM << "','";
908     myquery << (UInt_t)EV_TO << "','";
909     myquery << (UInt_t)NEVENTS << "','";
910     myquery << (UInt_t)LAST_TIMESYNC << "','";
911     myquery << (UInt_t)OBT_TIMESYNC << "','";
912     myquery << (UInt_t)COMPILATIONTIMESTAMP << "','";
913     myquery << (UInt_t)FAV_WRK_SCHEDULE << "','";
914     myquery << (UInt_t)EFF_WRK_SCHEDULE << "','";
915     myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','";
916     myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','";
917     myquery << (UInt_t)ACQ_BUILD_INFO << "','";
918     myquery << (UInt_t)ACQ_VAR_INFO << "','";
919     myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','";
920     myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','";
921     myquery << (UInt_t)PKT_COUNTER << "','";
922     myquery << (UInt_t)PKT_READY_COUNTER << "','";
923     myquery << (UInt_t)TRK_CALIB_USED << "','";
924     myquery << (UInt_t)CAL_DSP_MASK << "','";
925     myquery << (UInt_t)BOOT_NUMBER << "');";
926     //
927     // printf("myquery is %s \n",myquery.str().c_str());
928     //
929 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
930     this->GetGLTABLES()->AddQ();
931 mocchiut 1.1 dbc->Query(myquery.str().c_str());
932     //
933     return 0;
934    
935     };// ****************************************************
936    
937    
938     /**
939     * Function to query the GL_RUN table of the DB.
940     *
941     * \param RUN id
942     * \return struct of type GL_RUN _data, which stores the query result
943     *
944     */
945     Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){
946     // MySQL variables
947     TSQLResult *pResult;
948     TSQLRow *Row;
949     int t;
950     int r;
951     stringstream myquery;
952     // ----------------
953     myquery.str("");
954     myquery << " select ";
955     myquery << "ID";
956     myquery << ",ID_RUN_FRAG";
957     myquery << ",ID_ROOT_L0";
958     myquery << ",ID_ROOT_L2";
959     myquery << ",RUNHEADER_TIME";
960     myquery << ",RUNTRAILER_TIME";
961     myquery << ",RUNHEADER_OBT";
962     myquery << ",RUNTRAILER_OBT";
963     myquery << ",RUNHEADER_PKT";
964     myquery << ",RUNTRAILER_PKT";
965     myquery << ",EV_FROM";
966     myquery << ",EV_TO";
967     myquery << ",NEVENTS";
968     myquery << ",LAST_TIMESYNC";
969     myquery << ",OBT_TIMESYNC";
970     myquery << ",COMPILATIONTIMESTAMP";
971     myquery << ",FAV_WRK_SCHEDULE";
972     myquery << ",EFF_WRK_SCHEDULE";
973     myquery << ",PRH_VAR_TRG_MODE_A";
974     myquery << ",PRH_VAR_TRG_MODE_B";
975     myquery << ",ACQ_BUILD_INFO";
976     myquery << ",ACQ_VAR_INFO";
977     myquery << ",RM_ACQ_AFTER_CALIB";
978     myquery << ",RM_ACQ_SETTING_MODE";
979     myquery << ",PKT_COUNTER";
980     myquery << ",PKT_READY_COUNTER";
981     myquery << ",TRK_CALIB_USED";
982     myquery << ",CAL_DSP_MASK";
983     myquery << ",BOOT_NUMBER";
984     myquery << ",VALIDATION";
985     myquery << " from GL_RUN where ID=" << run << ";";
986     //
987 mocchiut 1.4 // printf(" myquery is %s \n",myquery.str().c_str());
988 mocchiut 1.22 if ( !this->IsConnected(dbc) ) return -57;
989     this->AddQ();
990 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
991 mocchiut 1.4 //
992     // printf(" getrowcount %i \n",pResult->GetRowCount());
993     //
994     if( !pResult->GetRowCount() ) return(-50);
995     //
996 mocchiut 1.1 for( r=0; r < 1000; r++){
997     Row = pResult->Next();
998     if( Row == NULL ) break;
999 pam-fi 1.9 // Set_GL_RUN(Row);
1000 mocchiut 1.1 for( t = 0; t < pResult->GetFieldCount(); t++){
1001 mocchiut 1.16 if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
1002     if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
1003     if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1004     if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
1005     if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
1006     if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
1007     if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
1008     if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
1009     if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
1010     if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
1011     if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t));
1012     if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t));
1013     if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t));
1014     if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1015     if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1016     if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
1017     if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
1018     if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
1019     if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
1020     if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
1021     if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
1022     if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
1023     if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
1024     if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
1025     if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
1026     if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
1027     if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
1028     if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
1029     if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
1030     if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
1031 mocchiut 1.1 };
1032     };
1033 mocchiut 1.4 // delete pResult;
1034     return(0);
1035 mocchiut 1.1 };
1036    
1037     /**
1038     * Function to query the GL_RUN table of the DB.
1039     *
1040     * \param where = condition string
1041     * \return struct of type GL_RUN _data, which stores the query result
1042     *
1043     */
1044     Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){
1045     // MySQL variables
1046     TSQLResult *pResult;
1047     TSQLRow *Row;
1048     int t;
1049     int r;
1050     stringstream myquery;
1051     // ----------------
1052     myquery.str("");
1053     myquery << " select ";
1054     myquery << "ID";
1055 mocchiut 1.2 myquery << ",ID_RUN_FRAG";
1056 mocchiut 1.1 myquery << ",ID_ROOT_L0";
1057 mocchiut 1.2 myquery << ",ID_ROOT_L2";
1058 mocchiut 1.1 myquery << ",RUNHEADER_TIME";
1059     myquery << ",RUNTRAILER_TIME";
1060     myquery << ",RUNHEADER_OBT";
1061     myquery << ",RUNTRAILER_OBT";
1062     myquery << ",RUNHEADER_PKT";
1063     myquery << ",RUNTRAILER_PKT";
1064     myquery << ",EV_FROM";
1065     myquery << ",EV_TO";
1066     myquery << ",NEVENTS";
1067     myquery << ",LAST_TIMESYNC";
1068     myquery << ",OBT_TIMESYNC";
1069     myquery << ",COMPILATIONTIMESTAMP";
1070     myquery << ",FAV_WRK_SCHEDULE";
1071     myquery << ",EFF_WRK_SCHEDULE";
1072     myquery << ",PRH_VAR_TRG_MODE_A";
1073     myquery << ",PRH_VAR_TRG_MODE_B";
1074     myquery << ",ACQ_BUILD_INFO";
1075     myquery << ",ACQ_VAR_INFO";
1076     myquery << ",RM_ACQ_AFTER_CALIB";
1077     myquery << ",RM_ACQ_SETTING_MODE";
1078     myquery << ",PKT_COUNTER";
1079     myquery << ",PKT_READY_COUNTER";
1080     myquery << ",TRK_CALIB_USED";
1081     myquery << ",CAL_DSP_MASK";
1082     myquery << ",BOOT_NUMBER";
1083 mocchiut 1.2 myquery << ",VALIDATION";
1084 mocchiut 1.1 myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";";
1085     //
1086 mocchiut 1.2 // printf(" query is %s \n",myquery.str().c_str());
1087     //
1088 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1089     this->GetGLTABLES()->AddQ();
1090 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1091     if(!pResult->GetRowCount())return(-50);
1092     for( r=0; r < 1000; r++){
1093 mocchiut 1.2 Row = pResult->Next();
1094     if( Row == NULL ) break;
1095     for( t = 0; t < pResult->GetFieldCount(); t++){
1096     if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
1097     if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
1098     if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1099     if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
1100     if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
1101     if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
1102     if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
1103     if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
1104     if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
1105     if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
1106     if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t));
1107     if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t));
1108     if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t));
1109     if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1110     if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1111     if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
1112     if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
1113     if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
1114     if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
1115     if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
1116     if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
1117     if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
1118     if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
1119     if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
1120     if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
1121     if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
1122     if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
1123     if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
1124     if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
1125     if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
1126     };
1127 mocchiut 1.1 };
1128 mocchiut 1.2 // delete pResult;
1129     return(0);
1130     };// ****************************************************
1131 mocchiut 1.1
1132     /**
1133     * Function to query the GL_ROOT table of the DB.
1134     *
1135     * \param entry ID
1136     * \return struct of type GL_ROOT_data, which stores the query result
1137     */
1138     Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){
1139     // MySQL variables
1140     TSQLResult *pResult;
1141     TSQLRow *Row;
1142     int t;
1143     int r;
1144     stringstream myquery;
1145     // ----------------
1146     myquery.str("");
1147     myquery << "select ";
1148     myquery << " ID";
1149     myquery << ",ID_RAW";
1150     myquery << ",ID_TIMESYNC";
1151     myquery << ",PATH";
1152     myquery << ",NAME";
1153     myquery << " from GL_ROOT where ID=" << id << ";";
1154     //
1155 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1156     this->GetGLTABLES()->AddQ();
1157 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1158     if(!pResult->GetRowCount())return (-51);
1159     for( r=0; r < 1000; r++){
1160     Row = pResult->Next();
1161     if( Row == NULL ) break;
1162     for( t = 0; t < pResult->GetFieldCount(); t++){
1163     if(t==0) ID = (UInt_t)atoll(Row->GetField(t));
1164     if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));
1165     if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1166 mocchiut 1.26 if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';
1167 mocchiut 1.1 if(t==4) NAME = Row->GetField(t);
1168     };
1169     };
1170     delete pResult;
1171     return 0;
1172     };
1173     // ****************************************************
1174     /**
1175     * Function to query the GL_TRK_CALIB table of the DB.
1176     *
1177     * \param run starting time
1178 pam-fi 1.9 * \param dbc DB server
1179 mocchiut 1.1 * \return struct of type GL_TRK_CALIB_data, which stores the query result
1180     */
1181     Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){
1182     // MySQL variables
1183     TSQLResult *pResult;
1184     TSQLRow *Row;
1185     int t;
1186     int r;
1187     stringstream myquery;
1188     // ----------------
1189     myquery.str("");
1190 pam-fi 1.9 myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2,BOOT_NUMBER,VALIDATION from GL_TRK_CALIB where FROM_TIME <= "<< time;
1191 pam-fi 1.24 // myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!!
1192 mocchiut 1.29 myquery << " and EV_ROOT_CALIBTRK1>=0 and EV_ROOT_CALIBTRK2>=0 "; // EM! SE MANCA UN PACCHETTO DEI DUE IL PROCESSAMENTO CRASHA... DA RIVEDERE LA VALIDAZIONE
1193 pam-fi 1.24 myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
1194 mocchiut 1.1 // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
1195 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1196     this->GetGLTABLES()->AddQ();
1197 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1198     if(!pResult->GetRowCount())return (-53);
1199     for( r=0; r < 1000; r++){
1200     Row = pResult->Next();
1201     if( Row == NULL ) break;
1202     for( t = 0; t < pResult->GetFieldCount(); t++){
1203 mocchiut 1.2 stringstream row;
1204     row.str("");
1205     row << "0" << Row->GetField(t); // add leading 0 since we have two fields that could be "null" and we want to avoid crashes due to atoll
1206 pam-fi 1.9 if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
1207     if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1208 mocchiut 1.2 if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str());
1209     if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str());
1210 pam-fi 1.9 if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1211     if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1212 mocchiut 1.1 //
1213 pam-fi 1.9 if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t));
1214     if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t));
1215     if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t));
1216     if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t));
1217     if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
1218     if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t));
1219     };
1220 mocchiut 1.1 };
1221 pam-fi 1.9 delete pResult;
1222 mocchiut 1.1 //
1223 pam-fi 1.9 // if ( TO_TIME < time ) return(51);
1224 mocchiut 1.8 //
1225 mocchiut 1.1 if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING!
1226     //
1227     return 0;
1228     };
1229    
1230     // ****************************************************
1231     /**
1232     * Function to query the GL_CALO_CALIB table of the DB.
1233     *
1234     * \param run starting time
1235     * \return struct of type GL_CALO_CALIB_data, which stores the query result
1236     */
1237 mocchiut 1.7 Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){
1238 mocchiut 1.1 // MySQL variables
1239     TSQLResult *pResult;
1240     TSQLRow *Row;
1241     int t;
1242     stringstream myquery;
1243 mocchiut 1.7 uptime = 0;
1244 mocchiut 1.1 //
1245     // select the correct calibration
1246     //
1247     myquery.str("");
1248     myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
1249     myquery << " and FROM_TIME <= " << time;
1250     myquery << " and TO_TIME > " << time;
1251 mocchiut 1.7 myquery << " ;";
1252     //myquery << " and VALIDATION=1;";
1253 mocchiut 1.1 //
1254 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1255     this->GetGLTABLES()->AddQ();
1256 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1257 mocchiut 1.7 // printf(" mysquery is %s\n",myquery.str().c_str());
1258     //
1259     if( !pResult->GetRowCount() ) return(-54);
1260     Row = pResult->Next();
1261     if( Row == NULL ) return (-54);
1262     //
1263     uptime = (UInt_t)atoll(Row->GetField(2));
1264 mocchiut 1.1 //
1265     // if it is corrupted validation is 0 and we have no results from the query...
1266     //
1267 mocchiut 1.7 if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0
1268 mocchiut 1.1 //
1269     // in this case take relax the conditions and take the valid calibration that preceed the correct one
1270     //
1271     myquery.str("");
1272     myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
1273     myquery << " and FROM_TIME <= " << time;
1274     myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
1275 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1276     this->GetGLTABLES()->AddQ();
1277 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1278 mocchiut 1.7 // printf(" mysquery is %s\n",myquery.str().c_str());
1279 mocchiut 1.1 //
1280     // if no results yet quit with error
1281     //
1282     if( !pResult->GetRowCount() ) return (-54);
1283 mocchiut 1.7 //
1284     Row = pResult->Next();
1285     //
1286 mocchiut 1.1 };
1287     //
1288     // store infos and exit
1289     //
1290     if( Row == NULL ) return (-54);
1291     for( t = 0; t < pResult->GetFieldCount(); t++){
1292     if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1293     if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1294     if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1295     if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
1296     };
1297     pResult->Delete();
1298     return 0;
1299     };
1300     // ****************************************************
1301     /**
1302     * Function to query the GL_S4_CALIB table of the DB.
1303     *
1304     * \param run starting time
1305     * \return struct of type GL_S4_CALIB_data, which stores the query result
1306     */
1307     Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){
1308     // MySQL variables
1309     TSQLResult *pResult;
1310     TSQLRow *Row;
1311     int t;
1312     int r;
1313     stringstream myquery;
1314     // ----------------
1315     myquery.str("");
1316     myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
1317 mocchiut 1.5 myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
1318 mocchiut 1.1 // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
1319 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1320     this->GetGLTABLES()->AddQ();
1321 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1322     if(!pResult->GetRowCount())return (-55);//throw -55;
1323     for( r=0; r < 1000; r++){
1324     Row = pResult->Next();
1325     if( Row == NULL ) break;
1326     for( t = 0; t < pResult->GetFieldCount(); t++){
1327     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
1328     if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1329     if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
1330     if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1331     if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1332     if (t==5) PARAM_FIT0 = atof(Row->GetField(t));
1333     if (t==6) PARAM_FIT1 = atof(Row->GetField(t));
1334     };
1335     };
1336     delete pResult;
1337     //
1338     if(TO_TIME < time)return(51);
1339     //
1340     return 0;
1341     };
1342     // ****************************************************
1343     /**
1344     * Function to query the GL_PARAM table of the DB.
1345     *
1346     * \param run starting time
1347     * \param parameter description (DESCR)
1348     * \return struct of type GL_ROOT_data, which stores the query result
1349     */
1350     Int_t GL_PARAM::Query_GL_PARAM(UInt_t time, UInt_t type, TSQLServer *dbc){
1351     // Bool_t debug = 1;
1352     // MySQL variables
1353     TSQLResult *pResult;
1354     TSQLRow *Row;
1355     int t;
1356     int r;
1357     stringstream myquery;
1358     // ----------------
1359     myquery.str("");
1360     myquery << " select ";
1361 mocchiut 1.25 myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE ";
1362 mocchiut 1.1 myquery << " from GL_PARAM ";
1363     myquery << " where TYPE = '"<<type<<"' ";
1364     myquery << " and FROM_TIME <= " << time;
1365     myquery << " ORDER BY TO_TIME DESC LIMIT 1;";
1366     //
1367 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1368     this->GetGLTABLES()->AddQ();
1369 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1370     if(!pResult->GetRowCount())return (-52);
1371     for( r=0; r < 1000; r++){
1372     Row = pResult->Next();
1373     if( Row == NULL ) break;
1374     for( t = 0; t < pResult->GetFieldCount(); t++){
1375     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
1376 mocchiut 1.26 if (t==1) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';// put in fpath the path to that file
1377 mocchiut 1.1 if (t==2) NAME = Row->GetField(t);
1378     if (t==3) DESCR = Row->GetField(t);
1379     if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1380     if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1381     if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t));
1382     };
1383     };
1384     delete pResult;
1385     //
1386     if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max();
1387     //
1388     if(TO_TIME < time) return(51);
1389     //
1390     return 0;
1391     };
1392    
1393    
1394     /**
1395     * Fills a struct cGLRun with values from a GLRun object (to put data into a F77 common).
1396     */
1397    
1398     void GL_RUN::GetLevel2Struct(cGLRun *l2) const{
1399     l2->id = ID;
1400     l2->id_reg_run = ID_ROOT_L0;
1401     l2->id_reg_run_l2 = ID_ROOT_L2;
1402     l2->runheader_time = RUNHEADER_TIME;
1403     l2->runtrailer_time = RUNTRAILER_TIME;
1404     l2->ev_from = EV_FROM;
1405     l2->trk_calib_used = TRK_CALIB_USED;
1406     l2->eff_wrk_schedule = EFF_WRK_SCHEDULE;
1407     l2->prh_var_trg_mode_a = PRH_VAR_TRG_MODE_A;
1408     l2->prh_var_trg_mode_b = PRH_VAR_TRG_MODE_B;
1409     l2->acq_build_info = ACQ_BUILD_INFO;
1410     l2->acq_var_info = ACQ_VAR_INFO;
1411     };
1412    
1413     GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
1414     // MySQL variables
1415     TFile *file = 0;
1416     UInt_t idraw = 0;
1417     //
1418     TSQLResult *pResult;
1419     TSQLRow *Row;
1420     stringstream myquery;
1421 mocchiut 1.14 stringstream rname;
1422 mocchiut 1.23 // pcksList packetsNames;
1423     // pcksList::iterator Iter;
1424     // getPacketsNames(packetsNames);
1425 mocchiut 1.14 rname.str("");
1426 mocchiut 1.1 // ----------------
1427     myquery.str("");
1428     myquery << "select ";
1429     myquery << "PATH";
1430     myquery << ",NAME,ID_RAW";
1431     myquery << " from GL_ROOT where ";
1432     myquery << type.Data();
1433     myquery << "=" << id << ";";
1434     //
1435 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;
1436     this->GetGLTABLES()->AddQ();
1437 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1438     if( pResult->GetRowCount() ){
1439     Row = pResult->Next();
1440     if( Row ){
1441     stringstream fname;
1442     fname.str("");
1443 mocchiut 1.26 fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1444 mocchiut 1.14 rname << Row->GetField(1);
1445 mocchiut 1.1 file = new TFile(fname.str().c_str(),"READ");
1446     idraw = (UInt_t)atoll(Row->GetField(2));
1447     };
1448     };
1449     //
1450     if ( file && file->IsOpen() ){
1451     TTree *T=(TTree*)file->Get("Physics");
1452     pamela::EventHeader *eh = 0;
1453     pamela::PscuHeader *ph = 0;
1454     T->SetBranchAddress("Header", &eh);
1455     //
1456     T->GetEntry(0);
1457     ph = eh->GetPscuHeader();
1458     pktfirst = ph->GetCounter();
1459     obtfirst = ph->GetOrbitalTime();
1460 mocchiut 1.23 //
1461     // code = eh->GetCounter();
1462     // UInt_t en = 0;
1463     // for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
1464     // en = code->Get(GetPacketType(*Iter));
1465     // if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){
1466     // //
1467     // TTree *TC = 0;
1468     // TC = (TTree*)file->Get("CalibCalPed");
1469     // if ( !TC || TC->IsZombie() ) return;
1470     // EventHeader *ehc = 0;
1471     // PscuHeader *phc = 0;
1472     // TC->SetBranchAddress("Header", &ehc);
1473     // TC->GetEntry(0);
1474     // phc = ehc->GetPscuHeader();
1475     // pktfirst = phc->GetCounter();
1476     // obtfirst = phc->GetOrbitalTime();
1477     // //
1478     // };
1479     // };
1480     //
1481 mocchiut 1.1 };
1482     //
1483     // look for Resurs offset
1484     //
1485 mocchiut 1.17 T0 = 0;
1486 mocchiut 1.1 //
1487 mocchiut 1.14 //
1488     stringstream oss;
1489 mocchiut 1.27 TString frn = rname.str().c_str();
1490     frn = frn.ReplaceAll(".root",5,".pam",4);
1491 mocchiut 1.14 oss.str("");
1492 mocchiut 1.18 oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"
1493 mocchiut 1.27 << frn.Data() << "';";
1494 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;
1495     this->GetGLTABLES()->AddQ();
1496 mocchiut 1.14 pResult = dbc->Query(oss.str().c_str());
1497     Row = pResult->Next();
1498     //
1499     TString name=rname.str().c_str();
1500     UInt_t dworbit = 0;
1501     Int_t nlength = name.Length();
1502     if ( nlength < 5 ) return;
1503     TString dwo = 0;
1504     for (Int_t i = 0; i<5; i++){
1505     dwo.Append(name[i],1);
1506     };
1507     if ( dwo.IsDigit() ){
1508     dworbit = (UInt_t)dwo.Atoi();
1509     } else {
1510     dwo="";
1511     for (Int_t i = 8; i<13; i++){
1512     dwo.Append(name[i],1);
1513     };
1514 mocchiut 1.23 if ( dwo.IsDigit() ){
1515     dworbit = (UInt_t)dwo.Atoi();
1516     } else {
1517     dworbit = 1;
1518     };
1519 mocchiut 1.14 };
1520     //
1521 mocchiut 1.23 //
1522 mocchiut 1.14 if ( !Row ){
1523     oss.str("");
1524 mocchiut 1.18 oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "
1525 mocchiut 1.14 << dworbit << " order by FROM_ORBIT desc limit 1;";
1526 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;
1527     this->GetGLTABLES()->AddQ();
1528 mocchiut 1.14 pResult = dbc->Query(oss.str().c_str());
1529 mocchiut 1.1 Row = pResult->Next();
1530 mocchiut 1.14 if ( !Row ){
1531     printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1532     return;
1533 mocchiut 1.1 };
1534     };
1535     //
1536 mocchiut 1.18 TTimeStamp tu = TTimeStamp((UInt_t)atoi(Row->GetField(0)),(UInt_t)atoi(Row->GetField(1)),(UInt_t)atoi(Row->GetField(2)),(UInt_t)atoi(Row->GetField(3)),(UInt_t)atoi(Row->GetField(4)),(UInt_t)atoi(Row->GetField(5)),0,true,0);
1537 mocchiut 1.17 T0 = (UInt_t)tu.GetSec();
1538 mocchiut 1.1 //
1539     // look for the correct timesync entry
1540     //
1541     myquery.str("");
1542 mocchiut 1.17 myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "
1543 mocchiut 1.1 << " WHERE ID_RAW = " << idraw
1544     << ";";
1545 mocchiut 1.22 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;
1546     this->GetGLTABLES()->AddQ();
1547 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
1548     if ( pResult ){
1549     Row = pResult->Next();
1550     if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){
1551 mocchiut 1.17 OBT0 = (UInt_t)atoll(Row->GetField(0));
1552     TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1553     TYPE = (UInt_t)atoll(Row->GetField(2));
1554     toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0;
1555 mocchiut 1.1 };
1556     };
1557 mocchiut 1.3 //
1558     file->Close();
1559 mocchiut 1.1 delete pResult;
1560     };
1561    
1562     /**
1563     *
1564     * Returns the DB absolute time needed to associate calibrations to data
1565     *
1566     */
1567     UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){
1568     //
1569     return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1570     //
1571     };
1572    
1573 mocchiut 1.17 /**
1574     *
1575     * Returns the Resurs time given the OBT needed to process inclination and orbital infos
1576     *
1577     */
1578     UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){
1579     //
1580 mocchiut 1.19 return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC));
1581 mocchiut 1.17 //
1582     };
1583    
1584 mocchiut 1.1
1585 mocchiut 1.20 /**
1586     * Return the correct packet number if we went back to zero
1587     */
1588     Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){
1589 mocchiut 1.1 //
1590 mocchiut 1.20 if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){
1591     return((Long64_t)pkt_num+16777215LL);
1592     };
1593 mocchiut 1.1 //
1594 mocchiut 1.20 if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1595     return((Long64_t)pkt_num-16777215LL);
1596 mocchiut 1.1 };
1597     //
1598 mocchiut 1.20 return((Long64_t)pkt_num);
1599 mocchiut 1.1 //
1600     };
1601    
1602 mocchiut 1.20 /**
1603     * Return the correct On Board Time if we went back to zero
1604     */
1605     Long64_t GL_TIMESYNC::DBobt(UInt_t obt){
1606 mocchiut 1.1 //
1607 mocchiut 1.20 if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max()));
1608 mocchiut 1.1 //
1609 mocchiut 1.20 if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1610     return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
1611 mocchiut 1.1 };
1612     //
1613 mocchiut 1.20 return((Long64_t)obt);
1614 mocchiut 1.1 };
1615 mocchiut 1.5
1616 mocchiut 1.20
1617    
1618     // ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){
1619     // //
1620     // if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));
1621     // //
1622     // if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1623     // if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){
1624     // return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));
1625     // } else {
1626     // return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));
1627     // };
1628     // };
1629     // //
1630     // return((ULong64_t)obt);
1631     // //
1632     // };
1633    
1634     // UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){
1635     // //
1636     // if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215));
1637     // //
1638     // if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1639     // if ( (pkt_num-16777215) < 0 ){
1640     // return((16777215-pkt_num));
1641     // } else {
1642     // return((pkt_num-16777215));
1643     // };
1644     // };
1645     // //
1646     // return(pkt_num);
1647     // //
1648     // };
1649    
1650 mocchiut 1.5 /*
1651     *
1652     * Convert the time in the DB from UInt_t to a string
1653     *
1654     * @param dbt time in the DB
1655     * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
1656     *
1657     */
1658 mocchiut 1.10 TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){
1659 mocchiut 1.5 //
1660 mocchiut 1.16 Int_t offset = 0;
1661 mocchiut 1.5 TString rtime;
1662 mocchiut 1.10 Bool_t found = false;
1663 mocchiut 1.5 //
1664 mocchiut 1.11 if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){
1665 mocchiut 1.5 //
1666 mocchiut 1.16 offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time
1667 mocchiut 1.10 found = true;
1668 mocchiut 1.5 //
1669     };
1670     //
1671     if ( !strcmp(tzone.Data(),"CET") ){
1672     //
1673 mocchiut 1.16 offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs
1674 mocchiut 1.10 found = true;
1675 mocchiut 1.5 //
1676     };
1677     //
1678     if ( !strcmp(tzone.Data(),"CEST") ){
1679     //
1680 mocchiut 1.16 offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h
1681 mocchiut 1.10 found = true;
1682 mocchiut 1.5 //
1683     };
1684     //
1685 mocchiut 1.11 if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){
1686 mocchiut 1.5 //
1687 mocchiut 1.16 offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h
1688 mocchiut 1.10 found = true;
1689 mocchiut 1.5 //
1690     };
1691     //
1692 mocchiut 1.11 if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){
1693     printf("\n Unknown time zone %s using UTC \n",tzone.Data());
1694     tzone = "UTC";
1695 mocchiut 1.10 };
1696     //
1697 mocchiut 1.16 dbt += offset;
1698     //
1699     TTimeStamp *time = new TTimeStamp((time_t)dbt,0);
1700     //
1701     rtime = time->AsString("s");
1702     //
1703     delete time;
1704 mocchiut 1.5 //
1705     return(rtime);
1706     }
1707 mocchiut 1.6
1708     /*
1709     *
1710 mocchiut 1.16 * Convert the time from TZONE to UTC
1711 mocchiut 1.6 *
1712     * @param dbt time in the DB
1713     * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
1714     *
1715     */
1716 mocchiut 1.10 TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){
1717 mocchiut 1.6 //
1718 mocchiut 1.16 Int_t offset = 0;
1719 mocchiut 1.6 TString rtime;
1720     //
1721 mocchiut 1.10 Bool_t found = false;
1722     //
1723 mocchiut 1.11 if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){
1724 mocchiut 1.6 //
1725 mocchiut 1.16 offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs
1726 mocchiut 1.10 found = true;
1727 mocchiut 1.6 //
1728     };
1729     //
1730     if ( !strcmp(tzone.Data(),"CET") ){
1731     //
1732 mocchiut 1.16 offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC
1733 mocchiut 1.10 found = true;
1734 mocchiut 1.6 //
1735     };
1736     //
1737     if ( !strcmp(tzone.Data(),"CEST") ){
1738     //
1739 mocchiut 1.16 offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC
1740 mocchiut 1.10 found = true;
1741 mocchiut 1.6 //
1742     };
1743     //
1744 mocchiut 1.10 if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){
1745 mocchiut 1.6 //
1746 mocchiut 1.16 offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC
1747 mocchiut 1.10 found = true;
1748     //
1749     };
1750     //
1751 mocchiut 1.11 if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){
1752 mocchiut 1.6 //
1753 mocchiut 1.16 offset = 0;
1754 mocchiut 1.11 printf("\n Unknown time zone %s using UTC \n",tzone.Data());
1755     tzone = "UTC";
1756 mocchiut 1.6 };
1757     //
1758 mocchiut 1.16 dbt += offset;
1759     TTimeStamp *time = new TTimeStamp((time_t)dbt,0);
1760     //
1761     rtime = time->AsString("s");
1762 mocchiut 1.6 //
1763     return(rtime);
1764     }
1765 mocchiut 1.12
1766    
1767 mocchiut 1.21 //
1768     // Build a query and call DoQuery.
1769     //
1770     // date it's an SQL datetime date and dbc is the connection to be
1771     // used. It will query for the tle with the nearest but previous date
1772     // and the immediatly next one.
1773     //
1774     Int_t GL_TLE::Query(TString date, TSQLServer *dbc){
1775 mocchiut 1.12 stringstream myquery;
1776     myquery.str("");
1777    
1778 mocchiut 1.21 myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1779     << "WHERE FROM_TIME <= '" << date.Data()
1780     << "' ORDER BY FROM_TIME DESC LIMIT 1) "
1781     << "UNION "
1782     << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1783     << "WHERE FROM_TIME > '" << date.Data()
1784     << "' ORDER BY FROM_TIME ASC LIMIT 1)";
1785 mocchiut 1.12
1786 mocchiut 1.21 return DoQuery(myquery.str().c_str(), dbc);
1787 mocchiut 1.12 }
1788    
1789    
1790 mocchiut 1.21 //
1791     // Build a query and call DoQuery.
1792     //
1793     // time is the UTC date in unix time (UTC) and dbc is the connection
1794     // to be used. It will query for the tle with the nearest but
1795     // previous date and the immediatly next one.
1796     //
1797     // Returns the value returned by DoQuery().
1798     //
1799     Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){
1800 mocchiut 1.12 stringstream myquery;
1801     myquery.str("");
1802    
1803 mocchiut 1.21 myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1804     << "WHERE FROM_TIME <= FROM_UNIXTIME('" << time
1805     << "') ORDER BY FROM_TIME DESC LIMIT 1) "
1806     << "UNION "
1807     << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1808     << "WHERE FROM_TIME > FROM_UNIXTIME('" << time
1809     << "') ORDER BY FROM_TIME ASC LIMIT 1)";
1810 mocchiut 1.12
1811 mocchiut 1.21 return DoQuery(myquery.str().c_str(), dbc);
1812 mocchiut 1.12 }
1813    
1814    
1815 mocchiut 1.21 //
1816     // Do the query myquery on the connectio dbc. Initialize tle,
1817     // tleFromTime and tleToTime.
1818     //
1819     // We should have two rows (unless the table is old). From the last
1820     // one we only take tleToTime.
1821     //
1822     // Returns 0 for success, 1 for failure.
1823     //
1824     Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){
1825 mocchiut 1.12 TSQLResult *result;
1826     TSQLRow *row;
1827    
1828 mocchiut 1.21 // Set the right time_zone (otherwise horrible things will occur! :)
1829 mocchiut 1.30 if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;
1830 mocchiut 1.21 dbc->Query("SET time_zone = '+0:00'");
1831    
1832     // Do the query
1833 mocchiut 1.22 this->GetGLTABLES()->AddQ();
1834 mocchiut 1.12 result = dbc->Query(myquery.Data());
1835 mocchiut 1.21 if(! result->GetRowCount() ) {
1836     cerr << "GL_TLE: query failed: " << myquery.Data() << endl;
1837     return 1;
1838     }
1839    
1840     // Get results
1841     row = result->Next(); // first tle row
1842     tle = GiveTle(row);
1843    
1844     tleFromTime = strtol(row->GetField(4), NULL, 10);
1845    
1846     row = result->Next(); // second tle row
1847     if(row)
1848     tleToTime = strtol(row->GetField(4), NULL, 10);
1849     else {
1850     cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n";
1851     tleToTime = UINT_MAX;
1852     }
1853    
1854     delete row;
1855     delete result;
1856 mocchiut 1.12
1857 mocchiut 1.21 return 0;
1858     }
1859 mocchiut 1.12
1860    
1861 mocchiut 1.21 //
1862     // Build a cTle object from the GL_TLE row.
1863     //
1864     cTle* GL_TLE::GiveTle(TSQLRow *row) {
1865     cTle *thistle = NULL;
1866     string tle1, tle2, tle3;
1867    
1868     // Build cTle object
1869     tle1 = row->GetField(1);
1870     tle2 = row->GetField(2);
1871     tle3 = row->GetField(3);
1872    
1873     thistle = new cTle(tle1, tle2, tle3);
1874 mocchiut 1.12
1875 mocchiut 1.21 return thistle;
1876 mocchiut 1.12 }

  ViewVC Help
Powered by ViewVC 1.1.23