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 |
#include <iostream> |
10 |
#include <limits.h> |
11 |
// |
12 |
#include <TFile.h> |
13 |
#include <TTree.h> |
14 |
#include <TTimeStamp.h> |
15 |
#include <EventHeader.h> |
16 |
#include <PscuHeader.h> |
17 |
// |
18 |
#include <GLTables.h> |
19 |
#include <sgp4.h> |
20 |
// |
21 |
ClassImp(Q2TH); |
22 |
ClassImp(GL_TABLES); |
23 |
ClassImp(GL_TRK_CALIB); |
24 |
ClassImp(GL_RUN); |
25 |
ClassImp(GL_ROOT); |
26 |
ClassImp(GL_PARAM); |
27 |
ClassImp(GL_S4_CALIB); |
28 |
ClassImp(GL_CALO_CALIB); |
29 |
ClassImp(GL_CALOPULSE_CALIB); |
30 |
ClassImp(GL_TIMESYNC); |
31 |
ClassImp(GL_TLE); |
32 |
// |
33 |
using namespace std; |
34 |
|
35 |
Q2TH::Q2TH(TString host, TString user, TString psw){ |
36 |
this->Open(host,user,psw); |
37 |
}; |
38 |
|
39 |
void Q2TH::Open(TString host, TString user, TString psw){ |
40 |
fh = gSystem->ExpandPathName(host.Data()); |
41 |
fu = gSystem->ExpandPathName(user.Data()); |
42 |
fp = gSystem->ExpandPathName(psw.Data()); |
43 |
printf(" Connecting to DB %s \n",fh.Data()); |
44 |
dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); |
45 |
if ( dbc && dbc->IsConnected() ){ |
46 |
printf(" connected! \n"); |
47 |
} else { |
48 |
printf(" ERROR! not connected... :( \n"); |
49 |
}; |
50 |
}; |
51 |
|
52 |
TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){ |
53 |
// |
54 |
if ( !strcmp(query.Data(),"help") ){ |
55 |
printf(" USAGE: \n"); |
56 |
printf(" 1) start root and create Q2TH object with \n"); |
57 |
printf(" Q2TH *qt = new Q2TH() \n"); |
58 |
printf(" or \n"); |
59 |
printf(" Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\") \n"); |
60 |
printf(" 2) query the DB with \n"); |
61 |
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\"); \n"); |
62 |
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n"); |
63 |
printf(" qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n"); |
64 |
printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo: \n"); |
65 |
printf(" TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n"); |
66 |
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n"); |
67 |
|
68 |
return NULL; |
69 |
}; |
70 |
// |
71 |
if (Row) |
72 |
delete Row; |
73 |
pResult = dbc->Query(query.Data()); |
74 |
// |
75 |
Row = pResult->Next(); |
76 |
// |
77 |
Int_t dim = pResult->GetFieldCount(); |
78 |
if ( dim < 1 || dim > 2 ){ |
79 |
printf(" Dim == %i not supported yet \n",dim); |
80 |
return NULL; |
81 |
}; |
82 |
// |
83 |
TH1D *h1 = NULL; |
84 |
TH2D *h2 = NULL; |
85 |
Double_t f1 = 0.; |
86 |
Double_t minf1 = numeric_limits<Double_t>::max(); |
87 |
Double_t maxf1 = numeric_limits<Double_t>::min(); |
88 |
Double_t f2 = 0.; |
89 |
Double_t minf2 = numeric_limits<Double_t>::max(); |
90 |
Double_t maxf2 = numeric_limits<Double_t>::min(); |
91 |
// |
92 |
while ( Row ){ |
93 |
f1 = (Double_t)atof(Row->GetField(0)); |
94 |
if ( f1 > maxf1 ) maxf1 = f1; |
95 |
if ( f1 < minf1 ) minf1 = f1; |
96 |
if ( dim == 2 ){ |
97 |
f2 = (Double_t)atof(Row->GetField(1)); |
98 |
if ( f2 > maxf2 ) maxf2 = f2; |
99 |
if ( f2 < minf2 ) minf2 = f2; |
100 |
|
101 |
}; |
102 |
if (Row) |
103 |
delete Row; |
104 |
Row = pResult->Next(); |
105 |
}; |
106 |
pResult->Delete(); |
107 |
// |
108 |
|
109 |
// |
110 |
Int_t f1bin = 70; |
111 |
Int_t f2bin = 70; |
112 |
if ( dim == 1 ){ |
113 |
f1bin = int((maxf1-minf1)/1000.); |
114 |
if ( f1bin < 70 ) f1bin = 70; |
115 |
if ( f1bin > 1000 ) f1bin = 1000; |
116 |
if ( !strcmp(hname.Data(),"q2th") ) hname += "1"; |
117 |
// h1 = dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data())); |
118 |
h1 = (TH1D*)(gDirectory->FindObject(hname.Data())); |
119 |
if ( !strcmp(hname.Data(),"q2th1") ){ |
120 |
if ( h1 ) h1->Delete(); |
121 |
}; |
122 |
if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02); |
123 |
// h1->SetBit(TH1::kCanRebin); |
124 |
if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); |
125 |
}; |
126 |
if ( dim == 2 ){ |
127 |
f2bin = int((maxf2-minf2)/1000.); |
128 |
if ( f2bin < 70 ) f2bin = 70; |
129 |
if ( f2bin > 1000 ) f2bin = 1000; |
130 |
if ( !strcmp(hname.Data(),"q2th") ) hname += "2"; |
131 |
// h2 = dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data())); |
132 |
h2 = (TH2D*)(gDirectory->FindObject(hname.Data())); |
133 |
if ( !strcmp(hname.Data(),"q2th2") ){ |
134 |
if ( h2 ) h2->Delete(); |
135 |
}; |
136 |
if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); |
137 |
// h2->SetBit(TH2::kCanRebin); |
138 |
if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); |
139 |
}; |
140 |
// |
141 |
pResult = dbc->Query(query.Data()); |
142 |
// |
143 |
if (Row) |
144 |
delete Row; |
145 |
Row = pResult->Next(); |
146 |
// |
147 |
Int_t r = 0; |
148 |
// |
149 |
while ( Row ){ |
150 |
f1 = (Double_t)atof(Row->GetField(0)); |
151 |
if ( dim == 1 ){ |
152 |
if ( verbose ) printf(" %i %f \n",r,f1); |
153 |
h1->Fill(f1); |
154 |
} else { |
155 |
f2 = (Double_t)atof(Row->GetField(1)); |
156 |
if ( verbose ) printf(" %i %f %f \n",r,f1,f2); |
157 |
h2->Fill(f1,f2); |
158 |
}; |
159 |
r++; |
160 |
if (Row) |
161 |
delete Row; |
162 |
Row = pResult->Next(); |
163 |
}; |
164 |
// |
165 |
TCanvas *c = NULL; |
166 |
TString cname = Form("%sc",hname.Data()); |
167 |
// c = dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data())); |
168 |
c = (TCanvas*)(gDirectory->FindObject(cname.Data())); |
169 |
if ( !c ) c = new TCanvas(Form("%sc",cname.Data())); |
170 |
c->Clear(); |
171 |
c->cd(); |
172 |
if ( dim == 1 ) h1->Draw(); |
173 |
if ( dim == 2 ) h2->Draw(); |
174 |
// |
175 |
if (Row) |
176 |
delete Row; |
177 |
pResult->Delete(); |
178 |
if ( dim == 1 ) return h1; |
179 |
if ( dim == 2 ) return h2; |
180 |
// |
181 |
return NULL; |
182 |
}; |
183 |
|
184 |
GL_TABLES::GL_TABLES(){ |
185 |
}; |
186 |
|
187 |
GL_TABLES::GL_TABLES(TString host, TString user, TString psw){ |
188 |
fHost = new TString(host.Data()); |
189 |
fUser = new TString(user.Data()); |
190 |
fPsw = new TString(psw.Data()); |
191 |
fSet = true; |
192 |
fNquery = 0; |
193 |
mh = host.Data(); |
194 |
mu = user.Data(); |
195 |
mp = psw.Data(); |
196 |
}; |
197 |
|
198 |
|
199 |
void GL_TABLES::Set(TString host, TString user, TString psw){ |
200 |
fHost = new TString(host.Data()); |
201 |
fUser = new TString(user.Data()); |
202 |
fPsw = new TString(psw.Data()); |
203 |
fSet = true; |
204 |
fNquery = 0; |
205 |
mh = host.Data(); |
206 |
mu = user.Data(); |
207 |
mp = psw.Data(); |
208 |
}; |
209 |
|
210 |
//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
211 |
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
212 |
// |
213 |
// |
214 |
// |
215 |
if ( !fSet ){ |
216 |
return true; |
217 |
}; |
218 |
// |
219 |
// printf(" host is %s \n",fHost->Data()); |
220 |
// |
221 |
stringstream myquery; |
222 |
myquery.str(""); |
223 |
myquery << "show databases;"; |
224 |
if ( dbc ){ |
225 |
if ( dbc->IsConnected() ){ |
226 |
delete dbc->Query(myquery.str().c_str()); |
227 |
fNquery++; |
228 |
if ( !(dbc->GetErrorCode()) ){ |
229 |
// printf("ok\n"); |
230 |
// |
231 |
// if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ |
232 |
// if ( !(dbc->GetErrorCode()) ){ |
233 |
// is connected |
234 |
return true; |
235 |
// }; |
236 |
}; |
237 |
}; |
238 |
}; |
239 |
// |
240 |
if ( true ) { |
241 |
// |
242 |
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
243 |
// |
244 |
TString host = fHost->Data(); |
245 |
TString user = fUser->Data(); |
246 |
TString psw = fPsw->Data(); |
247 |
if ( dbc ){ |
248 |
dbc->Close(); |
249 |
delete dbc; |
250 |
dbc = 0; |
251 |
}; |
252 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
253 |
// |
254 |
myquery.str(""); |
255 |
myquery << "show databases;"; |
256 |
delete dbc->Query(myquery.str().c_str()); |
257 |
fNquery++; |
258 |
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
259 |
if ( !(dbc->GetErrorCode()) ){ |
260 |
// |
261 |
printf(" ...connection recovered, I can continue! \n"); |
262 |
// |
263 |
myquery.str(""); |
264 |
myquery << "SET time_zone='+0:00'"; |
265 |
delete dbc->Query(myquery.str().c_str()); |
266 |
fNquery++; |
267 |
myquery.str(""); |
268 |
myquery << "SET wait_timeout=173000;"; |
269 |
delete dbc->Query(myquery.str().c_str()); |
270 |
fNquery++; |
271 |
return true; |
272 |
}; |
273 |
}; |
274 |
// |
275 |
printf(" GLTABLES: connection is gone away, query will fail\n"); |
276 |
// |
277 |
return false; |
278 |
// |
279 |
}; |
280 |
|
281 |
void GL_TABLES::ResetCounters(){ |
282 |
fNquery = 0; |
283 |
}; |
284 |
|
285 |
void GL_TABLES::AddQ(){ |
286 |
if ( fSet ) fNquery++; |
287 |
}; |
288 |
|
289 |
UInt_t GL_TABLES::GetNqueries(){ |
290 |
UInt_t rn = 0; |
291 |
rn += (UInt_t&)fNquery; |
292 |
return(rn); |
293 |
}; |
294 |
|
295 |
GL_RUN::GL_RUN() { |
296 |
ID = 0; |
297 |
ID_RUN_FRAG = 0; |
298 |
ID_ROOT_L0 = 0; |
299 |
ID_ROOT_L2 = 0; |
300 |
RUNHEADER_TIME = 0; |
301 |
RUNTRAILER_TIME = 0; |
302 |
EV_FROM = 0; |
303 |
EV_TO = 0; |
304 |
TRK_CALIB_USED = 0; |
305 |
EFF_WRK_SCHEDULE = 0; |
306 |
PRH_VAR_TRG_MODE_A = 0; |
307 |
PRH_VAR_TRG_MODE_B = 0; |
308 |
ACQ_BUILD_INFO = 0; |
309 |
ACQ_VAR_INFO = 0; |
310 |
RUNHEADER_OBT = 0; |
311 |
RUNTRAILER_OBT = 0; |
312 |
RUNHEADER_PKT = 0; |
313 |
RUNTRAILER_PKT = 0; |
314 |
NEVENTS = 0; |
315 |
LAST_TIMESYNC = 0; |
316 |
OBT_TIMESYNC = 0; |
317 |
COMPILATIONTIMESTAMP = 0; |
318 |
FAV_WRK_SCHEDULE = 0; |
319 |
RM_ACQ_AFTER_CALIB = 0; |
320 |
RM_ACQ_SETTING_MODE = 0; |
321 |
PKT_COUNTER = 0; |
322 |
PKT_READY_COUNTER = 0; |
323 |
TRK_CALIB_USED = 0; |
324 |
CAL_DSP_MASK = 0; |
325 |
BOOT_NUMBER = 0; |
326 |
PHYSENDRUN_MASK_S3S2S12 = 0; |
327 |
PHYSENDRUN_MASK_S11CRC = 0; |
328 |
VALIDATION = 0; |
329 |
} |
330 |
|
331 |
|
332 |
void GL_RUN::Clear(Option_t *t) { |
333 |
ID = 0; |
334 |
ID_RUN_FRAG = 0; |
335 |
ID_ROOT_L0 = 0; |
336 |
ID_ROOT_L2 = 0; |
337 |
RUNHEADER_TIME = 0; |
338 |
RUNTRAILER_TIME = 0; |
339 |
EV_FROM = 0; |
340 |
EV_TO = 0; |
341 |
TRK_CALIB_USED = 0; |
342 |
EFF_WRK_SCHEDULE = 0; |
343 |
PRH_VAR_TRG_MODE_A = 0; |
344 |
PRH_VAR_TRG_MODE_B = 0; |
345 |
ACQ_BUILD_INFO = 0; |
346 |
ACQ_VAR_INFO = 0; |
347 |
RUNHEADER_OBT = 0; |
348 |
RUNTRAILER_OBT = 0; |
349 |
RUNHEADER_PKT = 0; |
350 |
RUNTRAILER_PKT = 0; |
351 |
NEVENTS = 0; |
352 |
LAST_TIMESYNC = 0; |
353 |
OBT_TIMESYNC = 0; |
354 |
COMPILATIONTIMESTAMP = 0; |
355 |
FAV_WRK_SCHEDULE = 0; |
356 |
RM_ACQ_AFTER_CALIB = 0; |
357 |
RM_ACQ_SETTING_MODE = 0; |
358 |
PKT_COUNTER = 0; |
359 |
PKT_READY_COUNTER = 0; |
360 |
TRK_CALIB_USED = 0; |
361 |
CAL_DSP_MASK = 0; |
362 |
BOOT_NUMBER = 0; |
363 |
PHYSENDRUN_MASK_S3S2S12 = 0; |
364 |
PHYSENDRUN_MASK_S11CRC = 0; |
365 |
VALIDATION = 0; |
366 |
} |
367 |
|
368 |
GL_ROOT::GL_ROOT(){ |
369 |
ID = 0; |
370 |
ID_RAW = 0; |
371 |
ID_TIMESYNC = 0; |
372 |
PATH = ""; |
373 |
NAME = ""; |
374 |
} |
375 |
|
376 |
GL_RAW::GL_RAW(){ |
377 |
ID = 0; |
378 |
PATH = ""; |
379 |
NAME = ""; |
380 |
BOOT_NUMBER = 0; |
381 |
} |
382 |
|
383 |
GL_PARAM::GL_PARAM(){ |
384 |
ID = 0; |
385 |
PATH = ""; |
386 |
NAME = ""; |
387 |
DESCR = ""; |
388 |
FROM_TIME = 0; |
389 |
TO_TIME = 0; |
390 |
TYPE = 0; |
391 |
} |
392 |
|
393 |
|
394 |
GL_TRK_CALIB::GL_TRK_CALIB(){ |
395 |
ID = 0; |
396 |
ID_ROOT_L0 = 0; |
397 |
EV_ROOT_CALIBTRK1 = 0; |
398 |
EV_ROOT_CALIBTRK2 = 0; |
399 |
FROM_TIME = 0; |
400 |
TO_TIME = 0; |
401 |
OBT1 = 0; |
402 |
OBT2 = 0; |
403 |
PKT1 = 0; |
404 |
PKT2 = 0; |
405 |
BOOT_NUMBER = 0; |
406 |
VALIDATION = 0; |
407 |
} |
408 |
|
409 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
410 |
ID = 0; |
411 |
ID_ROOT_L0 = 0; |
412 |
EV_ROOT = 0; |
413 |
FROM_TIME = 0; |
414 |
TO_TIME = 0; |
415 |
SECTION = 0; |
416 |
OBT = 0; |
417 |
PKT = 0; |
418 |
BOOT_NUMBER = 0; |
419 |
VALIDATION = 0; |
420 |
} |
421 |
|
422 |
GL_CALOPULSE_CALIB::GL_CALOPULSE_CALIB(){ |
423 |
ID = 0; |
424 |
ID_ROOT_L0 = 0; |
425 |
EV_ROOT = 0; |
426 |
FROM_TIME = 0; |
427 |
TO_TIME = 0; |
428 |
SECTION = 0; |
429 |
PULSED_STRIP = 0; |
430 |
PULSE_AMPLITUDE = 0; |
431 |
OBT = 0; |
432 |
PKT = 0; |
433 |
BOOT_NUMBER = 0; |
434 |
VALIDATION = 0; |
435 |
} |
436 |
|
437 |
GL_S4_CALIB::GL_S4_CALIB(){ |
438 |
ID = 0; |
439 |
ID_ROOT_L0 = 0; |
440 |
EV_ROOT = 0; |
441 |
FROM_TIME = 0; |
442 |
TO_TIME = 0; |
443 |
OBT = 0; |
444 |
PKT = 0; |
445 |
BOOT_NUMBER = 0; |
446 |
} |
447 |
|
448 |
GL_TIMESYNC::GL_TIMESYNC(){ |
449 |
obtfirst = 0; |
450 |
pktfirst = 0; |
451 |
ID_RESURS_OFFSET = 0; |
452 |
ID = 0; |
453 |
ID_RAW = 0; |
454 |
OBT0 = 0; |
455 |
TIMESYNC = 0; |
456 |
TYPE = 0; |
457 |
} |
458 |
|
459 |
// **************************************************** |
460 |
|
461 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
462 |
EV_FROM = evfrom; |
463 |
}; |
464 |
|
465 |
void GL_RUN::SetEV_TO(UInt_t evto){ |
466 |
EV_TO = evto; |
467 |
}; |
468 |
|
469 |
void GL_RUN::SetNEVENTS(UInt_t nev){ |
470 |
NEVENTS = nev; |
471 |
}; |
472 |
|
473 |
void GL_RUN::SetBOOTNUMBER(UInt_t boot){ |
474 |
BOOT_NUMBER = boot; |
475 |
}; |
476 |
|
477 |
void GL_RUN::SetRUNHEADER_TIME(UInt_t absth){ |
478 |
RUNHEADER_TIME = absth; |
479 |
}; |
480 |
|
481 |
void GL_RUN::SetRUNTRAILER_TIME(UInt_t abstt){ |
482 |
RUNTRAILER_TIME = abstt; |
483 |
}; |
484 |
|
485 |
void GL_RUN::SetRUNHEADER_PKT(UInt_t absth){ |
486 |
RUNHEADER_PKT = absth; |
487 |
}; |
488 |
|
489 |
void GL_RUN::SetRUNTRAILER_PKT(UInt_t abstt){ |
490 |
RUNTRAILER_PKT = abstt; |
491 |
}; |
492 |
|
493 |
void GL_RUN::SetRUNHEADER_OBT(UInt_t absth){ |
494 |
RUNHEADER_OBT = absth; |
495 |
}; |
496 |
|
497 |
void GL_RUN::SetRUNTRAILER_OBT(UInt_t abstt){ |
498 |
RUNTRAILER_OBT = abstt; |
499 |
}; |
500 |
|
501 |
void GL_RUN::SetID_ROOT_L2(UInt_t idl2){ |
502 |
ID_ROOT_L2 = idl2; |
503 |
}; |
504 |
|
505 |
void GL_RUN::SetID_ROOT_L0(UInt_t idroot){ |
506 |
ID_ROOT_L0 = idroot; |
507 |
}; |
508 |
|
509 |
void GL_RUN::SetID_RUN_FRAG(UInt_t idfrag){ |
510 |
ID_RUN_FRAG = idfrag; |
511 |
}; |
512 |
|
513 |
void GL_RUN::SetVALIDATION(UInt_t valid){ |
514 |
VALIDATION = valid; |
515 |
}; |
516 |
|
517 |
void GL_RUN::SetLAST_TIMESYNC(UInt_t ts){ |
518 |
LAST_TIMESYNC = ts; |
519 |
}; |
520 |
|
521 |
void GL_RUN::SetOBT_TIMESYNC(UInt_t ts){ |
522 |
OBT_TIMESYNC = ts; |
523 |
}; |
524 |
|
525 |
void GL_RUN:: SetPKT_COUNTER(UInt_t value){ |
526 |
PKT_COUNTER = value; |
527 |
}; |
528 |
|
529 |
void GL_RUN:: SetPKT_READY_COUNTER(UInt_t value){ |
530 |
PKT_READY_COUNTER = value; |
531 |
}; |
532 |
|
533 |
void GL_RUN:: SetCOMPILATIONTIMESTAMP(UInt_t value){ |
534 |
COMPILATIONTIMESTAMP = value; |
535 |
}; |
536 |
|
537 |
void GL_RUN:: SetPHYSENDRUN_MASK_S3S2S12(UInt_t value){ |
538 |
PHYSENDRUN_MASK_S3S2S12 = value; |
539 |
}; |
540 |
|
541 |
void GL_RUN:: SetPHYSENDRUN_MASK_S11CRC(UInt_t value){ |
542 |
PHYSENDRUN_MASK_S11CRC = value; |
543 |
}; |
544 |
|
545 |
|
546 |
void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){ |
547 |
FAV_WRK_SCHEDULE = value; |
548 |
}; |
549 |
|
550 |
void GL_RUN:: SetEFF_WRK_SCHEDULE(UInt_t value){ |
551 |
EFF_WRK_SCHEDULE = value; |
552 |
}; |
553 |
|
554 |
void GL_RUN:: SetPRH_VAR_TRG_MODE_A(UInt_t value){ |
555 |
PRH_VAR_TRG_MODE_A = value; |
556 |
}; |
557 |
|
558 |
void GL_RUN:: SetPRH_VAR_TRG_MODE_B(UInt_t value){ |
559 |
PRH_VAR_TRG_MODE_B = value; |
560 |
}; |
561 |
|
562 |
void GL_RUN:: SetACQ_BUILD_INFO(UInt_t value){ |
563 |
ACQ_BUILD_INFO = value; |
564 |
}; |
565 |
|
566 |
void GL_RUN:: SetACQ_VAR_INFO(UInt_t value){ |
567 |
ACQ_VAR_INFO = value; |
568 |
}; |
569 |
|
570 |
void GL_RUN:: SetRM_ACQ_AFTER_CALIB(UInt_t value){ |
571 |
RM_ACQ_AFTER_CALIB = value; |
572 |
}; |
573 |
|
574 |
void GL_RUN:: SetRM_ACQ_SETTING_MODE(UInt_t value){ |
575 |
RM_ACQ_SETTING_MODE = value; |
576 |
}; |
577 |
|
578 |
void GL_RUN:: SetTRK_CALIB_USED(UInt_t value){ |
579 |
TRK_CALIB_USED = value; |
580 |
}; |
581 |
|
582 |
void GL_RUN:: SetCAL_DSP_MASK(UInt_t value){ |
583 |
CAL_DSP_MASK = value; |
584 |
}; |
585 |
|
586 |
void GL_RUN:: SetID(UInt_t value){ |
587 |
ID = value; |
588 |
}; |
589 |
|
590 |
void GL_RUN::Set_GL_RUNT(RunTrailerEvent *runt, PscuHeader *pht){ |
591 |
PKT_COUNTER = runt->PKT_COUNTER; |
592 |
PKT_READY_COUNTER = runt->PKT_ReadyCounter; |
593 |
RUNTRAILER_OBT = pht->GetOrbitalTime(); |
594 |
RUNTRAILER_PKT = pht->GetCounter(); |
595 |
}; |
596 |
|
597 |
void GL_RUN::Set_GL_RUNH(RunHeaderEvent *runh, PscuHeader *phh){ |
598 |
TRK_CALIB_USED = runh->TRK_CALIB_USED; |
599 |
PRH_VAR_TRG_MODE_A = runh->PRH_VAR_TRIGGER_MODE_A; |
600 |
PRH_VAR_TRG_MODE_B = runh->PRH_VAR_TRIGGER_MODE_B; |
601 |
ACQ_BUILD_INFO = runh->ACQ_BUILD_INFO; |
602 |
ACQ_VAR_INFO = runh->ACQ_VAR_INFO; |
603 |
RUNHEADER_OBT = phh->GetOrbitalTime(); |
604 |
RUNHEADER_PKT = phh->GetCounter(); |
605 |
LAST_TIMESYNC = runh->LAST_TIME_SYNC_INFO; |
606 |
OBT_TIMESYNC = runh->OBT_TIME_SYNC; |
607 |
COMPILATIONTIMESTAMP = runh->COMPILATIONTIMESTAMP; |
608 |
FAV_WRK_SCHEDULE = runh->FAVOURITE_WORKING_SCHEDULE; |
609 |
EFF_WRK_SCHEDULE = runh->EFFECTIVE_WORKING_SCHEDULE; |
610 |
RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB; |
611 |
RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE; |
612 |
TRK_CALIB_USED = runh->TRK_CALIB_USED; |
613 |
CAL_DSP_MASK = runh->CAL_DSP_MASK; |
614 |
}; |
615 |
|
616 |
void GL_RUN::Set_GL_RUNT0(){ |
617 |
PKT_COUNTER = 0; |
618 |
PKT_READY_COUNTER = 0; |
619 |
RUNTRAILER_OBT = 0; |
620 |
RUNTRAILER_PKT = 0; |
621 |
}; |
622 |
|
623 |
void GL_RUN::Set_GL_RUNH0(){ |
624 |
TRK_CALIB_USED = 0; |
625 |
PRH_VAR_TRG_MODE_A = 0; |
626 |
PRH_VAR_TRG_MODE_B = 0; |
627 |
ACQ_BUILD_INFO = 0; |
628 |
ACQ_VAR_INFO = 0; |
629 |
RUNHEADER_OBT = 0; |
630 |
RUNHEADER_PKT = 0; |
631 |
LAST_TIMESYNC = 0; |
632 |
OBT_TIMESYNC = 0; |
633 |
COMPILATIONTIMESTAMP = 0; |
634 |
FAV_WRK_SCHEDULE = 0; |
635 |
EFF_WRK_SCHEDULE = 0; |
636 |
RM_ACQ_AFTER_CALIB = 0; |
637 |
RM_ACQ_SETTING_MODE = 0; |
638 |
TRK_CALIB_USED = 0; |
639 |
CAL_DSP_MASK = 0; |
640 |
}; |
641 |
|
642 |
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
643 |
for( Int_t t = 0; t < 32; t++){ |
644 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
645 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
646 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
647 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
648 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
649 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
650 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
651 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
652 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
653 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
654 |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
655 |
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
656 |
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
657 |
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
658 |
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
659 |
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
660 |
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
661 |
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
662 |
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
663 |
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
664 |
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
665 |
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
666 |
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
667 |
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
668 |
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
669 |
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
670 |
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
671 |
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
672 |
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
673 |
if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); |
674 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
675 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
676 |
}; |
677 |
|
678 |
} |
679 |
|
680 |
/** |
681 |
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
682 |
* If IDRUN is 0 "this->ID" run is used. |
683 |
* |
684 |
**/ |
685 |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
686 |
// MySQL variables |
687 |
TSQLResult *pResult; |
688 |
TSQLRow *Row = NULL; |
689 |
stringstream myquery; |
690 |
// |
691 |
if ( !IDRUN ) IDRUN = ID; |
692 |
if ( !IDRUN ) return 1; |
693 |
// ---------------- |
694 |
myquery.str(""); |
695 |
myquery << " INSERT INTO GL_RUN_TRASH ("; |
696 |
myquery << "ID"; |
697 |
myquery << ",ID_RUN_FRAG"; |
698 |
myquery << ",ID_ROOT_L0"; |
699 |
myquery << ",ID_ROOT_L2"; |
700 |
myquery << ",RUNHEADER_TIME"; |
701 |
myquery << ",RUNTRAILER_TIME"; |
702 |
myquery << ",RUNHEADER_OBT"; |
703 |
myquery << ",RUNTRAILER_OBT"; |
704 |
myquery << ",RUNHEADER_PKT"; |
705 |
myquery << ",RUNTRAILER_PKT"; |
706 |
myquery << ",BOOT_NUMBER"; |
707 |
myquery << ",EV_FROM"; |
708 |
myquery << ",EV_TO"; |
709 |
myquery << ",NEVENTS"; |
710 |
myquery << ",PKT_COUNTER"; |
711 |
myquery << ",PKT_READY_COUNTER"; |
712 |
myquery << ",COMPILATIONTIMESTAMP"; |
713 |
myquery << ",FAV_WRK_SCHEDULE"; |
714 |
myquery << ",EFF_WRK_SCHEDULE"; |
715 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
716 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
717 |
myquery << ",ACQ_BUILD_INFO"; |
718 |
myquery << ",ACQ_VAR_INFO"; |
719 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
720 |
myquery << ",RM_ACQ_SETTING_MODE"; |
721 |
myquery << ",TRK_CALIB_USED"; |
722 |
myquery << ",CAL_DSP_MASK"; |
723 |
myquery << ",LAST_TIMESYNC"; |
724 |
myquery << ",OBT_TIMESYNC"; |
725 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
726 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
727 |
myquery << ",VALIDATION"; |
728 |
myquery << ",INSERT_TIME"; |
729 |
myquery << ") SELECT * FROM "; |
730 |
myquery << FromTable.Data(); |
731 |
myquery << " WHERE ID="; |
732 |
myquery << (UInt_t)IDRUN << ";"; |
733 |
// |
734 |
// printf("1myquery is %s \n",myquery.str().c_str()); |
735 |
// |
736 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
737 |
this->GetGLTABLES()->AddQ(); |
738 |
delete dbc->Query(myquery.str().c_str()); |
739 |
// |
740 |
// retrieve this ID_TRASH |
741 |
// |
742 |
myquery.str(""); |
743 |
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
744 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
745 |
this->GetGLTABLES()->AddQ(); |
746 |
pResult = dbc->Query(myquery.str().c_str()); |
747 |
// |
748 |
UInt_t idtrash = 0; |
749 |
UInt_t idl0 = 0; |
750 |
UInt_t idl2 = 0; |
751 |
// |
752 |
if (Row) |
753 |
delete Row; |
754 |
Row = pResult->Next(); |
755 |
if( Row != NULL ){ |
756 |
idtrash = (UInt_t)atoll(Row->GetField(0)); |
757 |
idl0 = (UInt_t)atoll(Row->GetField(1)); |
758 |
idl2 = (UInt_t)atoll(Row->GetField(2)); |
759 |
}; |
760 |
// |
761 |
TString fileL0 = ""; |
762 |
TString fileL2 = ""; |
763 |
myquery.str(""); |
764 |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
765 |
myquery << idl0 << ";"; |
766 |
// |
767 |
// printf("2myquery is %s \n",myquery.str().c_str()); |
768 |
// |
769 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ){ |
770 |
if (pResult) |
771 |
delete pResult; |
772 |
if (Row) |
773 |
delete Row; |
774 |
return -57; |
775 |
} |
776 |
this->GetGLTABLES()->AddQ(); |
777 |
pResult = dbc->Query(myquery.str().c_str()); |
778 |
// |
779 |
if (Row) |
780 |
delete Row; |
781 |
Row = pResult->Next(); |
782 |
if( Row != NULL ){ |
783 |
fileL0 = (TString)Row->GetField(0); |
784 |
}; |
785 |
// |
786 |
// |
787 |
// |
788 |
myquery.str(""); |
789 |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
790 |
myquery << idl2 << ";"; |
791 |
// |
792 |
// printf("3myquery is %s \n",myquery.str().c_str()); |
793 |
// |
794 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ){ |
795 |
if (pResult) |
796 |
delete pResult; |
797 |
if (Row) |
798 |
delete Row; |
799 |
return -57; |
800 |
} |
801 |
this->GetGLTABLES()->AddQ(); |
802 |
pResult = dbc->Query(myquery.str().c_str()); |
803 |
// |
804 |
if (Row) |
805 |
delete Row; |
806 |
Row = pResult->Next(); |
807 |
if( Row != NULL ){ |
808 |
fileL2 = (TString)Row->GetField(0); |
809 |
} |
810 |
delete pResult; |
811 |
pResult = NULL; |
812 |
if (Row){ |
813 |
delete Row; |
814 |
Row = NULL; // This variable is not used below |
815 |
} |
816 |
// |
817 |
// |
818 |
// |
819 |
myquery.str(""); |
820 |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
821 |
myquery << fileL0.Data() << "' where ID_TRASH="; |
822 |
myquery << idtrash << ";"; |
823 |
// |
824 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
825 |
// |
826 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
827 |
this->GetGLTABLES()->AddQ(); |
828 |
delete dbc->Query(myquery.str().c_str()); |
829 |
// |
830 |
myquery.str(""); |
831 |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
832 |
myquery << fileL2.Data() << "' where ID_TRASH="; |
833 |
myquery << idtrash << ";"; |
834 |
// |
835 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
836 |
// |
837 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
838 |
this->GetGLTABLES()->AddQ(); |
839 |
delete dbc->Query(myquery.str().c_str()); |
840 |
// |
841 |
myquery.str(""); |
842 |
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
843 |
myquery << FromTable.Data() << "' where ID_TRASH="; |
844 |
myquery << idtrash << ";"; |
845 |
// |
846 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
847 |
// |
848 |
// |
849 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
850 |
this->GetGLTABLES()->AddQ(); |
851 |
delete dbc->Query(myquery.str().c_str()); |
852 |
// |
853 |
myquery.str(""); |
854 |
myquery << " DELETE FROM "; |
855 |
myquery << FromTable.Data() << " where ID="; |
856 |
myquery << IDRUN << ";"; |
857 |
// |
858 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
859 |
// |
860 |
// |
861 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
862 |
this->GetGLTABLES()->AddQ(); |
863 |
delete dbc->Query(myquery.str().c_str()); |
864 |
// |
865 |
return 0; |
866 |
}; |
867 |
|
868 |
|
869 |
|
870 |
/** |
871 |
* This method restore a run from the GL_RUN_TRASH table. |
872 |
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
873 |
* |
874 |
**/ |
875 |
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
876 |
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
877 |
//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; |
878 |
// MySQL variables |
879 |
TSQLResult *pResult = NULL; |
880 |
TSQLRow *Row = NULL; |
881 |
stringstream myquery; |
882 |
// |
883 |
if ( !IDRUN ) IDRUN = ID; |
884 |
if ( !IDRUN ) return 1; |
885 |
// |
886 |
if ( !strcmp(ToTable.Data(),"") ){ |
887 |
// |
888 |
myquery.str(""); |
889 |
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
890 |
myquery << (UInt_t)IDRUN << ";"; |
891 |
// |
892 |
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
893 |
// |
894 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
895 |
this->GetGLTABLES()->AddQ(); |
896 |
pResult = dbc->Query(myquery.str().c_str()); |
897 |
// |
898 |
Row = pResult->Next(); |
899 |
if( Row != NULL ){ |
900 |
ToTable = (TString)Row->GetField(0); |
901 |
} else { |
902 |
delete pResult; |
903 |
return 1; |
904 |
}; |
905 |
}; |
906 |
|
907 |
if (pResult) |
908 |
delete pResult; |
909 |
if (Row) |
910 |
delete Row; |
911 |
// ---------------- |
912 |
myquery.str(""); |
913 |
myquery << " INSERT INTO "; |
914 |
myquery << ToTable.Data(); |
915 |
myquery << " ("; |
916 |
myquery << "ID"; |
917 |
myquery << ",ID_RUN_FRAG"; |
918 |
myquery << ",ID_ROOT_L0"; |
919 |
myquery << ",ID_ROOT_L2"; |
920 |
myquery << ",RUNHEADER_TIME"; |
921 |
myquery << ",RUNTRAILER_TIME"; |
922 |
myquery << ",RUNHEADER_OBT"; |
923 |
myquery << ",RUNTRAILER_OBT"; |
924 |
myquery << ",RUNHEADER_PKT"; |
925 |
myquery << ",RUNTRAILER_PKT"; |
926 |
myquery << ",BOOT_NUMBER"; |
927 |
myquery << ",EV_FROM"; |
928 |
myquery << ",EV_TO"; |
929 |
myquery << ",NEVENTS"; |
930 |
myquery << ",PKT_COUNTER"; |
931 |
myquery << ",PKT_READY_COUNTER"; |
932 |
myquery << ",COMPILATIONTIMESTAMP"; |
933 |
myquery << ",FAV_WRK_SCHEDULE"; |
934 |
myquery << ",EFF_WRK_SCHEDULE"; |
935 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
936 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
937 |
myquery << ",ACQ_BUILD_INFO"; |
938 |
myquery << ",ACQ_VAR_INFO"; |
939 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
940 |
myquery << ",RM_ACQ_SETTING_MODE"; |
941 |
myquery << ",TRK_CALIB_USED"; |
942 |
myquery << ",CAL_DSP_MASK"; |
943 |
myquery << ",LAST_TIMESYNC"; |
944 |
myquery << ",OBT_TIMESYNC"; |
945 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
946 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
947 |
myquery << ",VALIDATION"; |
948 |
myquery << ",INSERT_TIME"; |
949 |
myquery << ") SELECT "; |
950 |
myquery << "ID"; |
951 |
myquery << ",ID_RUN_FRAG"; |
952 |
myquery << ",ID_ROOT_L0"; |
953 |
myquery << ",ID_ROOT_L2"; |
954 |
myquery << ",RUNHEADER_TIME"; |
955 |
myquery << ",RUNTRAILER_TIME"; |
956 |
myquery << ",RUNHEADER_OBT"; |
957 |
myquery << ",RUNTRAILER_OBT"; |
958 |
myquery << ",RUNHEADER_PKT"; |
959 |
myquery << ",RUNTRAILER_PKT"; |
960 |
myquery << ",BOOT_NUMBER"; |
961 |
myquery << ",EV_FROM"; |
962 |
myquery << ",EV_TO"; |
963 |
myquery << ",NEVENTS"; |
964 |
myquery << ",PKT_COUNTER"; |
965 |
myquery << ",PKT_READY_COUNTER"; |
966 |
myquery << ",COMPILATIONTIMESTAMP"; |
967 |
myquery << ",FAV_WRK_SCHEDULE"; |
968 |
myquery << ",EFF_WRK_SCHEDULE"; |
969 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
970 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
971 |
myquery << ",ACQ_BUILD_INFO"; |
972 |
myquery << ",ACQ_VAR_INFO"; |
973 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
974 |
myquery << ",RM_ACQ_SETTING_MODE"; |
975 |
myquery << ",TRK_CALIB_USED"; |
976 |
myquery << ",CAL_DSP_MASK"; |
977 |
myquery << ",LAST_TIMESYNC"; |
978 |
myquery << ",OBT_TIMESYNC"; |
979 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
980 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
981 |
myquery << ",VALIDATION"; |
982 |
myquery << ",INSERT_TIME"; |
983 |
myquery << " FROM GL_RUN_TRASH "; |
984 |
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
985 |
myquery << (UInt_t)IDRUN << ";"; |
986 |
// |
987 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
988 |
// |
989 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
990 |
this->GetGLTABLES()->AddQ(); |
991 |
delete dbc->Query(myquery.str().c_str()); |
992 |
// |
993 |
// |
994 |
myquery.str(""); |
995 |
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
996 |
myquery << IDRUN << ";"; |
997 |
// |
998 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
999 |
this->GetGLTABLES()->AddQ(); |
1000 |
delete dbc->Query(myquery.str().c_str()); |
1001 |
// |
1002 |
return 0; |
1003 |
}; |
1004 |
|
1005 |
/** |
1006 |
* Function to fill the GL_RUN table of the DB. |
1007 |
* |
1008 |
* \param |
1009 |
* |
1010 |
*/ |
1011 |
Int_t GL_RUN::Fill_GL_RUN(TSQLServer *dbc){ |
1012 |
// MySQL variables |
1013 |
stringstream myquery; |
1014 |
// ---------------- |
1015 |
myquery.str(""); |
1016 |
myquery << " INSERT INTO GL_RUN ("; |
1017 |
myquery << "ID"; |
1018 |
myquery << ",ID_RUN_FRAG"; |
1019 |
myquery << ",ID_ROOT_L0"; |
1020 |
myquery << ",ID_ROOT_L2"; |
1021 |
myquery << ",RUNHEADER_TIME"; |
1022 |
myquery << ",RUNTRAILER_TIME"; |
1023 |
myquery << ",RUNHEADER_OBT"; |
1024 |
myquery << ",RUNTRAILER_OBT"; |
1025 |
myquery << ",RUNHEADER_PKT"; |
1026 |
myquery << ",RUNTRAILER_PKT"; |
1027 |
myquery << ",EV_FROM"; |
1028 |
myquery << ",EV_TO"; |
1029 |
myquery << ",NEVENTS"; |
1030 |
myquery << ",LAST_TIMESYNC"; |
1031 |
myquery << ",OBT_TIMESYNC"; |
1032 |
myquery << ",COMPILATIONTIMESTAMP"; |
1033 |
myquery << ",FAV_WRK_SCHEDULE"; |
1034 |
myquery << ",EFF_WRK_SCHEDULE"; |
1035 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
1036 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
1037 |
myquery << ",ACQ_BUILD_INFO"; |
1038 |
myquery << ",ACQ_VAR_INFO"; |
1039 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
1040 |
myquery << ",RM_ACQ_SETTING_MODE"; |
1041 |
myquery << ",PKT_COUNTER"; |
1042 |
myquery << ",PKT_READY_COUNTER"; |
1043 |
myquery << ",TRK_CALIB_USED"; |
1044 |
myquery << ",CAL_DSP_MASK"; |
1045 |
myquery << ",BOOT_NUMBER"; |
1046 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
1047 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
1048 |
myquery << ",VALIDATION"; |
1049 |
myquery << ") VALUES ('"; |
1050 |
|
1051 |
myquery << (UInt_t)ID << "','"; |
1052 |
myquery << (UInt_t)ID_RUN_FRAG << "','"; |
1053 |
myquery << (UInt_t)ID_ROOT_L0 << "','"; |
1054 |
myquery << (UInt_t)ID_ROOT_L2 << "','"; |
1055 |
myquery << (UInt_t)RUNHEADER_TIME << "','"; |
1056 |
myquery << (UInt_t)RUNTRAILER_TIME << "','"; |
1057 |
myquery << (UInt_t)RUNHEADER_OBT << "','"; |
1058 |
myquery << (UInt_t)RUNTRAILER_OBT << "','"; |
1059 |
myquery << (UInt_t)RUNHEADER_PKT << "','"; |
1060 |
myquery << (UInt_t)RUNTRAILER_PKT << "','"; |
1061 |
myquery << (UInt_t)EV_FROM << "','"; |
1062 |
myquery << (UInt_t)EV_TO << "','"; |
1063 |
myquery << (UInt_t)NEVENTS << "','"; |
1064 |
myquery << (UInt_t)LAST_TIMESYNC << "','"; |
1065 |
myquery << (UInt_t)OBT_TIMESYNC << "','"; |
1066 |
myquery << (UInt_t)COMPILATIONTIMESTAMP << "','"; |
1067 |
myquery << (UInt_t)FAV_WRK_SCHEDULE << "','"; |
1068 |
myquery << (UInt_t)EFF_WRK_SCHEDULE << "','"; |
1069 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','"; |
1070 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','"; |
1071 |
myquery << (UInt_t)ACQ_BUILD_INFO << "','"; |
1072 |
myquery << (UInt_t)ACQ_VAR_INFO << "','"; |
1073 |
myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','"; |
1074 |
myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','"; |
1075 |
myquery << (UInt_t)PKT_COUNTER << "','"; |
1076 |
myquery << (UInt_t)PKT_READY_COUNTER << "','"; |
1077 |
myquery << (UInt_t)TRK_CALIB_USED << "','"; |
1078 |
myquery << (UInt_t)CAL_DSP_MASK << "','"; |
1079 |
myquery << (UInt_t)BOOT_NUMBER << "','"; |
1080 |
myquery << (UInt_t)PHYSENDRUN_MASK_S3S2S12 << "','"; |
1081 |
myquery << (UInt_t)PHYSENDRUN_MASK_S11CRC << "','"; |
1082 |
myquery << (UInt_t)VALIDATION << "');"; |
1083 |
// |
1084 |
// printf("myquery is %s \n",myquery.str().c_str()); |
1085 |
// |
1086 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1087 |
this->GetGLTABLES()->AddQ(); |
1088 |
delete dbc->Query(myquery.str().c_str()); |
1089 |
// |
1090 |
return 0; |
1091 |
|
1092 |
};// **************************************************** |
1093 |
|
1094 |
/** |
1095 |
* Function to fill the GL_RUN table of the DB. |
1096 |
* |
1097 |
* \param |
1098 |
* |
1099 |
*/ |
1100 |
Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQLServer *dbc){ |
1101 |
// MySQL variables |
1102 |
stringstream myquery; |
1103 |
// ---------------- |
1104 |
myquery.str(""); |
1105 |
myquery << " INSERT INTO GL_RUN_FRAGMENTS ("; |
1106 |
myquery << "ID"; |
1107 |
myquery << ",ID_ROOT_L0"; |
1108 |
myquery << ",RUNHEADER_TIME"; |
1109 |
myquery << ",RUNTRAILER_TIME"; |
1110 |
myquery << ",RUNHEADER_OBT"; |
1111 |
myquery << ",RUNTRAILER_OBT"; |
1112 |
myquery << ",RUNHEADER_PKT"; |
1113 |
myquery << ",RUNTRAILER_PKT"; |
1114 |
myquery << ",EV_FROM"; |
1115 |
myquery << ",EV_TO"; |
1116 |
myquery << ",NEVENTS"; |
1117 |
myquery << ",LAST_TIMESYNC"; |
1118 |
myquery << ",OBT_TIMESYNC"; |
1119 |
myquery << ",COMPILATIONTIMESTAMP"; |
1120 |
myquery << ",FAV_WRK_SCHEDULE"; |
1121 |
myquery << ",EFF_WRK_SCHEDULE"; |
1122 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
1123 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
1124 |
myquery << ",ACQ_BUILD_INFO"; |
1125 |
myquery << ",ACQ_VAR_INFO"; |
1126 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
1127 |
myquery << ",RM_ACQ_SETTING_MODE"; |
1128 |
myquery << ",PKT_COUNTER"; |
1129 |
myquery << ",PKT_READY_COUNTER"; |
1130 |
myquery << ",TRK_CALIB_USED"; |
1131 |
myquery << ",CAL_DSP_MASK"; |
1132 |
myquery << ",BOOT_NUMBER"; |
1133 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
1134 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
1135 |
myquery << ") VALUES ('"; |
1136 |
myquery << (UInt_t)ID << "','"; |
1137 |
myquery << (UInt_t)ID_ROOT_L0 << "','"; |
1138 |
myquery << (UInt_t)RUNHEADER_TIME << "','"; |
1139 |
myquery << (UInt_t)RUNTRAILER_TIME << "','"; |
1140 |
myquery << (UInt_t)RUNHEADER_OBT << "','"; |
1141 |
myquery << (UInt_t)RUNTRAILER_OBT << "','"; |
1142 |
myquery << (UInt_t)RUNHEADER_PKT << "','"; |
1143 |
myquery << (UInt_t)RUNTRAILER_PKT << "','"; |
1144 |
myquery << (UInt_t)EV_FROM << "','"; |
1145 |
myquery << (UInt_t)EV_TO << "','"; |
1146 |
myquery << (UInt_t)NEVENTS << "','"; |
1147 |
myquery << (UInt_t)LAST_TIMESYNC << "','"; |
1148 |
myquery << (UInt_t)OBT_TIMESYNC << "','"; |
1149 |
myquery << (UInt_t)COMPILATIONTIMESTAMP << "','"; |
1150 |
myquery << (UInt_t)FAV_WRK_SCHEDULE << "','"; |
1151 |
myquery << (UInt_t)EFF_WRK_SCHEDULE << "','"; |
1152 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','"; |
1153 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','"; |
1154 |
myquery << (UInt_t)ACQ_BUILD_INFO << "','"; |
1155 |
myquery << (UInt_t)ACQ_VAR_INFO << "','"; |
1156 |
myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','"; |
1157 |
myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','"; |
1158 |
myquery << (UInt_t)PKT_COUNTER << "','"; |
1159 |
myquery << (UInt_t)PKT_READY_COUNTER << "','"; |
1160 |
myquery << (UInt_t)TRK_CALIB_USED << "','"; |
1161 |
myquery << (UInt_t)CAL_DSP_MASK << "','"; |
1162 |
myquery << (UInt_t)BOOT_NUMBER << "','"; |
1163 |
myquery << (UInt_t)PHYSENDRUN_MASK_S3S2S12 << "','"; |
1164 |
myquery << (UInt_t)PHYSENDRUN_MASK_S11CRC << "');"; |
1165 |
// |
1166 |
// printf("myquery is %s \n",myquery.str().c_str()); |
1167 |
// |
1168 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1169 |
this->GetGLTABLES()->AddQ(); |
1170 |
delete dbc->Query(myquery.str().c_str()); |
1171 |
// |
1172 |
return 0; |
1173 |
|
1174 |
};// **************************************************** |
1175 |
|
1176 |
|
1177 |
/** |
1178 |
* Function to query the GL_RUN table of the DB. |
1179 |
* |
1180 |
* \param RUN id |
1181 |
* \return struct of type GL_RUN _data, which stores the query result |
1182 |
* |
1183 |
*/ |
1184 |
Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ |
1185 |
// MySQL variables |
1186 |
TSQLResult *pResult; |
1187 |
TSQLRow *Row = NULL; |
1188 |
int r; |
1189 |
stringstream myquery; |
1190 |
// ---------------- |
1191 |
myquery.str(""); |
1192 |
myquery << " select "; |
1193 |
myquery << "ID"; |
1194 |
myquery << ",ID_RUN_FRAG"; |
1195 |
myquery << ",ID_ROOT_L0"; |
1196 |
myquery << ",ID_ROOT_L2"; |
1197 |
myquery << ",RUNHEADER_TIME"; |
1198 |
myquery << ",RUNTRAILER_TIME"; |
1199 |
myquery << ",RUNHEADER_OBT"; |
1200 |
myquery << ",RUNTRAILER_OBT"; |
1201 |
myquery << ",RUNHEADER_PKT"; |
1202 |
myquery << ",RUNTRAILER_PKT"; |
1203 |
myquery << ",EV_FROM"; |
1204 |
myquery << ",EV_TO"; |
1205 |
myquery << ",NEVENTS"; |
1206 |
myquery << ",LAST_TIMESYNC"; |
1207 |
myquery << ",OBT_TIMESYNC"; |
1208 |
myquery << ",COMPILATIONTIMESTAMP"; |
1209 |
myquery << ",FAV_WRK_SCHEDULE"; |
1210 |
myquery << ",EFF_WRK_SCHEDULE"; |
1211 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
1212 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
1213 |
myquery << ",ACQ_BUILD_INFO"; |
1214 |
myquery << ",ACQ_VAR_INFO"; |
1215 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
1216 |
myquery << ",RM_ACQ_SETTING_MODE"; |
1217 |
myquery << ",PKT_COUNTER"; |
1218 |
myquery << ",PKT_READY_COUNTER"; |
1219 |
myquery << ",TRK_CALIB_USED"; |
1220 |
myquery << ",CAL_DSP_MASK"; |
1221 |
myquery << ",BOOT_NUMBER"; |
1222 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
1223 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
1224 |
myquery << ",VALIDATION"; |
1225 |
myquery << " from GL_RUN where ID=" << run << ";"; |
1226 |
// |
1227 |
// printf(" myquery is %s \n",myquery.str().c_str()); |
1228 |
if ( !this->IsConnected(dbc) ) return -57; |
1229 |
this->AddQ(); |
1230 |
pResult = dbc->Query(myquery.str().c_str()); |
1231 |
// |
1232 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
1233 |
// |
1234 |
if( !pResult->GetRowCount() ){ |
1235 |
delete pResult; |
1236 |
if (Row) |
1237 |
delete Row; |
1238 |
return(-50); |
1239 |
} |
1240 |
// |
1241 |
for( r=0; r < 1000; r++){ |
1242 |
if (Row) |
1243 |
delete Row; |
1244 |
Row = pResult->Next(); |
1245 |
if( Row == NULL ) break; |
1246 |
// Set_GL_RUN(Row); |
1247 |
for( int t = 0; t < pResult->GetFieldCount(); t++){ |
1248 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
1249 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
1250 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1251 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
1252 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1253 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1254 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1255 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1256 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1257 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1258 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1259 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1260 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1261 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1262 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1263 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1264 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1265 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1266 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
1267 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
1268 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1269 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1270 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
1271 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
1272 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1273 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1274 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1275 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1276 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1277 |
if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); |
1278 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
1279 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1280 |
}; |
1281 |
} |
1282 |
|
1283 |
if (Row) |
1284 |
delete Row; |
1285 |
delete pResult; |
1286 |
return(0); |
1287 |
}; |
1288 |
|
1289 |
/** |
1290 |
* Function to query the GL_RUN table of the DB. |
1291 |
* |
1292 |
* \param where = condition string |
1293 |
* \return struct of type GL_RUN _data, which stores the query result |
1294 |
* |
1295 |
*/ |
1296 |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
1297 |
// MySQL variables |
1298 |
TSQLResult *pResult; |
1299 |
TSQLRow *Row = NULL; |
1300 |
int t; |
1301 |
int r; |
1302 |
stringstream myquery; |
1303 |
// ---------------- |
1304 |
myquery.str(""); |
1305 |
myquery << " select "; |
1306 |
myquery << "ID"; |
1307 |
myquery << ",ID_RUN_FRAG"; |
1308 |
myquery << ",ID_ROOT_L0"; |
1309 |
myquery << ",ID_ROOT_L2"; |
1310 |
myquery << ",RUNHEADER_TIME"; |
1311 |
myquery << ",RUNTRAILER_TIME"; |
1312 |
myquery << ",RUNHEADER_OBT"; |
1313 |
myquery << ",RUNTRAILER_OBT"; |
1314 |
myquery << ",RUNHEADER_PKT"; |
1315 |
myquery << ",RUNTRAILER_PKT"; |
1316 |
myquery << ",EV_FROM"; |
1317 |
myquery << ",EV_TO"; |
1318 |
myquery << ",NEVENTS"; |
1319 |
myquery << ",LAST_TIMESYNC"; |
1320 |
myquery << ",OBT_TIMESYNC"; |
1321 |
myquery << ",COMPILATIONTIMESTAMP"; |
1322 |
myquery << ",FAV_WRK_SCHEDULE"; |
1323 |
myquery << ",EFF_WRK_SCHEDULE"; |
1324 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
1325 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
1326 |
myquery << ",ACQ_BUILD_INFO"; |
1327 |
myquery << ",ACQ_VAR_INFO"; |
1328 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
1329 |
myquery << ",RM_ACQ_SETTING_MODE"; |
1330 |
myquery << ",PKT_COUNTER"; |
1331 |
myquery << ",PKT_READY_COUNTER"; |
1332 |
myquery << ",TRK_CALIB_USED"; |
1333 |
myquery << ",CAL_DSP_MASK"; |
1334 |
myquery << ",BOOT_NUMBER"; |
1335 |
myquery << ",PHYSENDRUN_MASK_S3S2S12"; |
1336 |
myquery << ",PHYSENDRUN_MASK_S11CRC"; |
1337 |
myquery << ",VALIDATION"; |
1338 |
myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";"; |
1339 |
// |
1340 |
// printf(" query is %s \n",myquery.str().c_str()); |
1341 |
// |
1342 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1343 |
this->GetGLTABLES()->AddQ(); |
1344 |
pResult = dbc->Query(myquery.str().c_str()); |
1345 |
if(!pResult->GetRowCount()){ |
1346 |
delete pResult; |
1347 |
if (Row) |
1348 |
delete Row; |
1349 |
return(-50); |
1350 |
} |
1351 |
for( r=0; r < 1000; r++){ |
1352 |
if (Row) |
1353 |
delete Row; |
1354 |
Row = pResult->Next(); |
1355 |
if( Row == NULL ) break; |
1356 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1357 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
1358 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
1359 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1360 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
1361 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1362 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1363 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1364 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1365 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1366 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1367 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1368 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1369 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1370 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1371 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1372 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1373 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1374 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1375 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
1376 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
1377 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1378 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1379 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
1380 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
1381 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1382 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1383 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1384 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1385 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1386 |
if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); |
1387 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
1388 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1389 |
}; |
1390 |
} |
1391 |
|
1392 |
if (Row) |
1393 |
delete Row; |
1394 |
delete pResult; |
1395 |
return(0); |
1396 |
};// **************************************************** |
1397 |
|
1398 |
/** |
1399 |
* Function to query the GL_ROOT table of the DB. |
1400 |
* |
1401 |
* \param entry ID |
1402 |
* \return struct of type GL_ROOT_data, which stores the query result |
1403 |
*/ |
1404 |
Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ |
1405 |
// MySQL variables |
1406 |
TSQLResult *pResult; |
1407 |
TSQLRow *Row = NULL; |
1408 |
int t; |
1409 |
int r; |
1410 |
stringstream myquery; |
1411 |
// ---------------- |
1412 |
myquery.str(""); |
1413 |
myquery << "select "; |
1414 |
myquery << " ID"; |
1415 |
myquery << ",ID_RAW"; |
1416 |
myquery << ",ID_TIMESYNC"; |
1417 |
myquery << ",PATH"; |
1418 |
myquery << ",NAME"; |
1419 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
1420 |
// |
1421 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1422 |
this->GetGLTABLES()->AddQ(); |
1423 |
pResult = dbc->Query(myquery.str().c_str()); |
1424 |
if(!pResult->GetRowCount()){ |
1425 |
delete pResult; |
1426 |
if (Row) |
1427 |
delete Row; |
1428 |
return (-51); |
1429 |
} |
1430 |
for( r=0; r < 1000; r++){ |
1431 |
if (Row) |
1432 |
delete Row; |
1433 |
Row = pResult->Next(); |
1434 |
if( Row == NULL ) break; |
1435 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1436 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1437 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1438 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1439 |
if(t==3){ |
1440 |
PATH = TString(Row->GetField(t)) + '/'; |
1441 |
gSystem->ExpandPathName(PATH); |
1442 |
} |
1443 |
if(t==4) NAME = Row->GetField(t); |
1444 |
} |
1445 |
} |
1446 |
if (Row) |
1447 |
delete Row; |
1448 |
delete pResult; |
1449 |
return 0; |
1450 |
}; |
1451 |
// **************************************************** |
1452 |
/** |
1453 |
* Function to query the GL_TRK_CALIB table of the DB. |
1454 |
* |
1455 |
* \param run starting time |
1456 |
* \param dbc DB server |
1457 |
* \return struct of type GL_TRK_CALIB_data, which stores the query result |
1458 |
*/ |
1459 |
Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){ |
1460 |
// MySQL variables |
1461 |
TSQLResult *pResult; |
1462 |
TSQLRow *Row = NULL; |
1463 |
int t; |
1464 |
int r; |
1465 |
stringstream myquery; |
1466 |
// ---------------- |
1467 |
myquery.str(""); |
1468 |
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; |
1469 |
// myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!! |
1470 |
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 |
1471 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1472 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1473 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1474 |
this->GetGLTABLES()->AddQ(); |
1475 |
pResult = dbc->Query(myquery.str().c_str()); |
1476 |
if(!pResult->GetRowCount()){ |
1477 |
delete pResult; |
1478 |
return (-53); |
1479 |
} |
1480 |
for( r=0; r < 1000; r++){ |
1481 |
if (Row) |
1482 |
delete Row; |
1483 |
Row = pResult->Next(); |
1484 |
if( Row == NULL ) break; |
1485 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1486 |
stringstream row; |
1487 |
row.str(""); |
1488 |
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 |
1489 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1490 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1491 |
if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str()); |
1492 |
if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str()); |
1493 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1494 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1495 |
// |
1496 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1497 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1498 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1499 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
1500 |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1501 |
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1502 |
}; |
1503 |
} |
1504 |
if (Row) |
1505 |
delete Row; |
1506 |
delete pResult; |
1507 |
// |
1508 |
// if ( TO_TIME < time ) return(51); |
1509 |
// |
1510 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1511 |
// |
1512 |
return 0; |
1513 |
}; |
1514 |
|
1515 |
// **************************************************** |
1516 |
/** |
1517 |
* Function to query the GL_CALO_CALIB table of the DB. |
1518 |
* |
1519 |
* \param run starting time |
1520 |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
1521 |
*/ |
1522 |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ |
1523 |
// MySQL variables |
1524 |
TSQLResult *pResult; |
1525 |
TSQLRow *Row = NULL; |
1526 |
int t; |
1527 |
stringstream myquery; |
1528 |
uptime = 0; |
1529 |
// |
1530 |
// select the correct calibration |
1531 |
// |
1532 |
myquery.str(""); |
1533 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
1534 |
myquery << " and FROM_TIME <= " << time; |
1535 |
myquery << " and TO_TIME > " << time; |
1536 |
myquery << " ;"; |
1537 |
//myquery << " and VALIDATION=1;"; |
1538 |
// |
1539 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1540 |
this->GetGLTABLES()->AddQ(); |
1541 |
pResult = dbc->Query(myquery.str().c_str()); |
1542 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1543 |
// |
1544 |
if (Row) |
1545 |
delete Row; |
1546 |
if( !pResult->GetRowCount() ){ |
1547 |
delete pResult; |
1548 |
return(-54); |
1549 |
} |
1550 |
Row = pResult->Next(); |
1551 |
if( Row == NULL ){ |
1552 |
delete pResult; |
1553 |
return (-54); |
1554 |
} |
1555 |
// |
1556 |
uptime = (UInt_t)atoll(Row->GetField(2)); |
1557 |
// |
1558 |
UInt_t myfromtime = (UInt_t)atoll(Row->GetField(1)); |
1559 |
UInt_t mytotime = (UInt_t)atoll(Row->GetField(2)); |
1560 |
// |
1561 |
// if it is corrupted validation is 0 and we have no results from the query... |
1562 |
// |
1563 |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
1564 |
// |
1565 |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
1566 |
// |
1567 |
myquery.str(""); |
1568 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
1569 |
myquery << " and FROM_TIME <= " << time; |
1570 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1571 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ){ |
1572 |
if(pResult) |
1573 |
delete pResult; |
1574 |
if(Row) |
1575 |
delete Row; |
1576 |
return -57; |
1577 |
} |
1578 |
this->GetGLTABLES()->AddQ(); |
1579 |
pResult = dbc->Query(myquery.str().c_str()); |
1580 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1581 |
// |
1582 |
// if no results yet quit with error |
1583 |
// |
1584 |
if( !pResult->GetRowCount() ){ |
1585 |
delete pResult; |
1586 |
if(Row) |
1587 |
delete Row; |
1588 |
return (-54); |
1589 |
} |
1590 |
// |
1591 |
if (Row) |
1592 |
delete Row; |
1593 |
Row = pResult->Next(); |
1594 |
// |
1595 |
myfromtime = (UInt_t)atoll(Row->GetField(1)); |
1596 |
// |
1597 |
}; |
1598 |
// |
1599 |
// if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one |
1600 |
// |
1601 |
if ( (time-myfromtime)>28500 && myfromtime > 0 ){ |
1602 |
// |
1603 |
myquery.str(""); |
1604 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; |
1605 |
myquery << " and VALIDATION=1 ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;"; |
1606 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ){ |
1607 |
if(pResult) |
1608 |
delete pResult; |
1609 |
if(Row) |
1610 |
delete Row; |
1611 |
return -57; |
1612 |
} |
1613 |
this->GetGLTABLES()->AddQ(); |
1614 |
pResult = dbc->Query(myquery.str().c_str()); |
1615 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1616 |
// |
1617 |
// if no results yet quit with error |
1618 |
// |
1619 |
if( !pResult->GetRowCount() ){ |
1620 |
if (Row) |
1621 |
delete Row; |
1622 |
delete pResult; |
1623 |
return (-54); |
1624 |
} |
1625 |
// |
1626 |
if (Row) |
1627 |
delete Row; |
1628 |
Row = pResult->Next(); |
1629 |
// |
1630 |
}; |
1631 |
// |
1632 |
// store infos and exit |
1633 |
// |
1634 |
if( Row == NULL ){ |
1635 |
delete pResult; |
1636 |
return (-54); |
1637 |
} |
1638 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1639 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1640 |
if (t==1) FROM_TIME = myfromtime; |
1641 |
if (t==2) TO_TIME = mytotime; |
1642 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1643 |
} |
1644 |
if (Row) |
1645 |
delete Row; |
1646 |
delete pResult; |
1647 |
return 0; |
1648 |
}; |
1649 |
|
1650 |
|
1651 |
// **************************************************** |
1652 |
/** |
1653 |
* Function to query the GL_CALOPULSE_CALIB table of the DB. |
1654 |
* |
1655 |
* \param run starting time |
1656 |
* \return struct of type GL_CALOPULSE_CALIB_data, which stores the query result |
1657 |
*/ |
1658 |
Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ |
1659 |
// MySQL variables |
1660 |
TSQLResult *pResult; |
1661 |
TSQLRow *Row = NULL; |
1662 |
int t; |
1663 |
stringstream myquery; |
1664 |
// |
1665 |
// select the correct calibration i.e. the closest to our time |
1666 |
// |
1667 |
myquery.str(""); |
1668 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALOPULSE_CALIB where SECTION=" << section; |
1669 |
myquery << " and PULSE_AMPLITUDE=" << pampli; |
1670 |
myquery << " and VALIDATION=1 and (PULSED_STRIP IS NULL OR PULSED_STRIP<100) ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;"; |
1671 |
// printf(" myq is %s \n",myquery.str().c_str()); |
1672 |
// |
1673 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1674 |
this->GetGLTABLES()->AddQ(); |
1675 |
pResult = dbc->Query(myquery.str().c_str()); |
1676 |
// |
1677 |
if( !pResult ) return(-54); |
1678 |
// |
1679 |
if (Row) |
1680 |
delete Row; |
1681 |
Row = pResult->Next(); |
1682 |
// |
1683 |
if( !Row ){ |
1684 |
delete pResult; |
1685 |
return (-54); |
1686 |
} |
1687 |
// |
1688 |
// store infos and exit |
1689 |
// |
1690 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1691 |
// printf(" field %i is %s \n",t,Row->GetField(t)); |
1692 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1693 |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1694 |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1695 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1696 |
} |
1697 |
if (Row) |
1698 |
delete Row; |
1699 |
pResult->Delete(); |
1700 |
return 0; |
1701 |
}; |
1702 |
|
1703 |
|
1704 |
// **************************************************** |
1705 |
/** |
1706 |
* Function to query the GL_S4_CALIB table of the DB. |
1707 |
* |
1708 |
* \param run starting time |
1709 |
* \return struct of type GL_S4_CALIB_data, which stores the query result |
1710 |
*/ |
1711 |
Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){ |
1712 |
// MySQL variables |
1713 |
TSQLResult *pResult; |
1714 |
TSQLRow *Row = NULL; |
1715 |
int t; |
1716 |
int r; |
1717 |
stringstream myquery; |
1718 |
// ---------------- |
1719 |
myquery.str(""); |
1720 |
myquery << "select ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME from GL_S4_CALIB where FROM_TIME <= "<< time; |
1721 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1722 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1723 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1724 |
this->GetGLTABLES()->AddQ(); |
1725 |
pResult = dbc->Query(myquery.str().c_str()); |
1726 |
if(!pResult->GetRowCount()){ |
1727 |
delete pResult; |
1728 |
return (-55);//throw -55; |
1729 |
} |
1730 |
for( r=0; r < 1000; r++){ |
1731 |
if (Row) |
1732 |
delete Row; |
1733 |
Row = pResult->Next(); |
1734 |
if( Row == NULL ) break; |
1735 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1736 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1737 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1738 |
if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1739 |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1740 |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1741 |
}; |
1742 |
} |
1743 |
if (Row) |
1744 |
delete Row; |
1745 |
delete pResult; |
1746 |
// |
1747 |
if(TO_TIME < time)return(51); |
1748 |
// |
1749 |
return 0; |
1750 |
}; |
1751 |
// **************************************************** |
1752 |
/** |
1753 |
* Function to query the GL_PARAM table of the DB. |
1754 |
* |
1755 |
* \param run starting time |
1756 |
* \param parameter description (DESCR) |
1757 |
* \return struct of type GL_ROOT_data, which stores the query result |
1758 |
*/ |
1759 |
Int_t GL_PARAM::Query_GL_PARAM(UInt_t time, UInt_t type, TSQLServer *dbc){ |
1760 |
// Bool_t debug = 1; |
1761 |
// MySQL variables |
1762 |
TSQLResult *pResult; |
1763 |
TSQLRow *Row = NULL; |
1764 |
int t; |
1765 |
int r; |
1766 |
stringstream myquery; |
1767 |
// ---------------- |
1768 |
myquery.str(""); |
1769 |
myquery << " select "; |
1770 |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1771 |
myquery << " from GL_PARAM "; |
1772 |
myquery << " where TYPE = '"<<type<<"' "; |
1773 |
myquery << " and FROM_TIME <= " << time; |
1774 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1775 |
// |
1776 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1777 |
this->GetGLTABLES()->AddQ(); |
1778 |
pResult = dbc->Query(myquery.str().c_str()); |
1779 |
if(!pResult->GetRowCount()){ |
1780 |
delete pResult; |
1781 |
return (-52); |
1782 |
} |
1783 |
for( r=0; r < 1000; r++){ |
1784 |
if (Row) |
1785 |
delete Row; |
1786 |
Row = pResult->Next(); |
1787 |
if( Row == NULL ) break; |
1788 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1789 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1790 |
if (t==1) { |
1791 |
PATH = TString(Row->GetField(t)) + "/";// put in fpath the path to that file |
1792 |
gSystem->ExpandPathName(PATH); |
1793 |
} |
1794 |
if (t==2) NAME = Row->GetField(t); |
1795 |
if (t==3) DESCR = Row->GetField(t); |
1796 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1797 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1798 |
if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); |
1799 |
}; |
1800 |
} |
1801 |
if (Row) |
1802 |
delete Row; |
1803 |
delete pResult; |
1804 |
// |
1805 |
if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max(); |
1806 |
// |
1807 |
if(TO_TIME < time) return(51); |
1808 |
// |
1809 |
return 0; |
1810 |
}; |
1811 |
|
1812 |
|
1813 |
/** |
1814 |
* Fills a struct cGLRun with values from a GLRun object (to put data into a F77 common). |
1815 |
*/ |
1816 |
|
1817 |
void GL_RUN::GetLevel2Struct(cGLRun *l2) const{ |
1818 |
l2->id = ID; |
1819 |
l2->id_reg_run = ID_ROOT_L0; |
1820 |
l2->id_reg_run_l2 = ID_ROOT_L2; |
1821 |
l2->runheader_time = RUNHEADER_TIME; |
1822 |
l2->runtrailer_time = RUNTRAILER_TIME; |
1823 |
l2->ev_from = EV_FROM; |
1824 |
l2->trk_calib_used = TRK_CALIB_USED; |
1825 |
l2->eff_wrk_schedule = EFF_WRK_SCHEDULE; |
1826 |
l2->prh_var_trg_mode_a = PRH_VAR_TRG_MODE_A; |
1827 |
l2->prh_var_trg_mode_b = PRH_VAR_TRG_MODE_B; |
1828 |
l2->acq_build_info = ACQ_BUILD_INFO; |
1829 |
l2->acq_var_info = ACQ_VAR_INFO; |
1830 |
}; |
1831 |
|
1832 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
1833 |
// MySQL variables |
1834 |
TFile *file = 0; |
1835 |
UInt_t idtsy = 0; |
1836 |
// |
1837 |
TSQLResult *pResult; |
1838 |
TSQLRow *Row = NULL; |
1839 |
stringstream myquery; |
1840 |
stringstream rname; |
1841 |
// pcksList packetsNames; |
1842 |
// pcksList::iterator Iter; |
1843 |
// getPacketsNames(packetsNames); |
1844 |
rname.str(""); |
1845 |
// ---------------- |
1846 |
myquery.str(""); |
1847 |
myquery << "select "; |
1848 |
myquery << "PATH"; |
1849 |
myquery << ",NAME,ID_TIMESYNC"; |
1850 |
myquery << " from GL_ROOT where "; |
1851 |
myquery << type.Data(); |
1852 |
myquery << "=" << id << ";"; |
1853 |
// |
1854 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1855 |
this->GetGLTABLES()->AddQ(); |
1856 |
pResult = dbc->Query(myquery.str().c_str()); |
1857 |
if( pResult->GetRowCount() ){ |
1858 |
if (Row) |
1859 |
delete Row; |
1860 |
Row = pResult->Next(); |
1861 |
if( Row ){ |
1862 |
stringstream fname; |
1863 |
fname.str(""); |
1864 |
TString auxStr(Row->GetField(0)); |
1865 |
gSystem->ExpandPathName(auxStr); |
1866 |
fname << auxStr << "/" << Row->GetField(1); |
1867 |
rname << Row->GetField(1); |
1868 |
file = new TFile(fname.str().c_str(),"READ"); |
1869 |
idtsy = (UInt_t)atoll(Row->GetField(2)); |
1870 |
}; |
1871 |
}; |
1872 |
// |
1873 |
if ( file && file->IsOpen() ){ |
1874 |
TTree *T=(TTree*)file->Get("Physics"); |
1875 |
pamela::EventHeader *eh = 0; |
1876 |
pamela::PscuHeader *ph = 0; |
1877 |
T->SetBranchAddress("Header", &eh); |
1878 |
// |
1879 |
T->GetEntry(0); |
1880 |
ph = eh->GetPscuHeader(); |
1881 |
pktfirst = ph->GetCounter(); |
1882 |
// obtfirst = ph->GetOrbitalTime(); |
1883 |
// |
1884 |
}; |
1885 |
// |
1886 |
// look for Resurs offset |
1887 |
// |
1888 |
T0 = 0; |
1889 |
// |
1890 |
stringstream oss; |
1891 |
// |
1892 |
TString name=rname.str().c_str(); |
1893 |
// UInt_t dworbit = 0; |
1894 |
// Int_t nlength = name.Length(); |
1895 |
delete pResult; |
1896 |
if (Row){ |
1897 |
delete Row; |
1898 |
Row = NULL; |
1899 |
} |
1900 |
// |
1901 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1902 |
// |
1903 |
oss.str(""); |
1904 |
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
1905 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1906 |
this->GetGLTABLES()->AddQ(); |
1907 |
pResult = dbc->Query(oss.str().c_str()); |
1908 |
Bool_t fndit = false; |
1909 |
if ( pResult ){ |
1910 |
if (Row) |
1911 |
delete Row; |
1912 |
Row = pResult->Next(); |
1913 |
if ( Row ){ |
1914 |
// |
1915 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1916 |
obtfirst = OBT0; |
1917 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1918 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1919 |
// |
1920 |
oss.str(""); |
1921 |
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 ID=" |
1922 |
<< Row->GetField(3) << ";"; |
1923 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ){ |
1924 |
delete pResult; |
1925 |
delete Row; |
1926 |
return; |
1927 |
} |
1928 |
this->GetGLTABLES()->AddQ(); |
1929 |
delete pResult; |
1930 |
pResult = dbc->Query(oss.str().c_str()); |
1931 |
if (pResult){ |
1932 |
if (Row) |
1933 |
delete Row; |
1934 |
Row = pResult->Next(); |
1935 |
if ( Row ){ |
1936 |
// printf(" GREAT! the DB structure is the new one! \n"); |
1937 |
fndit = true; |
1938 |
// dworbit = 1; |
1939 |
}; |
1940 |
}; |
1941 |
}; |
1942 |
}; |
1943 |
if ( !fndit ){ |
1944 |
// |
1945 |
printf(" ERROR OLD DB! \n"); |
1946 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1947 |
// |
1948 |
}; |
1949 |
// |
1950 |
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); |
1951 |
T0 = (UInt_t)tu.GetSec(); |
1952 |
// |
1953 |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
1954 |
// |
1955 |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
1956 |
// |
1957 |
if ( file ) file->Close(); |
1958 |
if (Row) |
1959 |
delete Row; |
1960 |
delete pResult; |
1961 |
}; |
1962 |
|
1963 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ |
1964 |
// MySQL variables |
1965 |
TFile *file = 0; |
1966 |
UInt_t idtsy = 0; |
1967 |
// |
1968 |
TSQLResult *pResult; |
1969 |
TSQLRow *Row = NULL; |
1970 |
stringstream myquery; |
1971 |
stringstream rname; |
1972 |
// pcksList packetsNames; |
1973 |
// pcksList::iterator Iter; |
1974 |
// getPacketsNames(packetsNames); |
1975 |
rname.str(""); |
1976 |
// ---------------- |
1977 |
myquery.str(""); |
1978 |
myquery << "select "; |
1979 |
myquery << "PATH"; |
1980 |
myquery << ",NAME,ID_TIMESYNC"; |
1981 |
myquery << " from GL_ROOT where "; |
1982 |
myquery << type.Data(); |
1983 |
myquery << "=" << id << ";"; |
1984 |
// |
1985 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1986 |
this->GetGLTABLES()->AddQ(); |
1987 |
pResult = dbc->Query(myquery.str().c_str()); |
1988 |
if( pResult->GetRowCount() ){ |
1989 |
if (Row) |
1990 |
delete Row; |
1991 |
Row = pResult->Next(); |
1992 |
if( Row ){ |
1993 |
stringstream fname; |
1994 |
fname.str(""); |
1995 |
TString auxString(Row->GetField(0)); |
1996 |
gSystem->ExpandPathName(auxString); |
1997 |
fname << auxString << "/" << Row->GetField(1); |
1998 |
rname << Row->GetField(1); |
1999 |
if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); |
2000 |
idtsy = (UInt_t)atoll(Row->GetField(2)); |
2001 |
}; |
2002 |
}; |
2003 |
// |
2004 |
if ( usel0file && file && file->IsOpen() ){ |
2005 |
TTree *T=(TTree*)file->Get("Physics"); |
2006 |
pamela::EventHeader *eh = 0; |
2007 |
pamela::PscuHeader *ph = 0; |
2008 |
T->SetBranchAddress("Header", &eh); |
2009 |
// |
2010 |
T->GetEntry(0); |
2011 |
ph = eh->GetPscuHeader(); |
2012 |
pktfirst = ph->GetCounter(); |
2013 |
// obtfirst = ph->GetOrbitalTime(); |
2014 |
// |
2015 |
}; |
2016 |
if ( !usel0file ) pktfirst = 0; |
2017 |
// |
2018 |
// look for Resurs offset |
2019 |
// |
2020 |
T0 = 0; |
2021 |
// |
2022 |
stringstream oss; |
2023 |
// |
2024 |
TString name=rname.str().c_str(); |
2025 |
// UInt_t dworbit = 0; |
2026 |
// Int_t nlength = name.Length(); |
2027 |
delete pResult; |
2028 |
if (Row){ |
2029 |
delete Row; |
2030 |
Row = NULL; |
2031 |
} |
2032 |
// |
2033 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
2034 |
// |
2035 |
oss.str(""); |
2036 |
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
2037 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
2038 |
this->GetGLTABLES()->AddQ(); |
2039 |
pResult = dbc->Query(oss.str().c_str()); |
2040 |
Bool_t fndit = false; |
2041 |
if ( pResult ){ |
2042 |
if (Row) |
2043 |
delete Row; |
2044 |
Row = pResult->Next(); |
2045 |
if ( Row ){ |
2046 |
// |
2047 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
2048 |
obtfirst = OBT0; |
2049 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
2050 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
2051 |
// |
2052 |
oss.str(""); |
2053 |
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 ID=" |
2054 |
<< Row->GetField(3) << ";"; |
2055 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ){ |
2056 |
delete pResult; |
2057 |
delete Row; |
2058 |
return; |
2059 |
} |
2060 |
this->GetGLTABLES()->AddQ(); |
2061 |
delete pResult; |
2062 |
pResult = dbc->Query(oss.str().c_str()); |
2063 |
if (pResult){ |
2064 |
if (Row) |
2065 |
delete Row; |
2066 |
Row = pResult->Next(); |
2067 |
if (Row){ |
2068 |
// printf(" GREAT! the DB structure is the new one! \n"); |
2069 |
fndit = true; |
2070 |
// dworbit = 1; |
2071 |
}; |
2072 |
}; |
2073 |
}; |
2074 |
}; |
2075 |
if ( !fndit ){ |
2076 |
// |
2077 |
printf(" ERROR OLD DB! \n"); |
2078 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
2079 |
// |
2080 |
}; |
2081 |
// |
2082 |
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); |
2083 |
T0 = (UInt_t)tu.GetSec(); |
2084 |
// |
2085 |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
2086 |
// |
2087 |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
2088 |
// |
2089 |
if ( file ) file->Close(); |
2090 |
if (Row) |
2091 |
delete Row; |
2092 |
delete pResult; |
2093 |
}; |
2094 |
|
2095 |
/** |
2096 |
* |
2097 |
* Returns the DB absolute time needed to associate calibrations to data |
2098 |
* |
2099 |
*/ |
2100 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
2101 |
// |
2102 |
// printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
2103 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
2104 |
// |
2105 |
}; |
2106 |
|
2107 |
/** |
2108 |
* |
2109 |
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
2110 |
* |
2111 |
*/ |
2112 |
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
2113 |
// |
2114 |
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0)/1000))+TIMESYNC)); |
2115 |
// |
2116 |
}; |
2117 |
|
2118 |
|
2119 |
/** |
2120 |
* Return the correct packet number if we went back to zero |
2121 |
*/ |
2122 |
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
2123 |
// |
2124 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
2125 |
return((Long64_t)pkt_num+16777215LL); |
2126 |
}; |
2127 |
// |
2128 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
2129 |
return((Long64_t)pkt_num-16777215LL); |
2130 |
}; |
2131 |
// |
2132 |
return((Long64_t)pkt_num); |
2133 |
// |
2134 |
}; |
2135 |
|
2136 |
/** |
2137 |
* Return the correct On Board Time if we went back to zero |
2138 |
*/ |
2139 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
2140 |
// |
2141 |
if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
2142 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
2143 |
}; |
2144 |
// |
2145 |
if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
2146 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
2147 |
}; |
2148 |
// |
2149 |
return((Long64_t)obt); |
2150 |
}; |
2151 |
|
2152 |
|
2153 |
|
2154 |
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
2155 |
// // |
2156 |
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
2157 |
// // |
2158 |
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
2159 |
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
2160 |
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
2161 |
// } else { |
2162 |
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
2163 |
// }; |
2164 |
// }; |
2165 |
// // |
2166 |
// return((ULong64_t)obt); |
2167 |
// // |
2168 |
// }; |
2169 |
|
2170 |
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
2171 |
// // |
2172 |
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
2173 |
// // |
2174 |
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
2175 |
// if ( (pkt_num-16777215) < 0 ){ |
2176 |
// return((16777215-pkt_num)); |
2177 |
// } else { |
2178 |
// return((pkt_num-16777215)); |
2179 |
// }; |
2180 |
// }; |
2181 |
// // |
2182 |
// return(pkt_num); |
2183 |
// // |
2184 |
// }; |
2185 |
|
2186 |
/* |
2187 |
* |
2188 |
* Convert the time in the DB from UInt_t to a string |
2189 |
* |
2190 |
* @param dbt time in the DB |
2191 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
2192 |
* |
2193 |
*/ |
2194 |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
2195 |
// |
2196 |
Int_t offset = 0; |
2197 |
TString rtime; |
2198 |
Bool_t found = false; |
2199 |
// |
2200 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
2201 |
// |
2202 |
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
2203 |
found = true; |
2204 |
// |
2205 |
}; |
2206 |
// |
2207 |
if ( !strcmp(tzone.Data(),"CET") ){ |
2208 |
// |
2209 |
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
2210 |
found = true; |
2211 |
// |
2212 |
}; |
2213 |
// |
2214 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
2215 |
// |
2216 |
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
2217 |
found = true; |
2218 |
// |
2219 |
}; |
2220 |
// |
2221 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
2222 |
// |
2223 |
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
2224 |
found = true; |
2225 |
// |
2226 |
}; |
2227 |
// |
2228 |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
2229 |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
2230 |
tzone = "UTC"; |
2231 |
}; |
2232 |
// |
2233 |
dbt += offset; |
2234 |
// |
2235 |
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
2236 |
// |
2237 |
rtime = time->AsString("s"); |
2238 |
// |
2239 |
delete time; |
2240 |
// |
2241 |
return(rtime); |
2242 |
} |
2243 |
|
2244 |
/* |
2245 |
* |
2246 |
* Convert the time from TZONE to UTC |
2247 |
* |
2248 |
* @param dbt time in the DB |
2249 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
2250 |
* |
2251 |
*/ |
2252 |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
2253 |
// |
2254 |
Int_t offset = 0; |
2255 |
TString rtime; |
2256 |
// |
2257 |
Bool_t found = false; |
2258 |
// |
2259 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
2260 |
// |
2261 |
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
2262 |
found = true; |
2263 |
// |
2264 |
}; |
2265 |
// |
2266 |
if ( !strcmp(tzone.Data(),"CET") ){ |
2267 |
// |
2268 |
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
2269 |
found = true; |
2270 |
// |
2271 |
}; |
2272 |
// |
2273 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
2274 |
// |
2275 |
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
2276 |
found = true; |
2277 |
// |
2278 |
}; |
2279 |
// |
2280 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
2281 |
// |
2282 |
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
2283 |
found = true; |
2284 |
// |
2285 |
}; |
2286 |
// |
2287 |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
2288 |
// |
2289 |
offset = 0; |
2290 |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
2291 |
tzone = "UTC"; |
2292 |
}; |
2293 |
// |
2294 |
dbt += offset; |
2295 |
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
2296 |
// |
2297 |
rtime = time->AsString("s"); |
2298 |
// |
2299 |
return(rtime); |
2300 |
} |
2301 |
|
2302 |
|
2303 |
// |
2304 |
// Build a query and call DoQuery. |
2305 |
// |
2306 |
// date it's an SQL datetime date and dbc is the connection to be |
2307 |
// used. It will query for the tle with the nearest but previous date |
2308 |
// and the immediatly next one. |
2309 |
// |
2310 |
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
2311 |
stringstream myquery; |
2312 |
myquery.str(""); |
2313 |
|
2314 |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
2315 |
<< "WHERE FROM_TIME <= '" << date.Data() |
2316 |
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
2317 |
<< "UNION " |
2318 |
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
2319 |
<< "WHERE FROM_TIME > '" << date.Data() |
2320 |
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
2321 |
|
2322 |
return DoQuery(myquery.str().c_str(), dbc); |
2323 |
} |
2324 |
|
2325 |
|
2326 |
// |
2327 |
// Build a query and call DoQuery. |
2328 |
// |
2329 |
// time is the UTC date in unix time (UTC) and dbc is the connection |
2330 |
// to be used. It will query for the tle with the nearest but |
2331 |
// previous date and the immediatly next one. |
2332 |
// |
2333 |
// Returns the value returned by DoQuery(). |
2334 |
// |
2335 |
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
2336 |
stringstream myquery; |
2337 |
myquery.str(""); |
2338 |
|
2339 |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
2340 |
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
2341 |
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
2342 |
<< "UNION " |
2343 |
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
2344 |
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
2345 |
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
2346 |
|
2347 |
return DoQuery(myquery.str().c_str(), dbc); |
2348 |
} |
2349 |
|
2350 |
|
2351 |
// |
2352 |
// Do the query myquery on the connectio dbc. Initialize tle, |
2353 |
// tleFromTime and tleToTime. |
2354 |
// |
2355 |
// We should have two rows (unless the table is old). From the last |
2356 |
// one we only take tleToTime. |
2357 |
// |
2358 |
// Returns 0 for success, 1 for failure. |
2359 |
// |
2360 |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
2361 |
TSQLResult *result; |
2362 |
TSQLRow *row = NULL; |
2363 |
|
2364 |
// Set the right time_zone (otherwise horrible things will occur! :) |
2365 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
2366 |
delete dbc->Query("SET time_zone = '+0:00'"); |
2367 |
|
2368 |
// Do the query |
2369 |
this->GetGLTABLES()->AddQ(); |
2370 |
result = dbc->Query(myquery.Data()); |
2371 |
if(! result->GetRowCount() ) { |
2372 |
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
2373 |
delete result; |
2374 |
return 1; |
2375 |
} |
2376 |
|
2377 |
// Get results |
2378 |
row = result->Next(); // first tle row |
2379 |
tle = GiveTle(row); |
2380 |
|
2381 |
tleFromTime = strtol(row->GetField(4), NULL, 10); |
2382 |
if (row) |
2383 |
delete row; |
2384 |
row = result->Next(); // second tle row |
2385 |
if(row) |
2386 |
tleToTime = strtol(row->GetField(4), NULL, 10); |
2387 |
else { |
2388 |
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
2389 |
tleToTime = UINT_MAX; |
2390 |
} |
2391 |
|
2392 |
if (row) |
2393 |
delete row; |
2394 |
delete result; |
2395 |
|
2396 |
return 0; |
2397 |
} |
2398 |
|
2399 |
|
2400 |
// |
2401 |
// Build a cTle object from the GL_TLE row. |
2402 |
// |
2403 |
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
2404 |
cTle *thistle = NULL; |
2405 |
string tle1, tle2, tle3; |
2406 |
|
2407 |
// Build cTle object |
2408 |
tle1 = row->GetField(1); |
2409 |
tle2 = row->GetField(2); |
2410 |
tle3 = row->GetField(3); |
2411 |
|
2412 |
thistle = new cTle(tle1, tle2, tle3); |
2413 |
|
2414 |
return thistle; |
2415 |
} |