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

Diff of /yoda/techmodel/CalibCalPulse2Reader.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by kusanagi, Thu Aug 19 15:24:46 2004 UTC revision 2.2 by kusanagi, Thu Jan 13 14:48:04 2005 UTC
# Line 5  Line 5 
5  #define UINT unsigned int  #define UINT unsigned int
6  #define BYTE  unsigned char  #define BYTE  unsigned char
7  #include <string>  #include <string>
8  #include <log4cpp/Category.hh>  #include <log4cxx/logger.h>
9    
10  extern "C" {  extern "C" {
11  #include "CRC.h"    #include "CRC.h"  
12      //Struct per il passaggio di dati da e verso la chiamata fortran      //Struct per il passaggio di dati da e verso la chiamata fortran
13      extern struct {  extern struct {
14          int IEV2;          int   iev;
15          int calped[4][11][96];          int   pstwerr[4];
16          int calgood[4][11][96];          float pperror[4];
17          int calthr[4][11][6];          float calpuls[4][11][96];
18          int calrms[4][11][96];      } calpul_;
         int calbase[4][11][6];  
         int calvar[4][11][6];  
         int calpuls[4][11][96];  
     } calib_;  
19            
20      //external declaration of the Fortran function      //external declaration of the Fortran function
21      void calpulse_(short[], long int*, int*);      void calpulse_(char*, long int*, int*);
22  }  }
23  #include <fstream>  #include <fstream>
24  #include "stdio.h"  #include "stdio.h"
# Line 33  extern "C" { Line 29  extern "C" {
29  using namespace pamela;  using namespace pamela;
30  using namespace pamela::techmodel;  using namespace pamela::techmodel;
31    
32  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPulse2Reader");    static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibCalPulse2Reader"));
33    
34  /**  /**
35   * Constructor.   * Constructor.
36   */   */
37  CalibCalPulse2Reader::CalibCalPulse2Reader(void):  CalibCalPulse2Reader::CalibCalPulse2Reader(void):
38    TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") {    TechmodelAlgorithm(PacketType::CalibCalPulse2, "TechmodelCalibCalPulse2Reader") {
39    cat <<  log4cpp::Priority::DEBUG    logger->debug(_T("Constructor"));
       <<  "Constructor "  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
