1 |
//============================================================================ |
//============================================================================ |
2 |
// $Id: PamOffLineSW_Main.cpp,v 1.51 2008-09-05 14:33:48 messineo 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 |
|
|
8 |
#include "StateManager.h" |
#include "StateManager.h" |
9 |
|
|
10 |
#include "PacketUser.h" |
#include "PacketUser.h" |
11 |
|
#include <TArrayL64.h> |
12 |
|
|
13 |
extern "C" { |
extern "C" { |
14 |
#include <dirent.h> |
#include <dirent.h> |
43 |
|
|
44 |
//global variables |
//global variables |
45 |
bool simulated_data = false; |
bool simulated_data = false; |
46 |
bool do_vrl_check = false; |
//bool do_vrl_check = false; //EMI |
47 |
|
bool do_vrl_check = true; //EMI |
48 |
|
int cclung = 0; |
49 |
|
Bool_t headok = true; |
50 |
|
Bool_t crcok = true; |
51 |
|
|
52 |
char* db_host = ""; |
const char* db_host = ""; |
53 |
int db_port = 0; |
int db_port = 0; |
54 |
char* db_name = ""; |
const char* db_name = ""; |
55 |
char conn[100]=""; |
char conn[100]=""; |
|
//char* connection = NULL; |
|
|
//char* db_user = "yoda_user"; |
|
|
//char* db_pwd = "yoda_pwd"; |
|
56 |
|
|
57 |
LogUtil::logLevel loglevel=LogUtil::LOGERROR; |
LogUtil::logLevel loglevel=LogUtil::LOGERROR; |
58 |
char* logfilename = "pamofflinesw.log"; |
const char* logfilename = "chewbacca.log"; |
59 |
//current route |
//current route |
60 |
int route = 999; |
int route = 999; |
61 |
//previous route |
//previous route |
62 |
int old_route = 999; |
int old_route = 999; |
63 |
|
|
64 |
|
Long64_t filelength = 0LL; |
65 |
|
Long64_t streamposi = 0LL; |
66 |
|
Long64_t streamposisaved = 0LL; |
67 |
|
Long64_t streamposiorig = 0LL; |
68 |
|
Int_t numposi = 10; |
69 |
|
Long64_t downcount = 1LL; |
70 |
|
TArrayL64 *dwin=new TArrayL64(12); |
71 |
|
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 |
77 |
|
|
78 |
// global variables used in all the project |
// global variables used in all the project |
79 |
namespace PamOffLineSW |
namespace PamOffLineSW |
80 |
{ |
{ |
81 |
char* db_user = ""; |
const char* db_user = ""; |
82 |
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 |
90 |
char* fni; //path completo |
char* fni; //path completo |
91 |
short compression = 3; |
short compression = 3; |
92 |
// char *outDir = "."; |
// char *outDir = "."; |
93 |
char *outDir = ""; |
const char *outDir = ""; |
94 |
|
|
95 |
char * nome_output="yoda"; |
// char * nome_output="chewbacca"; //EMI |
96 |
bool multiFile = 0; |
const char * nome_output="L0PAM";//EMI |
97 |
unsigned long int step_pkt_number=0; |
bool multiFile = 0; |
98 |
unsigned long int step_pkt_obt=0; |
// unsigned long int step_pkt_number=0; // EMI |
99 |
|
unsigned long int step_pkt_number=3000; |
100 |
|
// unsigned long int step_pkt_obt=0; // EMI |
101 |
|
unsigned long int step_pkt_obt=7200000; // EMI |
102 |
LogUtil* mainLogUtil = NULL; |
LogUtil* mainLogUtil = NULL; |
103 |
TSQLServer* sqlServer = NULL; |
TSQLServer* sqlServer = NULL; |
104 |
unsigned long int max_pkt_number = 16777215;//biggest value before reset |
unsigned long int max_pkt_number = 16777215;//biggest value before reset |
105 |
unsigned long int max_pkt_obt = 4294967295u;//biggest value before reset |
unsigned long int max_pkt_obt = 4294967295u;//biggest value before reset |
106 |
|
|
107 |
bool is_new_route = false; |
// bool is_new_route = false; // EMI |
108 |
|
bool is_new_route = true; // EMI ??????????? VA BENE? SECONDO ME SI` |
109 |
unsigned int download = 0; |
unsigned int download = 0; |
110 |
unsigned int orbit_number=0; |
unsigned int orbit_number=0; |
111 |
unsigned int mmm_number = 0;//session_number |
unsigned int mmm_number = 0;//session_number |
112 |
unsigned long int time_Offset=0; |
unsigned long int time_Offset=0; |
113 |
bool tryMerge = false; |
// bool tryMerge = false; |
114 |
|
bool tryMerge = true; |
115 |
|
bool candelete = true; //EM |
116 |
|
|
117 |
bool do_cont_check=true;//if do_cont_check is false do not use a DB ... |
bool do_cont_check=true;//if do_cont_check is false do not use a DB ... |
118 |
|
|
119 |
//TODO: now it is unused |
//TODO: now it is unused |
120 |
unsigned long int delta_Time=0;//in seconds |
unsigned long int delta_Time=0;//in seconds |
121 |
|
#define TAGVALUELEN 4 |
122 |
|
char tag_value[TAGVALUELEN]; |
123 |
} |
} |
124 |
|
|
125 |
// main: |
// main: |
182 |
cout << "\t (-help | --help | -h) print this help and exit \n"; |
cout << "\t (-help | --help | -h) print this help and exit \n"; |
183 |
cout << "\t -simu if the input file contains simulated data instead of real data\n"; |
cout << "\t -simu if the input file contains simulated data instead of real data\n"; |
184 |
cout << "\t -vrl if you want to perform the vrl check\n"; |
cout << "\t -vrl if you want to perform the vrl check\n"; |
185 |
cout << "\t -filelog set the log filename. [default: pamofflinesw.log]\n"; |
cout << "\t -no-vrl if you DO NOT want to perform the vrl check\n"; |
186 |
|
cout << "\t -gpamela gpamela data as input\n"; |
187 |
|
cout << "\t -filelog set the log filename. [default: chewbacca.log]\n"; |
188 |
cout << "\t -loglevel set the log level. Values: [0,3] (error,warning,info,all) [default:0]\n"; |
cout << "\t -loglevel set the log level. Values: [0,3] (error,warning,info,all) [default:0]\n"; |
189 |
cout << "\t -c set the compression level for the generated ROOT file(s). Values: [0,9] [default = 3]\n"; |
cout << "\t -c set the compression level for the generated ROOT file(s). Values: [0,9] [default = 3]\n"; |
190 |
cout << "\t -root_name set the root-name for the generated ROOT file(s). [default = yoda]\n"; |
cout << "\t -root_name set the root-name for the generated ROOT file(s). [default = chewbacca]\n"; |
191 |
cout << "\t -outDir set the output directory for the generated root file(s). [default = .]\n"; |
cout << "\t -outDir set the output directory for the generated root file(s). [default = .]\n"; |
192 |
cout << "\t -delta_counter set the allowed difference in the Packet Counter between two continuos packets. If 0 all packets are considered continuos. [default = 0]\n"; |
cout << "\t -delta_counter set the allowed difference in the Packet Counter between two continuos packets. If 0 all packets are considered continuos. [default = 0]\n"; |
193 |
cout << "\t -delta_obt set the allowed difference (ms) in the Packet Orbital Time between two continuos packets. If 0 all packets are considered continuos. [default = 0]\n"; |
cout << "\t -delta_obt set the allowed difference (ms) in the Packet Orbital Time between two continuos packets. If 0 all packets are considered continuos. [default = 0]\n"; |
194 |
cout << "\t -db_host set the host-name of the DataBase. [default = localhost]\n"; |
cout << "\t -db_host set the host-name of the DataBase. [default = localhost]\n"; |
195 |
cout << "\t -db_port set the port of the DataBase. [default = 3306]\n"; |
cout << "\t -db_port set the port of the DataBase. [default = 3306]\n"; |
196 |
cout << "\t -db_name set the name of the DataBase. [default = yoda_db]\n"; |
cout << "\t -db_name set the name of the DataBase. [default = chewbacca_db]\n"; |
197 |
cout << "\t -db_user set the user of the DataBase. [default = yoda_user]\n"; |
cout << "\t -db_user set the user of the DataBase. [default = chewbacca_user]\n"; |
198 |
cout << "\t -db_pwd set the user of the DataBase. [default = yoda_pwd]\n"; |
cout << "\t -db_pwd set the user of the DataBase. [default = chewbacca_pwd]\n"; |
199 |
cout << "\t -max_pkt_number Maximum value for Packet Counter, after this value it is resetted. [default = 2^24 - 1]\n"; |
cout << "\t -max_pkt_number Maximum value for Packet Counter, after this value it is resetted. [default = 2^24 - 1]\n"; |
200 |
cout << "\t -max_pkt_obt Maximum value for Packet OBT, after this value it is resetted. [default = 2^32 - 1]\n"; |
cout << "\t -max_pkt_obt Maximum value for Packet OBT, after this value it is resetted. [default = 2^32 - 1]\n"; |
201 |
cout << "\t -orbit_number Value of the orbital number. If 0 this is retrieved from the input file name. [default = 0]\n"; |
cout << "\t -orbit_number Value of the orbital number. If 0 this is retrieved from the input file name. [default = 0]\n"; |
202 |
cout << "\t -session_number Value of the session number. If 0 this is retrieved from the input file name. [default = 0]\n"; |
cout << "\t -session_number Value of the session number. If 0 this is retrieved from the input file name. [default = 0]\n"; |
203 |
cout << "\t -time_Offset Value of the timeOffset. If 0 this is retrieved using the orbital number. [default = 0]\n"; |
cout << "\t -time_Offset Value of the timeOffset. If 0 this is retrieved using the orbital number. [default = 0]\n"; |
204 |
cout << "\t -tryMerge if you want to try to Merge ROOT files\n"; |
cout << "\t -tryMerge if you want to try to Merge ROOT files\n"; |
205 |
//marco_new_01 |
cout << "\t -dontMerge if you do not want to try to Merge ROOT files\n"; |
206 |
|
cout << "\t -dontDelete if you do not want to delete bad ROOT files from disks\n"; |
207 |
|
//marco_new_01 |
208 |
cout << "\t -single_connection if you want to open only one connection to DB.\n"; |
cout << "\t -single_connection if you want to open only one connection to DB.\n"; |
209 |
// cout << "\t -delta_Time set the allowed difference (seconds) in the Real Time between two root file. [default = 0]\n"; |
cout << "\t -tag if you want add the 'The owner of the file' - the tag lenght is 4 char\n"; |
210 |
|
// cout << "\t -delta_Time set the allowed difference (seconds) in the Real Time between two root file. [default = 0]\n"; |
211 |
//cout << "\t -multi generate multiple root files \n"; |
//cout << "\t -multi generate multiple root files \n"; |
212 |
exit(1); |
exit(1); |
213 |
} |
} |
226 |
exit(1); |
exit(1); |
227 |
} |
} |
228 |
|
|
229 |
|
//input file |
230 |
|
fni= argv[1]; |
231 |
|
|
232 |
for (int i = 2; i < argc; i++) |
for (int i = 2; i < argc; i++) |
233 |
{ |
{ |
234 |
//marco_new_01 |
//marco_new_01 |
244 |
tryMerge = true; |
tryMerge = true; |
245 |
continue; |
continue; |
246 |
} |
} |
247 |
|
|
248 |
|
if (!strcmp(argv[i], "-dontMerge")) // EMI |
249 |
|
{ |
250 |
|
tryMerge = false; |
251 |
|
continue; |
252 |
|
} |
253 |
|
|
254 |
|
if (!strcmp(argv[i], "-dontDelete")) // EMI |
255 |
|
{ |
256 |
|
candelete = false; |
257 |
|
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"; |
343 |
simulated_data = true; |
simulated_data = true; |
344 |
continue; |
continue; |
345 |
} |
} |
346 |
|
|
347 |
|
if (!strcmp(argv[i], "-gpamela")) |
348 |
|
{ |
349 |
|
simulated_data = true; |
350 |
|
do_vrl_check = false; |
351 |
|
nome_output = (char *)gSystem->BaseName(fni); |
352 |
|
tryMerge = false; |
353 |
|
candelete = false; |
354 |
|
continue; |
355 |
|
} |
356 |
|
|
357 |
|
if (!strcmp(argv[i], "-no-vrl")) //EMI |
358 |
|
{ |
359 |
|
do_vrl_check = false; |
360 |
|
} |
361 |
if (!strcmp(argv[i], "-vrl")) |
if (!strcmp(argv[i], "-vrl")) |
362 |
{ |
{ |
363 |
do_vrl_check = true; |
do_vrl_check = true; |
421 |
exit(1); |
exit(1); |
422 |
} |
} |
423 |
DIR* tempdir; |
DIR* tempdir; |
424 |
if ((tempdir = opendir(argv[i])) != 0) { |
if ((tempdir = opendir(gSystem->ExpandPathName(argv[i]))) != 0) { // EMI |
425 |
outDir = argv[i]; |
outDir = argv[i]; |
426 |
closedir(tempdir); |
closedir(tempdir); |
427 |
} else { |
} else { |
545 |
db_pwd = argv[i]; |
db_pwd = argv[i]; |
546 |
continue; |
continue; |
547 |
} |
} |
548 |
|
if (!strcmp(argv[i], "-tag")){ |
549 |
|
if (++i >= argc){ |
550 |
|
cerr << "-tag needs arguments. \n"; |
551 |
|
cout << "Try '-help' for more information. \n"; |
552 |
|
exit(1); |
553 |
|
} |
554 |
|
int len=strlen(argv[i])>TAGVALUELEN?TAGVALUELEN:strlen(argv[i]); |
555 |
|
strncpy(tag_value,argv[i],len); |
556 |
|
tag_value[len]=0; |
557 |
|
continue; |
558 |
|
} |
559 |
|
|
560 |
//TODO: check that multiFile is always 0 |
//TODO: check that multiFile is always 0 |
561 |
// if (!strcmp(argv[i], "-multi")){multiFile = 1; cout<<"debug: multi= "<<multiFile<<endl;} |
// if (!strcmp(argv[i], "-multi")){multiFile = 1; cout<<"debug: multi= "<<multiFile<<endl;} |
562 |
} |
} |
563 |
|
|
|
//input file |
|
|
fni= argv[1]; |
|
|
|
|
564 |
//TODO: maybe if simulated data I don't need nothig so I can skip the following lines |
//TODO: maybe if simulated data I don't need nothig so I can skip the following lines |
565 |
// and use instead something similar to: |
// and use instead something similar to: |
566 |
//if(simulated data){orbit_number=99999; mmm_number=999; download=999; } |
if (simulated_data) {orbit_number=99999; mmm_number=999; download=999; } |
567 |
|
|
568 |
//I need the following lines only to retrieve orbit_number and mmm_number (session_number)from the filename |
//I need the following lines only to retrieve orbit_number and mmm_number (session_number)from the filename |
569 |
if((!orbit_number)||(!mmm_number)) |
if((!orbit_number)||(!mmm_number)) |
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 |
{ |
{ |
652 |
|
|
653 |
if (!strcmp(db_name,"")) |
if (!strcmp(db_name,"")) |
654 |
{ |
{ |
655 |
db_name="yoda_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,"")) |
672 |
} |
} |
673 |
else |
else |
674 |
{ |
{ |
675 |
db_user="yoda_user"; |
db_user="chewbacca_user"; |
676 |
} |
} |
677 |
|
|
678 |
} |
} |
686 |
} |
} |
687 |
else |
else |
688 |
{ |
{ |
689 |
db_pwd="yoda_pwd"; |
db_pwd="chewbacca_pwd"; |
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 |
|
|
699 |
string msg = "Input file: " + (string)fni; |
string msg = "Input file: " + (string)fni; |
700 |
mainLogUtil->logAlways(msg); |
mainLogUtil->logAlways(msg); |
701 |
|
|
702 |
msg = "Output directory for the generated root file(s): " + (string)outDir; |
msg = "Output directory for the generated root file(s): " + (string)outDir; |
703 |
mainLogUtil->logAlways(msg); |
mainLogUtil->logAlways(msg); |
704 |
|
msg = "Output directory for the generated root file(s) expanded: " + (string)gSystem->ExpandPathName(outDir); // EMI |
705 |
|
mainLogUtil->logAlways(msg); //EMI |
706 |
|
|
707 |
msg = "Output root name for the generated root file(s): " + (string)nome_output; |
msg = "Output root name for the generated root file(s): " + (string)nome_output; |
708 |
mainLogUtil->logAlways(msg); |
mainLogUtil->logAlways(msg); |
858 |
ifstream fin; |
ifstream fin; |
859 |
fin.open(fni, ifstream::binary); |
fin.open(fni, ifstream::binary); |
860 |
if (!fin) {cout<<"Can not open input file "<<fni<<endl; exit(1);} |
if (!fin) {cout<<"Can not open input file "<<fni<<endl; exit(1);} |
861 |
|
|
862 |
|
|
863 |
|
// |
864 |
|
// EM determine file length, number of downloads (a part small fractions of download due to VRL memory) and interval window for allowed change in download number |
865 |
|
// |
866 |
|
fin.seekg(0,std::ios::end); |
867 |
|
filelength = (Long64_t)fin.tellg(); |
868 |
|
// |
869 |
|
// filelength = 3840214016LL; |
870 |
|
// filelength = 5763760128LL; |
871 |
|
// filelength = 15370027008LL; |
872 |
|
// |
873 |
|
downcount = (Long64_t)round((Double_t)filelength/2000000000.); |
874 |
|
if ( downcount < 1LL ) downcount = 1LL; |
875 |
|
Long64_t downsize = (Long64_t)round((Double_t)filelength/(Double_t)downcount); |
876 |
|
Long64_t hwint = Long64_t((Double_t)downsize/25.); |
877 |
|
// |
878 |
|
if ( downcount > 5LL ) dwin->Set(2LL+2LL*downcount); |
879 |
|
dwin->Reset(); |
880 |
|
dwin->AddAt(0LL,0); |
881 |
|
// |
882 |
|
Int_t dco = 1; |
883 |
|
// |
884 |
|
for (Int_t ee=1; ee<(-1+2+2*downcount); ee+=2){ |
885 |
|
dwin->AddAt(((downsize*(dco-1))+hwint),ee); |
886 |
|
dwin->AddAt(((downsize*dco)-hwint),ee+1); |
887 |
|
dco++; |
888 |
|
}; |
889 |
|
// |
890 |
|
fin.seekg(0,std::ios::beg); |
891 |
|
// |
892 |
|
dwin->AddAt(filelength,(-1LL+2LL+2LL*downcount)); |
893 |
|
// |
894 |
|
// printf(" file lenght is %L downcount is %L downsize is %L hwint is %L \n",filelength,downcount,downsize,hwint); |
895 |
|
stringstream ess; |
896 |
|
ess.str() = ""; |
897 |
|
ess << " (EM) " << " file lenght is "<< filelength<< " downcount is "<< downcount <<" downsize is "<< downsize <<" hwint is " << hwint; |
898 |
|
string emsg = ess.str(); |
899 |
|
mainLogUtil->logInfo(emsg); |
900 |
|
// |
901 |
|
// cout << " file lenght is "<< filelength<< " downcount is "<< downcount <<" downsize is "<< downsize <<" hwint is " << hwint << endl; |
902 |
|
// for (Int_t ee=0; ee<TMath::Max((2+2*downcount),12LL); ee++){ |
903 |
|
// cout << " " << ee << " ==> "<< dwin->At(ee) << endl; |
904 |
|
// //a printf(" %i ==> %L \n",ee,dwin->At(ee)); |
905 |
|
// }; |
906 |
|
|
907 |
//main read loop |
//main read loop |
908 |
while(fin.eof()==0) |
while(fin.eof()==0) |
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 |
|
// printf(" position in file is %llu \n",streamposi); |
921 |
|
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 |
943 |
if(do_vrl_check){isCadreGood=false;} |
if(do_vrl_check){isCadreGood=false;} |
944 |
break; |
break; |
945 |
} |
} |
946 |
|
skip_cadre = false; |
947 |
//check of the VRL header e setta route number |
//check of the VRL header e setta route number |
948 |
if(!VRL_Header_Check(ccHeader_VRL,LENGTH_HEADER_VRL)) |
if(!VRL_Header_Check(ccHeader_VRL,LENGTH_HEADER_VRL)) |
949 |
{ |
{ |
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 |
} |
} |
1063 |
string msg = oss.str(); |
string msg = oss.str(); |
1064 |
mainLogUtil->logError(msg); |
mainLogUtil->logError(msg); |
1065 |
|
|
1066 |
//non mi fido del contatore del route |
//non mi fido del contatore del route |
|
|
|
1067 |
stringstream oss1; |
stringstream oss1; |
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 |
{ |
{ |
1083 |
if(route!=old_route) |
if(route!=old_route) |
1084 |
{ |
{ |
1085 |
is_new_route=true; |
is_new_route=true; |
1086 |
|
cadcount = 1LL; |
1087 |
download++; |
download++; |
1088 |
stringstream oss; |
stringstream oss; |
1089 |
oss<<"Found a new download n: "<<download<<". Header VRL ends at byte: "<<iByte_tot; |
oss<<"Found a new download n: "<<download<<". Header VRL ends at byte: "<<iByte_tot; |
1091 |
mainLogUtil->logAll(msg); |
mainLogUtil->logAll(msg); |
1092 |
} |
} |
1093 |
// is_new_route will be reset to false in PacketUser after the packet is used and stored |
// is_new_route will be reset to false in PacketUser after the packet is used and stored |
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]); |
1101 |
iByte_tot++; |
iByte_tot++; |
1102 |
if(exitdbg==true){cout<<"**** DBG EXIT FOR****"<<endl; break;} |
if(exitdbg==true){cout<<"**** DBG EXIT FOR****"<<endl; break;} |
1103 |
} |
} |
1104 |
} |
} |
1105 |
else{ |
else{ |
1106 |
iByte_tot+=LENGTH_DATA_CADRE; |
iByte_tot+=LENGTH_DATA_CADRE; |
1139 |
//function that check the header VRL |
//function that check the header VRL |
1140 |
bool VRL_Header_Check(char* headVRL, int length) |
bool VRL_Header_Check(char* headVRL, int length) |
1141 |
{ |
{ |
1142 |
|
|
|
|
|
1143 |
/* stringstream oss; |
/* stringstream oss; |
1144 |
oss<<"Pippooooooo: at byte+ "<<iByte_tot<<" cadre ... route number = "<<(int)headVRL[3]; |
oss<<"Pippooooooo: at byte+ "<<iByte_tot<<" cadre ... route number = "<<(int)headVRL[3]; |
1145 |
string msg = oss.str(); |
string msg = oss.str(); |
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 |
route = (int)headVRL[3]; |
horrorcount = 0; |
1191 |
|
|
1192 |
if(route!=old_route) |
// EM qui condizione su posizione file |
1193 |
{ |
Bool_t downchangeallowed = false; |
1194 |
stringstream oss; |
for (Int_t ee=0; ee<(-1+2+2*downcount); ee+=2){ |
1195 |
oss<<"Changing ROUTE at byte: "<<iByte_tot<<" route = "<<route<<" old value = "<<old_route<<" (download="<<download<<")"; |
if ( streamposi >= dwin->At(ee) && streamposi < dwin->At(ee+1) ) downchangeallowed = true; |
1196 |
string msg = oss.str(); |
// printf(" %i ==> %i \n",ee,dwin->At(ee)); |
1197 |
mainLogUtil->logAll(msg); |
}; |
1198 |
} |
if ( cadcount < 10000LL && cadcount > 0LL) downchangeallowed = false; |
1199 |
|
cadcount++; |
1200 |
|
// cout << " cadcount " << cadcount << endl; |
1201 |
|
// printf("cadcount %L \n",cadcount); |
1202 |
|
if ( downchangeallowed ){ |
1203 |
|
// printf(" change allowed! \n"); |
1204 |
|
|
1205 |
|
route = (int)headVRL[3]; |
1206 |
|
|
1207 |
|
if(route!=old_route) |
1208 |
|
{ |
1209 |
|
stringstream oss; |
1210 |
|
oss<<"Changing ROUTE at byte: "<<iByte_tot<<" route = "<<route<<" old value = "<<old_route<<" (download="<<download<<")"; |
1211 |
|
string msg = oss.str(); |
1212 |
|
mainLogUtil->logAll(msg); |
1213 |
|
} |
1214 |
|
|
1215 |
|
}; |
1216 |
|
|
1217 |
//TODO: check the cadre number and save this info? |
//TODO: check the cadre number and save this info? |
1218 |
//TODO check that the lenght is 8 |
//TODO check that the lenght is 8 |