--- yoda/techmodel/forroutines/anticounter/AC.c 2004/10/17 12:42:54 2.1 +++ yoda/techmodel/forroutines/anticounter/AC.c 2005/01/03 14:20:11 2.6 @@ -1,180 +1,172 @@ -/***************************************************************** -Function to read AC physics data v1.1 +/*******************************v1.1******************************** + +Functions to read AC physics data (ACphysics) and AC calibration +data (ACcalib). Author: Petter Hofverberg, petter@particle.kth.se -0408 v1.0 alive -0409 Added shifting operators to fix problem with odd data (BBAC|11DD) - ----- +0410 v1.0 alive +0412 v1.1 fixed problem with found, and changed headers + Errors: (returned to the main program as the variable "err") err= -0 - Ok -1 - Data found, but corrupt -2 - Data dont found in buffer +0xFF - data (physics or calibration) from both cards found +0xF0 - only data from main card found +0x0F - only data from extra card found +0x00 - no data found -ToDo: i) do it endian-independent - ii) check for more events in the same file? ******************************************************************/ #include #include "AC.h" -int i,err,found,j; -//unsigned short buffer[1000]; -//unsigned short tmp1,tmp2; +int i,j,found; unsigned short buffer[1000]; -unsigned short tmp1; +unsigned short tmp1,tmp2; +unsigned char err; -struct physicsstruct physicsdata; +struct physicsstruct physicsdata[2]; struct physicsstruct *physicspointer; struct calibstruct calibdata; struct calibstruct *calibpointer; - -//int ACphysics(int length,unsigned short* datapointer,struct physicsstruct* physicspointer) -int ACphysics(int length,unsigned char* datapointer,struct physicsstruct* physicspointer) +//Fill physicsdata from buffer +void fillphys(int k,unsigned short *buff) { + for(i=0;i<2;i++) physicsdata[k].header[i]=buff[i]; + physicsdata[k].status=buff[2]; + physicsdata[k].hitmap=buff[3]; + for(i=0;i<6;i++) physicsdata[k].regist[i]=buff[4+i]; + for(i=0;i<16;i++) physicsdata[k].shift[i]=buff[10+i]; + for(i=0;i<16;i++) physicsdata[k].counters[i]=buff[26+i]; + for(i=0;i<8;i++) physicsdata[k].coinc[i]=buff[42+i]; + physicsdata[k].trigg=buff[50]; + for(i=0;i<2;i++) physicsdata[k].clock[i]=buff[51+i]; + for(i=0;i<2;i++) physicsdata[k].temp[i]=buff[53+i]; + for(i=0;i<8;i++) physicsdata[k].DAC[i]=buff[55+i]; + physicsdata[k].CRC=buff[63]; - int iter=2; +} - *physicspointer=physicsdata; +//Fill calibdata from buffer +void fillcalib(unsigned short *buff) +{ + for(i=0;i<2;i++) calibdata.header[i]=buff[i]; + for(i=0;i<5;i++) calibdata.status[i]=buff[2+i]; + for(i=0;i<8;i++) calibdata.temp[i]=buff[7+i]; + for(i=0;i<8;i++) calibdata.DAC1[i]=buff[15+i]; + for(i=0;i<8;i++) calibdata.DAC2[i]=buff[23+i]; + for(i=0;i<6;i++) calibdata.regist[i]=buff[31+i]; + for(i=0;i<8;i++) calibdata.time[i]=buff[37+i]; + calibdata.n_tr=buff[45]; + for(i=0;i<16;i++) calibdata.hitmap_tr[i]=buff[46+i]; + for(i=0;i<4096;i++) calibdata.curve1[i]=buff[62+i]; + for(i=0;i<4096;i++) calibdata.curve2[i]=buff[4158+i]; + calibdata.iCRC=buff[8254]; + calibdata.tail=buff[8255]; + calibdata.CRC=buff[8256]; + //printf("tail:CRC > %hx:%hx\n",buff[8255],buff[8256]); +} - //look for header AC11, then cut out the event to a temp buffer - while(found==0 && iter> 8); - return temp; -}