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

Diff of /yoda/techmodel/CalibS4Reader.cpp

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

revision 1.2 by kusanagi, Sat Jul 17 20:03:38 2004 UTC revision 4.0 by kusanagi, Sun Mar 6 04:33:02 2005 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v $   * $Source: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v $
3   * $Id: CalibS4Reader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $   * $Id: CalibS4Reader.cpp,v 3.0 2005/03/04 15:54:11 kusanagi Exp $
4   * $Author: kusanagi $   * $Author: kusanagi $
5   *   *
6   * Implementation of the LogReader class.   * Implementation of the LogReader class.
# Line 11  Line 11 
11  #define UINT unsigned int  #define UINT unsigned int
12  #define BYTE  unsigned char  #define BYTE  unsigned char
13  #include <string>  #include <string>
14  #include <log4cpp/Category.hh>  #include <log4cxx/logger.h>
15  extern "C" {  extern "C" {
16  #include <sys/time.h>  #include <sys/time.h>
17  #include "CRC.h"  #include "CRC.h"
# Line 20  extern "C" { Line 20  extern "C" {
20  #include <fstream>  #include <fstream>
21  #include "stdio.h"  #include "stdio.h"
22  #include "ReaderAlgorithms.h"  #include "ReaderAlgorithms.h"
23    #include "event/physics/S4/S4Event.h"
24    //#include "event/CalibS4Event.h"
25    
 #include "event/CalibS4Event.h"  
26    
27  using namespace pamela;  using namespace pamela;
28  using namespace pamela::techmodel;  using namespace pamela::techmodel;
29    
30  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibS4Reader");    static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibS4Reader"));
31    
32  /**  /**
33   * Constructor.   * Constructor.
34   */   */
35  CalibS4Reader::CalibS4Reader(void):  CalibS4Reader::CalibS4Reader(void):
36    TechmodelAlgorithm(PacketType::Log, "TechmodelCalibS4Reader") {    TechmodelAlgorithm(PacketType::Log, "TechmodelCalibS4Reader") {
37    cat <<  log4cpp::Priority::DEBUG    logger->debug(_T("Constructor"));
38        <<  "Constructor "    calibS4 = new CalibS4Event();
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
   CalibS4 = new CalibS4Event();  
39  }  }
40    
41  /**  /**
# Line 44  CalibS4Reader::CalibS4Reader(void): Line 43  CalibS4Reader::CalibS4Reader(void):
43   */   */
44  std::string CalibS4Reader::GetVersionInfo(void) const {  std::string CalibS4Reader::GetVersionInfo(void) const {
45    return    return
46      "$Header: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n";      "$Header: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v 3.0 2005/03/04 15:54:11 kusanagi Exp $\n";
47  }  }
48    
49  /**  /**
# Line 52  std::string CalibS4Reader::GetVersionInf Line 51  std::string CalibS4Reader::GetVersionInf
51   * event reader routines for all packet types.   * event reader routines for all packet types.
52   */   */
53  void CalibS4Reader::Init(PamelaRun *run) {  void CalibS4Reader::Init(PamelaRun *run) {
54      logger->debug(_T("Initialize"));
55    SetInputStream(run);    SetInputStream(run);
56    run->WriteSubPacket(this, &CalibS4, CalibS4->Class());    run->WriteSubPacket(this, &calibS4, calibS4->Class());
57  }  }
58    
59  /**  /**
60   * Unpack the CalibS4 event from an input file.   * Unpack the CalibS4 event from an input file.
61   */   */
62  void CalibS4Reader::RunEvent(int EventNumber, long int length) {  void CalibS4Reader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){
63      char     *subData;      
64      char      eventCRC[2];      int offset;
65        char subData[length];    //impulse*(11 + 10 + 01 + 00)*eventLength + CRC = 128*4*6 + UINT16
66      UINT16    subCRC;      //CRC of the data      UINT16    subCRC;      //CRC of the data
67      UINT16    readCRC;     //CRC read from the end of the subpacket      UINT16    readCRC;     //CRC read from the end of the subpacket
68      long int  dataLength;  
69        int numRecords = ((length - 2)/6);
70      //the 2 bytes subtracted belong to the final event CRC bytes          
71      dataLength = length - (long int)2;      S4::S4Event* rec;
72        calibS4->Records->Clear();
73      subData = new char[dataLength];      TClonesArray &recs = *(calibS4->Records);
74      InputFile->read(subData, sizeof(unsigned char)*dataLength);  
75      subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength);      InputFile->read(subData, sizeof(unsigned char)*length);
76        subCRC = CM_Compute_CRC16(0, (BYTE*)subData, length - 2);
77      //took the final CRC to compare it with the previous calculated CRC of the data      readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF);
     InputFile->read(eventCRC, sizeof(eventCRC));  
     readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);  
78            
79      if (subCRC == readCRC){      if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for CalibS4 Packet ");
80          //put here the reader  
81      } else {      for(int i = 0; i < numRecords; i++) {
82          cat <<  log4cpp::Priority::ERROR          offset = i*6;
83              <<  "Wrong CRC for CalibS4 Packet "          rec = new(recs[i]) S4::S4Event(); //add a new S4Event
84              <<  "\n " << log4cpp::CategoryStream::ENDLINE;          rec->S4_REG_STATUS        = (((UINT8)subData[offset])&0xF0);
85            rec->S4_DATA              = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF));
86            rec->S4_CMD_NUM           = (((UINT8)subData[offset+2])&0xFF);
87            rec->S4_RESP_LENGHT       = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF));
88            rec->S4_OVERALL_CHKCODE   = (((UINT8)subData[offset+5])&0xFF);
89      }      }
       
90  }  }
91    

Legend:
Removed from v.1.2  
changed lines
  Added in v.4.0

  ViewVC Help
Powered by ViewVC 1.1.23