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 |
|
|
660 |
UInt_t tjump = 50000; |
UInt_t tjump = 50000; |
661 |
//UInt_t tjump = 100; |
//UInt_t tjump = 100; |
662 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
663 |
pktlast = numeric_limits<UInt_t>::max(); |
// pktlast = numeric_limits<UInt_t>::max(); |
664 |
while ( pktlast > chpktmax && (Int_t)(nevent-1-it) >= 0 ){ |
pktlast = chpktmax + 1; |
665 |
|
while ( PKT(pktlast) > PKT(chpktmax) && (Int_t)(nevent-1-it) >= 0 ){ |
666 |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
if ( (Int_t)(nevent-1-it) >= 0 ){ |
667 |
T->GetEntry(nevent-1-it); |
T->GetEntry(nevent-1-it); |
668 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
670 |
} else { |
} else { |
671 |
pktlast = chpktmax + 1; |
pktlast = chpktmax + 1; |
672 |
}; |
}; |
673 |
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)); |
674 |
it += tjump; |
it += tjump; |
675 |
}; |
}; |
676 |
if ( tjump > 1 ) it -= 2*tjump; |
if ( tjump > 1 ) it -= 2*tjump; |
694 |
tjump = 50000; |
tjump = 50000; |
695 |
//tjump = 100; |
//tjump = 100; |
696 |
while ( tjump > 0 ){ |
while ( tjump > 0 ){ |
697 |
pktlast = 0; |
// pktlast = 0; |
698 |
while ( pktlast < chpktmin && it < (Int_t)nevent ){ |
pktlast = chpktmin - 1; |
699 |
|
if ( debug ) printf("LLlook for down %i %i %llu %llu \n",it,pktlast,PKT(pktlast),PKT(chpktmin)); |
700 |
|
while ( PKT(pktlast) < PKT(chpktmin) && it < (Int_t)nevent ){ |
701 |
if ( it < (Int_t)nevent ){ |
if ( it < (Int_t)nevent ){ |
702 |
T->GetEntry(it); |
T->GetEntry(it); |
703 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1139 |
stringstream oss; |
stringstream oss; |
1140 |
// |
// |
1141 |
oss.str(""); |
oss.str(""); |
1142 |
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. |
1143 |
|
if ( !strcmp(tag.Data(),"NONE") ){ |
1144 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< chiby.Data() <<"');"; |
1145 |
|
} else { |
1146 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1147 |
|
}; |
1148 |
|
} else { |
1149 |
|
oss << "INSERT INTO _RUNID_GEN VALUES (NULL,'"<< tag.Data() <<"');"; |
1150 |
|
}; |
1151 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
1152 |
if ( !result ) throw -10; |
if ( !result ) throw -10; |
1153 |
oss.str(""); |
oss.str(""); |
1486 |
// PUBLIC FUNCTIONS |
// PUBLIC FUNCTIONS |
1487 |
// |
// |
1488 |
|
|
|
// /** |
|
|
// * Insert a new row into GL_RAW table. |
|
|
// */ |
|
|
// Int_t PamelaDBOperations::insertPamelaRawFile(){ |
|
|
// // |
|
|
// stringstream oss; |
|
|
// // |
|
|
// Bool_t idr = this->SetID_RAW(); |
|
|
// if ( idr ) return(1); |
|
|
// // |
|
|
// oss.str(""); |
|
|
// if ( STATIC ){ |
|
|
// oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('" |
|
|
// << this->GetRawPath().Data() << "', '" << this->GetRawFile().Data() << "')"; |
|
|
// } else { |
|
|
// oss << "INSERT INTO GL_RAW (PATH, NAME) VALUES ('$PAM_RAW', '" << this->GetRawFile().Data() << "')"; |
|
|
// }; |
|
|
// if ( conn->Query(oss.str().c_str()) == 0 ) throw -4; |
|
|
// // |
|
|
// idr = this->SetID_RAW(); |
|
|
// if ( !idr ) throw -11; |
|
|
// // |
|
|
// return(0); |
|
|
// } |
|
1489 |
/** |
/** |
1490 |
* Insert a new row into GL_RAW table. |
* Insert a new row into GL_RAW table. |
1491 |
*/ |
*/ |
1499 |
|
|
1500 |
glraw.PATH = GetRawPath(); |
glraw.PATH = GetRawPath(); |
1501 |
glraw.NAME = GetRawFile(); |
glraw.NAME = GetRawFile(); |
1502 |
glraw.BOOT_NUMBER = 0;//??? |
// glraw.BOOT_NUMBER = 0;//??? |
1503 |
|
glraw.BOOT_NUMBER = this->GetBOOTnumber(); |
1504 |
|
|
1505 |
if( insertPamelaRawFile(&glraw) )return(1); |
if( insertPamelaRawFile(&glraw) )return(1); |
1506 |
// |
// |
1514 |
*/ |
*/ |
1515 |
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
Int_t PamelaDBOperations::insertPamelaRawFile(GL_RAW *glraw){ |
1516 |
// |
// |
1517 |
if(!glraw)return(1);//?? |
if(!glraw)return(1);//?? ok I think |
1518 |
// |
// |
1519 |
stringstream oss; |
stringstream oss; |
1520 |
// |
// |
1851 |
return(signal); |
return(signal); |
1852 |
} |
} |
1853 |
|
|
|
// /** |
|
|
// * Insert all the new rows into GL_ROOT. |
|
|
// * The raw file indicates in the parameters should be already been stored in the database. |
|
|
// */ |
|
|
// Int_t PamelaDBOperations::insertPamelaRootFile(){ |
|
|
// stringstream oss; |
|
|
// TSQLResult *result = 0; |
|
|
// TSQLRow *row = 0; |
|
|
// UInt_t idtimesync = 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; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( !row ) throw -3; |
|
|
// idtimesync = (UInt_t)atoll(row->GetField(0)); |
|
|
// } else { |
|
|
// oss.str(""); |
|
|
// if ( STATIC ){ |
|
|
// oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
|
|
// << " LEFT JOIN GL_ROOT " |
|
|
// << " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
|
|
// << " WHERE GL_RAW.PATH = '" << this->GetRawPath().Data() << "' AND " |
|
|
// << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
|
|
// } else { |
|
|
// oss << " SELECT COUNT(GL_ROOT.ID_RAW),GL_RAW.ID,GL_ROOT.ID FROM GL_RAW " |
|
|
// << " LEFT JOIN GL_ROOT " |
|
|
// << " ON GL_RAW.ID = GL_ROOT.ID_RAW " |
|
|
// << " WHERE GL_RAW.PATH = '$PAM_RAW' AND " |
|
|
// << " GL_RAW.NAME = '" << this->GetRawFile().Data() << "' GROUP BY GL_RAW.ID "; |
|
|
// }; |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -12; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( !row ) throw -10; |
|
|
// if ( row != NULL && (UInt_t)atoll(row->GetField(0))>0 ){ |
|
|
// idroot = (UInt_t)atoll(row->GetField(2)); |
|
|
// return(1); |
|
|
// }; |
|
|
// // |
|
|
// // determine which timesync has to be used |
|
|
// // |
|
|
// oss.str(""); |
|
|
// 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;"; |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -3; |
|
|
// // |
|
|
// row = result->Next(); |
|
|
// // |
|
|
// if ( !row ) throw -3; |
|
|
// idtimesync = (UInt_t)atoll(row->GetField(0)); |
|
|
// }; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// if ( STATIC ){ |
|
|
// oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
|
|
// << 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() << "')"; |
|
|
// }; |
|
|
// // |
|
|
// if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
|
|
// if (conn->Query(oss.str().c_str()) == 0) throw -4; |
|
|
// // |
|
|
// delete result; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// // oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
|
|
// if ( STATIC ){ |
|
|
// 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() <<"';"; |
|
|
// }; |
|
|
// // |
|
|
// if ( debug ) printf(" query is %s \n",oss.str().c_str()); |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// if ( !result ) throw -12; |
|
|
// row = result->Next(); |
|
|
// if ( !row ) throw -3; |
|
|
// this->SetID_ROOT((UInt_t)atoll(row->GetField(0))); |
|
|
// if ( debug ) printf(" The ID of the ROOT file is %u \n",this->GetID_ROOT()); |
|
|
// // |
|
|
// delete result; |
|
|
// // |
|
|
// return(0); |
|
|
// } |
|
1854 |
/** |
/** |
1855 |
* Insert all the new rows into GL_ROOT. |
* Insert all the new rows into GL_ROOT. |
1856 |
* 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. |
1860 |
stringstream oss; |
stringstream oss; |
1861 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1862 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1863 |
// |
// |
1864 |
// ---------------------- |
// ---------------------- |
1865 |
// determine the timesync |
// determine the timesync |
1866 |
// ---------------------- |
// ---------------------- |
1932 |
|
|
1933 |
glroot.ID_RAW = GetID_RAW(); |
glroot.ID_RAW = GetID_RAW(); |
1934 |
glroot.ID_TIMESYNC = idtimesync; |
glroot.ID_TIMESYNC = idtimesync; |
1935 |
glroot.PATH = GetRootPath(); |
if ( STATIC ){ |
1936 |
|
glroot.PATH = GetRootPath(); |
1937 |
|
} else { |
1938 |
|
if ( KEEPENV ){ |
1939 |
|
glroot.PATH = gSystem->DirName(filerootname.Data()); |
1940 |
|
} else { |
1941 |
|
glroot.PATH = "$PAM_L0"; |
1942 |
|
}; |
1943 |
|
}; |
1944 |
glroot.NAME = GetRootFile(); |
glroot.NAME = GetRootFile(); |
1945 |
|
|
1946 |
if ( insertPamelaRootFile(&glroot) )return 1; |
if ( insertPamelaRootFile(&glroot) )return 1; |
1955 |
* 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. |
1956 |
*/ |
*/ |
1957 |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
Int_t PamelaDBOperations::insertPamelaRootFile(GL_ROOT *glroot){ |
|
|
|
|
|
|
|
|
|
1958 |
stringstream oss; |
stringstream oss; |
1959 |
TSQLResult *result = 0; |
TSQLResult *result = 0; |
1960 |
TSQLRow *row = 0; |
TSQLRow *row = 0; |
1961 |
// |
// |
1962 |
// |
// |
1963 |
oss.str(""); |
oss.str(""); |
1964 |
if ( STATIC ){ |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
1965 |
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; |
|
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '" << glroot->PATH << "', '" << glroot->NAME << "')"; |
|
|
} else { |
|
|
oss << "INSERT INTO GL_ROOT (ID_RAW, ID_TIMESYNC,PATH, NAME) VALUES ('" |
|
|
<< glroot->ID_RAW << "', '" << glroot->ID_TIMESYNC << "', '$PAM_L0', '" << glroot->NAME << "')"; |
|
|
}; |
|
1966 |
// |
// |
1967 |
if ( debug ) printf("%s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1968 |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
if (conn->Query(oss.str().c_str()) == 0) throw -4; |
1971 |
// |
// |
1972 |
oss.str(""); |
oss.str(""); |
1973 |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
// oss << "SELECT ID FROM GL_ROOT WHERE ID_RAW=" << this->GetID_RAW() << ";"; |
1974 |
if ( STATIC ){ |
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; |
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='" << glroot->PATH << "' and NAME='"<< glroot->NAME <<"';"; |
|
|
} else { |
|
|
oss << "SELECT ID FROM GL_ROOT WHERE PATH='$PAM_L0' and NAME='"<< glroot->NAME <<"';"; |
|
|
}; |
|
1975 |
// |
// |
1976 |
if ( debug ) printf("%s \n",oss.str().c_str()); |
if ( debug ) printf("%s \n",oss.str().c_str()); |
1977 |
result = conn->Query(oss.str().c_str()); |
result = conn->Query(oss.str().c_str()); |
3346 |
// 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 |
3347 |
// |
// |
3348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3349 |
mishead = true; |
mishead = true; |
3350 |
|
|
3351 |
|
|
3665 |
}; // EEE |
}; // EEE |
3666 |
|
|
3667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3668 |
} else { |
} else { |
3669 |
if ( !IsRunAlreadyInserted() ){ |
if ( !IsRunAlreadyInserted() ){ |
3670 |
glrun->SetID(this->AssignRunID()); |
glrun->SetID(this->AssignRunID()); |
4495 |
return(0); |
return(0); |
4496 |
}; |
}; |
4497 |
|
|
|
// /** |
|
|
// * Fill the GL_TRK_CALIB table |
|
|
// */ |
|
|
// void PamelaDBOperations::HandleTRK_CALIB(Bool_t pk1, Bool_t pk2){ |
|
|
// // |
|
|
// TSQLResult *result = 0; |
|
|
// 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; |
|
|
// // |
|
|
// } else { |
|
|
// // |
|
|
// // we have to insert a new calibration, check where to place it |
|
|
// // |
|
|
// oss.str(""); |
|
|
// oss << " SELECT ID,TO_TIME FROM GL_TRK_CALIB WHERE " |
|
|
// << " FROM_TIME < "<< fromtime << " AND " |
|
|
// << " TO_TIME > "<< fromtime << ";"; |
|
|
// // |
|
|
// if ( IsDebug() ) printf(" Check where to place the trk 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 ){ |
|
|
// // |
|
|
// // no calibrations in the db contain our calibration |
|
|
// // |
|
|
// 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; |
|
|
// // |
|
|
// }; |
|
|
// // |
|
|
// oss.str(""); |
|
|
// 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 << "',"; |
|
|
// // |
|
|
// if ( !pk1 ){ |
|
|
// oss << "NULL,"; |
|
|
// } else { |
|
|
// oss << "'" |
|
|
// << t1 << "',"; |
|
|
// }; |
|
|
// // |
|
|
// if ( !pk2 ){ |
|
|
// oss << "NULL,'"; |
|
|
// } else { |
|
|
// oss << "'" |
|
|
// << t2 << "','"; |
|
|
// }; |
|
|
// // |
|
|
// 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()); |
|
|
// // |
|
|
// result = conn->Query(oss.str().c_str()); |
|
|
// // |
|
|
// if ( !result ) throw -4; |
|
|
// // |
|
|
// }; |
|
|
// // |
|
|
// }; |
|
4498 |
/** |
/** |
4499 |
* Fill the GL_TRK_CALIB table |
* Fill the GL_TRK_CALIB table |
4500 |
*/ |
*/ |
4895 |
// |
// |
4896 |
}; |
}; |
4897 |
// |
// |
4898 |
|
|
4899 |
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
4900 |
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
4901 |
|
ncalib++; |
4902 |
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
4903 |
|
} |
4904 |
|
|
4905 |
|
|
4906 |
} else { |
} else { |
4907 |
// |
// |
4908 |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
if ( IsDebug() ) printf(" Trk calibration1 at time %u obt %u pkt %u OUTSIDE the considered time interval \n",fromtime,obt1,pkt1); |
4909 |
// if ( PEDANTIC ) throw -79; |
// if ( PEDANTIC ) throw -79; |
4910 |
// |
// |
4911 |
}; |
}; |
4912 |
// |
// |
4913 |
|
|
|
if( !(MISSING_pkt1&MISSING_pkt2) ){ |
|
|
this->HandleTRK_CALIB(!MISSING_pkt1,!MISSING_pkt2); |
|
|
ncalib++; |
|
|
if( MISSING_pkt1||MISSING_pkt2||!valid )try_to_recover=true; |
|
|
} |
|
|
|
|
4914 |
}; //end loop on pkt1 |
}; //end loop on pkt1 |
4915 |
|
|
4916 |
|
|
5126 |
|
|
5127 |
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
if ( IsDebug() ) cout << "- - - - - - - - - - -" <<endl; |
5128 |
// cout << path <<endl; |
// cout << path <<endl; |
5129 |
cout << "File : " <<name <<endl; |
// cout << "File : " <<name <<endl; |
5130 |
// cout << obt0 <<endl; |
// cout << obt0 <<endl; |
5131 |
// cout << timesync <<endl; |
// cout << timesync <<endl; |
5132 |
cout << "boot n. : "<<boot_number <<endl; |
// cout << "boot n. : "<<boot_number <<endl; |
5133 |
// cout << raw <<endl; |
// cout << raw <<endl; |
5134 |
|
|
5135 |
// ------------------------------------------------------ |
// ------------------------------------------------------ |
5136 |
// ... retrieve the calibration packets. |
// ... retrieve the calibration packets. |
5137 |
// ------------------------------------------------------ |
// ------------------------------------------------------ |
5138 |
TFile *file = new TFile(path+"/"+name); |
if ( IsDebug() ) printf(" file is %s/%s \n",((TString)gSystem->ExpandPathName(path.Data())).Data(),name.Data()); |
5139 |
|
TFile *file = new TFile(((TString)gSystem->ExpandPathName(path.Data()))+"/"+name); // EM, path could be symbolic and we must expand it |
5140 |
if(!file)throw -100; |
if(!file)throw -100; |
5141 |
if(file->IsZombie())throw -100; |
if(file->IsZombie())throw -100; |
5142 |
// |
// |
5206 |
// |
// |
5207 |
// check if the raw file already exist |
// check if the raw file already exist |
5208 |
// |
// |
5209 |
UInt_t id_raw = 0; |
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 |
5210 |
oss.str(""); |
// oss.str(""); |
5211 |
oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
// oss << "SELECT ID FROM GL_RAW where NAME=\"" << gSystem->BaseName(raw.Data()) <<"\";"; |
5212 |
if ( IsDebug() ) cout << oss.str().c_str() << endl; |
// if ( IsDebug() ) cout << oss.str().c_str() << endl; |
5213 |
|
|
5214 |
result = conn->Query(oss.str().c_str()); |
// result = conn->Query(oss.str().c_str()); |
5215 |
if ( !result ) throw -4;; |
// if ( !result ) throw -4;; |
5216 |
if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
// if ( IsDebug() ) cout <<"Rows: "<<result->GetRowCount()<<endl; |
5217 |
if( result->GetRowCount() == 0){ |
// if( result->GetRowCount() == 0){ |
5218 |
if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
// if ( IsDebug() ) cout << " << Insert new RAW file >> "<<endl; |
5219 |
// - - - - - - - - - - - |
// // - - - - - - - - - - - |
5220 |
// insert new raw file |
// // insert new raw file |
5221 |
// - - - - - - - - - - - |
// // - - - - - - - - - - - |
5222 |
GL_RAW glraw = GL_RAW(); |
// GL_RAW glraw = GL_RAW(); |
5223 |
glraw.PATH = gSystem->DirName(raw.Data()); |
// glraw.PATH = gSystem->DirName(raw.Data()); |
5224 |
glraw.NAME = gSystem->BaseName(raw.Data()); |
// glraw.NAME = gSystem->BaseName(raw.Data()); |
5225 |
glraw.BOOT_NUMBER = boot_number; |
// glraw.BOOT_NUMBER = boot_number; |
5226 |
// |
// // |
5227 |
insertPamelaRawFile( &glraw ); |
// insertPamelaRawFile( &glraw ); |
5228 |
// |
// // |
5229 |
id_raw = glraw.ID; |
// id_raw = glraw.ID; |
5230 |
}else{ |
// }else{ |
5231 |
row = result->Next(); |
// row = result->Next(); |
5232 |
id_raw = (UInt_t)atoll(row->GetField(0)); |
// id_raw = (UInt_t)atoll(row->GetField(0)); |
5233 |
} |
// } |
5234 |
if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
// if ( IsDebug() ) cout << "ID_RAW = "<<id_raw<<endl; |
5235 |
|
|
5236 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5237 |
// step 1(bis): retrieve the timesync id associated to the file |
// step 1(bis): retrieve the timesync id associated to the file |
5252 |
// step 2: insert a new root file in GL_ROOT |
// step 2: insert a new root file in GL_ROOT |
5253 |
// --------------------------------------------------------------------- |
// --------------------------------------------------------------------- |
5254 |
// |
// |
5255 |
// check if the raw file already exist |
// check if the root file already exist |
5256 |
// |
// |
5257 |
UInt_t id_root = 0; |
UInt_t id_root = 0; |
5258 |
oss.str(""); |
oss.str(""); |
5270 |
GL_ROOT glroot = GL_ROOT(); |
GL_ROOT glroot = GL_ROOT(); |
5271 |
glroot.ID_RAW = id_raw; |
glroot.ID_RAW = id_raw; |
5272 |
glroot.ID_TIMESYNC = idtimesync; |
glroot.ID_TIMESYNC = idtimesync; |
5273 |
glroot.PATH = path; |
// |
5274 |
|
// 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, |
5275 |
|
// NOT STATIC NOT KEEPENV = $PAM_L0 must be used in the DB |
5276 |
|
// |
5277 |
|
if ( STATIC ){ |
5278 |
|
glroot.PATH = (TString)gSystem->ExpandPathName(path); |
5279 |
|
} else { |
5280 |
|
if ( KEEPENV ){ |
5281 |
|
glroot.PATH = path; |
5282 |
|
} else { |
5283 |
|
glroot.PATH = "$PAM_L0"; |
5284 |
|
}; |
5285 |
|
}; |
5286 |
|
// glroot.PATH = path; |
5287 |
glroot.NAME = name; |
glroot.NAME = name; |
5288 |
// |
// |
5289 |
insertPamelaRootFile( &glroot ); |
insertPamelaRootFile( &glroot ); |
7098 |
|
|
7099 |
|
|
7100 |
} |
} |
|
// UInt_t PamelaDBOperations::ValidateTrkCalib( CalibTrk1Event* caltrk, EventHeader *eh ){ |
|
|
|
|
|
// if(!caltrk || !eh) return 0; |
|
|
|
|
|
// Int_t vorder[]={5,5,3,3,4,4,2,2,1,1,0,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; // :-) |
|
|
|
|
|
// // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime()<<endl; |
|
|
|
|
|
// // ----------------------------------------------- |
|
|
// // If missing packets: check the acq configuration |
|
|
// // (some DSPs might be excluded from acquisition) |
|
|
// // ----------------------------------------------- |
|
|
|
|
|
// // ----------------------------------------------- |
|
|
// // retrieve the first run header after calib |
|
|
// // ----------------------------------------------- |
|
|
// PacketType *pctp; |
|
|
// EventCounter *cod; |
|
|
// cod = eh->GetCounter(); |
|
|
// Int_t irun = cod->Get(pctp->RunHeader); |
|
|
// TTree *rh=(TTree*)file->Get("RunHeader"); |
|
|
// if ( !rh || rh->IsZombie() ) throw -17; |
|
|
// if( rh->GetEntries() == irun ){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (1) -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
// RunHeaderEvent *run = 0; |
|
|
// EventHeader *hrun = 0; |
|
|
// rh->SetBranchAddress("RunHeader", &run); |
|
|
// rh->SetBranchAddress("Header", &hrun); |
|
|
// rh->GetEntry(irun); |
|
|
// // cout << classname << " "<<eh->GetPscuHeader()->GetOrbitalTime() << " Run " << hrun->GetPscuHeader()->GetOrbitalTime() <<endl; |
|
|
|
|
|
// if( OBT(hrun->GetPscuHeader()->GetOrbitalTime()) < OBT(eh->GetPscuHeader()->GetOrbitalTime())){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) no runs after calib (2) -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
// if( !run->RM_ACQ_AFTER_CALIB ){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) RM_ACQ_AFTER_CALIB=0 -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
// UInt_t dtime = OBT(hrun->GetPscuHeader()->GetOrbitalTime()) - OBT(eh->GetPscuHeader()->GetOrbitalTime()); |
|
|
// if( dtime > timeaftercalib ){ |
|
|
// if ( IsDebug() ) cout << "ValidateTrkCalib: (MISSING VIEW) run after calib too far ( "<<dtime<<"ms ) -- cannot validate :-( "<<endl; |
|
|
// return 0; // :-( |
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 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; // :-) |
|
|
|
|
|
// } |
|
7101 |
|
|
7102 |
/** |
/** |
7103 |
* |
* |