1 |
mocchiut |
1.1 |
|
2 |
|
|
// Implementation of the CalibCalPulse2Reader class. |
3 |
|
|
|
4 |
|
|
|
5 |
|
|
extern "C" { |
6 |
|
|
#include "CRC.h" |
7 |
|
|
//Struct per il passaggio di dati da e verso la chiamata fortran |
8 |
|
|
extern struct { |
9 |
|
|
int iev; |
10 |
|
|
int pstwerr[4]; |
11 |
|
|
float pperror[4]; |
12 |
|
|
float calpuls[4][11][96]; |
13 |
|
|
} calpul_; |
14 |
|
|
|
15 |
|
|
//external declaration of the Fortran function |
16 |
|
|
void calpulse_(char*, long int*, int*); |
17 |
|
|
} |
18 |
|
|
#include "ReaderAlgorithms.h" |
19 |
|
|
|
20 |
|
|
using namespace pamela::techmodel; |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
/** |
24 |
|
|
* Constructor. |
25 |
|
|
*/ |
26 |
|
|
CalibCalPulse2Reader::CalibCalPulse2Reader(void): |
27 |
|
|
TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") { |
28 |
|
|
calibCalPulse2 = new CalibCalPulse2Event(); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* Get a string with the version info of the algorithm. |
33 |
|
|
*/ |
34 |
|
|
std::string CalibCalPulse2Reader::GetVersionInfo(void) const { |
35 |
|
|
return |
36 |
|
|
"$Header: /repository/PamOffLineSW/techmodel/CalibCalPulse2Reader.cpp,v 1.5 2008-03-04 18:09:31 messineo Exp $\n"; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
/** |
40 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
41 |
|
|
* event reader routines for all packet types. |
42 |
|
|
*/ |
43 |
|
|
void CalibCalPulse2Reader::Init(PamelaRun *run) { |
44 |
|
|
run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class()); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* Unpack the CalibCalPulse2 event |
49 |
|
|
*/ |
50 |
|
|
void CalibCalPulse2Reader::PKT_RunEvent(char* packetData, long int dataLength) throw (Exception){ |
51 |
|
|
string msg; |
52 |
|
|
|
53 |
|
|
std::stringstream oss; |
54 |
|
|
int ERROR; |
55 |
|
|
calpulse_(packetData, &dataLength, &ERROR); |
56 |
|
|
|
57 |
|
|
calibCalPulse2->unpackError = ERROR; |
58 |
|
|
|
59 |
|
|
if (ERROR != 0) { |
60 |
|
|
char *errmsg; |
61 |
|
|
switch (ERROR){ |
62 |
|
|
case 1: errmsg = "CALORIMETER NOT FOUND"; |
63 |
|
|
} |
64 |
|
|
oss.str(""); |
65 |
|
|
oss << "CalibCalPulse2: Fortran77 function calpulse error code = " << ERROR |
66 |
|
|
<< " " << errmsg; |
67 |
|
|
msg=oss.str(); |
68 |
|
|
PamOffLineSW::mainLogUtil->logWarning(msg); |
69 |
|
|
} //else { |
70 |
|
|
//Store the unpacked data |
71 |
|
|
calibCalPulse2->iev = calpul_.iev; |
72 |
|
|
memcpy(calibCalPulse2->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse2->pstwerr)); |
73 |
|
|
memcpy(calibCalPulse2->pperror, calpul_.pperror, sizeof(calibCalPulse2->pperror)); |
74 |
|
|
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
75 |
|
|
float tempCalpuls[96][11][4]; |
76 |
|
|
memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls)); |
77 |
|
|
for (int i = 0; i < 4; i++){ |
78 |
|
|
for (int j = 0; j <11; j++){ |
79 |
|
|
for (int z = 0; z < 96; z++){ |
80 |
|
|
calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i]; |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
//----------------------------------------------------------------------------------------- |
85 |
|
|
//} |
86 |
|
|
} |