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

Diff of /yoda/techmodel/CalibCalPulse1Reader.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.3 by mocchiut, Fri Sep 29 10:19:19 2006 UTC
# Line 2  Line 2 
2  // Implementation of the CalibCalPulse1Reader class.  // Implementation of the CalibCalPulse1Reader 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  }  }
18    
 #include <fstream>  
 #include "stdio.h"  
19  #include "ReaderAlgorithms.h"  #include "ReaderAlgorithms.h"
20    
 #include "event/CalibCalPulse1Event.h"  
   
 using namespace pamela;  
21  using namespace pamela::techmodel;  using namespace pamela::techmodel;
22    
23  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibCalPulse1Reader");    static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibCalPulse1Reader"));
24    
25  /**  /**
26   * Constructor.   * Constructor.
27   */   */
28  CalibCalPulse1Reader::CalibCalPulse1Reader(void):  CalibCalPulse1Reader::CalibCalPulse1Reader(void):
29    TechmodelAlgorithm(PacketType::CalibCalPulse1, "TechmodelCalibCalPulse1Reader") {    TechmodelAlgorithm(PacketType::CalibCalPulse1, "TechmodelCalibCalPulse1Reader") {
30    cat <<  log4cpp::Priority::DEBUG    logger->debug(_T("Constructor"));
       <<  "Constructor "  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
31    calibCalPulse1 = new CalibCalPulse1Event();    calibCalPulse1 = new CalibCalPulse1Event();
32  }  }
33    
# Line 51  CalibCalPulse1Reader::CalibCalPulse1Read Line 36  CalibCalPulse1Reader::CalibCalPulse1Read
36   */   */
37  std::string CalibCalPulse1Reader::GetVersionInfo(void) const {  std::string CalibCalPulse1Reader::GetVersionInfo(void) const {
38    return    return
39      "$Header: /home/cvsmanager/yoda/techmodel/CalibCalPulse1Reader.cpp,v 1.2 2004/08/20 15:01:41 kusanagi Exp $\n";      "$Header: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/CalibCalPulse1Reader.cpp,v 6.2 2006/05/30 19:10:03 kusanagi Exp $\n";
40  }  }
41    
42  /**  /**
# Line 59  std::string CalibCalPulse1Reader::GetVer Line 44  std::string CalibCalPulse1Reader::GetVer
44   * event reader routines for all packet types.   * event reader routines for all packet types.
45   */   */
46  void CalibCalPulse1Reader::Init(PamelaRun *run) {  void CalibCalPulse1Reader::Init(PamelaRun *run) {
47      logger->debug(_T("Initialize"));
48    SetInputStream(run);    SetInputStream(run);
49    run->WriteSubPacket(this, &calibCalPulse1, calibCalPulse1->Class());    run->WriteSubPacket(this, &calibCalPulse1, calibCalPulse1->Class());
50  }  }
# Line 66  void CalibCalPulse1Reader::Init(PamelaRu Line 52  void CalibCalPulse1Reader::Init(PamelaRu
52  /**  /**
53   * Unpack the CalibCalPulse1 event from an input file.   * Unpack the CalibCalPulse1 event from an input file.
54   */   */
55  void CalibCalPulse1Reader::RunEvent(int EventNumber, long int length) {  void CalibCalPulse1Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){
56            std::stringstream oss;      
57      char        *packetData;      char        packetData[dataLength];
     char        CRCevent[2];  
     UINT16      calculatedCRC    = 0;   //calculated CRC  
     UINT16      readCRC          = 0;   //read CRC  
     long int    dataLength;  
58      int         ERROR;      int         ERROR;
59        memset(packetData,  0, dataLength*sizeof(char));
     dataLength = length - 2;  
     packetData = new char[dataLength];  
60      InputFile->read(packetData, sizeof(packetData));      InputFile->read(packetData, sizeof(packetData));
     InputFile->read(CRCevent, sizeof(CRCevent));  
61    
62      calculatedCRC = CM_Compute_CRC16(0, (BYTE*)packetData, dataLength);      calpulse_(packetData, &dataLength, &ERROR);
     readCRC = ((UINT16)(CRCevent[0]<<8)&0xFF00) + ((UINT16)(CRCevent[1])&0x00FF);  
63            
64      if (calculatedCRC == readCRC) {      calibCalPulse1->unpackError = ERROR;
65          calpulse_((short*)packetData, &dataLength, &ERROR);      oss.str("");    
66          if (ERROR != 0) {      if (ERROR != 0) {
67                      char *errmsg;          char *errmsg;
68                      switch (ERROR){          switch (ERROR){
69                          case 1: errmsg = "CALORIMETER NOT FOUND";              case 1: errmsg = "CALORIMETER NOT FOUND";
70                      }          }
71                      cat <<  log4cpp::Priority::ERROR          oss << "Fortran77 function calpulse error code = " << ERROR
72                          <<  "Fortran77 function calpulse error code = " << ERROR              <<  " " << errmsg;
73                          <<  errmsg          logger->warn(oss.str().c_str());
74                          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      } //else {
75          } else {        //Store the unpacked data
76            //Store the unpacked data          calibCalPulse1->iev = calpul_.iev;
77              calibCalPulse1->IEV2 = calib_.IEV2;          memcpy(calibCalPulse1->pstwerr, calpul_.pstwerr, sizeof(calibCalPulse1->pstwerr));
78          //--------have to invert array because of FORTRAN <-> C different management of the indexes          memcpy(calibCalPulse1->pperror, calpul_.pperror, sizeof(calibCalPulse1->pperror));
79              int tempCalped[96][11][4];      //--------have to invert array because of FORTRAN <-> C different management of the indexes
80              int tempCalgood[96][11][4];          float tempCalpuls[96][11][4];
81              int tempCalthr[6][11][4];          memcpy(tempCalpuls, calpul_.calpuls, sizeof(tempCalpuls));
82              int tempCalrms[96][11][4];          for (int i = 0; i < 4; i++){
83              int tempCalbase[6][11][4];              for (int j = 0; j <11; j++){
84              int tempCalvar[6][11][4];                  for (int z = 0; z < 96; z++){
85              int tempCalpuls[96][11][4];                      calibCalPulse1->calpuls[i][j][z]  = tempCalpuls[z][j][i];
   
             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++){  
                         calibCalPulse1->calped[i][j][z]    = tempCalped[z][j][i];  
                         calibCalPulse1->calgood[i][j][z]   = tempCalgood[z][j][i];  
                         calibCalPulse1->calrms[i][j][z]    = tempCalrms[z][j][i];  
                         calibCalPulse1->calpuls[i][j][z]  = tempCalpuls[z][j][i];  
                     }  
                 }  
             }  
   
             for (int i = 0; i < 4; i++){  
                 for (int j = 0; j <11; j++){  
                     for (int z = 0; z < 6; z++){  
                         calibCalPulse1->calthr[i][j][z]    = tempCalthr[z][j][i];  
                         calibCalPulse1->calbase[i][j][z]   = tempCalbase[z][j][i];  
                         calibCalPulse1->calvar[i][j][z]    = tempCalvar[z][j][i];  
                     }  
86                  }                  }
87              }              }
         //-----------------------------------------------------------------------------------------  
88          }          }
89      } else {     //-----------------------------------------------------------------------------------------
90              cat <<  log4cpp::Priority::ERROR      //}
             <<  "The test of calculated CRC with one wrote on file FAILED!!"  
             <<  "\n " << log4cpp::CategoryStream::ENDLINE;      
     }  
     delete [] packetData;  
91  }  }
92    

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

  ViewVC Help
Powered by ViewVC 1.1.23