| 56 |
* @param debug debug flag. |
* @param debug debug flag. |
| 57 |
* @param tlefilename ascii file with TLE 3 line elements. |
* @param tlefilename ascii file with TLE 3 line elements. |
| 58 |
*/ |
*/ |
| 59 |
PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename){ |
PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput){ |
| 60 |
// |
// |
| 61 |
// |
// |
| 62 |
SetConnection(host,user,password); |
SetConnection(host,user,password); |
| 79 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
| 80 |
if( INSERT_ROOT ){ |
if( INSERT_ROOT ){ |
| 81 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
| 82 |
this->SetOrbitNo(); |
this->SetOrbitNo(dwinput); |
| 83 |
file = TFile::Open(this->GetRootName().Data()); |
file = TFile::Open(this->GetRootName().Data()); |
| 84 |
} else { |
} else { |
| 85 |
this->SetRootName(""); |
this->SetRootName(""); |
| 215 |
/** |
/** |
| 216 |
* Store the downlink orbit number from filename. |
* Store the downlink orbit number from filename. |
| 217 |
*/ |
*/ |
| 218 |
void PamelaDBOperations::SetOrbitNo(){ |
void PamelaDBOperations::SetOrbitNo(UInt_t dwinput){ |
| 219 |
dworbit = 0; |
dworbit = 0; |
| 220 |
|
// |
| 221 |
|
if ( dwinput ){ |
| 222 |
|
dworbit = dwinput; |
| 223 |
|
if ( IsDebug() ) printf(" Downlink orbit given by hand: %i \n",dworbit); |
| 224 |
|
return; |
| 225 |
|
}; |
| 226 |
|
// |
| 227 |
TString name = this->GetRootFile(); |
TString name = this->GetRootFile(); |
| 228 |
Int_t nlength = name.Length(); |
Int_t nlength = name.Length(); |
| 229 |
if ( nlength < 5 ) return; |
if ( nlength < 5 ) return; |
| 280 |
oss << "SELECT ID FROM GL_RAW WHERE " |
oss << "SELECT ID FROM GL_RAW WHERE " |
| 281 |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
<< " PATH = '" << this->GetRawPath().Data() << "' AND " |
| 282 |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
<< " NAME = '" << this->GetRawFile().Data() << "' "; |
| 283 |
|
|
| 284 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 285 |
if ( result == NULL ) throw -4; |
if ( result == NULL ) throw -4; |
| 286 |
row = result->Next(); |
row = result->Next(); |
| 368 |
if ( !nevent ) return(2); |
if ( !nevent ) return(2); |
| 369 |
// |
// |
| 370 |
if ( nevent < 2 ) return(4); |
if ( nevent < 2 ) return(4); |
| 371 |
|
if ( nevent < jump ) jump = 1; |
| 372 |
|
// if ( nevent < jump ) jump = int(nevent/10); |
| 373 |
|
// if ( !jump ) jump = 1; |
| 374 |
// |
// |
| 375 |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) ){ |
if ( (PKT(pktlast) < PKT(pktfirst) && OBT(obtlast) < OBT(obtfirst)) || (labs(PKT(pktlast)-PKT(pktfirst))<deltapkt && labs(OBT(obtlast)-OBT(obtfirst))<deltaobt) && nevent > deltapkt ){ |
| 376 |
// |
// |
| 377 |
|
if ( IsDebug() ) printf(" starting jump %i \n",jump); |
| 378 |
// go back |
// go back |
| 379 |
zomp = nevent - 2; |
zomp = nevent - 2; |
| 380 |
// |
// |
| 450 |
Long64_t pkth = 0LL; |
Long64_t pkth = 0LL; |
| 451 |
Long64_t obth = 0LL; |
Long64_t obth = 0LL; |
| 452 |
// |
// |
| 453 |
|
if ( rhev || rtev ){ |
| 454 |
|
|
| 455 |
|
|
| 456 |
T->GetEntry(upperentry); |
T->GetEntry(upperentry); |
| 457 |
code = eh->GetCounter(); |
code = eh->GetCounter(); |
| 458 |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
Int_t lasttrail = code->Get(pctp->RunTrailer); |
| 659 |
}; |
}; |
| 660 |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
if ( IsDebug() ) printf(" rtev after %i pt %lld upperp %lld ot %lld uppero %lld \n",rtev,pktt,upperpkt,obtt,upperobt); |
| 661 |
// |
// |
| 662 |
|
|
| 663 |
|
|
| 664 |
|
}; |
| 665 |
|
// |
| 666 |
if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry); |
if ( IsDebug() ) printf(" Upper limits are: OBT %lld pkt_num %lld upper entry %i \n",upperobt,upperpkt,upperentry); |
| 667 |
// |
// |
| 668 |
return(0); |
return(0); |
| 797 |
if( !conn ) throw -1; |
if( !conn ) throw -1; |
| 798 |
bool connect = conn->IsConnected(); |
bool connect = conn->IsConnected(); |
| 799 |
if( !connect ) throw -1; |
if( !connect ) throw -1; |
| 800 |
|
// |
| 801 |
|
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()); |
| 802 |
|
// |
| 803 |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
if ( !dworbit && strcmp(this->GetRootName().Data(),"") ) throw -27; |
| 804 |
// |
// |
| 805 |
// set DB timezone to UTC |
// set DB timezone to UTC |
| 811 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
| 812 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
| 813 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
| 814 |
|
oss.str(""); |
| 815 |
|
oss << "SET wait_timeout=173000;"; |
| 816 |
|
conn->Query(oss.str().c_str()); |
| 817 |
// |
// |
| 818 |
}; |
}; |
| 819 |
|
|
| 1398 |
// |
// |
| 1399 |
Int_t sgn = 0; |
Int_t sgn = 0; |
| 1400 |
// |
// |
| 1401 |
if ( !found ){ |
if ( !found && !BOOTNO ){ |
| 1402 |
throw -29; |
throw -29; |
| 1403 |
} else { |
} else { |
| 1404 |
if ( afound ){ |
if ( afound ){ |
| 1732 |
delete result; |
delete result; |
| 1733 |
// |
// |
| 1734 |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); |
| 1735 |
|
if ( !signal && IsDebug() ) printf(" The run existed and was deleted, fill the DB \n"); |
| 1736 |
return(signal); |
return(signal); |
| 1737 |
}; |
}; |
| 1738 |
|
|
| 1846 |
// |
// |
| 1847 |
} else { |
} else { |
| 1848 |
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"); |
| 1849 |
|
return; |
| 1850 |
}; |
}; |
| 1851 |
// |
// |
| 1852 |
// |
// |
| 4449 |
// |
// |
| 4450 |
}; |
}; |
| 4451 |
}; |
}; |
| 4452 |
|
|
| 4453 |
/** |
/** |
| 4454 |
* |
* |
| 4455 |
* Rearrange calibration tables |
* Rearrange calibration tables |
| 4567 |
return 1; // :-) |
return 1; // :-) |
| 4568 |
|
|
| 4569 |
} |
} |
| 4570 |
|
|
| 4571 |
|
/** |
| 4572 |
|
* |
| 4573 |
|
* Check the DB (only for overlapping runs at the moment) |
| 4574 |
|
* |
| 4575 |
|
**/ |
| 4576 |
|
UInt_t PamelaDBOperations::Check(){ |
| 4577 |
|
// |
| 4578 |
|
UInt_t test = 0; |
| 4579 |
|
// |
| 4580 |
|
UInt_t thisrht = 0; |
| 4581 |
|
UInt_t thisrtt = 0; |
| 4582 |
|
UInt_t thisid = 0; |
| 4583 |
|
UInt_t prevrht = 0; |
| 4584 |
|
UInt_t prevrtt = 0; |
| 4585 |
|
UInt_t previd = 0; |
| 4586 |
|
// |
| 4587 |
|
UInt_t prevl0id = 0; |
| 4588 |
|
UInt_t thisl0id = 0; |
| 4589 |
|
// |
| 4590 |
|
stringstream oss; |
| 4591 |
|
TSQLResult *result = 0; |
| 4592 |
|
TSQLRow *row = 0; |
| 4593 |
|
TSQLResult *result2 = 0; |
| 4594 |
|
TSQLRow *row2 = 0; |
| 4595 |
|
oss.str(""); |
| 4596 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; |
| 4597 |
|
// oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; |
| 4598 |
|
result = conn->Query(oss.str().c_str()); |
| 4599 |
|
// |
| 4600 |
|
if ( !result ) throw -4;; |
| 4601 |
|
// |
| 4602 |
|
row = result->Next(); |
| 4603 |
|
// |
| 4604 |
|
while ( row ){ |
| 4605 |
|
thisid = (UInt_t)atoll(row->GetField(0)); |
| 4606 |
|
thisl0id = (UInt_t)atoll(row->GetField(1)); |
| 4607 |
|
thisrht = (UInt_t)atoll(row->GetField(2)); |
| 4608 |
|
thisrtt = (UInt_t)atoll(row->GetField(3)); |
| 4609 |
|
// |
| 4610 |
|
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
| 4611 |
|
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
| 4612 |
|
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
| 4613 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
| 4614 |
|
printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
| 4615 |
|
TString prevf = ""; |
| 4616 |
|
TString thisf = ""; |
| 4617 |
|
oss.str(""); |
| 4618 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
| 4619 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4620 |
|
if ( !result2 ) throw -4;; |
| 4621 |
|
row2 = result2->Next(); |
| 4622 |
|
prevf = (TString)row2->GetField(0); |
| 4623 |
|
oss.str(""); |
| 4624 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
| 4625 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4626 |
|
if ( !result2 ) throw -4;; |
| 4627 |
|
row2 = result2->Next(); |
| 4628 |
|
thisf = (TString)row2->GetField(0); |
| 4629 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
| 4630 |
|
test = 1; |
| 4631 |
|
}; |
| 4632 |
|
// |
| 4633 |
|
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
| 4634 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
| 4635 |
|
printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
| 4636 |
|
TString prevf = ""; |
| 4637 |
|
TString thisf = ""; |
| 4638 |
|
oss.str(""); |
| 4639 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
| 4640 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4641 |
|
if ( !result2 ) throw -4;; |
| 4642 |
|
row2 = result2->Next(); |
| 4643 |
|
prevf = (TString)row2->GetField(0); |
| 4644 |
|
oss.str(""); |
| 4645 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
| 4646 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4647 |
|
if ( !result2 ) throw -4;; |
| 4648 |
|
row2 = result2->Next(); |
| 4649 |
|
thisf = (TString)row2->GetField(0); |
| 4650 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
| 4651 |
|
test = 1; |
| 4652 |
|
}; |
| 4653 |
|
// |
| 4654 |
|
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
| 4655 |
|
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
| 4656 |
|
printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
| 4657 |
|
TString prevf = ""; |
| 4658 |
|
TString thisf = ""; |
| 4659 |
|
oss.str(""); |
| 4660 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
| 4661 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4662 |
|
if ( !result2 ) throw -4;; |
| 4663 |
|
row2 = result2->Next(); |
| 4664 |
|
prevf = (TString)row2->GetField(0); |
| 4665 |
|
oss.str(""); |
| 4666 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)thisl0id <<";"; |
| 4667 |
|
result2 = conn->Query(oss.str().c_str()); |
| 4668 |
|
if ( !result2 ) throw -4;; |
| 4669 |
|
row2 = result2->Next(); |
| 4670 |
|
thisf = (TString)row2->GetField(0); |
| 4671 |
|
if ( IsDebug() ) printf(" ==> files %s and %s \n",prevf.Data(),thisf.Data()); |
| 4672 |
|
test = 1; |
| 4673 |
|
}; |
| 4674 |
|
|
| 4675 |
|
// |
| 4676 |
|
prevrht = thisrht; |
| 4677 |
|
prevrtt = thisrtt; |
| 4678 |
|
previd = thisid; |
| 4679 |
|
prevl0id = thisl0id; |
| 4680 |
|
row = result->Next(); |
| 4681 |
|
}; |
| 4682 |
|
// |
| 4683 |
|
return(test); |
| 4684 |
|
// |
| 4685 |
|
}; |