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> |
30 |
#include <varDump/VarDumpEvent.h> |
#include <varDump/VarDumpEvent.h> |
31 |
#include <varDump/VarDumpRecord.h> |
#include <varDump/VarDumpRecord.h> |
32 |
#include <physics/S4/S4Event.h> |
#include <physics/S4/S4Event.h> |
|
|
|
33 |
// |
// |
34 |
#include <PamelaDBOperations.h> |
#include <PamelaDBOperations.h> |
35 |
// |
// |
36 |
using namespace std; |
using namespace std; |
37 |
using namespace pamela; |
using namespace pamela; |
|
//using namespace yngn::util; |
|
38 |
|
|
39 |
/** |
/** |
40 |
* Constructor. |
* Constructor. |
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 |
|
this->SetRootName(filerootname); |
72 |
|
file = TFile::Open(this->GetRootName().Data()); |
73 |
|
}; |
74 |
// |
// |
75 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
76 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
77 |
|
|
78 |
|
VALIDATE = false; |
79 |
|
|
80 |
// |
// |
81 |
}; |
}; |
82 |
|
|
85 |
*/ |
*/ |
86 |
void PamelaDBOperations::Close(){ |
void PamelaDBOperations::Close(){ |
87 |
if( conn && conn->IsConnected() ) conn->Close(); |
if( conn && conn->IsConnected() ) conn->Close(); |
88 |
|
delete clean_time; |
89 |
delete glrun; |
delete glrun; |
90 |
delete this; |
delete this; |
91 |
}; |
}; |
94 |
// SETTERS |
// SETTERS |
95 |
// |
// |
96 |
|
|
97 |
|
// |
98 |
|
// 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 |
99 |
|
// |
100 |
|
void PamelaDBOperations::CheckValidate(Long64_t olderthan){ |
101 |
|
clean_time = new TDatime(); |
102 |
|
if(olderthan >= 0){ |
103 |
|
VALIDATE = true; |
104 |
|
UInt_t timelim = 0; |
105 |
|
timelim = (UInt_t)clean_time->Convert() - olderthan; |
106 |
|
clean_time->Set(timelim,false); |
107 |
|
}; |
108 |
|
}; |
109 |
|
|
110 |
/** |
/** |
111 |
* Open the DB connection |
* Open the DB connection |
112 |
* @param host hostname for the SQL connection. |
* @param host hostname for the SQL connection. |
190 |
}; |
}; |
191 |
|
|
192 |
/** |
/** |
193 |
|
* Store the olderthan variable |
194 |
|
* @param olderthan |
195 |
|
*/ |
196 |
|
// void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
197 |
|
// olderthan = oldthan; |
198 |
|
// }; |
199 |
|
|
200 |
|
/** |
201 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
202 |
*/ |
*/ |
203 |
Bool_t PamelaDBOperations::SetID_RAW(){ |
Bool_t PamelaDBOperations::SetID_RAW(){ |
209 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
210 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
211 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
212 |
if (result == NULL) throw -4; |
if ( result == NULL ) throw -4; |
213 |
row = result->Next(); |
row = result->Next(); |
214 |
if (row == NULL) return false; |
if ( !row ) return(false); |
215 |
delete result; |
delete result; |
216 |
id = (UInt_t)atoll(row->GetField(0)); |
id = (UInt_t)atoll(row->GetField(0)); |
217 |
return(true); |
return(true); |
244 |
ULong64_t upperobt2 = 0; |
ULong64_t upperobt2 = 0; |
245 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
246 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
247 |
|
EventCounter *code=0; |
248 |
|
// |
249 |
|
// pcksList packetsNames; |
250 |
|
// pcksList::iterator Iter; |
251 |
|
// getPacketsNames(packetsNames); |
252 |
// |
// |
253 |
pktfirst = 0; |
pktfirst = 0; |
254 |
obtfirst = 0; |
obtfirst = 0; |
266 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
267 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
268 |
// |
// |
269 |
|
// code = eh->GetCounter(); |
270 |
|
// UInt_t en = 0; |
271 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
272 |
|
// en = code->Get(GetPacketType(*Iter)); |
273 |
|
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
274 |
|
//}; |
275 |
|
// |
276 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
277 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
278 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
341 |
// 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) |
342 |
// |
// |
343 |
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); |
|
344 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
345 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
346 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
354 |
// |
// |
355 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
356 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
357 |
|
UInt_t sobtt = 0; |
358 |
|
UInt_t sobth = 0; |
359 |
|
UInt_t spktt = 0; |
360 |
|
UInt_t spkth = 0; |
361 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
362 |
ULong64_t obtt = 0; |
ULong64_t obtt = 0; |
363 |
UInt_t pkth = 0; |
UInt_t pkth = 0; |
364 |
ULong64_t obth = 0; |
ULong64_t obth = 0; |
365 |
// |
// |
366 |
|
T->GetEntry(upperentry); |
367 |
|
code = eh->GetCounter(); |
368 |
|
Int_t lasttrail = code->Get(pctp->RunTrailer); |
369 |
|
Int_t lasthead = code->Get(pctp->RunHeader); |
370 |
if ( lasttrail < rtev ){ |
if ( lasttrail < rtev ){ |
371 |
rt->GetEntry(lasttrail); |
rt->GetEntry(lasttrail); |
372 |
pht = eht->GetPscuHeader(); |
pht = eht->GetPscuHeader(); |
374 |
obtt = OBT(pht->GetOrbitalTime()); |
obtt = OBT(pht->GetOrbitalTime()); |
375 |
}; |
}; |
376 |
// |
// |
377 |
|
if ( lasthead < rhev ){ |
378 |
|
rh->GetEntry(lasthead); |
379 |
|
phh = ehh->GetPscuHeader(); |
380 |
|
pkth = PKT(phh->GetCounter()); |
381 |
|
obth = OBT(phh->GetOrbitalTime()); |
382 |
|
}; |
383 |
|
// |
384 |
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
385 |
|
if ( pkth > upperpkt && obth > upperobt ){ |
386 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last header: ph %i upperp %i oh %llu uppero %llu \n",pkth,upperpkt,obth,upperobt); |
387 |
|
upperpkt = pkth; |
388 |
|
upperobt = obth; |
389 |
|
rhev = lasthead+1; |
390 |
|
} else { |
391 |
|
rhev = lasthead; |
392 |
|
}; |
393 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
394 |
|
// |
395 |
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); |
396 |
if ( pktt > upperpkt && obtt > upperobt ){ |
if ( pktt > upperpkt && obtt > upperobt ){ |
397 |
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); |
402 |
rtev = lasttrail; |
rtev = lasttrail; |
403 |
}; |
}; |
404 |
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); |
405 |
|
// goto kikko; |
406 |
|
// |
407 |
|
// |
408 |
|
// Check if runtrailer/runheader are within lower limits |
409 |
|
// |
410 |
|
// |
411 |
|
pkth = 0; |
412 |
|
obth = 0; |
413 |
|
spkth = 0; |
414 |
|
sobth = 0; |
415 |
|
for (Int_t k=0; k<rhev; k++){ |
416 |
|
if ( k > 0 ){ |
417 |
|
spkth = pkth; |
418 |
|
sobth = obth; |
419 |
|
}; |
420 |
|
rh->GetEntry(k); |
421 |
|
phh = ehh->GetPscuHeader(); |
422 |
|
pkth = PKT(phh->GetCounter()); |
423 |
|
obth = OBT(phh->GetOrbitalTime()); |
424 |
|
// |
425 |
|
// if ( IsDebug() ) printf(" k %i rhev before %i ph %u upperp %u oh %u uppero %u \n",k,rhev,pkth,spkth,obth,sobth); |
426 |
|
// |
427 |
|
if ( pkth < spkth && obth < sobth ){ |
428 |
|
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
429 |
|
// |
430 |
|
rhev = k-1; |
431 |
|
rh->GetEntry(rhev); |
432 |
|
pkth = spkth; |
433 |
|
obth = sobth; |
434 |
|
// |
435 |
|
UInt_t evbefh = 0; |
436 |
|
code = ehh->GetCounter(); |
437 |
|
evbefh = code->Get(pctp->Physics); |
438 |
|
if ( evbefh >= 0 ){ |
439 |
|
T->GetEntry(evbefh); |
440 |
|
ph = eh->GetPscuHeader(); |
441 |
|
t_pktlast = PKT(ph->GetCounter()); |
442 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
443 |
|
if ( t_pktlast <= spkth && t_obtlast <= sobth ){ // jump |
444 |
|
upperpkt = pkth; |
445 |
|
upperobt = obth; |
446 |
|
upperentry = evbefh-1; |
447 |
|
} else { |
448 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
449 |
|
evbefh++; |
450 |
|
T->GetEntry(evbefh); |
451 |
|
ph = eh->GetPscuHeader(); |
452 |
|
t_pktlast = PKT(ph->GetCounter()); |
453 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
454 |
|
}; |
455 |
|
T->GetEntry(evbefh-1); |
456 |
|
ph = eh->GetPscuHeader(); |
457 |
|
upperpkt = PKT(ph->GetCounter()); |
458 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
459 |
|
upperentry = evbefh-1; |
460 |
|
}; |
461 |
|
}; |
462 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
463 |
|
goto kikko0; |
464 |
|
}; |
465 |
|
}; |
466 |
|
kikko0: |
467 |
|
// |
468 |
|
// |
469 |
|
// |
470 |
|
pktt = 0; |
471 |
|
obtt = 0; |
472 |
|
spktt = 0; |
473 |
|
sobtt = 0; |
474 |
|
for (Int_t k=0; k<rtev; k++){ |
475 |
|
if ( k > 0 ){ |
476 |
|
spktt = pktt; |
477 |
|
sobtt = obtt; |
478 |
|
}; |
479 |
|
rt->GetEntry(k); |
480 |
|
pht = eht->GetPscuHeader(); |
481 |
|
pktt = PKT(pht->GetCounter()); |
482 |
|
obtt = OBT(pht->GetOrbitalTime()); |
483 |
|
// |
484 |
|
// if ( IsDebug() ) printf(" k %i rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",k,rtev,pktt,spktt,obtt,sobtt); |
485 |
|
// |
486 |
|
if ( pktt < spktt && obtt < sobtt ){ |
487 |
|
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
488 |
|
// |
489 |
|
rtev = k-1; |
490 |
|
rt->GetEntry(rtev); |
491 |
|
pktt = spktt; |
492 |
|
obtt = sobtt; |
493 |
|
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
494 |
|
// |
495 |
|
UInt_t evbeft = 0; |
496 |
|
code = eht->GetCounter(); |
497 |
|
evbeft = code->Get(pctp->Physics); |
498 |
|
if ( evbeft >= 0 ){ |
499 |
|
T->GetEntry(evbeft); |
500 |
|
ph = eh->GetPscuHeader(); |
501 |
|
t_pktlast = PKT(ph->GetCounter()); |
502 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
503 |
|
if ( t_pktlast <= spktt && t_obtlast <= sobtt ){ // jump |
504 |
|
upperpkt = pktt; |
505 |
|
upperobt = obtt; |
506 |
|
upperentry = evbeft-1; |
507 |
|
} else { |
508 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
509 |
|
evbeft++; |
510 |
|
T->GetEntry(evbeft); |
511 |
|
ph = eh->GetPscuHeader(); |
512 |
|
t_pktlast = PKT(ph->GetCounter()); |
513 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
514 |
|
}; |
515 |
|
T->GetEntry(evbeft-1); |
516 |
|
ph = eh->GetPscuHeader(); |
517 |
|
upperpkt = PKT(ph->GetCounter()); |
518 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
519 |
|
upperentry = evbeft-1; |
520 |
|
}; |
521 |
|
}; |
522 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
523 |
|
goto kikko; |
524 |
|
// break; |
525 |
|
// |
526 |
|
}; |
527 |
|
// |
528 |
|
}; |
529 |
|
// |
530 |
|
kikko: |
531 |
|
// |
532 |
|
T->GetEntry(upperentry); |
533 |
|
code = eh->GetCounter(); |
534 |
|
lasttrail = code->Get(pctp->RunTrailer); |
535 |
|
lasthead = code->Get(pctp->RunHeader); |
536 |
|
if ( lasttrail < rtev ){ |
537 |
|
rt->GetEntry(lasttrail); |
538 |
|
pht = eht->GetPscuHeader(); |
539 |
|
pktt = PKT(pht->GetCounter()); |
540 |
|
obtt = OBT(pht->GetOrbitalTime()); |
541 |
|
}; |
542 |
// |
// |
543 |
if ( lasthead < rhev ){ |
if ( lasthead < rhev ){ |
544 |
rh->GetEntry(lasthead); |
rh->GetEntry(lasthead); |
545 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
546 |
pkth = PKT(pht->GetCounter()); |
pkth = PKT(phh->GetCounter()); |
547 |
obth = OBT(pht->GetOrbitalTime()); |
obth = OBT(phh->GetOrbitalTime()); |
548 |
}; |
}; |
549 |
// |
// |
550 |
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); |
558 |
}; |
}; |
559 |
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); |
560 |
// |
// |
561 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
562 |
|
if ( pktt > upperpkt && obtt > upperobt ){ |
563 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
564 |
|
upperpkt = pktt; |
565 |
|
upperobt = obtt; |
566 |
|
rtev = lasttrail+1; |
567 |
|
} else { |
568 |
|
rtev = lasttrail; |
569 |
|
}; |
570 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
571 |
|
// |
572 |
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); |
573 |
// |
// |
574 |
return(0); |
return(0); |
649 |
// PRIVATE FUNCTIONS |
// PRIVATE FUNCTIONS |
650 |
// |
// |
651 |
|
|
652 |
/** |
// /** |
653 |
* Open the ROOT filename for reading |
// * Open the ROOT filename for reading |
654 |
*/ |
// */ |
655 |
void PamelaDBOperations::OpenFile(){ |
// void PamelaDBOperations::OpenFile(){ |
656 |
file = TFile::Open(this->GetRootName().Data()); |
// file = TFile::Open(this->GetRootName().Data()); |
657 |
|
// // |
658 |
|
|
659 |
|
void PamelaDBOperations::CheckFile(){ |
660 |
|
if ( !file ) throw -12; |
661 |
}; |
}; |
662 |
|
|
663 |
|
|
664 |
/** |
/** |
665 |
* Check if LEVEL0 file and DB connection have really be opened |
* Check if LEVEL0 file and DB connection have really be opened |
666 |
*/ |
*/ |
667 |
void PamelaDBOperations::CheckFile(){ |
void PamelaDBOperations::CheckConnection(){ |
|
// |
|
|
if ( !file ) throw -12; |
|
668 |
// |
// |
669 |
// check connection |
// check connection |
670 |
// |
// |
671 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
672 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
673 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
674 |
}; |
}; |
675 |
|
|
676 |
/** |
/** |
761 |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
762 |
}; |
}; |
763 |
// |
// |
764 |
if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported |
if ( mishead && mistrail && lastev+1 == firstev ) throw -14; // run with no events, no runtrailer, no runheader... unsupported should never arrive here |
765 |
// |
// |
766 |
if ( mishead ) { |
if ( mishead ) { |
767 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
879 |
}; |
}; |
880 |
// |
// |
881 |
TTree *T = 0; |
TTree *T = 0; |
882 |
|
Int_t signal = 0; |
883 |
// |
// |
884 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
885 |
UInt_t recEntries = 0; |
UInt_t recEntries = 0; |
931 |
// |
// |
932 |
TYPE = 55;//224; |
TYPE = 55;//224; |
933 |
// |
// |
934 |
|
if ( IsDebug() ) printf("mcmd tsync %i tsync %u obt %u \n",i,TSYNC,OBT); |
935 |
|
// |
936 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
937 |
existsts = true; |
existsts = true; |
938 |
goto out; |
goto eout; |
939 |
}; |
}; |
940 |
// |
// |
941 |
}; |
}; |
943 |
}; |
}; |
944 |
if ( !existsts ) { // try with runheader and runtrailer |
if ( !existsts ) { // try with runheader and runtrailer |
945 |
// |
// |
946 |
|
if ( IsDebug() ) printf(" No ts mcmd \n"); |
947 |
|
signal = 2; |
948 |
|
// |
949 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
950 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
951 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
955 |
// |
// |
956 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
957 |
// |
// |
958 |
// Int_t rhev = rh->GetEntries(); |
Int_t nrhev = rh->GetEntries(); |
959 |
// Int_t rtev = rt->GetEntries(); |
Int_t nrtev = rt->GetEntries(); |
960 |
|
if ( IsDebug() ) printf(" ou nevent %i rhev %i rtev %i \n",nevent,nrhev,nrtev); |
961 |
// |
// |
962 |
if ( rhev > 0 ){ |
if ( nrhev > 0 ){ |
963 |
rh->GetEntry(0); |
for (Int_t i=0; i<nrhev; i++){ |
964 |
// |
// |
965 |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
rh->GetEntry(i); |
966 |
OBT = runh->OBT_TIME_SYNC * 1000; |
// |
967 |
// |
TSYNC = runh->LAST_TIME_SYNC_INFO; |
968 |
TYPE = 20; |
OBT = runh->OBT_TIME_SYNC * 1000; |
969 |
// |
// |
970 |
if ( TSYNC && OBT ){ |
TYPE = 20; |
971 |
existsts = true; |
// |
972 |
goto out; |
if ( IsDebug() ) printf("runheader %i tsync %u obt %u \n",i,TSYNC,OBT); |
973 |
|
// |
974 |
|
if ( TSYNC && OBT ){ |
975 |
|
existsts = true; |
976 |
|
goto eout; |
977 |
|
}; |
978 |
}; |
}; |
979 |
// |
// |
980 |
}; |
}; |
981 |
if ( rtev > 0 ){ |
if ( nrtev > 0 ){ |
|
rt->GetEntry(0); |
|
|
// |
|
|
TSYNC = runt->LAST_TYME_SYNC_INFO; |
|
|
OBT = runt->OBT_TYME_SYNC * 1000; |
|
982 |
// |
// |
983 |
TYPE = 21; |
if ( IsDebug() ) printf(" No runheader \n"); |
984 |
|
signal = 6; |
985 |
// |
// |
986 |
if ( TSYNC && OBT ){ |
for (Int_t i=0; i<nrtev; i++){ |
987 |
existsts = true; |
// |
988 |
goto out; |
rt->GetEntry(i); |
989 |
|
// |
990 |
|
TSYNC = runt->LAST_TYME_SYNC_INFO; |
991 |
|
OBT = runt->OBT_TYME_SYNC * 1000; |
992 |
|
// |
993 |
|
TYPE = 21; |
994 |
|
// |
995 |
|
if ( IsDebug() ) printf("runtrailer %i tsync %u obt %u \n",i,TSYNC,OBT); |
996 |
|
// |
997 |
|
if ( TSYNC && OBT ){ |
998 |
|
existsts = true; |
999 |
|
goto eout; |
1000 |
|
}; |
1001 |
}; |
}; |
1002 |
// |
// |
1003 |
|
} else { |
1004 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
1005 |
}; |
}; |
1006 |
}; |
}; |
1007 |
// |
// |
1008 |
if ( !existsts ){ // try with inclination mcmd |
if ( !existsts ){ // try with inclination mcmd |
1009 |
|
// |
1010 |
|
if ( IsDebug() ) printf(" No runtrailer \n"); |
1011 |
|
signal = 14; |
1012 |
|
// |
1013 |
Double_t timesync = 0.; |
Double_t timesync = 0.; |
1014 |
for (UInt_t i=0; i<nevent;i++){ |
for (UInt_t i=0; i<nevent;i++){ |
1015 |
// |
// |
1038 |
TYPE = 666; |
TYPE = 666; |
1039 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
1040 |
existsts = true; |
existsts = true; |
1041 |
goto out; |
goto eout; |
1042 |
}; |
}; |
1043 |
}; |
}; |
1044 |
}; |
}; |
1045 |
// |
// |
1046 |
if ( !existsts && obt0 ){ // insert timesync by hand |
if ( !existsts && obt0 ){ // insert timesync by hand |
1047 |
|
// |
1048 |
|
if ( IsDebug() ) printf(" No incl mcmd \n"); |
1049 |
|
signal = 30; |
1050 |
|
// |
1051 |
OBT = obt0; |
OBT = obt0; |
1052 |
TSYNC = tsync; |
TSYNC = tsync; |
1053 |
TYPE = 999; |
TYPE = 999; |
1054 |
existsts = true; |
existsts = true; |
1055 |
goto out; |
goto eout; |
1056 |
}; |
}; |
1057 |
// |
// |
1058 |
out: |
eout: |
1059 |
// |
// |
1060 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
1061 |
// |
// |
1071 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
1072 |
// |
// |
1073 |
delete result; |
delete result; |
1074 |
return(0); |
return(signal); |
1075 |
} |
} |
1076 |
|
|
1077 |
/** |
/** |
1149 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
1150 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1151 |
// |
// |
1152 |
if ( !result ) return(8); |
if ( !result ) throw -4;; |
1153 |
row = result->Next(); |
row = result->Next(); |
1154 |
if ( !row ) return(16); |
if ( !row ) return(16); |
1155 |
if ( row->GetField(1) ){ |
if ( row->GetField(1) ){ |
1156 |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
1157 |
return(1); |
return(1); |
1158 |
}; |
}; |
1159 |
if ( !row->GetField(0) ) return(8); |
if ( !row->GetField(0) ) throw -26; |
1160 |
// |
// |
1161 |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
1162 |
// |
// |
1166 |
trDumpEv = (TTree*)file->Get("VarDump"); |
trDumpEv = (TTree*)file->Get("VarDump"); |
1167 |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
1168 |
// |
// |
|
if (trDumpEv == NULL) return(2); |
|
|
// |
|
1169 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
1170 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
1171 |
// |
// |
1172 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
1173 |
if (trDumpEv->GetEntries() > 0){ |
if ( trDumpEv->GetEntries() > 0 ){ |
1174 |
trDumpEv->GetEntry(0); |
Bool_t found = false; |
1175 |
vde->Records->GetEntries(); |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
1176 |
if ( !vde->Records->GetEntries() ){ |
trDumpEv->GetEntry(i); |
1177 |
if ( !this->GetBOOTnumber() ) return(4); |
vde->Records->GetEntries(); |
1178 |
} else { |
if ( vde->Records->GetEntries()>0 ){ |
1179 |
|
found = true; |
1180 |
|
goto fill; |
1181 |
|
}; |
1182 |
|
}; |
1183 |
|
fill: |
1184 |
|
if ( found ){ |
1185 |
|
// |
1186 |
vdr = (VarDumpRecord*)vde->Records->At(6); |
vdr = (VarDumpRecord*)vde->Records->At(6); |
1187 |
|
// |
1188 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
1189 |
|
// |
1190 |
|
} else { |
1191 |
|
if ( !this->GetBOOTnumber() ) return(4); |
1192 |
}; |
}; |
1193 |
} else { |
} else { |
1194 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( !this->GetBOOTnumber() ) return(2); |
1274 |
// |
// |
1275 |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
1276 |
// |
// |
1277 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1278 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1279 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1280 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1380 |
if ( (UInt_t)evbeft < upperentry-1 ){ |
if ( (UInt_t)evbeft < upperentry-1 ){ |
1381 |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n"); |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER!\n"); |
1382 |
// |
// |
1383 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1384 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1385 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1386 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
2357 |
if ( firstev == lastev+1 ) { // no events inside the run! |
if ( firstev == lastev+1 ) { // no events inside the run! |
2358 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
2359 |
// |
// |
|
// if ( IsDebug() ) printf(" -> fill the DB \n"); |
|
|
// |
|
2360 |
this->FillClass(); |
this->FillClass(); |
2361 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
2362 |
// |
// |
2567 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
2568 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
2569 |
// |
// |
2570 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
2571 |
// |
// |
2572 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
2573 |
tr->GetEntry(i); |
tr->GetEntry(i); |
2884 |
tr2->SetBranchAddress("Header", &eh2); |
tr2->SetBranchAddress("Header", &eh2); |
2885 |
nevents2 = tr2->GetEntries(); |
nevents2 = tr2->GetEntries(); |
2886 |
// |
// |
2887 |
if ( !nevents1 && !nevents2 ) return(0); |
if ( !nevents1 && !nevents2 ) return(1); |
2888 |
// |
// |
2889 |
t2 = -1; |
t2 = -1; |
2890 |
Int_t pret2 = 0; |
Int_t pret2 = 0; |
3056 |
stringstream oss; |
stringstream oss; |
3057 |
oss.str(""); |
oss.str(""); |
3058 |
// |
// |
|
CalibS4Event *calibS4 = new CalibS4Event(); |
|
3059 |
TTree *tr = 0; |
TTree *tr = 0; |
3060 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
3061 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
3069 |
tr = (TTree*)file->Get("CalibS4"); |
tr = (TTree*)file->Get("CalibS4"); |
3070 |
if ( !tr || tr->IsZombie() ) throw -24; |
if ( !tr || tr->IsZombie() ) throw -24; |
3071 |
// |
// |
|
tr->SetBranchAddress("CalibS4", &calibS4); |
|
3072 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
3073 |
// |
// |
3074 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
3075 |
// |
// |
3076 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
3077 |
// |
// |
3078 |
for (UInt_t i = 0; i < nevents; i++){ |
for (UInt_t i = 0; i < nevents; i++){ |
3079 |
// |
// |
3080 |
tr->GetEntry(i); |
tr->GetEntry(i); |
|
TArrayD params = S4_paramfit(calibS4); |
|
3081 |
// |
// |
3082 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
3083 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
3167 |
}; |
}; |
3168 |
// |
// |
3169 |
oss.str(""); |
oss.str(""); |
3170 |
oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,PARAM_FIT0,PARAM_FIT1,OBT,PKT,BOOT_NUMBER,VALIDATION) " |
oss << " INSERT INTO GL_S4_CALIB (ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME,OBT,PKT,BOOT_NUMBER) " |
3171 |
<< " VALUES (NULL,' " |
<< " VALUES (NULL,' " |
3172 |
<< idroot << "','" |
<< idroot << "','" |
3173 |
<< i << "','" |
<< i << "','" |
3174 |
<< fromtime << "','" |
<< fromtime << "','" |
3175 |
<< totime << "','" |
<< totime << "','" |
|
<< dec << params.At(0) << "','" |
|
|
<< dec << params.At(1) << "','" |
|
3176 |
<< obt << "','" |
<< obt << "','" |
3177 |
<< pkt << "','" |
<< pkt << "','" |
3178 |
<< this->GetBOOTnumber() << "','" |
<< this->GetBOOTnumber() << "');"; |
|
<< valid << "');"; |
|
3179 |
// |
// |
3180 |
if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Insert the new calibration: query is \n %s \n",oss.str().c_str()); |
3181 |
// |
// |
3196 |
return(0); |
return(0); |
3197 |
}; |
}; |
3198 |
|
|
3199 |
|
/** |
3200 |
/* |
* Scan the fragment table and move old fragments to the GL_RUN table |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
|
3201 |
*/ |
*/ |
3202 |
Double_t fitf(Double_t *x, Double_t *par){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
3203 |
Double_t fitval =(par[0]*x[0])+par[1]; |
// |
3204 |
return fitval; |
TSQLResult *result = 0; |
3205 |
} |
TSQLRow *row = 0; |
3206 |
|
TSQLResult *result2 = 0; |
3207 |
|
TSQLRow *row2 = 0; |
3208 |
|
// |
3209 |
|
UInt_t moved = 0; |
3210 |
|
// UInt_t timelim = 0; |
3211 |
|
// TDatime *time = new TDatime(); |
3212 |
|
// |
3213 |
|
stringstream oss; |
3214 |
|
oss.str(""); |
3215 |
|
// |
3216 |
|
// |
3217 |
|
// check if there are entries older than "olderthan" seconds from now |
3218 |
|
// |
3219 |
|
oss.str(""); |
3220 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3221 |
|
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
3222 |
|
// |
3223 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
3224 |
|
result = conn->Query(oss.str().c_str()); |
3225 |
|
// |
3226 |
|
if ( result ){ |
3227 |
|
// |
3228 |
|
row = result->Next(); |
3229 |
|
// |
3230 |
|
if ( row ){ |
3231 |
|
// |
3232 |
|
oss.str(""); |
3233 |
|
oss << " ID= "<< row->GetField(0); |
3234 |
|
// |
3235 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3236 |
|
// |
3237 |
|
oss.str(""); |
3238 |
|
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
3239 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
3240 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
3241 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
3242 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
3243 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3244 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3245 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
3246 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
3247 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
3248 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
3249 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3250 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3251 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
3252 |
|
// |
3253 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
3254 |
|
result2 = conn->Query(oss.str().c_str()); |
3255 |
|
// |
3256 |
|
if ( !result2 ) throw -4; |
3257 |
|
// |
3258 |
|
row2 = result2->Next(); |
3259 |
|
// |
3260 |
|
if ( !row2 ){ |
3261 |
|
// |
3262 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
3263 |
|
if ( IsDebug() ) printf(" -> fill the DB \n"); |
3264 |
|
// |
3265 |
|
glrun->SetID(0); |
3266 |
|
glrun->Fill_GL_RUN(conn); |
3267 |
|
// |
3268 |
|
oss.str(""); |
3269 |
|
oss << " SELECT ID FROM GL_RUN WHERE " |
3270 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
3271 |
|
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
3272 |
|
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
3273 |
|
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
3274 |
|
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
3275 |
|
// |
3276 |
|
if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
3277 |
|
result2 = conn->Query(oss.str().c_str()); |
3278 |
|
// |
3279 |
|
if ( !result2 ) throw -4; |
3280 |
|
// |
3281 |
|
row2 = result2->Next(); |
3282 |
|
// |
3283 |
|
if ( !row2 ) throw -25; |
3284 |
|
// |
3285 |
|
oss.str(""); |
3286 |
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
3287 |
|
if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
3288 |
|
result2 = conn->Query(oss.str().c_str()); |
3289 |
|
// |
3290 |
|
if ( !result2 ) throw -4; |
3291 |
|
// |
3292 |
|
moved++; |
3293 |
|
// |
3294 |
|
} else { |
3295 |
|
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
3296 |
|
}; |
3297 |
|
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
3298 |
|
// |
3299 |
|
// |
3300 |
|
oss.str(""); |
3301 |
|
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
3302 |
|
if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
3303 |
|
result2 = conn->Query(oss.str().c_str()); |
3304 |
|
// |
3305 |
|
if ( !result2 ) throw -4; |
3306 |
|
// |
3307 |
|
}; |
3308 |
|
}; |
3309 |
|
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
3310 |
|
return(0); |
3311 |
|
}; |
3312 |
|
|
3313 |
/* |
/** |
3314 |
* Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006 |
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
3315 |
*/ |
*/ |
3316 |
TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3317 |
|
// |
3318 |
//----------- variable initialization ------------------------------------------------- |
TSQLResult *result = 0; |
3319 |
|
TSQLRow *row = 0; |
3320 |
Double_t mip[3]={1, 30, 300}; |
// |
3321 |
Double_t adc[3] = {0.,0.,0.}; |
stringstream oss; |
3322 |
|
oss.str(""); |
3323 |
|
// |
3324 |
|
// ======================================================= |
3325 |
|
// validate runs by checking missing calibrations |
3326 |
|
// ======================================================= |
3327 |
|
UInt_t t_stop = 0; |
3328 |
|
UInt_t t_start = 0; |
3329 |
|
// -------------------------------------------------------------- |
3330 |
|
// 1) get the OBT of the last run inserted after clean-time limit |
3331 |
|
// -------------------------------------------------------------- |
3332 |
|
oss.str(""); |
3333 |
|
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
3334 |
|
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3335 |
|
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3336 |
|
result = conn->Query(oss.str().c_str()); |
3337 |
|
if ( !result ) throw -4; |
3338 |
|
if ( !result->GetRowCount() ) { |
3339 |
|
printf(" No runs to validate \n"); |
3340 |
|
return(1); |
3341 |
|
}else{ |
3342 |
|
row = result->Next(); |
3343 |
|
t_start = (UInt_t)atoll(row->GetField(4)); |
3344 |
|
}; |
3345 |
|
// -------------------------------------------------------------- |
3346 |
|
// 2) get the OBT of the last validated run |
3347 |
|
// -------------------------------------------------------------- |
3348 |
|
oss.str(""); |
3349 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3350 |
|
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3351 |
|
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
3352 |
|
result = conn->Query(oss.str().c_str()); |
3353 |
|
if ( !result ) throw -4; |
3354 |
|
if ( result->GetRowCount() ){ |
3355 |
|
row = result->Next(); |
3356 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3357 |
|
}; |
3358 |
|
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
3359 |
|
// -------------------------------------------------------------- |
3360 |
|
// now retrieves runs to be validated |
3361 |
|
// -------------------------------------------------------------- |
3362 |
|
oss.str(""); |
3363 |
|
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3364 |
|
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3365 |
|
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3366 |
|
// if ( IsDebug() ) |
3367 |
|
if ( IsDebug() )printf(" Check runs for validation: query is \n %s \n",oss.str().c_str()); |
3368 |
|
result = conn->Query(oss.str().c_str()); |
3369 |
|
if ( !result ) throw -4; |
3370 |
|
if ( !result->GetRowCount() ) printf(" No runs to validate \n"); |
3371 |
|
// printf("------------------------------------------------------------------------------- \n"); |
3372 |
|
|
3373 |
TArrayD parametri(2); |
Int_t nrow = 0; |
3374 |
|
GL_RUN* this_run = new GL_RUN(); |
3375 |
valid = 1; |
GL_RUN* next_run = new GL_RUN(); |
3376 |
|
Int_t nseq_max = 1000; |
3377 |
//------------ Fit calibrations and find parameters to calibrate data ------------------ |
// UInt_t* sequence = new UInt_t[100]; |
3378 |
pamela::S4::S4Event *s4Record; |
vector<UInt_t> sequence(nseq_max); |
3379 |
|
Int_t nseq = 0; |
3380 |
|
Bool_t CHECK = false; |
3381 |
|
Bool_t this_ONLINE = false; |
3382 |
|
Bool_t next_ONLINE = false; |
3383 |
|
UInt_t t1=0,t2=0; |
3384 |
|
// --------------------------------------------------------------------------------- |
3385 |
|
// - loop over runs, back in time, |
3386 |
|
// - select sequences of runs close in time (less than 60 s apart), |
3387 |
|
// which could be preceeded by a calibration |
3388 |
|
// - check if there might be a missing calibration |
3389 |
|
// --------------------------------------------------------------------------------- |
3390 |
|
while(1){ |
3391 |
|
|
3392 |
|
row = result->Next(); |
3393 |
|
if( row == NULL ) break; |
3394 |
|
|
3395 |
|
//------------ |
3396 |
|
//get run info |
3397 |
|
//------------ |
3398 |
|
this_run->Set_GL_RUN(row); |
3399 |
|
|
3400 |
|
Bool_t this_BAD = false; |
3401 |
|
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
3402 |
|
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
3403 |
|
else{ |
3404 |
|
// printf("Missing or corrupted header!! \n"); |
3405 |
|
this_ONLINE = false; |
3406 |
|
this_BAD = true; |
3407 |
|
}; |
3408 |
|
|
3409 |
for (Int_t j = 0; j < 4; j++){ |
//----------------------------------- |
3410 |
for (Int_t i = 0; i < 128; i++){ |
//compare with previous(next in time) |
3411 |
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
//----------------------------------- |
3412 |
switch (j) { |
CHECK = false; |
3413 |
case 0 :{ |
UInt_t interval=0; |
3414 |
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
|
3415 |
break; |
if( nrow != 0){ |
3416 |
}; |
|
3417 |
case 1 :{ |
|
3418 |
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
t1 = this_run->GetRUNTRAILER_TIME(); |
3419 |
break; |
t2 = next_run->GetRUNHEADER_TIME(); |
3420 |
}; |
interval = (t2-t1); |
3421 |
case 3 :{ |
|
3422 |
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE |
3423 |
break; |
|
3424 |
}; |
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3425 |
}; |
|
3426 |
}; |
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
3427 |
|
|
3428 |
|
if( !CHECK && this_run->VALIDATION ){ |
3429 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3430 |
|
nseq=0; |
3431 |
|
} |
3432 |
|
|
3433 |
|
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
3434 |
|
|
3435 |
|
CHECK = true; |
3436 |
|
|
3437 |
|
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
3438 |
|
|
3439 |
|
assignVALIDATION(next_run->ID,true); |
3440 |
|
nseq=0; |
3441 |
|
} |
3442 |
|
} |
3443 |
|
|
3444 |
|
//---------------------------- |
3445 |
|
//check run sequence for calib |
3446 |
|
//---------------------------- |
3447 |
|
if( CHECK ){ |
3448 |
|
// check if calibration exists |
3449 |
|
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
3450 |
|
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
3451 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
3452 |
|
nseq=0; |
3453 |
|
}; |
3454 |
|
//-------------- |
3455 |
|
//store run info |
3456 |
|
//-------------- |
3457 |
|
*next_run = *this_run; |
3458 |
|
next_ONLINE = this_ONLINE; |
3459 |
|
if( !this_BAD ){ |
3460 |
|
if(nseq < nseq_max){ |
3461 |
|
sequence[nseq] = this_run->ID; |
3462 |
|
nseq++; |
3463 |
|
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
3464 |
|
}; |
3465 |
|
|
3466 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
3467 |
|
nrow++; |
3468 |
|
|
3469 |
}; |
}; |
3470 |
|
delete this_run; |
3471 |
adc[0]=adc[0]/128; |
delete next_run; |
3472 |
adc[1]=adc[1]/128; |
// |
3473 |
adc[2]=adc[2]/128; |
return(0); |
3474 |
|
}; |
3475 |
TGraph *fitpar = new TGraph (3, adc, mip); |
/** |
3476 |
TF1 *func = new TF1("fitf", fitf, -0., 1000., 2); // definizione della funzione, 2 = num. parametri |
* Check if there might be a missing tracker calibration in a given time interval |
3477 |
|
* @param t1 From absolute time |
3478 |
func->SetParameters(0.3,1.); //inizializzazione dei parametri a 1 |
* @param t2 To absolute time |
3479 |
func->SetParNames("m","q"); //definisce il nome dei parametri |
* @return true if there might be a missing calibration |
3480 |
fitpar->Fit(func,"qr"); //fitta fitpar con la funzione func nel range definito nella funzione |
*/ |
3481 |
//fitpar->Fit(func,"r"); //fitta fitpar con la funzione func nel range definito nella funzione |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
3482 |
|
|
3483 |
parametri[0] = func -> GetParameter(0); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
3484 |
parametri[1] = func -> GetParameter(1); |
|
3485 |
|
// get the closest VALIDATED calibration before the run start (t2) |
3486 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
3487 |
|
|
3488 |
|
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
3489 |
|
|
3490 |
|
//============================================================== |
3491 |
|
// Check is done first on the basis of time between calibration, |
3492 |
|
// which should be equal to the time between ascending-nodes. |
3493 |
|
//============================================================== |
3494 |
|
if ( t2 - trkcalib->FROM_TIME > 5700) { |
3495 |
|
if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
3496 |
|
//============================================================== |
3497 |
|
// there might be a missing calibration, due to: |
3498 |
|
// - MM full |
3499 |
|
// - corrupted packets |
3500 |
|
// - loss of data |
3501 |
|
// There is an exception in case a download was done during ascending node |
3502 |
|
//============================================================== |
3503 |
|
Bool_t DOWNLOAD = false; |
3504 |
|
// check if the calib was skipped becouse of download .... DA FARE!! |
3505 |
|
if(DOWNLOAD)return(false); |
3506 |
|
|
3507 |
|
return(true); //>>> missing |
3508 |
|
|
3509 |
|
}; |
3510 |
|
|
3511 |
|
//============================================================== |
3512 |
|
// If the last calibration is close to the run less than this time, |
3513 |
|
// it is enough to say that there are no missing calibrations |
3514 |
|
//============================================================== |
3515 |
|
// the long time interval bewteen runs might be due to download |
3516 |
|
if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
3517 |
|
return(false); |
3518 |
|
|
3519 |
|
}; |
3520 |
|
/** |
3521 |
|
* Assign VALIDATION value to a GL_RUN entry |
3522 |
|
* @param idrun Run ID |
3523 |
|
* @param validation true/false |
3524 |
|
*/ |
3525 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
3526 |
|
TSQLResult *result = 0; |
3527 |
|
stringstream oss; |
3528 |
|
oss.str(""); |
3529 |
|
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
3530 |
|
// |
3531 |
|
// if ( IsDebug() ) |
3532 |
|
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
3533 |
|
if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); |
3534 |
|
result = conn->Query(oss.str().c_str()); |
3535 |
|
if ( !result ) throw -4; |
3536 |
|
return(0); |
3537 |
|
} |
3538 |
|
|
3539 |
|
|
|
if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0; |
|
3540 |
|
|
|
if ( IsDebug() ) printf(" par1 = %g par2 = %g\n",parametri[0],parametri[1]); |
|
|
|
|
|
return parametri; |
|
|
}; |
|