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