/[PAMELA software]/rawreader/src/Verify.cpp
ViewVC logotype

Diff of /rawreader/src/Verify.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by cafagna, Sun Dec 10 12:21:27 2006 UTC revision 1.4 by cafagna, Sun Dec 10 13:06:00 2006 UTC
# Line 5  Line 5 
5  #include "CRC.h"  #include "CRC.h"
6    
7  short int CRC_H(char [], char []);  short int CRC_H(char [], char []);
8    extern char MYSQL[120];
9    extern char database[120];
10    extern float YODA_flag;
11    extern float transmit_flag;
12    extern int print_flag;
13    
14  void verify(char fni[], char inf[], char log[], char pam[],  void verify(char fni[], char inf[], char log[], char pam[],
15                    char fno[], char path[], char name_ini[], char name_in[], int packet_type[],                    char fno[], char path[], char name_ini[], char name_in[], int packet_type[],
16                    float IndexQ, int r_counter, int real_route[])                    float IndexQ, int r_counter, int real_route[])
17  {  {
18   FILE *fo_log, *fo_inf, *fo_work, *fo_miss, *fo_row;   FILE *fo_log, *fo_inf, *fo_miss, *fo_row;
19    
20   time_t seconds;   time_t seconds;
21    
# Line 18  void verify(char fni[], char inf[], char Line 23  void verify(char fni[], char inf[], char
23   char time_year[5], time_month[5], time_day[5];   char time_year[5], time_month[5], time_day[5];
24   char data_time[80];   char data_time[80];
25   char cirquit_no[10], route_no[80], name_path[80], name_cln2[80];   char cirquit_no[10], route_no[80], name_path[80], name_cln2[80];
26     char connection[80];
27   bool file_ready, file_deleted, file_archived, file_proces;   bool file_ready, file_deleted, file_archived, file_proces;
28   int flag_to_transmit=0;   int flag_to_transmit=0;
29   int flag_sec_trans=0;             /*Second transmission flag*/   int flag_sec_trans=0;             /*Second transmission flag*/
# Line 27  void verify(char fni[], char inf[], char Line 33  void verify(char fni[], char inf[], char
33   char str_route[10];   char str_route[10];
34   char str_file[80];   char str_file[80];
35    
36   char ch;   char ch, ttt[80];
37   char miss_file[80];   char miss_file[80];
38   char Name_Buf[9];                 /*Name buffer*/   char Name_Buf[9];                 /*Name buffer*/
39   char Name_Buf_add[9];             /*Header buffer*/   char Name_Buf_add[9];             /*Header buffer*/
# Line 45  void verify(char fni[], char inf[], char Line 51  void verify(char fni[], char inf[], char
51   int Byte_adr2[4];                 /*Bytes for Packet end packing*/   int Byte_adr2[4];                 /*Bytes for Packet end packing*/
52   int packet_counter[NumberPack+1]; /*Counter for each packet type*/   int packet_counter[NumberPack+1]; /*Counter for each packet type*/
53   int count_name_cor=0;             /*Counter for packet with corrected name*/   int count_name_cor=0;             /*Counter for packet with corrected name*/
54   int er_pack_count=0;              /*Error packet counter*/   int er_pack_CRC=0;                /*CRC error packet counter*/
55     int er_pack_Len=0;                /*Length error packet counter*/
56     int er_pack_count=0;              /*Errors counter*/
57   int count_miss=0;                 /*Missed packet counter*/   int count_miss=0;                 /*Missed packet counter*/
58     int count_sec_miss=0;
59   int P_er=0;                       /*Number of packet with counter error*/   int P_er=0;                       /*Number of packet with counter error*/
60   int flag_CRC_H[3];                /*Flag for CRC header error*/   int flag_CRC_H[3];                /*Flag for CRC header error*/
61   int flag_pack[3];                 /*Flag for error in packet counter*/   int flag_pack[3];                 /*Flag for error in packet counter*/
# Line 66  void verify(char fni[], char inf[], char Line 75  void verify(char fni[], char inf[], char
75   long int icount_int=0;            /*Entire part of total file size in Kbytes*/   long int icount_int=0;            /*Entire part of total file size in Kbytes*/
76   long int icount_frac=0;           /*Fractional part of total file size*/   long int icount_frac=0;           /*Fractional part of total file size*/
77   long int N1=0;                    /*Number of identified PAMELA packets*/   long int N1=0;                    /*Number of identified PAMELA packets*/
78   long int numP[3];                     /*Packet numbers for previous packets*/   long int numP[3];                 /*Packet numbers for previous packets*/
79     long int PackType[3];             /*Packet type for previous packets*/
80   long int LenP[3];                 /*Packet length for previous packets*/   long int LenP[3];                 /*Packet length for previous packets*/
81   unsigned long int time_p[3];      /*Packet time*/   unsigned long int time_p[3];      /*Packet time*/
82     unsigned long int time_max=0;
83     unsigned long int time_min=0;
84   long int pack_length=0;           /*PAMELA packet length*/   long int pack_length=0;           /*PAMELA packet length*/
85   long long int adr_first[3];       /*Start displacement from file begin*/   long long int adr_first[3];       /*Start displacement from file begin*/
86   long long int adr_last[3];        /*Finish displacement from file begin*/   long long int adr_last[3];        /*Finish displacement from file begin*/
# Line 78  void verify(char fni[], char inf[], char Line 90  void verify(char fni[], char inf[], char
90   unsigned long int k=0, j=0;   unsigned long int k=0, j=0;
91   int i;   int i;
92   //initialization  , all =0   //initialization  , all =0
93   float process, transmit;   float ratioCln1Cln2;
94   int output;   int output;
95   char str[80];   char str[80];
96    
  FILE *fpar;  
  fpar=fopen("/home/pamelaprod/rawreader/bin/parameters.dat","r");  
  fscanf(fpar,"%f %s %s %s",&process,str,str,str);  
  fscanf(fpar,"%f %s %s %s",&transmit,str,str,str);  
  fscanf(fpar,"%i",&output);  
  fclose(fpar);  
   
97   stringstream oss, oss1;   stringstream oss, oss1;
98    
99   TSQLServer *sqlServer = TSQLServer::Connect("mysql://pamela_1.ntsomz.ru:3306/rawreader", "pamelaprod", "rawprod");   strcpy(connection,MYSQL);
100     strcat(connection,database);
101     TSQLServer *sqlServer = TSQLServer::Connect(connection, "pamelaprod", "rawprod");
102     if (sqlServer==0) {cerr<<"can not connect with  MYSQL server\n"; exit(1);}
103   oss.str("");   oss.str("");
104   oss<<"select * from FILES1";   oss<<"select * from FILES1";
105   TSQLResult *res1=sqlServer->Query(oss.str().c_str());   TSQLResult *res1=sqlServer->Query(oss.str().c_str());
# Line 126  void verify(char fni[], char inf[], char Line 133  void verify(char fni[], char inf[], char
133   {numP[i]=0; time_p[i]=0; CRC_Header[i]=0; CRC_bad_pack[i]=0;   {numP[i]=0; time_p[i]=0; CRC_Header[i]=0; CRC_bad_pack[i]=0;
134    flag_CRC_H[i]=0; flag_len[i]=0; flag_len_weak[i]=0; flag_pack[i]=0; flag_CRC_cor[i]=0;    flag_CRC_H[i]=0; flag_len[i]=0; flag_len_weak[i]=0; flag_pack[i]=0; flag_CRC_cor[i]=0;
135    flag_name[i]=0; flag_type[i]=0; flag_time[i]=0;    flag_name[i]=0; flag_type[i]=0; flag_time[i]=0;
136    LenP[i]=0;    LenP[i]=0; PackType[i]=0;
137    adr_first[i]=0; adr_last[i]=0;    adr_first[i]=0; adr_last[i]=0;
138    Hex[i]=0;}    Hex[i]=0;}
139   for (i=0; i<4; i++) {Byte_adr1[i]=0; Byte_adr2[i]=0;}   for (i=0; i<4; i++) {Byte_adr1[i]=0; Byte_adr2[i]=0;}
140   for (i=0; i<2; i++) temp[i]=0;   for (i=0; i<2; i++) temp[i]=0;
141    
142   ifstream fin;   ifstream fin;
143   ofstream fo_pam;     ofstream fo_pam, fo_work;
144  /**********************OPEN NECESSARY FILES************************/  /**********************OPEN NECESSARY FILES************************/
145  /******************************************************************/  /******************************************************************/
146   fin.open(fni, ios::binary);     // open input file "xxx_mmm_nnnnn__cln1.pam"   fin.open(fni, ios::binary);     // open input file "nnnnn_mmm_xxx_cln1.pam"
147   if(fin.good()==0) {cerr<<"can not open input file "<<fni<<"\n"; exit(1);}   if(fin.good()==0) {cerr<<"can not open input file (Verify.cpp) "<<fni<<"\n"; exit(1);}
148    
149   fo_work=fopen(fno, "wb");       //open output help file "work.dat"   fo_work.open(fno, ios::out);    //open output help file "work.dat"
150   if(fo_work==NULL) {cerr<<"can not open outputfile"; exit(1);}   if(!fo_work) {cerr<<"can not open outputfile"; exit(1);}
151    
152   fo_log=fopen(log, "wb");        //open output file "xxx_mmm_nnnnn_cln2.log"   fo_log=fopen(log, "wb");        //open output file "xxx_mmm_nnnnn_cln2.log"
153   if(fo_log==NULL) {cerr<<"can not open log file"; exit(1);}   if(fo_log==NULL) {cerr<<"can not open log file"; exit(1);}
# Line 160  void verify(char fni[], char inf[], char Line 167  void verify(char fni[], char inf[], char
167  /******************************************************************/  /******************************************************************/
168    
169  //Write proccessed filename in help file  //Write proccessed filename in help file
170  // fprintf(fo_work,"file name=%s\n",name_in);    fo_work<<"initial file name : "<<name_in<<"\n";
171    
172  /******************************************************************/  /******************************************************************/
173  /******************MAIN READING CYCLE BEGIN************************/  /******************MAIN READING CYCLE BEGIN************************/
# Line 178  void verify(char fni[], char inf[], char Line 185  void verify(char fni[], char inf[], char
185                   256*(long int)(unsigned char)(Name_Buf[6])+                   256*(long int)(unsigned char)(Name_Buf[6])+
186               256*256*(long int)(unsigned char)(Name_Buf[5]);               256*256*(long int)(unsigned char)(Name_Buf[5]);
187    
   if (N1==0) numP[2]=tmpP-1;    //initial packet identification  
188    
189  /******************packet type identification**********************/  /******************packet type identification**********************/
190    for (i=0;i<NumberPack;i++)    for (i=0;i<NumberPack;i++)
# Line 190  void verify(char fni[], char inf[], char Line 196  void verify(char fni[], char inf[], char
196    if ((num_type1==0)&&(num_type2!=0)) num_type=num_type2;            if ((num_type1==0)&&(num_type2!=0)) num_type=num_type2;        
197    if ((num_type1!=0)&&(num_type2==0)) num_type=num_type1;    if ((num_type1!=0)&&(num_type2==0)) num_type=num_type1;
198    
199      if (N1==0)
200      {numP[2]=tmpP-1;          //initial packet identification
201       PackType[2]=num_type-1;} //initial packet type identification
202  ///////////////////////////////////////////////////////////////////  ///////////////////////////////////////////////////////////////////
203  ////////////////// PAMELA PACKET IDENTIFICATION////////////////////  ////////////////// PAMELA PACKET IDENTIFICATION////////////////////
204  ///////////////////////////////////////////////////////////////////  ///////////////////////////////////////////////////////////////////
205    if (((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&    if (((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)||
206             (tmpP==numP[2]+1)&&num_type!=0)||        ((int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)||
207        ((int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&        ((int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&(tmpP==numP[2]+1)&&num_type!=0&&N1!=0)||
208             (tmpP==numP[2]+1)&&num_type!=0)||        ((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&
209            ((int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&         (int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&num_type1!=0&&num_type1==num_type2)||
210             (tmpP==numP[2]+1)&&num_type!=0)||        ((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&(int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&
211            ((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&         (int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&(tmpP==numP[2]+1)))    
            (int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&  
            (int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&num_type1!=0&&num_type1==num_type2)||  
           ((int)(unsigned char)Name_Buf[0]==CODE_BYTE1&&  
            (int)(unsigned char)Name_Buf[1]==CODE_BYTE2&&  
            (int)(unsigned char)Name_Buf[2]==CODE_BYTE3&&  
            (tmpP==numP[2]+1)))      
212    {if (N1==0) {for (i=0;i<8;i++) buffer[i]=Name_Buf[i]; }    {if (N1==0) {for (i=0;i<8;i++) buffer[i]=Name_Buf[i]; }
213     N1+=1; FLAG_BIG=0;     N1+=1; FLAG_BIG=0;
214     if (N1==1) {icount+=8;}         if (N1==1) {icount+=8;}
    packet_counter[num_type]+=1;  //count packet number for each type  
 //   if ((fmod((float)(tmpP),(float)(1000.))==0.)&&(tmpP!=0)) cout<<"verifying "<<tmpP<<"\n";  
215    
216       packet_counter[num_type]+=1;  //count packet number for each type
217       if ((print_flag>0) && (fmod((float)(tmpP),(float)(1000.))==0.)&&(tmpP!=0)) cout<<"verifying "<<tmpP<<"\n";
218     if (N1!=1)     if (N1!=1)
219     {     {
220  /**************PAMELA PREVIOUS PACKET END DISPLACEMENT*************/  /**************PAMELA PREVIOUS PACKET END DISPLACEMENT*************/
# Line 219  void verify(char fni[], char inf[], char Line 222  void verify(char fni[], char inf[], char
222      else if ((icount-8-adr_first[2]+1-LenP[2]-16)>Limit) {adr_last[2]=adr_first[2]+Limit;} //end byte for previous packet      else if ((icount-8-adr_first[2]+1-LenP[2]-16)>Limit) {adr_last[2]=adr_first[2]+Limit;} //end byte for previous packet
223  /**************PAMELA PACKET LENGTH ERROR ANALYSIS*****************/  /**************PAMELA PACKET LENGTH ERROR ANALYSIS*****************/
224           if ( (flag_CRC_H[2]==1)&&(GLOBAL_LEN_ER>0)&&           if ( (flag_CRC_H[2]==1)&&(GLOBAL_LEN_ER>0)&&
225                    ( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))                    ( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) )
                     ||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) )  
226           {flag_len[2]=1;           {flag_len[2]=1;
227  //        cout<<"pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16<<" Type="<<num_type<<"\n";            er_pack_Len+=1;
228              if (print_flag>0)
229              {cout<<"pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16<<" Type="
230                   <<packet_type[PackType[2]]<<"\n";}
231              fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
232                       " : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<<
233                       packet_type[PackType[2]]<<dec<<"\n";
234           }           }
235           if ( (flag_CRC_H[2]==0)&&(GLOBAL_LEN_ER>0)&&           if ( (flag_CRC_H[2]==0)&&(GLOBAL_LEN_ER>0)&&
236                    ( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) )                    ( ((adr_last[2]-adr_first[2]+1)<(LenP[2]+16))||((adr_last[2]-adr_first[2]+1-LenP[2]-16)>64) ) )
237           {flag_len_weak[2]=1;           {flag_len_weak[2]=1;
238  //        cout<<"weak length error; pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16<<" Type="<<num_type<<"\n";            if (print_flag>0)
239              {cout<<"weak length error; pack num "<<numP[2]<<" len="<<LenP[2]<<" true len="<<adr_last[2]-adr_first[2]-16
240                   <<" Type="<<hex<<packet_type[PackType[2]]<<dec<<"\n";}
241              fo_work<<"Weak length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
242                       " : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<<
243                       packet_type[PackType[2]]<<dec<<"\n";
244           }           }
245    
246      if ((GLOBAL_LEN_ER>0)&&(flag_len[2]==1))      if ((GLOBAL_LEN_ER>0)&&(flag_len[2]==1))
247      {      {
248  //Write data in file "xxx_mmm_nnnnn_cln2.pam"  //Write data in file "nnnnn_mmm_xxx_cln2.pam"
249       for (i=0;i<adr_last[2]-adr_first[2]+1;i++)       for (i=0;i<adr_last[2]-adr_first[2]+1;i++)
250       {fo_pam<< buffer[i];}       {fo_pam<< buffer[i];}
251      }      }
252      else if ((GLOBAL_LEN_ER>0)&&(flag_len[2]!=1)&&(flag_len_weak[2]!=1))      else if ((GLOBAL_LEN_ER>0)&&(flag_len[2]!=1)&&(flag_len_weak[2]!=1))
253      {      {
254  //Write data in file "xxx_mmm_nnnnn_cln2.pam"  //Write data in file "nnnnn_mmm_xxx_cln2.pam"
255       for (i=0;i<LenP[2]+16;i++)       for (i=0;i<LenP[2]+16;i++)
256       {fo_pam<< buffer[i];}       {fo_pam<< buffer[i];}
257       adr_last[2]=adr_first[2]+LenP[2]+15;       adr_last[2]=adr_first[2]+LenP[2]+15;
# Line 246  void verify(char fni[], char inf[], char Line 259  void verify(char fni[], char inf[], char
259      }      }
260      else if ((GLOBAL_LEN_ER>0)&&(flag_len[2]!=1)&&(flag_len_weak[2]==1))      else if ((GLOBAL_LEN_ER>0)&&(flag_len[2]!=1)&&(flag_len_weak[2]==1))
261      {      {
262  //Write data in file "xxx_mmm_nnnnn_cln2.pam"  //Write data in file "nnnnn_mmm_xxx_cln2.pam"
263       for (i=0;i<adr_last[2]-adr_first[2]+1;i++)       for (i=0;i<adr_last[2]-adr_first[2]+1;i++)
264       {fo_pam<< buffer[i];}       {fo_pam<< buffer[i];}
265      }          }    
# Line 268  void verify(char fni[], char inf[], char Line 281  void verify(char fni[], char inf[], char
281       {Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i)));       {Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i)));
282        temp[1]=temp[1]-(long int)pow(256.,3-i)*        temp[1]=temp[1]-(long int)pow(256.,3-i)*
283        (int)(temp[1]/(long int)(pow(256.,3-i)));}}              (int)(temp[1]/(long int)(pow(256.,3-i)));}}      
284        //Write previous packet end displacement in xxx_mmm_nnnnn_cln2.log file        //Write previous packet end displacement in nnnnn_mmm_xxx_cln2.log file
285       for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i]));       for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i]));
286      }      }
287  /*********************reading remaining header********************/  /*********************reading remaining header********************/
# Line 288  void verify(char fni[], char inf[], char Line 301  void verify(char fni[], char inf[], char
301              LenP[2]=pack_length;              LenP[2]=pack_length;
302                      numP[2]=(long int)(unsigned char)(Name_Buf[7])+                      numP[2]=(long int)(unsigned char)(Name_Buf[7])+
303                      256*(long int)(unsigned char)(Name_Buf[6])+                      256*(long int)(unsigned char)(Name_Buf[6])+
304              256*256*(long int)(unsigned char)(Name_Buf[5]);              256*256*(long int)(unsigned char)(Name_Buf[5]);                
305                      time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+                      time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+
306                           256*(long int)(unsigned char)(Name_Buf_add[2])+                                256*(long int)(unsigned char)(Name_Buf_add[2])+
307                  256*256*(long int)(unsigned char)(Name_Buf_add[1])+                           256*256*(long int)(unsigned char)(Name_Buf_add[1])+
308                          256*256*256*(long int)(unsigned char)(Name_Buf_add[0]);                      256*256*256*(long int)(unsigned char)(Name_Buf_add[0]);
309                        time_max=time_p[2];
310                        time_min=time_p[2];
311    
312                          CRC_Header[2]=(int)(unsigned char)(Name_Buf_add[7]);                          CRC_Header[2]=(int)(unsigned char)(Name_Buf_add[7]);
313                          adr_first[2]=icount-15;                          adr_first[2]=icount-15;
# Line 304  void verify(char fni[], char inf[], char Line 319  void verify(char fni[], char inf[], char
319                          flag_time[2]=0;                          flag_time[2]=0;
320                          flag_CRC_cor[2]=0;                          flag_CRC_cor[2]=0;
321              for (i=0; i<2; i++)              for (i=0; i<2; i++)
322                          {numP[i]=numP[2]; time_p[i]=time_p[2];                          {numP[i]=numP[2]; PackType[i]=PackType[2]; time_p[i]=time_p[2];
323                           CRC_Header[i]=CRC_Header[2];                           CRC_Header[i]=CRC_Header[2];
324                           LenP[i]=LenP[2];                           LenP[i]=LenP[2];
325                           adr_first[i]=adr_first[2];                           adr_first[i]=adr_first[2];
# Line 319  void verify(char fni[], char inf[], char Line 334  void verify(char fni[], char inf[], char
334                     }                     }
335      default:{      default:{
336               for (i=0; i<2; i++)               for (i=0; i<2; i++)
337                           {numP[i]=numP[i+1];                           {numP[i]=numP[i+1]; PackType[i]=PackType[i+1];
338                            time_p[i]=time_p[i+1];                            time_p[i]=time_p[i+1];
339                            CRC_Header[i]=CRC_Header[i+1];                            CRC_Header[i]=CRC_Header[i+1];
340                            CRC_bad_pack[i]=CRC_bad_pack[i+1];                            CRC_bad_pack[i]=CRC_bad_pack[i+1];
# Line 337  void verify(char fni[], char inf[], char Line 352  void verify(char fni[], char inf[], char
352                            numP[2]=(long int)(unsigned char)(Name_Buf[7])+                            numP[2]=(long int)(unsigned char)(Name_Buf[7])+
353                                256*(long int)(unsigned char)(Name_Buf[6])+                                256*(long int)(unsigned char)(Name_Buf[6])+
354                            256*256*(long int)(unsigned char)(Name_Buf[5]);                            256*256*(long int)(unsigned char)(Name_Buf[5]);
355                              PackType[2]=num_type-1;
356                            time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+                            time_p[2]=(long int)(unsigned char)(Name_Buf_add[3])+
357                                   256*(long int)(unsigned char)(Name_Buf_add[2])+                                   256*(long int)(unsigned char)(Name_Buf_add[2])+
358                               256*256*(long int)(unsigned char)(Name_Buf_add[1])+                               256*256*(long int)(unsigned char)(Name_Buf_add[1])+
359                           256*256*256*(long int)(unsigned char)(Name_Buf_add[0]);                           256*256*256*(long int)(unsigned char)(Name_Buf_add[0]);                        
360                                
361                           CRC_Header[2]=(int)(unsigned char)(Name_Buf_add[7]);                           CRC_Header[2]=(int)(unsigned char)(Name_Buf_add[7]);
362                           CRC_bad_pack[2]=0;                           CRC_bad_pack[2]=0;
363                           adr_first[2]=icount-15;                           adr_first[2]=icount-15;
# Line 365  void verify(char fni[], char inf[], char Line 381  void verify(char fni[], char inf[], char
381    
382     CalcCheckSum=(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15);     CalcCheckSum=(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15);
383     if (CalcCheckSum!=(short int)(unsigned char)(Name_Buf_add[7]))     if (CalcCheckSum!=(short int)(unsigned char)(Name_Buf_add[7]))
384     {cerr<<"checksum error "<<N1<<" Pack="<<numP[2]<<" "<<num_type<<" "<<bitset<8>(CalcCheckSum)<<     {er_pack_CRC+=1;
385            " CRC="<<bitset<8>((int)(unsigned char)(Name_Buf_add[7]))<<"\n";      CRC_bad_pack[2]=numP[2];
386          CRC_bad_pack[2]=numP[2];      flag_CRC_H[2]=1;
387          flag_CRC_H[2]=1;}      fo_work<<"CRC error : PAMELA packet="<<numP[2]<<" : real CRC="<<bitset<8>(CRC_Header[2])<<"("<<CRC_Header[2]<<
388                 ") : calculated CRC="<<bitset<8>(CalcCheckSum)<<"("<<CalcCheckSum<<")\n";
389       }
390       if ((time_max<time_p[2])&&(flag_CRC_H[2]!=1)) time_max=time_p[2];
391  /*********packet counter error analysis****************************/  /*********packet counter error analysis****************************/
392     if ((numP[2]!=(numP[1]+1))&&(N1!=1)&&     if ((numP[2]!=(numP[1]+1))&&(N1!=1)&&(flag_len[1]==0)&&(CRC_bad_pack[2]==numP[2]))
393             (flag_len[1]==0)&&(CRC_bad_pack[2]==numP[2])) flag_pack[2]=1;     {
394        fo_work<<"Packet number error : packet="<<numP[2]<<" : previous="<<numP[1]<<" "<<numP[0]<<"\n";
395        flag_pack[2]=1;
396       }
397    
398       if ((numP[1]!=(numP[0]+1))&&(numP[1]!=(numP[2]-1))&&(N1!=1)&&(CRC_bad_pack[1]==numP[1]))
399       {
400        fo_work<<"Packet number error : packet="<<numP[1]<<" : previous="<<numP[0]<<" : next="<<numP[2]<<"\n";
401    
402        P_er=N1-1; flag_pack[1]=1;
403    
    if ((numP[1]!=(numP[0]+1))&&(numP[1]!=(numP[2]-1))&&(N1!=1)&&  
            (CRC_bad_pack[1]==numP[1]))  
    {P_er=N1-1; flag_pack[1]=1;  
404  //Correct error packet number//  //Correct error packet number//
405     tmpP=numP[0]+1;     tmpP=numP[0]+1;
406      for (i=0;i<3;i++) Hex[i]=0;      for (i=0;i<3;i++) Hex[i]=0;
407          for (i=0;i<3;i++)      for (i=0;i<3;i++)
408          {if (tmpP/(long int)      (pow(256.,2-i))>=1)      {if (tmpP/(long int) (pow(256.,2-i))>=1)
409                  {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));       {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
410               tmpP=tmpP-(long int)(pow(256.,2-i)*        tmpP=tmpP-(long int)(pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)) ));
411                           (int)(tmpP/(long int)(pow(256.,2-i)) ));}}       }
412          for (i=5;i<8;i++) (Name_Buf_old[i]=(char)(Hex[7-i]));      }
413          if (CRC_Header[1]==(int)(CRC_H(Name_Buf_old, Name_Buf_add_old)))      for (i=5;i<8;i++) (Name_Buf_old[i]=(char)(Hex[7-i]));
414          {flag_CRC_cor[1]=1;}      for (i=0; i<8; i++)
415        {buff[i]=Name_Buf_old[i];
416         buff[i+8]=Name_Buf_add_old[i];}    
417         if (CRC_Header[1]==(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15))
418         {flag_CRC_cor[1]=1;}
419    //Correct error packet number//
420      tmpP=numP[2]-1;      tmpP=numP[2]-1;
421      for (i=0;i<3;i++) Hex[i]=0;      for (i=0;i<3;i++) Hex[i]=0;
422          for (i=0;i<3;i++)      for (i=0;i<3;i++)
423          {if (tmpP/(long int)(pow(256.,2-i))>=1)      {if (tmpP/(long int)(pow(256.,2-i))>=1)
424                  {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));       {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
425               tmpP=tmpP-(long int)pow(256.,2-i)*        tmpP=tmpP-(long int)pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)));
426                           (int)(tmpP/(long int)(pow(256.,2-i)));}}       }
427          for (i=5;i<8;i++) (Name_Buf_old[i]=(char)(Hex[7-i]));      }
428          if (CRC_Header[1]==(int)(CRC_H(Name_Buf_old, Name_Buf_add_old)))      for (i=5;i<8;i++) (Name_Buf_old[i]=(char)(Hex[7-i]));
429          {flag_CRC_cor[1]=1;}      for (i=0; i<8; i++)
430        {buff[i]=Name_Buf_old[i];
431         buff[i+8]=Name_Buf_add_old[i];}        
432        if (CRC_Header[1]==(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15))
433        {flag_CRC_cor[1]=1;}
434     }     }
435  /*********************Missing packet analysis**********************/  /*********************Missing packet analysis**********************/
436    /**packet numbers:  21 (22 17 18) 19 ******************************/
437    /***missed packets: 21  20 19 18  17 ******************************/  
438       if ((numP[1]<numP[0])&&(numP[1]==numP[2]-1)&&(flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
439       {Mis_group+=1;
440        count_sec_miss+=numP[0]-numP[1];
441        fprintf(fo_miss,"secondary transmitted packets may be %9i -%9i number of packets=%9i\n",
442                        numP[1],numP[0],numP[0]-numP[1]);
443       }
444  /**packet numbers: 10 11 (12 15 19) 20 ****************************/  /**packet numbers: 10 11 (12 15 19) 20 ****************************/
445  /***********missed packets: 16 17 18 ********************************/  /***********missed packets: 16 17 18 ********************************/
446     if ((numP[1]>numP[0]+1)&&(numP[1]<numP[2]-1)&&     else if ((numP[1]>numP[0]+1)&&(numP[1]<numP[2]-1)&&(flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
            (flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))  
447     {Mis_group+=1;     {Mis_group+=1;
448      fprintf(fo_miss,"%9i%9i\n",numP[1]+1,numP[2]-1);      fprintf(fo_miss,"1) %9i%9i\n",numP[1]+1,numP[2]-1);
449      count_miss+=numP[2]-numP[1]-1;}      count_miss+=numP[2]-numP[1]-1;}
450  /**packet numbers: 10 (11 12 15) 19 20 ****************************/  /**packet numbers: 10 (11 12 15) 19 20 ****************************/
451  /***********missed packets: 13 14 ***********************************/  /***********missed packets: 13 14 ***********************************/
452     else if ((numP[1]>=numP[0]+1)&&(numP[1]<numP[2]-1)&&             else if ((numP[1]>=numP[0]+1)&&(numP[1]<numP[2]-1)&&(flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
                         (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))  
453     {Mis_group+=1;     {Mis_group+=1;
454      fprintf(fo_miss,"%9i%9i\n",numP[0]+2,numP[2]-1);      fprintf(fo_miss,"2) %9i%9i\n",numP[0]+2,numP[2]-1);
455      count_miss+=numP[2]-numP[1]-1;}      count_miss+=numP[2]-numP[1]-1;}
456  /**packet numbers: 10 (11 20 15) 16 17 ****************************/  /**packet numbers: 10 (11 20 15) 16 17 ****************************/
457  /********missed packets number =2 ***********************************/  /********missed packets number =2 ***********************************/
458     else if ((numP[0]<numP[2]-2)&&                   else if ((numP[0]<numP[2]-2)&&(flag_pack[2]==0)&&(flag_pack[1]==1)&&(flag_pack[0]==0))  
                         (flag_pack[2]==0)&&(flag_pack[1]==1)&&(flag_pack[0]==0))    
459     {Mis_group+=1;     {Mis_group+=1;
460      fprintf(fo_miss,"%9i%9i%9i\n",numP[0]+1,numP[1],numP[2]-1);      fprintf(fo_miss,"3) %9i%9i\n",numP[0]+1, numP[2]-1);
461      count_miss+=numP[2]-numP[0]-2;}      count_miss+=numP[2]-numP[0]-2;}
462    
463  /**************Time error******************************************/  /**************Time error******************************************/
464     if ((numP[2]>=numP[0]+2)&&(flag_pack[2]==0)&&(flag_pack[0]==0)&&     if ((numP[2]>=numP[0]+2)&&(flag_pack[2]==0)&&(flag_pack[0]==0)&&
465             (flag_time[0]==0)&&(time_p[2]>time_p[0])&&             (flag_time[0]==0)&&(time_p[2]>time_p[0])&&
466             ((time_p[1]<time_p[0])||(time_p[1]>time_p[2])))             ((time_p[1]<time_p[0])||(time_p[1]>time_p[2])))
467     {flag_time[1]=1;}     {flag_time[1]=1;
468        fo_work<<"Time error : PAMELA packet="<<numP[2]<<" : time="<<time_p[1]<<" : time previous="<<time_p[1]
469               <<" : time_next="<<time_p[2]<<"\n";  
470       }
471      
472  /**************Error number calculation****************************/  /**************Error number calculation****************************/
473     if (N1!=1)     if (N1!=1)
474     {flags=(short int)((float)(flag_len_weak[1])+     {flags=(short int)((float)(flag_len_weak[1])+
475                        pow((float)(2*flag_CRC_H[1]),1)+                        pow((float)(2*flag_CRC_H[1]),1)+
476                            pow((float)(2*flag_len[1]),2)+                        pow((float)(2*flag_len[1]),2)+
477                        pow((float)(2*flag_pack[1]),3)+                        pow((float)(2*flag_pack[1]),3)+
478                                            pow((float)(2*flag_name[1]),4)+                        pow((float)(2*flag_name[1]),4)+
479                        pow((float)(2*flag_type[1]),5)+                        pow((float)(2*flag_type[1]),5)+
480                        pow((float)(2*flag_time[1]),6)+                        pow((float)(2*flag_time[1]),6)+
481                                            pow((float)(2*flag_CRC_cor[1]),7));                        pow((float)(2*flag_CRC_cor[1]),7));
482      if (flags!=0) er_pack_count+=1;      if (flags!=0) er_pack_count+=1;
483  //Write error number in log and work.dat files  //Write error number in log file
484          fprintf(fo_log,"%1c",char(flags));      fprintf(fo_log,"%1c",char(flags));
485  //    fprintf(fo_work," error num.=%i CRC=%i Calc=%i\n",  //Write error number in work.dat file
486  //                  flags,bitset<8>(CRC_Header[1]),      if (flags!=0) fo_work<<"PAMELA packet="<<numP[1]<<" : error flag="<<flags<<"\n";
 //                      (int)(CRC_H(Name_Buf_old, Name_Buf_add_old)));  
487     }     }
488  /***********************NAME ERROR*********************************/  /***********************NAME ERROR*********************************/
489     if (((int)(unsigned char)Name_Buf[0]!=CODE_BYTE1)||     if (((int)(unsigned char)Name_Buf[0]!=CODE_BYTE1)||
490         ((int)(unsigned char)Name_Buf[1]!=CODE_BYTE2)||         ((int)(unsigned char)Name_Buf[1]!=CODE_BYTE2)||
491         ((int)(unsigned char)Name_Buf[2]!=CODE_BYTE3))         ((int)(unsigned char)Name_Buf[2]!=CODE_BYTE3))
492     {     {
493        fo_work<<"Name error : packet number="<<numP[2]<<" : ";
494        fo_work<<hex<<(int)(unsigned char)Name_Buf[0]<<" : "<<(int)(unsigned char)Name_Buf[1]
495               <<" : "<<(int)(unsigned char)Name_Buf[2]<<dec<<"\n";
496      Name_Buf[0]=(char)(CODE_BYTE1);      Name_Buf[0]=(char)(CODE_BYTE1);
497      Name_Buf[1]=(char)(CODE_BYTE2);      Name_Buf[1]=(char)(CODE_BYTE2);
498      Name_Buf[2]=(char)(CODE_BYTE3);      Name_Buf[2]=(char)(CODE_BYTE3);
499      flag_name[2]=1;      flag_name[2]=1;
500      count_name_cor+=1;  
501      buffer[0]=(char)(CODE_BYTE1);      for (i=0; i<8; i++)
502      buffer[1]=(char)(CODE_BYTE2);      {buff[i]=Name_Buf[i];
503      buffer[2]=(char)(CODE_BYTE3);       buff[i+8]=Name_Buf_add[i];}    
504      if (CRC_Header[2]==(int)(CRC_H(Name_Buf, Name_Buf_add)))      if (CRC_Header[2]==(short int)(unsigned char)CM_Compute_CRC16(0, (unsigned char*)&buff, 15))
505      flag_CRC_cor[2]=1;      {
506         count_name_cor+=1;
507         buffer[0]=(char)(CODE_BYTE1);
508         buffer[1]=(char)(CODE_BYTE2);
509         buffer[2]=(char)(CODE_BYTE3);    
510         flag_CRC_cor[2]=1;
511        }
512     }     }
513    
514  /***********************PACKET TYPE ERROR**************************/  /***********************PACKET TYPE ERROR**************************/
515     if ((num_type==0)||(num_type1==0)||(num_type2==0)) flag_type[2]=1;     if ((num_type==0)||(num_type1==0)||(num_type2==0))
516       {
517        flag_type[2]=1;
518        fo_work<<"Packet type error : packet number="<<numP[2]<<" : packet type="<<hex<<packet_type[num_type]<<dec<<
519                 " : "<<num_type<<" : "<<num_type1<<" : "<<num_type2<<"\n";
520       }
521  /******************PAMELA BEGIN PACKET DISPLACEMENT****************/  /******************PAMELA BEGIN PACKET DISPLACEMENT****************/
522     temp[0]=adr_first[2];     temp[0]=adr_first[2];
523     for (i=0;i<4;i++) Byte_adr1[i]=0;     for (i=0;i<4;i++) Byte_adr1[i]=0;
524     for (i=0;i<4;i++)     for (i=0;i<4;i++)
525     {if (temp[0]/(long int)(pow(256.,3-i))>=1)     {if (temp[0]/(long int)(pow(256.,3-i))>=1)
526          {Byte_adr1[3-i]=(int)(temp[0]/(long int)(pow(256.,3-i)));      {Byte_adr1[3-i]=(int)(temp[0]/(long int)(pow(256.,3-i)));
527           temp[0]=temp[0]-(long int)pow(256.,3-i)*       temp[0]=temp[0]-(long int)pow(256.,3-i)*(int)(temp[0]/(long int)(pow(256.,3-i)));}
                            (int)(temp[0]/(long int)(pow(256.,3-i)));}  
528     }       }  
529    
530  //Write packet type and begin displacement in log and work.dat files  //Write packet type and begin displacement in log file
 //   fprintf(fo_work,"Type %i: num. %i: first=%i:",  
 //           num_type, numP[2], adr_first[2]);  
531     fprintf(fo_log,"%1c",char(num_type));     fprintf(fo_log,"%1c",char(num_type));
532     for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr1[i]));     for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr1[i]));
533    
534  /**************PAMELA PACKET OLD BUFFER***************************/  /**************PAMELA PACKET OLD BUFFER***************************/
535     for (i=0;i<8;i++)     for (i=0;i<8;i++)
536     {Name_Buf_old[i]=Name_Buf[i];Name_Buf_add_old[i]=Name_Buf_add[i];}     {Name_Buf_old[i]=Name_Buf[i]; Name_Buf_add_old[i]=Name_Buf_add[i];}
537    
538  /**********************data reading********************************/  /**********************data reading********************************/
539     fin.seekg(-1,ios::cur); icount-=1; icount_total-=1;     fin.seekg(-1,ios::cur); icount-=1; icount_total-=1;
# Line 499  void verify(char fni[], char inf[], char Line 549  void verify(char fni[], char inf[], char
549    fin.get(ch);    fin.get(ch);
550    if (fin.eof()) {break;}    if (fin.eof()) {break;}
551    icount_total+=1;    icount_total+=1;
552  //  if (fmod( double(icount_total), double(100000000.))==double(0.)) {cout<<"Mbytes="<<icount_total/1000000.<<"\n";}    if ((print_flag>0) && fmod( double(icount_total), double(100000000.))==double(0.)) {cout<<"Mbytes="<<icount_total/1000000.<<"\n";}
553    if ((N1>0)&&(FLAG_BIG==0)) icount+=1;    if ((N1>0)&&(FLAG_BIG==0)) icount+=1;
554    for (i=0;i<7;i++) Name_Buf[i]=Name_Buf[i+1];    for (i=0;i<7;i++) Name_Buf[i]=Name_Buf[i+1];
555    Name_Buf[7]=ch; /*for(i=0;i<8;i++) printf("%x",(int)(unsigned char)Name_Buf[i]); printf("\n");*/    Name_Buf[7]=ch;
556    if ((icount-adr_first[2]-1)<Nmax)    if ((icount-adr_first[2]-1)<Nmax)
557    {buffer[icount-adr_first[2]]=ch;}    {buffer[icount-adr_first[2]]=ch;}
558    else    else
559    {flag_len[2]=1;    {if (FLAG_BIG==0)
560  //   if (FLAG_BIG==0) {cout<<"too long packet "<<numP[2]<<"\n";}     {flag_len[2]=1;
561     FLAG_BIG=1;      er_pack_Len+=1;
562        fo_work<<"Length error (too long packet) : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
563                 " : length (> Nmax="<<Nmax<<")="<<icount-adr_first[2]<<" : packet type="<<hex<<
564                 packet_type[PackType[2]]<<dec<<"\n";
565        if (print_flag>0) {cout<<"too long packet "<<numP[2]<<"\n";}
566        FLAG_BIG=1;
567       }
568    }    }
569   }   }
570  /******************************************************************/  /******************************************************************/
# Line 516  void verify(char fni[], char inf[], char Line 572  void verify(char fni[], char inf[], char
572  /******************************************************************/  /******************************************************************/
573    
574  /*************PAMELA LAST PACKET END DISPLACEMENT******************/  /*************PAMELA LAST PACKET END DISPLACEMENT******************/
575    if (FLAG_BIG==0) {adr_last[2]=icount;}    if ((icount-adr_first[2]+1-LenP[2]-16)<=Limit) {adr_last[2]=icount;}                   //end byte for previous packet
576    else {adr_last[2]=adr_first[2]+Limit;}    else if ((icount-adr_first[2]+1-LenP[2]-16)>Limit) {adr_last[2]=adr_first[2]+Limit;}   //end byte for previous packet
577    if ((adr_last[2]-adr_first[2]+1-LenP[2]-16>64)||(adr_last[2]-adr_first[2]+1-LenP[2]-16<0)) flag_len[2]=1;    
578      if ((adr_last[2]-adr_first[2]+1-LenP[2]-16>64)||(adr_last[2]-adr_first[2]+1-LenP[2]-16<0))
579      {
580       flag_len[2]=1;
581       er_pack_Len+=1;
582       fo_work<<"Length error : packet number="<<numP[2]<<" : length in header="<<LenP[2]<<
583                " : length till next header="<<adr_last[2]-adr_first[2]-16<<" : packet type="<<hex<<
584                packet_type[PackType[2]]<<dec<<"\n";  
585      }
586    if ( (flag_len[2]!=1)&&(flag_CRC_H[2]!=1) )    if ( (flag_len[2]!=1)&&(flag_CRC_H[2]!=1) )
587    {adr_last[2]=adr_first[2]+LenP[2]+15;}    {adr_last[2]=adr_first[2]+LenP[2]+15;}
588    temp[1]=adr_last[2];    temp[1]=adr_last[2];
# Line 527  void verify(char fni[], char inf[], char Line 591  void verify(char fni[], char inf[], char
591    {if (temp[1]/(long int)(pow(256.,3-i))>=1)    {if (temp[1]/(long int)(pow(256.,3-i))>=1)
592          {Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i)));          {Byte_adr2[3-i]=(int)(temp[1]/(long int)(pow(256.,3-i)));
593       temp[1]=temp[1]-(long int)pow(256.,3-i)*       temp[1]=temp[1]-(long int)pow(256.,3-i)*
594       (int)(temp[1]/(long int)(pow(256.,3-i)));}}       (int)(temp[1]/(long int)(pow(256.,3-i)));}}  
     
 /*********PAMELA LAST PACKET LENGTH ERROR ANALYSIS*****************/  
 // if ((adr_last[2]-adr_first[2]+1)!=(LenP[2]+(64-LenP[2]%64)))  
 // {flag_len[2]=1;}  
