| 1 |
//============================================================================ |
//============================================================================ |
| 2 |
// $Id: PamOffLineSW_Main.cpp,v 1.7 2009/08/05 18:48:43 pam-fi Exp $ |
// $Id: PamOffLineSW_Main.cpp,v 1.12 2010/02/12 05:22:04 mocchiut Exp $ |
| 3 |
// Description : Pamela Off-Line Software |
// Description : Pamela Off-Line Software |
| 4 |
//============================================================================ |
//============================================================================ |
| 5 |
|
|
| 61 |
|
|
| 62 |
Long64_t filelength = 0LL; |
Long64_t filelength = 0LL; |
| 63 |
Long64_t streamposi = 0LL; |
Long64_t streamposi = 0LL; |
| 64 |
|
Long64_t streamposisaved = 0LL; |
| 65 |
|
Long64_t streamposiorig = 0LL; |
| 66 |
|
Int_t numposi = 10; |
| 67 |
Long64_t downcount = 1LL; |
Long64_t downcount = 1LL; |
| 68 |
TArrayL64 *dwin=new TArrayL64(12); |
TArrayL64 *dwin=new TArrayL64(12); |
| 69 |
Long64_t cadcount = 0LL; |
Long64_t cadcount = 0LL; |
| 70 |
|
Int_t horrorcount = 0; |
| 71 |
|
Int_t hc = 0; |
| 72 |
|
|
| 73 |
bool skip_cadre = false; |
bool skip_cadre = false; |
| 74 |
long int iNumGoodCadres=0; //total number of good cadres |
long int iNumGoodCadres=0; //total number of good cadres |
| 78 |
{ |
{ |
| 79 |
const char* db_user = ""; |
const char* db_user = ""; |
| 80 |
const char* db_pwd = ""; |
const char* db_pwd = ""; |
| 81 |
char* connection = NULL; |
char* pelosconnection = NULL; |
| 82 |
//marco_new_01 |
//marco_new_01 |
| 83 |
bool single_connection=false; |
bool single_connection=false; |
| 84 |
long int iNumCadres=0; //cadre's number |
long int iNumCadres=0; //cadre's number |
| 634 |
char *pamdbhost = getenv("PAM_DBHOST"); |
char *pamdbhost = getenv("PAM_DBHOST"); |
| 635 |
if (pamdbhost) |
if (pamdbhost) |
| 636 |
{ |
{ |
| 637 |
connection = pamdbhost; |
pelosconnection = pamdbhost; |
| 638 |
} |
} |
| 639 |
else |
else |
| 640 |
{ |
{ |
| 653 |
db_name="chewbacca_db"; |
db_name="chewbacca_db"; |
| 654 |
} |
} |
| 655 |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
| 656 |
connection=conn; |
pelosconnection=conn; |
| 657 |
} |
} |
| 658 |
} |
} |
| 659 |
else{ |
else{ |
| 660 |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
sprintf(conn,"mysql://%s:%d/%s",db_host,db_port,db_name); |
| 661 |
connection=conn; |
pelosconnection=conn; |
| 662 |
} |
} |
| 663 |
|
|
| 664 |
if (!strcmp(db_user,"")) |
if (!strcmp(db_user,"")) |
| 688 |
} |
} |
| 689 |
} |
} |
| 690 |
|
|
| 691 |
string msg = "Using DB: " + string(connection);// +" "+ string(db_user) +" "+ string(db_pwd); |
string msg = "Using DB: " + string(pelosconnection);// +" "+ string(db_user) +" "+ string(db_pwd); |
| 692 |
mainLogUtil->logAlways(msg); |
mainLogUtil->logAlways(msg); |
| 693 |
} |
} |
| 694 |
|
|
| 907 |
{ |
{ |
| 908 |
isCadreGood = true; |
isCadreGood = true; |
| 909 |
//start reading the file |
//start reading the file |
| 910 |
|
streamposi = (Long64_t)fin.tellg(); // stream position in the file before reading the vrl header |
| 911 |
|
if ( iNumCadres > 9 && numposi > 9 ){ |
| 912 |
|
streamposisaved = streamposi; |
| 913 |
|
numposi = 0; |
| 914 |
|
}; |
| 915 |
|
numposi++; |
| 916 |
|
// |
| 917 |
fin.read(ccHeader_VRL, LENGTH_HEADER_VRL); |
fin.read(ccHeader_VRL, LENGTH_HEADER_VRL); |
| 918 |
streamposi = (Long64_t)fin.tellg(); // stream position in the file |
// printf(" position in file is %llu \n",streamposi); |
| 919 |
// printf(" position in file is %i \n",streamposi); |
stringstream ss; |
| 920 |
|
ss.str() = ""; |
| 921 |
|
ss << " position in file is "<<streamposi; |
| 922 |
|
string sms = ss.str(); |
| 923 |
|
// mainLogUtil->logError(sms); |
| 924 |
|
// |
| 925 |
if (!fin.good()) |
if (!fin.good()) |
| 926 |
{ |
{ |
| 927 |
//TODO: check here |
//TODO: check here |
| 949 |
" This error occurred after byte: "<<iByte_tot<<" ... use the data carefully"; |
" This error occurred after byte: "<<iByte_tot<<" ... use the data carefully"; |
| 950 |
string msg = oss.str(); |
string msg = oss.str(); |
| 951 |
mainLogUtil->logWarning(msg); |
mainLogUtil->logWarning(msg); |
| 952 |
|
// printf(" streamposi %llu \n",streamposi); |
| 953 |
} |
} |
| 954 |
|
|
| 955 |
|
// |
| 956 |
|
// we completely missed more than 10 VRL packets |
| 957 |
|
// |
| 958 |
|
if ( hc == 1100 ){ |
| 959 |
|
fin.seekg(streamposiorig); |
| 960 |
|
stringstream os; |
| 961 |
|
os<<" NEW (EM) UN-RECOVERABLE SYNC WITH VRL HEADERS, SIG! "; |
| 962 |
|
os<<" new position in file, go back to "<<streamposiorig; |
| 963 |
|
string ms = os.str(); |
| 964 |
|
mainLogUtil->logAll(ms); |
| 965 |
|
hc++; |
| 966 |
|
continue; |
| 967 |
|
}; |
| 968 |
|
if ( horrorcount > 10 && hc < 1100 ){ |
| 969 |
|
hc++; |
| 970 |
|
//if ( horrorcount > 1 ){ |
| 971 |
|
stringstream os; |
| 972 |
|
os<<" NEW (EM) THIS IS TOO MUCH, LOST SYNC WITH VRL HEADERS! try to recover horrorcount = "<<horrorcount; |
| 973 |
|
os<<" new position in file "<<(streamposi-(10LL*1024LL)+1LL); |
| 974 |
|
// os<<" new position in file "<<(streamposi-(1LL*1024LL)+1LL); |
| 975 |
|
string ms = os.str(); |
| 976 |
|
mainLogUtil->logAll(ms); |
| 977 |
|
// printf(" fin.(streamposi-10*1025-7) %llu \n",streamposi-(10LL*1025LL)-7LL); |
| 978 |
|
if ( (streamposi-(10LL*1024LL)+1LL) < streamposisaved ){ |
| 979 |
|
fin.seekg(streamposisaved+1LL); |
| 980 |
|
stringstream oss; |
| 981 |
|
oss<<" Problems repositioning stream reader... streamposisaved "<<streamposisaved; |
| 982 |
|
string msg = oss.str(); |
| 983 |
|
mainLogUtil->logWarning(msg); |
| 984 |
|
|
| 985 |
|
} else { |
| 986 |
|
fin.seekg(streamposi-(10LL*1024LL)+1LL); |
| 987 |
|
}; |
| 988 |
|
// fin.seekg(streamposi-(1LL*1024LL)+1LL); |
| 989 |
|
horrorcount = 0; |
| 990 |
|
continue; |
| 991 |
|
}; |
| 992 |
|
|
| 993 |
|
|
| 994 |
//we have read and analysed the header VRL of this cadre |
//we have read and analysed the header VRL of this cadre |
| 995 |
iByte_tot+=fin.gcount(); |
iByte_tot+=fin.gcount(); |
| 996 |
|
|
| 1162 |
" 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<<")"; |
| 1163 |
string msg = oss.str(); |
string msg = oss.str(); |
| 1164 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
| 1165 |
|
|
| 1166 |
|
if ( ((int)(unsigned char)headVRL[0]!=CODE_FF)&&((int)(unsigned char)headVRL[1]!=CODE_46)&& ((int)(unsigned char)headVRL[2]!=CODE_D5) ){ |
| 1167 |
|
stringstream os; |
| 1168 |
|
os<<" Horror movie, the cadre does not start with FF 46 D5 at all! "<< |
| 1169 |
|
" This error occurred after byte: "<<iByte_tot<<" ... Route number unused= "<<(int)headVRL[3]<<" Resetting ROUTE to old value = "<<old_route<<" (download="<<download<<")"; |
| 1170 |
|
string ms = os.str(); |
| 1171 |
|
mainLogUtil->logAll(ms); |
| 1172 |
|
if ( !hc && !horrorcount ) streamposiorig = streamposi; |
| 1173 |
|
horrorcount++; |
| 1174 |
|
}; |
| 1175 |
|
|
| 1176 |
return false; |
return false; |
| 1177 |
} |
} |
| 1178 |
|
|
| 1179 |
|
horrorcount = 0; |
| 1180 |
|
|
| 1181 |
// EM qui condizione su posizione file |
// EM qui condizione su posizione file |
| 1182 |
Bool_t downchangeallowed = false; |
Bool_t downchangeallowed = false; |
| 1183 |
for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){ |
for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){ |