--- yoda/techmodel/CalibCalPulse1Reader.cpp 2004/08/24 16:01:57 1.3 +++ yoda/techmodel/CalibCalPulse1Reader.cpp 2006/02/07 17:11:09 6.0 @@ -5,23 +5,19 @@ #define UINT unsigned int #define BYTE unsigned char #include -#include +#include extern "C" { #include "CRC.h" //Struct per il passaggio di dati da e verso la chiamata fortran extern struct { - int IEV2; - int calped[4][11][96]; - int calgood[4][11][96]; - int calthr[4][11][6]; - int calrms[4][11][96]; - int calbase[4][11][6]; - int calvar[4][11][6]; - int calpuls[4][11][96]; - } calib_; + int iev; + int pstwerr[4]; + float pperror[4]; + float calpuls[4][11][96]; + } calpul_; //external declaration of the Fortran function - void calpulse_(short[], long int*, int*); + void calpulse_(char*, long int*, int*); } #include @@ -33,16 +29,14 @@ using namespace pamela; using namespace pamela::techmodel; -static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPulse1Reader"); +static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibCalPulse1Reader")); /** * Constructor. */ CalibCalPulse1Reader::CalibCalPulse1Reader(void): TechmodelAlgorithm(PacketType::CalibCalPulse1, "TechmodelCalibCalPulse1Reader") { - cat << log4cpp::Priority::DEBUG - << "Constructor " - << "\n " << log4cpp::CategoryStream::ENDLINE; + logger->debug(_T("Constructor")); calibCalPulse1 = new CalibCalPulse1Event(); } @@ -51,7 +45,7 @@ */ std::string CalibCalPulse1Reader::GetVersionInfo(void) const { return - "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse1Reader.cpp,v 1.2 2004/08/20 15:01:41 kusanagi Exp $\n"; + "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse1Reader.cpp,v 5.1 2006/02/04 12:37:44 kusanagi Exp $\n"; } /** @@ -59,6 +53,7 @@ * event reader routines for all packet types. */ void CalibCalPulse1Reader::Init(PamelaRun *run) { + logger->debug(_T("Initialize")); SetInputStream(run); run->WriteSubPacket(this, &calibCalPulse1, calibCalPulse1->Class()); } @@ -66,81 +61,40 @@ /** * Unpack the CalibCalPulse1 event from an input file. */ -void CalibCalPulse1Reader::RunEvent(int EventNumber, long int length) { - - char *packetData; - char CRCevent[2]; - UINT16 calculatedCRC = 0; //calculated CRC - UINT16 readCRC = 0; //read CRC - long int dataLength; +void CalibCalPulse1Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){ + std::stringstream oss; + char packetData[dataLength]; int ERROR; - - dataLength = length - 2; - packetData = new char[dataLength]; 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); + calpulse_(packetData, &dataLength, &ERROR); - if (calculatedCRC == readCRC) { - calpulse_((short*)packetData, &dataLength, &ERROR); - if (ERROR != 0) { - char *errmsg; - switch (ERROR){ - case 1: errmsg = "CALORIMETER NOT FOUND"; - } - cat << log4cpp::Priority::ERROR - << "Fortran77 function calpulse error code = " << ERROR - << errmsg - << "\n " << log4cpp::CategoryStream::ENDLINE; - } else { - //Store the unpacked data - calibCalPulse1->IEV2 = calib_.IEV2; - //--------have to invert array because of FORTRAN <-> C different management of the indexes - int tempCalped[96][11][4]; - int tempCalgood[96][11][4]; - int tempCalthr[6][11][4]; - int tempCalrms[96][11][4]; - int tempCalbase[6][11][4]; - int tempCalvar[6][11][4]; - int tempCalpuls[96][11][4]; - - memcpy(tempCalped, calib_.calped, sizeof(tempCalped)); - memcpy(tempCalgood, calib_.calgood, sizeof(tempCalgood)); - memcpy(tempCalthr, calib_.calthr, sizeof(tempCalthr)); - memcpy(tempCalrms, calib_.calrms, sizeof(tempCalrms)); - memcpy(tempCalbase, calib_.calbase, sizeof(tempCalbase)); - memcpy(tempCalvar, calib_.calvar, sizeof(tempCalvar)); - memcpy(tempCalpuls, calib_.calpuls, sizeof(tempCalpuls)); - - for (int i = 0; i < 4; i++){ - for (int j = 0; j <11; j++){ - for (int z = 0; z < 96; z++){ - calibCalPulse1->calped[i][j][z] = tempCalped[z][j][i]; - calibCalPulse1->calgood[i][j][z] = tempCalgood[z][j][i]; - calibCalPulse1->calrms[i][j][z] = tempCalrms[z][j][i]; - calibCalPulse1->calpuls[i][j][z] = tempCalpuls[z][j][i]; - } - } - } - - for (int i = 0; i < 4; i++){ - for (int j = 0; j <11; j++){ - for (int z = 0; z < 6; z++){ - calibCalPulse1->calthr[i][j][z] = tempCalthr[z][j][i]; - calibCalPulse1->calbase[i][j][z] = tempCalbase[z][j][i]; - calibCalPulse1->calvar[i][j][z] = tempCalvar[z][j][i]; - } + calibCalPulse1->unpackError = ERROR; + oss.str(""); + if (ERROR != 0) { + char *errmsg; + switch (ERROR){ + case 1: errmsg = "CALORIMETER NOT FOUND"; + } + oss << "Fortran77 function calpulse error code = " << ERROR + << " " << errmsg; + logger->warn(oss.str().c_str()); + } //else { + //Store the unpacked data + calibCalPulse1->iev = calpul_.iev; + memcpy(calibCalPulse1->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse1->pstwerr)); + memcpy(calibCalPulse1->pperror, calpul_.pperror, sizeof(calibCalPulse1->pperror)); + //--------have to invert array because of FORTRAN <-> C different management of the indexes + float tempCalpuls[96][11][4]; + memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls)); + for (int i = 0; i < 4; i++){ + for (int j = 0; j <11; j++){ + for (int z = 0; z < 96; z++){ + calibCalPulse1->calpuls[i][j][z] = tempCalpuls[z][j][i]; } } - //----------------------------------------------------------------------------------------- } - } else { - cat << log4cpp::Priority::ERROR - << "The test of calculated CRC with one wrote on file FAILED!!" - << "\n " << log4cpp::CategoryStream::ENDLINE; - } - delete [] packetData; + //----------------------------------------------------------------------------------------- + //} }