595    
596  //Write last packet end displacement in log and work.dat files  //Write last packet end displacement in log file
597   for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i]));   for (i=0;i<4;i++) fprintf(fo_log,"%1c",char(Byte_adr2[i]));
 // fprintf(fo_work," last=%i",adr_last[2]);  
598    
599  //Write error number in log and work.dat files  //Write error number in log and work.dat files
600   flags=(short int)(pow((float)(2*flag_CRC_H[2]),1)+   flags=(short int)(pow((float)(2*flag_CRC_H[2]),1)+
601                         pow((float)(2*flag_len[2]),2)+                     pow((float)(2*flag_len[2]),2)+
602                     pow((float)(2*flag_pack[2]),3)+                     pow((float)(2*flag_pack[2]),3)+
603                     pow((float)(2*flag_name[2]),4)+                     pow((float)(2*flag_name[2]),4)+
604                                     pow((float)(2*flag_type[2]),5)+                     pow((float)(2*flag_type[2]),5)+
605                     pow((float)(2*flag_time[2]),6)+                     pow((float)(2*flag_time[2]),6)+
606                                     pow((float)(2*flag_CRC_cor[2]),7));                                     pow((float)(2*flag_CRC_cor[2]),7));
607   if ((flags!=0)&&(N1>0)) er_pack_count+=1;   if ((flags!=0)&&(N1>0)) er_pack_count+=1;
608   fprintf(fo_log,"%1c",char(flags));   fprintf(fo_log,"%1c",char(flags));
609  // fprintf(fo_work," error num.=%i CRC=%i Calc=%i\n",  //Write error number in work.dat file
610  //           flags,bitset<8>(CRC_Header[2]),   if (flags!=0) fo_work<<"PAMELA packet="<<numP[2]<<" : error flag="<<flags<<"\n";
 //               (int)(CRC_H(Name_Buf, Name_Buf_add)));  
