1 |
kusanagi |
1.1 |
|
2 |
|
|
// Implementation of the CalibCalPulse1Reader class. |
3 |
|
|
|
4 |
|
|
|
5 |
|
|
#define UINT unsigned int |
6 |
|
|
#define BYTE unsigned char |
7 |
|
|
#include <string> |
8 |
|
|
#include <log4cpp/Category.hh> |
9 |
|
|
extern "C" { |
10 |
|
|
#include "CRC.h" |
11 |
|
|
//Struct per il passaggio di dati da e verso la chiamata fortran |
12 |
|
|
extern struct { |
13 |
|
|
int IEV2; |
14 |
|
|
int calped[4][11][96]; |
15 |
|
|
int calgood[4][11][96]; |
16 |
|
|
int calthr[4][11][6]; |
17 |
|
|
int calrms[4][11][96]; |
18 |
|
|
int calbase[4][11][6]; |
19 |
|
|
int calvar[4][11][6]; |
20 |
|
|
int calpuls[4][11][96]; |
21 |
|
|
} calib_; |
22 |
|
|
|
23 |
|
|
//external declaration of the Fortran function |
24 |
|
|
void calpulse_(short[], long int*, int*); |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
#include <fstream> |
28 |
|
|
#include "stdio.h" |
29 |
|
|
#include "ReaderAlgorithms.h" |
30 |
|
|
|
31 |
|
|
#include "event/CalibCalPulse1Event.h" |
32 |
|
|
|
33 |
|
|
using namespace pamela; |
34 |
|
|
using namespace pamela::techmodel; |
35 |
|
|
|
36 |
|
|
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPulse1Reader"); |
37 |
|
|
|
38 |
|
|
/** |
39 |
|
|
* Constructor. |
40 |
|
|
*/ |
41 |
|
|
CalibCalPulse1Reader::CalibCalPulse1Reader(void): |
42 |
|
|
TechmodelAlgorithm(PacketType::CalibCalPulse1, "TechmodelCalibCalPulse1Reader") { |
43 |
|
|
cat << log4cpp::Priority::DEBUG |
44 |
|
|
<< "Constructor " |
45 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
46 |
|
|
calibCalPulse1 = new CalibCalPulse1Event(); |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* Get a string with the version info of the algorithm. |
51 |
|
|
*/ |
52 |
|
|
std::string CalibCalPulse1Reader::GetVersionInfo(void) const { |
53 |
|
|
return |
54 |
kusanagi |
1.3 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse1Reader.cpp,v 1.2 2004/08/20 15:01:41 kusanagi Exp $\n"; |
55 |
kusanagi |
1.1 |
} |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
59 |
|
|
* event reader routines for all packet types. |
60 |
|
|
*/ |
61 |
|
|
void CalibCalPulse1Reader::Init(PamelaRun *run) { |
62 |
|
|
SetInputStream(run); |
63 |
|
|
run->WriteSubPacket(this, &calibCalPulse1, calibCalPulse1->Class()); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
/** |
67 |
|
|
* Unpack the CalibCalPulse1 event from an input file. |
68 |
|
|
*/ |
69 |
|
|
void CalibCalPulse1Reader::RunEvent(int EventNumber, long int length) { |
70 |
|
|
|
71 |
kusanagi |
1.3 |
char *packetData; |
72 |
kusanagi |
1.1 |
char CRCevent[2]; |
73 |
|
|
UINT16 calculatedCRC = 0; //calculated CRC |
74 |
|
|
UINT16 readCRC = 0; //read CRC |
75 |
|
|
long int dataLength; |
76 |
|
|
int ERROR; |
77 |
|
|
|
78 |
|
|
dataLength = length - 2; |
79 |
kusanagi |
1.3 |
packetData = new char[dataLength]; |
80 |
kusanagi |
1.1 |
InputFile->read(packetData, sizeof(packetData)); |
81 |
|
|
InputFile->read(CRCevent, sizeof(CRCevent)); |
82 |
|
|
|
83 |
|
|
calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength); |
84 |
|
|
readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF); |
85 |
|
|
|
86 |
|
|
if (calculatedCRC == readCRC) { |
87 |
kusanagi |
1.2 |
calpulse_((short*)packetData, &dataLength, &ERROR); |
88 |
|
|
if (ERROR != 0) { |
89 |
|
|
char *errmsg; |
90 |
|
|
switch (ERROR){ |
91 |
|
|
case 1: errmsg = "CALORIMETER NOT FOUND"; |
92 |
|
|
} |
93 |
|
|
cat << log4cpp::Priority::ERROR |
94 |
|
|
<< "Fortran77 function calpulse error code = " << ERROR |
95 |
|
|
<< errmsg |
96 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
97 |
|
|
} else { |
98 |
|
|
//Store the unpacked data |
99 |
|
|
calibCalPulse1->IEV2 = calib_.IEV2; |
100 |
|
|
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
101 |
|
|
int tempCalped[96][11][4]; |
102 |
|
|
int tempCalgood[96][11][4]; |
103 |
|
|
int tempCalthr[6][11][4]; |
104 |
|
|
int tempCalrms[96][11][4]; |
105 |
|
|
int tempCalbase[6][11][4]; |
106 |
|
|
int tempCalvar[6][11][4]; |
107 |
|
|
int tempCalpuls[96][11][4]; |
108 |
|
|
|
109 |
|
|
memcpy(tempCalped, calib_.calped, sizeof(tempCalped)); |
110 |
|
|
memcpy(tempCalgood, calib_.calgood, sizeof(tempCalgood)); |
111 |
|
|
memcpy(tempCalthr, calib_.calthr, sizeof(tempCalthr)); |
112 |
|
|
memcpy(tempCalrms, calib_.calrms, sizeof(tempCalrms)); |
113 |
|
|
memcpy(tempCalbase, calib_.calbase, sizeof(tempCalbase)); |
114 |
|
|
memcpy(tempCalvar, calib_.calvar, sizeof(tempCalvar)); |
115 |
|
|
memcpy(tempCalpuls, calib_.calpuls, sizeof(tempCalpuls)); |
116 |
|
|
|
117 |
|
|
for (int i = 0; i < 4; i++){ |
118 |
|
|
for (int j = 0; j <11; j++){ |
119 |
|
|
for (int z = 0; z < 96; z++){ |
120 |
|
|
calibCalPulse1->calped[i][j][z] = tempCalped[z][j][i]; |
121 |
|
|
calibCalPulse1->calgood[i][j][z] = tempCalgood[z][j][i]; |
122 |
|
|
calibCalPulse1->calrms[i][j][z] = tempCalrms[z][j][i]; |
123 |
|
|
calibCalPulse1->calpuls[i][j][z] = tempCalpuls[z][j][i]; |
124 |
|
|
} |
125 |
|
|
} |
126 |
kusanagi |
1.1 |
} |
127 |
|
|
|
128 |
kusanagi |
1.2 |
for (int i = 0; i < 4; i++){ |
129 |
|
|
for (int j = 0; j <11; j++){ |
130 |
|
|
for (int z = 0; z < 6; z++){ |
131 |
|
|
calibCalPulse1->calthr[i][j][z] = tempCalthr[z][j][i]; |
132 |
|
|
calibCalPulse1->calbase[i][j][z] = tempCalbase[z][j][i]; |
133 |
|
|
calibCalPulse1->calvar[i][j][z] = tempCalvar[z][j][i]; |
134 |
|
|
} |
135 |
|
|
} |
136 |
kusanagi |
1.1 |
} |
137 |
kusanagi |
1.2 |
//----------------------------------------------------------------------------------------- |
138 |
kusanagi |
1.1 |
} |
139 |
|
|
} else { |
140 |
|
|
cat << log4cpp::Priority::ERROR |
141 |
|
|
<< "The test of calculated CRC with one wrote on file FAILED!!" |
142 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
143 |
|
|
} |
144 |
kusanagi |
1.3 |
delete [] packetData; |
145 |
kusanagi |
1.1 |
} |
146 |
|
|
|