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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Wed Aug 5 18:48:29 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
Error occurred while calculating annotation data.
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 CalibCalPulse1Reader 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
19 #include "ReaderAlgorithms.h"
20
21 using namespace pamela::techmodel;
22
23
24 /**
25 * Constructor.
26 */
27 CalibCalPulse1Reader::CalibCalPulse1Reader(void):
28 TechmodelAlgorithm(PacketType::CalibCalPulse1, "TechmodelCalibCalPulse1Reader") {
29 calibCalPulse1 = new CalibCalPulse1Event();
30 }
31
32 /**
33 * Get a string with the version info of the algorithm.
34 */
35 std::string CalibCalPulse1Reader::GetVersionInfo(void) const {
36 return
37 "$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/CalibCalPulse1Reader.cpp,v 1.3 2009-07-24 13:53:43 mocchiut Exp $\n";
38 }
39
40 /**
41 * Initialize the algorithm with a special run. This will initialize the
42 * event reader routines for all packet types.
43 */
44 void CalibCalPulse1Reader::Init(PamelaRun *run) {
45 run->WriteSubPacket(this, &calibCalPulse1, calibCalPulse1->Class());
46 }
47
48 /**
49 * Unpack the CalibCalPulse1 event
50 */
51 void CalibCalPulse1Reader::PKT_RunEvent(char* packetData, long int dataLength) throw (Exception){
52
53 string msg;
54 std::stringstream oss;
55 int ERROR;
56
57 //
58 // FAFEDE0808 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
59 // else when length > 6 we store calpulse1 data
60 //
61 if ( dataLength == 6 ){
62 if ( calpul_.iev != calpul_.iev || calpul_.iev < 0 || calpul_.iev > 9000000 ) calpul_.iev = 0;
63 calpul_.iev++;
64 calibCalPulse1->iev = calpul_.iev;
65 //
66 calibCalPulse1->pstwerr[0] = 0;
67 calibCalPulse1->pstwerr[1] = 0;
68 calibCalPulse1->pstwerr[2] = 0;
69 calibCalPulse1->pstwerr[3] = 0;
70 //
71 calibCalPulse1->pperror[0] = 129.;
72 calibCalPulse1->pperror[1] = 129.;
73 calibCalPulse1->pperror[2] = 129.;
74 calibCalPulse1->pperror[3] = 129.;
75 //
76 float tempCalpuls[96][11][4];
77 memset(calpul_.calpuls,0,sizeof(tempCalpuls));
78 memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls));
79 for (int i = 0; i < 4; i++){
80 for (int j = 0; j <11; j++){
81 for (int z = 0; z < 96; z++){
82 calibCalPulse1->calpuls[i][j][z] = tempCalpuls[z][j][i];
83 }
84 }
85 }
86 //
87 calibCalPulse1->CAL_RESET = (((UINT16)(packetData[0]<<8))&0xFF00) + (((UINT16)(packetData[1]))&0x00FF);
88 calibCalPulse1->WRITE_FPGA_REG_CH = (((UINT16)(packetData[2]<<8))&0xFF00) + (((UINT16)(packetData[3]))&0x00FF);
89 calibCalPulse1->WRITE_FPGA_REG_VCAL = (((UINT16)(packetData[4]<<8))&0xFF00) + (((UINT16)(packetData[5]))&0x00FF);
90 calibCalPulse1->unpackError = 1;
91 //
92 } else {
93 //
94 calpulse_(packetData, &dataLength, &ERROR);
95
96 calibCalPulse1->unpackError = ERROR;
97 oss.str("");
98 if (ERROR != 0) {
99 const char *errmsg="";
100 switch (ERROR){
101 case 1: errmsg = "CALORIMETER NOT FOUND";
102 }
103 oss << "CalibCalPulse1: Fortran77 function calpulse error code = " << ERROR
104 << " " << errmsg;
105 msg=oss.str();
106 if ( dataLength > 6 ) PamOffLineSW::mainLogUtil->logWarning(msg);
107 } //else {
108 //Store the unpacked data
109 calibCalPulse1->iev = calpul_.iev;
110 memcpy(calibCalPulse1->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse1->pstwerr));
111 memcpy(calibCalPulse1->pperror, calpul_.pperror, sizeof(calibCalPulse1->pperror));
112 //--------have to invert array because of FORTRAN <-> C different management of the indexes
113 float tempCalpuls[96][11][4];
114 memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls));
115 for (int i = 0; i < 4; i++){
116 for (int j = 0; j <11; j++){
117 for (int z = 0; z < 96; z++){
118 calibCalPulse1->calpuls[i][j][z] = tempCalpuls[z][j][i];
119 }
120 }
121 }
122 //
123 calibCalPulse1->CAL_RESET = 0;
124 calibCalPulse1->WRITE_FPGA_REG_CH = 0;
125 calibCalPulse1->WRITE_FPGA_REG_VCAL = 0;
126 //
127 };
128 //-----------------------------------------------------------------------------------------
129 //}
130 }

  ViewVC Help
Powered by ViewVC 1.1.23