58 |
* @param debug debug flag. |
* @param debug debug flag. |
59 |
* @param tlefilename ascii file with TLE 3 line elements. |
* @param tlefilename ascii file with TLE 3 line elements. |
60 |
*/ |
*/ |
61 |
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, Bool_t staticp, Bool_t gpamela){ |
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, Bool_t staticp, Bool_t gpamela, Bool_t keepenv){ |
62 |
// |
// |
63 |
chewbacca = false; |
chewbacca = false; |
64 |
chminentry = 0; |
chminentry = 0; |
76 |
// |
// |
77 |
}; |
}; |
78 |
// |
// |
79 |
|
KEEPENV = false; |
80 |
|
if ( keepenv ) KEEPENV=true; |
81 |
STATIC=false; |
STATIC=false; |
82 |
if ( staticp ) STATIC=true; |
if ( staticp ) STATIC=true; |
83 |
// |
// |
101 |
if (INSERT_RAW) SetRawName(filerawname); |
if (INSERT_RAW) SetRawName(filerawname); |
102 |
// |
// |
103 |
INSERT_ROOT = !filerootname.IsNull(); |
INSERT_ROOT = !filerootname.IsNull(); |
104 |
|
if ( INSERT_ROOT ) this->SetRootName(filerootname); |
105 |
this->SetOrbitNo(dwinput); |
this->SetOrbitNo(dwinput); |
106 |
// |
// |
107 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
141 |
TString chfile; |
TString chfile; |
142 |
UInt_t ridn = 0; |
UInt_t ridn = 0; |
143 |
qu.str(""); |
qu.str(""); |
144 |
qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; |
qu << "SELECT ROOT_ID_N,PKT_NUMBER_INIT,PKT_NUMBER_FINAL,PKT_OBT_INIT,PKT_OBT_FINAL,INSERTED_BY from ROOT_TABLE_MERGING where ID_N=" << chID << ";"; |
145 |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
146 |
result = conn->Query(qu.str().c_str()); |
result = conn->Query(qu.str().c_str()); |
147 |
if ( result ){ |
if ( result ){ |
152 |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
153 |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
154 |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
155 |
|
chiby = (TString)(row->GetField(5)); |
156 |
} else { |
} else { |
157 |
throw -84; |
throw -84; |
158 |
}; |
}; |
167 |
if ( result2 ){ |
if ( result2 ){ |
168 |
row2 = result2->Next(); |
row2 = result2->Next(); |
169 |
if ( row2 ){ |
if ( row2 ){ |
170 |
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
if ( KEEPENV ){ |
171 |
|
chpath = (TString)(row2->GetField(0))+'/'; |
172 |
|
} else { |
173 |
|
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
174 |
|
}; |
175 |
chfile = (TString)(row2->GetField(1)); |
chfile = (TString)(row2->GetField(1)); |
176 |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
177 |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
190 |
throw -85; |
throw -85; |
191 |
}; |
}; |
192 |
filerootname = chpath + chfile;// + ".root"; |
filerootname = chpath + chfile;// + ".root"; |
|
if ( debug ) printf(" chewbacca: filename is %s \n",filerootname.Data()); |
|
193 |
}; |
}; |
194 |
this->SetRootName(filerootname); |
this->SetRootName(filerootname); |
|
file = TFile::Open(this->GetRootName().Data()); |
|
|
} else { |
|
|
this->SetRootName(""); |
|
195 |
}; |
}; |
196 |
|
if ( debug ) printf(" Filename is %s \n",filerootname.Data()); |
197 |
|
file = TFile::Open(this->GetRootName().Data()); |
198 |
|
// } else { |
199 |
|
// this->SetRootName(""); |
200 |
|
// this->SetRootName(filerootname); |
201 |
|
// }; |
202 |
} |
} |
203 |
|
|
204 |
// |
// |
398 |
return; |
return; |
399 |
}; |
}; |
400 |
// |
// |
401 |
TString name = this->GetRootFile(); |
if ( !chewbacca ){ |
402 |
Int_t nlength = name.Length(); |
TString name = this->GetRootFile(); |
403 |
if ( nlength < 5 ) return; |
Int_t nlength = name.Length(); |
404 |
TString dwo = 0; |
if ( nlength < 5 ){ |
405 |
for (Int_t i = 0; i<5; i++){ |
if ( IsDebug() ) printf(" Agh problems determining the orbit number! name = %s \n",name.Data()); |
406 |
dwo.Append(name[i],1); |
return; |
407 |
}; |
}; |
408 |
if ( dwo.IsDigit() ){ |
TString dwo = 0; |
409 |
dworbit = (UInt_t)dwo.Atoi(); |
for (Int_t i = 0; i<5; i++){ |
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
410 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
411 |
}; |
}; |
412 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
413 |
|
dworbit = (UInt_t)dwo.Atoi(); |
414 |
|
} else { |
415 |
|
dwo=""; |
416 |
|
for (Int_t i = 8; i<13; i++){ |
417 |
|
dwo.Append(name[i],1); |
418 |
|
}; |
419 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
420 |
|
}; |
421 |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
422 |
}; |
}; |
|
if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
423 |
return; |
return; |
424 |
}; |
}; |
425 |
|
|
450 |
|
|
451 |
TString PamelaDBOperations::GetRootPath(){ |
TString PamelaDBOperations::GetRootPath(){ |
452 |
if ( STATIC ){ |
if ( STATIC ){ |
453 |
return((TString)gSystem->DirName(filerootname.Data())+'/'); |
return((TString)gSystem->DirName(this->GetRootName().Data())+'/'); |
454 |
} else { |
} else { |
455 |
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
if ( KEEPENV ){ |
456 |
|
return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/'); |
457 |
|
} else { |
458 |
|
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
459 |
|
}; |
460 |
}; |
}; |
461 |
}; |
}; |
462 |
|
|
668 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
669 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
670 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
671 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
672 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
673 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
674 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
675 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
676 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
678 |
} else { |
} else { |
679 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
680 |
}; |
}; |
681 |
if ( (!(it%1000) || abs((int)pktlast - (int)chpktmax)<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); |
if ( (!(it%1000) || abs((int)(PKT(pktlast) - PKT(chpktmax)))<1000 ) && debug ) printf(" look for up %i %i %i nevent %u (nevent-1-it) %i \n",it,pktlast,chpktmax,nevent,(Int_t)(nevent-1-it)); |
682 |
it += tjump; |
it += tjump; |
683 |
}; |
}; |
684 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
702 |
tjump = 50000; |
tjump = 50000; |
703 |
//tjump = 100; |
//tjump = 100; |
704 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
705 |
pktlast = 0; |
// pktlast = 0; |
706 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
707 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
708 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
709 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
710 |
T->GetEntry(it); |
T->GetEntry(it); |
711 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1147 |
stringstream oss; |
stringstream oss; |
1148 |
// |
// |
1149 |
oss.str(""); |
oss.str(""); |
1150 |
oss << "INSERT INTO _RUNID_GEN VALUES (NULL);"; |
if ( chewbacca ){// if chewbacca and tag=none then use chewbacca tag (chiby = chewbacca inserted by), if chewbacca and tag!=none then use tag, if not chewbacca use tag. |
1151 |
|
if ( !strcmp(tag.Data(),"NONE") ){ |
1152 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; |
1153 |
|
} else { |
1154 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1155 |
|
}; |
1156 |
|
} else { |
1157 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1158 |
|
}; |
1159 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1160 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1161 |
oss.str(""); |
oss.str(""); |
1303 |
stringstream oss; |
stringstream oss; |
1304 |
// |
// |
1305 |
oss.str(""); |
oss.str(""); |
1306 |
oss << "lock table GL_RUN write, GL_ROOT write, GL_RAW write, GL_TIMESYNC write, GL_RESURS_OFFSET write, GL_PARAM write, GL_TLE write, GL_RUN_FRAGMENTS write, GL_RUN_TRASH write, GL_CALO_CALIB write, GL_CALOPULSE_CALIB write, GL_TRK_CALIB write, GL_S4_CALIB write, ROOT_TABLE_MERGING write, ROOT_TABLE write, _RUNID_GEN write;"; |
oss << "lock table GL_RUN write, GL_ROOT write, GL_RAW write, GL_TIMESYNC write, GL_RESURS_OFFSET write, GL_PARAM write, GL_TLE write, GL_RUN_FRAGMENTS write, GL_RUN_TRASH write, GL_CALO_CALIB write, GL_CALOPULSE_CALIB write, GL_TRK_CALIB write, GL_S4_CALIB write, ROOT_TABLE_MERGING write, ROOT_TABLE_BAD write, ROOT_TABLE write, _RUNID_GEN write;"; |
1307 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1308 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1309 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1360 |
// |
// |
1361 |
// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
// if ( IsDebug() ) printf(" obt conversion: obt is %u obtfirst is %u (numeric_limits<UInt_t>::max()/2) is %u \n",obt,pobtfirst,(UInt_t)(numeric_limits<UInt_t>::max()/2)); |
1362 |
// |
// |
1363 |
if ( obt < (pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)pobtfirst/2) && pobtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
1364 |
// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
// if ( IsDebug() ) printf(" rise up obt %lld \n",(Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1365 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
1366 |
}; |
}; |
1407 |
UInt_t lastPkt = 0; |
UInt_t lastPkt = 0; |
1408 |
UInt_t rhtime = 0; |
UInt_t rhtime = 0; |
1409 |
UInt_t rttime = 0; |
UInt_t rttime = 0; |
1410 |
|
// |
1411 |
|
if ( IsDebug() ) printf(" A firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1412 |
|
// |
1413 |
if ( !mishead ){ |
if ( !mishead ){ |
1414 |
codh = ehh->GetCounter(); |
codh = ehh->GetCounter(); |
1415 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1416 |
|
if ( IsDebug() ) printf(" B firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1417 |
firstev = 1; |
firstev = 1; |
1418 |
lastev = 0; |
lastev = 0; |
1419 |
} else { |
} else { |
1426 |
}; |
}; |
1427 |
if ( !mistrail ){ |
if ( !mistrail ){ |
1428 |
codt = eht->GetCounter(); |
codt = eht->GetCounter(); |
1429 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1)){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1)){ |
1430 |
|
if ( IsDebug() ) printf(" C firstev %i lastev %i nevents %i \n",firstev,lastev,lastev-firstev+1); |
1431 |
lastev = 0; |
lastev = 0; |
1432 |
firstev = lastev+1; |
firstev = lastev+1; |
1433 |
} else { |
} else { |
1444 |
if ( mishead ) { |
if ( mishead ) { |
1445 |
glrun->Set_GL_RUNH0(); |
glrun->Set_GL_RUNH0(); |
1446 |
// |
// |
1447 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1448 |
firstObt = lastObt; |
firstObt = lastObt; |
1449 |
firstPkt = lastPkt; |
firstPkt = lastPkt; |
1450 |
rhtime = rttime; |
rhtime = rttime; |
1463 |
if ( mistrail ){ |
if ( mistrail ){ |
1464 |
glrun->Set_GL_RUNT0(); |
glrun->Set_GL_RUNT0(); |
1465 |
// |
// |
1466 |
if ( lastev+1 == firstev || (lastev == firstev && lastev != -1) ){ |
if ( (lastev+1 == firstev && lastev != -1) || (lastev == firstev && lastev != -1) ){ |
1467 |
lastObt = firstObt; |
lastObt = firstObt; |
1468 |
lastPkt = firstPkt; |
lastPkt = firstPkt; |
1469 |
rttime = rhtime; |
rttime = rhtime; |
1498 |
* Insert a new row into GL_RAW table. |
* Insert a new row into GL_RAW table. |
1499 |
*/ |
*/ |
1500 |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
1501 |
|
|
1502 |
|
// |
1503 |
|
Bool_t idr = this->SetID_RAW(); |
1504 |
|
if ( idr ) return(1); |
1505 |
|
|
1506 |
|
GL_RAW glraw = GL_RAW(); |
1507 |
|
|
1508 |
|
glraw.PATH = GetRawPath(); |
1509 |
|
glraw.NAME = GetRawFile(); |
1510 |
|
// glraw.BOOT_NUMBER = 0;//??? |
1511 |
|
glraw.BOOT_NUMBER = this->GetBOOTnumber(); |
1512 |
|
|
1513 |
|
if( insertPamelaRawFile(&glraw) )return(1); |
1514 |
|
// |
1515 |
|
idr = this->SetID_RAW(); |
1516 |
|
if ( !idr ) throw -11; |
1517 |
|
|
1518 |
|
return(0); |
1519 |
|
} |
1520 |
|
/** |
1521 |
|
* Insert a new row into GL_RAW table. |
1522 |
|
*/ |
1523 |
|
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
1524 |
// |
// |
1525 |
stringstream oss; |
if(!glraw)return(1);//?? ok I think |
1526 |
// |
// |
1527 |
Bool_t idr = this->SetID_RAW(); |
stringstream oss; |
1528 |
if ( idr ) return(1); |
// |
1529 |
// |
oss.str(""); |
1530 |
oss.str(""); |
if ( STATIC ){ |
1531 |
if ( STATIC ){ |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
1532 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
<< glraw->PATH << "', '" << glraw->NAME << "')"; |
1533 |
<< this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
} else { |
1534 |
} else { |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << glraw->NAME << "')"; |
1535 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
}; |
1536 |
}; |
if ( debug ) cout <<oss.str().c_str() <<endl; |
1537 |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1538 |
// |
// |
1539 |
idr = this->SetID_RAW(); |
oss.str(""); |
1540 |
if ( !idr ) throw -11; |
oss << "SELECT ID FROM GL_RAW WHERE NAME=\""<<glraw->NAME<<"\";"; |
1541 |
// |
if ( debug ) cout << oss.str().c_str()<<endl; |
1542 |
return(0); |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1543 |
|
// |
1544 |
|
TSQLResult *result = 0; |
1545 |
|
TSQLRow *row = 0; |
1546 |
|
result = conn->Query(oss.str().c_str()); |
1547 |
|
if ( result == NULL ) throw -4; |
1548 |
|
row = result->Next(); |
1549 |
|
if ( !row ) return(1); |
1550 |
|
glraw->ID = (UInt_t)atoll(row->GetField(0)); |
1551 |
|
if ( debug ) printf(" The ID of the RAW file is %u \n",glraw->ID); |
1552 |
|
delete result; |
1553 |
|
delete row; |
1554 |
|
// |
1555 |
|
return(0); |
1556 |
} |
} |
1557 |
|
|
1558 |
|
|
1585 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1586 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1587 |
row = result->Next(); |
row = result->Next(); |
1588 |
|
if ( !row ) throw -92; |
1589 |
idresof = (UInt_t)atoll(row->GetField(0)); |
idresof = (UInt_t)atoll(row->GetField(0)); |
1590 |
existsts = true; |
existsts = true; |
1591 |
goto eout; |
goto eout; |
1865 |
* The raw file indicates in the parameters should be already been stored in the database. |
* The raw file indicates in the parameters should be already been stored in the database. |
1866 |
*/ |
*/ |
1867 |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
1868 |
stringstream oss; |
|
1869 |
TSQLResult *result = 0; |
stringstream oss; |
1870 |
TSQLRow *row = 0; |
TSQLResult *result = 0; |
1871 |
UInt_t idtimesync = 0; |
TSQLRow *row = 0; |
|
// |
|
|
// |
|
|
if ( chewbacca ){ |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
|
|
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -3; |
|
1872 |
// |
// |
1873 |
row = result->Next(); |
// ---------------------- |
1874 |
|
// determine the timesync |
1875 |
|
// ---------------------- |
1876 |
|
UInt_t idtimesync = 0; |
1877 |
// |
// |
1878 |
if ( !row ) throw -3; |
if ( chewbacca ){ |
1879 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
oss.str(""); |
1880 |
} else { |
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
1881 |
oss.str(""); |
if ( debug ) printf(" %s \n",oss.str().c_str()); |
1882 |
if ( STATIC ){ |
result = conn->Query(oss.str().c_str()); |
1883 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
// |
1884 |
<< " LEFT JOIN GL_ROOT " |
if ( !result ) throw -3; |
1885 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
// |
1886 |
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
row = result->Next(); |
1887 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
// |
1888 |
|
if ( !row ) throw -3; |
1889 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1890 |
} else { |
} else { |
1891 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
oss.str(""); |
1892 |
<< " LEFT JOIN GL_ROOT " |
if ( STATIC ){ |
1893 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1894 |
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
<< " LEFT JOIN GL_ROOT " |
1895 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1896 |
|
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
1897 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1898 |
|
} else { |
1899 |
|
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1900 |
|
<< " LEFT JOIN GL_ROOT " |
1901 |
|
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1902 |
|
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
1903 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1904 |
|
}; |
1905 |
|
result = conn->Query(oss.str().c_str()); |
1906 |
|
// |
1907 |
|
if ( !result ) throw -12; |
1908 |
|
// |
1909 |
|
row = result->Next(); |
1910 |
|
// |
1911 |
|
if ( !row ) throw -10; |
1912 |
|
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
1913 |
|
idroot = (UInt_t)atoll(row->GetField(2)); |
1914 |
|
delete row; |
1915 |
|
delete result; |
1916 |
|
return(1); |
1917 |
|
}; |
1918 |
|
// |
1919 |
|
// determine which timesync has to be used |
1920 |
|
// |
1921 |
|
oss.str(""); |
1922 |
|
oss << "SELECT GL_TIMESYNC.ID FROM GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW ORDER BY GL_TIMESYNC.ID DESC LIMIT 1;"; |
1923 |
|
result = conn->Query(oss.str().c_str()); |
1924 |
|
// |
1925 |
|
if ( !result ) throw -3; |
1926 |
|
// |
1927 |
|
row = result->Next(); |
1928 |
|
// |
1929 |
|
if ( !row ) throw -3; |
1930 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1931 |
}; |
}; |
1932 |
result = conn->Query(oss.str().c_str()); |
|
1933 |
// |
delete row; |
1934 |
if ( !result ) throw -12; |
delete result; |
1935 |
// |
|
1936 |
row = result->Next(); |
// ---------------------- |
1937 |
// |
// insert root file |
1938 |
if ( !row ) throw -10; |
// ---------------------- |
1939 |
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
|
1940 |
idroot = (UInt_t)atoll(row->GetField(2)); |
GL_ROOT glroot = GL_ROOT(); |
1941 |
return(1); |
|
1942 |
|
glroot.ID_RAW = GetID_RAW(); |
1943 |
|
glroot.ID_TIMESYNC = idtimesync; |
1944 |
|
if ( STATIC ){ |
1945 |
|
glroot.PATH = GetRootPath(); |
1946 |
|
} else { |
1947 |
|
if ( KEEPENV ){ |
1948 |
|
glroot.PATH = gSystem->DirName(filerootname.Data()); |
1949 |
|
} else { |
1950 |
|
glroot.PATH = "$PAM_L0"; |
1951 |
|
}; |
1952 |
}; |
}; |
1953 |
// |
glroot.NAME = GetRootFile(); |
1954 |
// determine which timesync has to be used |
|
1955 |
// |
if ( insertPamelaRootFile(&glroot) )return 1; |
1956 |
oss.str(""); |
|
1957 |
oss << "SELECT GL_TIMESYNC.ID FROM GL_TIMESYNC LEFT JOIN GL_RAW ON GL_RAW.ID = GL_TIMESYNC.ID_RAW ORDER BY GL_TIMESYNC.ID DESC LIMIT 1;"; |
SetID_ROOT(glroot.ID); |
1958 |
result = conn->Query(oss.str().c_str()); |
|
1959 |
// |
|
1960 |
if ( !result ) throw -3; |
return (0); |
1961 |
// |
} |
1962 |
row = result->Next(); |
/** |
1963 |
// |
* Insert all the new rows into GL_ROOT. |
1964 |
if ( !row ) throw -3; |
* The raw file indicates in the parameters should be already been stored in the database. |
1965 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
*/ |
1966 |
}; |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
1967 |
|
stringstream oss; |
1968 |
|
TSQLResult *result = 0; |
1969 |
|
TSQLRow *row = 0; |
1970 |
|
// |
1971 |
// |
// |
1972 |
oss.str(""); |
oss.str(""); |
1973 |
if ( STATIC ){ |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
1974 |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; |
|
<< this->GetID_RAW() << "', '" << idtimesync << "', '" << this->GetRootPath().Data() << "', '" << this->GetRootFile().Data() << "')"; |
|
|
} else { |
|
|
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
|
|
<< this->GetID_RAW() << "', '" << idtimesync << "', '$PAM_L0', '" << this->GetRootFile().Data() << "')"; |
|
|
}; |
|
1975 |
// |
// |
1976 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1977 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
1978 |
// |
// |
1979 |
delete result; |
delete result; |
1980 |
// |
// |
1981 |
oss.str(""); |
oss.str(""); |
1982 |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
1983 |
if ( STATIC ){ |
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; |
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << this->GetRootPath().Data() << "' and NAME='"<< this->GetRootFile().Data() <<"';"; |
|
|
} else { |
|
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< this->GetRootFile().Data() <<"';"; |
|
|
}; |
|
1984 |
// |
// |
1985 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1986 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1987 |
if ( !result ) throw -12; |
if ( !result ) throw -12; |
1988 |
row = result->Next(); |
row = result->Next(); |
1989 |
if ( !row ) throw -3; |
if ( !row ) throw -3; |
1990 |
this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); |
|
1991 |
if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); |
glroot->ID = (UInt_t)atoll(row->GetField(0)); |
1992 |
|
|
1993 |
|
if ( debug ) printf(" The ID of the ROOT file is %u \n",glroot->ID); |
1994 |
// |
// |
1995 |
delete result; |
delete result; |
1996 |
// |
// |
2326 |
// |
// |
2327 |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
this->HandleRunFragments(true,true,chminentry,(evbefh)); |
2328 |
// |
// |
2329 |
|
// what about pth=ptht-1 |
2330 |
}; |
}; |
2331 |
}; |
}; |
2332 |
// |
// |
2389 |
// if ( ptt+1 == rtev){ |
// if ( ptt+1 == rtev){ |
2390 |
if ( conptt+1 == nrtev ){ |
if ( conptt+1 == nrtev ){ |
2391 |
// if ( conptt+1 == (nrtev+nrtbef )){ |
// if ( conptt+1 == (nrtev+nrtbef )){ |
2392 |
|
if ( IsDebug() ) printf(" >>>>>>>>>>> %i %u %i %u \n",ptht,rhev,nrtev,conptt); |
2393 |
ptht++; |
ptht++; |
2394 |
if ( ptht < rhev ){ |
if ( ptht < rhev ){ |
2395 |
rh->GetEntry(ptht); |
rh->GetEntry(ptht); |
2396 |
|
//pth++; |
2397 |
|
//if ( pth < rhev ){ |
2398 |
|
//rh->GetEntry(pth); |
2399 |
phh = ehh->GetPscuHeader(); |
phh = ehh->GetPscuHeader(); |
2400 |
pkth = phh->GetCounter(); |
pkth = phh->GetCounter(); |
2401 |
obth = phh->GetOrbitalTime(); |
obth = phh->GetOrbitalTime(); |
2420 |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); |
if ( IsDebug() ) printf(" Piece of run at the end of the file with NO RUNHEADER! evbeft %u upperentry-1 %u \n",(UInt_t)evbeft,upperentry-1); |
2421 |
// |
// |
2422 |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
if ( (ptt-1) < 0 ) throw -15; // should never arrive here! |
2423 |
rt->GetEntry(ptt-1); |
// rt->GetEntry(ptt-1); |
2424 |
|
rt->GetEntry(rtev-1); |
2425 |
cod = eht->GetCounter(); |
cod = eht->GetCounter(); |
2426 |
tcod = (UInt_t)cod->Get(pctp->Physics); |
tcod = (UInt_t)cod->Get(pctp->Physics)+1; |
2427 |
evbefh = TMath::Max(chminentry,tcod); |
evbefh = TMath::Max(chminentry,tcod); |
2428 |
// evbefh = cod->Get(pctp->Physics); |
// evbefh = cod->Get(pctp->Physics); |
2429 |
rt->GetEntry(ptt); |
rt->GetEntry(ptt); |
3257 |
// |
// |
3258 |
} else { |
} else { |
3259 |
// |
// |
3260 |
if ( IsDebug() ) printf(" There are no-phyics packets inside the run!\n"); |
if ( IsDebug() ) printf(" There are no-physics packets inside the run!\n"); |
3261 |
// |
// |
3262 |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
// HERE WE MUST HANDLE THAT RUNS AND GO BACK |
3263 |
// |
// |
3267 |
UInt_t check = 0; |
UInt_t check = 0; |
3268 |
UInt_t lastevtemp = lastev; |
UInt_t lastevtemp = lastev; |
3269 |
UInt_t firstevno = firstev; |
UInt_t firstevno = firstev; |
3270 |
|
UInt_t rhchko=0; |
3271 |
|
UInt_t rhchk=0; |
3272 |
// |
// |
3273 |
for (UInt_t i=firstev; i<=lastev; i++){ |
for (UInt_t i=firstev; i<=lastev; i++){ |
3274 |
// |
// |
3277 |
// |
// |
3278 |
check = 0; |
check = 0; |
3279 |
// |
// |
3280 |
|
|
3281 |
|
// if we have a runheader set lastev then exit |
3282 |
|
// |
3283 |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
3284 |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
if ( strcmp(*Iter,"Physics") ) check += code->Get(GetPacketType(*Iter)); |
3285 |
}; |
}; |
3286 |
|
// check here if we have a runheader |
3287 |
|
rhchko = rhchk; |
3288 |
|
rhchk = code->Get(GetPacketType("RunHeader")); |
3289 |
// |
// |
3290 |
if ( checkfirst < check || i == lastev ){ |
if ( checkfirst < check || i == lastev ){ |
3291 |
// |
// |
3369 |
// this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments |
// this->HandleRunFragments(true,mistrail,firstentry,lastentry); // cannot call it here since it enters a loop which will destroy the already stored variables if we arrive here from HandleRunFragments |
3370 |
// |
// |
3371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3372 |
mishead = true; |
mishead = true; |
3373 |
|
|
3374 |
|
|
3688 |
}; // EEE |
}; // EEE |
3689 |
|
|
3690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3691 |
} else { |
} else { |
3692 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
3693 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
3702 |
// |
// |
3703 |
}; |
}; |
3704 |
// |
// |
3705 |
|
if ( i > firstev ){ |
3706 |
|
if ( rhchko != rhchk ){ |
3707 |
|
if ( IsDebug() ) printf("oh oh... we have a runheader! stop here and handle later the remaining piece\n"); |
3708 |
|
lastev = i; |
3709 |
|
return(false); |
3710 |
|
}; |
3711 |
|
}; |
3712 |
|
// |
3713 |
if ( check == checklast && i != lastev ){ |
if ( check == checklast && i != lastev ){ |
3714 |
lastevtemp = i - 1; |
lastevtemp = i - 1; |
3715 |
i = lastev - 1; |
i = lastev - 1; |
4530 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
4531 |
*/ |
*/ |
4532 |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
4533 |
// |
|
4534 |
TSQLResult *result = 0; |
GL_TRK_CALIB *glcal = new GL_TRK_CALIB(); |
|
TSQLRow *row = 0; |
|
|
// |
|
|
stringstream oss; |
|
|
oss.str(""); |
|
|
// |
|
|
UInt_t totime = 0; |
|
|
// |
|
|
if ( !pk1 && !pk2 ){ |
|
|
if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
|
|
return; |
|
|
}; |
|
|
// |
|
|
// check if the calibration has already been inserted |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
|
|
<< " BOOT_NUMBER = "<< this->GetBOOTnumber(); // |
|
|
oss << " AND ( ( "; |
|
|
if ( pk1 ){ |
|
|
oss << " OBT1 = "<< obt1 << " AND " |
|
|
<< " PKT1 = "<< pkt1 |
|
|
<< " ) OR ( "; |
|
|
} else { |
|
|
oss << " PKT1 = "<< pkt2-1 |
|
|
<< " ) OR ( "; |
|
|
}; |
|
|
if ( pk2 ){ |
|
|
oss << " OBT2 = "<< obt2 << " AND " |
|
|
<< " PKT2 = "<< pkt2; |
|
|
} else { |
|
|
oss << " PKT2 = "<< pkt1+1; |
|
|
}; |
|
|
oss << " ) );"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
|
row = result->Next(); |
|
|
// |
|
|
if ( row ){ |
|
4535 |
// |
// |
4536 |
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
glcal->ID = 0; |
4537 |
if ( PEDANTIC ) throw -80; |
glcal->ID_ROOT_L0 = GetID_ROOT(); |
4538 |
|
glcal->EV_ROOT_CALIBTRK1 = t1; |
4539 |
|
glcal->EV_ROOT_CALIBTRK2 = t2; |
4540 |
|
glcal->FROM_TIME = fromtime; |
4541 |
|
glcal->TO_TIME = 0; |
4542 |
|
glcal->OBT1 = obt1; |
4543 |
|
glcal->OBT2 = obt2; |
4544 |
|
glcal->PKT1 = pkt1; |
4545 |
|
glcal->PKT2 = pkt2; |
4546 |
|
glcal->BOOT_NUMBER = GetBOOTnumber(); |
4547 |
|
glcal->VALIDATION = valid; |
4548 |
// |
// |
4549 |
} else { |
HandleTRK_CALIB(glcal); |
|
// |
|
|
// we have to insert a new calibration, check where to place it |
|
4550 |
// |
// |
4551 |
oss.str(""); |
delete glcal; |
4552 |
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
} |
4553 |
<< " FROM_TIME < "<< fromtime << " AND " |
/** |
4554 |
<< " TO_TIME > "<< fromtime << ";"; |
* Fill the GL_TRK_CALIB table |
4555 |
|
*/ |
4556 |
|
void PamelaDBOperations::HandleTRK_CALIB(GL_TRK_CALIB *glcal){ |
4557 |
|
|
4558 |
|
Bool_t pk1 = (glcal->OBT1>0&&glcal->PKT1>0); |
4559 |
|
Bool_t pk2 = (glcal->OBT2>0&&glcal->PKT2>0); |
4560 |
|
UInt_t boot_number = glcal->BOOT_NUMBER; |
4561 |
|
UInt_t obt1 = glcal->OBT1; |
4562 |
|
UInt_t obt2 = glcal->OBT2; |
4563 |
|
UInt_t pkt1 = glcal->PKT1; |
4564 |
|
UInt_t pkt2 = glcal->PKT2; |
4565 |
|
UInt_t fromtime = glcal->FROM_TIME; |
4566 |
|
UInt_t totime = 0; |
4567 |
|
UInt_t idroot = glcal->ID_ROOT_L0; |
4568 |
|
UInt_t t1 = glcal->EV_ROOT_CALIBTRK1; |
4569 |
|
UInt_t t2 = glcal->EV_ROOT_CALIBTRK2; |
4570 |
|
UInt_t valid = glcal->VALIDATION; |
4571 |
// |
// |
4572 |
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
TSQLResult *result = 0; |
4573 |
result = conn->Query(oss.str().c_str()); |
TSQLRow *row = 0; |
4574 |
// |
// |
4575 |
if ( !result ) throw -4; |
stringstream oss; |
4576 |
|
oss.str(""); |
4577 |
// |
// |
|
row = result->Next(); |
|
4578 |
// |
// |
4579 |
if ( !row ){ |
if ( !pk1 && !pk2 ){ |
4580 |
// |
if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
4581 |
// no calibrations in the db contain our calibration |
return; |
|
// |
|
|
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
|
|
if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
|
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
|
row = result->Next(); |
|
|
if ( !row ){ |
|
|
totime = numeric_limits<UInt_t>::max(); |
|
|
} else { |
|
|
totime = (UInt_t)atoll(row->GetField(0)); |
|
|
}; |
|
|
// |
|
|
} else { |
|
|
// |
|
|
// determine upper and lower limits and make space for the new calibration |
|
|
// |
|
|
totime = (UInt_t)atoll(row->GetField(1)); |
|
|
// |
|
|
oss.str(""); |
|
|
oss << " UPDATE GL_TRK_CALIB SET " |
|
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
|
|
<< " ID = "<< row->GetField(0) << ";"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); |
|
|
result = conn->Query(oss.str().c_str()); |
|
|
// |
|
|
if ( !result ) throw -4; |
|
|
// |
|
4582 |
}; |
}; |
4583 |
// |
// |
4584 |
oss.str(""); |
// check if the calibration has already been inserted |
|
oss << " INSERT INTO GL_TRK_CALIB (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) " |
|
|
<< " VALUES (NULL,' " |
|
|
<< idroot << "',"; |
|
4585 |
// |
// |
4586 |
if ( !pk1 ){ |
oss.str(""); |
4587 |
oss << "NULL,"; |
oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
4588 |
|
<< " BOOT_NUMBER = "<< boot_number; // |
4589 |
|
oss << " AND FROM_TIME="<<fromtime; /// NEWNEWNEW -- VA BENE ?!?!?!?! |
4590 |
|
oss << " AND ( ( "; |
4591 |
|
if ( pk1 ){ |
4592 |
|
oss << " OBT1 = "<< obt1 << " AND " |
4593 |
|
<< " PKT1 = "<< pkt1 |
4594 |
|
<< " ) OR ( "; |
4595 |
} else { |
} else { |
4596 |
oss << "'" |
oss << " PKT1 = "<< pkt2-1 |
4597 |
<< t1 << "',"; |
<< " ) OR ( "; |
4598 |
}; |
}; |
4599 |
// |
if ( pk2 ){ |
4600 |
if ( !pk2 ){ |
oss << " OBT2 = "<< obt2 << " AND " |
4601 |
oss << "NULL,'"; |
<< " PKT2 = "<< pkt2; |
4602 |
} else { |
} else { |
4603 |
oss << "'" |
oss << " PKT2 = "<< pkt1+1; |
4604 |
<< t2 << "','"; |
}; |
4605 |
}; |
oss << " ) );"; |
|
// |
|
|
oss << fromtime << "','" |
|
|
<< totime << "','" |
|
|
<< obt1 << "','" |
|
|
<< pkt1 << "','" |
|
|
<< obt2 << "','" |
|
|
<< pkt2 << "','" |
|
|
<< this->GetBOOTnumber() << "','" |
|
|
<< valid << "');"; |
|
|
// |
|
|
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
|
4606 |
// |
// |
4607 |
|
if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
4608 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
4609 |
// |
// |
4610 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
4611 |
// |
// |
4612 |
}; |
row = result->Next(); |
|
// |
|
|
}; |
|
|
|
|
|
/** |
|
|
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
|
|
*/ |
|
|
Int_t PamelaDBOperations::insertTRK_CALIB(){ |
|
|
// |
|
|
CalibTrk1Event *caltrk1 = 0; |
|
|
CalibTrk2Event *caltrk2 = 0; |
|
|
TTree *tr1 = 0; |
|
|
TTree *tr2 = 0; |
|
|
EventHeader *eh1 = 0; |
|
|
PscuHeader *ph1 = 0; |
|
|
EventHeader *eh2 = 0; |
|
|
PscuHeader *ph2 = 0; |
|
|
// |
|
|
PacketType *pctp=0; |
|
|
EventCounter *codt2=0; |
|
|
// |
|
|
Int_t nevents1 = 0; |
|
|
Int_t nevents2 = 0; |
|
|
// |
|
|
fromtime = 0; |
|
|
// |
|
|
obt1 = 0; |
|
|
pkt1 = 0; |
|
|
obt2 = 0; |
|
|
pkt2 = 0; |
|
|
// |
|
|
tr1 = (TTree*)file->Get("CalibTrk1"); |
|
|
if ( !tr1 || tr1->IsZombie() ) throw -22; |
|
|
tr2 = (TTree*)file->Get("CalibTrk2"); |
|
|
if ( !tr2 || tr2->IsZombie() ) throw -23; |
|
|
// |
|
|
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
|
|
tr1->SetBranchAddress("Header", &eh1); |
|
|
nevents1 = tr1->GetEntries(); |
|
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
|
|
tr2->SetBranchAddress("Header", &eh2); |
|
|
nevents2 = tr2->GetEntries(); |
|
|
// |
|
|
if ( !nevents1 && !nevents2 ) return(1); |
|
|
// |
|
|
t2 = -1; |
|
|
Int_t pret2 = 0; |
|
|
Int_t t2t1cal = 0; |
|
|
// |
|
|
for (t1=0; t1 < nevents1; t1++){ |
|
|
// |
|
|
pret2 = t2; |
|
|
tr1->GetEntry(t1); |
|
|
// |
|
|
ph1 = eh1->GetPscuHeader(); |
|
|
obt1 = ph1->GetOrbitalTime(); |
|
|
pkt1 = ph1->GetCounter(); |
|
|
fromtime = this->GetAbsTime(ph1->GetOrbitalTime()); |
|
|
// |
|
|
// valid = 1; |
|
|
// // |
|
|
// if ( caltrk1->unpackError != 0 && caltrk1->good0 == 0 ) valid = 0;// CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT1 |
|
|
// |
|
4613 |
// |
// |
4614 |
if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
if ( row ){ |
|
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
|
|
// |
|
|
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u \n",fromtime,obt1,pkt1); |
|
|
// |
|
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
|
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
|
|
// |
|
|
// Do we have the second calibration packet? |
|
|
// |
|
|
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
|
|
// |
|
|
t2++; |
|
|
// |
|
|
pret2 = t2 - 1; // EMILIANO |
|
|
// |
|
|
if ( t2 < nevents2 ){ |
|
|
tr2->GetEntry(t2); |
|
|
codt2 = eh2->GetCounter(); |
|
|
t2t1cal = codt2->Get(pctp->CalibTrk1); |
|
|
// |
|
|
ph2 = eh2->GetPscuHeader(); |
|
|
obt2 = ph2->GetOrbitalTime(); |
|
|
pkt2 = ph2->GetCounter(); |
|
|
// |
|
|
if ( IsDebug() ) printf(" This is a trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
|
|
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
|
|
// |
|
|
} else { |
|
|
// |
|
|
// running out of vector without finding the corresponding calibration, sig |
|
|
// |
|
|
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
|
|
pret2 = t2; |
|
|
obt2 = 0; |
|
|
// pkt2 = pkt1+2; |
|
|
pkt2 = 0; |
|
|
t2t1cal = t1+1; |
|
|
}; |
|
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
|
|
|
|
|
// EMILIANO |
|
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
|
|
// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
|
|
// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); |
|
|
// // |
|
|
// // running out of vector without finding the corresponding calibration, sig |
|
|
// // |
|
|
// pret2 = t2; |
|
|
// obt2 = 0; |
|
|
// // pkt2 = pkt1+2; |
|
|
// pkt2 = 0; |
|
|
// t2t1cal = t1+1; |
|
|
// }; |
|
|
|
|
|
|
|
4615 |
// |
// |
4616 |
}; |
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
4617 |
// |
if ( PEDANTIC ) throw -80; |
|
if ( IsDebug() ) printf(" Check if trk calibration2 exists \n"); |
|
|
// |
|
|
// EMILIANO |
|
|
if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
|
|
// if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
|
|
if ( IsDebug() ) printf(" The calibration found is outside the interval, sig \n"); |
|
4618 |
// |
// |
4619 |
// running out of vector without finding the corresponding calibration, sig |
} else { |
|
// |
|
|
pret2 = t2; |
|
|
obt2 = 0; |
|
|
pkt2 = 0; |
|
|
}; |
|
|
// |
|
|
// The calibration is good |
|
|
// |
|
|
if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){ |
|
4620 |
// |
// |
4621 |
if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
// we have to insert a new calibration, check where to place it |
|
if ( IsDebug() ) printf(" The trk calibration2 at obt %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
|
4622 |
// |
// |
4623 |
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
oss.str(""); |
4624 |
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
4625 |
valid = valid & valid2; |
<< " FROM_TIME < "<< fromtime << " AND " |
4626 |
|
<< " TO_TIME > "<< fromtime << ";"; |
4627 |
// |
// |
4628 |
// Handle good calib |
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
4629 |
|
result = conn->Query(oss.str().c_str()); |
4630 |
// |
// |
4631 |
this->HandleTRK_CALIB(true,true); |
if ( !result ) throw -4; |
4632 |
// |
// |
4633 |
// Check for missing calibtrk1 |
row = result->Next(); |
4634 |
// |
// |
4635 |
if ( t2 != pret2+1 ){ |
if ( !row ){ |
|
// |
|
|
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u pret2 is %u \n",obt2,pkt2,t2,pret2); |
|
|
// |
|
|
while ( t2 > pret2+1 ){ |
|
4636 |
// |
// |
4637 |
// handle missing calib1 |
// no calibrations in the db contain our calibration |
4638 |
// |
// |
4639 |
pret2++; |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
4640 |
|
if ( fromtime < 1150871000 ) fromtime = 0; // the first flight calibration was taken at about 1150863300 s, this line allows to analyze first runs in raw mode |
4641 |
// |
// |
4642 |
obt1 = 0; |
oss.str(""); |
4643 |
pkt1 = 0; |
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
4644 |
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
4645 |
// |
// |
4646 |
tr2->GetEntry(pret2); |
if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str()); |
4647 |
ph2 = eh2->GetPscuHeader(); |
result = conn->Query(oss.str().c_str()); |
|
obt2 = ph2->GetOrbitalTime(); |
|
|
pkt2 = ph2->GetCounter(); |
|
4648 |
// |
// |
4649 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
if ( !result ) throw -4; |
4650 |
// |
// |
4651 |
valid = 0; |
row = result->Next(); |
4652 |
this->HandleTRK_CALIB(false,true); |
if ( !row ){ |
4653 |
|
totime = numeric_limits<UInt_t>::max(); |
4654 |
|
} else { |
4655 |
|
totime = (UInt_t)atoll(row->GetField(0)); |
4656 |
|
}; |
4657 |
|
// |
4658 |
|
} else { |
4659 |
|
// |
4660 |
|
// determine upper and lower limits and make space for the new calibration |
4661 |
|
// |
4662 |
|
totime = (UInt_t)atoll(row->GetField(1)); |
4663 |
|
// |
4664 |
|
oss.str(""); |
4665 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
4666 |
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
4667 |
|
<< " ID = "<< row->GetField(0) << ";"; |
4668 |
|
// |
4669 |
|
if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); |
4670 |
|
result = conn->Query(oss.str().c_str()); |
4671 |
|
// |
4672 |
|
if ( !result ) throw -4; |
4673 |
// |
// |
|
}; |
|
|
// |
|
4674 |
}; |
}; |
4675 |
// |
// |
4676 |
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
oss.str(""); |
4677 |
|
oss << " INSERT INTO GL_TRK_CALIB (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) " |
4678 |
|
<< " VALUES (NULL,' " |
4679 |
|
<< idroot << "',"; |
4680 |
// |
// |
4681 |
// Check for missing calibtrk2 |
if ( !pk1 ){ |
4682 |
|
oss << "NULL,"; |
4683 |
|
} else { |
4684 |
|
oss << "'" |
4685 |
|
<< t1 << "',"; |
4686 |
|
}; |
4687 |
// |
// |
4688 |
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
if ( !pk2 ){ |
4689 |
t2 = pret2; |
oss << "NULL,'"; |
4690 |
|
} else { |
4691 |
|
oss << "'" |
4692 |
|
<< t2 << "','"; |
4693 |
|
}; |
4694 |
// |
// |
4695 |
// handle missing calib2 |
oss << fromtime << "','" |
4696 |
|
<< totime << "','" |
4697 |
|
<< obt1 << "','" |
4698 |
|
<< pkt1 << "','" |
4699 |
|
<< obt2 << "','" |
4700 |
|
<< pkt2 << "','" |
4701 |
|
<< boot_number << "','" |
4702 |
|
<< valid << "');"; |
4703 |
// |
// |
4704 |
obt2 = 0; |
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
4705 |
pkt2 = 0; |
// |
4706 |
valid = 0; |
result = conn->Query(oss.str().c_str()); |
4707 |
this->HandleTRK_CALIB(true,false); |
// |
4708 |
|
if ( !result ) throw -4; |
4709 |
// |
// |
|
}; |
|
|
// |
|
|
} else { |
|
|
// |
|
|
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
|
|
// if ( PEDANTIC ) throw -79; |
|
|
// |
|
4710 |
}; |
}; |
4711 |
// |
|
4712 |
}; |
oss.str(""); |
4713 |
// |
oss << " SELECT ID FROM GL_TRK_CALIB ORDER BY ID DESC LIMIT 1 ;"; |
4714 |
// we have one more calib pkt2 ! |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
4715 |
// |
result = conn->Query(oss.str().c_str()); |
4716 |
t2++; |
if ( !result ) throw -4;; |
4717 |
while ( t2 < nevents2 ){ |
row = result->Next(); |
4718 |
|
if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); |
4719 |
|
|
4720 |
// |
// |
4721 |
// handle missing calib1 |
}; |
4722 |
|
|
4723 |
|
/** |
4724 |
|
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
4725 |
|
*/ |
4726 |
|
Int_t PamelaDBOperations::insertTRK_CALIB(){ |
4727 |
|
// |
4728 |
|
CalibTrk1Event *caltrk1 = 0; |
4729 |
|
CalibTrk2Event *caltrk2 = 0; |
4730 |
|
TTree *tr1 = 0; |
4731 |
|
TTree *tr2 = 0; |
4732 |
|
EventHeader *eh1 = 0; |
4733 |
|
PscuHeader *ph1 = 0; |
4734 |
|
EventHeader *eh2 = 0; |
4735 |
|
PscuHeader *ph2 = 0; |
4736 |
|
// |
4737 |
|
PacketType *pctp=0; |
4738 |
|
EventCounter *codt2=0; |
4739 |
|
// |
4740 |
|
Int_t nevents1 = 0; |
4741 |
|
Int_t nevents2 = 0; |
4742 |
|
// |
4743 |
|
fromtime = 0; |
4744 |
// |
// |
|
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
|
4745 |
obt1 = 0; |
obt1 = 0; |
4746 |
pkt1 = 0; |
pkt1 = 0; |
4747 |
|
obt2 = 0; |
4748 |
|
pkt2 = 0; |
4749 |
// |
// |
4750 |
tr2->GetEntry(t2); |
tr1 = (TTree*)file->Get("CalibTrk1"); |
4751 |
ph2 = eh2->GetPscuHeader(); |
if ( !tr1 || tr1->IsZombie() ) throw -22; |
4752 |
obt2 = ph2->GetOrbitalTime(); |
tr2 = (TTree*)file->Get("CalibTrk2"); |
4753 |
pkt2 = ph2->GetCounter(); |
if ( !tr2 || tr2->IsZombie() ) throw -23; |
4754 |
// |
// |
4755 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
4756 |
valid = 0; |
tr1->SetBranchAddress("Header", &eh1); |
4757 |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
nevents1 = tr1->GetEntries(); |
4758 |
// EMILIANO |
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
4759 |
if ( this->PKT(pkt2) >= this->PKT(pktfirst) && this->PKT(pkt2 <= upperpkt) && this->OBT(obt2) >= this->OBT(obtfirst) && this->OBT(obt2) <= upperobt ){ |
tr2->SetBranchAddress("Header", &eh2); |
4760 |
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
nevents2 = tr2->GetEntries(); |
4761 |
// |
// |
4762 |
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
if ( !nevents1 && !nevents2 ) return(1); |
4763 |
// |
// |
4764 |
this->HandleTRK_CALIB(false,true); |
t2 = -1; |
4765 |
// |
Int_t pret2 = 0; |
4766 |
}; |
Int_t t2t1cal = 0; |
4767 |
|
// |
4768 |
|
bool MISSING_pkt1 = true; |
4769 |
|
bool MISSING_pkt2 = true; |
4770 |
|
int ncalib = 0; |
4771 |
|
bool try_to_recover = false; |
4772 |
// |
// |
4773 |
t2++; |
for (t1=0; t1 < nevents1; t1++){//loop over packet1 |
4774 |
|
// |
4775 |
|
pret2 = t2; |
4776 |
|
tr1->GetEntry(t1); |
4777 |
|
// |
4778 |
|
ph1 = eh1->GetPscuHeader(); |
4779 |
|
obt1 = ph1->GetOrbitalTime(); |
4780 |
|
pkt1 = ph1->GetCounter(); |
4781 |
|
fromtime = GetAbsTime(ph1->GetOrbitalTime()); |
4782 |
|
// |
4783 |
|
// chek if the packet number and obt are consistent with the other packets ??? |
4784 |
|
// |
4785 |
|
if ( PKT(pkt1) >= PKT(pktfirst) && PKT(pkt1) <= upperpkt && OBT(obt1) >= OBT(obtfirst) && OBT(obt1) <= upperobt ){ |
4786 |
|
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
4787 |
|
// |
4788 |
|
if ( IsDebug() ) printf("\n Trk calibration1 %u at time %u obt %u pkt %u \n",t1,fromtime,obt1,pkt1); |
4789 |
|
// |
4790 |
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
4791 |
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
4792 |
|
// |
4793 |
|
// Do we have the second calibration packet? |
4794 |
|
// |
4795 |
|
if ( IsDebug() ) cout << " Loop over calibration2 to search associated calibration: "<<endl; |
4796 |
|
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
4797 |
|
// |
4798 |
|
t2++; |
4799 |
|
// |
4800 |
|
pret2 = t2 - 1; // EMILIANO |
4801 |
|
// |
4802 |
|
if ( t2 < nevents2 ){ |
4803 |
|
tr2->GetEntry(t2); |
4804 |
|
codt2 = eh2->GetCounter(); |
4805 |
|
t2t1cal = codt2->Get(pctp->CalibTrk1); |
4806 |
|
// |
4807 |
|
ph2 = eh2->GetPscuHeader(); |
4808 |
|
obt2 = ph2->GetOrbitalTime(); |
4809 |
|
pkt2 = ph2->GetCounter(); |
4810 |
|
// |
4811 |
|
if ( IsDebug() ) printf(" >> trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
4812 |
|
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
4813 |
|
// |
4814 |
|
} else { |
4815 |
|
// |
4816 |
|
// running out of vector without finding the corresponding calibration, sig |
4817 |
|
// |
4818 |
|
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
4819 |
|
pret2 = t2; |
4820 |
|
obt2 = 0; |
4821 |
|
// pkt2 = pkt1+2; |
4822 |
|
pkt2 = 0; |
4823 |
|
t2t1cal = t1+1; |
4824 |
|
}; |
4825 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
4826 |
|
|
4827 |
|
// EMILIANO |
4828 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
4829 |
|
// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
4830 |
|
// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); |
4831 |
|
// // |
4832 |
|
// // running out of vector without finding the corresponding calibration, sig |
4833 |
|
// // |
4834 |
|
// pret2 = t2; |
4835 |
|
// obt2 = 0; |
4836 |
|
// // pkt2 = pkt1+2; |
4837 |
|
// pkt2 = 0; |
4838 |
|
// t2t1cal = t1+1; |
4839 |
|
// }; |
4840 |
|
|
4841 |
|
|
4842 |
|
// |
4843 |
|
}; |
4844 |
|
// |
4845 |
|
if ( IsDebug() ) printf(" Check if trk calibration2 is the right one \n"); |
4846 |
|
// |
4847 |
|
// EMILIANO |
4848 |
|
if ( ( PKT(pkt2) < PKT(pktfirst) || PKT(pkt2) > upperpkt) || (OBT(obt2) < OBT(obtfirst) || OBT(obt2) > upperobt) ){ |
4849 |
|
// if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
4850 |
|
if ( IsDebug() ) printf(" *WARNING* The calibration found is outside the interval, sig \n"); |
4851 |
|
// |
4852 |
|
// running out of vector without finding the corresponding calibration, sig |
4853 |
|
// |
4854 |
|
pret2 = t2; |
4855 |
|
obt2 = 0; |
4856 |
|
pkt2 = 0; |
4857 |
|
}; |
4858 |
|
if ( PKT(pkt2) == PKT(pkt1)+1 ){ |
4859 |
|
if ( IsDebug() ) cout << " ...OK"<<endl; |
4860 |
|
// ======================= |
4861 |
|
// The calibration is good |
4862 |
|
// ======================= |
4863 |
|
// |
4864 |
|
// if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
4865 |
|
// if ( IsDebug() ) printf(" Trk calibration2 at obt %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
4866 |
|
// if ( IsDebug() ) printf("\n Trk calibration2 at time %u obt %u pkt %u \n",fromtime,obt2,pkt2); |
4867 |
|
if ( IsDebug() ) printf(" Trk calibration2 %u at time %u obt %u pkt %u \n",t2,fromtime,obt2,pkt2); |
4868 |
|
// |
4869 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
4870 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
4871 |
|
// valid = valid & valid2; |
4872 |
|
valid = valid & valid2; //QUESTO VA CAMBIATO |
4873 |
|
// |
4874 |
|
// Handle good calib |
4875 |
|
// |
4876 |
|
MISSING_pkt1 = false; |
4877 |
|
MISSING_pkt2 = false; |
4878 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4879 |
|
// |
4880 |
|
// Check for missing calibtrk1 |
4881 |
|
// |
4882 |
|
if ( t2 != pret2+1 ){ |
4883 |
|
// |
4884 |
|
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u pret2 is %u \n",obt2,pkt2,t2,pret2); |
4885 |
|
// |
4886 |
|
while ( t2 > pret2+1 ){ |
4887 |
|
// |
4888 |
|
// handle missing calib1 |
4889 |
|
// |
4890 |
|
pret2++; |
4891 |
|
// |
4892 |
|
obt1 = 0; |
4893 |
|
pkt1 = 0; |
4894 |
|
// |
4895 |
|
tr2->GetEntry(pret2); |
4896 |
|
ph2 = eh2->GetPscuHeader(); |
4897 |
|
obt2 = ph2->GetOrbitalTime(); |
4898 |
|
pkt2 = ph2->GetCounter(); |
4899 |
|
// |
4900 |
|
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
4901 |
|
// |
4902 |
|
valid = 0; |
4903 |
|
MISSING_pkt1 = true; |
4904 |
|
MISSING_pkt2 = false; |
4905 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4906 |
|
// |
4907 |
|
}; |
4908 |
|
// |
4909 |
|
}; |
4910 |
|
// |
4911 |
|
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
4912 |
|
// |
4913 |
|
// Check for missing calibtrk2 |
4914 |
|
// |
4915 |
|
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
4916 |
|
t2 = pret2; |
4917 |
|
// |
4918 |
|
// handle missing calib2 |
4919 |
|
// |
4920 |
|
obt2 = 0; |
4921 |
|
pkt2 = 0; |
4922 |
|
valid = 0; |
4923 |
|
MISSING_pkt1 = false; |
4924 |
|
MISSING_pkt2 = true; |
4925 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4926 |
|
// |
4927 |
|
}; |
4928 |
|
// |
4929 |
|
|
4930 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
4931 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4932 |
|
ncalib++; |
4933 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4934 |
|
} |
4935 |
|
|
4936 |
|
|
4937 |
|
} else { |
4938 |
|
// |
4939 |
|
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
4940 |
|
// if ( PEDANTIC ) throw -79; |
4941 |
|
// |
4942 |
|
}; |
4943 |
|
// |
4944 |
|
|
4945 |
|
}; //end loop on pkt1 |
4946 |
|
|
4947 |
|
|
4948 |
|
|
4949 |
// |
// |
4950 |
}; |
// we have one more calib pkt2 ! |
4951 |
|
// |
4952 |
|
t2++; |
4953 |
|
while ( t2 < nevents2 ){ |
4954 |
|
// |
4955 |
|
// handle missing calib1 |
4956 |
|
// |
4957 |
|
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
4958 |
|
obt1 = 0; |
4959 |
|
pkt1 = 0; |
4960 |
|
// |
4961 |
|
tr2->GetEntry(t2); |
4962 |
|
ph2 = eh2->GetPscuHeader(); |
4963 |
|
obt2 = ph2->GetOrbitalTime(); |
4964 |
|
pkt2 = ph2->GetCounter(); |
4965 |
|
// |
4966 |
|
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
4967 |
|
valid = 0; |
4968 |
|
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
4969 |
|
// EMILIANO |
4970 |
|
if ( this->PKT(pkt2) >= this->PKT(pktfirst) && this->PKT(pkt2 <= upperpkt) && this->OBT(obt2) >= this->OBT(obtfirst) && this->OBT(obt2) <= upperobt ){ |
4971 |
|
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
4972 |
|
// |
4973 |
|
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
4974 |
|
// |
4975 |
|
MISSING_pkt1 = true; |
4976 |
|
MISSING_pkt2 = false; |
4977 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4978 |
|
ncalib++; |
4979 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4980 |
|
// |
4981 |
|
}; |
4982 |
|
// |
4983 |
|
t2++; |
4984 |
|
// |
4985 |
|
}; |
4986 |
|
|
4987 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4988 |
|
// ----------------------------------------------------------------- |
4989 |
|
// in case of corruption, check if the calibration can be recovered |
4990 |
|
// from another chewbacca file |
4991 |
|
// ----------------------------------------------------------------- |
4992 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4993 |
|
|
4994 |
|
// cout <<" TRY TO RECOVER ?? "<<try_to_recover<<endl; |
4995 |
|
|
4996 |
|
if(chewbacca&&try_to_recover){ |
4997 |
|
|
4998 |
|
|
4999 |
|
if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl; |
5000 |
|
|
5001 |
|
TSQLResult *result = 0; |
5002 |
|
TSQLRow *row = 0; |
5003 |
|
// |
5004 |
|
stringstream oss; |
5005 |
|
oss.str(""); |
5006 |
|
// |
5007 |
|
|
5008 |
|
//////////////////////////////////////////////////////////////////////// |
5009 |
|
// retrieve the name of the current file: |
5010 |
|
//////////////////////////////////////////////////////////////////////// |
5011 |
|
oss.str(""); |
5012 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << GetID_ROOT() <<";"; |
5013 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5014 |
|
|
5015 |
|
result = conn->Query(oss.str().c_str()); |
5016 |
|
if ( !result ) throw -4;; |
5017 |
|
row = result->Next(); |
5018 |
|
TString thisfilename = (TString)row->GetField(0); |
5019 |
|
if ( IsDebug() ) cout << "Current file ==> "<<thisfilename<<endl; |
5020 |
|
|
5021 |
|
//////////////////////////////////////////////////////////////////////// |
5022 |
|
// read all the calibrations inserted |
5023 |
|
//////////////////////////////////////////////////////////////////////// |
5024 |
|
oss.str(""); |
5025 |
|
oss << " SELECT "; |
5026 |
|
oss << " ID,FROM_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,TO_TIME"; |
5027 |
|
oss << " FROM GL_TRK_CALIB "; |
5028 |
|
oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; "; |
5029 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5030 |
|
|
5031 |
|
result = conn->Query(oss.str().c_str()); |
5032 |
|
if ( !result ) throw -4;; |
5033 |
|
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5034 |
|
|
5035 |
|
// ----------------------------------- |
5036 |
|
// loop over calibrations ... |
5037 |
|
// ----------------------------------- |
5038 |
|
UInt_t nn=0; |
5039 |
|
do { |
5040 |
|
row = result->Next(); |
5041 |
|
if(!row)break; |
5042 |
|
|
5043 |
|
UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5044 |
|
UInt_t fromtime = (UInt_t)atoll(row->GetField(1)); |
5045 |
|
UInt_t obt1 = (UInt_t)atoll(row->GetField(2)); |
5046 |
|
UInt_t pkt1 = (UInt_t)atoll(row->GetField(3)); |
5047 |
|
UInt_t obt2 = (UInt_t)atoll(row->GetField(4)); |
5048 |
|
UInt_t pkt2 = (UInt_t)atoll(row->GetField(5)); |
5049 |
|
UInt_t boot = (UInt_t)atoll(row->GetField(6)); |
5050 |
|
UInt_t valid = (UInt_t)atoll(row->GetField(7)); |
5051 |
|
bool MISSING_pkt1 = (row->GetFieldLength(8)==0); |
5052 |
|
bool MISSING_pkt2 = (row->GetFieldLength(9)==0); |
5053 |
|
UInt_t totime = (UInt_t)atoll(row->GetField(10)); |
5054 |
|
|
5055 |
|
// ------------------------------------- |
5056 |
|
// ...check if the entry is corrupted... |
5057 |
|
// ------------------------------------- |
5058 |
|
cout <<"*** "<< MISSING_pkt1 << MISSING_pkt2 << valid <<endl; |
5059 |
|
bool CORRUPTED = (MISSING_pkt1||MISSING_pkt2||!valid); |
5060 |
|
|
5061 |
|
if ( IsDebug() ) cout << "("<<nn<<") ID = "<<id<<" from GL_TRK_CALIB ==> corrupted ? "<<CORRUPTED<<endl; |
5062 |
|
|
5063 |
|
// if( !CORRUPTED )continue; // nothing to do |
5064 |
|
|
5065 |
|
///////////////////////////////////////////////////////// |
5066 |
|
// if it is corrupted, ...look for ather chewbacca files |
5067 |
|
// containing the same calibrations ... |
5068 |
|
///////////////////////////////////////////////////////// |
5069 |
|
|
5070 |
|
bool this_MISSING_pkt1 = false; |
5071 |
|
bool this_MISSING_pkt2 = false; |
5072 |
|
int this_t1=0; |
5073 |
|
int this_t2=0;; |
5074 |
|
UInt_t this_valid = 0; |
5075 |
|
|
5076 |
|
TString path = ""; |
5077 |
|
TString name = ""; |
5078 |
|
TString raw = ""; |
5079 |
|
UInt_t obt0 = 0; |
5080 |
|
UInt_t timesync = 0; |
5081 |
|
UInt_t boot_number = 0; |
5082 |
|
bool FOUND = false; |
5083 |
|
|
5084 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5085 |
|
|
5086 |
|
// for(int itable=0; itable<2; itable++){ |
5087 |
|
for(int itable=0; itable<1; itable++){ |
5088 |
|
|
5089 |
|
// ------------------------------------------------------ |
5090 |
|
// loop over both ROOT_TABLE and ROOT_TABLE_BAD |
5091 |
|
// ------------------------------------------------------ |
5092 |
|
|
5093 |
|
TString table = "ROOT_TABLE"; |
5094 |
|
if(itable==1)table = "ROOT_TABLE_BAD"; |
5095 |
|
|
5096 |
|
oss.str(""); |
5097 |
|
oss << " SELECT "; |
5098 |
|
oss << " FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,BOOT_NUMBER,INPUT_NAME "; |
5099 |
|
oss << " FROM "<<table; |
5100 |
|
oss << " WHERE 1 " << endl; |
5101 |
|
oss << " AND FILE_NAME != \""<< thisfilename<<"\""; |
5102 |
|
if( !MISSING_pkt1 ){ |
5103 |
|
oss << " AND "; |
5104 |
|
oss << " PKT_NUMBER_INIT < "<<pkt1; |
5105 |
|
oss << " AND "; |
5106 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt1; |
5107 |
|
oss << " AND "; |
5108 |
|
oss << " PKT_OBT_INIT < "<<obt1; |
5109 |
|
oss << " AND "; |
5110 |
|
oss << " PKT_OBT_FINAL > "<<obt1; |
5111 |
|
}else{ |
5112 |
|
if(pkt2>1) pkt1 = pkt2-1;//serve dopo |
5113 |
|
} |
5114 |
|
if( !MISSING_pkt2 ){ |
5115 |
|
oss << " AND "; |
5116 |
|
oss << " PKT_NUMBER_INIT < "<<pkt2; |
5117 |
|
oss << " AND "; |
5118 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt2; |
5119 |
|
oss << " AND "; |
5120 |
|
oss << " PKT_OBT_INIT < "<<obt2; |
5121 |
|
oss << " AND "; |
5122 |
|
oss << " PKT_OBT_FINAL > "<<obt2; |
5123 |
|
}else{ |
5124 |
|
if(pkt1>0) pkt2 = pkt1+1;//serve dopo |
5125 |
|
} |
5126 |
|
if( boot> 0 ){ |
5127 |
|
oss << " AND "; |
5128 |
|
oss << " BOOT_NUMBER = "<<boot; |
5129 |
|
}else{ |
5130 |
|
} |
5131 |
|
oss << " ORDER BY BAD_PKT_CALREAD ASC; "; |
5132 |
|
|
5133 |
|
TSQLResult *result2 = 0; |
5134 |
|
TSQLRow *row2 = 0; |
5135 |
|
|
5136 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5137 |
|
result2 = conn->Query(oss.str().c_str()); |
5138 |
|
if ( !result2 ) throw -4;; |
5139 |
|
if ( IsDebug() ) cout <<"Rows: "<<result2->GetRowCount()<<endl; |
5140 |
|
|
5141 |
|
// ------------------------------------------------------ |
5142 |
|
// loop over files containing repetition (if any) |
5143 |
|
// ------------------------------------------------------ |
5144 |
|
do { |
5145 |
|
row2 = result2->Next(); |
5146 |
|
if(!row2)break; |
5147 |
|
|
5148 |
|
// ------------------------------------------------------ |
5149 |
|
// ... a repetition is found ... |
5150 |
|
// ------------------------------------------------------ |
5151 |
|
path = (TString)row2->GetField(0); |
5152 |
|
name = (TString)row2->GetField(1); |
5153 |
|
raw = (TString)row2->GetField(5); |
5154 |
|
obt0 = (UInt_t)atoll(row2->GetField(2)); |
5155 |
|
timesync = (UInt_t)atoll(row2->GetField(3)); |
5156 |
|
boot_number = (UInt_t)atoll(row2->GetField(4)); |
5157 |
|
|
5158 |
|
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
5159 |
|
// cout << path <<endl; |
5160 |
|
// cout << "File : " <<name <<endl; |
5161 |
|
// cout << obt0 <<endl; |
5162 |
|
// cout << timesync <<endl; |
5163 |
|
// cout << "boot n. : "<<boot_number <<endl; |
5164 |
|
// cout << raw <<endl; |
5165 |
|
|
5166 |
|
// ------------------------------------------------------ |
5167 |
|
// ... retrieve the calibration packets. |
5168 |
|
// ------------------------------------------------------ |
5169 |
|
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5170 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5171 |
|
if(!file)throw -100; |
5172 |
|
if(file->IsZombie())throw -100; |
5173 |
|
// |
5174 |
|
tr1 = (TTree*)file->Get("CalibTrk1"); |
5175 |
|
if ( !tr1 || tr1->IsZombie() ) throw -22; |
5176 |
|
tr2 = (TTree*)file->Get("CalibTrk2"); |
5177 |
|
if ( !tr2 || tr2->IsZombie() ) throw -23; |
5178 |
|
// |
5179 |
|
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
5180 |
|
tr1->SetBranchAddress("Header", &eh1); |
5181 |
|
nevents1 = tr1->GetEntries(); |
5182 |
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
5183 |
|
tr2->SetBranchAddress("Header", &eh2); |
5184 |
|
nevents2 = tr2->GetEntries(); |
5185 |
|
for(this_t1=0; this_t1<nevents1; this_t1++){ |
5186 |
|
tr1->GetEntry(this_t1); |
5187 |
|
if( |
5188 |
|
(UInt_t)eh1->GetPscuHeader()->GetCounter() == pkt1 && |
5189 |
|
true) break; |
5190 |
|
this_MISSING_pkt1 = true; |
5191 |
|
} |
5192 |
|
for(this_t2=0; this_t2<nevents2; this_t2++){ |
5193 |
|
tr2->GetEntry(this_t2); |
5194 |
|
if( |
5195 |
|
(UInt_t)eh2->GetPscuHeader()->GetCounter() == pkt2 && |
5196 |
|
true) break; |
5197 |
|
this_MISSING_pkt2 = true; |
5198 |
|
} |
5199 |
|
this_valid = |
5200 |
|
ValidateTrkCalib( caltrk1, eh1, file ) |
5201 |
|
* |
5202 |
|
ValidateTrkCalib( caltrk2, eh2, file ); |
5203 |
|
|
5204 |
|
// --------------------------------------------------------------------- |
5205 |
|
// accept the calibration if it is better than the previous: |
5206 |
|
// |
5207 |
|
// - if the new calibration is perfect (both valid packets) |
5208 |
|
// - if the new calibration has both the packets and the previous does not |
5209 |
|
// --------------------------------------------------------------------- |
5210 |
|
if( |
5211 |
|
( !this_MISSING_pkt1&&!this_MISSING_pkt2&&this_valid )|| |
5212 |
|
( (MISSING_pkt1||MISSING_pkt2) && (!this_MISSING_pkt1&&!this_MISSING_pkt2) )|| |
5213 |
|
false)FOUND=true; |
5214 |
|
|
5215 |
|
if(file)file->Close(); |
5216 |
|
|
5217 |
|
if(FOUND)break; |
5218 |
|
|
5219 |
|
}while(1);//endl loop over root table entries |
5220 |
|
|
5221 |
|
if(FOUND)break; |
5222 |
|
|
5223 |
|
}//end loop over tables |
5224 |
|
|
5225 |
|
if(FOUND){ |
5226 |
|
|
5227 |
|
if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl; |
5228 |
|
|
5229 |
|
//////////////////////////////////////////// |
5230 |
|
// insert a new entry in GL_TRK_CALIB and |
5231 |
|
// modify the time-tag of the previous one |
5232 |
|
//////////////////////////////////////////// |
5233 |
|
|
5234 |
|
// --------------------------------------------------------------------- |
5235 |
|
// step 1: insert a new raw file in GL_RAW |
5236 |
|
// --------------------------------------------------------------------- |
5237 |
|
// |
5238 |
|
// check if the raw file already exist |
5239 |
|
// |
5240 |
|
UInt_t id_raw = 0; // EM GL_RAW is there only for backward compatibility so we do not need to fill it when in "chewbacca" mode |
5241 |
|
// oss.str(""); |
5242 |
|
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5243 |
|
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5244 |
|
|
5245 |
|
// result = conn->Query(oss.str().c_str()); |
5246 |
|
// if ( !result ) throw -4;; |
5247 |
|
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5248 |
|
// if( result->GetRowCount() == 0){ |
5249 |
|
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5250 |
|
// // - - - - - - - - - - - |
5251 |
|
// // insert new raw file |
5252 |
|
// // - - - - - - - - - - - |
5253 |
|
// GL_RAW glraw = GL_RAW(); |
5254 |
|
// glraw.PATH = gSystem->DirName(raw.Data()); |
5255 |
|
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5256 |
|
// glraw.BOOT_NUMBER = boot_number; |
5257 |
|
// // |
5258 |
|
// insertPamelaRawFile( &glraw ); |
5259 |
|
// // |
5260 |
|
// id_raw = glraw.ID; |
5261 |
|
// }else{ |
5262 |
|
// row = result->Next(); |
5263 |
|
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5264 |
|
// } |
5265 |
|
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5266 |
|
|
5267 |
|
// --------------------------------------------------------------------- |
5268 |
|
// step 1(bis): retrieve the timesync id associated to the file |
5269 |
|
// (NB, uso lo stesso associato al file iniziale) |
5270 |
|
// --------------------------------------------------------------------- |
5271 |
|
UInt_t idtimesync = 0; |
5272 |
|
oss.str(""); |
5273 |
|
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
5274 |
|
if ( debug ) printf(" %s \n",oss.str().c_str()); |
5275 |
|
result = conn->Query(oss.str().c_str()); |
5276 |
|
if ( !result ) throw -3; |
5277 |
|
row = result->Next(); |
5278 |
|
if ( !row ) throw -3; |
5279 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
5280 |
|
if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl; |
5281 |
|
|
5282 |
|
// --------------------------------------------------------------------- |
5283 |
|
// step 2: insert a new root file in GL_ROOT |
5284 |
|
// --------------------------------------------------------------------- |
5285 |
|
// |
5286 |
|
// check if the root file already exist |
5287 |
|
// |
5288 |
|
UInt_t id_root = 0; |
5289 |
|
oss.str(""); |
5290 |
|
oss << "SELECT ID FROM GL_ROOT where NAME=\"" << gSystem->BaseName(name.Data()) <<"\";"; |
5291 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5292 |
|
|
5293 |
|
result = conn->Query(oss.str().c_str()); |
5294 |
|
if ( !result ) throw -4;; |
5295 |
|
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5296 |
|
if( result->GetRowCount() == 0){ |
5297 |
|
if ( IsDebug() ) cout << " << Insert new ROOT file >> "<<endl; |
5298 |
|
// - - - - - - - - - - - |
5299 |
|
// insert new root file |
5300 |
|
// - - - - - - - - - - - |
5301 |
|
GL_ROOT glroot = GL_ROOT(); |
5302 |
|
glroot.ID_RAW = id_raw; |
5303 |
|
glroot.ID_TIMESYNC = idtimesync; |
5304 |
|
// |
5305 |
|
// EM STATIC = the full expanded path must be put in the DB, KEEPENV = the path given as input (or found in ROOT_TABLE) must be used, |
5306 |
|
// NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB |
5307 |
|
// |
5308 |
|
if ( STATIC ){ |
5309 |
|
glroot.PATH = (TString)gSystem->ExpandPathName(path); |
5310 |
|
} else { |
5311 |
|
if ( KEEPENV ){ |
5312 |
|
glroot.PATH = path; |
5313 |
|
} else { |
5314 |
|
glroot.PATH = "$PAM_L0"; |
5315 |
|
}; |
5316 |
|
}; |
5317 |
|
// glroot.PATH = path; |
5318 |
|
glroot.NAME = name; |
5319 |
|
// |
5320 |
|
insertPamelaRootFile( &glroot ); |
5321 |
|
// |
5322 |
|
id_root = glroot.ID; |
5323 |
|
}else{ |
5324 |
|
row = result->Next(); |
5325 |
|
if(row)id_root = (UInt_t)atoll(row->GetField(0)); |
5326 |
|
} |
5327 |
|
if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl; |
5328 |
|
|
5329 |
|
// --------------------------------------------------------------------- |
5330 |
|
// step 3: modify time-tag of corrupted GL_TRK_CALIB entry |
5331 |
|
// --------------------------------------------------------------------- |
5332 |
|
if ( IsDebug() ) cout << " << Modify time-tag of calibration ID="<<id<<" >> "<<endl; |
5333 |
|
oss.str(""); |
5334 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
5335 |
|
<< " TO_TIME=0 , FROM_TIME=0 WHERE " |
5336 |
|
<< " ID = "<< id << ";"; |
5337 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5338 |
|
result = conn->Query(oss.str().c_str()); |
5339 |
|
if ( !result ) throw -4;; |
5340 |
|
|
5341 |
|
// --------------------------------------------------------------------- |
5342 |
|
// step 4: insert the new calibration: |
5343 |
|
// --------------------------------------------------------------------- |
5344 |
|
if ( IsDebug() ) cout << " << Insert new TRK calibration >> "<<endl; |
5345 |
|
// |
5346 |
|
GL_TRK_CALIB glcal = GL_TRK_CALIB(); |
5347 |
|
// |
5348 |
|
glcal.ID_ROOT_L0 = id_root; |
5349 |
|
glcal.EV_ROOT_CALIBTRK1 = this_t1; |
5350 |
|
glcal.EV_ROOT_CALIBTRK2 = this_t2; |
5351 |
|
glcal.FROM_TIME = fromtime; |
5352 |
|
glcal.TO_TIME = totime; |
5353 |
|
glcal.OBT1 = obt1; |
5354 |
|
glcal.OBT2 = obt2; |
5355 |
|
glcal.PKT1 = pkt1; |
5356 |
|
glcal.PKT2 = pkt1; |
5357 |
|
glcal.BOOT_NUMBER = GetBOOTnumber(); |
5358 |
|
glcal.VALIDATION = this_valid; |
5359 |
|
// |
5360 |
|
HandleTRK_CALIB(&glcal); |
5361 |
|
if ( IsDebug() ) cout << "ID = "<<glcal.ID<<endl; |
5362 |
|
// |
5363 |
|
|
5364 |
|
} |
5365 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5366 |
|
|
5367 |
|
}while(1);//end loop over calibrations |
5368 |
|
|
5369 |
|
|
5370 |
|
if( result )delete result; |
5371 |
|
if( row )delete row; |
5372 |
|
|
5373 |
|
|
5374 |
|
|
5375 |
|
|
5376 |
|
|
5377 |
|
|
5378 |
|
} |
5379 |
|
|
5380 |
|
|
5381 |
|
// // ------------------------------ |
5382 |
|
// // try to recover the calibration |
5383 |
|
// // ------------------------------ |
5384 |
|
// cout << "TRY TO RECOVER TRACKER CALIBRATION"<<endl; |
5385 |
|
// // |
5386 |
|
// ULong64_t time = 0; //absolute time |
5387 |
|
// string path[100]; //mettere un limite massimo |
5388 |
|
// int nrows = 0; |
5389 |
|
// UInt_t pkt = 0; |
5390 |
|
// UInt_t obt = 0; |
5391 |
|
// char *type = ""; |
5392 |
|
// EventHeader *eh = new EventHeader(); |
5393 |
|
// CalibTrk1Event *c = new CalibTrk1Event(); |
5394 |
|
|
5395 |
|
// // |
5396 |
|
// if(which_is_not_valid==1 || which_is_not_valid==3){ |
5397 |
|
// // |
5398 |
|
// cout << "PKT1 --> missing or corrupted "<<endl; |
5399 |
|
// type = "CalibTrk1"; |
5400 |
|
// pkt = pkt1; |
5401 |
|
// obt = obt1; |
5402 |
|
// time = this->GetAbsTime(obt1); |
5403 |
|
// if( pkt1 == 0 ){//missing |
5404 |
|
// time = this->GetAbsTime(obt2); |
5405 |
|
// pkt = pkt2-1; |
5406 |
|
// } |
5407 |
|
// // |
5408 |
|
// }else if (which_is_not_valid==2 || which_is_not_valid==3){ |
5409 |
|
// // |
5410 |
|
// cout << "PKT2--> missing or corrupted "<<endl; |
5411 |
|
// type = "CalibTrk2 "; |
5412 |
|
// pkt = pkt2; |
5413 |
|
// obt = obt2; |
5414 |
|
// time = this->GetAbsTime(obt2); |
5415 |
|
// if( pkt2 == 0 ){//missing |
5416 |
|
// time = this->GetAbsTime(obt1); |
5417 |
|
// pkt = pkt1+1; |
5418 |
|
// } |
5419 |
|
// // |
5420 |
|
// }else{ |
5421 |
|
// cout << "this should not happen!!! "<<endl; |
5422 |
|
// trow -666; |
5423 |
|
// } |
5424 |
|
|
5425 |
|
// nrows = Query_ROOT_TABLE(time,conn,path);// get the list of file which might contain the packet |
5426 |
|
|
5427 |
|
|
5428 |
|
// for(int r=0; r<nrows; r++){ //loop over rows |
5429 |
|
// if(path)cout << r << " >>>> "<<(path+r)->c_str() << endl; |
5430 |
|
// /// verifica che il file non sia quello gia` aperto |
5431 |
|
// } |
5432 |
|
|
5433 |
|
// //////////////////////////////////////////////////////////////////////// |
5434 |
|
|
5435 |
|
// TSQLResult *result = 0; |
5436 |
|
// TSQLRow *row = 0; |
5437 |
|
// // |
5438 |
|
// stringstream oss; |
5439 |
|
// oss.str(""); |
5440 |
|
// // ---------------------------------------- |
5441 |
|
// // read the id of last calibration inserted |
5442 |
|
// // ---------------------------------------- |
5443 |
|
// oss.str(""); |
5444 |
|
// oss << " SELECT "; |
5445 |
|
// oss << " (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) "; |
5446 |
|
// oss << " ORDER BY ID DESC LIMIT 1; "; |
5447 |
|
|
5448 |
|
// result = conn->Query(oss.str().c_str()); |
5449 |
|
// row = result->Next(); |
5450 |
|
// if( !row )throw -666; |
5451 |
|
|
5452 |
|
// if( result )delete result; |
5453 |
|
// if( row )delete row; |
5454 |
|
|
5455 |
|
// UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5456 |
|
|
5457 |
|
// // ------------------------------------- |
5458 |
|
// // ...and modify it with new parameters |
5459 |
|
// // ------------------------------------- |
5460 |
|
|
5461 |
|
|
5462 |
|
// } |
5463 |
// |
// |
5464 |
return(0); |
return(0); |
5465 |
}; |
}; |
6091 |
// 2) get the OBT of the last validated run |
// 2) get the OBT of the last validated run |
6092 |
// -------------------------------------------------------------- |
// -------------------------------------------------------------- |
6093 |
oss.str(""); |
oss.str(""); |
6094 |
oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
// oss << " SELECT * FROM GL_RUN WHERE VALIDATION=1 AND RUNHEADER_TIME<="<< t_start |
6095 |
|
oss << " SELECT * FROM GL_RUN WHERE VALIDATION>0 AND RUNHEADER_TIME<="<< t_start |
6096 |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
<<" ORDER BY RUNHEADER_TIME DESC LIMIT 1;"; |
6097 |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
if ( IsDebug() ) printf(" Get stop validation-time: query is \n %s \n",oss.str().c_str()); |
6098 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
6235 |
if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration |
if( interval >= calibtime )CHECK = true; //more than calibtime s => there might be a calibration |
6236 |
|
|
6237 |
if( !CHECK && this_run->VALIDATION ){ |
if( !CHECK && this_run->VALIDATION ){ |
6238 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
// for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],true); |
6239 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],this_run->VALIDATION); |
6240 |
nseq=0; |
nseq=0; |
6241 |
} |
} |
6242 |
|
|
6257 |
if( CHECK ){ |
if( CHECK ){ |
6258 |
// check if calibration exists |
// check if calibration exists |
6259 |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
if ( IsDebug() )printf("DT %i ===> CHECK Missing calibration\n",interval); |
6260 |
Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
// Bool_t MISSING = MissingTRK_CALIB(t1,t2); |
6261 |
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],!MISSING); |
UInt_t MISSING = MissingTRK_CALIB(t1,t2); |
6262 |
|
UInt_t val = 0; |
6263 |
|
if ( MISSING == 1 ) val = 0; |
6264 |
|
if ( MISSING == 0 ) val = 1; |
6265 |
|
if ( MISSING == 2 ) val = 2; |
6266 |
|
for (Int_t irun = 0; irun < nseq; irun++)assignVALIDATION(sequence[irun],val); |
6267 |
nseq=0; |
nseq=0; |
6268 |
}; |
}; |
6269 |
//-------------- |
//-------------- |
6293 |
* @param t2 To absolute time |
* @param t2 To absolute time |
6294 |
* @return true if there might be a missing calibration |
* @return true if there might be a missing calibration |
6295 |
*/ |
*/ |
6296 |
Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
//Bool_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6297 |
|
UInt_t PamelaDBOperations::MissingTRK_CALIB(UInt_t t1,UInt_t t2){ |
6298 |
|
|
6299 |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
6300 |
|
|
6301 |
// get the closest VALIDATED calibration before the run start (t2) |
// get the closest calibration before the run start (t2) |
6302 |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
// if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
6303 |
|
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(1); //>>> missing |
6304 |
|
|
6305 |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
// if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
6306 |
|
if ( trkcalib->TO_TIME < t2 ) return(1); //>>> missing |
6307 |
|
|
6308 |
//============================================================== |
//============================================================== |
6309 |
// Check is done first on the basis of time between calibration, |
// Check is done first on the basis of time between calibration, |
6320 |
//============================================================== |
//============================================================== |
6321 |
Bool_t DOWNLOAD = false; |
Bool_t DOWNLOAD = false; |
6322 |
// check if the calib was skipped becouse of download .... DA FARE!! |
// check if the calib was skipped becouse of download .... DA FARE!! |
6323 |
if(DOWNLOAD)return(false); |
// if(DOWNLOAD)return(false); |
6324 |
|
if(DOWNLOAD)return(0); |
6325 |
|
|
6326 |
return(true); //>>> missing |
// return(true); //>>> missing |
6327 |
|
return(1); //>>> missing |
6328 |
|
|
6329 |
}; |
}; |
6330 |
|
|
6334 |
//============================================================== |
//============================================================== |
6335 |
// the long time interval bewteen runs might be due to download |
// the long time interval bewteen runs might be due to download |
6336 |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
if ( IsDebug() )printf("Short time between calib and run start %u :-) ==> OK! \n",t2 - trkcalib->FROM_TIME); |
6337 |
return(false); |
if ( trkcalib->VALIDATION ) return(0); |
6338 |
|
if ( IsDebug() )printf("Calibration is not validated... :-/ ==> OK but with VALIDATION=2! \n"); |
6339 |
|
return(2); |
6340 |
|
|
6341 |
}; |
}; |
6342 |
/** |
/** |
6345 |
* @param validation true/false |
* @param validation true/false |
6346 |
*/ |
*/ |
6347 |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, Bool_t validation){ |
6348 |
|
return(this->assignVALIDATION(idrun,(UInt_t)validation)); |
6349 |
|
} |
6350 |
|
|
6351 |
|
Int_t PamelaDBOperations::assignVALIDATION(UInt_t idrun, UInt_t validation){ |
6352 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
6353 |
stringstream oss; |
stringstream oss; |
6354 |
oss.str(""); |
oss.str(""); |
6545 |
stringstream myquery; |
stringstream myquery; |
6546 |
// |
// |
6547 |
myquery.str(""); |
myquery.str(""); |
6548 |
myquery << " SELECT ID, ID_RAW FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
myquery << " SELECT ID,ID_RAW,ID_TIMESYNC FROM GL_ROOT where NAME='"<<remfile.Data() <<"';"; |
6549 |
// |
// |
6550 |
pResult = conn->Query(myquery.str().c_str()); |
pResult = conn->Query(myquery.str().c_str()); |
6551 |
// |
// |
6561 |
// |
// |
6562 |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
this->SetID_ROOT((UInt_t)atoll(Row->GetField(0))); |
6563 |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
this->SetID_RAW((UInt_t)atoll(Row->GetField(1))); |
6564 |
|
UInt_t idtsy=(UInt_t)atoll(Row->GetField(2)); |
6565 |
// |
// |
6566 |
this->ValidationOFF(); |
this->ValidationOFF(); |
6567 |
// |
// |
6569 |
// |
// |
6570 |
this->RemoveRUNS(); |
this->RemoveRUNS(); |
6571 |
// |
// |
6572 |
this->RemoveFILES(); |
this->RemoveFILES(idtsy); |
6573 |
// |
// |
6574 |
this->SetID_ROOT(0); |
this->SetID_ROOT(0); |
6575 |
this->SetID_RAW(0); |
this->SetID_RAW(0); |
6789 |
* Rearrange calibration tables |
* Rearrange calibration tables |
6790 |
* |
* |
6791 |
**/ |
**/ |
6792 |
void PamelaDBOperations::RemoveFILES(){ |
void PamelaDBOperations::RemoveFILES(UInt_t idtsy){ |
6793 |
stringstream myquery; |
stringstream myquery; |
6794 |
// |
// |
6795 |
myquery.str(""); |
myquery.str(""); |
6799 |
// |
// |
6800 |
conn->Query(myquery.str().c_str()); |
conn->Query(myquery.str().c_str()); |
6801 |
// |
// |
6802 |
|
myquery.str(""); |
6803 |
|
myquery << " DELETE FROM GL_ROOT WHERE ID=" <<this->GetID_ROOT() <<";"; |
6804 |
|
// |
6805 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6806 |
|
// |
6807 |
|
conn->Query(myquery.str().c_str()); // |
6808 |
|
// |
6809 |
|
if ( !chewbacca ){ |
6810 |
|
myquery.str(""); |
6811 |
|
myquery << " DELETE FROM GL_TIMESYNC WHERE ID=" << idtsy <<";"; |
6812 |
|
// |
6813 |
|
if ( IsDebug() ) printf(" query is \n %s \n",myquery.str().c_str()); |
6814 |
|
// |
6815 |
|
conn->Query(myquery.str().c_str()); |
6816 |
|
}; |
6817 |
|
// |
6818 |
}; |
}; |
6819 |
|
|
6820 |
/** |
/** |
7019 |
* Rearrange calibration tables |
* Rearrange calibration tables |
7020 |
* |
* |
7021 |
**/ |
**/ |
7022 |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh , TFile *file){ |
7023 |
|
|
7024 |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
if(!caltrk) return 0; |
|
UInt_t timeaftercalib=120000; //2000; |
|
|
// ---------- |
|
|
// Check CRCs |
|
|
// ---------- |
|
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
|
|
if( caltrk->crc_hcal[ipkt] )return 0; // :-( |
|
|
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] )return 0; // :-( |
|
|
} |
|
|
// ----------------------- |
|
|
// Check missing packets: |
|
|
// ----------------------- |
|
|
// Readout order: |
|
|
// ------------------ |
|
|
// DSP packet board |
|
|
// ------------------ |
|
|
// 12 0 1 |
|
|
// 10 1 1 |
|
|
// 8 2 1 |
|
|
// 4 3 1 |
|
|
// 6 4 1 |
|
|
// 2 5 1 |
|
|
// ------------------ |
|
|
// 11 0 2 |
|
|
// 9 1 2 |
|
|
// 7 2 2 |
|
|
// 3 3 2 |
|
|
// 5 4 2 |
|
|
// 1 5 2 |
|
|
// ------------------ |
|
|
// ------------------------------------------------- |
|
|
// Check if it is first or second calibration packet |
|
|
// ------------------------------------------------- |
|
|
UInt_t build=0; |
|
|
TString classname = caltrk->GetName(); |
|
|
UInt_t base=0; |
|
|
UInt_t mask=0; |
|
|
if(classname.Contains("CalibTrk1Event")){ |
|
|
base=12; |
|
|
mask=0x03F000; |
|
|
} |
|
|
if(classname.Contains("CalibTrk2Event")){ |
|
|
base=18; |
|
|
mask=0xFC0000; |
|
|
} |
|
|
// ------------------------------------------------- |
|
|
// Count number of packets and set build variable |
|
|
// ------------------------------------------------- |
|
|
Int_t npkts=0; |
|
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
|
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
|
|
npkts++; |
|
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
|
|
} |
|
|
} |
|
|
// if( npkts==6 )return 1; // :-) |
|
7025 |
|
|
7026 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
if ( IsDebug() ) cout << "ValidateTrkCalib:"<<endl; |
7027 |
|
|
7028 |
// ----------------------------------------------- |
UInt_t validate = 1; |
7029 |
// If missing packets: check the acq configuration |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
7030 |
// (some DSPs might be excluded from acquisition) |
UInt_t timeaftercalib=120000; //2000; |
7031 |
// ----------------------------------------------- |
TString classname = caltrk->GetName(); |
7032 |
|
|
7033 |
// ----------------------------------------------- |
// ---------------------------------- |
7034 |
// retrieve the first run header after calib |
// Check CRCs and failed calibrations |
7035 |
// ----------------------------------------------- |
// ---------------------------------- |
7036 |
PacketType *pctp; |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7037 |
EventCounter *cod; |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7038 |
cod = eh->GetCounter(); |
if( caltrk->crc_hcal[ipkt] ){ |
7039 |
Int_t irun = cod->Get(pctp->RunHeader); |
// if(IsDebug())cout<<"(CRC Header)"; |
7040 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
validate = 0; |
7041 |
if ( !rh || rh->IsZombie() ) throw -17; |
if(IsDebug())cout <<endl<<" *** CRC *** (header DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
7042 |
if( rh->GetEntries() == irun ){ |
|
7043 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
} |
7044 |
return 0; // :-( |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
7045 |
} |
// if(IsDebug())cout<<"(CRC Pkt-"<<ilad<<")"; |
7046 |
|
if(IsDebug())cout <<endl<<" *** CRC *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<" ladder "<<ilad<<")"; |
7047 |
|
validate = 0; |
7048 |
|
} |
7049 |
|
if( !(caltrk->ncalib_event[ipkt]==0 && caltrk->cal_flag[ipkt]==0) ){ |
7050 |
|
if(IsDebug())cout <<endl<<" *** FAILURE *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
7051 |
|
validate = 0; |
7052 |
|
} |
7053 |
|
}else{ |
7054 |
|
// validate=0; |
7055 |
|
if(IsDebug())cout <<endl<<" *** DSPn *** ("<< caltrk->DSPnumber[ipkt] <<" @pkt "<<ipkt<<")"; |
7056 |
|
} |
7057 |
|
} |
7058 |
|
|
7059 |
RunHeaderEvent *run = 0; |
// ----------------------- |
7060 |
EventHeader *hrun = 0; |
// Check missing packets: |
7061 |
rh->SetBranchAddress("RunHeader", &run); |
// ----------------------- |
7062 |
rh->SetBranchAddress("Header", &hrun); |
// Readout order: |
7063 |
rh->GetEntry(irun); |
// ------------------ |
7064 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
// DSP packet board |
7065 |
|
// ------------------ |
7066 |
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
// 12 0 1 |
7067 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
// 10 1 1 |
7068 |
return 0; // :-( |
// 8 2 1 |
7069 |
} |
// 4 3 1 |
7070 |
|
// 6 4 1 |
7071 |
if( !run->RM_ACQ_AFTER_CALIB ){ |
// 2 5 1 |
7072 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
// ------------------ |
7073 |
return 0; // :-( |
// 11 0 2 |
7074 |
} |
// 9 1 2 |
7075 |
|
// 7 2 2 |
7076 |
|
// 3 3 2 |
7077 |
|
// 5 4 2 |
7078 |
|
// 1 5 2 |
7079 |
|
// ------------------ |
7080 |
|
// ------------------------------------------------- |
7081 |
|
// Check if it is first or second calibration packet |
7082 |
|
// ------------------------------------------------- |
7083 |
|
UInt_t build=0; |
7084 |
|
UInt_t base=0; |
7085 |
|
UInt_t mask=0; |
7086 |
|
if(classname.Contains("CalibTrk1Event")){ |
7087 |
|
base=12; |
7088 |
|
mask=0x03F000; |
7089 |
|
} |
7090 |
|
if(classname.Contains("CalibTrk2Event")){ |
7091 |
|
base=18; |
7092 |
|
mask=0xFC0000; |
7093 |
|
} |
7094 |
|
// ---------------------------------------------------- |
7095 |
|
// Count number of valid packets and set build variable |
7096 |
|
// ---------------------------------------------------- |
7097 |
|
if(IsDebug())cout <<endl<< " DSP: "; |
7098 |
|
Int_t npkts=0; |
7099 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7100 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7101 |
|
if(IsDebug())cout <<" "<<caltrk->DSPnumber[ipkt]; |
7102 |
|
npkts++; |
7103 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
7104 |
|
// cout << caltrk->DSPnumber[ipkt] |
7105 |
|
}; |
7106 |
|
} |
7107 |
|
if(IsDebug())cout << " ==> "<< hex << build << dec; |
7108 |
|
// ---------------------------------------------------- |
7109 |
|
// If the number of valid packets is 6, ok exit... |
7110 |
|
// ---------------------------------------------------- |
7111 |
|
if( npkts==6 ){ |
7112 |
|
return validate; // exit |
7113 |
|
} |
7114 |
|
//////////////////////////////////////////////////////// |
7115 |
|
// ...otherwise there might be some missing packets |
7116 |
|
// |
7117 |
|
// In this case check the acq configuration |
7118 |
|
// (some DSPs might be excluded from acquisition) |
7119 |
|
//////////////////////////////////////////////////////// |
7120 |
|
|
7121 |
|
if(!eh || !file || (file&&file->IsZombie()) ){ |
7122 |
|
if ( IsDebug() )cout << " *** MISSING VIEW *** eh="<<eh<<" file="<<file<<" cannot validate"<<endl; |
7123 |
|
return (0); |
7124 |
|
} |
7125 |
|
|
7126 |
|
// ----------------------------------------------- |
7127 |
|
// retrieve the first run header after calib |
7128 |
|
// ----------------------------------------------- |
7129 |
|
|
7130 |
|
PacketType *pctp; |
7131 |
|
EventCounter *cod; |
7132 |
|
cod = eh->GetCounter(); |
7133 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
7134 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
7135 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
7136 |
|
if( rh->GetEntries() <= irun ){ |
7137 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (1) -- cannot validate :-( "<<endl; |
7138 |
|
return 0; // :-( |
7139 |
|
} |
7140 |
|
RunHeaderEvent *run = 0; |
7141 |
|
EventHeader *hrun = 0; |
7142 |
|
rh->SetBranchAddress("RunHeader", &run); |
7143 |
|
rh->SetBranchAddress("Header", &hrun); |
7144 |
|
rh->GetEntry(irun); |
7145 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
7146 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (2) -- cannot validate :-( "<<endl; |
7147 |
|
return 0; // :-( |
7148 |
|
} |
7149 |
|
|
7150 |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
7151 |
if( dtime > timeaftercalib ){ |
if( dtime > timeaftercalib ){ |
7152 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
if ( IsDebug() ) cout << " *** MISSING-PKT *** run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
7153 |
return 0; // :-( |
return 0; // :-( |
7154 |
} |
} |
|
|
|
7155 |
|
|
7156 |
|
if ( IsDebug() ) cout <<endl<< " ACQ_BUILD_INFO ==> "<<hex<<(run->ACQ_BUILD_INFO & mask)<<dec; |
7157 |
|
|
7158 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
7159 |
|
validate=0; // :-( |
7160 |
|
cout <<endl<< " *** MISSING-PKT *** packet mismatch: ACQ_BUILD_INFO="<<hex<<(run->ACQ_BUILD_INFO&mask)<<" != "<<build<<dec; |
7161 |
|
}; |
7162 |
|
|
7163 |
|
return validate; |
7164 |
|
|
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
|
|
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) ACQ_BUILD_INFO= >>> "<<hex << (run->ACQ_BUILD_INFO&mask) << " != "<< build << dec<<endl; |
|
|
return 0; // :-( |
|
|
} |
|
|
return 1; // :-) |
|
7165 |
|
|
7166 |
} |
} |
7167 |
|
|