| 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. |
| 169 |
}; |
}; |
| 170 |
|
|
| 171 |
/** |
/** |
| 172 |
|
* Store the olderthan variable |
| 173 |
|
* @param olderthan |
| 174 |
|
*/ |
| 175 |
|
void PamelaDBOperations::SetOlderThan(Long64_t oldthan){ |
| 176 |
|
olderthan = oldthan; |
| 177 |
|
}; |
| 178 |
|
|
| 179 |
|
/** |
| 180 |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
* Retrieve the ID_RAW, if exists, returns NULL if does not exist. |
| 181 |
*/ |
*/ |
| 182 |
Bool_t PamelaDBOperations::SetID_RAW(){ |
Bool_t PamelaDBOperations::SetID_RAW(){ |
| 188 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
| 189 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
| 190 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 191 |
if (result == NULL) throw -4; |
if ( result == NULL ) throw -4; |
| 192 |
row = result->Next(); |
row = result->Next(); |
| 193 |
if (row == NULL) return false; |
if ( !row ) return(false); |
| 194 |
delete result; |
delete result; |
| 195 |
id = (UInt_t)atoll(row->GetField(0)); |
id = (UInt_t)atoll(row->GetField(0)); |
| 196 |
return(true); |
return(true); |
| 223 |
ULong64_t upperobt2 = 0; |
ULong64_t upperobt2 = 0; |
| 224 |
UInt_t zomp = 0; |
UInt_t zomp = 0; |
| 225 |
UInt_t jump = 50000; // was 5000 |
UInt_t jump = 50000; // was 5000 |
| 226 |
|
EventCounter *code=0; |
| 227 |
|
// |
| 228 |
|
// pcksList packetsNames; |
| 229 |
|
// pcksList::iterator Iter; |
| 230 |
|
// getPacketsNames(packetsNames); |
| 231 |
// |
// |
| 232 |
pktfirst = 0; |
pktfirst = 0; |
| 233 |
obtfirst = 0; |
obtfirst = 0; |
| 245 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
| 246 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
| 247 |
// |
// |
| 248 |
|
// code = eh->GetCounter(); |
| 249 |
|
// UInt_t en = 0; |
| 250 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
| 251 |
|
// en = code->Get(GetPacketType(*Iter)); |
| 252 |
|
// if ( en ) printf(" Packet type is %s, entries: %i \n",*Iter,en); |
| 253 |
|
//}; |
| 254 |
|
// |
| 255 |
T->GetEntry(nevent-1); |
T->GetEntry(nevent-1); |
| 256 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
| 257 |
pktlast = ph->GetCounter(); |
pktlast = ph->GetCounter(); |
| 320 |
// 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) |
| 321 |
// |
// |
| 322 |
PacketType *pctp=0; |
PacketType *pctp=0; |
|
EventCounter *code=0; |
|
| 323 |
T->GetEntry(upperentry); |
T->GetEntry(upperentry); |
| 324 |
code = eh->GetCounter(); |
code = eh->GetCounter(); |
| 325 |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
| 337 |
// |
// |
| 338 |
rhev = rh->GetEntries(); |
rhev = rh->GetEntries(); |
| 339 |
rtev = rt->GetEntries(); |
rtev = rt->GetEntries(); |
| 340 |
|
UInt_t sobtt = 0; |
| 341 |
|
UInt_t sobth = 0; |
| 342 |
|
UInt_t spktt = 0; |
| 343 |
|
UInt_t spkth = 0; |
| 344 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
| 345 |
ULong64_t obtt = 0; |
ULong64_t obtt = 0; |
| 346 |
UInt_t pkth = 0; |
UInt_t pkth = 0; |
| 353 |
obtt = OBT(pht->GetOrbitalTime()); |
obtt = OBT(pht->GetOrbitalTime()); |
| 354 |
}; |
}; |
| 355 |
// |
// |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
|
if ( 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); |
|
|
upperpkt = pktt; |
|
|
upperobt = obtt; |
|
|
rtev = lasttrail+1; |
|
|
} else { |
|
|
rtev = lasttrail; |
|
|
}; |
|
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
|
|
// |
|
| 356 |
if ( lasthead < rhev ){ |
if ( lasthead < rhev ){ |
| 357 |
rh->GetEntry(lasthead); |
rh->GetEntry(lasthead); |
| 358 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
| 371 |
}; |
}; |
| 372 |
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); |
| 373 |
// |
// |
| 374 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
| 375 |
|
if ( pktt > upperpkt && obtt > upperobt ){ |
| 376 |
|
if ( IsDebug() ) printf(" Upper limits extended to include last trailer: pt %i upperp %i ot %llu uppero %llu \n",pktt,upperpkt,obtt,upperobt); |
| 377 |
|
upperpkt = pktt; |
| 378 |
|
upperobt = obtt; |
| 379 |
|
rtev = lasttrail+1; |
| 380 |
|
} else { |
| 381 |
|
rtev = lasttrail; |
| 382 |
|
}; |
| 383 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
| 384 |
|
// goto kikko; |
| 385 |
|
// |
| 386 |
|
// |
| 387 |
|
// Check if runtrailer/runheader are within lower limits |
| 388 |
|
// |
| 389 |
|
// |
| 390 |
|
pkth = 0; |
| 391 |
|
obth = 0; |
| 392 |
|
spkth = 0; |
| 393 |
|
sobth = 0; |
| 394 |
|
for (Int_t k=0; k<rhev; k++){ |
| 395 |
|
if ( k > 0 ){ |
| 396 |
|
spkth = pkth; |
| 397 |
|
sobth = obth; |
| 398 |
|
}; |
| 399 |
|
rh->GetEntry(k); |
| 400 |
|
phh = ehh->GetPscuHeader(); |
| 401 |
|
pkth = PKT(phh->GetCounter()); |
| 402 |
|
obth = OBT(phh->GetOrbitalTime()); |
| 403 |
|
// |
| 404 |
|
if ( pkth < spkth && obth < sobth ){ |
| 405 |
|
if ( IsDebug() ) printf(" rhev before %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
| 406 |
|
if ( IsDebug() ) printf(" RH PROBLEMS determining the event repetition at the end of the file lasthead %i \n",rhev); |
| 407 |
|
// |
| 408 |
|
rhev--; |
| 409 |
|
rh->GetEntry(rhev); |
| 410 |
|
pkth = spkth; |
| 411 |
|
obth = sobth; |
| 412 |
|
if ( IsDebug() ) printf(" lasthead %i pt %i p1 %i ot %u o1 %u \n",rhev,pkth,spkth,obth,sobth); |
| 413 |
|
// |
| 414 |
|
UInt_t evbefh = 0; |
| 415 |
|
code = ehh->GetCounter(); |
| 416 |
|
evbefh = code->Get(pctp->Physics); |
| 417 |
|
if ( evbefh >= 0 ){ |
| 418 |
|
T->GetEntry(evbefh); |
| 419 |
|
ph = eh->GetPscuHeader(); |
| 420 |
|
t_pktlast = PKT(ph->GetCounter()); |
| 421 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
| 422 |
|
if ( t_pktlast < spkth && t_obtlast < sobth ){ // jump |
| 423 |
|
upperpkt = pkth; |
| 424 |
|
upperobt = obth; |
| 425 |
|
upperentry = evbefh-1; |
| 426 |
|
} else { |
| 427 |
|
while ( t_pktlast > spkth && t_obtlast > sobth && evbefh < nevent ){ |
| 428 |
|
evbefh++; |
| 429 |
|
T->GetEntry(evbefh); |
| 430 |
|
ph = eh->GetPscuHeader(); |
| 431 |
|
t_pktlast = PKT(ph->GetCounter()); |
| 432 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
| 433 |
|
}; |
| 434 |
|
T->GetEntry(evbefh-1); |
| 435 |
|
ph = eh->GetPscuHeader(); |
| 436 |
|
upperpkt = PKT(ph->GetCounter()); |
| 437 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
| 438 |
|
upperentry = evbefh-1; |
| 439 |
|
}; |
| 440 |
|
}; |
| 441 |
|
if ( IsDebug() ) printf(" rhev after %i ph %i upperp %i oh %llu uppero %llu \n",rhev,pkth,upperpkt,obth,upperobt); |
| 442 |
|
}; |
| 443 |
|
}; |
| 444 |
|
// |
| 445 |
|
// |
| 446 |
|
// |
| 447 |
|
pktt = 0; |
| 448 |
|
obtt = 0; |
| 449 |
|
spktt = 0; |
| 450 |
|
sobtt = 0; |
| 451 |
|
for (Int_t k=0; k<rtev; k++){ |
| 452 |
|
if ( k > 0 ){ |
| 453 |
|
spktt = pktt; |
| 454 |
|
sobtt = obtt; |
| 455 |
|
}; |
| 456 |
|
rt->GetEntry(k); |
| 457 |
|
pht = eht->GetPscuHeader(); |
| 458 |
|
pktt = PKT(pht->GetCounter()); |
| 459 |
|
obtt = OBT(pht->GetOrbitalTime()); |
| 460 |
|
// |
| 461 |
|
if ( pktt < spktt && obtt < sobtt ){ |
| 462 |
|
if ( IsDebug() ) printf(" rtev beforev %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
| 463 |
|
if ( IsDebug() ) printf(" RT PROBLEMS determining the event repetition at the end of the file lasttrail %i \n",rtev); |
| 464 |
|
// |
| 465 |
|
rtev--; |
| 466 |
|
rt->GetEntry(rtev); |
| 467 |
|
pktt = spktt; |
| 468 |
|
obtt = sobtt; |
| 469 |
|
if ( IsDebug() ) printf(" lasttrail %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
| 470 |
|
// |
| 471 |
|
UInt_t evbeft = 0; |
| 472 |
|
code = eht->GetCounter(); |
| 473 |
|
evbeft = code->Get(pctp->Physics); |
| 474 |
|
if ( evbeft >= 0 ){ |
| 475 |
|
T->GetEntry(evbeft); |
| 476 |
|
ph = eh->GetPscuHeader(); |
| 477 |
|
t_pktlast = PKT(ph->GetCounter()); |
| 478 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
| 479 |
|
if ( t_pktlast < spktt && t_obtlast < sobtt ){ // jump |
| 480 |
|
upperpkt = pktt; |
| 481 |
|
upperobt = obtt; |
| 482 |
|
upperentry = evbeft-1; |
| 483 |
|
} else { |
| 484 |
|
while ( t_pktlast > spktt && t_obtlast > sobtt && evbeft < nevent ){ |
| 485 |
|
evbeft++; |
| 486 |
|
T->GetEntry(evbeft); |
| 487 |
|
ph = eh->GetPscuHeader(); |
| 488 |
|
t_pktlast = PKT(ph->GetCounter()); |
| 489 |
|
t_obtlast = OBT(ph->GetOrbitalTime()); |
| 490 |
|
}; |
| 491 |
|
T->GetEntry(evbeft-1); |
| 492 |
|
ph = eh->GetPscuHeader(); |
| 493 |
|
upperpkt = PKT(ph->GetCounter()); |
| 494 |
|
upperobt = OBT(ph->GetOrbitalTime()); |
| 495 |
|
upperentry = evbeft-1; |
| 496 |
|
}; |
| 497 |
|
}; |
| 498 |
|
if ( IsDebug() ) printf(" rtev after %i pt %i upperp %i ot %llu uppero %llu \n",rtev,pktt,upperpkt,obtt,upperobt); |
| 499 |
|
break; |
| 500 |
|
// |
| 501 |
|
}; |
| 502 |
|
// |
| 503 |
|
}; |
| 504 |
|
// |
| 505 |
|
// kikko: |
| 506 |
|
// |
| 507 |
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); |
| 508 |
// |
// |
| 509 |
return(0); |
return(0); |
| 694 |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
lastPkt = glrun->GetRUNTRAILER_PKT(); |
| 695 |
}; |
}; |
| 696 |
// |
// |
| 697 |
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 |
| 698 |
// |
// |
| 699 |
if ( mishead ) { |
if ( mishead ) { |
| 700 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
| 812 |
}; |
}; |
| 813 |
// |
// |
| 814 |
TTree *T = 0; |
TTree *T = 0; |
| 815 |
|
Int_t signal = 0; |
| 816 |
// |
// |
| 817 |
UInt_t nevent = 0; |
UInt_t nevent = 0; |
| 818 |
UInt_t recEntries = 0; |
UInt_t recEntries = 0; |
| 866 |
// |
// |
| 867 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
| 868 |
existsts = true; |
existsts = true; |
| 869 |
goto out; |
goto eout; |
| 870 |
}; |
}; |
| 871 |
// |
// |
| 872 |
}; |
}; |
| 874 |
}; |
}; |
| 875 |
if ( !existsts ) { // try with runheader and runtrailer |
if ( !existsts ) { // try with runheader and runtrailer |
| 876 |
// |
// |
| 877 |
|
if ( IsDebug() ) printf(" No ts mcmd \n"); |
| 878 |
|
signal = 2; |
| 879 |
|
// |
| 880 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
TTree *rh=(TTree*)file->Get("RunHeader"); |
| 881 |
if ( !rh || rh->IsZombie() ) throw -17; |
if ( !rh || rh->IsZombie() ) throw -17; |
| 882 |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
TTree *rt=(TTree*)file->Get("RunTrailer"); |
| 886 |
// |
// |
| 887 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
| 888 |
// |
// |
|
// Int_t rhev = rh->GetEntries(); |
|
|
// Int_t rtev = rt->GetEntries(); |
|
|
// |
|
| 889 |
if ( rhev > 0 ){ |
if ( rhev > 0 ){ |
| 890 |
rh->GetEntry(0); |
rh->GetEntry(0); |
| 891 |
// |
// |
| 896 |
// |
// |
| 897 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
| 898 |
existsts = true; |
existsts = true; |
| 899 |
goto out; |
goto eout; |
| 900 |
}; |
}; |
| 901 |
// |
// |
| 902 |
}; |
}; |
| 903 |
if ( rtev > 0 ){ |
if ( rtev > 0 ){ |
| 904 |
|
// |
| 905 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
| 906 |
|
signal = 6; |
| 907 |
|
// |
| 908 |
rt->GetEntry(0); |
rt->GetEntry(0); |
| 909 |
// |
// |
| 910 |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
TSYNC = runt->LAST_TYME_SYNC_INFO; |
| 914 |
// |
// |
| 915 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
| 916 |
existsts = true; |
existsts = true; |
| 917 |
goto out; |
goto eout; |
| 918 |
}; |
}; |
| 919 |
// |
// |
| 920 |
|
} else { |
| 921 |
|
if ( IsDebug() ) printf(" No runheader \n"); |
| 922 |
}; |
}; |
| 923 |
}; |
}; |
| 924 |
// |
// |
| 925 |
if ( !existsts ){ // try with inclination mcmd |
if ( !existsts ){ // try with inclination mcmd |
| 926 |
|
// |
| 927 |
|
if ( IsDebug() ) printf(" No runtrailer \n"); |
| 928 |
|
signal = 14; |
| 929 |
|
// |
| 930 |
Double_t timesync = 0.; |
Double_t timesync = 0.; |
| 931 |
for (UInt_t i=0; i<nevent;i++){ |
for (UInt_t i=0; i<nevent;i++){ |
| 932 |
// |
// |
| 955 |
TYPE = 666; |
TYPE = 666; |
| 956 |
if ( TSYNC && OBT ){ |
if ( TSYNC && OBT ){ |
| 957 |
existsts = true; |
existsts = true; |
| 958 |
goto out; |
goto eout; |
| 959 |
}; |
}; |
| 960 |
}; |
}; |
| 961 |
}; |
}; |
| 962 |
// |
// |
| 963 |
if ( !existsts && obt0 ){ // insert timesync by hand |
if ( !existsts && obt0 ){ // insert timesync by hand |
| 964 |
|
// |
| 965 |
|
if ( IsDebug() ) printf(" No incl mcmd \n"); |
| 966 |
|
signal = 30; |
| 967 |
|
// |
| 968 |
OBT = obt0; |
OBT = obt0; |
| 969 |
TSYNC = tsync; |
TSYNC = tsync; |
| 970 |
TYPE = 999; |
TYPE = 999; |
| 971 |
existsts = true; |
existsts = true; |
| 972 |
goto out; |
goto eout; |
| 973 |
}; |
}; |
| 974 |
// |
// |
| 975 |
out: |
eout: |
| 976 |
// |
// |
| 977 |
if ( !existsts ) throw -3; |
if ( !existsts ) throw -3; |
| 978 |
// |
// |
| 988 |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
toffset = (UInt_t)TSYNC - (UInt_t)(this->OBT(OBT)/1000) + t0; |
| 989 |
// |
// |
| 990 |
delete result; |
delete result; |
| 991 |
return(0); |
return(signal); |
| 992 |
} |
} |
| 993 |
|
|
| 994 |
/** |
/** |
| 1066 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
| 1067 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 1068 |
// |
// |
| 1069 |
if ( !result ) return(8); |
if ( !result ) throw -4;; |
| 1070 |
row = result->Next(); |
row = result->Next(); |
| 1071 |
if ( !row ) return(16); |
if ( !row ) return(16); |
| 1072 |
if ( row->GetField(1) ){ |
if ( row->GetField(1) ){ |
| 1073 |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
this->SetBOOTnumber((UInt_t)atoll(row->GetField(1))); |
| 1074 |
return(1); |
return(1); |
| 1075 |
}; |
}; |
| 1076 |
if ( !row->GetField(0) ) return(8); |
if ( !row->GetField(0) ) throw -26; |
| 1077 |
// |
// |
| 1078 |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
UInt_t idRaw = (UInt_t)atoll(row->GetField(0)); |
| 1079 |
// |
// |
| 1083 |
trDumpEv = (TTree*)file->Get("VarDump"); |
trDumpEv = (TTree*)file->Get("VarDump"); |
| 1084 |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
if ( !trDumpEv || trDumpEv->IsZombie() ) throw -20; |
| 1085 |
// |
// |
|
if (trDumpEv == NULL) return(2); |
|
|
// |
|
| 1086 |
VarDumpEvent *vde = 0; |
VarDumpEvent *vde = 0; |
| 1087 |
VarDumpRecord *vdr = 0; |
VarDumpRecord *vdr = 0; |
| 1088 |
// |
// |
| 1089 |
trDumpEv->SetBranchAddress("VarDump", &vde); |
trDumpEv->SetBranchAddress("VarDump", &vde); |
| 1090 |
if (trDumpEv->GetEntries() > 0){ |
if ( trDumpEv->GetEntries() > 0 ){ |
| 1091 |
trDumpEv->GetEntry(0); |
Bool_t found = false; |
| 1092 |
vde->Records->GetEntries(); |
for ( Int_t i = 0; i < trDumpEv->GetEntries(); i++){ |
| 1093 |
if ( !vde->Records->GetEntries() ){ |
trDumpEv->GetEntry(i); |
| 1094 |
if ( !this->GetBOOTnumber() ) return(4); |
vde->Records->GetEntries(); |
| 1095 |
} else { |
if ( vde->Records->GetEntries()>0 ){ |
| 1096 |
|
found = true; |
| 1097 |
|
goto fill; |
| 1098 |
|
}; |
| 1099 |
|
}; |
| 1100 |
|
fill: |
| 1101 |
|
if ( found ){ |
| 1102 |
|
// |
| 1103 |
vdr = (VarDumpRecord*)vde->Records->At(6); |
vdr = (VarDumpRecord*)vde->Records->At(6); |
| 1104 |
|
// |
| 1105 |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
this->SetBOOTnumber((Int_t)vdr->VAR_VALUE); |
| 1106 |
|
// |
| 1107 |
|
} else { |
| 1108 |
|
if ( !this->GetBOOTnumber() ) return(4); |
| 1109 |
}; |
}; |
| 1110 |
} else { |
} else { |
| 1111 |
if ( !this->GetBOOTnumber() ) return(2); |
if ( !this->GetBOOTnumber() ) return(2); |
| 1191 |
// |
// |
| 1192 |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
if ( IsDebug() ) printf(" Missing header %i %i %i\n",ptht,pth,ptt); |
| 1193 |
// |
// |
| 1194 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
| 1195 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
| 1196 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
| 1197 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
| 1297 |
if ( (UInt_t)evbeft < upperentry-1 ){ |
if ( (UInt_t)evbeft < upperentry-1 ){ |
| 1298 |
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"); |
| 1299 |
// |
// |
| 1300 |
if ( (ptt-1) < 0 ) throw -15; |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
| 1301 |
rt->GetEntry(ptt-1); |
rt->GetEntry(ptt-1); |
| 1302 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
| 1303 |
evbefh = cod->Get(pctp->Physics); |
evbefh = cod->Get(pctp->Physics); |
| 2274 |
if ( firstev == lastev+1 ) { // no events inside the run! |
if ( firstev == lastev+1 ) { // no events inside the run! |
| 2275 |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
if ( IsDebug() ) printf(" Checking but no events in the run! \n"); |
| 2276 |
// |
// |
|
// if ( IsDebug() ) printf(" -> fill the DB \n"); |
|
|
// |
|
| 2277 |
this->FillClass(); |
this->FillClass(); |
| 2278 |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
if ( !IsRunAlreadyInserted() ) glrun->Fill_GL_RUN(conn); |
| 2279 |
// |
// |
| 2484 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
| 2485 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
| 2486 |
// |
// |
| 2487 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
| 2488 |
// |
// |
| 2489 |
for (UInt_t i=0; i < nevents; i++){ |
for (UInt_t i=0; i < nevents; i++){ |
| 2490 |
tr->GetEntry(i); |
tr->GetEntry(i); |
| 2801 |
tr2->SetBranchAddress("Header", &eh2); |
tr2->SetBranchAddress("Header", &eh2); |
| 2802 |
nevents2 = tr2->GetEntries(); |
nevents2 = tr2->GetEntries(); |
| 2803 |
// |
// |
| 2804 |
if ( !nevents1 && !nevents2 ) return(0); |
if ( !nevents1 && !nevents2 ) return(1); |
| 2805 |
// |
// |
| 2806 |
t2 = -1; |
t2 = -1; |
| 2807 |
Int_t pret2 = 0; |
Int_t pret2 = 0; |
| 2973 |
stringstream oss; |
stringstream oss; |
| 2974 |
oss.str(""); |
oss.str(""); |
| 2975 |
// |
// |
|
CalibS4Event *calibS4 = new CalibS4Event(); |
|
| 2976 |
TTree *tr = 0; |
TTree *tr = 0; |
| 2977 |
EventHeader *eh = 0; |
EventHeader *eh = 0; |
| 2978 |
PscuHeader *ph = 0; |
PscuHeader *ph = 0; |
| 2986 |
tr = (TTree*)file->Get("CalibS4"); |
tr = (TTree*)file->Get("CalibS4"); |
| 2987 |
if ( !tr || tr->IsZombie() ) throw -24; |
if ( !tr || tr->IsZombie() ) throw -24; |
| 2988 |
// |
// |
|
tr->SetBranchAddress("CalibS4", &calibS4); |
|
| 2989 |
tr->SetBranchAddress("Header", &eh); |
tr->SetBranchAddress("Header", &eh); |
| 2990 |
// |
// |
| 2991 |
nevents = tr->GetEntries(); |
nevents = tr->GetEntries(); |
| 2992 |
// |
// |
| 2993 |
if ( !nevents ) return(0); |
if ( !nevents ) return(1); |
| 2994 |
// |
// |
| 2995 |
for (UInt_t i = 0; i < nevents; i++){ |
for (UInt_t i = 0; i < nevents; i++){ |
| 2996 |
// |
// |
| 2997 |
tr->GetEntry(i); |
tr->GetEntry(i); |
|
TArrayD params = S4_paramfit(calibS4); |
|
| 2998 |
// |
// |
| 2999 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
| 3000 |
obt = ph->GetOrbitalTime(); |
obt = ph->GetOrbitalTime(); |
| 3084 |
}; |
}; |
| 3085 |
// |
// |
| 3086 |
oss.str(""); |
oss.str(""); |
| 3087 |
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) " |
| 3088 |
<< " VALUES (NULL,' " |
<< " VALUES (NULL,' " |
| 3089 |
<< idroot << "','" |
<< idroot << "','" |
| 3090 |
<< i << "','" |
<< i << "','" |
| 3091 |
<< fromtime << "','" |
<< fromtime << "','" |
| 3092 |
<< totime << "','" |
<< totime << "','" |
|
<< dec << params.At(0) << "','" |
|
|
<< dec << params.At(1) << "','" |
|
| 3093 |
<< obt << "','" |
<< obt << "','" |
| 3094 |
<< pkt << "','" |
<< pkt << "','" |
| 3095 |
<< this->GetBOOTnumber() << "','" |
<< this->GetBOOTnumber() << "');"; |
|
<< valid << "');"; |
|
| 3096 |
// |
// |
| 3097 |
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()); |
| 3098 |
// |
// |
| 3113 |
return(0); |
return(0); |
| 3114 |
}; |
}; |
| 3115 |
|
|
| 3116 |
|
/** |
| 3117 |
/* |
* Scan the fragment table and move old fragments to the GL_RUN table |
|
* Fit function Received from Valeria Malvezzi 06/02/2006 |
|
|
*/ |
|
|
Double_t fitf(Double_t *x, Double_t *par){ |
|
|
Double_t fitval =(par[0]*x[0])+par[1]; |
|
|
return fitval; |
|
|
} |
|
|
|
|
|
/* |
|
|
* Fit the S4 calibration with a straight line - Received from Valeria Malvezzi 06/02/2006 |
|
| 3118 |
*/ |
*/ |
| 3119 |
TArrayD PamelaDBOperations::S4_paramfit(pamela::CalibS4Event *S4CalibEvent){ |
Int_t PamelaDBOperations::CleanGL_RUN_FRAGMENTS(){ |
| 3120 |
|
// |
| 3121 |
//----------- variable initialization ------------------------------------------------- |
TSQLResult *result = 0; |
| 3122 |
|
TSQLRow *row = 0; |
| 3123 |
Double_t mip[3]={1, 30, 300}; |
TSQLResult *result2 = 0; |
| 3124 |
Double_t adc[3] = {0.,0.,0.}; |
TSQLRow *row2 = 0; |
| 3125 |
|
// |
| 3126 |
TArrayD parametri(2); |
UInt_t moved = 0; |
| 3127 |
|
UInt_t timelim = 0; |
| 3128 |
valid = 1; |
TDatime *time = new TDatime(); |
| 3129 |
|
// |
| 3130 |
//------------ Fit calibrations and find parameters to calibrate data ------------------ |
stringstream oss; |
| 3131 |
pamela::S4::S4Event *s4Record; |
oss.str(""); |
| 3132 |
|
// |
| 3133 |
for (Int_t j = 0; j < 4; j++){ |
// |
| 3134 |
for (Int_t i = 0; i < 128; i++){ |
// |
| 3135 |
s4Record = (pamela::S4::S4Event*)S4CalibEvent->Records->At((j*128 + i)); |
if ( olderthan < 0 ){ |
| 3136 |
switch (j) { |
if ( IsDebug() ) printf(" Do not clean GL_RUN_FRAGMENTS table \n"); |
| 3137 |
case 0 :{ |
return(1); |
| 3138 |
adc[0]=adc[0]+((s4Record->S4_DATA)-32); |
}; |
| 3139 |
break; |
// |
| 3140 |
}; |
// timelim = now - olderthan |
| 3141 |
case 1 :{ |
// |
| 3142 |
adc[1]=adc[1]+((s4Record->S4_DATA)-32); |
time->Set(); |
| 3143 |
break; |
timelim = (UInt_t)time->Convert() - olderthan; |
| 3144 |
}; |
time->Set(timelim,false); |
| 3145 |
case 3 :{ |
// |
| 3146 |
adc[2]=adc[2]+((s4Record->S4_DATA)-32); |
// check if there are entries older than "olderthan" seconds from now |
| 3147 |
break; |
// |
| 3148 |
}; |
oss.str(""); |
| 3149 |
|
oss << " SELECT ID FROM GL_RUN_FRAGMENTS WHERE" |
| 3150 |
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
| 3151 |
|
// |
| 3152 |
|
if ( IsDebug() ) printf(" Select from GL_RUN_FRAGMENTS runs older than %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
| 3153 |
|
result = conn->Query(oss.str().c_str()); |
| 3154 |
|
// |
| 3155 |
|
if ( result ){ |
| 3156 |
|
// |
| 3157 |
|
row = result->Next(); |
| 3158 |
|
// |
| 3159 |
|
if ( row ){ |
| 3160 |
|
// |
| 3161 |
|
oss.str(""); |
| 3162 |
|
oss << " ID= "<< row->GetField(0); |
| 3163 |
|
// |
| 3164 |
|
glrun->Query_GL_RUN_FRAGMENTS(oss.str().c_str(),conn); |
| 3165 |
|
// |
| 3166 |
|
oss.str(""); |
| 3167 |
|
oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " |
| 3168 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND (" |
| 3169 |
|
<< " (RUNHEADER_TIME>=" << (UInt_t)(glrun->GetRUNHEADER_TIME()-10) << " AND " |
| 3170 |
|
<< " RUNTRAILER_TIME<=" << (UInt_t)(glrun->GetRUNTRAILER_TIME()+10) << " AND (" |
| 3171 |
|
<< " RUNHEADER_OBT>=" << glrun->GetRUNHEADER_OBT() << " OR " |
| 3172 |
|
<< " RUNHEADER_PKT>=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
| 3173 |
|
<< " RUNTRAILER_OBT<=" << glrun->GetRUNTRAILER_OBT() << " OR " |
| 3174 |
|
<< " RUNTRAILER_PKT<=" << glrun->GetRUNTRAILER_PKT() << ") ) OR " |
| 3175 |
|
<< " (RUNHEADER_TIME<=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND " |
| 3176 |
|
<< " RUNTRAILER_TIME>=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND (" |
| 3177 |
|
<< " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " |
| 3178 |
|
<< " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" |
| 3179 |
|
<< " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " |
| 3180 |
|
<< " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; |
| 3181 |
|
// |
| 3182 |
|
if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); |
| 3183 |
|
result2 = conn->Query(oss.str().c_str()); |
| 3184 |
|
// |
| 3185 |
|
if ( !result2 ) throw -4; |
| 3186 |
|
// |
| 3187 |
|
row2 = result2->Next(); |
| 3188 |
|
// |
| 3189 |
|
if ( !row2 ){ |
| 3190 |
|
// |
| 3191 |
|
if ( IsDebug() ) printf(" The run is new \n"); |
| 3192 |
|
if ( IsDebug() ) printf(" -> fill the DB \n"); |
| 3193 |
|
// |
| 3194 |
|
glrun->SetID(0); |
| 3195 |
|
glrun->Fill_GL_RUN(conn); |
| 3196 |
|
// |
| 3197 |
|
oss.str(""); |
| 3198 |
|
oss << " SELECT ID FROM GL_RUN WHERE " |
| 3199 |
|
<< " BOOT_NUMBER=" << glrun->GetBOOT_NUMBER() << " AND " |
| 3200 |
|
<< " RUNHEADER_PKT=" << (UInt_t)glrun->GetRUNHEADER_PKT() << " AND " |
| 3201 |
|
<< " RUNTRAILER_PKT=" << (UInt_t)glrun->GetRUNTRAILER_PKT() << " AND " |
| 3202 |
|
<< " RUNHEADER_OBT=" << (UInt_t)glrun->GetRUNHEADER_OBT() << " AND " |
| 3203 |
|
<< " RUNTRAILER_OBT=" << (UInt_t)glrun->GetRUNTRAILER_OBT() << "; "; |
| 3204 |
|
// |
| 3205 |
|
if ( IsDebug() ) printf(" Look for the ID of the inserted run: query is \n %s \n",oss.str().c_str()); |
| 3206 |
|
result2 = conn->Query(oss.str().c_str()); |
| 3207 |
|
// |
| 3208 |
|
if ( !result2 ) throw -4; |
| 3209 |
|
// |
| 3210 |
|
row2 = result2->Next(); |
| 3211 |
|
// |
| 3212 |
|
if ( !row2 ) throw -25; |
| 3213 |
|
// |
| 3214 |
|
oss.str(""); |
| 3215 |
|
oss << " UPDATE GL_RUN SET ID_RUN_FRAG = " << row2->GetField(0) << " WHERE ID = " << row2->GetField(0); |
| 3216 |
|
if ( IsDebug() ) printf(" Update the ID_RUN_FRAG of the inserted run: query is \n %s \n",oss.str().c_str()); |
| 3217 |
|
result2 = conn->Query(oss.str().c_str()); |
| 3218 |
|
// |
| 3219 |
|
if ( !result2 ) throw -4; |
| 3220 |
|
// |
| 3221 |
|
moved++; |
| 3222 |
|
// |
| 3223 |
|
} else { |
| 3224 |
|
if ( IsDebug() ) printf(" The already exist in the GL_RUN table! \n"); |
| 3225 |
}; |
}; |
| 3226 |
|
if ( IsDebug() ) printf(" Delete run %s from the GL_RUN_FRAGMENTS table \n",row->GetField(0)); |
| 3227 |
|
// |
| 3228 |
|
// |
| 3229 |
|
oss.str(""); |
| 3230 |
|
oss << " DELETE from GL_RUN_FRAGMENTS where ID = " << row->GetField(0); |
| 3231 |
|
if ( IsDebug() ) printf(" Clean the GL_RUN_FRAGMENTS table: query is \n %s \n",oss.str().c_str()); |
| 3232 |
|
result2 = conn->Query(oss.str().c_str()); |
| 3233 |
|
// |
| 3234 |
|
if ( !result2 ) throw -4; |
| 3235 |
|
// |
| 3236 |
}; |
}; |
| 3237 |
}; |
}; |
| 3238 |
|
if ( IsDebug() ) printf(" Moved %u runs\n",moved); |
| 3239 |
adc[0]=adc[0]/128; |
return(0); |
| 3240 |
adc[1]=adc[1]/128; |
}; |
|
adc[2]=adc[2]/128; |
|
|
|
|
|
TGraph *fitpar = new TGraph (3, adc, mip); |
|
|
TF1 *func = new TF1("fitf", fitf, -0., 1000., 2); // definizione della funzione, 2 = num. parametri |
|
|
|
|
|
func->SetParameters(0.3,1.); //inizializzazione dei parametri a 1 |
|
|
func->SetParNames("m","q"); //definisce il nome dei parametri |
|
|
fitpar->Fit(func,"qr"); //fitta fitpar con la funzione func nel range definito nella funzione |
|
|
//fitpar->Fit(func,"r"); //fitta fitpar con la funzione func nel range definito nella funzione |
|
|
|
|
|
parametri[0] = func -> GetParameter(0); |
|
|
parametri[1] = func -> GetParameter(1); |
|
|
|
|
|
if ( parametri[0] < 0. || parametri[0] > 0.5 || parametri[1] < 0.8 || parametri[1] > 1. ) valid = 0; |
|
| 3241 |
|
|
| 3242 |
if ( IsDebug() ) printf(" par1 = %g par2 = %g\n",parametri[0],parametri[1]); |
/** |
| 3243 |
|
* Check if runs are good, i.e. if the tracker calibration is correctly associated.. |
| 3244 |
return parametri; |
*/ |
| 3245 |
|
Int_t PamelaDBOperations::ValidateRuns(){ |
| 3246 |
|
// |
| 3247 |
|
TSQLResult *result = 0; |
| 3248 |
|
// TSQLRow *row = 0; |
| 3249 |
|
// |
| 3250 |
|
UInt_t timelim = 0; |
| 3251 |
|
TDatime *time = new TDatime(); |
| 3252 |
|
// |
| 3253 |
|
stringstream oss; |
| 3254 |
|
oss.str(""); |
| 3255 |
|
// |
| 3256 |
|
// |
| 3257 |
|
// |
| 3258 |
|
if ( olderthan < 0 ){ |
| 3259 |
|
if ( IsDebug() ) printf(" Do not validate runs \n"); |
| 3260 |
|
return(1); |
| 3261 |
|
}; |
| 3262 |
|
// |
| 3263 |
|
// timelim = now - olderthan |
| 3264 |
|
// |
| 3265 |
|
time->Set(); |
| 3266 |
|
timelim = (UInt_t)time->Convert() - olderthan; |
| 3267 |
|
time->Set(timelim,false); |
| 3268 |
|
// |
| 3269 |
|
// First of all validate runs with default calibration: |
| 3270 |
|
// |
| 3271 |
|
oss.str(""); |
| 3272 |
|
oss << " UPDATE GL_RUN SET VALIDATION=1 WHERE" |
| 3273 |
|
<< " VALIDATION = 0 AND TRK_CALIB_USED=104 AND " |
| 3274 |
|
<< " INSERT_TIME <= '" << time->AsSQLString() << "';"; |
| 3275 |
|
// |
| 3276 |
|
if ( IsDebug() ) printf(" Validate runs with trk default calibration inserted before %s : query is \n %s \n",time->AsSQLString(),oss.str().c_str()); |
| 3277 |
|
result = conn->Query(oss.str().c_str()); |
| 3278 |
|
// |
| 3279 |
|
if ( !result ) throw -4; |
| 3280 |
|
// |
| 3281 |
|
return(0); |
| 3282 |
}; |
}; |