/** @file * $Source: /home/cvsmanager/yoda/techmodel/CalibCalPedReader.cpp,v $ * $Id: CalibCalPedReader.cpp,v 1.2 2004/07/08 12:31:42 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the LogReader class. * ToBeDone: * Control the CRC for the entire data Packet not just for single records */ //#define UINT unsigned int #define BYTE unsigned char #include #include #include #include "stdio.h" extern "C" { #include "CRC.h" //Struct per il passaggio di dati da e verso la chiamata fortran extern struct { int IEV2; int calped[96][11][4]; int calgood[96][11][4]; int calthr[96][11][4]; int calrms[96][11][4]; int calbase[96][11][4]; int calvar[96][11][4]; int calpuls[96][11][4]; } calib_; //external declaration of the Fortran function void calpedestal_(short[], int, int*); } #include "ReaderAlgorithms.h" #include "event/CalibCalPedEvent.h" using namespace pamela; using namespace pamela::techmodel; static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPedReader"); /** * Constructor. */ CalibCalPedReader::CalibCalPedReader(void): TechmodelAlgorithm(PacketType::Log, "TechmodelCalibCalPedReader") { cat << log4cpp::Priority::DEBUG << "Constructor " << "\n " << log4cpp::CategoryStream::ENDLINE; calibCalPed = new CalibCalPedEvent(); } /** * Get a string with the version info of the algorithm. */ std::string CalibCalPedReader::GetVersionInfo(void) const { return "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPedReader.cpp,v 1.2 2004/07/08 12:31:42 kusanagi Exp $\n"; } /** * Initialize the algorithm with a special run. This will initialize the * event reader routines for all packet types. */ void CalibCalPedReader::Init(PamelaRun *run) { SetInputStream(run); run->WriteSubPacket(this, &calibCalPed, calibCalPed->Class()); } /** * Unpack the CalibCalPed event from an input file. */ void CalibCalPedReader::RunEvent(int EventNumber, long int length) { char packetData[length-2]; char CRCevent[2]; UINT16 calculatedCRC = 0; //calculated CRC UINT16 readCRC = 0; //read CRC long int dataLength; int ERROR; dataLength = length - 2; InputFile->read(packetData, sizeof(packetData)); InputFile->read(CRCevent, sizeof(CRCevent)); calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength); readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF); if (calculatedCRC == readCRC) { calpedestal_((short*)packetData, dataLength, &ERROR); //Store the unpacked data calibCalPed->IEV2 = calib_.IEV2; memcpy(calibCalPed->calped, calib_.calped, sizeof(calibCalPed->calped)); memcpy(calibCalPed->calgood, calib_.calgood, sizeof(calibCalPed->calgood)); memcpy(calibCalPed->calthr, calib_.calthr, sizeof(calibCalPed->calthr)); memcpy(calibCalPed->calrms, calib_.calrms, sizeof(calibCalPed->calrms)); memcpy(calibCalPed->calbase, calib_.calbase, sizeof(calibCalPed->calbase)); memcpy(calibCalPed->calvar, calib_.calvar, sizeof(calibCalPed->calvar)); memcpy(calibCalPed->calpuls, calib_.calpuls, sizeof(calibCalPed->calpuls)); cat << log4cpp::Priority::ERROR << "Fortran77 function calpedestal error code = " << ERROR << "\n " << log4cpp::CategoryStream::ENDLINE; } else { cat << log4cpp::Priority::ERROR << "The test of calculated CRC with one wrote on file FAILED!!" << "\n " << log4cpp::CategoryStream::ENDLINE; } free(packetData); }