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

Annotation of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Sep 5 10:48:58 2006 UTC (18 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +2 -0 lines
Fixed compilation bug

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     //
10     #include <TFile.h>
11     #include <TTree.h>
12     #include <EventHeader.h>
13     #include <PscuHeader.h>
14     //
15     #include <GLTables.h>
16     //
17     ClassImp(GL_TRK_CALIB);
18     ClassImp(GL_RUN);
19     ClassImp(GL_ROOT);
20     ClassImp(GL_PARAM);
21     ClassImp(GL_S4_CALIB);
22     ClassImp(GL_CALO_CALIB);
23     ClassImp(GL_TIMESYNC);
24     //
25     using namespace std;
26    
27     GL_RUN::GL_RUN() {
28     ID = 0;
29     ID_RUN_FRAG = 0;
30     ID_ROOT_L0 = 0;
31     ID_ROOT_L2 = 0;
32     RUNHEADER_TIME = 0;
33     RUNTRAILER_TIME = 0;
34     EV_FROM = 0;
35     EV_TO = 0;
36     TRK_CALIB_USED = 0;
37     EFF_WRK_SCHEDULE = 0;
38     PRH_VAR_TRG_MODE_A = 0;
39     PRH_VAR_TRG_MODE_B = 0;
40     ACQ_BUILD_INFO = 0;
41     ACQ_VAR_INFO = 0;
42     RUNHEADER_OBT = 0;
43     RUNTRAILER_OBT = 0;
44     RUNHEADER_PKT = 0;
45     RUNTRAILER_PKT = 0;
46     NEVENTS = 0;
47     LAST_TIMESYNC = 0;
48     OBT_TIMESYNC = 0;
49     COMPILATIONTIMESTAMP = 0;
50     FAV_WRK_SCHEDULE = 0;
51     RM_ACQ_AFTER_CALIB = 0;
52     RM_ACQ_SETTING_MODE = 0;
53     PKT_COUNTER = 0;
54     PKT_READY_COUNTER = 0;
55     TRK_CALIB_USED = 0;
56     CAL_DSP_MASK = 0;
57     BOOT_NUMBER = 0;
58     VALIDATION = 0;
59     }
60    
61     void GL_RUN::Clear() {
62     ID = 0;
63     ID_RUN_FRAG = 0;
64     ID_ROOT_L0 = 0;
65     ID_ROOT_L2 = 0;
66     RUNHEADER_TIME = 0;
67     RUNTRAILER_TIME = 0;
68     EV_FROM = 0;
69     EV_TO = 0;
70     TRK_CALIB_USED = 0;
71     EFF_WRK_SCHEDULE = 0;
72     PRH_VAR_TRG_MODE_A = 0;
73     PRH_VAR_TRG_MODE_B = 0;
74     ACQ_BUILD_INFO = 0;
75     ACQ_VAR_INFO = 0;
76     RUNHEADER_OBT = 0;
77     RUNTRAILER_OBT = 0;
78     RUNHEADER_PKT = 0;
79     RUNTRAILER_PKT = 0;
80     NEVENTS = 0;
81     LAST_TIMESYNC = 0;
82     OBT_TIMESYNC = 0;
83     COMPILATIONTIMESTAMP = 0;
84     FAV_WRK_SCHEDULE = 0;
85     RM_ACQ_AFTER_CALIB = 0;
86     RM_ACQ_SETTING_MODE = 0;
87     PKT_COUNTER = 0;
88     PKT_READY_COUNTER = 0;
89     TRK_CALIB_USED = 0;
90     CAL_DSP_MASK = 0;
91     BOOT_NUMBER = 0;
92     VALIDATION = 0;
93     }
94    
95     GL_ROOT::GL_ROOT(){
96     ID = 0;
97     ID_RAW = 0;
98     ID_TIMESYNC = 0;
99     PATH = "";
100     NAME = "";
101     }
102    
103     GL_PARAM::GL_PARAM(){
104     ID = 0;
105     PATH = "";
106     NAME = "";
107     DESCR = "";
108     FROM_TIME = 0;
109     TO_TIME = 0;
110     TYPE = 0;
111     }
112    
113    
114     GL_TRK_CALIB::GL_TRK_CALIB(){
115     ID = 0;
116     ID_ROOT_L0 = 0;
117     EV_ROOT_CALIBTRK1 = 0;
118     EV_ROOT_CALIBTRK2 = 0;
119     FROM_TIME = 0;
120     TO_TIME = 0;
121     OBT1 = 0;
122     OBT2 = 0;
123     PKT1 = 0;
124     PKT2 = 0;
125     }
126    
127     GL_CALO_CALIB::GL_CALO_CALIB(){
128     ID = 0;
129     ID_ROOT_L0 = 0;
130     EV_ROOT = 0;
131     FROM_TIME = 0;
132     TO_TIME = 0;
133     SECTION = 0;
134     }
135    
136     GL_S4_CALIB::GL_S4_CALIB(){
137     ID = 0;
138     ID_ROOT_L0 = 0;
139     EV_ROOT = 0;
140     FROM_TIME = 0;
141     TO_TIME = 0;
142     PARAM_FIT0 = 0.;
143     PARAM_FIT1 = 0.;
144     }
145    
146     GL_TIMESYNC::GL_TIMESYNC(){
147     obtfirst = 0;
148     pktfirst = 0;
149     toffset = 0;
150     ID = 0;
151     ID_RAW = 0;
152     OBT0 = 0;
153     TIMESYNC = 0;
154     TYPE = 0;
155     }// ****************************************************
156    
157    
158     void GL_RUN::SetEV_FROM(UInt_t evfrom){
159     EV_FROM = evfrom;
160     };
161    
162     void GL_RUN::SetEV_TO(UInt_t evto){
163     EV_TO = evto;
164     };
165    
166     void GL_RUN::SetNEVENTS(UInt_t nev){
167     NEVENTS = nev;
168     };
169    
170     void GL_RUN::SetBOOTNUMBER(UInt_t boot){
171     BOOT_NUMBER = boot;
172     };
173    
174     void GL_RUN::SetRUNHEADER_TIME(UInt_t absth){
175     RUNHEADER_TIME = absth;
176     };
177    
178     void GL_RUN::SetRUNTRAILER_TIME(UInt_t abstt){
179     RUNTRAILER_TIME = abstt;
180     };
181    
182     void GL_RUN::SetRUNHEADER_PKT(UInt_t absth){
183     RUNHEADER_PKT = absth;
184     };
185    
186     void GL_RUN::SetRUNTRAILER_PKT(UInt_t abstt){
187     RUNTRAILER_PKT = abstt;
188     };
189    
190     void GL_RUN::SetRUNHEADER_OBT(UInt_t absth){
191     RUNHEADER_OBT = absth;
192     };
193    
194     void GL_RUN::SetRUNTRAILER_OBT(UInt_t abstt){
195     RUNTRAILER_OBT = abstt;
196     };
197    
198     void GL_RUN::SetID_ROOT_L2(UInt_t idl2){
199     ID_ROOT_L2 = idl2;
200     };
201    
202     void GL_RUN::SetID_ROOT_L0(UInt_t idroot){
203     ID_ROOT_L0 = idroot;
204     };
205    
206     void GL_RUN::SetID_RUN_FRAG(UInt_t idfrag){
207     ID_RUN_FRAG = idfrag;
208     };
209    
210     void GL_RUN::SetVALIDATION(UInt_t valid){
211     VALIDATION = valid;
212     };
213    
214     void GL_RUN::SetLAST_TIMESYNC(UInt_t ts){
215     LAST_TIMESYNC = ts;
216     };
217    
218     void GL_RUN::SetOBT_TIMESYNC(UInt_t ts){
219     OBT_TIMESYNC = ts;
220     };
221    
222     void GL_RUN:: SetPKT_COUNTER(UInt_t value){
223     PKT_COUNTER = value;
224     };
225    
226     void GL_RUN:: SetPKT_READY_COUNTER(UInt_t value){
227     PKT_READY_COUNTER = value;
228     };
229    
230     void GL_RUN:: SetCOMPILATIONTIMESTAMP(UInt_t value){
231     COMPILATIONTIMESTAMP = value;
232     };
233    
234     void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){
235     FAV_WRK_SCHEDULE = value;
236     };
237    
238     void GL_RUN:: SetEFF_WRK_SCHEDULE(UInt_t value){
239     EFF_WRK_SCHEDULE = value;
240     };
241    
242     void GL_RUN:: SetPRH_VAR_TRG_MODE_A(UInt_t value){
243     PRH_VAR_TRG_MODE_A = value;
244     };
245    
246     void GL_RUN:: SetPRH_VAR_TRG_MODE_B(UInt_t value){
247     PRH_VAR_TRG_MODE_B = value;
248     };
249    
250     void GL_RUN:: SetACQ_BUILD_INFO(UInt_t value){
251     ACQ_BUILD_INFO = value;
252     };
253    
254     void GL_RUN:: SetACQ_VAR_INFO(UInt_t value){
255     ACQ_VAR_INFO = value;
256     };
257    
258     void GL_RUN:: SetRM_ACQ_AFTER_CALIB(UInt_t value){
259     RM_ACQ_AFTER_CALIB = value;
260     };
261    
262     void GL_RUN:: SetRM_ACQ_SETTING_MODE(UInt_t value){
263     RM_ACQ_SETTING_MODE = value;
264     };
265    
266     void GL_RUN:: SetTRK_CALIB_USED(UInt_t value){
267     TRK_CALIB_USED = value;
268     };
269    
270     void GL_RUN:: SetCAL_DSP_MASK(UInt_t value){
271     CAL_DSP_MASK = value;
272     };
273    
274     void GL_RUN:: SetID(UInt_t value){
275     ID = value;
276     };
277    
278     void GL_RUN::Set_GL_RUNT(RunTrailerEvent *runt, PscuHeader *pht){
279     PKT_COUNTER = runt->PKT_COUNTER;
280     PKT_READY_COUNTER = runt->PKT_ReadyCounter;
281     RUNTRAILER_OBT = pht->GetOrbitalTime();
282     RUNTRAILER_PKT = pht->GetCounter();
283     };
284    
285     void GL_RUN::Set_GL_RUNH(RunHeaderEvent *runh, PscuHeader *phh){
286     TRK_CALIB_USED = runh->TRK_CALIB_USED;
287     PRH_VAR_TRG_MODE_A = runh->PRH_VAR_TRIGGER_MODE_A;
288     PRH_VAR_TRG_MODE_B = runh->PRH_VAR_TRIGGER_MODE_B;
289     ACQ_BUILD_INFO = runh->ACQ_BUILD_INFO;
290     ACQ_VAR_INFO = runh->ACQ_VAR_INFO;
291     RUNHEADER_OBT = phh->GetOrbitalTime();
292     RUNHEADER_PKT = phh->GetCounter();
293     LAST_TIMESYNC = runh->LAST_TIME_SYNC_INFO;
294     OBT_TIMESYNC = runh->OBT_TIME_SYNC;
295     COMPILATIONTIMESTAMP = runh->COMPILATIONTIMESTAMP;
296     FAV_WRK_SCHEDULE = runh->FAVOURITE_WORKING_SCHEDULE;
297     EFF_WRK_SCHEDULE = runh->EFFECTIVE_WORKING_SCHEDULE;
298     RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB;
299     RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE;
300     TRK_CALIB_USED = runh->TRK_CALIB_USED;
301     CAL_DSP_MASK = runh->CAL_DSP_MASK;
302     };
303    
304     void GL_RUN::Set_GL_RUNT0(){
305     PKT_COUNTER = 0;
306     PKT_READY_COUNTER = 0;
307     RUNTRAILER_OBT = 0;
308     RUNTRAILER_PKT = 0;
309     };
310    
311     void GL_RUN::Set_GL_RUNH0(){
312     TRK_CALIB_USED = 0;
313     PRH_VAR_TRG_MODE_A = 0;
314     PRH_VAR_TRG_MODE_B = 0;
315     ACQ_BUILD_INFO = 0;
316     ACQ_VAR_INFO = 0;
317     RUNHEADER_OBT = 0;
318     RUNHEADER_PKT = 0;
319     LAST_TIMESYNC = 0;
320     OBT_TIMESYNC = 0;
321     COMPILATIONTIMESTAMP = 0;
322     FAV_WRK_SCHEDULE = 0;
323     EFF_WRK_SCHEDULE = 0;
324     RM_ACQ_AFTER_CALIB = 0;
325     RM_ACQ_SETTING_MODE = 0;
326     TRK_CALIB_USED = 0;
327     CAL_DSP_MASK = 0;
328     };
329    
330    
331     /**
332     * Function to fill the GL_RUN table of the DB.
333     *
334     * \param
335     *
336     */
337     Int_t GL_RUN::Fill_GL_RUN(TSQLServer *dbc){
338     // MySQL variables
339     stringstream myquery;
340     // ----------------
341     myquery.str("");
342     myquery << " INSERT INTO GL_RUN (";
343     myquery << "ID";
344     myquery << ",ID_RUN_FRAG";
345     myquery << ",ID_ROOT_L0";
346     myquery << ",ID_ROOT_L2";
347     myquery << ",RUNHEADER_TIME";
348     myquery << ",RUNTRAILER_TIME";
349     myquery << ",RUNHEADER_OBT";
350     myquery << ",RUNTRAILER_OBT";
351     myquery << ",RUNHEADER_PKT";
352     myquery << ",RUNTRAILER_PKT";
353     myquery << ",EV_FROM";
354     myquery << ",EV_TO";
355     myquery << ",NEVENTS";
356     myquery << ",LAST_TIMESYNC";
357     myquery << ",OBT_TIMESYNC";
358     myquery << ",COMPILATIONTIMESTAMP";
359     myquery << ",FAV_WRK_SCHEDULE";
360     myquery << ",EFF_WRK_SCHEDULE";
361     myquery << ",PRH_VAR_TRG_MODE_A";
362     myquery << ",PRH_VAR_TRG_MODE_B";
363     myquery << ",ACQ_BUILD_INFO";
364     myquery << ",ACQ_VAR_INFO";
365     myquery << ",RM_ACQ_AFTER_CALIB";
366     myquery << ",RM_ACQ_SETTING_MODE";
367     myquery << ",PKT_COUNTER";
368     myquery << ",PKT_READY_COUNTER";
369     myquery << ",TRK_CALIB_USED";
370     myquery << ",CAL_DSP_MASK";
371     myquery << ",BOOT_NUMBER";
372     myquery << ",VALIDATION";
373     myquery << ") VALUES ('";
374    
375     myquery << (UInt_t)ID << "','";
376     myquery << (UInt_t)ID_RUN_FRAG << "','";
377     myquery << (UInt_t)ID_ROOT_L0 << "','";
378     myquery << (UInt_t)ID_ROOT_L2 << "','";
379     myquery << (UInt_t)RUNHEADER_TIME << "','";
380     myquery << (UInt_t)RUNTRAILER_TIME << "','";
381     myquery << (UInt_t)RUNHEADER_OBT << "','";
382     myquery << (UInt_t)RUNTRAILER_OBT << "','";
383     myquery << (UInt_t)RUNHEADER_PKT << "','";
384     myquery << (UInt_t)RUNTRAILER_PKT << "','";
385     myquery << (UInt_t)EV_FROM << "','";
386     myquery << (UInt_t)EV_TO << "','";
387     myquery << (UInt_t)NEVENTS << "','";
388     myquery << (UInt_t)LAST_TIMESYNC << "','";
389     myquery << (UInt_t)OBT_TIMESYNC << "','";
390     myquery << (UInt_t)COMPILATIONTIMESTAMP << "','";
391     myquery << (UInt_t)FAV_WRK_SCHEDULE << "','";
392     myquery << (UInt_t)EFF_WRK_SCHEDULE << "','";
393     myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','";
394     myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','";
395     myquery << (UInt_t)ACQ_BUILD_INFO << "','";
396     myquery << (UInt_t)ACQ_VAR_INFO << "','";
397     myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','";
398     myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','";
399     myquery << (UInt_t)PKT_COUNTER << "','";
400     myquery << (UInt_t)PKT_READY_COUNTER << "','";
401     myquery << (UInt_t)TRK_CALIB_USED << "','";
402     myquery << (UInt_t)CAL_DSP_MASK << "','";
403     myquery << (UInt_t)BOOT_NUMBER << "','";
404     myquery << (UInt_t)VALIDATION << "');";
405     //
406 mocchiut 1.2 // printf("myquery is %s \n",myquery.str().c_str());
407 mocchiut 1.1 //
408     dbc->Query(myquery.str().c_str());
409     //
410     return 0;
411    
412     };// ****************************************************
413    
414     /**
415     * Function to fill the GL_RUN table of the DB.
416     *
417     * \param
418     *
419     */
420     Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQLServer *dbc){
421     // MySQL variables
422     stringstream myquery;
423     // ----------------
424     myquery.str("");
425     myquery << " INSERT INTO GL_RUN_FRAGMENTS (";
426     myquery << "ID";
427     myquery << ",ID_ROOT_L0";
428     myquery << ",RUNHEADER_TIME";
429     myquery << ",RUNTRAILER_TIME";
430     myquery << ",RUNHEADER_OBT";
431     myquery << ",RUNTRAILER_OBT";
432     myquery << ",RUNHEADER_PKT";
433     myquery << ",RUNTRAILER_PKT";
434     myquery << ",EV_FROM";
435     myquery << ",EV_TO";
436     myquery << ",NEVENTS";
437     myquery << ",LAST_TIMESYNC";
438     myquery << ",OBT_TIMESYNC";
439     myquery << ",COMPILATIONTIMESTAMP";
440     myquery << ",FAV_WRK_SCHEDULE";
441     myquery << ",EFF_WRK_SCHEDULE";
442     myquery << ",PRH_VAR_TRG_MODE_A";
443     myquery << ",PRH_VAR_TRG_MODE_B";
444     myquery << ",ACQ_BUILD_INFO";
445     myquery << ",ACQ_VAR_INFO";
446     myquery << ",RM_ACQ_AFTER_CALIB";
447     myquery << ",RM_ACQ_SETTING_MODE";
448     myquery << ",PKT_COUNTER";
449     myquery << ",PKT_READY_COUNTER";
450     myquery << ",TRK_CALIB_USED";
451     myquery << ",CAL_DSP_MASK";
452     myquery << ",BOOT_NUMBER";
453     myquery << ") VALUES ('";
454     myquery << (UInt_t)ID << "','";
455     myquery << (UInt_t)ID_ROOT_L0 << "','";
456     myquery << (UInt_t)RUNHEADER_TIME << "','";
457     myquery << (UInt_t)RUNTRAILER_TIME << "','";
458     myquery << (UInt_t)RUNHEADER_OBT << "','";
459     myquery << (UInt_t)RUNTRAILER_OBT << "','";
460     myquery << (UInt_t)RUNHEADER_PKT << "','";
461     myquery << (UInt_t)RUNTRAILER_PKT << "','";
462     myquery << (UInt_t)EV_FROM << "','";
463     myquery << (UInt_t)EV_TO << "','";
464     myquery << (UInt_t)NEVENTS << "','";
465     myquery << (UInt_t)LAST_TIMESYNC << "','";
466     myquery << (UInt_t)OBT_TIMESYNC << "','";
467     myquery << (UInt_t)COMPILATIONTIMESTAMP << "','";
468     myquery << (UInt_t)FAV_WRK_SCHEDULE << "','";
469     myquery << (UInt_t)EFF_WRK_SCHEDULE << "','";
470     myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','";
471     myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','";
472     myquery << (UInt_t)ACQ_BUILD_INFO << "','";
473     myquery << (UInt_t)ACQ_VAR_INFO << "','";
474     myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','";
475     myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','";
476     myquery << (UInt_t)PKT_COUNTER << "','";
477     myquery << (UInt_t)PKT_READY_COUNTER << "','";
478     myquery << (UInt_t)TRK_CALIB_USED << "','";
479     myquery << (UInt_t)CAL_DSP_MASK << "','";
480     myquery << (UInt_t)BOOT_NUMBER << "');";
481     //
482     // printf("myquery is %s \n",myquery.str().c_str());
483     //
484     dbc->Query(myquery.str().c_str());
485     //
486     return 0;
487    
488     };// ****************************************************
489    
490    
491     /**
492     * Function to query the GL_RUN table of the DB.
493     *
494     * \param RUN id
495     * \return struct of type GL_RUN _data, which stores the query result
496     *
497     */
498     Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){
499     // MySQL variables
500     TSQLResult *pResult;
501     TSQLRow *Row;
502     int t;
503     int r;
504     stringstream myquery;
505     // ----------------
506     myquery.str("");
507     myquery << " select ";
508     myquery << "ID";
509     myquery << ",ID_RUN_FRAG";
510     myquery << ",ID_ROOT_L0";
511     myquery << ",ID_ROOT_L2";
512     myquery << ",RUNHEADER_TIME";
513     myquery << ",RUNTRAILER_TIME";
514     myquery << ",RUNHEADER_OBT";
515     myquery << ",RUNTRAILER_OBT";
516     myquery << ",RUNHEADER_PKT";
517     myquery << ",RUNTRAILER_PKT";
518     myquery << ",EV_FROM";
519     myquery << ",EV_TO";
520     myquery << ",NEVENTS";
521     myquery << ",LAST_TIMESYNC";
522     myquery << ",OBT_TIMESYNC";
523     myquery << ",COMPILATIONTIMESTAMP";
524     myquery << ",FAV_WRK_SCHEDULE";
525     myquery << ",EFF_WRK_SCHEDULE";
526     myquery << ",PRH_VAR_TRG_MODE_A";
527     myquery << ",PRH_VAR_TRG_MODE_B";
528     myquery << ",ACQ_BUILD_INFO";
529     myquery << ",ACQ_VAR_INFO";
530     myquery << ",RM_ACQ_AFTER_CALIB";
531     myquery << ",RM_ACQ_SETTING_MODE";
532     myquery << ",PKT_COUNTER";
533     myquery << ",PKT_READY_COUNTER";
534     myquery << ",TRK_CALIB_USED";
535     myquery << ",CAL_DSP_MASK";
536     myquery << ",BOOT_NUMBER";
537     myquery << ",VALIDATION";
538     myquery << " from GL_RUN where ID=" << run << ";";
539     //
540     pResult = dbc->Query(myquery.str().c_str());
541     if(!pResult->GetRowCount())return(-50);
542     for( r=0; r < 1000; r++){
543     Row = pResult->Next();
544     if( Row == NULL ) break;
545     for( t = 0; t < pResult->GetFieldCount(); t++){
546     if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
547     if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
548     if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
549     if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
550     if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
551     if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
552     if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
553     if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
554     if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
555     if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
556     if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t));
557     if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t));
558     if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t));
559     if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
560     if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
561     if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
562     if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
563     if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
564     if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
565     if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
566     if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
567     if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
568     if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
569     if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
570     if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
571     if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
572     if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
573     if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
574     if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
575     if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
576 mocchiut 1.2
577    
578 mocchiut 1.1 };
579     };
580     delete pResult;
581    
582     return 0;
583    
584     };
585    
586     /**
587     * Function to query the GL_RUN table of the DB.
588     *
589     * \param where = condition string
590     * \return struct of type GL_RUN _data, which stores the query result
591     *
592     */
593     Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){
594     // MySQL variables
595     TSQLResult *pResult;
596     TSQLRow *Row;
597     int t;
598     int r;
599     stringstream myquery;
600     // ----------------
601     myquery.str("");
602     myquery << " select ";
603     myquery << "ID";
604 mocchiut 1.2 myquery << ",ID_RUN_FRAG";
605 mocchiut 1.1 myquery << ",ID_ROOT_L0";
606 mocchiut 1.2 myquery << ",ID_ROOT_L2";
607 mocchiut 1.1 myquery << ",RUNHEADER_TIME";
608     myquery << ",RUNTRAILER_TIME";
609     myquery << ",RUNHEADER_OBT";
610     myquery << ",RUNTRAILER_OBT";
611     myquery << ",RUNHEADER_PKT";
612     myquery << ",RUNTRAILER_PKT";
613     myquery << ",EV_FROM";
614     myquery << ",EV_TO";
615     myquery << ",NEVENTS";
616     myquery << ",LAST_TIMESYNC";
617     myquery << ",OBT_TIMESYNC";
618     myquery << ",COMPILATIONTIMESTAMP";
619     myquery << ",FAV_WRK_SCHEDULE";
620     myquery << ",EFF_WRK_SCHEDULE";
621     myquery << ",PRH_VAR_TRG_MODE_A";
622     myquery << ",PRH_VAR_TRG_MODE_B";
623     myquery << ",ACQ_BUILD_INFO";
624     myquery << ",ACQ_VAR_INFO";
625     myquery << ",RM_ACQ_AFTER_CALIB";
626     myquery << ",RM_ACQ_SETTING_MODE";
627     myquery << ",PKT_COUNTER";
628     myquery << ",PKT_READY_COUNTER";
629     myquery << ",TRK_CALIB_USED";
630     myquery << ",CAL_DSP_MASK";
631     myquery << ",BOOT_NUMBER";
632 mocchiut 1.2 myquery << ",VALIDATION";
633 mocchiut 1.1 myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";";
634     //
635 mocchiut 1.2 // printf(" query is %s \n",myquery.str().c_str());
636     //
637 mocchiut 1.1 pResult = dbc->Query(myquery.str().c_str());
638     if(!pResult->GetRowCount())return(-50);
639     for( r=0; r < 1000; r++){
640 mocchiut 1.2 Row = pResult->Next();
641     if( Row == NULL ) break;
642     for( t = 0; t < pResult->GetFieldCount(); t++){
643     if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
644     if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
645     if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
646     if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
647     if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
648     if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
649     if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
650     if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
651     if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
652     if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
653     if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t));
654     if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t));
655     if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t));
656     if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
657     if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
658     if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
659     if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
660     if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
661     if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
662     if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
663     if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
664     if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
665     if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
666     if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
667     if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
668     if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
669     if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
670     if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
671     if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
672     if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
673     };
674 mocchiut 1.1 };
675 mocchiut 1.2 // delete pResult;
676     return(0);
677     };// ****************************************************
678 mocchiut 1.1
679     /**
680     * Function to query the GL_ROOT table of the DB.
681     *
682     * \param entry ID
683     * \return struct of type GL_ROOT_data, which stores the query result
684     */
685     Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){
686     // MySQL variables
687     TSQLResult *pResult;
688     TSQLRow *Row;
689     int t;
690     int r;
691     stringstream myquery;
692     // ----------------
693     myquery.str("");
694     myquery << "select ";
695     myquery << " ID";
696     myquery << ",ID_RAW";
697     myquery << ",ID_TIMESYNC";
698     myquery << ",PATH";
699     myquery << ",NAME";
700     myquery << " from GL_ROOT where ID=" << id << ";";
701     //
702     pResult = dbc->Query(myquery.str().c_str());
703     if(!pResult->GetRowCount())return (-51);
704     for( r=0; r < 1000; r++){
705     Row = pResult->Next();
706     if( Row == NULL ) break;
707     for( t = 0; t < pResult->GetFieldCount(); t++){
708     if(t==0) ID = (UInt_t)atoll(Row->GetField(t));
709     if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));
710     if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
711     if(t==3) PATH = Row->GetField(t);
712     if(t==4) NAME = Row->GetField(t);
713     };
714     };
715     delete pResult;
716     return 0;
717     };
718     // ****************************************************
719     /**
720     * Function to query the GL_TRK_CALIB table of the DB.
721     *
722     * \param run starting time
723     * \return struct of type GL_TRK_CALIB_data, which stores the query result
724     */
725     Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){
726     // MySQL variables
727     TSQLResult *pResult;
728     TSQLRow *Row;
729     int t;
730     int r;
731     stringstream myquery;
732     // ----------------
733     myquery.str("");
734     myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2 from GL_TRK_CALIB where FROM_TIME <= "<< time;
735     myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
736     // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
737     pResult = dbc->Query(myquery.str().c_str());
738     if(!pResult->GetRowCount())return (-53);
739     for( r=0; r < 1000; r++){
740     Row = pResult->Next();
741     if( Row == NULL ) break;
742     for( t = 0; t < pResult->GetFieldCount(); t++){
743 mocchiut 1.2 stringstream row;
744     row.str("");
745     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
746 mocchiut 1.1 if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
747     if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
748 mocchiut 1.2 if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str());
749     if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str());
750 mocchiut 1.1 if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
751     if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
752     //
753     if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t));
754     if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t));
755     if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t));
756     if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t));
757     };
758     };
759     delete pResult;
760     //
761     if(TO_TIME < time)return(51);
762     if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING!
763     //
764     return 0;
765     };
766    
767     // ****************************************************
768     /**
769     * Function to query the GL_CALO_CALIB table of the DB.
770     *
771     * \param run starting time
772     * \return struct of type GL_CALO_CALIB_data, which stores the query result
773     */
774     Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t section, TSQLServer *dbc){
775     // MySQL variables
776     TSQLResult *pResult;
777     TSQLRow *Row;
778     int t;
779     stringstream myquery;
780     //
781     // select the correct calibration
782     //
783     myquery.str("");
784     myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
785     myquery << " and FROM_TIME <= " << time;
786     myquery << " and TO_TIME > " << time;
787     myquery << " and VALIDATION=1;";
788     //
789     pResult = dbc->Query(myquery.str().c_str());
790     //
791     // if it is corrupted validation is 0 and we have no results from the query...
792     //
793     if( !pResult->GetRowCount() ){
794     // pResult->Delete();
795     //
796     // in this case take relax the conditions and take the valid calibration that preceed the correct one
797     //
798     myquery.str("");
799     myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
800     myquery << " and FROM_TIME <= " << time;
801     myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
802     pResult = dbc->Query(myquery.str().c_str());
803     //
804     // if no results yet quit with error
805     //
806     if( !pResult->GetRowCount() ) return (-54);
807     };
808     //
809     // store infos and exit
810     //
811     Row = pResult->Next();
812     if( Row == NULL ) return (-54);
813     for( t = 0; t < pResult->GetFieldCount(); t++){
814     if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
815     if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
816     if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t));
817     if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
818     };
819     pResult->Delete();
820     return 0;
821     };
822     // ****************************************************
823     /**
824     * Function to query the GL_S4_CALIB table of the DB.
825     *
826     * \param run starting time
827     * \return struct of type GL_S4_CALIB_data, which stores the query result
828     */
829     Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){
830     // MySQL variables
831     TSQLResult *pResult;
832     TSQLRow *Row;
833     int t;
834     int r;
835     stringstream myquery;
836     // ----------------
837     myquery.str("");
838     myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
839     myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;";
840     // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
841     pResult = dbc->Query(myquery.str().c_str());
842     if(!pResult->GetRowCount())return (-55);//throw -55;
843     for( r=0; r < 1000; r++){
844     Row = pResult->Next();
845     if( Row == NULL ) break;
846     for( t = 0; t < pResult->GetFieldCount(); t++){
847     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
848     if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
849     if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
850     if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
851     if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t));
852     if (t==5) PARAM_FIT0 = atof(Row->GetField(t));
853     if (t==6) PARAM_FIT1 = atof(Row->GetField(t));
854     };
855     };
856     delete pResult;
857     //
858     if(TO_TIME < time)return(51);
859     //
860     return 0;
861     };
862     // ****************************************************
863     /**
864     * Function to query the GL_PARAM table of the DB.
865     *
866     * \param run starting time
867     * \param parameter description (DESCR)
868     * \return struct of type GL_ROOT_data, which stores the query result
869     */
870     Int_t GL_PARAM::Query_GL_PARAM(UInt_t time, UInt_t type, TSQLServer *dbc){
871     // Bool_t debug = 1;
872     // MySQL variables
873     TSQLResult *pResult;
874     TSQLRow *Row;
875     int t;
876     int r;
877     stringstream myquery;
878     // ----------------
879     myquery.str("");
880     myquery << " select ";
881     myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME ";
882     myquery << " from GL_PARAM ";
883     myquery << " where TYPE = '"<<type<<"' ";
884     myquery << " and FROM_TIME <= " << time;
885     myquery << " ORDER BY TO_TIME DESC LIMIT 1;";
886     //
887     pResult = dbc->Query(myquery.str().c_str());
888     if(!pResult->GetRowCount())return (-52);
889     for( r=0; r < 1000; r++){
890     Row = pResult->Next();
891     if( Row == NULL ) break;
892     for( t = 0; t < pResult->GetFieldCount(); t++){
893     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
894     if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file
895     if (t==2) NAME = Row->GetField(t);
896     if (t==3) DESCR = Row->GetField(t);
897     if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
898     if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
899     if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t));
900     };
901     };
902     delete pResult;
903     //
904     if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max();
905     //
906     if(TO_TIME < time) return(51);
907     //
908     return 0;
909     };
910    
911    
912     /**
913     * Fills a struct cGLRun with values from a GLRun object (to put data into a F77 common).
914     */
915    
916     void GL_RUN::GetLevel2Struct(cGLRun *l2) const{
917     l2->id = ID;
918     l2->id_reg_run = ID_ROOT_L0;
919     l2->id_reg_run_l2 = ID_ROOT_L2;
920     l2->runheader_time = RUNHEADER_TIME;
921     l2->runtrailer_time = RUNTRAILER_TIME;
922     l2->ev_from = EV_FROM;
923     l2->trk_calib_used = TRK_CALIB_USED;
924     l2->eff_wrk_schedule = EFF_WRK_SCHEDULE;
925     l2->prh_var_trg_mode_a = PRH_VAR_TRG_MODE_A;
926     l2->prh_var_trg_mode_b = PRH_VAR_TRG_MODE_B;
927     l2->acq_build_info = ACQ_BUILD_INFO;
928     l2->acq_var_info = ACQ_VAR_INFO;
929     };
930    
931     GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
932     // MySQL variables
933     TFile *file = 0;
934     UInt_t idraw = 0;
935     //
936     TSQLResult *pResult;
937     TSQLRow *Row;
938     stringstream myquery;
939     // ----------------
940     myquery.str("");
941     myquery << "select ";
942     myquery << "PATH";
943     myquery << ",NAME,ID_RAW";
944     myquery << " from GL_ROOT where ";
945     myquery << type.Data();
946     myquery << "=" << id << ";";
947     //
948     pResult = dbc->Query(myquery.str().c_str());
949     if( pResult->GetRowCount() ){
950     Row = pResult->Next();
951     if( Row ){
952     stringstream fname;
953     fname.str("");
954     fname << Row->GetField(0) << "/" << Row->GetField(1);
955     file = new TFile(fname.str().c_str(),"READ");
956     idraw = (UInt_t)atoll(Row->GetField(2));
957     };
958     };
959     //
960     if ( file && file->IsOpen() ){
961     TTree *T=(TTree*)file->Get("Physics");
962     pamela::EventHeader *eh = 0;
963     pamela::PscuHeader *ph = 0;
964     T->SetBranchAddress("Header", &eh);
965     //
966     T->GetEntry(0);
967     ph = eh->GetPscuHeader();
968     pktfirst = ph->GetCounter();
969     obtfirst = ph->GetOrbitalTime();
970     };
971     //
972     // look for Resurs offset
973     //
974     UInt_t t0 = 0;
975     //
976     myquery.str("");
977     myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= "
978     << idraw << " AND TO_ID_RAW >= "
979     << idraw << ";";
980     pResult = dbc->Query(myquery.str().c_str());
981     if ( pResult ){
982     Row = pResult->Next();
983     if ( Row ){
984     //
985     t0 = (UInt_t)TDatime(Row->GetField(0)).Convert();
986     //
987     };
988     };
989     //
990     //
991     // look for the correct timesync entry
992     //
993     myquery.str("");
994     myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC "
995     << " WHERE ID_RAW = " << idraw
996     << ";";
997     pResult = dbc->Query(myquery.str().c_str());
998     if ( pResult ){
999     Row = pResult->Next();
1000     if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){
1001     toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0;
1002     };
1003     };
1004 mocchiut 1.3 //
1005     file->Close();
1006 mocchiut 1.1 delete pResult;
1007     };
1008    
1009     /**
1010     *
1011     * Returns the DB absolute time needed to associate calibrations to data
1012     *
1013     */
1014     UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){
1015     //
1016     return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1017     //
1018     };
1019    
1020    
1021     ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){
1022     //
1023     if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));
1024     //
1025     if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1026     if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){
1027     return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));
1028     } else {
1029     return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));
1030     };
1031     };
1032     //
1033     return((ULong64_t)obt);
1034     //
1035     };
1036    
1037     UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){
1038     //
1039     if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215));
1040     //
1041     if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1042     if ( (pkt_num-16777215) < 0 ){
1043     return((16777215-pkt_num));
1044     } else {
1045     return((pkt_num-16777215));
1046     };
1047     };
1048     //
1049     return(pkt_num);
1050     //
1051     };

  ViewVC Help
Powered by ViewVC 1.1.23