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

Legend:
Removed from v.1.3  
changed lines
  Added in v.6.1

  ViewVC Help
Powered by ViewVC 1.1.23