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

Annotation of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Wed Aug 30 11:18:13 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
Branch point for: YodaProfiler
Initial revision

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     //printf("myquery is %s \n",myquery.str().c_str());
407     //
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     };
577     };
578     delete pResult;
579    
580     return 0;
581    
582     };
583    
584     /**
585     * Function to query the GL_RUN table of the DB.
586     *
587     * \param where = condition string
588     * \return struct of type GL_RUN _data, which stores the query result
589     *
590     */
591     Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){
592     // Bool_t debug = 1;
593     // MySQL variables
594     TSQLResult *pResult;
595     TSQLRow *Row;
596     int t;
597     int r;
598     stringstream myquery;
599     // ----------------
600     // NB! unsigned long long integers: when set to a number use ULL to store the correct number
601     myquery.str("");
602     myquery << " select ";
603     // myquery << " * ";
604     myquery << "ID";
605     myquery << ",ID_ROOT_L0";
606     myquery << ",RUNHEADER_TIME";
607     myquery << ",RUNTRAILER_TIME";
608     myquery << ",RUNHEADER_OBT";
609     myquery << ",RUNTRAILER_OBT";
610     myquery << ",RUNHEADER_PKT";
611     myquery << ",RUNTRAILER_PKT";
612     myquery << ",EV_FROM";
613     myquery << ",EV_TO";
614     myquery << ",NEVENTS";
615     myquery << ",LAST_TIMESYNC";
616     myquery << ",OBT_TIMESYNC";
617     myquery << ",COMPILATIONTIMESTAMP";
618     myquery << ",FAV_WRK_SCHEDULE";
619     myquery << ",EFF_WRK_SCHEDULE";
620     myquery << ",PRH_VAR_TRG_MODE_A";
621     myquery << ",PRH_VAR_TRG_MODE_B";
622     myquery << ",ACQ_BUILD_INFO";
623     myquery << ",ACQ_VAR_INFO";
624     myquery << ",RM_ACQ_AFTER_CALIB";
625     myquery << ",RM_ACQ_SETTING_MODE";
626     myquery << ",PKT_COUNTER";
627     myquery << ",PKT_READY_COUNTER";
628     myquery << ",TRK_CALIB_USED";
629     myquery << ",CAL_DSP_MASK";
630     myquery << ",BOOT_NUMBER";
631     myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";";
632     //
633     pResult = dbc->Query(myquery.str().c_str());
634     if(!pResult->GetRowCount())return(-50);
635     for( r=0; r < 1000; r++){
636     Row = pResult->Next();
637     if( Row == NULL ) break;
638     for( t = 0; t < pResult->GetFieldCount(); t++){
639     if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
640     if (t== 1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
641     if (t== 2) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
642     if (t== 3) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
643     if (t== 4) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
644     if (t== 5) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
645     if (t== 6) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
646     if (t== 7) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
647     if (t== 8) EV_FROM = (UInt_t)atoll(Row->GetField(t));
648     if (t== 9) EV_TO = (UInt_t)atoll(Row->GetField(t));
649     if (t==10) NEVENTS = (UInt_t)atoll(Row->GetField(t));
650     if (t==11) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
651     if (t==12) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
652     if (t==13) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
653     if (t==14) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
654     if (t==15) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
655     if (t==16) PRH_VAR_TRG_MODE_A = (UInt_t)atoll(Row->GetField(t));
656     if (t==17) PRH_VAR_TRG_MODE_B = (UInt_t)atoll(Row->GetField(t));
657     if (t==18) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
658     if (t==19) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
659     if (t==20) RM_ACQ_AFTER_CALIB = (UInt_t)atoll(Row->GetField(t));
660     if (t==21) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
661     if (t==22) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
662     if (t==23) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
663     if (t==24) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
664     if (t==25) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
665     if (t==26) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
666     };
667     };
668     delete pResult;
669    
670     return 0;
671    
672     };// ****************************************************
673     /**
674     * Function to query the GL_ROOT table of the DB.
675     *
676     * \param entry ID
677     * \return struct of type GL_ROOT_data, which stores the query result
678     */
679     Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){
680     // MySQL variables
681     TSQLResult *pResult;
682     TSQLRow *Row;
683     int t;
684     int r;
685     stringstream myquery;
686     // ----------------
687     myquery.str("");
688     myquery << "select ";
689     myquery << " ID";
690     myquery << ",ID_RAW";
691     myquery << ",ID_TIMESYNC";
692     myquery << ",PATH";
693     myquery << ",NAME";
694     myquery << " from GL_ROOT where ID=" << id << ";";
695     //
696     pResult = dbc->Query(myquery.str().c_str());
697     if(!pResult->GetRowCount())return (-51);
698     for( r=0; r < 1000; r++){
699     Row = pResult->Next();
700     if( Row == NULL ) break;
701     for( t = 0; t < pResult->GetFieldCount(); t++){
702     if(t==0) ID = (UInt_t)atoll(Row->GetField(t));
703     if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));
704     if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
705     if(t==3) PATH = Row->GetField(t);
706     if(t==4) NAME = Row->GetField(t);
707     };
708     };
709     delete pResult;
710     return 0;
711     };
712     // ****************************************************
713     /**
714     * Function to query the GL_TRK_CALIB table of the DB.
715     *
716     * \param run starting time
717     * \return struct of type GL_TRK_CALIB_data, which stores the query result
718     */
719     Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){
720     // MySQL variables
721     TSQLResult *pResult;
722     TSQLRow *Row;
723     int t;
724     int r;
725     stringstream myquery;
726     // ----------------
727     myquery.str("");
728     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;
729     myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
730     // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
731     pResult = dbc->Query(myquery.str().c_str());
732     if(!pResult->GetRowCount())return (-53);
733     for( r=0; r < 1000; r++){
734     Row = pResult->Next();
735     if( Row == NULL ) break;
736     for( t = 0; t < pResult->GetFieldCount(); t++){
737     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
738     if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
739     if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(Row->GetField(t));
740     if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(Row->GetField(t));
741     if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
742     if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
743     //
744     if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t));
745     if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t));
746     if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t));
747     if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t));
748     };
749     };
750     delete pResult;
751     //
752     if(TO_TIME < time)return(51);
753     if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING!
754     //
755     return 0;
756     };
757    
758     // ****************************************************
759     /**
760     * Function to query the GL_CALO_CALIB table of the DB.
761     *
762     * \param run starting time
763     * \return struct of type GL_CALO_CALIB_data, which stores the query result
764     */
765     Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t section, TSQLServer *dbc){
766     // MySQL variables
767     TSQLResult *pResult;
768     TSQLRow *Row;
769     int t;
770     stringstream myquery;
771     //
772     // select the correct calibration
773     //
774     myquery.str("");
775     myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
776     myquery << " and FROM_TIME <= " << time;
777     myquery << " and TO_TIME > " << time;
778     myquery << " and VALIDATION=1;";
779     //
780     pResult = dbc->Query(myquery.str().c_str());
781     //
782     // if it is corrupted validation is 0 and we have no results from the query...
783     //
784     if( !pResult->GetRowCount() ){
785     // pResult->Delete();
786     //
787     // in this case take relax the conditions and take the valid calibration that preceed the correct one
788     //
789     myquery.str("");
790     myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
791     myquery << " and FROM_TIME <= " << time;
792     myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
793     pResult = dbc->Query(myquery.str().c_str());
794     //
795     // if no results yet quit with error
796     //
797     if( !pResult->GetRowCount() ) return (-54);
798     };
799     //
800     // store infos and exit
801     //
802     Row = pResult->Next();
803     if( Row == NULL ) return (-54);
804     for( t = 0; t < pResult->GetFieldCount(); t++){
805     if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
806     if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
807     if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t));
808     if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
809     };
810     pResult->Delete();
811     return 0;
812     };
813     // ****************************************************
814     /**
815     * Function to query the GL_S4_CALIB table of the DB.
816     *
817     * \param run starting time
818     * \return struct of type GL_S4_CALIB_data, which stores the query result
819     */
820     Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){
821     // MySQL variables
822     TSQLResult *pResult;
823     TSQLRow *Row;
824     int t;
825     int r;
826     stringstream myquery;
827     // ----------------
828     myquery.str("");
829     myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
830     myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;";
831     // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
832     pResult = dbc->Query(myquery.str().c_str());
833     if(!pResult->GetRowCount())return (-55);//throw -55;
834     for( r=0; r < 1000; r++){
835     Row = pResult->Next();
836     if( Row == NULL ) break;
837     for( t = 0; t < pResult->GetFieldCount(); t++){
838     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
839     if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
840     if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
841     if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
842     if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t));
843     if (t==5) PARAM_FIT0 = atof(Row->GetField(t));
844     if (t==6) PARAM_FIT1 = atof(Row->GetField(t));
845     };
846     };
847     delete pResult;
848     //
849     if(TO_TIME < time)return(51);
850     //
851     return 0;
852     };
853     // ****************************************************
854     /**
855     * Function to query the GL_PARAM table of the DB.
856     *
857     * \param run starting time
858     * \param parameter description (DESCR)
859     * \return struct of type GL_ROOT_data, which stores the query result
860     */
861     Int_t GL_PARAM::Query_GL_PARAM(UInt_t time, UInt_t type, TSQLServer *dbc){
862     // Bool_t debug = 1;
863     // MySQL variables
864     TSQLResult *pResult;
865     TSQLRow *Row;
866     int t;
867     int r;
868     stringstream myquery;
869     // ----------------
870     myquery.str("");
871     myquery << " select ";
872     myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME ";
873     myquery << " from GL_PARAM ";
874     myquery << " where TYPE = '"<<type<<"' ";
875     myquery << " and FROM_TIME <= " << time;
876     myquery << " ORDER BY TO_TIME DESC LIMIT 1;";
877     //
878     pResult = dbc->Query(myquery.str().c_str());
879     if(!pResult->GetRowCount())return (-52);
880     for( r=0; r < 1000; r++){
881     Row = pResult->Next();
882     if( Row == NULL ) break;
883     for( t = 0; t < pResult->GetFieldCount(); t++){
884     if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
885     if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file
886     if (t==2) NAME = Row->GetField(t);
887     if (t==3) DESCR = Row->GetField(t);
888     if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
889     if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
890     if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t));
891     };
892     };
893     delete pResult;
894     //
895     if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max();
896     //
897     if(TO_TIME < time) return(51);
898     //
899     return 0;
900     };
901    
902    
903     /**
904     * Fills a struct cGLRun with values from a GLRun object (to put data into a F77 common).
905     */
906    
907     void GL_RUN::GetLevel2Struct(cGLRun *l2) const{
908     l2->id = ID;
909     l2->id_reg_run = ID_ROOT_L0;
910     l2->id_reg_run_l2 = ID_ROOT_L2;
911     l2->runheader_time = RUNHEADER_TIME;
912     l2->runtrailer_time = RUNTRAILER_TIME;
913     l2->ev_from = EV_FROM;
914     l2->trk_calib_used = TRK_CALIB_USED;
915     l2->eff_wrk_schedule = EFF_WRK_SCHEDULE;
916     l2->prh_var_trg_mode_a = PRH_VAR_TRG_MODE_A;
917     l2->prh_var_trg_mode_b = PRH_VAR_TRG_MODE_B;
918     l2->acq_build_info = ACQ_BUILD_INFO;
919     l2->acq_var_info = ACQ_VAR_INFO;
920     };
921    
922     GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
923     // MySQL variables
924     TFile *file = 0;
925     UInt_t idraw = 0;
926     //
927     TSQLResult *pResult;
928     TSQLRow *Row;
929     stringstream myquery;
930     // ----------------
931     myquery.str("");
932     myquery << "select ";
933     myquery << "PATH";
934     myquery << ",NAME,ID_RAW";
935     myquery << " from GL_ROOT where ";
936     myquery << type.Data();
937     myquery << "=" << id << ";";
938     //
939     pResult = dbc->Query(myquery.str().c_str());
940     if( pResult->GetRowCount() ){
941     Row = pResult->Next();
942     if( Row ){
943     stringstream fname;
944     fname.str("");
945     fname << Row->GetField(0) << "/" << Row->GetField(1);
946     file = new TFile(fname.str().c_str(),"READ");
947     idraw = (UInt_t)atoll(Row->GetField(2));
948     };
949     };
950     //
951     if ( file && file->IsOpen() ){
952     TTree *T=(TTree*)file->Get("Physics");
953     pamela::EventHeader *eh = 0;
954     pamela::PscuHeader *ph = 0;
955     T->SetBranchAddress("Header", &eh);
956     //
957     T->GetEntry(0);
958     ph = eh->GetPscuHeader();
959     pktfirst = ph->GetCounter();
960     obtfirst = ph->GetOrbitalTime();
961     };
962     //
963     // look for Resurs offset
964     //
965     UInt_t t0 = 0;
966     //
967     myquery.str("");
968     myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= "
969     << idraw << " AND TO_ID_RAW >= "
970     << idraw << ";";
971     pResult = dbc->Query(myquery.str().c_str());
972     if ( pResult ){
973     Row = pResult->Next();
974     if ( Row ){
975     //
976     t0 = (UInt_t)TDatime(Row->GetField(0)).Convert();
977     //
978     };
979     };
980     //
981     //
982     // look for the correct timesync entry
983     //
984     myquery.str("");
985     myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC "
986     << " WHERE ID_RAW = " << idraw
987     << ";";
988     pResult = dbc->Query(myquery.str().c_str());
989     if ( pResult ){
990     Row = pResult->Next();
991     if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){
992     toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0;
993     };
994     };
995     delete pResult;
996     };
997    
998     /**
999     *
1000     * Returns the DB absolute time needed to associate calibrations to data
1001     *
1002     */
1003     UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){
1004     //
1005     return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1006     //
1007     };
1008    
1009    
1010     ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){
1011     //
1012     if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));
1013     //
1014     if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1015     if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){
1016     return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));
1017     } else {
1018     return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));
1019     };
1020     };
1021     //
1022     return((ULong64_t)obt);
1023     //
1024     };
1025    
1026     UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){
1027     //
1028     if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215));
1029     //
1030     if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1031     if ( (pkt_num-16777215) < 0 ){
1032     return((16777215-pkt_num));
1033     } else {
1034     return((pkt_num-16777215));
1035     };
1036     };
1037     //
1038     return(pkt_num);
1039     //
1040     };

  ViewVC Help
Powered by ViewVC 1.1.23