1 |
///////////////PAMELA PACKETS SORT/////////////////////////////////// |
///////////////PAMELA PACKETS SORT/////////////////////////////////// |
2 |
#include "descript.h" |
#include "descript.h" |
3 |
|
#include "flag.h" |
4 |
|
|
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; |
49 |
first[i]=0; |
first[i]=0; |
50 |
last[i]=0;} |
last[i]=0;} |
51 |
|
|
52 |
Length=(int)(strlen(file_init)); |
Length=(int)(strlen(file_init)); |
53 |
strncat(strcpy(tmp,"\0"),file_init,Length-8); |
strncat(strcpy(tmp,"\0"),file_init,Length-8); |
54 |
strcat(strcpy(tmp1,path),"tmp.dat"); |
strcat(strcpy(tmp1,path),"tmp.dat"); |
55 |
f_temp=fopen(tmp1,"wb+"); |
f_temp=fopen(tmp1,"wb+"); |
61 |
fseek(f_temp,0,0); |
fseek(f_temp,0,0); |
62 |
fgets(numer,10,f_temp); |
fgets(numer,10,f_temp); |
63 |
fseek(f_temp,0,0); |
fseek(f_temp,0,0); |
64 |
/*************Open files /home/pamelaprod/rawreader/level0/nnnnn/mmm_counter/packets/mmm_nnnnn_counter_xx.bin*******/ |
/*************Open files /home/pamelaprod/rawreader/level0/nnnnn/xxx_mmm/packets/nnnnn_mmm_xxx_AA.bin*******/ |
65 |
strncat(strcpy(data[i].a,path3),file_init,Length-8); |
strncat(strcpy(data[i].a,path3),file_init,Length-8); |
66 |
strcat(data[i].a,numer); |
strcat(data[i].a,numer); |
67 |
strcat(data[i].a,".bin"); |
strcat(data[i].a,".bin"); |
68 |
//form the 'mmm_' |
//form the 'nnnnn_mmm_xxx_AA.bin' |
69 |
for (j=0;j<4;j++) tmp[j]=data[i].a[strlen(data[i].a)-(20-j)]; |
for (j=0;j<20;j++) tmp[j]=data[i].a[strlen(data[i].a)-(20-j)]; |
70 |
//form the 'mmm_nnnnn_' |
/*********************Create names nnnnn_mmm_xxx_AA.bin********************/ |
|
for (j=0;j<6;j++) tmp[j+4]=data[i].a[strlen(data[i].a)-(12-j)]; |
|
|
//form the 'mmm_nnnnn_ccc_' |
|
|
for (j=0;j<4;j++) tmp[j+10]=data[i].a[strlen(data[i].a)-(16-j)]; |
|
|
//form the 'mmm_nnnnn_ccc_XX.bin' |
|
|
for (j=0;j<6;j++) tmp[j+14]=data[i].a[strlen(data[i].a)-(6-j)]; tmp[20]='\0'; |
|
|
/*********************Create names mmm_nnnnn_counter_xx.bin********************/ |
|
71 |
for (j=0;j<20;j++) |
for (j=0;j<20;j++) |
72 |
{data[i].a_short[j]=tmp[j]; data[i].a_short[20]='\0'; |
{data[i].a_short[j]=tmp[j]; data[i].a_short[20]='\0'; |
73 |
data[i].a[strlen(data[i].a)-(20-j)]=tmp[j]; |
data[i].a[strlen(data[i].a)-(20-j)]=tmp[j]; |
74 |
} |
} |
75 |
|
|
76 |
data[i].fo_a=fopen(data[i].a,"wb"); |
data[i].fo_a=fopen(data[i].a,"wb"); |
77 |
if(data[i].fo_a==NULL) |
if(data[i].fo_a==NULL) |
83 |
/**********************OPEN NECESSARY FILES************************/ |
/**********************OPEN NECESSARY FILES************************/ |
84 |
/******************************************************************/ |
/******************************************************************/ |
85 |
ifstream fo_pam; |
ifstream fo_pam; |
86 |
fo_pam.open(pam,ios::binary); //open input file "mmm_counter_nnnnn_cln2.pam" |
fo_pam.open(pam,ios::binary); //open input file "xxx_mmm_nnnnn_cln2.pam" |
87 |
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);} |
88 |
|
|
89 |
ofstream fo_arina; |
ofstream fo_arina; |
90 |
strcpy(arina,"/home/arina/orientation/"); |
strcpy(arina,"/home/arina/orientation/"); |
91 |
strcat(arina,data[28].a_short); cout<<arina<<"\n"; |
strcat(arina,data[28].a_short); //cout<<arina<<"\n"; |
92 |
fo_arina.open(arina,ios::binary); |
fo_arina.open(arina,ios::binary); |
93 |
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);} |
94 |
|
|
95 |
fo_log=fopen(log, "rb"); //open input file "mmm_counter_nnnnn_cln2.log" |
fo_log=fopen(log, "rb"); //open input file "xxx_mmm_nnnnn_cln2.log" |
96 |
if(fo_log==NULL) {cerr<<"can not open log file"; exit(1);} |
if(fo_log==NULL) {cerr<<"can not open log file"; exit(1);} |
97 |
|
|
98 |
strcpy(fno2,path3); |
strcpy(fno2,path3); |
99 |
strncat(fno2,file_init,strlen(file_init)-8); |
strncat(fno2,file_init,strlen(file_init)-8); |
100 |
fo_work2=fopen(strcat(fno2,"work2.dat"), "wb"); |
strcat(fno2,"work2.dat"); |
101 |
fo_work2=fopen(fno2, "wb"); //open output help file "work_cln2.dat" |
fo_work2=fopen(fno2, "wb"); //open output help file "xxx_mmm_nnnnn_work2.dat" |
102 |
if(fo_work2==NULL) {cerr<<"can not open outputfile"; exit(1);} |
if(fo_work2==NULL) {cerr<<"can not open outputfile"; exit(1);} |
103 |
|
|
104 |
strncat(strcpy(ql,path3),file_init,Length-8); |
strncat(strcpy(ql,path3),file_init,Length-8); |
105 |
strcat(ql,"ql.log"); |
strcat(ql,"ql.log"); |
106 |
fo_ql=fopen(ql, "wb"); //open output file "mmm_counter_nnnnn_ql.log" |
fo_ql=fopen(ql, "wb"); //open output file "xxx_mmm_nnnnn_ql.log" |
107 |
if(fo_ql==NULL) {cerr<<"can not open ql file"; exit(1);} |
if(fo_ql==NULL) {cerr<<"can not open ql file"; exit(1);} |
108 |
|
|
109 |
/******************************************************************/ |
/******************************************************************/ |
110 |
/******************************************************************/ |
/******************************************************************/ |
111 |
while(feof(fo_log)==0) |
while(feof(fo_log)==0) |
112 |
{ |
{ |
113 |
//read PAMELA packet information from Route_cln2.log |
//read PAMELA packet information from xxx_mmm_nnnnn__cln2.log |
114 |
fscanf(fo_log,"%1c",&type); |
fscanf(fo_log,"%1c",&type); |
115 |
if (feof(fo_log)!=0) break; |
if (feof(fo_log)!=0) break; |
116 |
fscanf(fo_log,"%4c",&adr1); |
fscanf(fo_log,"%4c",&adr1); |
120 |
fscanf(fo_log,"%1c",&error); |
fscanf(fo_log,"%1c",&error); |
121 |
if (feof(fo_log)!=0) break; |
if (feof(fo_log)!=0) break; |
122 |
|
|
|
// cout<<bitset<8>(error)<<"\n"; |
|
|
// cout<<bitset<8>(error).test(0)<<"\n"; |
|
123 |
if ( ( (bitset<8>(error).test(7))||(error==0)|| |
if ( ( (bitset<8>(error).test(7))||(error==0)|| |
124 |
((bitset<8>(error).test(0))&&(!bitset<8>(error).test(1))&&(!bitset<8>(error).test(2))&& |
((bitset<8>(error).test(0))&&(!bitset<8>(error).test(1))&&(!bitset<8>(error).test(2))&& |
125 |
(!bitset<8>(error).test(3))&&(!bitset<8>(error).test(4))&&(!bitset<8>(error).test(5))&& |
(!bitset<8>(error).test(3))&&(!bitset<8>(error).test(4))&&(!bitset<8>(error).test(5))&& |
126 |
(!bitset<8>(error).test(6))) )&& |
(!bitset<8>(error).test(6))) )&& |
127 |
(type>0)&&(type<NumberPack+1) ) |
(type>0)&&(type<NumberPack+1) ) |
128 |
{ |
{ |
129 |
/*Place file pointer in Route_cln2.pam on packet begin*/ |
/*Place file pointer in xxx_mmm_nnnnn_cln2.pam on packet begin*/ |
130 |
fo_pam.seekg(adr1-1,ios::beg); |
fo_pam.seekg(adr1-1,ios::beg); |
131 |
//read PAMELA packet from Route_cln2.pam |
//read PAMELA packet from xxx_mmm_nnnnn_cln2.pam |
132 |
fo_pam.read(packet,adr2-adr1+1); |
fo_pam.read(packet,adr2-adr1+1); |
133 |
|
|
134 |
/*OBT of Pamela*/ |
/*OBT of Pamela*/ |
141 |
|
|
142 |
moscowtime=time-(OBTtimesync-Timesync); |
moscowtime=time-(OBTtimesync-Timesync); |
143 |
|
|
144 |
if(type == 11) cout<<"time ="<<time<<" moscowtime ="<<moscowtime<<"\n"; |
// if(type == 11) cout<<"time ="<<time<<" moscowtime ="<<moscowtime<<"\n"; |
145 |
/*temp is packet number*/ |
/*temp is packet number*/ |
146 |
temp=(long int)(unsigned char)(packet[7])+ |
temp=(long int)(unsigned char)(packet[7])+ |
147 |
256*(long int)(unsigned char)(packet[6])+ |
256*(long int)(unsigned char)(packet[6])+ |
148 |
256*256*(long int)(unsigned char)(packet[5]); |
256*256*(long int)(unsigned char)(packet[5]); |
149 |
if ((fmod((float)(temp),(float)(10000.))==0.)&&(temp!=0)) cout<<"sorting "<<temp<<"\n"; |
// if ((fmod((float)(temp),(float)(10000.))==0.)&&(temp!=0)) cout<<"sorting "<<temp<<"\n"; |
150 |
/*unpacking several packets.... mikhailov |
/*unpacking several packets.... mikhailov |
151 |
unpackingPamelaPacket(packet,type)*/ |
unpackingPamelaPacket(packet,type)*/ |
152 |
|
|
154 |
if( type == 11){RunHeaderReader(packet);} |
if( type == 11){RunHeaderReader(packet);} |
155 |
/*******************Packet with type "type"***********************/ |
/*******************Packet with type "type"***********************/ |
156 |
counter[type]+=1; |
counter[type]+=1; |
157 |
//write PAMELA packet in mmm_nnnnn_counter_xx.bin |
//write PAMELA packet in mmm_nnnnn_xxx_AA.bin |
158 |
if (type!=4) fwrite(packet,adr2-adr1+1,1,data[type].fo_a); |
if (type!=4) fwrite(packet,adr2-adr1+1,1,data[type].fo_a); |
159 |
//write for ARINA |
//write for ARINA |
160 |
if (type==28) fo_arina.write(packet,adr2-adr1+1); |
if (type==28) fo_arina.write(packet,adr2-adr1+1); |
175 |
temp=temp-(long int)pow(256.,3-i)* |
temp=temp-(long int)pow(256.,3-i)* |
176 |
(int)(temp/(long int)(pow(256.,3-i)));} |
(int)(temp/(long int)(pow(256.,3-i)));} |
177 |
} |
} |
178 |
//write information about PAMELA packet in mmm_counter_nnnnn_ql.log |
//write information about PAMELA packet in xxx_mmm_nnnnn_ql.log |
179 |
if (type!=4) |
if (type!=4) |
180 |
{ |
{ |
181 |
fprintf(fo_ql,"%1c",char(type)); |
fprintf(fo_ql,"%1c",char(type)); |
226 |
(int)(temp/(long int)(pow(256.,3-i)));} |
(int)(temp/(long int)(pow(256.,3-i)));} |
227 |
} |
} |
228 |
if (type!=4) |
if (type!=4) |
229 |
{//write information about PAMELA packet in mmm_counter_nnnnn_ql.log |
{//write information about PAMELA packet in xxx_mmm_nnnnn_ql.log |
230 |
fprintf(fo_ql,"%1c",(char)(type)); |
fprintf(fo_ql,"%1c",(char)(type)); |
231 |
for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_first[i])); |
for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_first[i])); |
232 |
// for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_last[i])); //temporary |
// for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_last[i])); //temporary |