/** @file * $Source: /home/cvsmanager/yoda/techmodel/RunHeaderReader.cpp,v $ * $Id: RunHeaderReader.cpp,v 2.0 2004/09/21 20:50:54 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.0 2004/09/21 20:50:54 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) { 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){ RunHeader->RM_ACQ_SETTING_MODE = (BYTE)subData[0]; RunHeader->OBT_TIME_SYNC = (((UINT32)subData[1]<<24)&0xFF000000) + (((UINT32)subData[2]<<16)&0x00FF0000) + (((UINT32)subData[3]<<8)&0x0000FF00) + (((UINT32)subData[4])&0x000000FF); RunHeader->LAST_TYME_SYNC_INFO = (((UINT32)subData[5]<<24)&0xFF000000) + (((UINT32)subData[6]<<16)&0x00FF0000) + (((UINT32)subData[7]<<8)&0x0000FF00) + (((UINT32)subData[8])&0x000000FF); RunHeader->FAVOURITE_WORKING_SCHEDULE = (BYTE)subData[9]; RunHeader->EFFECTIVE_WORKING_SCHEDULE = (BYTE)subData[10]; RunHeader->PRH_VAR_TRIGGER_MODE_A = (((UINT32)subData[11]<<24)&0xFF000000) + (((UINT32)subData[12]<<16)&0x00FF0000) + (((UINT32)subData[13]<<8)&0x0000FF00) + (((UINT32)subData[14])&0x000000FF); RunHeader->PRH_VAR_TRIGGER_MODE_B = (((UINT32)subData[15]<<24)&0xFF000000) + (((UINT32)subData[16]<<16)&0x00FF0000) + (((UINT32)subData[17]<<8)&0x0000FF00) + (((UINT32)subData[18])&0x000000FF); RunHeader->RM_ACQ_AFTER_CALIB = (BYTE)subData[19]; } else { logger->warn(_T("Wrong CRC for RunHeader Packet ")); } }