1 |
/** @file |
/** @file |
2 |
* $Source: /home/cvsmanager/yoda/techmodel/CalibCalPedReader.cpp,v $ |
* $Source: /home/cvsmanager/yoda/techmodel/CalibCalPedReader.cpp,v $ |
3 |
* $Id: CalibCalPedReader.cpp,v 1.1 2004/07/06 14:07:27 kusanagi Exp $ |
* $Id: CalibCalPedReader.cpp,v 1.2 2004/07/08 12:31:42 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
5 |
* |
* |
6 |
* Implementation of the LogReader class. |
* Implementation of the LogReader class. |
15 |
#include <fstream> |
#include <fstream> |
16 |
#include "stdio.h" |
#include "stdio.h" |
17 |
extern "C" { |
extern "C" { |
18 |
|
#include "CRC.h" |
19 |
//Struct per il passaggio di dati da e verso la chiamata fortran |
//Struct per il passaggio di dati da e verso la chiamata fortran |
20 |
extern struct { |
extern struct { |
21 |
int IEV2; |
int IEV2; |
29 |
} calib_; |
} calib_; |
30 |
|
|
31 |
//external declaration of the Fortran function |
//external declaration of the Fortran function |
32 |
// void calpedestal_(short[], int, int*); |
void calpedestal_(short[], int, int*); |
33 |
} |
} |
34 |
|
|
35 |
#include "ReaderAlgorithms.h" |
#include "ReaderAlgorithms.h" |
48 |
cat << log4cpp::Priority::DEBUG |
cat << log4cpp::Priority::DEBUG |
49 |
<< "Constructor " |
<< "Constructor " |
50 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
51 |
CalibCalPed = new CalibCalPedEvent(); |
calibCalPed = new CalibCalPedEvent(); |
52 |
} |
} |
53 |
|
|
54 |
/** |
/** |
56 |
*/ |
*/ |
57 |
std::string CalibCalPedReader::GetVersionInfo(void) const { |
std::string CalibCalPedReader::GetVersionInfo(void) const { |
58 |
return |
return |
59 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPedReader.cpp,v 1.1 2004/07/06 14:07:27 kusanagi Exp $\n"; |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPedReader.cpp,v 1.2 2004/07/08 12:31:42 kusanagi Exp $\n"; |
60 |
} |
} |
61 |
|
|
62 |
/** |
/** |
65 |
*/ |
*/ |
66 |
void CalibCalPedReader::Init(PamelaRun *run) { |
void CalibCalPedReader::Init(PamelaRun *run) { |
67 |
SetInputStream(run); |
SetInputStream(run); |
68 |
run->WriteSubPacket(this, &CalibCalPed, CalibCalPed->Class()); |
run->WriteSubPacket(this, &calibCalPed, calibCalPed->Class()); |
69 |
} |
} |
70 |
|
|
71 |
/** |
/** |
73 |
*/ |
*/ |
74 |
void CalibCalPedReader::RunEvent(int EventNumber, long int length) { |
void CalibCalPedReader::RunEvent(int EventNumber, long int length) { |
75 |
|
|
76 |
char *subData; |
char packetData[length-2]; |
77 |
long int dataLength; |
char CRCevent[2]; |
78 |
int ERROR; |
UINT16 calculatedCRC = 0; //calculated CRC |
79 |
|
UINT16 readCRC = 0; //read CRC |
80 |
//the 2 bytes subtracted belong to the final event CRC bytes |
long int dataLength; |
81 |
dataLength = length - (long int)2; |
int ERROR; |
82 |
|
|
83 |
subData = new char[dataLength]; |
dataLength = length - 2; |
84 |
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
InputFile->read(packetData, sizeof(packetData)); |
85 |
|
InputFile->read(CRCevent, sizeof(CRCevent)); |
86 |
//Skip the last two crc bytes already checked in UnpackPscu |
|
87 |
//This part have to be refactored!!!! too bad...... |
calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength); |
88 |
InputFile->seekg((long int)2, std::ios::cur); |
readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF); |
89 |
|
|
90 |
//Chiamata alla funzione fortran per la lettura dei piedistalli |
if (calculatedCRC == readCRC) { |
91 |
// calpedestal_((short*)subData, dataLength, &ERROR); |
calpedestal_((short*)packetData, dataLength, &ERROR); |
92 |
cat << log4cpp::Priority::ERROR |
//Store the unpacked data |
93 |
<< "Fortran77 function calpedestal error code = " << ERROR |
calibCalPed->IEV2 = calib_.IEV2; |
94 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
memcpy(calibCalPed->calped, calib_.calped, sizeof(calibCalPed->calped)); |
95 |
free(subData); |
memcpy(calibCalPed->calgood, calib_.calgood, sizeof(calibCalPed->calgood)); |
96 |
} |
memcpy(calibCalPed->calthr, calib_.calthr, sizeof(calibCalPed->calthr)); |
97 |
|
memcpy(calibCalPed->calrms, calib_.calrms, sizeof(calibCalPed->calrms)); |
98 |
|
memcpy(calibCalPed->calbase, calib_.calbase, sizeof(calibCalPed->calbase)); |
99 |
|
memcpy(calibCalPed->calvar, calib_.calvar, sizeof(calibCalPed->calvar)); |
100 |
|
memcpy(calibCalPed->calpuls, calib_.calpuls, sizeof(calibCalPed->calpuls)); |
101 |
|
|
102 |
|
cat << log4cpp::Priority::ERROR |
103 |
|
<< "Fortran77 function calpedestal error code = " << ERROR |
104 |
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
105 |
|
} else { |
106 |
|
cat << log4cpp::Priority::ERROR |
107 |
|
<< "The test of calculated CRC with one wrote on file FAILED!!" |
108 |
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
109 |
|
} |
110 |
|
free(packetData); |
111 |
|
} |
112 |
|
|
113 |
|
|