10 |
#include "CRC.h" |
#include "CRC.h" |
11 |
//Struct per il passaggio di dati da e verso la chiamata fortran |
//Struct per il passaggio di dati da e verso la chiamata fortran |
12 |
extern struct { |
extern struct { |
13 |
int IEV2; |
int iev; |
14 |
int calped[4][11][96]; |
int pstwerr[4]; |
15 |
int calgood[4][11][96]; |
float pperror[4]; |
16 |
int calthr[4][11][6]; |
float calpuls[4][11][96]; |
17 |
int calrms[4][11][96]; |
} calpul_; |
|
int calbase[4][11][6]; |
|
|
int calvar[4][11][6]; |
|
|
int calpuls[4][11][96]; |
|
|
} calib_; |
|
18 |
|
|
19 |
//external declaration of the Fortran function |
//external declaration of the Fortran function |
20 |
void calpulse_(short[], long int*, int*); |
void calpulse_(char*, long int*, int*); |
21 |
} |
} |
22 |
|
|
23 |
#include <fstream> |
#include <fstream> |
45 |
*/ |
*/ |
46 |
std::string CalibCalPulse1Reader::GetVersionInfo(void) const { |
std::string CalibCalPulse1Reader::GetVersionInfo(void) const { |
47 |
return |
return |
48 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse1Reader.cpp,v 1.3 2004/08/24 16:01:57 kusanagi Exp $\n"; |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse1Reader.cpp,v 4.1 2005/05/28 08:00:08 kusanagi Exp $\n"; |
49 |
} |
} |
50 |
|
|
51 |
/** |
/** |
61 |
/** |
/** |
62 |
* Unpack the CalibCalPulse1 event from an input file. |
* Unpack the CalibCalPulse1 event from an input file. |
63 |
*/ |
*/ |
64 |
void CalibCalPulse1Reader::RunEvent(int EventNumber, long int length) { |
void CalibCalPulse1Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){ |
65 |
std::stringstream oss; |
std::stringstream oss; |
66 |
char *packetData; |
char packetData[dataLength]; |
|
char CRCevent[2]; |
|
|
UINT16 calculatedCRC = 0; //calculated CRC |
|
|
UINT16 readCRC = 0; //read CRC |
|
|
long int dataLength; |
|
67 |
int ERROR; |
int ERROR; |
|
|
|
|
dataLength = length - 2; |
|
|
packetData = new char[dataLength]; |
|
68 |
InputFile->read(packetData, sizeof(packetData)); |
InputFile->read(packetData, sizeof(packetData)); |
|
InputFile->read(CRCevent, sizeof(CRCevent)); |
|
69 |
|
|
70 |
calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength); |
calpulse_(packetData, &dataLength, &ERROR); |
|
readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF); |
|
71 |
|
|
72 |
if (calculatedCRC == readCRC) { |
calibCalPulse1->unpackError = ERROR; |
73 |
calpulse_((short*)packetData, &dataLength, &ERROR); |
oss.str(""); |
74 |
if (ERROR != 0) { |
if (ERROR != 0) { |
75 |
char *errmsg; |
char *errmsg; |
76 |
switch (ERROR){ |
switch (ERROR){ |
77 |
case 1: errmsg = "CALORIMETER NOT FOUND"; |
case 1: errmsg = "CALORIMETER NOT FOUND"; |
78 |
} |
} |
79 |
oss.flush(); |
oss << "Fortran77 function calpulse error code = " << ERROR |
80 |
oss << "Fortran77 function calpulse error code = " << ERROR |
<< " " << errmsg; |
81 |
<< errmsg; |
logger->warn(oss.str().c_str()); |
82 |
logger->warn(oss.str().c_str()); |
} //else { |
83 |
} else { |
//Store the unpacked data |
84 |
//Store the unpacked data |
calibCalPulse1->iev = calpul_.iev; |
85 |
calibCalPulse1->IEV2 = calib_.IEV2; |
memcpy(calibCalPulse1->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse1->pstwerr)); |
86 |
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
memcpy(calibCalPulse1->pperror, calpul_.pperror, sizeof(calibCalPulse1->pperror)); |
87 |
int tempCalped[96][11][4]; |
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
88 |
int tempCalgood[96][11][4]; |
float tempCalpuls[96][11][4]; |
89 |
int tempCalthr[6][11][4]; |
memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls)); |
90 |
int tempCalrms[96][11][4]; |
for (int i = 0; i < 4; i++){ |
91 |
int tempCalbase[6][11][4]; |
for (int j = 0; j <11; j++){ |
92 |
int tempCalvar[6][11][4]; |
for (int z = 0; z < 96; z++){ |
93 |
int tempCalpuls[96][11][4]; |
calibCalPulse1->calpuls[i][j][z] = tempCalpuls[z][j][i]; |
|
|
|
|
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]; |
|
|
} |
|
94 |
} |
} |
95 |
} |
} |
|
//----------------------------------------------------------------------------------------- |
|
96 |
} |
} |
97 |
} else { |
//----------------------------------------------------------------------------------------- |
98 |
logger->warn(_T("The test of calculated CRC with one wrote on file FAILED!!")); |
//} |
|
} |
|
|
delete [] packetData; |
|
99 |
} |
} |
100 |
|
|