| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $Id: PamOffLineSW_Main.cpp,v 1.7 2009/08/05 18:48:43 pam-fi Exp $ |
// $Id: PamOffLineSW_Main.cpp,v 1.14 2010/02/16 13:38:13 mocchiut Exp $ |
| 3 |
// Description : Pamela Off-Line Software |
// Description : Pamela Off-Line Software |
| 4 |
//============================================================================ |
//============================================================================ |
| 5 |
|
|
| 45 |
bool simulated_data = false; |
bool simulated_data = false; |
| 46 |
//bool do_vrl_check = false; //EMI |
//bool do_vrl_check = false; //EMI |
| 47 |
bool do_vrl_check = true; //EMI |
bool do_vrl_check = true; //EMI |
| 48 |
|
int cclung = 0; |
| 49 |
|
Bool_t headok = true; |
| 50 |
|
Bool_t crcok = true; |
| 51 |
|
|
| 52 |
const char* db_host = ""; |
const char* db_host = ""; |
| 53 |
int db_port = 0; |
int db_port = 0; |
| 63 |
|
|
| 64 |
Long64_t filelength = 0LL; |
Long64_t filelength = 0LL; |
| 65 |
Long64_t streamposi = 0LL; |
Long64_t streamposi = 0LL; |
| 66 |
|
Long64_t streamposisaved = 0LL; |
| 67 |
|
Long64_t streamposiorig = 0LL; |
| 68 |
|
Int_t numposi = 10; |
| 69 |
Long64_t downcount = 1LL; |
Long64_t downcount = 1LL; |
| 70 |
TArrayL64 *dwin=new TArrayL64(12); |
TArrayL64 *dwin=new TArrayL64(12); |
| 71 |
Long64_t cadcount = 0LL; |
Long64_t cadcount = 0LL; |
| 72 |
|
Int_t horrorcount = 0; |
| 73 |
|
Int_t hc = 0; |
| 74 |
|
|
| 75 |
bool skip_cadre = false; |
bool skip_cadre = false; |
| 76 |
long int iNumGoodCadres=0; //total number of good cadres |
long int iNumGoodCadres=0; //total number of good cadres |
| 80 |
{ |
{ |
| 81 |
const char* db_user = ""; |
const char* db_user = ""; |
| 82 |
const char* db_pwd = ""; |
const char* db_pwd = ""; |
| 83 |
char* connection = NULL; |
char* pelosconnection = NULL; |
| 84 |
//marco_new_01 |
//marco_new_01 |
| 85 |
bool single_connection=false; |
bool single_connection=false; |
| 86 |
long int iNumCadres=0; //cadre's number |
long int iNumCadres=0; //cadre's number |
| 257 |
continue; |
continue; |
| 258 |
} |
} |
| 259 |
|
|
| 260 |
if (!strcmp(argv[i], "-time_Offset")){ |
if (!strcmp(argv[i], "-time_Offset") || !strcmp(argv[i], "-time_offset") ){ |
| 261 |
if (++i >= argc){ |
if (++i >= argc){ |
| 262 |
cerr << "-time_Offset needs arguments. \n"; |
cerr << "-time_Offset needs arguments. \n"; |
| 263 |
cout << "Try '-help' for more information. \n"; |
cout << "Try '-help' for more information. \n"; |
| 636 |
char *pamdbhost = getenv("PAM_DBHOST"); |
char *pamdbhost = getenv("PAM_DBHOST"); |
| 637 |
if (pamdbhost) |
if (pamdbhost) |
| 638 |
{ |
{ |
| 639 |
connection = pamdbhost; |
pelosconnection = pamdbhost; |
| 640 |
} |
} |
| 641 |
else |
else |
| 642 |
{ |
{ |
| 655 |
db_name="chewbacca_db"; |
db_name="chewbacca_db"; |
| 656 |
} |
} |
| 657 |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
| 658 |
connection=conn; |
pelosconnection=conn; |
| 659 |
} |
} |
| 660 |
} |
} |
| 661 |
else{ |
else{ |
| 662 |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
| 663 |
connection=conn; |
pelosconnection=conn; |
| 664 |
} |
} |
| 665 |
|
|
| 666 |
if (!strcmp(db_user,"")) |
if (!strcmp(db_user,"")) |
| 690 |
} |
} |
| 691 |
} |
} |
| 692 |
|
|
| 693 |
string msg = "Using DB: " + string(connection);// +" "+ string(db_user) +" "+ string(db_pwd); |
string msg = "Using DB: " + string(pelosconnection);// +" "+ string(db_user) +" "+ string(db_pwd); |
| 694 |
mainLogUtil->logAlways(msg); |
mainLogUtil->logAlways(msg); |
| 695 |
} |
} |
| 696 |
|
|
| 909 |
{ |
{ |
| 910 |
isCadreGood = true; |
isCadreGood = true; |
| 911 |
//start reading the file |
//start reading the file |
| 912 |
|
streamposi = (Long64_t)fin.tellg(); // stream position in the file before reading the vrl header |
| 913 |
|
if ( iNumCadres > 9 && numposi > 9 ){ |
| 914 |
|
streamposisaved = streamposi; |
| 915 |
|
numposi = 0; |
| 916 |
|
}; |
| 917 |
|
numposi++; |
| 918 |
|
// |
| 919 |
fin.read(ccHeader_VRL, LENGTH_HEADER_VRL); |
fin.read(ccHeader_VRL, LENGTH_HEADER_VRL); |
| 920 |
streamposi = (Long64_t)fin.tellg(); // stream position in the file |
// printf(" position in file is %llu \n",streamposi); |
| 921 |
// printf(" position in file is %i \n",streamposi); |
stringstream ss; |
| 922 |
|
ss.str() = ""; |
| 923 |
|
ss << " position in file is "<<streamposi; |
| 924 |
|
string sms = ss.str(); |
| 925 |
|
// mainLogUtil->logError(sms); |
| 926 |
|
// |
| 927 |
|
headok = true; |
| 928 |
|
crcok = true; |
| 929 |
if (!fin.good()) |
if (!fin.good()) |
| 930 |
{ |
{ |
| 931 |
//TODO: check here |
//TODO: check here |
| 953 |
" This error occurred after byte: "<<iByte_tot<<" ... use the data carefully"; |
" This error occurred after byte: "<<iByte_tot<<" ... use the data carefully"; |
| 954 |
string msg = oss.str(); |
string msg = oss.str(); |
| 955 |
mainLogUtil->logWarning(msg); |
mainLogUtil->logWarning(msg); |
| 956 |
|
// printf(" streamposi %llu \n",streamposi); |
| 957 |
} |
} |
| 958 |
|
|
| 959 |
|
// |
| 960 |
|
// we completely missed more than 10 VRL packets |
| 961 |
|
// |
| 962 |
|
if ( hc == 1100 ){ |
| 963 |
|
fin.seekg(streamposiorig); |
| 964 |
|
stringstream os; |
| 965 |
|
os<<" NEW (EM) UN-RECOVERABLE SYNC WITH VRL HEADERS, SIG! "; |
| 966 |
|
os<<" new position in file, go back to "<<streamposiorig; |
| 967 |
|
string ms = os.str(); |
| 968 |
|
mainLogUtil->logAll(ms); |
| 969 |
|
hc++; |
| 970 |
|
continue; |
| 971 |
|
}; |
| 972 |
|
if ( horrorcount > 10 && hc < 1100 ){ |
| 973 |
|
hc++; |
| 974 |
|
//if ( horrorcount > 1 ){ |
| 975 |
|
stringstream os; |
| 976 |
|
os<<" NEW (EM) THIS IS TOO MUCH, LOST SYNC WITH VRL HEADERS! try to recover horrorcount = "<<horrorcount; |
| 977 |
|
os<<" new position in file "<<(streamposi-(10LL*1024LL)+1LL); |
| 978 |
|
// os<<" new position in file "<<(streamposi-(1LL*1024LL)+1LL); |
| 979 |
|
string ms = os.str(); |
| 980 |
|
mainLogUtil->logAll(ms); |
| 981 |
|
// printf(" fin.(streamposi-10*1025-7) %llu \n",streamposi-(10LL*1025LL)-7LL); |
| 982 |
|
if ( (streamposi-(10LL*1024LL)+1LL) < streamposisaved ){ |
| 983 |
|
fin.seekg(streamposisaved+1LL); |
| 984 |
|
stringstream oss; |
| 985 |
|
oss<<" Problems repositioning stream reader... streamposisaved "<<streamposisaved; |
| 986 |
|
string msg = oss.str(); |
| 987 |
|
mainLogUtil->logWarning(msg); |
| 988 |
|
|
| 989 |
|
} else { |
| 990 |
|
fin.seekg(streamposi-(10LL*1024LL)+1LL); |
| 991 |
|
}; |
| 992 |
|
// fin.seekg(streamposi-(1LL*1024LL)+1LL); |
| 993 |
|
horrorcount = 0; |
| 994 |
|
continue; |
| 995 |
|
}; |
| 996 |
|
|
| 997 |
|
|
| 998 |
//we have read and analysed the header VRL of this cadre |
//we have read and analysed the header VRL of this cadre |
| 999 |
iByte_tot+=fin.gcount(); |
iByte_tot+=fin.gcount(); |
| 1000 |
|
|
| 1001 |
//reading data in the cadre |
//reading data in the cadre |
| 1002 |
fin.read(ccData,LENGTH_DATA_CADRE); |
fin.read(ccData,LENGTH_DATA_CADRE); |
| 1003 |
|
cclung=fin.gcount(); |
| 1004 |
if (!fin.good()) |
if (!fin.good()) |
| 1005 |
{ |
{ |
| 1006 |
stringstream oss; |
stringstream oss; |
| 1043 |
{ |
{ |
| 1044 |
isCadreGood=false; |
isCadreGood=false; |
| 1045 |
} |
} |
| 1046 |
|
crcok = false; |
| 1047 |
//don't exit now, we need to keep it alive to process data |
//don't exit now, we need to keep it alive to process data |
| 1048 |
//we will exit the main reading cicle after, |
//we will exit the main reading cicle after, |
| 1049 |
} |
} |
| 1068 |
oss1<<"Route number unused = "<<route<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")"; |
oss1<<"Route number unused = "<<route<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")"; |
| 1069 |
msg = oss1.str(); |
msg = oss1.str(); |
| 1070 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1071 |
|
crcok = false; |
| 1072 |
|
|
| 1073 |
route=old_route; |
route=old_route; |
| 1074 |
|
|
| 1075 |
} |
} |
| 1076 |
} |
} |
| 1077 |
|
|
| 1078 |
|
// if ( !crcok && !headok ) skip_cadre = true; // useless |
| 1079 |
|
// if ( cclung != LENGTH_DATA_CADRE ) skip_cadre = true; // useless |
| 1080 |
|
|
| 1081 |
if(!skip_cadre) |
if(!skip_cadre) |
| 1082 |
{ |
{ |
| 1094 |
|
|
| 1095 |
|
|
| 1096 |
//main processing of the data, searching for Pamela Packets |
//main processing of the data, searching for Pamela Packets |
| 1097 |
|
// printf(" cc lung %i lung def %i \n",cclung,LENGTH_DATA_CADRE); |
| 1098 |
for(int i=0; i<LENGTH_DATA_CADRE; i++) |
for(int i=0; i<LENGTH_DATA_CADRE; i++) |
| 1099 |
{ |
{ |
| 1100 |
StateManager::getInstance().getCurrentState()->readInput(ccData[i]); |
StateManager::getInstance().getCurrentState()->readInput(ccData[i]); |
| 1172 |
" This error occurred after byte: "<<iByte_tot<<" ... Route number unused= "<<(int)headVRL[3]<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")"; |
" This error occurred after byte: "<<iByte_tot<<" ... Route number unused= "<<(int)headVRL[3]<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")"; |
| 1173 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1174 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1175 |
|
|
| 1176 |
|
if ( ((int)(unsigned char)headVRL[0]!=CODE_FF)&&((int)(unsigned char)headVRL[1]!=CODE_46)&& ((int)(unsigned char)headVRL[2]!=CODE_D5) ){ |
| 1177 |
|
stringstream os; |
| 1178 |
|
os<<" Horror movie, the cadre does not start with FF 46 D5 at all! "<< |
| 1179 |
|
" This error occurred after byte: "<<iByte_tot<<" ... Route number unused= "<<(int)headVRL[3]<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")"; |
| 1180 |
|
string ms = os.str(); |
| 1181 |
|
mainLogUtil->logAll(ms); |
| 1182 |
|
if ( !hc && !horrorcount ) streamposiorig = streamposi; |
| 1183 |
|
horrorcount++; |
| 1184 |
|
}; |
| 1185 |
|
headok = false; |
| 1186 |
|
|
| 1187 |
return false; |
return false; |
| 1188 |
} |
} |
| 1189 |
|
|
| 1190 |
|
horrorcount = 0; |
| 1191 |
|
|
| 1192 |
// EM qui condizione su posizione file |
// EM qui condizione su posizione file |
| 1193 |
Bool_t downchangeallowed = false; |
Bool_t downchangeallowed = false; |
| 1194 |
for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){ |
for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){ |