| 273 |
oss << "SELECT ID FROM GL_RAW WHERE " |
oss << "SELECT ID FROM GL_RAW WHERE " |
| 274 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
| 275 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
| 276 |
|
|
| 277 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 278 |
if ( result == NULL ) throw -4; |
if ( result == NULL ) throw -4; |
| 279 |
row = result->Next(); |
row = result->Next(); |
| 779 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
| 780 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
| 781 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
| 782 |
|
// |
| 783 |
|
if ( IsDebug() ) printf("\n DB INFORMATIONS:\n SQL: %s Version: %s Host %s Port %i \n\n",conn->GetDBMS(),conn->ServerInfo(),conn->GetHost(),conn->GetPort()); |
| 784 |
|
// |
| 785 |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
| 786 |
// |
// |
| 787 |
// set DB timezone to UTC |
// set DB timezone to UTC |
| 793 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
| 794 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 795 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
| 796 |
|
oss.str(""); |
| 797 |
|
oss << "SET wait_timeout=173000;"; |
| 798 |
|
conn->Query(oss.str().c_str()); |
| 799 |
// |
// |
| 800 |
}; |
}; |
| 801 |
|
|
| 1714 |
delete result; |
delete result; |
| 1715 |
// |
// |
| 1716 |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
| 1717 |
|
if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n"); |
| 1718 |
return(signal); |
return(signal); |
| 1719 |
}; |
}; |
| 1720 |
|
|
| 1828 |
// |
// |
| 1829 |
} else { |
} else { |
| 1830 |
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
if ( IsDebug() ) printf(" The run is already present in the fragment table \n"); |
| 1831 |
|
return; |
| 1832 |
}; |
}; |
| 1833 |
// |
// |
| 1834 |
// |
// |
| 3101 |
pkt1 = ph1->GetCounter(); |
pkt1 = ph1->GetCounter(); |
| 3102 |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
| 3103 |
// |
// |
| 3104 |
valid = 1; |
// valid = 1; |
| 3105 |
// |
// // |
| 3106 |
if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
| 3107 |
// |
// |
| 3108 |
// |
// |
| 3109 |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
| 3110 |
// |
// |
| 3111 |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Trk calibration1 at time %i obt %i pkt %i \n",fromtime,obt1,pkt1); |
| 3112 |
|
// |
| 3113 |
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
| 3114 |
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
| 3115 |
// |
// |
| 3116 |
// Do we have the second calibration packet? |
// Do we have the second calibration packet? |
| 3117 |
// |
// |
| 3128 |
obt2 = ph2->GetOrbitalTime(); |
obt2 = ph2->GetOrbitalTime(); |
| 3129 |
pkt2 = ph2->GetCounter(); |
pkt2 = ph2->GetCounter(); |
| 3130 |
// |
// |
| 3131 |
if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
| 3132 |
// |
// |
| 3133 |
} else { |
} else { |
| 3134 |
// |
// |
| 3159 |
// |
// |
| 3160 |
if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); |
if ( IsDebug() ) printf(" The trk calibration2 at obt %i pkt %i t2 is %i is good \n",obt2,pkt2,t2); |
| 3161 |
// |
// |
| 3162 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
| 3163 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
| 3164 |
|
valid = valid & valid2; |
| 3165 |
|
// |
| 3166 |
// Handle good calib |
// Handle good calib |
| 3167 |
// |
// |
| 3168 |
this->HandleTRK_CALIB(true,true); |
this->HandleTRK_CALIB(true,true); |
| 4431 |
// |
// |
| 4432 |
}; |
}; |
| 4433 |
}; |
}; |
| 4434 |
|
|
| 4435 |
|
/** |
| 4436 |
|
* |
| 4437 |
|
* Rearrange calibration tables |
| 4438 |
|
* |
| 4439 |
|
**/ |
| 4440 |
|
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
| 4441 |
|
|
| 4442 |
|
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
| 4443 |
|
UInt_t timeaftercalib=120000; //2000; |
| 4444 |
|
// ---------- |
| 4445 |
|
// Check CRCs |
| 4446 |
|
// ---------- |
| 4447 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
| 4448 |
|
if( caltrk->crc_hcal[ipkt] )return 0; // :-( |
| 4449 |
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( |
| 4450 |
|
} |
| 4451 |
|
// ----------------------- |
| 4452 |
|
// Check missing packets: |
| 4453 |
|
// ----------------------- |
| 4454 |
|
// Readout order: |
| 4455 |
|
// ------------------ |
| 4456 |
|
// DSP packet board |
| 4457 |
|
// ------------------ |
| 4458 |
|
// 12 0 1 |
| 4459 |
|
// 10 1 1 |
| 4460 |
|
// 8 2 1 |
| 4461 |
|
// 4 3 1 |
| 4462 |
|
// 6 4 1 |
| 4463 |
|
// 2 5 1 |
| 4464 |
|
// ------------------ |
| 4465 |
|
// 11 0 2 |
| 4466 |
|
// 9 1 2 |
| 4467 |
|
// 7 2 2 |
| 4468 |
|
// 3 3 2 |
| 4469 |
|
// 5 4 2 |
| 4470 |
|
// 1 5 2 |
| 4471 |
|
// ------------------ |
| 4472 |
|
// ------------------------------------------------- |
| 4473 |
|
// Check if it is first or second calibration packet |
| 4474 |
|
// ------------------------------------------------- |
| 4475 |
|
UInt_t build=0; |
| 4476 |
|
TString classname = caltrk->GetName(); |
| 4477 |
|
UInt_t base=0; |
| 4478 |
|
UInt_t mask=0; |
| 4479 |
|
if(classname.Contains("CalibTrk1Event")){ |
| 4480 |
|
base=12; |
| 4481 |
|
mask=0x03F000; |
| 4482 |
|
} |
| 4483 |
|
if(classname.Contains("CalibTrk2Event")){ |
| 4484 |
|
base=18; |
| 4485 |
|
mask=0xFC0000; |
| 4486 |
|
} |
| 4487 |
|
// ------------------------------------------------- |
| 4488 |
|
// Count number of packets and set build variable |
| 4489 |
|
// ------------------------------------------------- |
| 4490 |
|
Int_t npkts=0; |
| 4491 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
| 4492 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
| 4493 |
|
npkts++; |
| 4494 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
| 4495 |
|
} |
| 4496 |
|
} |
| 4497 |
|
// if( npkts==6 )return 1; // :-) |
| 4498 |
|
|
| 4499 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
| 4500 |
|
|
| 4501 |
|
// ----------------------------------------------- |
| 4502 |
|
// If missing packets: check the acq configuration |
| 4503 |
|
// (some DSPs might be excluded from acquisition) |
| 4504 |
|
// ----------------------------------------------- |
| 4505 |
|
|
| 4506 |
|
// ----------------------------------------------- |
| 4507 |
|
// retrieve the first run header after calib |
| 4508 |
|
// ----------------------------------------------- |
| 4509 |
|
PacketType *pctp; |
| 4510 |
|
EventCounter *cod; |
| 4511 |
|
cod = eh->GetCounter(); |
| 4512 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
| 4513 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
| 4514 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
| 4515 |
|
if( rh->GetEntries() == irun ){ |
| 4516 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
| 4517 |
|
return 0; // :-( |
| 4518 |
|
} |
| 4519 |
|
|
| 4520 |
|
RunHeaderEvent *run = 0; |
| 4521 |
|
EventHeader *hrun = 0; |
| 4522 |
|
rh->SetBranchAddress("RunHeader", &run); |
| 4523 |
|
rh->SetBranchAddress("Header", &hrun); |
| 4524 |
|
rh->GetEntry(irun); |
| 4525 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
| 4526 |
|
|
| 4527 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
| 4528 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
| 4529 |
|
return 0; // :-( |
| 4530 |
|
} |
| 4531 |
|
|
| 4532 |
|
if( !run->RM_ACQ_AFTER_CALIB ){ |
| 4533 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
| 4534 |
|
return 0; // :-( |
| 4535 |
|
} |
| 4536 |
|
|
| 4537 |
|
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
| 4538 |
|
if( dtime > timeaftercalib ){ |
| 4539 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
| 4540 |
|
return 0; // :-( |
| 4541 |
|
} |
| 4542 |
|
|
| 4543 |
|
|
| 4544 |
|
|
| 4545 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
| 4546 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
| 4547 |
|
return 0; // :-( |
| 4548 |
|
} |
| 4549 |
|
return 1; // :-) |
| 4550 |
|
|
| 4551 |
|
} |
| 4552 |
|
|
| 4553 |
|
/** |
| 4554 |
|
* |
| 4555 |
|
* Check the DB (only for overlapping runs at the moment) |
| 4556 |
|
* |
| 4557 |
|
**/ |
| 4558 |
|
UInt_t PamelaDBOperations::Check(){ |
| 4559 |
|
// |
| 4560 |
|
UInt_t test = 0; |
| 4561 |
|
// |
| 4562 |
|
UInt_t thisrht = 0; |
| 4563 |
|
UInt_t thisrtt = 0; |
| 4564 |
|
UInt_t thisid = 0; |
| 4565 |
|
UInt_t prevrht = 0; |
| 4566 |
|
UInt_t prevrtt = 0; |
| 4567 |
|
UInt_t previd = 0; |
| 4568 |
|
// |
| 4569 |
|
UInt_t prevl0id = 0; |
| 4570 |
|
UInt_t thisl0id = 0; |
| 4571 |
|
// |
| 4572 |
|
stringstream oss; |
| 4573 |
|
TSQLResult *result = 0; |
| 4574 |
|
TSQLRow *row = 0; |
| 4575 |
|
TSQLResult *result2 = 0; |
| 4576 |
|
TSQLRow *row2 = 0; |
| 4577 |
|
oss.str(""); |
| 4578 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; |
| 4579 |
|
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
| 4580 |
|
result = conn->Query(oss.str().c_str()); |
| 4581 |
|
// |
| 4582 |
|
if ( !result ) throw -4;; |
| 4583 |
|
// |
| 4584 |
|
row = result->Next(); |
| 4585 |
|
// |
| 4586 |
|
while ( row ){ |
| 4587 |
|
thisid = (UInt_t)atoll(row->GetField(0)); |
| 4588 |
|
thisl0id = (UInt_t)atoll(row->GetField(1)); |
| 4589 |
|
thisrht = (UInt_t)atoll(row->GetField(2)); |
| 4590 |
|
thisrtt = (UInt_t)atoll(row->GetField(3)); |
| 4591 |
|
// |
| 4592 |
|
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
| 4593 |
|
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
| 4594 |
|
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
| 4595 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
| 4596 |
|
printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
| 4597 |
|
TString prevf = ""; |
| 4598 |
|
TString thisf = ""; |
| 4599 |
|
oss.str(""); |
| 4600 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
| 4601 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4602 |
|
if ( !result2 ) throw -4;; |
| 4603 |
|
row2 = result2->Next(); |
| 4604 |
|
prevf = (TString)row2->GetField(0); |
| 4605 |
|
oss.str(""); |
| 4606 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
| 4607 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4608 |
|
if ( !result2 ) throw -4;; |
| 4609 |
|
row2 = result2->Next(); |
| 4610 |
|
thisf = (TString)row2->GetField(0); |
| 4611 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
| 4612 |
|
test = 1; |
| 4613 |
|
}; |
| 4614 |
|
// |
| 4615 |
|
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
| 4616 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
| 4617 |
|
printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
| 4618 |
|
TString prevf = ""; |
| 4619 |
|
TString thisf = ""; |
| 4620 |
|
oss.str(""); |
| 4621 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
| 4622 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4623 |
|
if ( !result2 ) throw -4;; |
| 4624 |
|
row2 = result2->Next(); |
| 4625 |
|
prevf = (TString)row2->GetField(0); |
| 4626 |
|
oss.str(""); |
| 4627 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
| 4628 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4629 |
|
if ( !result2 ) throw -4;; |
| 4630 |
|
row2 = result2->Next(); |
| 4631 |
|
thisf = (TString)row2->GetField(0); |
| 4632 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
| 4633 |
|
test = 1; |
| 4634 |
|
}; |
| 4635 |
|
// |
| 4636 |
|
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
| 4637 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
| 4638 |
|
printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
| 4639 |
|
TString prevf = ""; |
| 4640 |
|
TString thisf = ""; |
| 4641 |
|
oss.str(""); |
| 4642 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
| 4643 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4644 |
|
if ( !result2 ) throw -4;; |
| 4645 |
|
row2 = result2->Next(); |
| 4646 |
|
prevf = (TString)row2->GetField(0); |
| 4647 |
|
oss.str(""); |
| 4648 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
| 4649 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4650 |
|
if ( !result2 ) throw -4;; |
| 4651 |
|
row2 = result2->Next(); |
| 4652 |
|
thisf = (TString)row2->GetField(0); |
| 4653 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
| 4654 |
|
test = 1; |
| 4655 |
|
}; |
| 4656 |
|
|
| 4657 |
|
// |
| 4658 |
|
prevrht = thisrht; |
| 4659 |
|
prevrtt = thisrtt; |
| 4660 |
|
previd = thisid; |
| 4661 |
|
prevl0id = thisl0id; |
| 4662 |
|
row = result->Next(); |
| 4663 |
|
}; |
| 4664 |
|
// |
| 4665 |
|
return(test); |
| 4666 |
|
// |
| 4667 |
|
}; |