/[PAMELA software]/yoda/techmodel/CalibCalPulse2Reader.cpp
ViewVC logotype

Annotation of /yoda/techmodel/CalibCalPulse2Reader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Fri Aug 20 15:01:42 2004 UTC (20 years, 3 months ago) by kusanagi
Branch: MAIN
Changes since 1.1: +49 -42 lines
*** empty log message ***

1 kusanagi 1.1
2     // Implementation of the CalibCalPulse2Reader class.
3    
4    
5     #define UINT unsigned int
6     #define BYTE unsigned char
7     #include <string>
8     #include <log4cpp/Category.hh>
9    
10     extern "C" {
11     #include "CRC.h"
12     //Struct per il passaggio di dati da e verso la chiamata fortran
13     extern struct {
14     int IEV2;
15     int calped[4][11][96];
16     int calgood[4][11][96];
17     int calthr[4][11][6];
18     int calrms[4][11][96];
19     int calbase[4][11][6];
20     int calvar[4][11][6];
21     int calpuls[4][11][96];
22     } calib_;
23    
24     //external declaration of the Fortran function
25     void calpulse_(short[], long int*, int*);
26     }
27     #include <fstream>
28     #include "stdio.h"
29     #include "ReaderAlgorithms.h"
30    
31     #include "event/CalibCalPulse2Event.h"
32    
33     using namespace pamela;
34     using namespace pamela::techmodel;
35    
36     static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPulse2Reader");
37    
38     /**
39     * Constructor.
40     */
41     CalibCalPulse2Reader::CalibCalPulse2Reader(void):
42     TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") {
43     cat << log4cpp::Priority::DEBUG
44     << "Constructor "
45     << "\n " << log4cpp::CategoryStream::ENDLINE;
46     calibCalPulse2 = new CalibCalPulse2Event();
47     }
48    
49     /**
50     * Get a string with the version info of the algorithm.
51     */
52     std::string CalibCalPulse2Reader::GetVersionInfo(void) const {
53     return
54 kusanagi 1.2 "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse2Reader.cpp,v 1.1 2004/08/19 15:24:46 kusanagi Exp $\n";
55 kusanagi 1.1 }
56    
57     /**
58     * Initialize the algorithm with a special run. This will initialize the
59     * event reader routines for all packet types.
60     */
61     void CalibCalPulse2Reader::Init(PamelaRun *run) {
62     SetInputStream(run);
63     run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class());
64     }
65    
66     /**
67     * Unpack the CalibCalPulse2 event from an input file.
68     */
69     void CalibCalPulse2Reader::RunEvent(int EventNumber, long int length) {
70    
71     char packetData[length-2];
72     char CRCevent[2];
73     UINT16 calculatedCRC = 0; //calculated CRC
74     UINT16 readCRC = 0; //read CRC
75     long int dataLength;
76     int ERROR;
77    
78     dataLength = length - 2;
79     InputFile->read(packetData, sizeof(packetData));
80     InputFile->read(CRCevent, sizeof(CRCevent));
81    
82     calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength);
83     readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF);
84    
85     if (calculatedCRC == readCRC) {
86 kusanagi 1.2 calpulse_((short*)packetData, &dataLength, &ERROR);
87     if (ERROR != 0) {
88     char *errmsg;
89     switch (ERROR){
90     case 1: errmsg = "CALORIMETER NOT FOUND";
91     }
92     cat << log4cpp::Priority::ERROR
93     << "Fortran77 function calpulse error code = " << ERROR
94     << errmsg
95     << "\n " << log4cpp::CategoryStream::ENDLINE;
96     } else {
97     //Store the unpacked data
98     calibCalPulse2->IEV2 = calib_.IEV2;
99     //--------have to invert array because of FORTRAN <-> C different management of the indexes
100     int tempCalped[96][11][4];
101     int tempCalgood[96][11][4];
102     int tempCalthr[6][11][4];
103     int tempCalrms[96][11][4];
104     int tempCalbase[6][11][4];
105     int tempCalvar[6][11][4];
106     int tempCalpuls[96][11][4];
107    
108     memcpy(tempCalped, calib_.calped, sizeof(tempCalped));
109     memcpy(tempCalgood, calib_.calgood, sizeof(tempCalgood));
110     memcpy(tempCalthr, calib_.calthr, sizeof(tempCalthr));
111     memcpy(tempCalrms, calib_.calrms, sizeof(tempCalrms));
112     memcpy(tempCalbase, calib_.calbase, sizeof(tempCalbase));
113     memcpy(tempCalvar, calib_.calvar, sizeof(tempCalvar));
114     memcpy(tempCalpuls, calib_.calpuls, sizeof(tempCalpuls));
115    
116     for (int i = 0; i < 4; i++){
117     for (int j = 0; j <11; j++){
118     for (int z = 0; z < 96; z++){
119     calibCalPulse2->calped[i][j][z] = tempCalped[z][j][i];
120     calibCalPulse2->calgood[i][j][z] = tempCalgood[z][j][i];
121     calibCalPulse2->calrms[i][j][z] = tempCalrms[z][j][i];
122     calibCalPulse2->calpuls[i][j][z] = tempCalpuls[z][j][i];
123     }
124     }
125 kusanagi 1.1 }
126    
127 kusanagi 1.2 for (int i = 0; i < 4; i++){
128     for (int j = 0; j <11; j++){
129     for (int z = 0; z < 6; z++){
130     calibCalPulse2->calthr[i][j][z] = tempCalthr[z][j][i];
131     calibCalPulse2->calbase[i][j][z] = tempCalbase[z][j][i];
132     calibCalPulse2->calvar[i][j][z] = tempCalvar[z][j][i];
133     }
134     }
135 kusanagi 1.1 }
136 kusanagi 1.2 //-----------------------------------------------------------------------------------------
137 kusanagi 1.1 }
138     } else {
139     cat << log4cpp::Priority::ERROR
140     << "The test of calculated CRC with one wrote on file FAILED!!"
141     << "\n " << log4cpp::CategoryStream::ENDLINE;
142     }
143     free(packetData);
144     }
145    

  ViewVC Help
Powered by ViewVC 1.1.23