8 |
#include <list> |
#include <list> |
9 |
#include <errno.h> |
#include <errno.h> |
10 |
// |
// |
11 |
|
#include <TFile.h> |
12 |
|
#include <TSystem.h> |
13 |
#include <TSQLResult.h> |
#include <TSQLResult.h> |
|
#include <TRFIOFile.h> |
|
14 |
#include <TSQLRow.h> |
#include <TSQLRow.h> |
15 |
#include <TTree.h> |
#include <TTree.h> |
16 |
#include <TGraph.h> |
#include <TGraph.h> |
63 |
SetObt0(obt0); |
SetObt0(obt0); |
64 |
// |
// |
65 |
// |
// |
66 |
SetRootName(filerootname); |
INSERT_RAW =!filerawname.IsNull(); |
67 |
SetRawName(filerawname); |
if(INSERT_RAW)SetRawName(filerawname); |
68 |
// |
// |
69 |
this->OpenFile(); |
INSERT_ROOT = !filerootname.IsNull(); |
70 |
|
if( INSERT_ROOT ){ |
71 |
|
file = TFile::Open(this->GetRootName().Data()); |
72 |
|
// if ( !file ) INSERT_ROOT = false; |
73 |
|
}; |
74 |
|
// this->OpenFile(); |
75 |
// |
// |
76 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
77 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
78 |
|
|
79 |
|
VALIDATE = false; |
80 |
|
|
81 |
// |
// |
82 |
}; |
}; |
83 |
|
|
86 |
*/ |
*/ |
87 |
void PamelaDBOperations::Close(){ |
void PamelaDBOperations::Close(){ |
88 |
if( conn && conn->IsConnected() ) conn->Close(); |
if( conn && conn->IsConnected() ) conn->Close(); |
89 |
|
delete clean_time; |
90 |
delete glrun; |
delete glrun; |
91 |
delete this; |
delete this; |
92 |
}; |
}; |
95 |
// SETTERS |
// SETTERS |
96 |
// |
// |
97 |
|
|
98 |
|
// |
99 |
|
// must be out of the constructor in order to FORCE the validation of the latest runs in case you run the validation together with the latest file |
100 |
|
// |
101 |
|
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
102 |
|
clean_time = new TDatime(); |
103 |
|
if(olderthan >= 0){ |
104 |
|
VALIDATE = true; |
105 |
|
UInt_t timelim = 0; |
106 |
|
timelim = (UInt_t)clean_time->Convert() - olderthan; |
107 |
|
clean_time->Set(timelim,false); |
108 |
|
}; |
109 |
|
}; |
110 |
|
|
111 |
/** |
/** |
112 |
* Open the DB connection |
* Open the DB connection |
113 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
194 |
* Store the olderthan variable |
* Store the olderthan variable |
195 |
* @param olderthan |
* @param olderthan |
196 |
*/ |
*/ |
197 |
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
198 |
olderthan = oldthan; |
// olderthan = oldthan; |
199 |
}; |
// }; |
200 |
|
|
201 |
/** |
/** |
202 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
245 |
ULong64_t upperobt2 = 0; |
ULong64_t upperobt2 = 0; |
246 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
247 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
248 |
|
EventCounter *code=0; |
249 |
|
// |
250 |
|
// pcksList packetsNames; |
251 |
|
// pcksList::iterator Iter; |
252 |
|
// getPacketsNames(packetsNames); |
253 |
// |
// |
254 |
pktfirst = 0; |
pktfirst = 0; |
255 |
obtfirst = 0; |
obtfirst = 0; |
267 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
268 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
269 |
// |
// |
270 |
|
// code = eh->GetCounter(); |
271 |
|
// UInt_t en = 0; |
272 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
273 |
|
// en = code->Get(GetPacketType(*Iter)); |
274 |
|
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
275 |
|
//}; |
276 |
|
// |
277 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
278 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
279 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
342 |
// check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer) |
// check if last runtrailer is within limits, if not extend limits (one should check for all packets but we need only runtrailer) |
343 |
// |
// |
344 |
PacketType *pctp=0; |
PacketType *pctp=0; |
|
EventCounter *code=0; |
|
|
T->GetEntry(upperentry); |
|
|
code = eh->GetCounter(); |
|
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
|
|
Int_t lasthead = code->Get(pctp->RunHeader); |
|
345 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
346 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
347 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
355 |
// |
// |
356 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
357 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
358 |
|
UInt_t sobtt = 0; |
359 |
|
UInt_t sobth = 0; |
360 |
|
UInt_t spktt = 0; |
361 |
|
UInt_t spkth = 0; |
362 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
363 |
ULong64_t obtt = 0; |
ULong64_t obtt = 0; |
364 |
UInt_t pkth = 0; |
UInt_t pkth = 0; |
365 |
ULong64_t obth = 0; |
ULong64_t obth = 0; |
366 |
// |
// |
367 |
|
T->GetEntry(upperentry); |
368 |
|
code = eh->GetCounter(); |
369 |
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
370 |
|
Int_t lasthead = code->Get(pctp->RunHeader); |
371 |
if ( lasttrail < rtev ){ |
if ( lasttrail < rtev ){ |
372 |
rt->GetEntry(lasttrail); |
rt->GetEntry(lasttrail); |
373 |
pht = eht->GetPscuHeader(); |
pht = eht->GetPscuHeader(); |
375 |
obtt = OBT(pht->GetOrbitalTime()); |
obtt = OBT(pht->GetOrbitalTime()); |
376 |
}; |
}; |
377 |
// |
// |
378 |
|
if ( lasthead < rhev ){ |
379 |
|
rh->GetEntry(lasthead); |
380 |
|
phh = ehh->GetPscuHeader(); |
381 |
|
pkth = PKT(phh->GetCounter()); |
382 |
|
obth = OBT(phh->GetOrbitalTime()); |
383 |
|
}; |
384 |
|
// |
385 |
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
386 |
|
if ( pkth > upperpkt && obth > upperobt ){ |
387 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); |
388 |
|
upperpkt = pkth; |
389 |
|
upperobt = obth; |
390 |
|
rhev = lasthead+1; |
391 |
|
} else { |
392 |
|
rhev = lasthead; |
393 |
|
}; |
394 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
395 |
|
// |
396 |
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
397 |
if ( pktt > upperpkt && obtt > upperobt ){ |
if ( pktt > upperpkt && obtt > upperobt ){ |
398 |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
403 |
rtev = lasttrail; |
rtev = lasttrail; |
404 |
}; |
}; |
405 |
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
406 |
|
// goto kikko; |
407 |
|
// |
408 |
|
// |
409 |
|
// Check if runtrailer/runheader are within lower limits |
410 |
|
// |
411 |
|
// |
412 |
|
pkth = 0; |
413 |
|
obth = 0; |
414 |
|
spkth = 0; |
415 |
|
sobth = 0; |
416 |
|
for (Int_t k=0; k<rhev; k++){ |
417 |
|
if ( k > 0 ){ |
418 |
|
spkth = pkth; |
419 |
|
sobth = obth; |
420 |
|
}; |
421 |
|
rh->GetEntry(k); |
422 |
|
phh = ehh->GetPscuHeader(); |
423 |
|
pkth = PKT(phh->GetCounter()); |
424 |
|
obth = OBT(phh->GetOrbitalTime()); |
425 |
|
// |
426 |
|
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
427 |
|
// |
428 |
|
if ( pkth < spkth && obth < sobth ){ |
429 |
|
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
430 |
|
// |
431 |
|
rhev = k-1; |
432 |
|
rh->GetEntry(rhev); |
433 |
|
pkth = spkth; |
434 |
|
obth = sobth; |
435 |
|
// |
436 |
|
UInt_t evbefh = 0; |
437 |
|
code = ehh->GetCounter(); |
438 |
|
evbefh = code->Get(pctp->Physics); |
439 |
|
if ( evbefh >= 0 ){ |
440 |
|
T->GetEntry(evbefh); |
441 |
|
ph = eh->GetPscuHeader(); |
442 |
|
t_pktlast = PKT(ph->GetCounter()); |
443 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
444 |
|
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
445 |
|
upperpkt = pkth; |
446 |
|
upperobt = obth; |
447 |
|
upperentry = evbefh-1; |
448 |
|
} else { |
449 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
450 |
|
evbefh++; |
451 |
|
T->GetEntry(evbefh); |
452 |
|
ph = eh->GetPscuHeader(); |
453 |
|
t_pktlast = PKT(ph->GetCounter()); |
454 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
455 |
|
}; |
456 |
|
T->GetEntry(evbefh-1); |
457 |
|
ph = eh->GetPscuHeader(); |
458 |
|
upperpkt = PKT(ph->GetCounter()); |
459 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
460 |
|
upperentry = evbefh-1; |
461 |
|
}; |
462 |
|
}; |
463 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
464 |
|
goto kikko0; |
465 |
|
}; |
466 |
|
}; |
467 |
|
kikko0: |
468 |
|
// |
469 |
|
// |
470 |
|
// |
471 |
|
pktt = 0; |
472 |
|
obtt = 0; |
473 |
|
spktt = 0; |
474 |
|
sobtt = 0; |
475 |
|
for (Int_t k=0; k<rtev; k++){ |
476 |
|
if ( k > 0 ){ |
477 |
|
spktt = pktt; |
478 |
|
sobtt = obtt; |
479 |
|
}; |
480 |
|
rt->GetEntry(k); |
481 |
|
pht = eht->GetPscuHeader(); |
482 |
|
pktt = PKT(pht->GetCounter()); |
483 |
|
obtt = OBT(pht->GetOrbitalTime()); |
484 |
|
// |
485 |
|
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
486 |
|
// |
487 |
|
if ( pktt < spktt && obtt < sobtt ){ |
488 |
|
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
489 |
|
// |
490 |
|
rtev = k-1; |
491 |
|
rt->GetEntry(rtev); |
492 |
|
pktt = spktt; |
493 |
|
obtt = sobtt; |
494 |
|
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
495 |
|
// |
496 |
|
UInt_t evbeft = 0; |
497 |
|
code = eht->GetCounter(); |
498 |
|
evbeft = code->Get(pctp->Physics); |
499 |
|
if ( evbeft >= 0 ){ |
500 |
|
T->GetEntry(evbeft); |
501 |
|
ph = eh->GetPscuHeader(); |
502 |
|
t_pktlast = PKT(ph->GetCounter()); |
503 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
504 |
|
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
505 |
|
upperpkt = pktt; |
506 |
|
upperobt = obtt; |
507 |
|
upperentry = evbeft-1; |
508 |
|
} else { |
509 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
510 |
|
evbeft++; |
511 |
|
T->GetEntry(evbeft); |
512 |
|
ph = eh->GetPscuHeader(); |
513 |
|
t_pktlast = PKT(ph->GetCounter()); |
514 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
515 |
|
}; |
516 |
|
T->GetEntry(evbeft-1); |
517 |
|
ph = eh->GetPscuHeader(); |
518 |
|
upperpkt = PKT(ph->GetCounter()); |
519 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
520 |
|
upperentry = evbeft-1; |
521 |
|
}; |
522 |
|
}; |
523 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
524 |
|
goto kikko; |
525 |
|
// break; |
526 |
|
// |
527 |
|
}; |
528 |
|
// |
529 |
|
}; |
530 |
|
// |
531 |
|
kikko: |
532 |
|
// |
533 |
|
T->GetEntry(upperentry); |
534 |
|
code = eh->GetCounter(); |
535 |
|
lasttrail = code->Get(pctp->RunTrailer); |
536 |
|
lasthead = code->Get(pctp->RunHeader); |
537 |
|
if ( lasttrail < rtev ){ |
538 |
|
rt->GetEntry(lasttrail); |
539 |
|
pht = eht->GetPscuHeader(); |
540 |
|
pktt = PKT(pht->GetCounter()); |
541 |
|
obtt = OBT(pht->GetOrbitalTime()); |
542 |
|
}; |
543 |
// |
// |
544 |
if ( lasthead < rhev ){ |
if ( lasthead < rhev ){ |
545 |
rh->GetEntry(lasthead); |
rh->GetEntry(lasthead); |
546 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
547 |
pkth = PKT(pht->GetCounter()); |
pkth = PKT(phh->GetCounter()); |
548 |
obth = OBT(pht->GetOrbitalTime()); |
obth = OBT(phh->GetOrbitalTime()); |
549 |
}; |
}; |
550 |
// |
// |
551 |
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
559 |
}; |
}; |
560 |
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
561 |
// |
// |
562 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
563 |
|
if ( pktt > upperpkt && obtt > upperobt ){ |
564 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
565 |
|
upperpkt = pktt; |
566 |
|
upperobt = obtt; |
567 |
|
rtev = lasttrail+1; |
568 |
|
} else { |
569 |
|
rtev = lasttrail; |
570 |
|
}; |
571 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
572 |
|
// |
573 |
if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Upper limits are: OBT %llu pkt_num %i upper entry %i \n",upperobt,upperpkt,upperentry); |
574 |
// |
// |
575 |
return(0); |
return(0); |
650 |
// PRIVATE FUNCTIONS |
// PRIVATE FUNCTIONS |
651 |
// |
// |
652 |
|
|
653 |
/** |
// /** |
654 |
* Open the ROOT filename for reading |
// * Open the ROOT filename for reading |
655 |
*/ |
// */ |
656 |
void PamelaDBOperations::OpenFile(){ |
// void PamelaDBOperations::OpenFile(){ |
657 |
file = TFile::Open(this->GetRootName().Data()); |
// file = TFile::Open(this->GetRootName().Data()); |
658 |
|
// // |
659 |
|
|
660 |
|
void PamelaDBOperations::CheckFile(){ |
661 |
|
if ( !file ) throw -12; |
662 |
}; |
}; |
663 |
|
|
664 |
|
|
665 |
/** |
/** |
666 |
* Check if LEVEL0 file and DB connection have really be opened |
* Check if LEVEL0 file and DB connection have really be opened |
667 |
*/ |
*/ |
668 |
void PamelaDBOperations::CheckFile(){ |
void PamelaDBOperations::CheckConnection(){ |
|
// |
|
|
if ( !file ) throw -12; |
|
669 |
// |
// |
670 |
// check connection |
// check connection |
671 |
// |
// |
672 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
673 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
674 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
675 |
}; |
}; |
676 |
|
|
677 |
/** |
/** |
3192 |
TSQLRow *row2 = 0; |
TSQLRow *row2 = 0; |
3193 |
// |
// |
3194 |
UInt_t moved = 0; |
UInt_t moved = 0; |
3195 |
UInt_t timelim = 0; |
// UInt_t timelim = 0; |
3196 |
TDatime *time = new TDatime(); |
// TDatime *time = new TDatime(); |
3197 |
// |
// |
3198 |
stringstream oss; |
stringstream oss; |
3199 |
oss.str(""); |
oss.str(""); |
3200 |
// |
// |
3201 |
// |
// |
|
// |
|
|
if ( olderthan < 0 ){ |
|
|
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
|
|
return(1); |
|
|
}; |
|
|
// |
|
|
// timelim = now - olderthan |
|
|
// |
|
|
time->Set(); |
|
|
timelim = (UInt_t)time->Convert() - olderthan; |
|
|
time->Set(timelim,false); |
|
|
// |
|
3202 |
// check if there are entries older than "olderthan" seconds from now |
// check if there are entries older than "olderthan" seconds from now |
3203 |
// |
// |
3204 |
oss.str(""); |
oss.str(""); |
3205 |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3206 |
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
3207 |
// |
// |
3208 |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
3209 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
3210 |
// |
// |
3211 |
if ( result ){ |
if ( result ){ |
3301 |
Int_t PamelaDBOperations::ValidateRuns(){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3302 |
// |
// |
3303 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
3304 |
// TSQLRow *row = 0; |
TSQLRow *row = 0; |
|
// |
|
|
UInt_t timelim = 0; |
|
|
TDatime *time = new TDatime(); |
|
3305 |
// |
// |
3306 |
stringstream oss; |
stringstream oss; |
3307 |
oss.str(""); |
oss.str(""); |
3308 |
// |
// |
3309 |
// |
// ======================================================= |
3310 |
// |
// validate runs by checking missing calibrations |
3311 |
if ( olderthan < 0 ){ |
// ======================================================= |
3312 |
if ( IsDebug() ) printf(" Do not validate runs \n"); |
UInt_t t_stop = 0; |
3313 |
return(1); |
UInt_t t_start = 0; |
3314 |
|
// -------------------------------------------------------------- |
3315 |
|
// 1) get the OBT of the last run inserted after clean-time limit |
3316 |
|
// -------------------------------------------------------------- |
3317 |
|
oss.str(""); |
3318 |
|
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
3319 |
|
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3320 |
|
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3321 |
|
result = conn->Query(oss.str().c_str()); |
3322 |
|
if ( !result ) throw -4; |
3323 |
|
if ( !result->GetRowCount() ) { |
3324 |
|
printf(" No runs to validate \n"); |
3325 |
|
return(1); |
3326 |
|
}else{ |
3327 |
|
row = result->Next(); |
3328 |
|
t_start = (UInt_t)atoll(row->GetField(4)); |
3329 |
|
}; |
3330 |
|
// -------------------------------------------------------------- |
3331 |
|
// 2) get the OBT of the last validated run |
3332 |
|
// -------------------------------------------------------------- |
3333 |
|
oss.str(""); |
3334 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3335 |
|
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3336 |
|
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
3337 |
|
result = conn->Query(oss.str().c_str()); |
3338 |
|
if ( !result ) throw -4; |
3339 |
|
if ( result->GetRowCount() ){ |
3340 |
|
row = result->Next(); |
3341 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3342 |
}; |
}; |
3343 |
// |
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
3344 |
// timelim = now - olderthan |
// -------------------------------------------------------------- |
3345 |
// |
// now retrieves runs to be validated |
3346 |
time->Set(); |
// -------------------------------------------------------------- |
3347 |
timelim = (UInt_t)time->Convert() - olderthan; |
oss.str(""); |
3348 |
time->Set(timelim,false); |
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3349 |
// |
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3350 |
// First of all validate runs with default calibration: |
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3351 |
// |
// if ( IsDebug() ) |
3352 |
oss.str(""); |
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
|
oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE" |
|
|
<< " VALIDATION = 0 AND TRK_CALIB_USED=104 AND " |
|
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
|
3353 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
|
// |
|
3354 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
3355 |
|
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
3356 |
|
// printf("------------------------------------------------------------------------------- \n"); |
3357 |
|
|
3358 |
|
Int_t nrow = 0; |
3359 |
|
GL_RUN* this_run = new GL_RUN(); |
3360 |
|
GL_RUN* next_run = new GL_RUN(); |
3361 |
|
Int_t nseq_max = 1000; |
3362 |
|
// UInt_t* sequence = new UInt_t[100]; |
3363 |
|
vector<UInt_t> sequence(nseq_max); |
3364 |
|
Int_t nseq = 0; |
3365 |
|
Bool_t CHECK = false; |
3366 |
|
Bool_t this_ONLINE = false; |
3367 |
|
Bool_t next_ONLINE = false; |
3368 |
|
UInt_t t1=0,t2=0; |
3369 |
|
// --------------------------------------------------------------------------------- |
3370 |
|
// - loop over runs, back in time, |
3371 |
|
// - select sequences of runs close in time (less than 60 s apart), |
3372 |
|
// which could be preceeded by a calibration |
3373 |
|
// - check if there might be a missing calibration |
3374 |
|
// --------------------------------------------------------------------------------- |
3375 |
|
while(1){ |
3376 |
|
|
3377 |
|
row = result->Next(); |
3378 |
|
if( row == NULL ) break; |
3379 |
|
|
3380 |
|
//------------ |
3381 |
|
//get run info |
3382 |
|
//------------ |
3383 |
|
this_run->Set_GL_RUN(row); |
3384 |
|
|
3385 |
|
Bool_t this_BAD = false; |
3386 |
|
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
3387 |
|
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
3388 |
|
else{ |
3389 |
|
// printf("Missing or corrupted header!! \n"); |
3390 |
|
this_ONLINE = false; |
3391 |
|
this_BAD = true; |
3392 |
|
}; |
3393 |
|
|
3394 |
|
//----------------------------------- |
3395 |
|
//compare with previous(next in time) |
3396 |
|
//----------------------------------- |
3397 |
|
CHECK = false; |
3398 |
|
UInt_t interval=0; |
3399 |
|
|
3400 |
|
if( nrow != 0){ |
3401 |
|
|
3402 |
|
|
3403 |
|
t1 = this_run->GetRUNTRAILER_TIME(); |
3404 |
|
t2 = next_run->GetRUNHEADER_TIME(); |
3405 |
|
interval = (t2-t1); |
3406 |
|
|
3407 |
|
if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE |
3408 |
|
|
3409 |
|
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3410 |
|
|
3411 |
|
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
3412 |
|
|
3413 |
|
if( !CHECK && this_run->VALIDATION ){ |
3414 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3415 |
|
nseq=0; |
3416 |
|
} |
3417 |
|
|
3418 |
|
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
3419 |
|
|
3420 |
|
CHECK = true; |
3421 |
|
|
3422 |
|
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
3423 |
|
|
3424 |
|
assignVALIDATION(next_run->ID,true); |
3425 |
|
nseq=0; |
3426 |
|
} |
3427 |
|
} |
3428 |
|
|
3429 |
|
//---------------------------- |
3430 |
|
//check run sequence for calib |
3431 |
|
//---------------------------- |
3432 |
|
if( CHECK ){ |
3433 |
|
// check if calibration exists |
3434 |
|
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
3435 |
|
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
3436 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
3437 |
|
nseq=0; |
3438 |
|
}; |
3439 |
|
//-------------- |
3440 |
|
//store run info |
3441 |
|
//-------------- |
3442 |
|
*next_run = *this_run; |
3443 |
|
next_ONLINE = this_ONLINE; |
3444 |
|
if( !this_BAD ){ |
3445 |
|
if(nseq < nseq_max){ |
3446 |
|
sequence[nseq] = this_run->ID; |
3447 |
|
nseq++; |
3448 |
|
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
3449 |
|
}; |
3450 |
|
|
3451 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
3452 |
|
nrow++; |
3453 |
|
|
3454 |
|
}; |
3455 |
|
delete this_run; |
3456 |
|
delete next_run; |
3457 |
// |
// |
3458 |
return(0); |
return(0); |
3459 |
}; |
}; |
3460 |
|
/** |
3461 |
|
* Check if there might be a missing tracker calibration in a given time interval |
3462 |
|
* @param t1 From absolute time |
3463 |
|
* @param t2 To absolute time |
3464 |
|
* @return true if there might be a missing calibration |
3465 |
|
*/ |
3466 |
|
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
3467 |
|
|
3468 |
|
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
3469 |
|
|
3470 |
|
// get the closest VALIDATED calibration before the run start (t2) |
3471 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
3472 |
|
|
3473 |
|
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
3474 |
|
|
3475 |
|
//============================================================== |
3476 |
|
// Check is done first on the basis of time between calibration, |
3477 |
|
// which should be equal to the time between ascending-nodes. |
3478 |
|
//============================================================== |
3479 |
|
if ( t2 - trkcalib->FROM_TIME > 5700) { |
3480 |
|
if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
3481 |
|
//============================================================== |
3482 |
|
// there might be a missing calibration, due to: |
3483 |
|
// - MM full |
3484 |
|
// - corrupted packets |
3485 |
|
// - loss of data |
3486 |
|
// There is an exception in case a download was done during ascending node |
3487 |
|
//============================================================== |
3488 |
|
Bool_t DOWNLOAD = false; |
3489 |
|
// check if the calib was skipped becouse of download .... DA FARE!! |
3490 |
|
if(DOWNLOAD)return(false); |
3491 |
|
|
3492 |
|
return(true); //>>> missing |
3493 |
|
|
3494 |
|
}; |
3495 |
|
|
3496 |
|
//============================================================== |
3497 |
|
// If the last calibration is close to the run less than this time, |
3498 |
|
// it is enough to say that there are no missing calibrations |
3499 |
|
//============================================================== |
3500 |
|
// the long time interval bewteen runs might be due to download |
3501 |
|
if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
3502 |
|
return(false); |
3503 |
|
|
3504 |
|
}; |
3505 |
|
/** |
3506 |
|
* Assign VALIDATION value to a GL_RUN entry |
3507 |
|
* @param idrun Run ID |
3508 |
|
* @param validation true/false |
3509 |
|
*/ |
3510 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
3511 |
|
TSQLResult *result = 0; |
3512 |
|
stringstream oss; |
3513 |
|
oss.str(""); |
3514 |
|
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
3515 |
|
// |
3516 |
|
// if ( IsDebug() ) |
3517 |
|
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
3518 |
|
if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); |
3519 |
|
result = conn->Query(oss.str().c_str()); |
3520 |
|
if ( !result ) throw -4; |
3521 |
|
return(0); |
3522 |
|
} |
3523 |
|
|
3524 |
|
|
3525 |
|
|