1 |
kusanagi |
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 |
kusanagi |
2.1 |
extern struct { |
9 |
|
|
int iev; |
10 |
|
|
int pstwerr[4]; |
11 |
|
|
float pperror[4]; |
12 |
|
|
float calpuls[4][11][96]; |
13 |
|
|
} calpul_; |
14 |
kusanagi |
1.1 |
|
15 |
|
|
//external declaration of the Fortran function |
16 |
kusanagi |
2.1 |
void calpulse_(char*, long int*, int*); |
17 |
kusanagi |
1.1 |
} |
18 |
|
|
#include "ReaderAlgorithms.h" |
19 |
|
|
|
20 |
|
|
using namespace pamela::techmodel; |
21 |
|
|
|
22 |
kusanagi |
1.4 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibCalPulse2Reader")); |
23 |
kusanagi |
1.1 |
|
24 |
|
|
/** |
25 |
|
|
* Constructor. |
26 |
|
|
*/ |
27 |
|
|
CalibCalPulse2Reader::CalibCalPulse2Reader(void): |
28 |
|
|
TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") { |
29 |
kusanagi |
1.4 |
logger->debug(_T("Constructor")); |
30 |
kusanagi |
1.1 |
calibCalPulse2 = new CalibCalPulse2Event(); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* Get a string with the version info of the algorithm. |
35 |
|
|
*/ |
36 |
|
|
std::string CalibCalPulse2Reader::GetVersionInfo(void) const { |
37 |
|
|
return |
38 |
kusanagi |
6.2 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse2Reader.cpp,v 6.1 2006/05/30 19:10:01 kusanagi Exp $\n"; |
39 |
kusanagi |
1.1 |
} |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
43 |
|
|
* event reader routines for all packet types. |
44 |
|
|
*/ |
45 |
|
|
void CalibCalPulse2Reader::Init(PamelaRun *run) { |
46 |
kusanagi |
1.4 |
logger->debug(_T("Initialize")); |
47 |
kusanagi |
1.1 |
SetInputStream(run); |
48 |
|
|
run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class()); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
* Unpack the CalibCalPulse2 event from an input file. |
53 |
|
|
*/ |
54 |
kusanagi |
2.1 |
void CalibCalPulse2Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){ |
55 |
kusanagi |
1.4 |
std::stringstream oss; |
56 |
kusanagi |
2.1 |
char packetData[dataLength]; |
57 |
kusanagi |
1.1 |
int ERROR; |
58 |
|
|
InputFile->read(packetData, sizeof(packetData)); |
59 |
kusanagi |
2.2 |
|
60 |
kusanagi |
2.1 |
calpulse_(packetData, &dataLength, &ERROR); |
61 |
kusanagi |
2.2 |
|
62 |
|
|
calibCalPulse2->unpackError = ERROR; |
63 |
|
|
|
64 |
kusanagi |
2.1 |
if (ERROR != 0) { |
65 |
|
|
char *errmsg; |
66 |
|
|
switch (ERROR){ |
67 |
|
|
case 1: errmsg = "CALORIMETER NOT FOUND"; |
68 |
|
|
} |
69 |
|
|
oss.str(""); |
70 |
|
|
oss << "Fortran77 function calpulse error code = " << ERROR |
71 |
kusanagi |
2.3 |
<< " " << errmsg; |
72 |
kusanagi |
2.1 |
logger->warn(oss.str().c_str()); |
73 |
kusanagi |
4.1 |
} //else { |
74 |
kusanagi |
2.1 |
//Store the unpacked data |
75 |
|
|
calibCalPulse2->iev = calpul_.iev; |
76 |
|
|
memcpy(calibCalPulse2->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse2->pstwerr)); |
77 |
|
|
memcpy(calibCalPulse2->pperror, calpul_.pperror, sizeof(calibCalPulse2->pperror)); |
78 |
|
|
//--------have to invert array because of FORTRAN <-> C different management of the indexes |
79 |
|
|
float tempCalpuls[96][11][4]; |
80 |
|
|
memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls)); |
81 |
|
|
for (int i = 0; i < 4; i++){ |
82 |
|
|
for (int j = 0; j <11; j++){ |
83 |
|
|
for (int z = 0; z < 96; z++){ |
84 |
|
|
calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i]; |
85 |
kusanagi |
1.2 |
} |
86 |
kusanagi |
1.1 |
} |
87 |
|
|
} |
88 |
kusanagi |
2.1 |
//----------------------------------------------------------------------------------------- |
89 |
kusanagi |
4.1 |
//} |
90 |
kusanagi |
1.1 |
} |
91 |
|
|
|