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