1707 |
delete result; |
delete result; |
1708 |
// |
// |
1709 |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
1710 |
|
if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n"); |
1711 |
return(signal); |
return(signal); |
1712 |
}; |
}; |
1713 |
|
|
1821 |
// |
// |
1822 |
} else { |
} else { |
1823 |
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"); |
1824 |
|
return; |
1825 |
}; |
}; |
1826 |
// |
// |
1827 |
// |
// |
3094 |
pkt1 = ph1->GetCounter(); |
pkt1 = ph1->GetCounter(); |
3095 |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
3096 |
// |
// |
3097 |
valid = 1; |
// valid = 1; |
3098 |
// |
// // |
3099 |
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 |
3100 |
// |
// |
3101 |
// |
// |
3102 |
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) ){ |
3103 |
// |
// |
3104 |
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); |
3105 |
|
// |
3106 |
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
3107 |
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
3108 |
// |
// |
3109 |
// Do we have the second calibration packet? |
// Do we have the second calibration packet? |
3110 |
// |
// |
3121 |
obt2 = ph2->GetOrbitalTime(); |
obt2 = ph2->GetOrbitalTime(); |
3122 |
pkt2 = ph2->GetCounter(); |
pkt2 = ph2->GetCounter(); |
3123 |
// |
// |
3124 |
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 |
3125 |
// |
// |
3126 |
} else { |
} else { |
3127 |
// |
// |
3152 |
// |
// |
3153 |
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); |
3154 |
// |
// |
3155 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
3156 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
3157 |
|
valid = valid & valid2; |
3158 |
|
// |
3159 |
// Handle good calib |
// Handle good calib |
3160 |
// |
// |
3161 |
this->HandleTRK_CALIB(true,true); |
this->HandleTRK_CALIB(true,true); |
4424 |
// |
// |
4425 |
}; |
}; |
4426 |
}; |
}; |
4427 |
|
|
4428 |
|
/** |
4429 |
|
* |
4430 |
|
* Rearrange calibration tables |
4431 |
|
* |
4432 |
|
**/ |
4433 |
|
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
4434 |
|
|
4435 |
|
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
4436 |
|
UInt_t timeaftercalib=120000; //2000; |
4437 |
|
// ---------- |
4438 |
|
// Check CRCs |
4439 |
|
// ---------- |
4440 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
4441 |
|
if( caltrk->crc_hcal[ipkt] )return 0; // :-( |
4442 |
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( |
4443 |
|
} |
4444 |
|
// ----------------------- |
4445 |
|
// Check missing packets: |
4446 |
|
// ----------------------- |
4447 |
|
// Readout order: |
4448 |
|
// ------------------ |
4449 |
|
// DSP packet board |
4450 |
|
// ------------------ |
4451 |
|
// 12 0 1 |
4452 |
|
// 10 1 1 |
4453 |
|
// 8 2 1 |
4454 |
|
// 4 3 1 |
4455 |
|
// 6 4 1 |
4456 |
|
// 2 5 1 |
4457 |
|
// ------------------ |
4458 |
|
// 11 0 2 |
4459 |
|
// 9 1 2 |
4460 |
|
// 7 2 2 |
4461 |
|
// 3 3 2 |
4462 |
|
// 5 4 2 |
4463 |
|
// 1 5 2 |
4464 |
|
// ------------------ |
4465 |
|
// ------------------------------------------------- |
4466 |
|
// Check if it is first or second calibration packet |
4467 |
|
// ------------------------------------------------- |
4468 |
|
UInt_t build=0; |
4469 |
|
TString classname = caltrk->GetName(); |
4470 |
|
UInt_t base=0; |
4471 |
|
UInt_t mask=0; |
4472 |
|
if(classname.Contains("CalibTrk1Event")){ |
4473 |
|
base=12; |
4474 |
|
mask=0x03F000; |
4475 |
|
} |
4476 |
|
if(classname.Contains("CalibTrk2Event")){ |
4477 |
|
base=18; |
4478 |
|
mask=0xFC0000; |
4479 |
|
} |
4480 |
|
// ------------------------------------------------- |
4481 |
|
// Count number of packets and set build variable |
4482 |
|
// ------------------------------------------------- |
4483 |
|
Int_t npkts=0; |
4484 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
4485 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
4486 |
|
npkts++; |
4487 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
4488 |
|
} |
4489 |
|
} |
4490 |
|
// if( npkts==6 )return 1; // :-) |
4491 |
|
|
4492 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
4493 |
|
|
4494 |
|
// ----------------------------------------------- |
4495 |
|
// If missing packets: check the acq configuration |
4496 |
|
// (some DSPs might be excluded from acquisition) |
4497 |
|
// ----------------------------------------------- |
4498 |
|
|
4499 |
|
// ----------------------------------------------- |
4500 |
|
// retrieve the first run header after calib |
4501 |
|
// ----------------------------------------------- |
4502 |
|
PacketType *pctp; |
4503 |
|
EventCounter *cod; |
4504 |
|
cod = eh->GetCounter(); |
4505 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
4506 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
4507 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
4508 |
|
if( rh->GetEntries() == irun ){ |
4509 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
4510 |
|
return 0; // :-( |
4511 |
|
} |
4512 |
|
|
4513 |
|
RunHeaderEvent *run = 0; |
4514 |
|
EventHeader *hrun = 0; |
4515 |
|
rh->SetBranchAddress("RunHeader", &run); |
4516 |
|
rh->SetBranchAddress("Header", &hrun); |
4517 |
|
rh->GetEntry(irun); |
4518 |
|
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
4519 |
|
|
4520 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
4521 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
4522 |
|
return 0; // :-( |
4523 |
|
} |
4524 |
|
|
4525 |
|
if( !run->RM_ACQ_AFTER_CALIB ){ |
4526 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
4527 |
|
return 0; // :-( |
4528 |
|
} |
4529 |
|
|
4530 |
|
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
4531 |
|
if( dtime > timeaftercalib ){ |
4532 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
4533 |
|
return 0; // :-( |
4534 |
|
} |
4535 |
|
|
4536 |
|
|
4537 |
|
|
4538 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
4539 |
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
4540 |
|
return 0; // :-( |
4541 |
|
} |
4542 |
|
return 1; // :-) |
4543 |
|
|
4544 |
|
} |
4545 |
|
|
4546 |
|
/** |
4547 |
|
* |
4548 |
|
* Check the DB (only for overlapping runs at the moment) |
4549 |
|
* |
4550 |
|
**/ |
4551 |
|
UInt_t PamelaDBOperations::Check(){ |
4552 |
|
// |
4553 |
|
UInt_t test = 0; |
4554 |
|
// |
4555 |
|
UInt_t thisrht = 0; |
4556 |
|
UInt_t thisrtt = 0; |
4557 |
|
UInt_t thisid = 0; |
4558 |
|
UInt_t prevrht = 0; |
4559 |
|
UInt_t prevrtt = 0; |
4560 |
|
UInt_t previd = 0; |
4561 |
|
// |
4562 |
|
UInt_t prevl0id = 0; |
4563 |
|
UInt_t thisl0id = 0; |
4564 |
|
// |
4565 |
|
stringstream oss; |
4566 |
|
TSQLResult *result = 0; |
4567 |
|
TSQLRow *row = 0; |
4568 |
|
TSQLResult *result2 = 0; |
4569 |
|
TSQLRow *row2 = 0; |
4570 |
|
oss.str(""); |
4571 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; |
4572 |
|
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
4573 |
|
result = conn->Query(oss.str().c_str()); |
4574 |
|
// |
4575 |
|
if ( !result ) throw -4;; |
4576 |
|
// |
4577 |
|
row = result->Next(); |
4578 |
|
// |
4579 |
|
while ( row ){ |
4580 |
|
thisid = (UInt_t)atoll(row->GetField(0)); |
4581 |
|
thisl0id = (UInt_t)atoll(row->GetField(1)); |
4582 |
|
thisrht = (UInt_t)atoll(row->GetField(2)); |
4583 |
|
thisrtt = (UInt_t)atoll(row->GetField(3)); |
4584 |
|
// |
4585 |
|
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
4586 |
|
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
4587 |
|
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
4588 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4589 |
|
printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
4590 |
|
TString prevf = ""; |
4591 |
|
TString thisf = ""; |
4592 |
|
oss.str(""); |
4593 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4594 |
|
result2 = conn->Query(oss.str().c_str()); |
4595 |
|
if ( !result2 ) throw -4;; |
4596 |
|
row2 = result2->Next(); |
4597 |
|
prevf = (TString)row2->GetField(0); |
4598 |
|
oss.str(""); |
4599 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4600 |
|
result2 = conn->Query(oss.str().c_str()); |
4601 |
|
if ( !result2 ) throw -4;; |
4602 |
|
row2 = result2->Next(); |
4603 |
|
thisf = (TString)row2->GetField(0); |
4604 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4605 |
|
test = 1; |
4606 |
|
}; |
4607 |
|
// |
4608 |
|
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
4609 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4610 |
|
printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
4611 |
|
TString prevf = ""; |
4612 |
|
TString thisf = ""; |
4613 |
|
oss.str(""); |
4614 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4615 |
|
result2 = conn->Query(oss.str().c_str()); |
4616 |
|
if ( !result2 ) throw -4;; |
4617 |
|
row2 = result2->Next(); |
4618 |
|
prevf = (TString)row2->GetField(0); |
4619 |
|
oss.str(""); |
4620 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4621 |
|
result2 = conn->Query(oss.str().c_str()); |
4622 |
|
if ( !result2 ) throw -4;; |
4623 |
|
row2 = result2->Next(); |
4624 |
|
thisf = (TString)row2->GetField(0); |
4625 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4626 |
|
test = 1; |
4627 |
|
}; |
4628 |
|
// |
4629 |
|
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
4630 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4631 |
|
printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
4632 |
|
TString prevf = ""; |
4633 |
|
TString thisf = ""; |
4634 |
|
oss.str(""); |
4635 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4636 |
|
result2 = conn->Query(oss.str().c_str()); |
4637 |
|
if ( !result2 ) throw -4;; |
4638 |
|
row2 = result2->Next(); |
4639 |
|
prevf = (TString)row2->GetField(0); |
4640 |
|
oss.str(""); |
4641 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
4642 |
|
result2 = conn->Query(oss.str().c_str()); |
4643 |
|
if ( !result2 ) throw -4;; |
4644 |
|
row2 = result2->Next(); |
4645 |
|
thisf = (TString)row2->GetField(0); |
4646 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
4647 |
|
test = 1; |
4648 |
|
}; |
4649 |
|
|
4650 |
|
// |
4651 |
|
prevrht = thisrht; |
4652 |
|
prevrtt = thisrtt; |
4653 |
|
previd = thisid; |
4654 |
|
prevl0id = thisl0id; |
4655 |
|
row = result->Next(); |
4656 |
|
}; |
4657 |
|
// |
4658 |
|
return(test); |
4659 |
|
// |
4660 |
|
}; |