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; |
933 |
// |
// |
934 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
935 |
existsts = true; |
existsts = true; |
936 |
goto out; |
goto eout; |
937 |
}; |
}; |
938 |
// |
// |
939 |
}; |
}; |
941 |
}; |
}; |
942 |
if ( !existsts ) { // try with runheader and runtrailer |
if ( !existsts ) { // try with runheader and runtrailer |
943 |
// |
// |
944 |
|
if ( IsDebug() ) printf(" No ts mcmd \n"); |
945 |
|
signal = 2; |
946 |
|
// |
947 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
948 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
949 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
953 |
// |
// |
954 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
955 |
// |
// |
|
// Int_t rhev = rh->GetEntries(); |
|
|
// Int_t rtev = rt->GetEntries(); |
|
|
// |
|
956 |
if ( rhev > 0 ){ |
if ( rhev > 0 ){ |
957 |
rh->GetEntry(0); |
rh->GetEntry(0); |
958 |
// |
// |
963 |
// |
// |
964 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
965 |
existsts = true; |
existsts = true; |
966 |
goto out; |
goto eout; |
967 |
}; |
}; |
968 |
// |
// |
969 |
}; |
}; |
970 |
if ( rtev > 0 ){ |
if ( rtev > 0 ){ |
971 |
|
// |
972 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
973 |
|
signal = 6; |
974 |
|
// |
975 |
rt->GetEntry(0); |
rt->GetEntry(0); |
976 |
// |
// |
977 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
981 |
// |
// |
982 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
983 |
existsts = true; |
existsts = true; |
984 |
goto out; |
goto eout; |
985 |
}; |
}; |
986 |
// |
// |
987 |
|
} else { |
988 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
989 |
}; |
}; |
990 |
}; |
}; |
991 |
// |
// |
992 |
if ( !existsts ){ // try with inclination mcmd |
if ( !existsts ){ // try with inclination mcmd |
993 |
|
// |
994 |
|
if ( IsDebug() ) printf(" No runtrailer \n"); |
995 |
|
signal = 14; |
996 |
|
// |
997 |
Double_t timesync = 0.; |
Double_t timesync = 0.; |
998 |
for (UInt_t i=0; i<nevent;i++){ |
for (UInt_t i=0; i<nevent;i++){ |
999 |
// |
// |
1022 |
TYPE = 666; |
TYPE = 666; |
1023 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
1024 |
existsts = true; |
existsts = true; |
1025 |
goto out; |
goto eout; |
1026 |
}; |
}; |
1027 |
}; |
}; |
1028 |
}; |
}; |
1029 |
// |
// |
1030 |
if ( !existsts && obt0 ){ // insert timesync by hand |
if ( !existsts && obt0 ){ // insert timesync by hand |
1031 |
|
// |
1032 |
|
if ( IsDebug() ) printf(" No incl mcmd \n"); |
1033 |
|
signal = 30; |
1034 |
|
// |
1035 |
OBT = obt0; |
OBT = obt0; |
1036 |
TSYNC = tsync; |
TSYNC = tsync; |
1037 |
TYPE = 999; |
TYPE = 999; |
1038 |
existsts = true; |
existsts = true; |
1039 |
goto out; |
goto eout; |
1040 |
}; |
}; |
1041 |
// |
// |
1042 |
out: |
eout: |
1043 |
// |
// |
1044 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
1045 |
// |
// |
1055 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
1056 |
// |
// |
1057 |
delete result; |
delete result; |
1058 |
return(0); |
return(signal); |
1059 |
} |
} |
1060 |
|
|
1061 |
/** |
/** |
1133 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
1134 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1135 |
// |
// |
1136 |
if ( !result ) return(8); |
if ( !result ) throw -4;; |
1137 |
row = result->Next(); |
row = result->Next(); |
1138 |
if ( !row ) return(16); |
if ( !row ) return(16); |
1139 |
if ( row->GetField(1) ){ |
if ( row->GetField(1) ){ |
1140 |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
1141 |
return(1); |
return(1); |
1142 |
}; |
}; |
1143 |
if ( !row->GetField(0) ) return(8); |
if ( !row->GetField(0) ) throw -26; |
1144 |
// |
// |
1145 |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
1146 |
// |
// |
1150 |
trDumpEv = (TTree*)file->Get("VarDump"); |
trDumpEv = (TTree*)file->Get("VarDump"); |
1151 |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
1152 |
// |
// |
|
if (trDumpEv == NULL) return(2); |
|
|
// |
|
1153 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
1154 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
1155 |
// |
// |
1156 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
1157 |
if (trDumpEv->GetEntries() > 0){ |
if ( trDumpEv->GetEntries() > 0 ){ |
1158 |
trDumpEv->GetEntry(0); |
Bool_t found = false; |
1159 |
vde->Records->GetEntries(); |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
1160 |
if ( !vde->Records->GetEntries() ){ |
trDumpEv->GetEntry(i); |
1161 |
if ( !this->GetBOOTnumber() ) return(4); |
vde->Records->GetEntries(); |
1162 |
} else { |
if ( vde->Records->GetEntries()>0 ){ |
1163 |
|
found = true; |
1164 |
|
goto fill; |
1165 |
|
}; |
1166 |
|
}; |
1167 |
|
fill: |
1168 |
|
if ( found ){ |
1169 |
|
// |
1170 |
vdr = (VarDumpRecord*)vde->Records->At(6); |
vdr = (VarDumpRecord*)vde->Records->At(6); |
1171 |
|
// |
1172 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
1173 |
|
// |
1174 |
|
} else { |
1175 |
|
if ( !this->GetBOOTnumber() ) return(4); |
1176 |
}; |
}; |
1177 |
} else { |
} else { |
1178 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( !this->GetBOOTnumber() ) return(2); |
1258 |
// |
// |
1259 |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
1260 |
// |
// |
1261 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1262 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1263 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1264 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
1364 |
if ( (UInt_t)evbeft < upperentry-1 ){ |
if ( (UInt_t)evbeft < upperentry-1 ){ |
1365 |
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"); |
1366 |
// |
// |
1367 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
1368 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
1369 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
1370 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
2341 |
if ( firstev == lastev+1 ) { // no events inside the run! |
if ( firstev == lastev+1 ) { // no events inside the run! |
2342 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
2343 |
// |
// |
|
// if ( IsDebug() ) printf(" -> fill the DB \n"); |
|
|
// |
|
2344 |
this->FillClass(); |
this->FillClass(); |
2345 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
2346 |
// |
// |
2551 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
2552 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
2553 |
// |
// |
2554 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
2555 |
// |
// |
2556 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
2557 |
tr->GetEntry(i); |
tr->GetEntry(i); |
2868 |
tr2->SetBranchAddress("Header", &eh2); |
tr2->SetBranchAddress("Header", &eh2); |
2869 |
nevents2 = tr2->GetEntries(); |
nevents2 = tr2->GetEntries(); |
2870 |
// |
// |
2871 |
if ( !nevents1 && !nevents2 ) return(0); |
if ( !nevents1 && !nevents2 ) return(1); |
2872 |
// |
// |
2873 |
t2 = -1; |
t2 = -1; |
2874 |
Int_t pret2 = 0; |
Int_t pret2 = 0; |
3040 |
stringstream oss; |
stringstream oss; |
3041 |
oss.str(""); |
oss.str(""); |
3042 |
// |
// |
|
CalibS4Event *calibS4 = new CalibS4Event(); |
|
3043 |
TTree *tr = 0; |
TTree *tr = 0; |
3044 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
3045 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
3053 |
tr = (TTree*)file->Get("CalibS4"); |
tr = (TTree*)file->Get("CalibS4"); |
3054 |
if ( !tr || tr->IsZombie() ) throw -24; |
if ( !tr || tr->IsZombie() ) throw -24; |
3055 |
// |
// |
|
tr->SetBranchAddress("CalibS4", &calibS4); |
|
3056 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
3057 |
// |
// |
3058 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
3059 |
// |
// |
3060 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
3061 |
// |
// |
3062 |
for (UInt_t i = 0; i < nevents; i++){ |
for (UInt_t i = 0; i < nevents; i++){ |
3063 |
// |
// |
3064 |
tr->GetEntry(i); |
tr->GetEntry(i); |
|
TArrayD params = S4_paramfit(calibS4); |
|
3065 |
// |
// |
3066 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
3067 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
3151 |
}; |
}; |
3152 |
// |
// |
3153 |
oss.str(""); |
oss.str(""); |
3154 |
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) " |
3155 |
<< " VALUES (NULL,' " |
<< " VALUES (NULL,' " |
3156 |
<< idroot << "','" |
<< idroot << "','" |
3157 |
<< i << "','" |
<< i << "','" |
3158 |
<< fromtime << "','" |
<< fromtime << "','" |
3159 |
<< totime << "','" |
<< totime << "','" |
|
<< dec << params.At(0) << "','" |
|
|
<< dec << params.At(1) << "','" |
|
3160 |
<< obt << "','" |
<< obt << "','" |
3161 |
<< pkt << "','" |
<< pkt << "','" |
3162 |
<< this->GetBOOTnumber() << "','" |
<< this->GetBOOTnumber() << "');"; |
|
<< valid << "');"; |
|
3163 |
// |
// |
3164 |
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()); |
3165 |
// |
// |
3180 |
return(0); |
return(0); |
3181 |
}; |
}; |
3182 |
|
|
3183 |
|
/** |
3184 |
/* |
* Scan the fragment table and move old fragments to the GL_RUN table |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
|
3185 |
*/ |
*/ |
3186 |
Double_t fitf(Double_t *x, Double_t *par){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
3187 |
Double_t fitval =(par[0]*x[0])+par[1]; |
// |
3188 |
return fitval; |
TSQLResult *result = 0; |
3189 |
} |
TSQLRow *row = 0; |
3190 |
|
TSQLResult *result2 = 0; |
3191 |
|
TSQLRow *row2 = 0; |
3192 |
|
// |
3193 |
|
UInt_t moved = 0; |
3194 |
|
// UInt_t timelim = 0; |
3195 |
|
// TDatime *time = new TDatime(); |
3196 |
|
// |
3197 |
|
stringstream oss; |
3198 |
|
oss.str(""); |
3199 |
|
// |
3200 |
|
// |
3201 |
|
// check if there are entries older than "olderthan" seconds from now |
3202 |
|
// |
3203 |
|
oss.str(""); |
3204 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
3205 |
|
<< " INSERT_TIME <= '" << clean_time->AsSQLString() << "';"; |
3206 |
|
// |
3207 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",clean_time->AsSQLString(),oss.str().c_str()); |
3208 |
|
result = conn->Query(oss.str().c_str()); |
3209 |
|
// |
3210 |
|
if ( result ){ |
3211 |
|
// |
3212 |
|
row = result->Next(); |
3213 |
|
// |
3214 |
|
if ( row ){ |
3215 |
|
// |
3216 |
|
oss.str(""); |
3217 |
|
oss << " ID= "<< row->GetField(0); |
3218 |
|
// |
3219 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
3220 |
|
// |
3221 |
|
oss.str(""); |
3222 |
|
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
3223 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
3224 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
3225 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
3226 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
3227 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3228 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3229 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
3230 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
3231 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
3232 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
3233 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
3234 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
3235 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
3236 |
|
// |
3237 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
3238 |
|
result2 = conn->Query(oss.str().c_str()); |
3239 |
|
// |
3240 |
|
if ( !result2 ) throw -4; |
3241 |
|
// |
3242 |
|
row2 = result2->Next(); |
3243 |
|
// |
3244 |
|
if ( !row2 ){ |
3245 |
|
// |
3246 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
3247 |
|
if ( IsDebug() ) printf(" -> fill the DB \n"); |
3248 |
|
// |
3249 |
|
glrun->SetID(0); |
3250 |
|
glrun->Fill_GL_RUN(conn); |
3251 |
|
// |
3252 |
|
oss.str(""); |
3253 |
|
oss << " SELECT ID FROM GL_RUN WHERE " |
3254 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
3255 |
|
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
3256 |
|
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
3257 |
|
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
3258 |
|
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
3259 |
|
// |
3260 |
|
if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
3261 |
|
result2 = conn->Query(oss.str().c_str()); |
3262 |
|
// |
3263 |
|
if ( !result2 ) throw -4; |
3264 |
|
// |
3265 |
|
row2 = result2->Next(); |
3266 |
|
// |
3267 |
|
if ( !row2 ) throw -25; |
3268 |
|
// |
3269 |
|
oss.str(""); |
3270 |
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
3271 |
|
if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
3272 |
|
result2 = conn->Query(oss.str().c_str()); |
3273 |
|
// |
3274 |
|
if ( !result2 ) throw -4; |
3275 |
|
// |
3276 |
|
moved++; |
3277 |
|
// |
3278 |
|
} else { |
3279 |
|
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
3280 |
|
}; |
3281 |
|
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
3282 |
|
// |
3283 |
|
// |
3284 |
|
oss.str(""); |
3285 |
|
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
3286 |
|
if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
3287 |
|
result2 = conn->Query(oss.str().c_str()); |
3288 |
|
// |
3289 |
|
if ( !result2 ) throw -4; |
3290 |
|
// |
3291 |
|
}; |
3292 |
|
}; |
3293 |
|
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
3294 |
|
return(0); |
3295 |
|
}; |
3296 |
|
|
3297 |
/* |
/** |
3298 |
* 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.. |
3299 |
*/ |
*/ |
3300 |
TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){ |
Int_t PamelaDBOperations::ValidateRuns(){ |
3301 |
|
// |
3302 |
//----------- variable initialization ------------------------------------------------- |
TSQLResult *result = 0; |
3303 |
|
TSQLRow *row = 0; |
3304 |
Double_t mip[3]={1, 30, 300}; |
// |
3305 |
Double_t adc[3] = {0.,0.,0.}; |
stringstream oss; |
3306 |
|
oss.str(""); |
3307 |
|
// |
3308 |
|
// ======================================================= |
3309 |
|
// validate runs by checking missing calibrations |
3310 |
|
// ======================================================= |
3311 |
|
UInt_t t_stop = 0; |
3312 |
|
UInt_t t_start = 0; |
3313 |
|
// -------------------------------------------------------------- |
3314 |
|
// 1) get the OBT of the last run inserted after clean-time limit |
3315 |
|
// -------------------------------------------------------------- |
3316 |
|
oss.str(""); |
3317 |
|
oss << " SELECT * FROM GL_RUN WHERE INSERT_TIME <= '" << clean_time->AsSQLString() |
3318 |
|
<< "' ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3319 |
|
if ( IsDebug() ) printf(" Get start validation-time: query is \n %s \n",oss.str().c_str()); |
3320 |
|
result = conn->Query(oss.str().c_str()); |
3321 |
|
if ( !result ) throw -4; |
3322 |
|
if ( !result->GetRowCount() ) { |
3323 |
|
printf(" No runs to validate \n"); |
3324 |
|
return(1); |
3325 |
|
}else{ |
3326 |
|
row = result->Next(); |
3327 |
|
t_start = (UInt_t)atoll(row->GetField(4)); |
3328 |
|
}; |
3329 |
|
// -------------------------------------------------------------- |
3330 |
|
// 2) get the OBT of the last validated run |
3331 |
|
// -------------------------------------------------------------- |
3332 |
|
oss.str(""); |
3333 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
3334 |
|
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
3335 |
|
if ( IsDebug() ) printf(" Get stop 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 |
|
row = result->Next(); |
3340 |
|
t_stop = (UInt_t)atoll(row->GetField(4)); |
3341 |
|
}; |
3342 |
|
if ( IsDebug() ) printf("Validation interval: from time %i - to time %i \n\n",t_stop,t_start); |
3343 |
|
// -------------------------------------------------------------- |
3344 |
|
// now retrieves runs to be validated |
3345 |
|
// -------------------------------------------------------------- |
3346 |
|
oss.str(""); |
3347 |
|
oss << " SELECT * FROM GL_RUN WHERE RUNHEADER_TIME <=" << t_start; |
3348 |
|
oss << " AND RUNHEADER_TIME >="<< t_stop; |
3349 |
|
oss << " ORDER BY RUNHEADER_TIME DESC;"; |
3350 |
|
// if ( IsDebug() ) |
3351 |
|
if ( IsDebug() )printf(" Check runs for validation: 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() ) printf(" No runs to validate \n"); |
3355 |
|
// printf("------------------------------------------------------------------------------- \n"); |
3356 |
|
|
3357 |
TArrayD parametri(2); |
Int_t nrow = 0; |
3358 |
|
GL_RUN* this_run = new GL_RUN(); |
3359 |
valid = 1; |
GL_RUN* next_run = new GL_RUN(); |
3360 |
|
Int_t nseq_max = 1000; |
3361 |
//------------ Fit calibrations and find parameters to calibrate data ------------------ |
// UInt_t* sequence = new UInt_t[100]; |
3362 |
pamela::S4::S4Event *s4Record; |
vector<UInt_t> sequence(nseq_max); |
3363 |
|
Int_t nseq = 0; |
3364 |
|
Bool_t CHECK = false; |
3365 |
|
Bool_t this_ONLINE = false; |
3366 |
|
Bool_t next_ONLINE = false; |
3367 |
|
UInt_t t1=0,t2=0; |
3368 |
|
// --------------------------------------------------------------------------------- |
3369 |
|
// - loop over runs, back in time, |
3370 |
|
// - select sequences of runs close in time (less than 60 s apart), |
3371 |
|
// which could be preceeded by a calibration |
3372 |
|
// - check if there might be a missing calibration |
3373 |
|
// --------------------------------------------------------------------------------- |
3374 |
|
while(1){ |
3375 |
|
|
3376 |
|
row = result->Next(); |
3377 |
|
if( row == NULL ) break; |
3378 |
|
|
3379 |
|
//------------ |
3380 |
|
//get run info |
3381 |
|
//------------ |
3382 |
|
this_run->Set_GL_RUN(row); |
3383 |
|
|
3384 |
|
Bool_t this_BAD = false; |
3385 |
|
if(this_run->GetTRK_CALIB_USED() == 1 || this_run->GetTRK_CALIB_USED() == 2) this_ONLINE = true; |
3386 |
|
else if (this_run->GetTRK_CALIB_USED() == 104) this_ONLINE = false; |
3387 |
|
else{ |
3388 |
|
// printf("Missing or corrupted header!! \n"); |
3389 |
|
this_ONLINE = false; |
3390 |
|
this_BAD = true; |
3391 |
|
}; |
3392 |
|
|
3393 |
for (Int_t j = 0; j < 4; j++){ |
//----------------------------------- |
3394 |
for (Int_t i = 0; i < 128; i++){ |
//compare with previous(next in time) |
3395 |
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
//----------------------------------- |
3396 |
switch (j) { |
CHECK = false; |
3397 |
case 0 :{ |
UInt_t interval=0; |
3398 |
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
|
3399 |
break; |
if( nrow != 0){ |
3400 |
}; |
|
3401 |
case 1 :{ |
|
3402 |
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
t1 = this_run->GetRUNTRAILER_TIME(); |
3403 |
break; |
t2 = next_run->GetRUNHEADER_TIME(); |
3404 |
}; |
interval = (t2-t1); |
3405 |
case 3 :{ |
|
3406 |
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
if(this_ONLINE && next_ONLINE){ // this: ON-LINE + next: ON-LINE |
3407 |
break; |
|
3408 |
}; |
if( this_run->ID == next_run->ID_RUN_FRAG ) interval = 0; //=> run fragments |
3409 |
}; |
|
3410 |
}; |
if( interval >= 60 )CHECK = true; //more than 60 s => there might be a calibration |
3411 |
|
|
3412 |
|
if( !CHECK && this_run->VALIDATION ){ |
3413 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
3414 |
|
nseq=0; |
3415 |
|
} |
3416 |
|
|
3417 |
|
}else if( !this_ONLINE && next_ONLINE) { // this: DEFAULT + next:ON-LINE |
3418 |
|
|
3419 |
|
CHECK = true; |
3420 |
|
|
3421 |
|
}else if( !next_ONLINE ){ // this:ANY + next:DEFAULT |
3422 |
|
|
3423 |
|
assignVALIDATION(next_run->ID,true); |
3424 |
|
nseq=0; |
3425 |
|
} |
3426 |
|
} |
3427 |
|
|
3428 |
|
//---------------------------- |
3429 |
|
//check run sequence for calib |
3430 |
|
//---------------------------- |
3431 |
|
if( CHECK ){ |
3432 |
|
// check if calibration exists |
3433 |
|
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
3434 |
|
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
3435 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
3436 |
|
nseq=0; |
3437 |
|
}; |
3438 |
|
//-------------- |
3439 |
|
//store run info |
3440 |
|
//-------------- |
3441 |
|
*next_run = *this_run; |
3442 |
|
next_ONLINE = this_ONLINE; |
3443 |
|
if( !this_BAD ){ |
3444 |
|
if(nseq < nseq_max){ |
3445 |
|
sequence[nseq] = this_run->ID; |
3446 |
|
nseq++; |
3447 |
|
}else printf("ValidateRuns ***WARNING*** : run sequence exceed assumed size (%i) \n",nseq_max); |
3448 |
|
}; |
3449 |
|
|
3450 |
|
if ( IsDebug() ) printf("%i Run %i \n",nrow,this_run->ID); |
3451 |
|
nrow++; |
3452 |
|
|
3453 |
}; |
}; |
3454 |
|
delete this_run; |
3455 |
adc[0]=adc[0]/128; |
delete next_run; |
3456 |
adc[1]=adc[1]/128; |
// |
3457 |
adc[2]=adc[2]/128; |
return(0); |
3458 |
|
}; |
3459 |
TGraph *fitpar = new TGraph (3, adc, mip); |
/** |
3460 |
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 |
3461 |
|
* @param t1 From absolute time |
3462 |
func->SetParameters(0.3,1.); //inizializzazione dei parametri a 1 |
* @param t2 To absolute time |
3463 |
func->SetParNames("m","q"); //definisce il nome dei parametri |
* @return true if there might be a missing calibration |
3464 |
fitpar->Fit(func,"qr"); //fitta fitpar con la funzione func nel range definito nella funzione |
*/ |
3465 |
//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){ |
3466 |
|
|
3467 |
parametri[0] = func -> GetParameter(0); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
3468 |
parametri[1] = func -> GetParameter(1); |
|
3469 |
|
// get the closest VALIDATED calibration before the run start (t2) |
3470 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
3471 |
|
|
3472 |
|
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
3473 |
|
|
3474 |
|
//============================================================== |
3475 |
|
// Check is done first on the basis of time between calibration, |
3476 |
|
// which should be equal to the time between ascending-nodes. |
3477 |
|
//============================================================== |
3478 |
|
if ( t2 - trkcalib->FROM_TIME > 5700) { |
3479 |
|
if ( IsDebug() )printf("Long time between calib and run start %i :-( ==> there might be a missing calib \n",t2 - trkcalib->FROM_TIME); |
3480 |
|
//============================================================== |
3481 |
|
// there might be a missing calibration, due to: |
3482 |
|
// - MM full |
3483 |
|
// - corrupted packets |
3484 |
|
// - loss of data |
3485 |
|
// There is an exception in case a download was done during ascending node |
3486 |
|
//============================================================== |
3487 |
|
Bool_t DOWNLOAD = false; |
3488 |
|
// check if the calib was skipped becouse of download .... DA FARE!! |
3489 |
|
if(DOWNLOAD)return(false); |
3490 |
|
|
3491 |
|
return(true); //>>> missing |
3492 |
|
|
3493 |
|
}; |
3494 |
|
|
3495 |
|
//============================================================== |
3496 |
|
// If the last calibration is close to the run less than this time, |
3497 |
|
// it is enough to say that there are no missing calibrations |
3498 |
|
//============================================================== |
3499 |
|
// the long time interval bewteen runs might be due to download |
3500 |
|
if ( IsDebug() )printf("Short time between calib and run start %i :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
3501 |
|
return(false); |
3502 |
|
|
3503 |
|
}; |
3504 |
|
/** |
3505 |
|
* Assign VALIDATION value to a GL_RUN entry |
3506 |
|
* @param idrun Run ID |
3507 |
|
* @param validation true/false |
3508 |
|
*/ |
3509 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
3510 |
|
TSQLResult *result = 0; |
3511 |
|
stringstream oss; |
3512 |
|
oss.str(""); |
3513 |
|
oss << " UPDATE GL_RUN SET VALIDATION="<< (UInt_t)validation <<" WHERE ID= " << idrun << ";"; |
3514 |
|
// |
3515 |
|
// if ( IsDebug() ) |
3516 |
|
// printf(" Set VALIDATION = %i for run %i \n",validation,idrun); |
3517 |
|
if ( IsDebug() )printf(" Query: %s \n",oss.str().c_str()); |
3518 |
|
result = conn->Query(oss.str().c_str()); |
3519 |
|
if ( !result ) throw -4; |
3520 |
|
return(0); |
3521 |
|
} |
3522 |
|
|
3523 |
|
|
|
if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0; |
|
3524 |
|
|
|
if ( IsDebug() ) printf(" par1 = %g par2 = %g\n",parametri[0],parametri[1]); |
|
|
|
|
|
return parametri; |
|
|
}; |
|