/** @file * $Source: /home/cvsmanager/yoda/techmodel/VarDumpReader.cpp,v $ * $Id: VarDumpReader.cpp,v 2.1 2004/12/03 22:08:01 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the VarDumpReader class. */ #include #include #include #include "stdio.h" extern "C" { #include "CRC.h" } #include "ReaderAlgorithms.h" using namespace pamela; using namespace pamela::techmodel; static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.VarDumpReader")); /** * Constructor. */ VarDumpReader::VarDumpReader(void): TechmodelAlgorithm(PacketType::VarDump, "TechmodelVarDump") { VarDump = new VarDumpEvent(); } /** * Get a string with the version info of the algorithm. */ std::string VarDumpReader::GetVersionInfo(void) const { return "$Header: /home/cvsmanager/yoda/techmodel/VarDumpReader.cpp,v 2.1 2004/12/03 22:08:01 kusanagi Exp $\n"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void VarDumpReader::Init(PamelaRun *run) { SetInputStream(run); run->WriteSubPacket(this, &VarDump, VarDump->Class()); } /** * Unpack the VarDump event from an input file. */ void VarDumpReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ char *subData; char eventCRC[2]; UINT16 subCRC; //CRC of the data UINT16 readCRC; //CRC read from the end of the subpacket long int dataLength; int vars; //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) throw WrongCRCException(" Wrong CRC for VarDump Packet "); VarDumpRecord* rec; VarDump->Records->Clear(); TClonesArray &recs = *(VarDump->Records); vars = dataLength/5; for (int i=0; iVAR_ID = subData[i*5]; rec->VAR_VALUE = (((UINT32)subData[1+i*5]<<24)&0xFF000000) + (((UINT32)subData[2+i*5]<<16)&0x00FF0000) + (((UINT32)subData[3+i*5]<<8)&0x0000FF00) + (((UINT32)subData[4+i*5])&0x000000FF); } delete [] subData; }