5 |
#define UINT unsigned int |
#define UINT unsigned int |
6 |
#define BYTE unsigned char |
#define BYTE unsigned char |
7 |
#include <string> |
#include <string> |
8 |
#include <log4cpp/Category.hh> |
#include <log4cxx/logger.h> |
9 |
|
|
10 |
extern "C" { |
extern "C" { |
11 |
#include "CRC.h" |
#include "CRC.h" |
12 |
//Struct per il passaggio di dati da e verso la chiamata fortran |
//Struct per il passaggio di dati da e verso la chiamata fortran |
13 |
extern struct { |
extern struct { |
14 |
int IEV2; |
int iev; |
15 |
int calped[4][11][96]; |
int pstwerr[4]; |
16 |
int calgood[4][11][96]; |
float pperror[4]; |
17 |
int calthr[4][11][6]; |
float calpuls[4][11][96]; |
18 |
int calrms[4][11][96]; |
} calpul_; |
|
int calbase[4][11][6]; |
|
|
int calvar[4][11][6]; |
|
|
int calpuls[4][11][96]; |
|
|
} calib_; |
|
19 |
|
|
20 |
//external declaration of the Fortran function |
//external declaration of the Fortran function |
21 |
void calpulse_(short[], long int*, int*); |
void calpulse_(char*, long int*, int*); |
22 |
} |
} |
23 |
#include <fstream> |
#include <fstream> |
24 |
#include "stdio.h" |
#include "stdio.h" |
29 |
using namespace pamela; |
using namespace pamela; |
30 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
31 |
|
|
32 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPulse2Reader"); |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibCalPulse2Reader")); |
33 |
|
|
34 |
/** |
/** |
35 |
* Constructor. |
* Constructor. |
36 |
*/ |
*/ |
37 |
CalibCalPulse2Reader::CalibCalPulse2Reader(void): |
CalibCalPulse2Reader::CalibCalPulse2Reader(void): |
38 |
TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") { |
TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") { |
39 |
cat << log4cpp::Priority::DEBUG |
logger->debug(_T("Constructor")); |
|
<< "Constructor " |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
40 |
calibCalPulse2 = new CalibCalPulse2Event(); |
calibCalPulse2 = new CalibCalPulse2Event(); |
41 |
} |
} |
42 |
|
|
45 |
*/ |
*/ |
46 |
std::string CalibCalPulse2Reader::GetVersionInfo(void) const { |
std::string CalibCalPulse2Reader::GetVersionInfo(void) const { |
47 |
return |
return |
48 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse2Reader.cpp,v 1.2 2004/08/20 15:01:42 kusanagi Exp $\n"; |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse2Reader.cpp,v 5.1 2006/02/04 12:37:44 kusanagi Exp $\n"; |
49 |
} |
} |
50 |
|
|
51 |
/** |
/** |
53 |
* event reader routines for all packet types. |
* event reader routines for all packet types. |
54 |
*/ |
*/ |
55 |
void CalibCalPulse2Reader::Init(PamelaRun *run) { |
void CalibCalPulse2Reader::Init(PamelaRun *run) { |
56 |
|
logger->debug(_T("Initialize")); |
57 |
SetInputStream(run); |
SetInputStream(run); |
58 |
run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class()); |
run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class()); |
59 |
} |
} |
61 |
/** |
/** |
62 |
* Unpack the CalibCalPulse2 event from an input file. |
* Unpack the CalibCalPulse2 event from an input file. |
63 |
*/ |
*/ |
64 |
void CalibCalPulse2Reader::RunEvent(int EventNumber, long int length) { |
void CalibCalPulse2Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){ |
65 |
|
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); |
71 |
readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF); |
|
72 |
|
calibCalPulse2->unpackError = 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 |
|
|
calibCalPulse2->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++){ |
|
|
calibCalPulse2->calped[i][j][z] = tempCalped[z][j][i]; |
|
|
calibCalPulse2->calgood[i][j][z] = tempCalgood[z][j][i]; |
|
|
calibCalPulse2->calrms[i][j][z] = tempCalrms[z][j][i]; |
|
|
calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i]; |
|
|
} |
|
|
} |
|
|
} |
|
73 |
|
|
74 |
for (int i = 0; i < 4; i++){ |
if (ERROR != 0) { |
75 |
for (int j = 0; j <11; j++){ |
char *errmsg; |
76 |
for (int z = 0; z < 6; z++){ |
switch (ERROR){ |
77 |
calibCalPulse2->calthr[i][j][z] = tempCalthr[z][j][i]; |
case 1: errmsg = "CALORIMETER NOT FOUND"; |
78 |
calibCalPulse2->calbase[i][j][z] = tempCalbase[z][j][i]; |
} |
79 |
calibCalPulse2->calvar[i][j][z] = tempCalvar[z][j][i]; |
oss.str(""); |
80 |
} |
oss << "Fortran77 function calpulse error code = " << ERROR |
81 |
|
<< " " << errmsg; |
82 |
|
logger->warn(oss.str().c_str()); |
83 |
|
} //else { |
84 |
|
//Store the unpacked data |
85 |
|
calibCalPulse2->iev = calpul_.iev; |
86 |
|
memcpy(calibCalPulse2->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse2->pstwerr)); |
87 |
|
memcpy(calibCalPulse2->pperror, calpul_.pperror, sizeof(calibCalPulse2->pperror)); |
88 |
|
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
89 |
|
float tempCalpuls[96][11][4]; |
90 |
|
memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls)); |
91 |
|
for (int i = 0; i < 4; i++){ |
92 |
|
for (int j = 0; j <11; j++){ |
93 |
|
for (int z = 0; z < 96; z++){ |
94 |
|
calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i]; |
95 |
} |
} |
96 |
} |
} |
|
//----------------------------------------------------------------------------------------- |
|
97 |
} |
} |
98 |
} else { |
//----------------------------------------------------------------------------------------- |
99 |
cat << log4cpp::Priority::ERROR |
//} |
|
<< "The test of calculated CRC with one wrote on file FAILED!!" |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
|
|
} |
|
|
delete [] packetData; |
|
100 |
} |
} |
101 |
|
|