/[PAMELA software]/yoda/techmodel/forroutines/anticounter/AC.c
ViewVC logotype

Annotation of /yoda/techmodel/forroutines/anticounter/AC.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.0 - (hide annotations) (download)
Tue Feb 7 17:11:10 2006 UTC (18 years, 9 months ago) by kusanagi
Branch: MAIN
CVS Tags: yodaPreTermistors2_1/00, YODA6_2/01, YODA6_2/00, YODA6_3/19, YODA6_3/18, YODA6_3/13, YODA6_3/12, YODA6_3/11, YODA6_3/10, YODA6_3/17, YODA6_3/16, YODA6_3/15, YODA6_3/14, YODA6_3/06, YODA6_1/00, YODA6_0/00, YODA6_3/04, YODA6_3/05, YODA6_3/20, YODA6_3/07, YODA6_3/00, YODA6_3/01, YODA6_3/02, YODA6_3/03, YODA6_3/08, YODA6_3/09, yodaPreTermistores2_0/00, HEAD
Branch point for: PreThermistores2
Changes since 5.0: +0 -0 lines
File MIME type: text/plain
Several new features in this revision:
a) all the packets are conform to the Mass Memory Format specifications (http://people.roma2.infn.it/~cpu/Mass_Memory_Format.html)
b) unpacking either using the old files structure OR the new one file unpacking.
c) parametrized root files compression factor
d) deleting of the following packet: TofTest, TrkTest, TrkEvent.
e) the Tracker routines now work without the use of temp files.

The point a) allow Yoda to unpack in the root file all the packets generated by the CPU. According to the MassMemoryFormat; that is three possible data are available:

1) almost explicit structure of the packet (like for Log, Tracker, Mcmd, etc....);
2) dummy data collection structure (InitHeader, InitTrailer, CalibHeader, CalibTrailer);
3) just the data of the packet (almost all Alarm and Init procedures). The class regarding this packets have only one parameters, a TArrayC class, which contain the data-block included in the packet (tat is the data below the packet Header).

The point b) has been implemented as a consequence of an agreement about a more compact structure of the unpacked data. Up to now the structure of each unpacked data consisted of a folder, named after the packet type, and three files: xxx.Header.root, xxx.NamePacket.root, xxx.Registry.root.
Starting from this release YODA, by default will unpack the data in a unique root file. The structure of this file will consist of:
- several TTree(s) named after the packet type;
- into each TTree are foreseen three TBranche(s):
    - 'Header'  (the old xxx.Header.root file)
    - 'NameOfThePacket' (the old xxx.Event.root file or the xxx.Event.DETECTOR.root)
    - 'Registry' (the old xxx.Registry.root file)

Anyway is still possible, but deprecated, to unpack using the old structure, passing to the "yoda" command the optional parameter "-multifile"

The point c) has been implemented because is well know that writing time in a TTree is as much fast as much lower is the compression factor for the root file; anyway for a PAMELA dat file, a compression equal to 0 will generate a root file which will be more than two times the original size. To modify the compression parameter just add the optional parameter "-c [0-9]" to the yoda command line.