611    
612  //Write inf file  //Write inf file
613   fprintf(fo_inf,"file name=%s\n",name_in);   fprintf(fo_inf,"%lli bytes in initial file %s\n", icount_total, name_in);
  fprintf(fo_inf,"%lli bytes\n",icount_total);  
614   icount_int = (int)(icount_total/1024);   icount_int = (int)(icount_total/1024);
615   icount_frac= icount_total%1024;   icount_frac= icount_total%1024;
616   fprintf(fo_inf,"file size= %i,%i kByte \n", icount_int,   fprintf(fo_inf,"file size= %i,%i kByte \n", icount_int, icount_frac);
617                                                         icount_frac);   strcpy(ttt,name_in);
618     ttt[17]='2';
619     fprintf(fo_inf,"%lli bytes in cln2 file %s\n", icount, ttt);
620     ratioCln1Cln2=(float)icount/icount_total;
621     fprintf(fo_inf,"ratio of sizes of Cln1 and Cln2 files %f\n", ratioCln1Cln2);
622    
623   fprintf(fo_inf,"number of identified packets= %i\n", N1);   fprintf(fo_inf,"number of identified packets= %i\n", N1);
624   fprintf(fo_inf,"number of PAMELA missed packets= %i\n",   fprintf(fo_inf,"number of PAMELA missed packets= %i\n",count_miss);
625                       count_miss);   fprintf(fo_inf,"number of PAMELA double transmitted packets = %i\n",count_sec_miss);                
626   fprintf(fo_inf,"number of PAMELA packets with error= %i\n",   fprintf(fo_inf,"number of PAMELA packets with CRC error= %i\n",er_pack_CRC);                
627                       er_pack_count);   fprintf(fo_inf,"number of PAMELA packets with length error= %i\n",er_pack_Len);                                    
628   fprintf(fo_inf,"number of PAMELA packets with corrected name= %i\n",   fprintf(fo_inf,"Overall number of PAMELA packets with error= %i\n",er_pack_count);
629                       count_name_cor);   fprintf(fo_inf,"number of PAMELA packets with corrected name= %i\n",count_name_cor);
630   fprintf(fo_inf,"number of PAMELA packets with non identified type");   fprintf(fo_inf,"number of PAMELA packets with non identified type =%i\n",packet_counter[0]);
  fprintf(fo_inf," =%i\n",packet_counter[0]);  
