38 |
fPsw = new TString(psw.Data()); |
fPsw = new TString(psw.Data()); |
39 |
fSet = true; |
fSet = true; |
40 |
fNquery = 0; |
fNquery = 0; |
41 |
|
mh = host.Data(); |
42 |
|
mu = user.Data(); |
43 |
|
mp = psw.Data(); |
44 |
}; |
}; |
45 |
|
|
46 |
|
|
50 |
fPsw = new TString(psw.Data()); |
fPsw = new TString(psw.Data()); |
51 |
fSet = true; |
fSet = true; |
52 |
fNquery = 0; |
fNquery = 0; |
53 |
|
mh = host.Data(); |
54 |
|
mu = user.Data(); |
55 |
|
mp = psw.Data(); |
56 |
}; |
}; |
57 |
|
|
58 |
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
59 |
// |
// |
60 |
// |
// |
61 |
// |
// |
65 |
// |
// |
66 |
// |
// |
67 |
// |
// |
68 |
// printf(" host is %s \n",fHost->Data()); |
// printf(" host is %s \n",fHost->Data()); |
69 |
// |
// |
70 |
stringstream myquery; |
stringstream myquery; |
71 |
myquery.str(""); |
myquery.str(""); |
72 |
myquery << "show databases;"; |
myquery << "show databases;"; |
73 |
dbc->Query(myquery.str().c_str()); |
if ( dbc ){ |
74 |
fNquery++; |
if ( dbc->IsConnected() ){ |
75 |
// |
dbc->Query(myquery.str().c_str()); |
76 |
if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
fNquery++; |
77 |
// is connected |
if ( !(dbc->GetErrorCode()) ){ |
78 |
return true; |
// printf("ok\n"); |
79 |
} else { |
// |
80 |
|
// if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ |
81 |
|
// if ( !(dbc->GetErrorCode()) ){ |
82 |
|
// is connected |
83 |
|
return true; |
84 |
|
// }; |
85 |
|
}; |
86 |
|
}; |
87 |
|
}; |
88 |
|
// printf("porca di quella \n"); |
89 |
|
if ( true ) { |
90 |
// |
// |
91 |
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
92 |
// |
// |
100 |
myquery << "show databases;"; |
myquery << "show databases;"; |
101 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
102 |
fNquery++; |
fNquery++; |
103 |
|
// printf(" e riporca di quella \n"); |
104 |
// |
// |
105 |
if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
106 |
|
if ( !(dbc->GetErrorCode()) ){ |
107 |
// |
// |
108 |
printf(" ...connection recovered, I can continue! \n"); |
printf(" ...connection recovered, I can continue! \n"); |
109 |
// |
// |
264 |
GL_TIMESYNC::GL_TIMESYNC(){ |
GL_TIMESYNC::GL_TIMESYNC(){ |
265 |
obtfirst = 0; |
obtfirst = 0; |
266 |
pktfirst = 0; |
pktfirst = 0; |
267 |
toffset = 0; |
ID_RESURS_OFFSET = 0; |
268 |
// ID = 0; |
ID = 0; |
269 |
// ID_RAW = 0; |
ID_RAW = 0; |
270 |
OBT0 = 0; |
OBT0 = 0; |
271 |
TIMESYNC = 0; |
TIMESYNC = 0; |
272 |
TYPE = 0; |
TYPE = 0; |
1163 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1164 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1165 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1166 |
if(t==3) PATH = Row->GetField(t); |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
1167 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
1168 |
}; |
}; |
1169 |
}; |
}; |
1188 |
// ---------------- |
// ---------------- |
1189 |
myquery.str(""); |
myquery.str(""); |
1190 |
myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2,BOOT_NUMBER,VALIDATION from GL_TRK_CALIB where FROM_TIME <= "<< time; |
myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2,BOOT_NUMBER,VALIDATION from GL_TRK_CALIB where FROM_TIME <= "<< time; |
1191 |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!! |
1192 |
|
myquery << " and EV_ROOT_CALIBTRK1>=0 and EV_ROOT_CALIBTRK2>=0 "; // EM! SE MANCA UN PACCHETTO DEI DUE IL PROCESSAMENTO CRASHA... DA RIVEDERE LA VALIDAZIONE |
1193 |
|
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1194 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1195 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1196 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1358 |
// ---------------- |
// ---------------- |
1359 |
myquery.str(""); |
myquery.str(""); |
1360 |
myquery << " select "; |
myquery << " select "; |
1361 |
myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME "; |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1362 |
myquery << " from GL_PARAM "; |
myquery << " from GL_PARAM "; |
1363 |
myquery << " where TYPE = '"<<type<<"' "; |
myquery << " where TYPE = '"<<type<<"' "; |
1364 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1373 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1374 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1375 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1376 |
if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file |
if (t==1) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';// put in fpath the path to that file |
1377 |
if (t==2) NAME = Row->GetField(t); |
if (t==2) NAME = Row->GetField(t); |
1378 |
if (t==3) DESCR = Row->GetField(t); |
if (t==3) DESCR = Row->GetField(t); |
1379 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1419 |
TSQLRow *Row; |
TSQLRow *Row; |
1420 |
stringstream myquery; |
stringstream myquery; |
1421 |
stringstream rname; |
stringstream rname; |
1422 |
|
// pcksList packetsNames; |
1423 |
|
// pcksList::iterator Iter; |
1424 |
|
// getPacketsNames(packetsNames); |
1425 |
rname.str(""); |
rname.str(""); |
1426 |
// ---------------- |
// ---------------- |
1427 |
myquery.str(""); |
myquery.str(""); |
1440 |
if( Row ){ |
if( Row ){ |
1441 |
stringstream fname; |
stringstream fname; |
1442 |
fname.str(""); |
fname.str(""); |
1443 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1444 |
rname << Row->GetField(1); |
rname << Row->GetField(1); |
1445 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1446 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1457 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1458 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1459 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
1460 |
|
// |
1461 |
|
// code = eh->GetCounter(); |
1462 |
|
// UInt_t en = 0; |
1463 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
1464 |
|
// en = code->Get(GetPacketType(*Iter)); |
1465 |
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
1466 |
|
// // |
1467 |
|
// TTree *TC = 0; |
1468 |
|
// TC = (TTree*)file->Get("CalibCalPed"); |
1469 |
|
// if ( !TC || TC->IsZombie() ) return; |
1470 |
|
// EventHeader *ehc = 0; |
1471 |
|
// PscuHeader *phc = 0; |
1472 |
|
// TC->SetBranchAddress("Header", &ehc); |
1473 |
|
// TC->GetEntry(0); |
1474 |
|
// phc = ehc->GetPscuHeader(); |
1475 |
|
// pktfirst = phc->GetCounter(); |
1476 |
|
// obtfirst = phc->GetOrbitalTime(); |
1477 |
|
// // |
1478 |
|
// }; |
1479 |
|
// }; |
1480 |
|
// |
1481 |
}; |
}; |
1482 |
// |
// |
1483 |
// look for Resurs offset |
// look for Resurs offset |
1486 |
// |
// |
1487 |
// |
// |
1488 |
stringstream oss; |
stringstream oss; |
1489 |
|
TString frn = rname.str().c_str(); |
1490 |
|
frn = frn.ReplaceAll(".root",5,".pam",4); |
1491 |
oss.str(""); |
oss.str(""); |
1492 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1493 |
<< rname.str().c_str() << "';"; |
<< frn.Data() << "';"; |
1494 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1495 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1496 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1499 |
TString name=rname.str().c_str(); |
TString name=rname.str().c_str(); |
1500 |
UInt_t dworbit = 0; |
UInt_t dworbit = 0; |
1501 |
Int_t nlength = name.Length(); |
Int_t nlength = name.Length(); |
1502 |
if ( nlength < 5 ) return; |
// |
1503 |
TString dwo = 0; |
// Is not a special file |
|
for (Int_t i = 0; i<5; i++){ |
|
|
dwo.Append(name[i],1); |
|
|
}; |
|
|
if ( dwo.IsDigit() ){ |
|
|
dworbit = (UInt_t)dwo.Atoi(); |
|
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
|
dwo.Append(name[i],1); |
|
|
}; |
|
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
|
|
}; |
|
1504 |
// |
// |
1505 |
if ( !Row ){ |
if ( !Row ){ |
1506 |
|
delete pResult; |
1507 |
|
// |
1508 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1509 |
|
// |
1510 |
oss.str(""); |
oss.str(""); |
1511 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
|
1512 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1513 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1514 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1515 |
Row = pResult->Next(); |
Bool_t fndit = false; |
1516 |
if ( !Row ){ |
if ( pResult ){ |
1517 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
Row = pResult->Next(); |
1518 |
return; |
if ( Row ){ |
1519 |
|
oss.str(""); |
1520 |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE ID=" |
1521 |
|
<< Row->GetField(0) << ";"; |
1522 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1523 |
|
this->GetGLTABLES()->AddQ(); |
1524 |
|
pResult = dbc->Query(oss.str().c_str()); |
1525 |
|
if ( pResult ){ |
1526 |
|
Row = pResult->Next(); |
1527 |
|
if ( Row ){ |
1528 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
1529 |
|
fndit = true; |
1530 |
|
dworbit = 1; |
1531 |
|
}; |
1532 |
|
}; |
1533 |
|
}; |
1534 |
|
}; |
1535 |
|
if ( !fndit ){ |
1536 |
|
delete pResult; |
1537 |
|
// |
1538 |
|
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
1539 |
|
// |
1540 |
|
// Old code, we must trust the filename |
1541 |
|
// |
1542 |
|
if ( nlength < 5 ) return; |
1543 |
|
TString dwo = 0; |
1544 |
|
for (Int_t i = 0; i<5; i++){ |
1545 |
|
dwo.Append(name[i],1); |
1546 |
|
}; |
1547 |
|
if ( dwo.IsDigit() ){ |
1548 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1549 |
|
} else { |
1550 |
|
dwo=""; |
1551 |
|
for (Int_t i = 8; i<13; i++){ |
1552 |
|
dwo.Append(name[i],1); |
1553 |
|
}; |
1554 |
|
if ( dwo.IsDigit() ){ |
1555 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1556 |
|
} else { |
1557 |
|
dworbit = 1; |
1558 |
|
}; |
1559 |
|
}; |
1560 |
|
// |
1561 |
|
oss.str(""); |
1562 |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1563 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1564 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1565 |
|
this->GetGLTABLES()->AddQ(); |
1566 |
|
pResult = dbc->Query(oss.str().c_str()); |
1567 |
|
Row = pResult->Next(); |
1568 |
|
if ( !Row ){ |
1569 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1570 |
|
return; |
1571 |
|
}; |
1572 |
}; |
}; |
1573 |
}; |
}; |
1574 |
// |
// |
1865 |
TSQLRow *row; |
TSQLRow *row; |
1866 |
|
|
1867 |
// Set the right time_zone (otherwise horrible things will occur! :) |
// Set the right time_zone (otherwise horrible things will occur! :) |
1868 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1869 |
dbc->Query("SET time_zone = '+0:00'"); |
dbc->Query("SET time_zone = '+0:00'"); |
1870 |
|
|
1871 |
// Do the query |
// Do the query |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
|
1872 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
1873 |
result = dbc->Query(myquery.Data()); |
result = dbc->Query(myquery.Data()); |
1874 |
if(! result->GetRowCount() ) { |
if(! result->GetRowCount() ) { |