| 1 |
/***************************************************************** |
| 2 |
Function to read AC physics data v1.1 |
| 3 |
Author: Petter Hofverberg, petter@particle.kth.se |
| 4 |
|
| 5 |
0408 v1.0 alive |
| 6 |
0409 Added shifting operators to fix problem with odd data (BBAC|11DD) |
| 7 |
----- |
| 8 |
Errors: (returned to the main program as the variable "err") |
| 9 |
err= |
| 10 |
0 - Ok |
| 11 |
1 - Data found, but corrupt |
| 12 |
2 - Data dont found in buffer |
| 13 |
|
| 14 |
ToDo: i) do it endian-independent |
| 15 |
ii) check for more events in the same file? |
| 16 |
******************************************************************/ |
| 17 |
|
| 18 |
#include <stdio.h> |
| 19 |
#include "AC.h" |
| 20 |
int i,err,found,j; |
| 21 |
|
| 22 |
int ACphysics(int length,unsigned short* datapointer,struct physicsstruct* physicspointer) |
| 23 |
{ |
| 24 |
int iter=2; |
| 25 |
|
| 26 |
*physicspointer=physicsdata; |
| 27 |
|
| 28 |
//look for header AC11, then cut out the event to a temp buffer |
| 29 |
while(found==0 && iter<length) |
| 30 |
{ |
| 31 |
tmp1=*datapointer; |
| 32 |
tmp2=*(datapointer+1); |
| 33 |
|
| 34 |
if(tmp1==0x11AC) |
| 35 |
//if(tmp1==0xAC11) //flipped |
| 36 |
{ |
| 37 |
found=1; |
| 38 |
for(i=0;i<64;i++) |
| 39 |
{ |
| 40 |
buffer[i]=flip(*datapointer); |
| 41 |
datapointer++; |
| 42 |
} |
| 43 |
tmp1=0x0000; |
| 44 |
} |
| 45 |
else if(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 ) == 0x11AC) |
| 46 |
//else if((tmp1&0x00FF) + (tmp2&0xFF00)==0xAC11) //flipped |
| 47 |
{ |
| 48 |
found=1; |
| 49 |
for(i=0;i<64;i++) |
| 50 |
{ |
| 51 |
buffer[i]=flip(((tmp1&0xFF00) >> 8 ) + ((tmp2&0x00FF) << 8 )); |
| 52 |
//buffer[i]=(tmp1&0x00FF) + (tmp2&0xFF00); //flipped |
| 53 |
datapointer++; |
| 54 |
tmp1=tmp2; |
| 55 |
tmp2=*(datapointer+1); |
| 56 |
} |
| 57 |
} |
| 58 |
else{ |
| 59 |
datapointer++; |
| 60 |
iter=iter+2;} |
| 61 |
} |
| 62 |
|
| 63 |
//check errors |
| 64 |
if(found==0) |
| 65 |
err=2; |
| 66 |
else if(buffer[1]==0x22AC || buffer[1]==0xAC22) |
| 67 |
err=0; |
| 68 |
else |
| 69 |
err=1; |
| 70 |
|
| 71 |
//Fill physicsdata from buffer |
| 72 |
for(i=0;i<2;i++) physicsdata.header[i]=buffer[i]; |
| 73 |
physicsdata.status=buffer[2]; |
| 74 |
physicsdata.hitmap=buffer[3]; |
| 75 |
for(i=0;i<6;i++) physicsdata.regist[i]=buffer[4+i]; |
| 76 |
for(i=0;i<16;i++) physicsdata.shift[i]=buffer[10+i]; |
| 77 |
for(i=0;i<16;i++) physicsdata.counters[i]=buffer[26+i]; |
| 78 |
for(i=0;i<8;i++) physicsdata.coinc[i]=buffer[42+i]; |
| 79 |
physicsdata.trigg=buffer[50]; |
| 80 |
for(i=0;i<2;i++) physicsdata.clock[i]=buffer[51+i]; |
| 81 |
for(i=0;i<2;i++) physicsdata.temp[i]=buffer[53+i]; |
| 82 |
for(i=0;i<8;i++) physicsdata.DAC[i]=buffer[55+i]; |
| 83 |
physicsdata.CRC=buffer[63]; |
| 84 |
|
| 85 |
return err; |
| 86 |
|
| 87 |
} |
| 88 |
|