631    
632   for (i=1;i<NumberPack;i++)   for (i=1;i<NumberPack;i++)
633   {   {
634    fprintf(fo_inf,"Type %x  number of PAMELA packets= %i\n",    fprintf(fo_inf,"Type %x  number of PAMELA packets= %i\n",
635                       packet_type[i-1], packet_counter[i]);                       packet_type[i-1], packet_counter[i]);
636   }   }
637  //Write data in file "mmm_counter_nnnnn_cln2.pam"  //Write data in file "nnnnn_mmm_xxx_cln2.pam"
638   for (i=0;i<adr_last[2]-adr_first[2]+1;i++)   for (i=0;i<adr_last[2]-adr_first[2]+1;i++)
639   {fo_pam<<buffer[i];}   {fo_pam<<buffer[i];}
640    
# Line 593  void verify(char fni[], char inf[], char Line 653  void verify(char fni[], char inf[], char
653   for (i=0;i<5;i++)   for (i=0;i<5;i++)
654   {cirquit_no[i]=name_cln2[i];}   {cirquit_no[i]=name_cln2[i];}
655   cirquit_no[5]='\0';   cirquit_no[5]='\0';
656   for (i=10;i<13;i++)   for (i=6;i<9;i++)
657   {route_no[i-10]=name_cln2[i];}   {route_no[i-6]=name_cln2[i];}
658   route_no[3]='\0';   route_no[3]='\0';
659   file_ready=1;   file_ready=1;
660   file_deleted=0;   file_deleted=0;
661   file_archived=0;   file_archived=0;
662   file_proces=0;   file_proces=0;
663   if (IndexQ>process) file_proces=1;   if (IndexQ>YODA_flag) file_proces=1;
664    
665     if (IndexQ>transmit_flag) {flag_to_transmit=1;}
  if (IndexQ>transmit) {flag_to_transmit=1;}  