1 kusanagi 2.10 /*******************************v1.3********************************
2 kusanagi 2.2
3     Functions to read AC physics data (ACphysics) and AC calibration
4     data (ACcalib).
5 kusanagi 2.1 Author: Petter Hofverberg, petter@particle.kth.se
6    
7 kusanagi 2.2 0410 v1.0 alive
8 kusanagi 2.5 0412 v1.1 fixed problem with found, and changed headers
9 kusanagi 2.8 0502 v1.2 added a crc check
10 kusanagi 2.10 0502 v1.3 increased buffer size
11 kusanagi 2.2
12 kusanagi 2.1 Errors: (returned to the main program as the variable "err")
13     err=
14 kusanagi 2.2 0xFF - data (physics or calibration) from both cards found
15     0xF0 - only data from main card found
16     0x0F - only data from extra card found
17     0x00 - no data found
18 kusanagi 2.1
19 kusanagi 2.8 CRCcheck: 1 - OK, 0 - error
20 kusanagi 2.1 ******************************************************************/
21    
22     #include <stdio.h>
23     #include "AC.h"
24 kusanagi 2.8 #define TRUE 1
25     #define FALSE 0
26 kusanagi 2.1
27 kusanagi 2.5 int i,j,found;
28 kusanagi 2.10 unsigned short buffer[8300];
29 kusanagi 2.8 unsigned short tmp1,tmp2,check;
30 kusanagi 2.2 unsigned char err;
31 kusanagi 2.1
32 kusanagi 2.2 struct physicsstruct physicsdata[2];
33 kusanagi 2.1 struct physicsstruct *physicspointer;
34    
35 kusanagi 2.6 struct calibstruct calibdata;
36 kusanagi 2.1 struct calibstruct *calibpointer;
37    
38 kusanagi 2.8
39     //CRC check function
40     short crc(short old,short new)
41     {
42     union crc_data {
43     short word;
44     struct bit_field {
45     unsigned b0:1;
46     unsigned b1:1;
47     unsigned b2:1;
48     unsigned b3:1;
49     unsigned b4:1;
50     unsigned b5:1;
51     unsigned b6:1;
52     unsigned b7:1;
53     unsigned b8:1;
54     unsigned b9:1;
55     unsigned b10:1;
56     unsigned b11:1;
57     unsigned b12:1;
58     unsigned b13:1;
59     unsigned b14:1;
60     unsigned b15:1;
61     } bit;
62     } c,d,r;
63    
64     c.word = old;
65     d.word = new;
66     r.word = 0;
67    
68     r.bit.b0 = c.bit.b0 ^ c.bit.b4 ^ c.bit.b8 ^ c.bit.b11 ^ c.bit.b12 ^
69     d.bit.b0 ^ d.bit.b4 ^ d.bit.b8 ^ d.bit.b11 ^ d.bit.b12;
70    
71     r.bit.b1 = c.bit.b1 ^ c.bit.b5 ^ c.bit.b9 ^ c.bit.b12 ^ c.bit.b13 ^
72     d.bit.b1 ^ d.bit.b5 ^ d.bit.b9 ^ d.bit.b12 ^ d.bit.b13;
73    
74     r.bit.b2 = c.bit.b2 ^ c.bit.b6 ^ c.bit.b10 ^ c.bit.b13 ^ c.bit.b14 ^
75     d.bit.b2 ^ d.bit.b6 ^ d.bit.b10 ^ d.bit.b13 ^ d.bit.b14;
76    
77     r.bit.b3 = c.bit.b3 ^ c.bit.b7 ^ c.bit.b11 ^ c.bit.b14 ^ c.bit.b15 ^
78     d.bit.b3 ^ d.bit.b7 ^ d.bit.b11 ^ d.bit.b14 ^ d.bit.b15;
79    
80     r.bit.b4 = c.bit.b4 ^ c.bit.b8 ^ c.bit.b12 ^ c.bit.b15 ^
81     d.bit.b4 ^ d.bit.b8 ^ d.bit.b12 ^ d.bit.b15;
82    
83     r.bit.b5 = c.bit.b0 ^ c.bit.b4 ^ c.bit.b5 ^ c.bit.b8 ^ c.bit.b9 ^
84     c.bit.b11 ^ c.bit.b12 ^ c.bit.b13 ^
85     d.bit.b0 ^ d.bit.b4 ^ d.bit.b5 ^ d.bit.b8 ^ d.bit.b9 ^
86     d.bit.b11 ^ d.bit.b12 ^ d.bit.b13;
87    
88     r.bit.b6 = c.bit.b1 ^ c.bit.b5 ^ c.bit.b6 ^ c.bit.b9 ^ c.bit.b10 ^
89     c.bit.b12 ^ c.bit.b13 ^ c.bit.b14 ^
90     d.bit.b1 ^ d.bit.b5 ^ d.bit.b6 ^ d.bit.b9 ^ d.bit.b10 ^
91     d.bit.b12 ^ d.bit.b13 ^ d.bit.b14;
92    
93     r.bit.b7 = c.bit.b2 ^ c.bit.b6 ^ c.bit.b7 ^ c.bit.b10 ^ c.bit.b11 ^
94     c.bit.b13 ^ c.bit.b14 ^ c.bit.b15 ^
95     d.bit.b2 ^ d.bit.b6 ^ d.bit.b7 ^ d.bit.b10 ^ d.bit.b11 ^
96     d.bit.b13 ^ d.bit.b14 ^ d.bit.b15;
97    
98     r.bit.b8 = c.bit.b3 ^ c.bit.b7 ^ c.bit.b8 ^ c.bit.b11 ^ c.bit.b12 ^
99     c.bit.b14 ^ c.bit.b15 ^
100     d.bit.b3 ^ d.bit.b7 ^ d.bit.b8 ^ d.bit.b11 ^ d.bit.b12 ^
101     d.bit.b14 ^ d.bit.b15;
102    
103     r.bit.b9 = c.bit.b4 ^ c.bit.b8 ^ c.bit.b9 ^ c.bit.b12 ^ c.bit.b13 ^
104     c.bit.b15 ^
105     d.bit.b4 ^ d.bit.b8 ^ d.bit.b9 ^ d.bit.b12 ^ d.bit.b13 ^
106     d.bit.b15;
107    
108     r.bit.b10 = c.bit.b5 ^ c.bit.b9 ^ c.bit.b10 ^ c.bit.b13 ^ c.bit.b14 ^
109     d.bit.b5 ^ d.bit.b9 ^ d.bit.b10 ^ d.bit.b13 ^ d.bit.b14;
110    
111     r.bit.b11 = c.bit.b6 ^ c.bit.b10 ^ c.bit.b11 ^ c.bit.b14 ^ c.bit.b15 ^
112     d.bit.b6 ^ d.bit.b10 ^ d.bit.b11 ^ d.bit.b14 ^ d.bit.b15;
113    
114     r.bit.b12 = c.bit.b0 ^ c.bit.b4 ^ c.bit.b7 ^ c.bit.b8 ^ c.bit.b15 ^
115     d.bit.b0 ^ d.bit.b4 ^ d.bit.b7 ^ d.bit.b8 ^ d.bit.b15;
116    
117     r.bit.b13 = c.bit.b1 ^ c.bit.b5 ^ c.bit.b8 ^ c.bit.b9 ^
118     d.bit.b1 ^ d.bit.b5 ^ d.bit.b8 ^ d.bit.b9;
119    
120     r.bit.b14 = c.bit.b2 ^ c.bit.b6 ^ c.bit.b9 ^ c.bit.b10 ^
121     d.bit.b2 ^ d.bit.b6 ^ d.bit.b9 ^ d.bit.b10;
122    
123     r.bit.b15 = c.bit.b3 ^ c.bit.b7 ^ c.bit.b10 ^ c.bit.b11 ^
124     d.bit.b3 ^ d.bit.b7 ^ d.bit.b10 ^ d.bit.b11;
125    
126     return r.word;
127     }
128    
129    
130 kusanagi 2.3 //Fill physicsdata from buffer
131     void fillphys(int k,unsigned short *buff)
132     {
133     for(i=0;i<2;i++) physicsdata[k].header[i]=buff[i];
134     physicsdata[k].status=buff[2];
135     physicsdata[k].hitmap=buff[3];
136     for(i=0;i<6;i++) physicsdata[k].regist[i]=buff[4+i];
137     for(i=0;i<16;i++) physicsdata[k].shift[i]=buff[10+i];
138     for(i=0;i<16;i++) physicsdata[k].counters[i]=buff[26+i];
139     for(i=0;i<8;i++) physicsdata[k].coinc[i]=buff[42+i];
140     physicsdata[k].trigg=buff[50];
141     for(i=0;i<2;i++) physicsdata[k].clock[i]=buff[51+i];
142     for(i=0;i<2;i++) physicsdata[k].temp[i]=buff[53+i];
143     for(i=0;i<8;i++) physicsdata[k].DAC[i]=buff[55+i];
144     physicsdata[k].CRC=buff[63];
145 kusanagi 2.8 if(check==physicsdata[k].CRC)
146     physicsdata[k].CRCcheck=TRUE;
147     else
148     physicsdata[k].CRCcheck=FALSE;
149 kusanagi 2.3 }
150    
151     //Fill calibdata from buffer
152 kusanagi 2.6 void fillcalib(unsigned short *buff)
153 kusanagi 2.3 {
154 kusanagi 2.6 for(i=0;i<2;i++) calibdata.header[i]=buff[i];
155     for(i=0;i<5;i++) calibdata.status[i]=buff[2+i];
156     for(i=0;i<8;i++) calibdata.temp[i]=buff[7+i];
157     for(i=0;i<8;i++) calibdata.DAC1[i]=buff[15+i];
158     for(i=0;i<8;i++) calibdata.DAC2[i]=buff[23+i];
159     for(i=0;i<6;i++) calibdata.regist[i]=buff[31+i];
160     for(i=0;i<8;i++) calibdata.time[i]=buff[37+i];
161     calibdata.n_tr=buff[45];
162     for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buff[46+i];
163     for(i=0;i<4096;i++) calibdata.curve1[i]=buff[62+i];
164     for(i=0;i<4096;i++) calibdata.curve2[i]=buff[4158+i];
165     calibdata.iCRC=buff[8254];
166     calibdata.tail=buff[8255];
167     calibdata.CRC=buff[8256];
168 kusanagi 2.8 if(check==calibdata.CRC)
169     calibdata.CRCcheck=TRUE;
170     else
171     calibdata.CRCcheck=FALSE;
172 kusanagi 2.3 }
173 kusanagi 2.1
174 kusanagi 2.2 unsigned char ACphysics(int length,unsigned char* datapointer,struct physicsstruct* physicspointer)
175 kusanagi 2.1 {
176    
177 kusanagi 2.5 err=0;
178     found=0;
179 kusanagi 2.8 check=0;
180 kusanagi 2.5 int iter=2;
181 kusanagi 2.10 for(i=0;i<8300;i++)
182 kusanagi 2.5 buffer[i]=0;
183     fillphys(0,&buffer[0]);
184     fillphys(1,&buffer[0]);
185    
186 kusanagi 2.2 //look for top header ACAC, then unpack data to main card buffer or extra card buffer depending on the subheader
187     //AC11 for main, AC22 for extra
188     while(found<2 && iter<length)
189 kusanagi 2.1 {
190     tmp1 = ((*datapointer) << 8) | *(datapointer+1);
191 kusanagi 2.2 tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);
192 kusanagi 2.4 if(tmp1 == 0xACAC && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xAC22 && (err&0x0F)==0x0)))
193 kusanagi 2.1 {
194     for(i=0;i<64;i++)
195     {
196     buffer[i]=((*datapointer) << 8) | *(datapointer+1);
197 kusanagi 2.8 if(i<63)
198     check=crc(check,buffer[i]);
199 kusanagi 2.1 datapointer=datapointer+2;
200     }
201 kusanagi 2.2 if(tmp2==0xAC11){ //main card
202     fillphys(0,&buffer[0]);
203     err |= 0xF0;
204     }
205     else{ //extra card
206     fillphys(1,&buffer[0]);
207     err |= 0x0F;
208     }
209     tmp1=tmp2=0x0000;
210 kusanagi 2.8 check=0x0;
211 kusanagi 2.2 found++;
212 kusanagi 2.1 }
213     else{
214     datapointer++;
215     iter=iter+1;}
216     }
217 kusanagi 2.6 //point struct-pointer to physicsdata
218     physicspointer[0]=physicsdata[0]; //card1
219     physicspointer[1]=physicsdata[1]; //card2
220    
221 kusanagi 2.1 return err;
222    
223     }
224    
225    
226 kusanagi 2.10 unsigned char ACcalib(int length, unsigned char* datapointer, struct calibstruct* calibpointer)
227 kusanagi 2.1 {
228    
229 kusanagi 2.5 err=0;
230     found=0;
231 kusanagi 2.8 check=0;
232 kusanagi 2.1 int iter=2;
233 kusanagi 2.10 for(i=0;i<8300;i++)
234 kusanagi 2.5 buffer[i]=0;
235 kusanagi 2.6 fillcalib(&buffer[0]);
236 kusanagi 2.5
237 kusanagi 2.2 //look for the top header 0xACCA, then the subheaders 0xAC11 and 0xAC22, and unpack the data
238     //to each card depending on these.
239 kusanagi 2.6 while(found<1 && iter<length)
240 kusanagi 2.1 {
241     tmp1 = ((*datapointer) << 8) | *(datapointer+1);
242 kusanagi 2.2 tmp2 = ((*(datapointer+2)) << 8) | *(datapointer+3);
243 kusanagi 2.8
244 kusanagi 2.5 if(tmp1 == 0xACCA && ((tmp2 == 0xAC11 && (err&0xF0)==0x0) || (tmp2 == 0xACA2 && (err&0x0F)==0x0)))
245 kusanagi 2.1 {
246 kusanagi 2.10 for(i=0;i<8257;i++)
247 kusanagi 2.1 {
248     buffer[i]=((*datapointer) << 8) | *(datapointer+1);
249 kusanagi 2.10 if(i<8256) //8257
250 kusanagi 2.8 check=crc(check,buffer[i]);
251 kusanagi 2.1 datapointer=datapointer+2;
252 kusanagi 2.8 }
253    
254 kusanagi 2.2 if(tmp2==0xAC11){ //main
255 kusanagi 2.6 fillcalib(&buffer[0]);
256 kusanagi 2.2 err |= 0xF0;
257     }
258     else{ //extra
259 kusanagi 2.6 fillcalib(&buffer[0]);
260 kusanagi 2.2 err |= 0x0F;
261 kusanagi 2.8 }
262     tmp1=tmp2=0x0000;
263 kusanagi 2.2 found++;
264 kusanagi 2.1 }
265     else{
266 kusanagi 2.2 datapointer++;
267     iter=iter+1;}
268 kusanagi 2.1 }
269 kusanagi 2.10 memcpy(calibpointer,&calibdata,sizeof(calibdata));
270    
271 kusanagi 2.1 return err;
272     }
273 kusanagi 2.8

  ViewVC Help
Powered by ViewVC 1.1.23