/** @file * $Source: /home/cvsmanager/yoda/techmodel/TabDumpReader.cpp,v $ * $Id: TabDumpReader.cpp,v 2.3 2005/03/03 13:02:54 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the TabDumpReader 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.TabDumpReader")); /** * Constructor. */ TabDumpReader::TabDumpReader(void): TechmodelAlgorithm(PacketType::TabDump, "TechmodelTabDump") { TabDump = new TabDumpEvent(); logger->debug(_T("Constructor")); } /** * Get a string with the version info of the algorithm. */ std::string TabDumpReader::GetVersionInfo(void) const { return "$Header: /home/cvsmanager/yoda/techmodel/TabDumpReader.cpp,v 2.3 2005/03/03 13:02:54 kusanagi Exp $\n"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void TabDumpReader::Init(PamelaRun *run) { SetInputStream(run); run->WriteSubPacket(this, &TabDump, TabDump->Class()); logger->debug(_T("Initialize")); } /** * Unpack the TabDump event from an input file. */ void TabDumpReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ char subData[length]; char eventCRC[2]; UINT16 subCRC; //CRC of the data UINT16 readCRC; //CRC read from the end of the subpacket long int dataLength = length - 2; InputFile->read(subData, sizeof(unsigned char)*length); subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF); //if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for TabDump Packet "); if (subCRC != readCRC) { logger->error(" Wrong CRC for TabDump Packet but I process it anyway"); } TabDumpRecord* rec; TabDump->PARAMETER_STAMP = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF); long int offset = 4; int i = 0; int size; TabDump->Records->Clear(); TClonesArray &recs = *(TabDump->Records); while (offset < dataLength){ rec = new(recs[i++]) TabDumpRecord(); //add a new TabDump rec->Tab_ID = ((UINT8)subData[offset])&0xFF; rec->Nrow = ((UINT8)subData[offset+1])&0xFF; rec->Ncol = ((UINT8)subData[offset+2])&0xFF; //rec->Data = new UINT32[(rec->Nrow)*(rec->Ncol)]; size = sizeof(UINT32)*(rec->Nrow)*(rec->Ncol); rec->Data = new TArrayI((int)((rec->Nrow)*(rec->Ncol)), (int*)(subData+offset+3)); //memcpy(rec->Data, (UINT32*)(subData+offset+3), size); offset = offset + size + 3; } //delete [] subData; }