/** @file * $Source: /home/cvspamela/yoda/techmodel/ArrDumpReader.cpp,v $ * $Id: ArrDumpReader.cpp,v 1.7 2004/05/11 10:12:35 nagni Exp $ * $Author: nagni $ * * Implementation of the ArrDumpReader class. */ #include #include #include #include "stdio.h" extern "C" { #include "CRC.h" } #include "ReaderAlgorithms.h" using namespace pamela; using namespace pamela::techmodel; static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.ArrDumpReader"); /** * Constructor. */ ArrDumpReader::ArrDumpReader(void): TechmodelAlgorithm(PacketType::ArrDump, "TechmodelArrDump") { ArrDump = new ArrDumpEvent(); } /** * Get a string with the version info of the algorithm. */ std::string ArrDumpReader::GetVersionInfo(void) const { return "$Header: /home/cvspamela/yoda/techmodel/ArrDumpReader.cpp,v 1.7 2004/05/11 10:12:35 nagni Exp $\n"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void ArrDumpReader::Init(PamelaRun *run) { SetInputStream(run); run->WriteSubPacket(this, &ArrDump, ArrDump->Class()); } /** * Unpack the ArrDump event from an input file. */ void ArrDumpReader::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; //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)) { cat << log4cpp::Priority::ERROR << "The test of calculated CRC with one wrote on file FAILED!!" << "\n " << log4cpp::CategoryStream::ENDLINE; } //finally check if the RecordCRC is correct and finally update the partialCRC if (subCRC == readCRC){ /**************************************************************************** ---------------------TBD read the data--------------------------- ****************************************************************************/ free(subData); } else { cat << log4cpp::Priority::ERROR << "Wrong CRC on Subpacket in ArrDump Packet " << "\n " << log4cpp::CategoryStream::ENDLINE; } }