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

Diff of /rawreader/src/sort.cpp

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

revision 1.3 by cafagna, Sun Dec 10 12:52:52 2006 UTC revision 1.4 by cafagna, Sun Dec 10 13:06:03 2006 UTC
# Line 5  Line 5 
5  void  RunHeaderReader(char *buf);  void  RunHeaderReader(char *buf);
6  extern long int OBTtimesync;  extern long int OBTtimesync;
7  extern long int Timesync;  extern long int Timesync;
8  extern char MYSQL[80];  extern char MYSQL[120];
9  extern char database[80];  extern char database[120];
10    extern char arina[120];
11  extern int print_flag;  extern int print_flag;
12    
13  struct Names  struct Names
14  {  {
15   char a[80];                     /*Full name for nnnnn_mmm_xxx_AA.bin*/   char a[100];                     /*Full name for nnnnn_mmm_xxx_AA.bin*/
16   char a_short[80];               /*Short name for nnnnn_mmm_xxx_AA.bin*/   char a_short[80];                /*Short name for nnnnn_mmm_xxx_AA.bin*/
17   FILE *fo_a;   FILE *fo_a;
18  };  };
19    
# Line 20  void sort(char log[], char pam[], char p Line 21  void sort(char log[], char pam[], char p
21                    char file_init[], int packet_type[])                    char file_init[], int packet_type[])
22    
23  {  {
24   FILE *fo_log, *fo_ql, *fo_work2, *f_temp;   FILE *fo_log, *fo_ql, *fo_work2;
25    
26   Names data[NumberPack+1];   Names data[NumberPack+1];
27   char fno2[80];       /* Out help file mm_nnnnn_work2.dat*/   char fno2[80];       /* Out help file mm_nnnnn_work2.dat*/
28   char ql[80];   char ql[80];
29   char tmp[80], tmp1[80], numer[10];   char tmp[80], tmp1[80], numer[10];
  char arina[80];  
30   char connection[80];   char connection[80];
31   char query[500];   char query[500];
32   long int orbit, route, count;   long int orbit=0, route=0, count=0;
33  // char buffer[10];  // char buffer[10];
34   char *packet=new char[Nmax];   char *packet=new char[Nmax];
35   unsigned int type=0;           /*PAMELA packet type*/   unsigned int type=0;           /*PAMELA packet type*/
# Line 52  void sort(char log[], char pam[], char p Line 52  void sort(char log[], char pam[], char p
52   for (i=0;i<4;i++)   for (i=0;i<4;i++)
53   {Hex_first[i]=0;   {Hex_first[i]=0;
54    Hex_last[i]=0;}    Hex_last[i]=0;}
   
55   for (i=0;i<NumberPack+1;i++)   for (i=0;i<NumberPack+1;i++)
56   {counter[i]=0;   {counter[i]=0;
57    first[i]=0;    first[i]=0;
58    last[i]=0;}    last[i]=0;}
   
59   Length=(int)(strlen(file_init));   Length=(int)(strlen(file_init));
60   strncat(strcpy(tmp,"\0"),file_init,Length-8);   strncat(strcpy(tmp,"\0"),file_init,Length-8);
  strcat(strcpy(tmp1,path),"tmp.dat");  
  f_temp=fopen(tmp1,"wb+");  
61    
62   stringstream oss;   stringstream oss;
63    
64   strcpy(connection,MYSQL);   strcpy(connection,MYSQL);
65   strcat(connection,database);   strcat(connection,database);
66   TSQLServer *sqlServer = TSQLServer::Connect(connection, "pamelaprod", "rawprod");   TSQLServer *sqlServer = TSQLServer::Connect(connection, "pamelaprod", "rawprod");
67     if (sqlServer==0) {cerr<<"can not connect with MYSQL server\n"; exit(1);}
68    
69   for (i=0;i<NumberPack+1;i++)   for (i=0;i<NumberPack+1;i++)
70   {   {
71    if (i==0) {fprintf(f_temp,"%02i",i);}    if (i==0)
72    else {fprintf(f_temp,"%02X",packet_type[i-1]);}    {sprintf(tmp1,"%02i",i);
73    fseek(f_temp,0,0);     sscanf(tmp1,"%02s",numer);
74    fgets(numer,10,f_temp);     numer[2]='\0';  
75    fseek(f_temp,0,0);    }
76      else
77      {sprintf(tmp1,"%02X",packet_type[i-1]);
78       sscanf(tmp1,"%02s",numer);
79       numer[2]='\0';
80      }
81    
82  /*************Open files /home/pamelaprod/rawreader/level0/nnnnn/xxx_mmm/packets/nnnnn_mmm_xxx_AA.bin*******/  /*************Open files /home/pamelaprod/rawreader/level0/nnnnn/xxx_mmm/packets/nnnnn_mmm_xxx_AA.bin*******/
83    strncat(strcpy(data[i].a,path3),file_init,Length-8);    strncat(strcpy(data[i].a,path3),file_init,Length-8);
84    strcat(data[i].a,numer);    strcat(data[i].a,numer);
# Line 93  void sort(char log[], char pam[], char p Line 96  void sort(char log[], char pam[], char p
96    {cerr<<"can not open _%s.dat file",numer; exit(1);}    {cerr<<"can not open _%s.dat file",numer; exit(1);}
97        
98   }   }
  fclose(f_temp);  
  remove(tmp1);  
99  /**********************OPEN NECESSARY FILES************************/  /**********************OPEN NECESSARY FILES************************/
100  /******************************************************************/  /******************************************************************/
101   ifstream fo_pam;   ifstream fo_pam;
# Line 102  void sort(char log[], char pam[], char p Line 103  void sort(char log[], char pam[], char p
103   if(fo_pam.good()==0) {cerr<<"can not open pam file"; exit(1);}   if(fo_pam.good()==0) {cerr<<"can not open pam file"; exit(1);}
104    
105   ofstream fo_arina;   ofstream fo_arina;
106   strcpy(arina,"/home/arina/orientation/");   strcat(arina,data[28].a_short);
107   strcat(arina,data[28].a_short);   if (print_flag>0) cout<<"arina="<<arina<<"\n";
108   if (print_flag>0) cout<<arina<<"\n";   fo_arina.open(arina,ios::binary);  //open file for arina
  fo_arina.open(arina,ios::binary);  
109   if(fo_arina.good()==0) {cerr<<"can not open arina file"; exit(1);}   if(fo_arina.good()==0) {cerr<<"can not open arina file"; exit(1);}
110    
111   fo_log=fopen(log, "rb");      //open input file "nnnnn_mmm_xxx_cln2.log"   fo_log=fopen(log, "rb");      //open input file "nnnnn_mmm_xxx_cln2.log"
# Line 158  void sort(char log[], char pam[], char p Line 158  void sort(char log[], char pam[], char p
158     moscowtime=time-(OBTtimesync-Timesync);     moscowtime=time-(OBTtimesync-Timesync);
159                
160     /*temp is packet number*/     /*temp is packet number*/
161     temp=(long int)(unsigned char)(packet[7])+     temp=(long int)(unsigned char)(packet[7])+256*(long int)(unsigned char)(packet[6])+
162                    256*(long int)(unsigned char)(packet[6])+                                           256*256*(long int)(unsigned char)(packet[5]);
           256*256*(long int)(unsigned char)(packet[5]);  
163     if ((print_flag>0)&&(fmod((float)(temp),(float)(10000.))==0.)&&(temp!=0)) cout<<"sorting "<<temp<<"\n";     if ((print_flag>0)&&(fmod((float)(temp),(float)(10000.))==0.)&&(temp!=0)) cout<<"sorting "<<temp<<"\n";
164    
165     /*unpacking several packets....   mikhailov     /*unpacking several packets....   mikhailov
# Line 264  void sort(char log[], char pam[], char p Line 263  void sort(char log[], char pam[], char p
263    
264   for (i=0;i<NumberPack+1;i++)   for (i=0;i<NumberPack+1;i++)
265   fprintf(fo_work2,"Number of packets in %s file = %i\n",data[i].a_short,counter[i]);   fprintf(fo_work2,"Number of packets in %s file = %i\n",data[i].a_short,counter[i]);
266     if (print_flag>0) cout<<file_init<<"\n";
267   for(i=0;i<5;i++) {tmp1[i]=file_init[i];} tmp1[5]=' ';   for(i=0;i<5;i++) {tmp1[i]=file_init[i];} tmp1[5]='\0';
268   sscanf(tmp1,"%5d",&orbit);   sscanf(tmp1,"%5u",&orbit);
269     for(i=6;i<9;i++) {tmp1[i-6]=file_init[i];} tmp1[3]='\0';
270   for(i=6;i<9;i++) {tmp1[i-6]=file_init[i];} tmp1[3]=' ';   sscanf(tmp1,"%3u",&route);
271   sscanf(tmp1,"%3d",&route);   for(i=10;i<13;i++) {tmp1[i-10]=file_init[i];} tmp1[3]='\0';
272     sscanf(tmp1,"%3u",&count);
  for(i=10;i<13;i++) {tmp1[i-10]=file_init[i];} tmp1[3]=' ';  
  sscanf(tmp1,"%3d",&count);  
   
273   oss.str("");   oss.str("");
274   oss << "UPDATE FILES1 set time_dif="<<time_differ<<" where cirquit_n="<<orbit<<" and route_n="<<route<<   oss << "UPDATE FILES1 set time_dif="<<time_differ<<" where cirquit_n="<<orbit<<" and route_n="<<route<<
275          " and counter="<<count;          " and counter="<<count;

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

  ViewVC Help
Powered by ViewVC 1.1.23