--- yoda/techmodel/InitHeaderReader.cpp 2004/09/21 20:24:33 1.2 +++ yoda/techmodel/InitHeaderReader.cpp 2006/05/30 19:10:03 6.2 @@ -1,23 +1,13 @@ +/** @file + * $Author: kusanagi $ + * $Date: 2006/05/30 19:10:02 $ + * $Revision: 6.1 $ + * + * Implementation of the InitHeaderReader class. + */ -// Implementation of the InitHeaderReader class. - - -#define UINT unsigned int -#define BYTE unsigned char -#include -#include -extern "C" { -#include -#include "CRC.h" -} - -#include -#include "stdio.h" #include "ReaderAlgorithms.h" -#include "event/InitHeaderEvent.h" - -using namespace pamela; using namespace pamela::techmodel; static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.InitHeaderReader")); @@ -36,12 +26,14 @@ */ std::string InitHeaderReader::GetVersionInfo(void) const { return - "$Header: /home/cvsmanager/yoda/techmodel/InitHeaderReader.cpp,v 1.1 2004/08/19 15:24:46 kusanagi Exp $\n"; + "$Header: /home/cvsmanager/yoda/techmodel/InitHeaderReader.cpp,v 6.1 2006/05/30 19:10:02 kusanagi Exp $\n"; } /** - * Initialize the algorithm with a special run. This will initialize the + Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. + * + * @param run */ void InitHeaderReader::Init(PamelaRun *run) { logger->debug(_T("Initialize")); @@ -49,12 +41,24 @@ run->WriteSubPacket(this, &initHeader, initHeader->Class()); } + /** * Unpack the InitHeader event from an input file. + * @param EventNumber + * @param dataLength */ -void InitHeaderReader::RunEvent(int EventNumber, long int length) { - - - +void InitHeaderReader::RunEvent(int EventNumber, long int dataLength) throw (WrongCRCException){ + + char subData[dataLength]; + UINT16 subCRC; //calculated CRC of the data + UINT16 readCRC; //CRC read from the end of the subpacket + long int length = dataLength - 2; //the block of data + + InputFile->read(subData, sizeof(subData)); + subCRC = CM_Compute_CRC16(0, (UINT8*)subData, length); + readCRC = (((UINT16)(subData[dataLength - 2]<<8))&0xFF00) + (((UINT16)subData[dataLength - 1])&0x00FF); + + if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for InitHeader Packet "); + initHeader->initHeaderData = new TArrayC(length, subData); }