/[PAMELA software]/chewbacca/PamOffLineSW/techmodel/CalibCalPulse2Reader.cpp
ViewVC logotype

Contents of /chewbacca/PamOffLineSW/techmodel/CalibCalPulse2Reader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Wed Aug 5 18:48:38 2009 UTC (15 years, 4 months ago) by pam-fi
Branch: MAIN
CVS Tags: v10RED, v9r00, v9r01, HEAD
Changes since 1.3: +2 -2 lines
Various minor modifications for compatibility with gcc 4.4, removal of warnings due to mismatch between char* and const char*, bug fix.

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: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/CalibCalPulse2Reader.cpp,v 1.3 2009-07-24 13:53:44 mocchiut 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 std::stringstream oss;
53 int ERROR;
54
55 //
56 // FAFEDE0909 is used to store two different data set: when length = 6 we store the calorimeter answer to commands CAL_RESET, WRITE_FPGA_REG_CH, WRITE_FPGA_REG_VCAL
57 // else when length > 6 we store calpulse2 data
58 //
59 if ( dataLength == 6 ){
60 if ( calpul_.iev != calpul_.iev || calpul_.iev < 0 || calpul_.iev > 9000000 ) calpul_.iev = 0;
61 calpul_.iev++;
62 calibCalPulse2->iev = calpul_.iev;
63 //
64 calibCalPulse2->pstwerr[0] = 0;
65 calibCalPulse2->pstwerr[1] = 0;
66 calibCalPulse2->pstwerr[2] = 0;
67 calibCalPulse2->pstwerr[3] = 0;
68 //
69 calibCalPulse2->pperror[0] = 129.;
70 calibCalPulse2->pperror[1] = 129.;
71 calibCalPulse2->pperror[2] = 129.;
72 calibCalPulse2->pperror[3] = 129.;
73 //
74 float tempCalpuls[96][11][4];
75 memset(calpul_.calpuls,0,sizeof(tempCalpuls));
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 calibCalPulse2->CAL_RESET = (((UINT16)(packetData[0]<<8))&0xFF00) + (((UINT16)(packetData[1]))&0x00FF);
86 calibCalPulse2->WRITE_FPGA_REG_CH = (((UINT16)(packetData[2]<<8))&0xFF00) + (((UINT16)(packetData[3]))&0x00FF);
87 calibCalPulse2->WRITE_FPGA_REG_VCAL = (((UINT16)(packetData[4]<<8))&0xFF00) + (((UINT16)(packetData[5]))&0x00FF);
88 calibCalPulse2->unpackError = 1;
89 //
90 } else {
91 //
92 calpulse_(packetData, &dataLength, &ERROR);
93
94 calibCalPulse2->unpackError = ERROR;
95 oss.str("");
96 if (ERROR != 0) {
97 const char *errmsg="";
98 switch (ERROR){
99 case 1: errmsg = "CALORIMETER NOT FOUND";
100 }
101 oss << "CalibCalPulse2: Fortran77 function calpulse error code = " << ERROR
102 << " " << errmsg;
103 msg=oss.str();
104 if ( dataLength > 6 ) PamOffLineSW::mainLogUtil->logWarning(msg);
105 } //else {
106 //Store the unpacked data
107 calibCalPulse2->iev = calpul_.iev;
108 memcpy(calibCalPulse2->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse2->pstwerr));
109 memcpy(calibCalPulse2->pperror, calpul_.pperror, sizeof(calibCalPulse2->pperror));
110 //--------have to invert array because of FORTRAN <-> C different management of the indexes
111 float tempCalpuls[96][11][4];
112 memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls));
113 for (int i = 0; i < 4; i++){
114 for (int j = 0; j <11; j++){
115 for (int z = 0; z < 96; z++){
116 calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i];
117 }
118 }
119 }
120 //
121 calibCalPulse2->CAL_RESET = 0;
122 calibCalPulse2->WRITE_FPGA_REG_CH = 0;
123 calibCalPulse2->WRITE_FPGA_REG_VCAL = 0;
124 //
125 };
126
127
128 // calpulse_(packetData, &dataLength, &ERROR);
129
130 // calibCalPulse2->unpackError = ERROR;
131
132 // if (ERROR != 0) {
133 // char *errmsg;
134 // switch (ERROR){
135 // case 1: errmsg = "CALORIMETER NOT FOUND";
136 // }
137 // oss.str("");
138 // oss << "CalibCalPulse2: Fortran77 function calpulse error code = " << ERROR
139 // << " " << errmsg;
140 // msg=oss.str();
141 // if ( dataLength > 6 ) PamOffLineSW::mainLogUtil->logWarning(msg);
142 // } //else {
143 // //Store the unpacked data
144 // calibCalPulse2->iev = calpul_.iev;
145 // memcpy(calibCalPulse2->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse2->pstwerr));
146 // memcpy(calibCalPulse2->pperror, calpul_.pperror, sizeof(calibCalPulse2->pperror));
147 // //--------have to invert array because of FORTRAN <-> C different management of the indexes
148 // float tempCalpuls[96][11][4];
149 // memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls));
150 // for (int i = 0; i < 4; i++){
151 // for (int j = 0; j <11; j++){
152 // for (int z = 0; z < 96; z++){
153 // calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i];
154 // }
155 // }
156 // }
157 // //-----------------------------------------------------------------------------------------
158 // //}
159 }

  ViewVC Help
Powered by ViewVC 1.1.23