/** @file * $Source: /home/cvsmanager/yoda/techmodel/RunHeaderReader.cpp,v $ * $Id: RunHeaderReader.cpp,v 2.1 2004/10/17 12:28:38 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the RunHeader 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/RunHeaderEvent.h" using namespace pamela; using namespace pamela::techmodel; static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.RunHeaderReader")); /** * Constructor. */ RunHeaderReader::RunHeaderReader(void): TechmodelAlgorithm(PacketType::Log, "TechmodelRunHeaderReader") { logger->debug(_T("Constructor")); RunHeader = new RunHeaderEvent(); } /** * Get a string with the version info of the algorithm. */ std::string RunHeaderReader::GetVersionInfo(void) const { return "$Header: /home/cvsmanager/yoda/techmodel/RunHeaderReader.cpp,v 2.1 2004/10/17 12:28:38 kusanagi Exp $\n"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void RunHeaderReader::Init(PamelaRun *run) { SetInputStream(run); run->WriteSubPacket(this, &RunHeader, RunHeader->Class()); logger->debug(_T("Initialize")); } /** * Unpack the RunHeader event from an input file. */ void RunHeaderReader::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; //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 RunHeader Packet "); RunHeader->COMPILATIONTIMESTAMP = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF); RunHeader->RM_ACQ_SETTING_MODE = (BYTE)subData[4]; RunHeader->OBT_TIME_SYNC = (((UINT32)subData[5]<<24)&0xFF000000) + (((UINT32)subData[6]<<16)&0x00FF0000) + (((UINT32)subData[7]<<8)&0x0000FF00) + (((UINT32)subData[8])&0x000000FF); RunHeader->LAST_TYME_SYNC_INFO = (((UINT32)subData[9]<<24)&0xFF000000) + (((UINT32)subData[10]<<16)&0x00FF0000) + (((UINT32)subData[11]<<8)&0x0000FF00) + (((UINT32)subData[12])&0x000000FF); RunHeader->FAVOURITE_WORKING_SCHEDULE = (BYTE)subData[13]; RunHeader->EFFECTIVE_WORKING_SCHEDULE = (BYTE)subData[14]; RunHeader->PRH_VAR_TRIGGER_MODE_A = (((UINT32)subData[15]<<24)&0xFF000000) + (((UINT32)subData[16]<<16)&0x00FF0000) + (((UINT32)subData[17]<<8)&0x0000FF00) + (((UINT32)subData[18])&0x000000FF); RunHeader->PRH_VAR_TRIGGER_MODE_B = (((UINT32)subData[19]<<24)&0xFF000000) + (((UINT32)subData[20]<<16)&0x00FF0000) + (((UINT32)subData[21]<<8)&0x0000FF00) + (((UINT32)subData[22])&0x000000FF); RunHeader->RM_ACQ_AFTER_CALIB = (BYTE)subData[23]; }