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 |
// |
// |
140 |
TString chfile; |
TString chfile; |
141 |
UInt_t ridn = 0; |
UInt_t ridn = 0; |
142 |
qu.str(""); |
qu.str(""); |
143 |
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 << ";"; |
144 |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
if ( debug ) printf(" chewbacca: query is %s \n",qu.str().c_str()); |
145 |
result = conn->Query(qu.str().c_str()); |
result = conn->Query(qu.str().c_str()); |
146 |
if ( result ){ |
if ( result ){ |
151 |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
chpktmax = (UInt_t)atoll(row->GetField(2)); |
152 |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
chobtmin = (UInt_t)atoll(row->GetField(3)); |
153 |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
chobtmax = (UInt_t)atoll(row->GetField(4)); |
154 |
|
chiby = (TString)(row->GetField(5)); |
155 |
} else { |
} else { |
156 |
throw -84; |
throw -84; |
157 |
}; |
}; |
166 |
if ( result2 ){ |
if ( result2 ){ |
167 |
row2 = result2->Next(); |
row2 = result2->Next(); |
168 |
if ( row2 ){ |
if ( row2 ){ |
169 |
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
if ( KEEPENV ){ |
170 |
|
chpath = (TString)(row2->GetField(0))+'/'; |
171 |
|
} else { |
172 |
|
chpath = (TString)gSystem->ExpandPathName(row2->GetField(0))+'/'; |
173 |
|
}; |
174 |
chfile = (TString)(row2->GetField(1)); |
chfile = (TString)(row2->GetField(1)); |
175 |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
chobtts = (UInt_t)atoll(row2->GetField(2)); |
176 |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
chlastts = (UInt_t)atoll(row2->GetField(3)); |
442 |
|
|
443 |
TString PamelaDBOperations::GetRootPath(){ |
TString PamelaDBOperations::GetRootPath(){ |
444 |
if ( STATIC ){ |
if ( STATIC ){ |
445 |
return((TString)gSystem->DirName(filerootname.Data())+'/'); |
return((TString)gSystem->DirName(this->GetRootName().Data())+'/'); |
446 |
} else { |
} else { |
447 |
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
if ( KEEPENV ){ |
448 |
|
return((TString)gSystem->ExpandPathName(gSystem->DirName(filerootname.Data()))+'/'); |
449 |
|
} else { |
450 |
|
return((TString)gSystem->ExpandPathName("$PAM_L0")+'/'); |
451 |
|
}; |
452 |
}; |
}; |
453 |
}; |
}; |
454 |
|
|
1136 |
stringstream oss; |
stringstream oss; |
1137 |
// |
// |
1138 |
oss.str(""); |
oss.str(""); |
1139 |
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. |
1140 |
|
if ( !strcmp(tag.Data(),"NONE") ){ |
1141 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; |
1142 |
|
} else { |
1143 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1144 |
|
}; |
1145 |
|
} else { |
1146 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1147 |
|
}; |
1148 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1149 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1150 |
oss.str(""); |
oss.str(""); |
1292 |
stringstream oss; |
stringstream oss; |
1293 |
// |
// |
1294 |
oss.str(""); |
oss.str(""); |
1295 |
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;"; |
1296 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1297 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1298 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1487 |
* Insert a new row into GL_RAW table. |
* Insert a new row into GL_RAW table. |
1488 |
*/ |
*/ |
1489 |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
Int_t PamelaDBOperations::insertPamelaRawFile(){ |
1490 |
|
|
1491 |
|
// |
1492 |
|
Bool_t idr = this->SetID_RAW(); |
1493 |
|
if ( idr ) return(1); |
1494 |
|
|
1495 |
|
GL_RAW glraw = GL_RAW(); |
1496 |
|
|
1497 |
|
glraw.PATH = GetRawPath(); |
1498 |
|
glraw.NAME = GetRawFile(); |
1499 |
|
// glraw.BOOT_NUMBER = 0;//??? |
1500 |
|
glraw.BOOT_NUMBER = this->GetBOOTnumber(); |
1501 |
|
|
1502 |
|
if( insertPamelaRawFile(&glraw) )return(1); |
1503 |
|
// |
1504 |
|
idr = this->SetID_RAW(); |
1505 |
|
if ( !idr ) throw -11; |
1506 |
|
|
1507 |
|
return(0); |
1508 |
|
} |
1509 |
|
/** |
1510 |
|
* Insert a new row into GL_RAW table. |
1511 |
|
*/ |
1512 |
|
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
1513 |
// |
// |
1514 |
stringstream oss; |
if(!glraw)return(1);//?? ok I think |
1515 |
// |
// |
1516 |
Bool_t idr = this->SetID_RAW(); |
stringstream oss; |
1517 |
if ( idr ) return(1); |
// |
1518 |
// |
oss.str(""); |
1519 |
oss.str(""); |
if ( STATIC ){ |
1520 |
if ( STATIC ){ |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
1521 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
<< glraw->PATH << "', '" << glraw->NAME << "')"; |
1522 |
<< this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
} else { |
1523 |
} else { |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << glraw->NAME << "')"; |
1524 |
oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
}; |
1525 |
}; |
if ( debug ) cout <<oss.str().c_str() <<endl; |
1526 |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1527 |
// |
// |
1528 |
idr = this->SetID_RAW(); |
oss.str(""); |
1529 |
if ( !idr ) throw -11; |
oss << "SELECT ID FROM GL_RAW WHERE NAME=\""<<glraw->NAME<<"\";"; |
1530 |
// |
if ( debug ) cout << oss.str().c_str()<<endl; |
1531 |
return(0); |
if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
1532 |
|
// |
1533 |
|
TSQLResult *result = 0; |
1534 |
|
TSQLRow *row = 0; |
1535 |
|
result = conn->Query(oss.str().c_str()); |
1536 |
|
if ( result == NULL ) throw -4; |
1537 |
|
row = result->Next(); |
1538 |
|
if ( !row ) return(1); |
1539 |
|
glraw->ID = (UInt_t)atoll(row->GetField(0)); |
1540 |
|
if ( debug ) printf(" The ID of the RAW file is %u \n",glraw->ID); |
1541 |
|
delete result; |
1542 |
|
delete row; |
1543 |
|
// |
1544 |
|
return(0); |
1545 |
} |
} |
1546 |
|
|
1547 |
|
|
1853 |
* 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. |
1854 |
*/ |
*/ |
1855 |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
Int_t PamelaDBOperations::insertPamelaRootFile(){ |
1856 |
stringstream oss; |
|
1857 |
TSQLResult *result = 0; |
stringstream oss; |
1858 |
TSQLRow *row = 0; |
TSQLResult *result = 0; |
1859 |
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; |
|
1860 |
// |
// |
1861 |
row = result->Next(); |
// ---------------------- |
1862 |
|
// determine the timesync |
1863 |
|
// ---------------------- |
1864 |
|
UInt_t idtimesync = 0; |
1865 |
// |
// |
1866 |
if ( !row ) throw -3; |
if ( chewbacca ){ |
1867 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
oss.str(""); |
1868 |
} else { |
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
1869 |
oss.str(""); |
if ( debug ) printf(" %s \n",oss.str().c_str()); |
1870 |
if ( STATIC ){ |
result = conn->Query(oss.str().c_str()); |
1871 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
// |
1872 |
<< " LEFT JOIN GL_ROOT " |
if ( !result ) throw -3; |
1873 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
// |
1874 |
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
row = result->Next(); |
1875 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
// |
1876 |
|
if ( !row ) throw -3; |
1877 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1878 |
} else { |
} else { |
1879 |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
oss.str(""); |
1880 |
<< " LEFT JOIN GL_ROOT " |
if ( STATIC ){ |
1881 |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1882 |
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
<< " LEFT JOIN GL_ROOT " |
1883 |
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1884 |
|
<< " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
1885 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1886 |
|
} else { |
1887 |
|
oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
1888 |
|
<< " LEFT JOIN GL_ROOT " |
1889 |
|
<< " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
1890 |
|
<< " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
1891 |
|
<< " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
1892 |
|
}; |
1893 |
|
result = conn->Query(oss.str().c_str()); |
1894 |
|
// |
1895 |
|
if ( !result ) throw -12; |
1896 |
|
// |
1897 |
|
row = result->Next(); |
1898 |
|
// |
1899 |
|
if ( !row ) throw -10; |
1900 |
|
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
1901 |
|
idroot = (UInt_t)atoll(row->GetField(2)); |
1902 |
|
delete row; |
1903 |
|
delete result; |
1904 |
|
return(1); |
1905 |
|
}; |
1906 |
|
// |
1907 |
|
// determine which timesync has to be used |
1908 |
|
// |
1909 |
|
oss.str(""); |
1910 |
|
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;"; |
1911 |
|
result = conn->Query(oss.str().c_str()); |
1912 |
|
// |
1913 |
|
if ( !result ) throw -3; |
1914 |
|
// |
1915 |
|
row = result->Next(); |
1916 |
|
// |
1917 |
|
if ( !row ) throw -3; |
1918 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
1919 |
}; |
}; |
1920 |
result = conn->Query(oss.str().c_str()); |
|
1921 |
// |
delete row; |
1922 |
if ( !result ) throw -12; |
delete result; |
1923 |
// |
|
1924 |
row = result->Next(); |
// ---------------------- |
1925 |
// |
// insert root file |
1926 |
if ( !row ) throw -10; |
// ---------------------- |
1927 |
if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
|
1928 |
idroot = (UInt_t)atoll(row->GetField(2)); |
GL_ROOT glroot = GL_ROOT(); |
1929 |
return(1); |
|
1930 |
|
glroot.ID_RAW = GetID_RAW(); |
1931 |
|
glroot.ID_TIMESYNC = idtimesync; |
1932 |
|
if ( STATIC ){ |
1933 |
|
glroot.PATH = GetRootPath(); |
1934 |
|
} else { |
1935 |
|
if ( KEEPENV ){ |
1936 |
|
glroot.PATH = gSystem->DirName(filerootname.Data()); |
1937 |
|
} else { |
1938 |
|
glroot.PATH = "$PAM_L0"; |
1939 |
|
}; |
1940 |
}; |
}; |
1941 |
// |
glroot.NAME = GetRootFile(); |
1942 |
// determine which timesync has to be used |
|
1943 |
// |
if ( insertPamelaRootFile(&glroot) )return 1; |
1944 |
oss.str(""); |
|
1945 |
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); |
1946 |
result = conn->Query(oss.str().c_str()); |
|
1947 |
// |
|
1948 |
if ( !result ) throw -3; |
return (0); |
1949 |
// |
} |
1950 |
row = result->Next(); |
/** |
1951 |
// |
* Insert all the new rows into GL_ROOT. |
1952 |
if ( !row ) throw -3; |
* The raw file indicates in the parameters should be already been stored in the database. |
1953 |
idtimesync = (UInt_t)atoll(row->GetField(0)); |
*/ |
1954 |
}; |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
1955 |
|
stringstream oss; |
1956 |
|
TSQLResult *result = 0; |
1957 |
|
TSQLRow *row = 0; |
1958 |
|
// |
1959 |
// |
// |
1960 |
oss.str(""); |
oss.str(""); |
1961 |
if ( STATIC ){ |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
1962 |
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() << "')"; |
|
|
}; |
|
1963 |
// |
// |
1964 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1965 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
1966 |
// |
// |
1967 |
delete result; |
delete result; |
1968 |
// |
// |
1969 |
oss.str(""); |
oss.str(""); |
1970 |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
1971 |
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() <<"';"; |
|
|
}; |
|
1972 |
// |
// |
1973 |
if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1974 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1975 |
if ( !result ) throw -12; |
if ( !result ) throw -12; |
1976 |
row = result->Next(); |
row = result->Next(); |
1977 |
if ( !row ) throw -3; |
if ( !row ) throw -3; |
1978 |
this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); |
|
1979 |
if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); |
glroot->ID = (UInt_t)atoll(row->GetField(0)); |
1980 |
|
|
1981 |
|
if ( debug ) printf(" The ID of the ROOT file is %u \n",glroot->ID); |
1982 |
// |
// |
1983 |
delete result; |
delete result; |
1984 |
// |
// |
3343 |
// 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 |
3344 |
// |
// |
3345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3346 |
mishead = true; |
mishead = true; |
3347 |
|
|
3348 |
|
|
3662 |
}; // EEE |
}; // EEE |
3663 |
|
|
3664 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3665 |
} else { |
} else { |
3666 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
3667 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
4496 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
4497 |
*/ |
*/ |
4498 |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
4499 |
// |
|
4500 |
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 ){ |
|
|
// |
|
|
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
|
|
if ( PEDANTIC ) throw -80; |
|
4501 |
// |
// |
4502 |
} else { |
glcal->ID = 0; |
4503 |
|
glcal->ID_ROOT_L0 = GetID_ROOT(); |
4504 |
|
glcal->EV_ROOT_CALIBTRK1 = t1; |
4505 |
|
glcal->EV_ROOT_CALIBTRK2 = t2; |
4506 |
|
glcal->FROM_TIME = fromtime; |
4507 |
|
glcal->TO_TIME = 0; |
4508 |
|
glcal->OBT1 = obt1; |
4509 |
|
glcal->OBT2 = obt2; |
4510 |
|
glcal->PKT1 = pkt1; |
4511 |
|
glcal->PKT2 = pkt2; |
4512 |
|
glcal->BOOT_NUMBER = GetBOOTnumber(); |
4513 |
|
glcal->VALIDATION = valid; |
4514 |
// |
// |
4515 |
// we have to insert a new calibration, check where to place it |
HandleTRK_CALIB(glcal); |
4516 |
// |
// |
4517 |
oss.str(""); |
delete glcal; |
4518 |
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
} |
4519 |
<< " FROM_TIME < "<< fromtime << " AND " |
/** |
4520 |
<< " TO_TIME > "<< fromtime << ";"; |
* Fill the GL_TRK_CALIB table |
4521 |
|
*/ |
4522 |
|
void PamelaDBOperations::HandleTRK_CALIB(GL_TRK_CALIB *glcal){ |
4523 |
|
|
4524 |
|
Bool_t pk1 = (glcal->OBT1>0&&glcal->PKT1>0); |
4525 |
|
Bool_t pk2 = (glcal->OBT2>0&&glcal->PKT2>0); |
4526 |
|
UInt_t boot_number = glcal->BOOT_NUMBER; |
4527 |
|
UInt_t obt1 = glcal->OBT1; |
4528 |
|
UInt_t obt2 = glcal->OBT2; |
4529 |
|
UInt_t pkt1 = glcal->PKT1; |
4530 |
|
UInt_t pkt2 = glcal->PKT2; |
4531 |
|
UInt_t fromtime = glcal->FROM_TIME; |
4532 |
|
UInt_t totime = 0; |
4533 |
|
UInt_t idroot = glcal->ID_ROOT_L0; |
4534 |
|
UInt_t t1 = glcal->EV_ROOT_CALIBTRK1; |
4535 |
|
UInt_t t2 = glcal->EV_ROOT_CALIBTRK2; |
4536 |
|
UInt_t valid = glcal->VALIDATION; |
4537 |
// |
// |
4538 |
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
TSQLResult *result = 0; |
4539 |
result = conn->Query(oss.str().c_str()); |
TSQLRow *row = 0; |
4540 |
// |
// |
4541 |
if ( !result ) throw -4; |
stringstream oss; |
4542 |
|
oss.str(""); |
4543 |
// |
// |
|
row = result->Next(); |
|
4544 |
// |
// |
4545 |
if ( !row ){ |
if ( !pk1 && !pk2 ){ |
4546 |
// |
if ( IsDebug() ) printf(" Cannot handle trk calibration with both packet missing!\n"); |
4547 |
// 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; |
|
|
// |
|
4548 |
}; |
}; |
4549 |
// |
// |
4550 |
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 << "',"; |
|
4551 |
// |
// |
4552 |
if ( !pk1 ){ |
oss.str(""); |
4553 |
oss << "NULL,"; |
oss << " SELECT ID FROM GL_TRK_CALIB WHERE " |
4554 |
|
<< " BOOT_NUMBER = "<< boot_number; // |
4555 |
|
oss << " AND FROM_TIME="<<fromtime; /// NEWNEWNEW -- VA BENE ?!?!?!?! |
4556 |
|
oss << " AND ( ( "; |
4557 |
|
if ( pk1 ){ |
4558 |
|
oss << " OBT1 = "<< obt1 << " AND " |
4559 |
|
<< " PKT1 = "<< pkt1 |
4560 |
|
<< " ) OR ( "; |
4561 |
} else { |
} else { |
4562 |
oss << "'" |
oss << " PKT1 = "<< pkt2-1 |
4563 |
<< t1 << "',"; |
<< " ) OR ( "; |
4564 |
}; |
}; |
4565 |
// |
if ( pk2 ){ |
4566 |
if ( !pk2 ){ |
oss << " OBT2 = "<< obt2 << " AND " |
4567 |
oss << "NULL,'"; |
<< " PKT2 = "<< pkt2; |
4568 |
} else { |
} else { |
4569 |
oss << "'" |
oss << " PKT2 = "<< pkt1+1; |
4570 |
<< t2 << "','"; |
}; |
4571 |
}; |
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()); |
|
4572 |
// |
// |
4573 |
|
if ( IsDebug() ) printf(" Check if the trk calibration has already been inserted: query is \n %s \n",oss.str().c_str()); |
4574 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
4575 |
// |
// |
4576 |
if ( !result ) throw -4; |
if ( !result ) throw -4; |
4577 |
// |
// |
4578 |
}; |
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 |
|
|
// |
|
4579 |
// |
// |
4580 |
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++; |
|
4581 |
// |
// |
4582 |
pret2 = t2 - 1; // EMILIANO |
if ( IsDebug() ) printf(" Trk calibration already inserted in the DB\n"); |
4583 |
|
if ( PEDANTIC ) throw -80; |
4584 |
// |
// |
4585 |
if ( t2 < nevents2 ){ |
} else { |
|
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; |
|
|
// }; |
|
|
|
|
|
|
|
|
// |
|
|
}; |
|
|
// |
|
|
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"); |
|
|
// |
|
|
// running out of vector without finding the corresponding calibration, sig |
|
|
// |
|
|
pret2 = t2; |
|
|
obt2 = 0; |
|
|
pkt2 = 0; |
|
|
}; |
|
|
// |
|
|
// The calibration is good |
|
|
// |
|
|
if ( this->PKT(pkt2) == this->PKT(pkt1)+1 ){ |
|
4586 |
// |
// |
4587 |
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); |
|
4588 |
// |
// |
4589 |
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
oss.str(""); |
4590 |
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
4591 |
valid = valid & valid2; |
<< " FROM_TIME < "<< fromtime << " AND " |
4592 |
|
<< " TO_TIME > "<< fromtime << ";"; |
4593 |
// |
// |
4594 |
// Handle good calib |
if ( IsDebug() ) printf(" Check where to place the trk calibration: query is \n %s \n",oss.str().c_str()); |
4595 |
|
result = conn->Query(oss.str().c_str()); |
4596 |
// |
// |
4597 |
this->HandleTRK_CALIB(true,true); |
if ( !result ) throw -4; |
4598 |
// |
// |
4599 |
// Check for missing calibtrk1 |
row = result->Next(); |
4600 |
// |
// |
4601 |
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 ){ |
|
4602 |
// |
// |
4603 |
// handle missing calib1 |
// no calibrations in the db contain our calibration |
4604 |
// |
// |
4605 |
pret2++; |
if ( IsDebug() ) printf(" Calibration with fromtime lower than others to be inserted in the DB\n"); |
4606 |
|
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 |
4607 |
// |
// |
4608 |
obt1 = 0; |
oss.str(""); |
4609 |
pkt1 = 0; |
oss << " SELECT FROM_TIME FROM GL_TRK_CALIB WHERE " |
4610 |
|
<< " FROM_TIME > "<< fromtime << " ORDER BY FROM_TIME ASC LIMIT 1;"; |
4611 |
// |
// |
4612 |
tr2->GetEntry(pret2); |
if ( IsDebug() ) printf(" Check the upper limit for calibration: query is \n %s \n",oss.str().c_str()); |
4613 |
ph2 = eh2->GetPscuHeader(); |
result = conn->Query(oss.str().c_str()); |
|
obt2 = ph2->GetOrbitalTime(); |
|
|
pkt2 = ph2->GetCounter(); |
|
4614 |
// |
// |
4615 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
if ( !result ) throw -4; |
4616 |
// |
// |
4617 |
valid = 0; |
row = result->Next(); |
4618 |
this->HandleTRK_CALIB(false,true); |
if ( !row ){ |
4619 |
|
totime = numeric_limits<UInt_t>::max(); |
4620 |
|
} else { |
4621 |
|
totime = (UInt_t)atoll(row->GetField(0)); |
4622 |
|
}; |
4623 |
|
// |
4624 |
|
} else { |
4625 |
|
// |
4626 |
|
// determine upper and lower limits and make space for the new calibration |
4627 |
|
// |
4628 |
|
totime = (UInt_t)atoll(row->GetField(1)); |
4629 |
|
// |
4630 |
|
oss.str(""); |
4631 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
4632 |
|
<< " TO_TIME = "<< fromtime << " WHERE " // NOTICE: to_time is equal to from_time of the calibration before, so the interval is: [from_time,to_time[ |
4633 |
|
<< " ID = "<< row->GetField(0) << ";"; |
4634 |
|
// |
4635 |
|
if ( IsDebug() ) printf(" Make space for the new trk calibration: query is \n %s \n",oss.str().c_str()); |
4636 |
|
result = conn->Query(oss.str().c_str()); |
4637 |
|
// |
4638 |
|
if ( !result ) throw -4; |
4639 |
// |
// |
|
}; |
|
|
// |
|
4640 |
}; |
}; |
4641 |
// |
// |
4642 |
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
oss.str(""); |
4643 |
|
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) " |
4644 |
|
<< " VALUES (NULL,' " |
4645 |
|
<< idroot << "',"; |
4646 |
// |
// |
4647 |
// Check for missing calibtrk2 |
if ( !pk1 ){ |
4648 |
|
oss << "NULL,"; |
4649 |
|
} else { |
4650 |
|
oss << "'" |
4651 |
|
<< t1 << "',"; |
4652 |
|
}; |
4653 |
// |
// |
4654 |
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
if ( !pk2 ){ |
4655 |
t2 = pret2; |
oss << "NULL,'"; |
4656 |
|
} else { |
4657 |
|
oss << "'" |
4658 |
|
<< t2 << "','"; |
4659 |
|
}; |
4660 |
// |
// |
4661 |
// handle missing calib2 |
oss << fromtime << "','" |
4662 |
|
<< totime << "','" |
4663 |
|
<< obt1 << "','" |
4664 |
|
<< pkt1 << "','" |
4665 |
|
<< obt2 << "','" |
4666 |
|
<< pkt2 << "','" |
4667 |
|
<< boot_number << "','" |
4668 |
|
<< valid << "');"; |
4669 |
// |
// |
4670 |
obt2 = 0; |
if ( IsDebug() ) printf(" Insert the new trk calibration: query is \n %s \n",oss.str().c_str()); |
4671 |
pkt2 = 0; |
// |
4672 |
valid = 0; |
result = conn->Query(oss.str().c_str()); |
4673 |
this->HandleTRK_CALIB(true,false); |
// |
4674 |
|
if ( !result ) throw -4; |
4675 |
// |
// |
|
}; |
|
|
// |
|
|
} 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; |
|
|
// |
|
4676 |
}; |
}; |
4677 |
// |
|
4678 |
}; |
oss.str(""); |
4679 |
// |
oss << " SELECT ID FROM GL_TRK_CALIB ORDER BY ID DESC LIMIT 1 ;"; |
4680 |
// we have one more calib pkt2 ! |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
4681 |
// |
result = conn->Query(oss.str().c_str()); |
4682 |
t2++; |
if ( !result ) throw -4;; |
4683 |
while ( t2 < nevents2 ){ |
row = result->Next(); |
4684 |
|
if(row)glcal->ID = (UInt_t)atoll(row->GetField(0)); |
4685 |
|
|
4686 |
// |
// |
4687 |
// handle missing calib1 |
}; |
4688 |
|
|
4689 |
|
/** |
4690 |
|
* Scan tracker calibrations packets, fill the GL_TRK_CALIB table |
4691 |
|
*/ |
4692 |
|
Int_t PamelaDBOperations::insertTRK_CALIB(){ |
4693 |
|
// |
4694 |
|
CalibTrk1Event *caltrk1 = 0; |
4695 |
|
CalibTrk2Event *caltrk2 = 0; |
4696 |
|
TTree *tr1 = 0; |
4697 |
|
TTree *tr2 = 0; |
4698 |
|
EventHeader *eh1 = 0; |
4699 |
|
PscuHeader *ph1 = 0; |
4700 |
|
EventHeader *eh2 = 0; |
4701 |
|
PscuHeader *ph2 = 0; |
4702 |
|
// |
4703 |
|
PacketType *pctp=0; |
4704 |
|
EventCounter *codt2=0; |
4705 |
|
// |
4706 |
|
Int_t nevents1 = 0; |
4707 |
|
Int_t nevents2 = 0; |
4708 |
|
// |
4709 |
|
fromtime = 0; |
4710 |
// |
// |
|
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
|
4711 |
obt1 = 0; |
obt1 = 0; |
4712 |
pkt1 = 0; |
pkt1 = 0; |
4713 |
|
obt2 = 0; |
4714 |
|
pkt2 = 0; |
4715 |
// |
// |
4716 |
tr2->GetEntry(t2); |
tr1 = (TTree*)file->Get("CalibTrk1"); |
4717 |
ph2 = eh2->GetPscuHeader(); |
if ( !tr1 || tr1->IsZombie() ) throw -22; |
4718 |
obt2 = ph2->GetOrbitalTime(); |
tr2 = (TTree*)file->Get("CalibTrk2"); |
4719 |
pkt2 = ph2->GetCounter(); |
if ( !tr2 || tr2->IsZombie() ) throw -23; |
4720 |
// |
// |
4721 |
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
4722 |
valid = 0; |
tr1->SetBranchAddress("Header", &eh1); |
4723 |
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
nevents1 = tr1->GetEntries(); |
4724 |
// EMILIANO |
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
4725 |
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); |
4726 |
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
nevents2 = tr2->GetEntries(); |
4727 |
// |
// |
4728 |
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); |
4729 |
// |
// |
4730 |
this->HandleTRK_CALIB(false,true); |
t2 = -1; |
4731 |
// |
Int_t pret2 = 0; |
4732 |
}; |
Int_t t2t1cal = 0; |
4733 |
|
// |
4734 |
|
bool MISSING_pkt1 = true; |
4735 |
|
bool MISSING_pkt2 = true; |
4736 |
|
int ncalib = 0; |
4737 |
|
bool try_to_recover = false; |
4738 |
// |
// |
4739 |
t2++; |
for (t1=0; t1 < nevents1; t1++){//loop over packet1 |
4740 |
|
// |
4741 |
|
pret2 = t2; |
4742 |
|
tr1->GetEntry(t1); |
4743 |
|
// |
4744 |
|
ph1 = eh1->GetPscuHeader(); |
4745 |
|
obt1 = ph1->GetOrbitalTime(); |
4746 |
|
pkt1 = ph1->GetCounter(); |
4747 |
|
fromtime = GetAbsTime(ph1->GetOrbitalTime()); |
4748 |
|
// |
4749 |
|
// chek if the packet number and obt are consistent with the other packets ??? |
4750 |
|
// |
4751 |
|
if ( PKT(pkt1) >= PKT(pktfirst) && PKT(pkt1) <= upperpkt && OBT(obt1) >= OBT(obtfirst) && OBT(obt1) <= upperobt ){ |
4752 |
|
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->OBT(obt1) >= this->OBT(obtfirst) ){ |
4753 |
|
// |
4754 |
|
if ( IsDebug() ) printf("\n Trk calibration1 %u at time %u obt %u pkt %u \n",t1,fromtime,obt1,pkt1); |
4755 |
|
// |
4756 |
|
valid = ValidateTrkCalib( caltrk1, eh1 ); |
4757 |
|
if ( IsDebug() ) cout << " pkt1 validation --> "<<valid<<endl; |
4758 |
|
// |
4759 |
|
// Do we have the second calibration packet? |
4760 |
|
// |
4761 |
|
if ( IsDebug() ) cout << " Loop over calibration2 to search associated calibration: "<<endl; |
4762 |
|
while ( t2t1cal < t1+1 ){ // get the calibration packet2 that follows the packet1 |
4763 |
|
// |
4764 |
|
t2++; |
4765 |
|
// |
4766 |
|
pret2 = t2 - 1; // EMILIANO |
4767 |
|
// |
4768 |
|
if ( t2 < nevents2 ){ |
4769 |
|
tr2->GetEntry(t2); |
4770 |
|
codt2 = eh2->GetCounter(); |
4771 |
|
t2t1cal = codt2->Get(pctp->CalibTrk1); |
4772 |
|
// |
4773 |
|
ph2 = eh2->GetPscuHeader(); |
4774 |
|
obt2 = ph2->GetOrbitalTime(); |
4775 |
|
pkt2 = ph2->GetCounter(); |
4776 |
|
// |
4777 |
|
if ( IsDebug() ) printf(" >> trk calibration2 at obt %u pkt %u t2 is %u , t2t1cal is %u \n",obt2,pkt2,t2,t2t1cal); |
4778 |
|
// if ( caltrk2->unpackError != 0 || caltrk2->good0 == 0 ) valid = 0; // CONDITIONS ON THE GOODNESS OF THE CALIBRATION PKT2 |
4779 |
|
// |
4780 |
|
} else { |
4781 |
|
// |
4782 |
|
// running out of vector without finding the corresponding calibration, sig |
4783 |
|
// |
4784 |
|
if ( IsDebug() ) printf(" t2 >= nevents2 \n"); |
4785 |
|
pret2 = t2; |
4786 |
|
obt2 = 0; |
4787 |
|
// pkt2 = pkt1+2; |
4788 |
|
pkt2 = 0; |
4789 |
|
t2t1cal = t1+1; |
4790 |
|
}; |
4791 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) && (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
4792 |
|
|
4793 |
|
// EMILIANO |
4794 |
|
// if ( (this->PKT(pkt2) < this->PKT(pktfirst) || this->PKT(pkt2) > upperpkt) || (this->OBT(obt2) < this->OBT(obtfirst) || this->OBT(obt2) > upperobt) ){ |
4795 |
|
// // if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
4796 |
|
// if ( IsDebug() ) printf(" running out of vector without finding the corresponding calibration, sig \n"); |
4797 |
|
// // |
4798 |
|
// // running out of vector without finding the corresponding calibration, sig |
4799 |
|
// // |
4800 |
|
// pret2 = t2; |
4801 |
|
// obt2 = 0; |
4802 |
|
// // pkt2 = pkt1+2; |
4803 |
|
// pkt2 = 0; |
4804 |
|
// t2t1cal = t1+1; |
4805 |
|
// }; |
4806 |
|
|
4807 |
|
|
4808 |
|
// |
4809 |
|
}; |
4810 |
|
// |
4811 |
|
if ( IsDebug() ) printf(" Check if trk calibration2 is the right one \n"); |
4812 |
|
// |
4813 |
|
// EMILIANO |
4814 |
|
if ( ( PKT(pkt2) < PKT(pktfirst) || PKT(pkt2) > upperpkt) || (OBT(obt2) < OBT(obtfirst) || OBT(obt2) > upperobt) ){ |
4815 |
|
// if ( this->PKT(pkt2) < this->PKT(pktfirst) && this->OBT(obt2) < this->OBT(obtfirst) ){ |
4816 |
|
if ( IsDebug() ) printf(" *WARNING* The calibration found is outside the interval, sig \n"); |
4817 |
|
// |
4818 |
|
// running out of vector without finding the corresponding calibration, sig |
4819 |
|
// |
4820 |
|
pret2 = t2; |
4821 |
|
obt2 = 0; |
4822 |
|
pkt2 = 0; |
4823 |
|
}; |
4824 |
|
if ( PKT(pkt2) == PKT(pkt1)+1 ){ |
4825 |
|
if ( IsDebug() ) cout << " ...OK"<<endl; |
4826 |
|
// ======================= |
4827 |
|
// The calibration is good |
4828 |
|
// ======================= |
4829 |
|
// |
4830 |
|
// if ( IsDebug() ) printf(" Found trk calibration2 at obt %u pkt %u t2 is %u \n",obt2,pkt2,t2); |
4831 |
|
// if ( IsDebug() ) printf(" Trk calibration2 at obt %u pkt %u t2 is %u is good \n",obt2,pkt2,t2); |
4832 |
|
// if ( IsDebug() ) printf("\n Trk calibration2 at time %u obt %u pkt %u \n",fromtime,obt2,pkt2); |
4833 |
|
if ( IsDebug() ) printf(" Trk calibration2 %u at time %u obt %u pkt %u \n",t2,fromtime,obt2,pkt2); |
4834 |
|
// |
4835 |
|
UInt_t valid2 = ValidateTrkCalib( caltrk2, eh2 ); |
4836 |
|
if ( IsDebug() ) cout << " pkt2 validation --> "<<valid2<<endl; |
4837 |
|
// valid = valid & valid2; |
4838 |
|
valid = valid & valid2; //QUESTO VA CAMBIATO |
4839 |
|
// |
4840 |
|
// Handle good calib |
4841 |
|
// |
4842 |
|
MISSING_pkt1 = false; |
4843 |
|
MISSING_pkt2 = false; |
4844 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4845 |
|
// |
4846 |
|
// Check for missing calibtrk1 |
4847 |
|
// |
4848 |
|
if ( t2 != pret2+1 ){ |
4849 |
|
// |
4850 |
|
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); |
4851 |
|
// |
4852 |
|
while ( t2 > pret2+1 ){ |
4853 |
|
// |
4854 |
|
// handle missing calib1 |
4855 |
|
// |
4856 |
|
pret2++; |
4857 |
|
// |
4858 |
|
obt1 = 0; |
4859 |
|
pkt1 = 0; |
4860 |
|
// |
4861 |
|
tr2->GetEntry(pret2); |
4862 |
|
ph2 = eh2->GetPscuHeader(); |
4863 |
|
obt2 = ph2->GetOrbitalTime(); |
4864 |
|
pkt2 = ph2->GetCounter(); |
4865 |
|
// |
4866 |
|
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
4867 |
|
// |
4868 |
|
valid = 0; |
4869 |
|
MISSING_pkt1 = true; |
4870 |
|
MISSING_pkt2 = false; |
4871 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4872 |
|
// |
4873 |
|
}; |
4874 |
|
// |
4875 |
|
}; |
4876 |
|
// |
4877 |
|
} else if ( this->PKT(pkt2) > this->PKT(pkt1)+1 ){ |
4878 |
|
// |
4879 |
|
// Check for missing calibtrk2 |
4880 |
|
// |
4881 |
|
if ( IsDebug() ) printf(" Missing the trk calibration2! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
4882 |
|
t2 = pret2; |
4883 |
|
// |
4884 |
|
// handle missing calib2 |
4885 |
|
// |
4886 |
|
obt2 = 0; |
4887 |
|
pkt2 = 0; |
4888 |
|
valid = 0; |
4889 |
|
MISSING_pkt1 = false; |
4890 |
|
MISSING_pkt2 = true; |
4891 |
|
// this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4892 |
|
// |
4893 |
|
}; |
4894 |
|
// |
4895 |
|
|
4896 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
4897 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4898 |
|
ncalib++; |
4899 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4900 |
|
} |
4901 |
|
|
4902 |
|
|
4903 |
|
} else { |
4904 |
|
// |
4905 |
|
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
4906 |
|
// if ( PEDANTIC ) throw -79; |
4907 |
|
// |
4908 |
|
}; |
4909 |
|
// |
4910 |
|
|
4911 |
|
}; //end loop on pkt1 |
4912 |
|
|
4913 |
|
|
4914 |
|
|
4915 |
// |
// |
4916 |
}; |
// we have one more calib pkt2 ! |
4917 |
|
// |
4918 |
|
t2++; |
4919 |
|
while ( t2 < nevents2 ){ |
4920 |
|
// |
4921 |
|
// handle missing calib1 |
4922 |
|
// |
4923 |
|
if ( IsDebug() ) printf(" t2 is %u nevents2 is %u \n",t2,nevents2); |
4924 |
|
obt1 = 0; |
4925 |
|
pkt1 = 0; |
4926 |
|
// |
4927 |
|
tr2->GetEntry(t2); |
4928 |
|
ph2 = eh2->GetPscuHeader(); |
4929 |
|
obt2 = ph2->GetOrbitalTime(); |
4930 |
|
pkt2 = ph2->GetCounter(); |
4931 |
|
// |
4932 |
|
fromtime = this->GetAbsTime(ph2->GetOrbitalTime()); |
4933 |
|
valid = 0; |
4934 |
|
// if ( this->PKT(pkt1) >= this->PKT(pktfirst) && this->PKT(pkt1) <= upperpkt && this->OBT(obt1) >= this->OBT(obtfirst) && this->OBT(obt1) <= upperobt ){ |
4935 |
|
// EMILIANO |
4936 |
|
if ( this->PKT(pkt2) >= this->PKT(pktfirst) && this->PKT(pkt2 <= upperpkt) && this->OBT(obt2) >= this->OBT(obtfirst) && this->OBT(obt2) <= upperobt ){ |
4937 |
|
// if ( this->PKT(pkt2) > this->PKT(pktfirst) || this->OBT(obt2) > this->OBT(obtfirst) ){ |
4938 |
|
// |
4939 |
|
if ( IsDebug() ) printf(" Missing the trk calibration1! Next one at obt %u pkt %u t2 is %u\n",obt2,pkt2,t2); |
4940 |
|
// |
4941 |
|
MISSING_pkt1 = true; |
4942 |
|
MISSING_pkt2 = false; |
4943 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4944 |
|
ncalib++; |
4945 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4946 |
|
// |
4947 |
|
}; |
4948 |
|
// |
4949 |
|
t2++; |
4950 |
|
// |
4951 |
|
}; |
4952 |
|
|
4953 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4954 |
|
// ----------------------------------------------------------------- |
4955 |
|
// in case of corruption, check if the calibration can be recovered |
4956 |
|
// from another chewbacca file |
4957 |
|
// ----------------------------------------------------------------- |
4958 |
|
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4959 |
|
|
4960 |
|
// cout <<" TRY TO RECOVER ?? "<<try_to_recover<<endl; |
4961 |
|
|
4962 |
|
if(chewbacca&&try_to_recover){ |
4963 |
|
|
4964 |
|
|
4965 |
|
if ( IsDebug() ) cout << endl << ">>>> TRY TO RECOVER TRACKER CALIBRATIONS <<<<"<<endl; |
4966 |
|
|
4967 |
|
TSQLResult *result = 0; |
4968 |
|
TSQLRow *row = 0; |
4969 |
|
// |
4970 |
|
stringstream oss; |
4971 |
|
oss.str(""); |
4972 |
|
// |
4973 |
|
|
4974 |
|
//////////////////////////////////////////////////////////////////////// |
4975 |
|
// retrieve the name of the current file: |
4976 |
|
//////////////////////////////////////////////////////////////////////// |
4977 |
|
oss.str(""); |
4978 |
|
oss << "SELECT NAME FROM GL_ROOT where ID=" << GetID_ROOT() <<";"; |
4979 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
4980 |
|
|
4981 |
|
result = conn->Query(oss.str().c_str()); |
4982 |
|
if ( !result ) throw -4;; |
4983 |
|
row = result->Next(); |
4984 |
|
TString thisfilename = (TString)row->GetField(0); |
4985 |
|
if ( IsDebug() ) cout << "Current file ==> "<<thisfilename<<endl; |
4986 |
|
|
4987 |
|
//////////////////////////////////////////////////////////////////////// |
4988 |
|
// read all the calibrations inserted |
4989 |
|
//////////////////////////////////////////////////////////////////////// |
4990 |
|
oss.str(""); |
4991 |
|
oss << " SELECT "; |
4992 |
|
oss << " ID,FROM_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,TO_TIME"; |
4993 |
|
oss << " FROM GL_TRK_CALIB "; |
4994 |
|
oss << " ORDER BY ID DESC LIMIT "<<ncalib<<"; "; |
4995 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
4996 |
|
|
4997 |
|
result = conn->Query(oss.str().c_str()); |
4998 |
|
if ( !result ) throw -4;; |
4999 |
|
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5000 |
|
|
5001 |
|
// ----------------------------------- |
5002 |
|
// loop over calibrations ... |
5003 |
|
// ----------------------------------- |
5004 |
|
UInt_t nn=0; |
5005 |
|
do { |
5006 |
|
row = result->Next(); |
5007 |
|
if(!row)break; |
5008 |
|
|
5009 |
|
UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5010 |
|
UInt_t fromtime = (UInt_t)atoll(row->GetField(1)); |
5011 |
|
UInt_t obt1 = (UInt_t)atoll(row->GetField(2)); |
5012 |
|
UInt_t pkt1 = (UInt_t)atoll(row->GetField(3)); |
5013 |
|
UInt_t obt2 = (UInt_t)atoll(row->GetField(4)); |
5014 |
|
UInt_t pkt2 = (UInt_t)atoll(row->GetField(5)); |
5015 |
|
UInt_t boot = (UInt_t)atoll(row->GetField(6)); |
5016 |
|
UInt_t valid = (UInt_t)atoll(row->GetField(7)); |
5017 |
|
bool MISSING_pkt1 = (row->GetFieldLength(8)==0); |
5018 |
|
bool MISSING_pkt2 = (row->GetFieldLength(9)==0); |
5019 |
|
UInt_t totime = (UInt_t)atoll(row->GetField(10)); |
5020 |
|
|
5021 |
|
// ------------------------------------- |
5022 |
|
// ...check if the entry is corrupted... |
5023 |
|
// ------------------------------------- |
5024 |
|
cout <<"*** "<< MISSING_pkt1 << MISSING_pkt2 << valid <<endl; |
5025 |
|
bool CORRUPTED = (MISSING_pkt1||MISSING_pkt2||!valid); |
5026 |
|
|
5027 |
|
if ( IsDebug() ) cout << "("<<nn<<") ID = "<<id<<" from GL_TRK_CALIB ==> corrupted ? "<<CORRUPTED<<endl; |
5028 |
|
|
5029 |
|
// if( !CORRUPTED )continue; // nothing to do |
5030 |
|
|
5031 |
|
///////////////////////////////////////////////////////// |
5032 |
|
// if it is corrupted, ...look for ather chewbacca files |
5033 |
|
// containing the same calibrations ... |
5034 |
|
///////////////////////////////////////////////////////// |
5035 |
|
|
5036 |
|
bool this_MISSING_pkt1 = false; |
5037 |
|
bool this_MISSING_pkt2 = false; |
5038 |
|
int this_t1=0; |
5039 |
|
int this_t2=0;; |
5040 |
|
UInt_t this_valid = 0; |
5041 |
|
|
5042 |
|
TString path = ""; |
5043 |
|
TString name = ""; |
5044 |
|
TString raw = ""; |
5045 |
|
UInt_t obt0 = 0; |
5046 |
|
UInt_t timesync = 0; |
5047 |
|
UInt_t boot_number = 0; |
5048 |
|
bool FOUND = false; |
5049 |
|
|
5050 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5051 |
|
|
5052 |
|
// for(int itable=0; itable<2; itable++){ |
5053 |
|
for(int itable=0; itable<1; itable++){ |
5054 |
|
|
5055 |
|
// ------------------------------------------------------ |
5056 |
|
// loop over both ROOT_TABLE and ROOT_TABLE_BAD |
5057 |
|
// ------------------------------------------------------ |
5058 |
|
|
5059 |
|
TString table = "ROOT_TABLE"; |
5060 |
|
if(itable==1)table = "ROOT_TABLE_BAD"; |
5061 |
|
|
5062 |
|
oss.str(""); |
5063 |
|
oss << " SELECT "; |
5064 |
|
oss << " FOLDER_NAME,FILE_NAME,OBT_TIME_SYNC,LAST_TIME_SYNC_INFO,BOOT_NUMBER,INPUT_NAME "; |
5065 |
|
oss << " FROM "<<table; |
5066 |
|
oss << " WHERE 1 " << endl; |
5067 |
|
oss << " AND FILE_NAME != \""<< thisfilename<<"\""; |
5068 |
|
if( !MISSING_pkt1 ){ |
5069 |
|
oss << " AND "; |
5070 |
|
oss << " PKT_NUMBER_INIT < "<<pkt1; |
5071 |
|
oss << " AND "; |
5072 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt1; |
5073 |
|
oss << " AND "; |
5074 |
|
oss << " PKT_OBT_INIT < "<<obt1; |
5075 |
|
oss << " AND "; |
5076 |
|
oss << " PKT_OBT_FINAL > "<<obt1; |
5077 |
|
}else{ |
5078 |
|
if(pkt2>1) pkt1 = pkt2-1;//serve dopo |
5079 |
|
} |
5080 |
|
if( !MISSING_pkt2 ){ |
5081 |
|
oss << " AND "; |
5082 |
|
oss << " PKT_NUMBER_INIT < "<<pkt2; |
5083 |
|
oss << " AND "; |
5084 |
|
oss << " PKT_NUMBER_FINAL > "<<pkt2; |
5085 |
|
oss << " AND "; |
5086 |
|
oss << " PKT_OBT_INIT < "<<obt2; |
5087 |
|
oss << " AND "; |
5088 |
|
oss << " PKT_OBT_FINAL > "<<obt2; |
5089 |
|
}else{ |
5090 |
|
if(pkt1>0) pkt2 = pkt1+1;//serve dopo |
5091 |
|
} |
5092 |
|
if( boot> 0 ){ |
5093 |
|
oss << " AND "; |
5094 |
|
oss << " BOOT_NUMBER = "<<boot; |
5095 |
|
}else{ |
5096 |
|
} |
5097 |
|
oss << " ORDER BY BAD_PKT_CALREAD ASC; "; |
5098 |
|
|
5099 |
|
TSQLResult *result2 = 0; |
5100 |
|
TSQLRow *row2 = 0; |
5101 |
|
|
5102 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5103 |
|
result2 = conn->Query(oss.str().c_str()); |
5104 |
|
if ( !result2 ) throw -4;; |
5105 |
|
if ( IsDebug() ) cout <<"Rows: "<<result2->GetRowCount()<<endl; |
5106 |
|
|
5107 |
|
// ------------------------------------------------------ |
5108 |
|
// loop over files containing repetition (if any) |
5109 |
|
// ------------------------------------------------------ |
5110 |
|
do { |
5111 |
|
row2 = result2->Next(); |
5112 |
|
if(!row2)break; |
5113 |
|
|
5114 |
|
// ------------------------------------------------------ |
5115 |
|
// ... a repetition is found ... |
5116 |
|
// ------------------------------------------------------ |
5117 |
|
path = (TString)row2->GetField(0); |
5118 |
|
name = (TString)row2->GetField(1); |
5119 |
|
raw = (TString)row2->GetField(5); |
5120 |
|
obt0 = (UInt_t)atoll(row2->GetField(2)); |
5121 |
|
timesync = (UInt_t)atoll(row2->GetField(3)); |
5122 |
|
boot_number = (UInt_t)atoll(row2->GetField(4)); |
5123 |
|
|
5124 |
|
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
5125 |
|
// cout << path <<endl; |
5126 |
|
// cout << "File : " <<name <<endl; |
5127 |
|
// cout << obt0 <<endl; |
5128 |
|
// cout << timesync <<endl; |
5129 |
|
// cout << "boot n. : "<<boot_number <<endl; |
5130 |
|
// cout << raw <<endl; |
5131 |
|
|
5132 |
|
// ------------------------------------------------------ |
5133 |
|
// ... retrieve the calibration packets. |
5134 |
|
// ------------------------------------------------------ |
5135 |
|
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5136 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5137 |
|
if(!file)throw -100; |
5138 |
|
if(file->IsZombie())throw -100; |
5139 |
|
// |
5140 |
|
tr1 = (TTree*)file->Get("CalibTrk1"); |
5141 |
|
if ( !tr1 || tr1->IsZombie() ) throw -22; |
5142 |
|
tr2 = (TTree*)file->Get("CalibTrk2"); |
5143 |
|
if ( !tr2 || tr2->IsZombie() ) throw -23; |
5144 |
|
// |
5145 |
|
tr1->SetBranchAddress("CalibTrk1", &caltrk1); |
5146 |
|
tr1->SetBranchAddress("Header", &eh1); |
5147 |
|
nevents1 = tr1->GetEntries(); |
5148 |
|
tr2->SetBranchAddress("CalibTrk2", &caltrk2); |
5149 |
|
tr2->SetBranchAddress("Header", &eh2); |
5150 |
|
nevents2 = tr2->GetEntries(); |
5151 |
|
for(this_t1=0; this_t1<nevents1; this_t1++){ |
5152 |
|
tr1->GetEntry(this_t1); |
5153 |
|
if( |
5154 |
|
(UInt_t)eh1->GetPscuHeader()->GetCounter() == pkt1 && |
5155 |
|
true) break; |
5156 |
|
this_MISSING_pkt1 = true; |
5157 |
|
} |
5158 |
|
for(this_t2=0; this_t2<nevents2; this_t2++){ |
5159 |
|
tr2->GetEntry(this_t2); |
5160 |
|
if( |
5161 |
|
(UInt_t)eh2->GetPscuHeader()->GetCounter() == pkt2 && |
5162 |
|
true) break; |
5163 |
|
this_MISSING_pkt2 = true; |
5164 |
|
} |
5165 |
|
this_valid = |
5166 |
|
ValidateTrkCalib( caltrk1, eh1, file ) |
5167 |
|
* |
5168 |
|
ValidateTrkCalib( caltrk2, eh2, file ); |
5169 |
|
|
5170 |
|
// --------------------------------------------------------------------- |
5171 |
|
// accept the calibration if it is better than the previous: |
5172 |
|
// |
5173 |
|
// - if the new calibration is perfect (both valid packets) |
5174 |
|
// - if the new calibration has both the packets and the previous does not |
5175 |
|
// --------------------------------------------------------------------- |
5176 |
|
if( |
5177 |
|
( !this_MISSING_pkt1&&!this_MISSING_pkt2&&this_valid )|| |
5178 |
|
( (MISSING_pkt1||MISSING_pkt2) && (!this_MISSING_pkt1&&!this_MISSING_pkt2) )|| |
5179 |
|
false)FOUND=true; |
5180 |
|
|
5181 |
|
if(file)file->Close(); |
5182 |
|
|
5183 |
|
if(FOUND)break; |
5184 |
|
|
5185 |
|
}while(1);//endl loop over root table entries |
5186 |
|
|
5187 |
|
if(FOUND)break; |
5188 |
|
|
5189 |
|
}//end loop over tables |
5190 |
|
|
5191 |
|
if(FOUND){ |
5192 |
|
|
5193 |
|
if ( IsDebug() ) cout << " >>> REPETITION FOUND :-) <<<" <<endl; |
5194 |
|
|
5195 |
|
//////////////////////////////////////////// |
5196 |
|
// insert a new entry in GL_TRK_CALIB and |
5197 |
|
// modify the time-tag of the previous one |
5198 |
|
//////////////////////////////////////////// |
5199 |
|
|
5200 |
|
// --------------------------------------------------------------------- |
5201 |
|
// step 1: insert a new raw file in GL_RAW |
5202 |
|
// --------------------------------------------------------------------- |
5203 |
|
// |
5204 |
|
// check if the raw file already exist |
5205 |
|
// |
5206 |
|
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 |
5207 |
|
// oss.str(""); |
5208 |
|
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5209 |
|
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5210 |
|
|
5211 |
|
// result = conn->Query(oss.str().c_str()); |
5212 |
|
// if ( !result ) throw -4;; |
5213 |
|
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5214 |
|
// if( result->GetRowCount() == 0){ |
5215 |
|
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5216 |
|
// // - - - - - - - - - - - |
5217 |
|
// // insert new raw file |
5218 |
|
// // - - - - - - - - - - - |
5219 |
|
// GL_RAW glraw = GL_RAW(); |
5220 |
|
// glraw.PATH = gSystem->DirName(raw.Data()); |
5221 |
|
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5222 |
|
// glraw.BOOT_NUMBER = boot_number; |
5223 |
|
// // |
5224 |
|
// insertPamelaRawFile( &glraw ); |
5225 |
|
// // |
5226 |
|
// id_raw = glraw.ID; |
5227 |
|
// }else{ |
5228 |
|
// row = result->Next(); |
5229 |
|
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5230 |
|
// } |
5231 |
|
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5232 |
|
|
5233 |
|
// --------------------------------------------------------------------- |
5234 |
|
// step 1(bis): retrieve the timesync id associated to the file |
5235 |
|
// (NB, uso lo stesso associato al file iniziale) |
5236 |
|
// --------------------------------------------------------------------- |
5237 |
|
UInt_t idtimesync = 0; |
5238 |
|
oss.str(""); |
5239 |
|
oss << " SELECT ID FROM GL_TIMESYNC where TIMESYNC="<<chlastts<<" AND OBT0="<<chobtts*1000<<" limit 1;"; |
5240 |
|
if ( debug ) printf(" %s \n",oss.str().c_str()); |
5241 |
|
result = conn->Query(oss.str().c_str()); |
5242 |
|
if ( !result ) throw -3; |
5243 |
|
row = result->Next(); |
5244 |
|
if ( !row ) throw -3; |
5245 |
|
idtimesync = (UInt_t)atoll(row->GetField(0)); |
5246 |
|
if ( IsDebug() ) cout << "ID_TIMESYNC = "<<idtimesync<<endl; |
5247 |
|
|
5248 |
|
// --------------------------------------------------------------------- |
5249 |
|
// step 2: insert a new root file in GL_ROOT |
5250 |
|
// --------------------------------------------------------------------- |
5251 |
|
// |
5252 |
|
// check if the root file already exist |
5253 |
|
// |
5254 |
|
UInt_t id_root = 0; |
5255 |
|
oss.str(""); |
5256 |
|
oss << "SELECT ID FROM GL_ROOT where NAME=\"" << gSystem->BaseName(name.Data()) <<"\";"; |
5257 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5258 |
|
|
5259 |
|
result = conn->Query(oss.str().c_str()); |
5260 |
|
if ( !result ) throw -4;; |
5261 |
|
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5262 |
|
if( result->GetRowCount() == 0){ |
5263 |
|
if ( IsDebug() ) cout << " << Insert new ROOT file >> "<<endl; |
5264 |
|
// - - - - - - - - - - - |
5265 |
|
// insert new root file |
5266 |
|
// - - - - - - - - - - - |
5267 |
|
GL_ROOT glroot = GL_ROOT(); |
5268 |
|
glroot.ID_RAW = id_raw; |
5269 |
|
glroot.ID_TIMESYNC = idtimesync; |
5270 |
|
// |
5271 |
|
// 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, |
5272 |
|
// NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB |
5273 |
|
// |
5274 |
|
if ( STATIC ){ |
5275 |
|
glroot.PATH = (TString)gSystem->ExpandPathName(path); |
5276 |
|
} else { |
5277 |
|
if ( KEEPENV ){ |
5278 |
|
glroot.PATH = path; |
5279 |
|
} else { |
5280 |
|
glroot.PATH = "$PAM_L0"; |
5281 |
|
}; |
5282 |
|
}; |
5283 |
|
// glroot.PATH = path; |
5284 |
|
glroot.NAME = name; |
5285 |
|
// |
5286 |
|
insertPamelaRootFile( &glroot ); |
5287 |
|
// |
5288 |
|
id_root = glroot.ID; |
5289 |
|
}else{ |
5290 |
|
row = result->Next(); |
5291 |
|
if(row)id_root = (UInt_t)atoll(row->GetField(0)); |
5292 |
|
} |
5293 |
|
if ( IsDebug() ) cout << "ID_ROOT = "<<id_root<<endl; |
5294 |
|
|
5295 |
|
// --------------------------------------------------------------------- |
5296 |
|
// step 3: modify time-tag of corrupted GL_TRK_CALIB entry |
5297 |
|
// --------------------------------------------------------------------- |
5298 |
|
if ( IsDebug() ) cout << " << Modify time-tag of calibration ID="<<id<<" >> "<<endl; |
5299 |
|
oss.str(""); |
5300 |
|
oss << " UPDATE GL_TRK_CALIB SET " |
5301 |
|
<< " TO_TIME=0 , FROM_TIME=0 WHERE " |
5302 |
|
<< " ID = "<< id << ";"; |
5303 |
|
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5304 |
|
result = conn->Query(oss.str().c_str()); |
5305 |
|
if ( !result ) throw -4;; |
5306 |
|
|
5307 |
|
// --------------------------------------------------------------------- |
5308 |
|
// step 4: insert the new calibration: |
5309 |
|
// --------------------------------------------------------------------- |
5310 |
|
if ( IsDebug() ) cout << " << Insert new TRK calibration >> "<<endl; |
5311 |
|
// |
5312 |
|
GL_TRK_CALIB glcal = GL_TRK_CALIB(); |
5313 |
|
// |
5314 |
|
glcal.ID_ROOT_L0 = id_root; |
5315 |
|
glcal.EV_ROOT_CALIBTRK1 = this_t1; |
5316 |
|
glcal.EV_ROOT_CALIBTRK2 = this_t2; |
5317 |
|
glcal.FROM_TIME = fromtime; |
5318 |
|
glcal.TO_TIME = totime; |
5319 |
|
glcal.OBT1 = obt1; |
5320 |
|
glcal.OBT2 = obt2; |
5321 |
|
glcal.PKT1 = pkt1; |
5322 |
|
glcal.PKT2 = pkt1; |
5323 |
|
glcal.BOOT_NUMBER = GetBOOTnumber(); |
5324 |
|
glcal.VALIDATION = this_valid; |
5325 |
|
// |
5326 |
|
HandleTRK_CALIB(&glcal); |
5327 |
|
if ( IsDebug() ) cout << "ID = "<<glcal.ID<<endl; |
5328 |
|
// |
5329 |
|
|
5330 |
|
} |
5331 |
|
if ( IsDebug() ) cout << "------------------------------------------------------------" <<endl; |
5332 |
|
|
5333 |
|
}while(1);//end loop over calibrations |
5334 |
|
|
5335 |
|
|
5336 |
|
if( result )delete result; |
5337 |
|
if( row )delete row; |
5338 |
|
|
5339 |
|
|
5340 |
|
|
5341 |
|
|
5342 |
|
|
5343 |
|
|
5344 |
|
} |
5345 |
|
|
5346 |
|
|
5347 |
|
// // ------------------------------ |
5348 |
|
// // try to recover the calibration |
5349 |
|
// // ------------------------------ |
5350 |
|
// cout << "TRY TO RECOVER TRACKER CALIBRATION"<<endl; |
5351 |
|
// // |
5352 |
|
// ULong64_t time = 0; //absolute time |
5353 |
|
// string path[100]; //mettere un limite massimo |
5354 |
|
// int nrows = 0; |
5355 |
|
// UInt_t pkt = 0; |
5356 |
|
// UInt_t obt = 0; |
5357 |
|
// char *type = ""; |
5358 |
|
// EventHeader *eh = new EventHeader(); |
5359 |
|
// CalibTrk1Event *c = new CalibTrk1Event(); |
5360 |
|
|
5361 |
|
// // |
5362 |
|
// if(which_is_not_valid==1 || which_is_not_valid==3){ |
5363 |
|
// // |
5364 |
|
// cout << "PKT1 --> missing or corrupted "<<endl; |
5365 |
|
// type = "CalibTrk1"; |
5366 |
|
// pkt = pkt1; |
5367 |
|
// obt = obt1; |
5368 |
|
// time = this->GetAbsTime(obt1); |
5369 |
|
// if( pkt1 == 0 ){//missing |
5370 |
|
// time = this->GetAbsTime(obt2); |
5371 |
|
// pkt = pkt2-1; |
5372 |
|
// } |
5373 |
|
// // |
5374 |
|
// }else if (which_is_not_valid==2 || which_is_not_valid==3){ |
5375 |
|
// // |
5376 |
|
// cout << "PKT2--> missing or corrupted "<<endl; |
5377 |
|
// type = "CalibTrk2 "; |
5378 |
|
// pkt = pkt2; |
5379 |
|
// obt = obt2; |
5380 |
|
// time = this->GetAbsTime(obt2); |
5381 |
|
// if( pkt2 == 0 ){//missing |
5382 |
|
// time = this->GetAbsTime(obt1); |
5383 |
|
// pkt = pkt1+1; |
5384 |
|
// } |
5385 |
|
// // |
5386 |
|
// }else{ |
5387 |
|
// cout << "this should not happen!!! "<<endl; |
5388 |
|
// trow -666; |
5389 |
|
// } |
5390 |
|
|
5391 |
|
// nrows = Query_ROOT_TABLE(time,conn,path);// get the list of file which might contain the packet |
5392 |
|
|
5393 |
|
|
5394 |
|
// for(int r=0; r<nrows; r++){ //loop over rows |
5395 |
|
// if(path)cout << r << " >>>> "<<(path+r)->c_str() << endl; |
5396 |
|
// /// verifica che il file non sia quello gia` aperto |
5397 |
|
// } |
5398 |
|
|
5399 |
|
// //////////////////////////////////////////////////////////////////////// |
5400 |
|
|
5401 |
|
// TSQLResult *result = 0; |
5402 |
|
// TSQLRow *row = 0; |
5403 |
|
// // |
5404 |
|
// stringstream oss; |
5405 |
|
// oss.str(""); |
5406 |
|
// // ---------------------------------------- |
5407 |
|
// // read the id of last calibration inserted |
5408 |
|
// // ---------------------------------------- |
5409 |
|
// oss.str(""); |
5410 |
|
// oss << " SELECT "; |
5411 |
|
// oss << " (ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,PKT1,OBT2,PKT2,BOOT_NUMBER,VALIDATION) "; |
5412 |
|
// oss << " ORDER BY ID DESC LIMIT 1; "; |
5413 |
|
|
5414 |
|
// result = conn->Query(oss.str().c_str()); |
5415 |
|
// row = result->Next(); |
5416 |
|
// if( !row )throw -666; |
5417 |
|
|
5418 |
|
// if( result )delete result; |
5419 |
|
// if( row )delete row; |
5420 |
|
|
5421 |
|
// UInt_t id = (UInt_t)atoll(row->GetField(0)); |
5422 |
|
|
5423 |
|
// // ------------------------------------- |
5424 |
|
// // ...and modify it with new parameters |
5425 |
|
// // ------------------------------------- |
5426 |
|
|
5427 |
|
|
5428 |
|
// } |
5429 |
// |
// |
5430 |
return(0); |
return(0); |
5431 |
}; |
}; |
6256 |
|
|
6257 |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
GL_TRK_CALIB* trkcalib = new GL_TRK_CALIB(); |
6258 |
|
|
6259 |
// get the closest VALIDATED calibration before the run start (t2) |
// get the closest calibration before the run start (t2) |
6260 |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
if ( trkcalib->Query_GL_TRK_CALIB(t2, conn) )return(true); //>>> missing |
6261 |
|
|
6262 |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
if ( trkcalib->TO_TIME < t2 ) return(true); //>>> missing |
6950 |
* Rearrange calibration tables |
* Rearrange calibration tables |
6951 |
* |
* |
6952 |
**/ |
**/ |
6953 |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh , TFile *file){ |
6954 |
|
|
6955 |
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; // :-) |
|
6956 |
|
|
6957 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
if ( IsDebug() ) cout << "ValidateTrkCalib:"<<endl; |
6958 |
|
|
6959 |
// ----------------------------------------------- |
UInt_t validate = 1; |
6960 |
// If missing packets: check the acq configuration |
Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,0}; |
6961 |
// (some DSPs might be excluded from acquisition) |
UInt_t timeaftercalib=120000; //2000; |
6962 |
// ----------------------------------------------- |
TString classname = caltrk->GetName(); |
6963 |
|
|
6964 |
// ----------------------------------------------- |
// ---------------------------------- |
6965 |
// retrieve the first run header after calib |
// Check CRCs and failed calibrations |
6966 |
// ----------------------------------------------- |
// ---------------------------------- |
6967 |
PacketType *pctp; |
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
6968 |
EventCounter *cod; |
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
6969 |
cod = eh->GetCounter(); |
if( caltrk->crc_hcal[ipkt] ){ |
6970 |
Int_t irun = cod->Get(pctp->RunHeader); |
// if(IsDebug())cout<<"(CRC Header)"; |
6971 |
TTree *rh=(TTree*)file->Get("RunHeader"); |
validate = 0; |
6972 |
if ( !rh || rh->IsZombie() ) throw -17; |
if(IsDebug())cout <<endl<<" *** CRC *** (header DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
6973 |
if( rh->GetEntries() == irun ){ |
|
6974 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
} |
6975 |
return 0; // :-( |
for(Int_t ilad=0; ilad<3; ilad++)if( caltrk->crc_cal[ipkt][ilad] ){ |
6976 |
} |
// if(IsDebug())cout<<"(CRC Pkt-"<<ilad<<")"; |
6977 |
|
if(IsDebug())cout <<endl<<" *** CRC *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<" ladder "<<ilad<<")"; |
6978 |
|
validate = 0; |
6979 |
|
} |
6980 |
|
if( !(caltrk->ncalib_event[ipkt]==0 && caltrk->cal_flag[ipkt]==0) ){ |
6981 |
|
if(IsDebug())cout <<endl<<" *** FAILURE *** (data DSPn "<<caltrk->DSPnumber[ipkt]<<")"; |
6982 |
|
validate = 0; |
6983 |
|
} |
6984 |
|
}else{ |
6985 |
|
// validate=0; |
6986 |
|
if(IsDebug())cout <<endl<<" *** DSPn *** ("<< caltrk->DSPnumber[ipkt] <<" @pkt "<<ipkt<<")"; |
6987 |
|
} |
6988 |
|
} |
6989 |
|
|
6990 |
RunHeaderEvent *run = 0; |
// ----------------------- |
6991 |
EventHeader *hrun = 0; |
// Check missing packets: |
6992 |
rh->SetBranchAddress("RunHeader", &run); |
// ----------------------- |
6993 |
rh->SetBranchAddress("Header", &hrun); |
// Readout order: |
6994 |
rh->GetEntry(irun); |
// ------------------ |
6995 |
// cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
// DSP packet board |
6996 |
|
// ------------------ |
6997 |
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
// 12 0 1 |
6998 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
// 10 1 1 |
6999 |
return 0; // :-( |
// 8 2 1 |
7000 |
} |
// 4 3 1 |
7001 |
|
// 6 4 1 |
7002 |
if( !run->RM_ACQ_AFTER_CALIB ){ |
// 2 5 1 |
7003 |
if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
// ------------------ |
7004 |
return 0; // :-( |
// 11 0 2 |
7005 |
} |
// 9 1 2 |
7006 |
|
// 7 2 2 |
7007 |
|
// 3 3 2 |
7008 |
|
// 5 4 2 |
7009 |
|
// 1 5 2 |
7010 |
|
// ------------------ |
7011 |
|
// ------------------------------------------------- |
7012 |
|
// Check if it is first or second calibration packet |
7013 |
|
// ------------------------------------------------- |
7014 |
|
UInt_t build=0; |
7015 |
|
UInt_t base=0; |
7016 |
|
UInt_t mask=0; |
7017 |
|
if(classname.Contains("CalibTrk1Event")){ |
7018 |
|
base=12; |
7019 |
|
mask=0x03F000; |
7020 |
|
} |
7021 |
|
if(classname.Contains("CalibTrk2Event")){ |
7022 |
|
base=18; |
7023 |
|
mask=0xFC0000; |
7024 |
|
} |
7025 |
|
// ---------------------------------------------------- |
7026 |
|
// Count number of valid packets and set build variable |
7027 |
|
// ---------------------------------------------------- |
7028 |
|
if(IsDebug())cout <<endl<< " DSP: "; |
7029 |
|
Int_t npkts=0; |
7030 |
|
for(Int_t ipkt=0; ipkt<6; ipkt++){ |
7031 |
|
if(caltrk->DSPnumber[ipkt]>0 && caltrk->DSPnumber[ipkt]<=12){ |
7032 |
|
if(IsDebug())cout <<" "<<caltrk->DSPnumber[ipkt]; |
7033 |
|
npkts++; |
7034 |
|
build = build | ( 1<<(base+vorder[caltrk->DSPnumber[ipkt]-1]) ); |
7035 |
|
// cout << caltrk->DSPnumber[ipkt] |
7036 |
|
}; |
7037 |
|
} |
7038 |
|
if(IsDebug())cout << " ==> "<< hex << build << dec; |
7039 |
|
// ---------------------------------------------------- |
7040 |
|
// If the number of valid packets is 6, ok exit... |
7041 |
|
// ---------------------------------------------------- |
7042 |
|
if( npkts==6 ){ |
7043 |
|
return validate; // exit |
7044 |
|
} |
7045 |
|
//////////////////////////////////////////////////////// |
7046 |
|
// ...otherwise there might be some missing packets |
7047 |
|
// |
7048 |
|
// In this case check the acq configuration |
7049 |
|
// (some DSPs might be excluded from acquisition) |
7050 |
|
//////////////////////////////////////////////////////// |
7051 |
|
|
7052 |
|
if(!eh || !file || (file&&file->IsZombie()) ){ |
7053 |
|
if ( IsDebug() )cout << " *** MISSING VIEW *** eh="<<eh<<" file="<<file<<" cannot validate"<<endl; |
7054 |
|
return (0); |
7055 |
|
} |
7056 |
|
|
7057 |
|
// ----------------------------------------------- |
7058 |
|
// retrieve the first run header after calib |
7059 |
|
// ----------------------------------------------- |
7060 |
|
|
7061 |
|
PacketType *pctp; |
7062 |
|
EventCounter *cod; |
7063 |
|
cod = eh->GetCounter(); |
7064 |
|
Int_t irun = cod->Get(pctp->RunHeader); |
7065 |
|
TTree *rh=(TTree*)file->Get("RunHeader"); |
7066 |
|
if ( !rh || rh->IsZombie() ) throw -17; |
7067 |
|
if( rh->GetEntries() <= irun ){ |
7068 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (1) -- cannot validate :-( "<<endl; |
7069 |
|
return 0; // :-( |
7070 |
|
} |
7071 |
|
RunHeaderEvent *run = 0; |
7072 |
|
EventHeader *hrun = 0; |
7073 |
|
rh->SetBranchAddress("RunHeader", &run); |
7074 |
|
rh->SetBranchAddress("Header", &hrun); |
7075 |
|
rh->GetEntry(irun); |
7076 |
|
if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
7077 |
|
if ( IsDebug() ) cout << " *** MISSING-PKT *** no runs after calib (2) -- cannot validate :-( "<<endl; |
7078 |
|
return 0; // :-( |
7079 |
|
} |
7080 |
|
|
7081 |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
7082 |
if( dtime > timeaftercalib ){ |
if( dtime > timeaftercalib ){ |
7083 |
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; |
7084 |
return 0; // :-( |
return 0; // :-( |
7085 |
} |
} |
|
|
|
7086 |
|
|
7087 |
|
if ( IsDebug() ) cout <<endl<< " ACQ_BUILD_INFO ==> "<<hex<<(run->ACQ_BUILD_INFO & mask)<<dec; |
7088 |
|
|
7089 |
|
if( (run->ACQ_BUILD_INFO & mask) != build ){ |
7090 |
|
validate=0; // :-( |
7091 |
|
cout <<endl<< " *** MISSING-PKT *** packet mismatch: ACQ_BUILD_INFO="<<hex<<(run->ACQ_BUILD_INFO&mask)<<" != "<<build<<dec; |
7092 |
|
}; |
7093 |
|
|
7094 |
|
return validate; |
7095 |
|
|
|
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; // :-) |
|
7096 |
|
|
7097 |
} |
} |
7098 |
|
|