40    calibCalPulse2 = new CalibCalPulse2Event();    calibCalPulse2 = new CalibCalPulse2Event();
41  }  }
42    
# Line 51  CalibCalPulse2Reader::CalibCalPulse2Read Line 45  CalibCalPulse2Reader::CalibCalPulse2Read
45   */   */
46  std::string CalibCalPulse2Reader::GetVersionInfo(void) const {  std::string CalibCalPulse2Reader::GetVersionInfo(void) const {
47    return    return
48      "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse2Reader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n";      "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse2Reader.cpp,v 2.1 2004/12/03 22:08:00 kusanagi Exp $\n";
49  }  }
50    
51  /**  /**
# Line 59  std::string CalibCalPulse2Reader::GetVer Line 53  std::string CalibCalPulse2Reader::GetVer
53   * event reader routines for all packet types.   * event reader routines for all packet types.
54   */   */
55  void CalibCalPulse2Reader::Init(PamelaRun *run) {  void CalibCalPulse2Reader::Init(PamelaRun *run) {
56      logger->debug(_T("Initialize"));
57    SetInputStream(run);    SetInputStream(run);
58    run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class());    run->WriteSubPacket(this, &calibCalPulse2, calibCalPulse2->Class());
59  }  }
# Line 66  void CalibCalPulse2Reader::Init(PamelaRu Line 61  void CalibCalPulse2Reader::Init(PamelaRu
61  /**  /**
62   * Unpack the CalibCalPulse2 event from an input file.   * Unpack the CalibCalPulse2 event from an input file.
63   */   */
64  void CalibCalPulse2Reader::RunEvent(int EventNumber, long int length) {  void CalibCalPulse2Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){
65              std::stringstream oss;      
66      char        packetData[length-2];      char        packetData[dataLength];
     char        CRCevent[2];  
     UINT16      calculatedCRC    = 0;   //calculated CRC  
     UINT16      readCRC          = 0;   //read CRC  
     long int    dataLength;  
67      int         ERROR;      int         ERROR;
   
     dataLength = length - 2;  
68      InputFile->read(packetData, sizeof(packetData));      InputFile->read(packetData, sizeof(packetData));
     InputFile->read(CRCevent, sizeof(CRCevent));  
69    
70      calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength);      calpulse_(packetData, &dataLength, &ERROR);
     readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF);  
       
     if (calculatedCRC == readCRC) {  
             calpulse_((short*)packetData, &dataLength, &ERROR);  
   //Store the unpacked data  
     calibCalPulse2->IEV2 = calib_.IEV2;  
 //--------have to invert array because of FORTRAN <-> C different management of the indexes  
     int tempCalped[96][11][4];  
     int tempCalgood[96][11][4];  
     int tempCalthr[6][11][4];  
     int tempCalrms[96][11][4];  
     int tempCalbase[6][11][4];  
     int tempCalvar[6][11][4];  
     int tempCalpuls[96][11][4];  
   
     memcpy(tempCalped,  calib_.calped,  sizeof(tempCalped));  
     memcpy(tempCalgood, calib_.calgood, sizeof(tempCalgood));  
     memcpy(tempCalthr,  calib_.calthr,  sizeof(tempCalthr));  
     memcpy(tempCalrms,  calib_.calrms,  sizeof(tempCalrms));  
     memcpy(tempCalbase, calib_.calbase, sizeof(tempCalbase));  
     memcpy(tempCalvar,  calib_.calvar,  sizeof(tempCalvar));  
     memcpy(tempCalpuls, calib_.calpuls, sizeof(tempCalpuls));  
   
     for (int i = 0; i < 4; i++){  
         for (int j = 0; j <11; j++){  
             for (int z = 0; z < 96; z++){  
                 calibCalPulse2->calped[i][j][z]    = tempCalped[z][j][i];  
                 calibCalPulse2->calgood[i][j][z]   = tempCalgood[z][j][i];  
                 calibCalPulse2->calrms[i][j][z]    = tempCalrms[z][j][i];  
                 calibCalPulse2->calpuls[i][j][z]    = tempCalpuls[z][j][i];  
             }  
         }  
     }  
71    
72      for (int i = 0; i < 4; i++){      calibCalPulse2->unpackError = ERROR;
73          for (int j = 0; j <11; j++){  
74              for (int z = 0; z < 6; z++){      if (ERROR != 0) {
75                  calibCalPulse2->calthr[i][j][z]    = tempCalthr[z][j][i];          char *errmsg;
76                  calibCalPulse2->calbase[i][j][z]   = tempCalbase[z][j][i];          switch (ERROR){
77                  calibCalPulse2->calvar[i][j][z]    = tempCalvar[z][j][i];              case 1: errmsg = "CALORIMETER NOT FOUND";
             }  
78          }          }
79      }          oss.str("");
80  //-----------------------------------------------------------------------------------------          oss << "Fortran77 function calpulse error code = " << ERROR
81                    <<  "\n" <<errmsg;
82      cat <<  log4cpp::Priority::ERROR          logger->warn(oss.str().c_str());
         <<  "Fortran77 function calpulse error code = " << ERROR  
         <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
83      } else {      } else {
84              cat <<  log4cpp::Priority::ERROR         //Store the unpacked data
85              <<  "The test of calculated CRC with one wrote on file FAILED!!"          calibCalPulse2->iev = calpul_.iev;
86              <<  "\n " << log4cpp::CategoryStream::ENDLINE;              memcpy(calibCalPulse2->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse2->pstwerr));
87            memcpy(calibCalPulse2->pperror, calpul_.pperror, sizeof(calibCalPulse2->pperror));
88        //--------have to invert array because of FORTRAN <-> C different management of the indexes
89            float tempCalpuls[96][11][4];
90            memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls));
91            for (int i = 0; i < 4; i++){
92                for (int j = 0; j <11; j++){
93                    for (int z = 0; z < 96; z++){
94                        calibCalPulse2->calpuls[i][j][z]  = tempCalpuls[z][j][i];
95                    }
96                }
97            }
98       //-----------------------------------------------------------------------------------------
99      }      }
     free(packetData);      
100  }  }
101    

Legend:
Removed from v.1.1  
changed lines
  Added in v.2.2

  ViewVC Help
Powered by ViewVC 1.1.23