--- yoda/techmodel/CalibAcReader.cpp 2004/09/21 20:50:54 2.0 +++ yoda/techmodel/CalibAcReader.cpp 2004/12/03 22:08:00 2.2 @@ -1,6 +1,6 @@ /** @file * $Source: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v $ - * $Id: CalibAcReader.cpp,v 1.5 2004/09/21 20:24:33 kusanagi Exp $ + * $Id: CalibAcReader.cpp,v 2.1 2004/10/17 12:28:38 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the ArrDumpReader class. @@ -12,8 +12,8 @@ #include "stdio.h" extern "C" { #include "CRC.h" - #include "forroutines/anticounter/ACcalib.h" - extern int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer); + #include "forroutines/anticounter/AC.h" + extern int ACcalib(int length, unsigned char* calibpointer, struct calibstruct* calibpointer); } #include "ReaderAlgorithms.h" @@ -36,7 +36,7 @@ * Get a string with the version info of the algorithm. */ std::string CalibAcReader::GetVersionInfo(void) const { - return "$Header: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v 1.5 2004/09/21 20:24:33 kusanagi Exp $\n"; + return "$Header: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v 2.1 2004/10/17 12:28:38 kusanagi Exp $\n"; } /** @@ -52,45 +52,30 @@ /** * Unpack the CalibAc event from an input file. */ -void CalibAcReader::RunEvent(int EventNumber, long int length) { - char *subData; - char eventCRC[2]; - UINT16 subCRC; //CRC of the data - UINT16 readCRC; //CRC read from the end of the subpacket - long int dataLength; +void CalibAcReader::RunEvent(int EventNumber, long int dataLength) throw (Exception){ + char subData[dataLength]; + InputFile->read(subData, sizeof(unsigned char)*dataLength); - //the 2 bytes subtracted belong to the final event CRC bytes - dataLength = length - (long int)2; - - subData = new char[dataLength]; - InputFile->read(subData, sizeof(unsigned char)*dataLength); - subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); - - //took the final CRC to compare it with the previous calculated CRC of the data - InputFile->read(eventCRC, sizeof(eventCRC)); - readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); - - if (subCRC == readCRC){ - datastruct output; - int ERROR; - ERROR = ACcalib(dataLength, (unsigned short*)subData, &output); - - CalibAc->header = output.header; - memcpy(CalibAc->status, output.status, sizeof(CalibAc->status)); - memcpy(CalibAc->temp, output.temp, sizeof(CalibAc->temp)); - memcpy(CalibAc->DAC1, output.DAC1, sizeof(CalibAc->DAC1)); - memcpy(CalibAc->DAC2, output.DAC2, sizeof(CalibAc->DAC2)); - memcpy(CalibAc->regist, output.regist, sizeof(CalibAc->regist)); - memcpy(CalibAc->time, output.time, sizeof(CalibAc->time)); - CalibAc->n_tr = output.n_tr; - memcpy(CalibAc->hitmap_tr, output.hitmap_tr, sizeof(CalibAc->hitmap_tr)); - memcpy(CalibAc->curve1, output.curve1, sizeof(CalibAc->curve1)); - memcpy(CalibAc->curve2, output.curve2, sizeof(CalibAc->curve2)); - CalibAc->iCRC = output.iCRC; - CalibAc->tail = output.tail; - CalibAc->CRC = output.CRC; - } else { - logger->warn(_T("Wrong CRC on Subpacket in ArrDump Packet ")); + struct calibstruct output[2]; + int ERROR; + CalibAc->ERROR = ACcalib(dataLength, (unsigned char*)subData, &(*output)); + + for (int i = 0; i<2; i++){ + CalibAc->header[i] = output[i].header; + memcpy(CalibAc->status[i], output[i].status, sizeof(output[i].status)); + memcpy(CalibAc->temp[i], output[i].temp, sizeof(output[i].temp)); + memcpy(CalibAc->DAC1[i], output[i].DAC1, sizeof(output[i].DAC1)); + memcpy(CalibAc->DAC2[i], output[i].DAC2, sizeof(output[i].DAC2)); + memcpy(CalibAc->regist[i], output[i].regist, sizeof(output[i].regist)); + memcpy(CalibAc->time[i], output[i].time, sizeof(output[i].time)); + CalibAc->n_tr[i] = output[i].n_tr; + memcpy(CalibAc->hitmap_tr[i], output[i].hitmap_tr, sizeof(output[i].hitmap_tr)); + memcpy(CalibAc->curve1[i], output[i].curve1, sizeof(output[i].curve1)); + memcpy(CalibAc->curve2[i], output[i].curve2, sizeof(output[i].curve2)); + CalibAc->iCRC[i] = output[i].iCRC; + CalibAc->tail[i] = output[i].tail; + CalibAc->CRC[i] = output[i].CRC; } + delete [] subData; }