666   else {flag_to_transmit=0;}   else {flag_to_transmit=0;}
667   oss.str("");   oss.str("");
668   oss << "INSERT INTO FILES (cirquit_n, route_n, counter, qual_index, ready, deleted, date,"   oss << "INSERT INTO FILES (cirquit_n, route_n, counter, qual_index, ready, deleted, date,"
669       << " archived, path, cln2_name, proces_flag, transit_flag)"       << " archived, path, cln2_name, proces_flag, transit_flag)"
670       << " VALUES ('"<< cirquit_no << "','"<< route_no << "','"<<r_counter<<"','"<< IndexQ << "','"       << " VALUES ('"<< cirquit_no << "','"<< route_no << "','"<<r_counter<<"','"<< IndexQ << "','"
671       << file_ready << "','"<< file_deleted << "','"<< data_time << "','"<< file_archived << "','"       << file_ready << "','"<< file_deleted << "','"<< data_time << "','"<< file_archived << "','"
672       << name_path << "', '" << name_cln2 << "', '" << file_proces << "','"       << name_path << "', '" << name_cln2 << "','"<< file_proces << "','"
673       << flag_to_transmit << "')";       << flag_to_transmit << "')";
674  // cout<<oss.str().c_str()<<" table FILES\n";         if (print_flag>0) cout<<oss.str().c_str()<<" table FILES\n";      
675   TSQLResult *res=sqlServer->Query(oss.str().c_str());   TSQLResult *res=sqlServer->Query(oss.str().c_str());
676    
677   flag_sec_trans=0;   flag_sec_trans=0;
678    
679   oss1.str("");   oss1.str("");
680   oss1 <<"INSERT INTO FILES1 (my_route, raw_filename, pam_size, cirquit_n, route_n, route_real,"   oss1 <<"INSERT INTO FILES1 (my_route, raw_filename, pam_size, ratioCln1Cln2, cirquit_n, route_n, route_real,"
681        <<" counter, board_time, Num_all, Num_macro, flag_twice)"        <<" counter, board_time, Num_all, Num_macro, flag_twice, OBT_first, OBT_last)"
682        <<" VALUES ('"<<current_route<<"','"<<name_ini<<"','"<<icount<<"','"<<cirquit_no<<"','"        <<" VALUES ('"<<current_route<<"','"<<name_ini<<"','"<<icount<<"','"<<ratioCln1Cln2<<"','"<<cirquit_no<<"','"
683        <<route_no<<"','"<<real_route[r_counter]<<"','"<<r_counter        <<route_no<<"','"<<real_route[r_counter]<<"','"<<r_counter
684        <<"','"<<time_p[2]<<"','"<<N1<<"','"<<packet_counter[28]<<"','"<<flag_sec_trans<<"')";        <<"','"<<time_p[2]<<"','"<<N1<<"','"<<packet_counter[28]<<"','"<<flag_sec_trans<<"','"<<time_min<<"','"<<time_max<<"')";
685  // cout<<oss1.str().c_str()<<" table FILES1\n";         if (print_flag>0) cout<<oss1.str().c_str()<<" table FILES1\n";      
686   TSQLResult *res3=sqlServer->Query(oss1.str().c_str());   TSQLResult *res3=sqlServer->Query(oss1.str().c_str());
687    
688  // if (conn->Query(oss.str().c_str()) == 0)  // if (conn->Query(oss.str().c_str()) == 0)
# Line 632  void verify(char fni[], char inf[], char Line 691  void verify(char fni[], char inf[], char
691  // }  // }
692    
693   delete [] buffer;   delete [] buffer;
   
694  /***************************************************************/  /***************************************************************/
695    fin.close();    fin.close();
696    fclose(fo_work);    fo_work.close();
697    fclose(fo_log);    fclose(fo_log);
698    fclose(fo_inf);    fclose(fo_inf);
699    fo_pam.close();    fo_pam.close();

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.23