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

Diff of /yoda/techmodel/CalibAcReader.cpp

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

revision 1.1 by kusanagi, Thu Jul 8 12:31:42 2004 UTC revision 2.2 by kusanagi, Fri Dec 3 22:08:00 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v $   * $Source: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v $
3   * $Id: ArrDumpReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $   * $Id: CalibAcReader.cpp,v 2.1 2004/10/17 12:28:38 kusanagi Exp $
4   * $Author: kusanagi $   * $Author: kusanagi $
5   *   *
6   * Implementation of the ArrDumpReader class.   * Implementation of the ArrDumpReader class.
7   */   */
8    
9  #include <string>  #include <string>
10  #include <log4cpp/Category.hh>  #include <log4cxx/logger.h>
11  #include <fstream>  #include <fstream>
12  #include "stdio.h"  #include "stdio.h"
13  extern "C" {  extern "C" {
14      #include "CRC.h"      #include "CRC.h"
15      #include "forroutines/anticoinc/ACcalib.h"      #include "forroutines/anticounter/AC.h"
16      int ACcalib(unsigned short* datapointer, struct datastruct* calibpointer);      extern int ACcalib(int length, unsigned char* calibpointer, struct calibstruct* calibpointer);
17  }  }
18    
19  #include "ReaderAlgorithms.h"  #include "ReaderAlgorithms.h"
# Line 21  extern "C" { Line 21  extern "C" {
21  using namespace pamela;  using namespace pamela;
22  using namespace pamela::techmodel;  using namespace pamela::techmodel;
23    
24  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibAcReader");    static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibAcReader"));
25    
26  /**  /**
27   * Constructor.   * Constructor.
28   */   */
29  CalibAcReader::CalibAcReader(void):  CalibAcReader::CalibAcReader(void):
30    TechmodelAlgorithm(PacketType::CalibAc, "TechmodelCalibAc") {    TechmodelAlgorithm(PacketType::CalibAc, "TechmodelCalibAc") {
31      logger->debug(_T("Constructor"));
32    CalibAc = new CalibAcEvent();    CalibAc = new CalibAcEvent();
33  }  }
34    
# Line 35  CalibAcReader::CalibAcReader(void): Line 36  CalibAcReader::CalibAcReader(void):
36   * Get a string with the version info of the algorithm.   * Get a string with the version info of the algorithm.
37   */   */
38  std::string CalibAcReader::GetVersionInfo(void) const {  std::string CalibAcReader::GetVersionInfo(void) const {
39    return "$Header: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n";    return "$Header: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v 2.1 2004/10/17 12:28:38 kusanagi Exp $\n";
40  }  }
41    
42  /**  /**
# Line 43  std::string CalibAcReader::GetVersionInf Line 44  std::string CalibAcReader::GetVersionInf
44   * event reader routines for all packet types.   * event reader routines for all packet types.
45   */   */
46  void CalibAcReader::Init(PamelaRun *run) {  void CalibAcReader::Init(PamelaRun *run) {
47      logger->debug(_T("Initialize"));
48    SetInputStream(run);    SetInputStream(run);
49    run->WriteSubPacket(this, &CalibAc, CalibAc->Class());    run->WriteSubPacket(this, &CalibAc, CalibAc->Class());
50  }  }
# Line 50  void CalibAcReader::Init(PamelaRun *run) Line 52  void CalibAcReader::Init(PamelaRun *run)
52  /**  /**
53   * Unpack the CalibAc event from an input file.   * Unpack the CalibAc event from an input file.
54   */   */
55  void CalibAcReader::RunEvent(int EventNumber, long int length) {  void CalibAcReader::RunEvent(int EventNumber, long int dataLength) throw (Exception){
56      char   subData[dataLength];
57      InputFile->read(subData, sizeof(unsigned char)*dataLength);
58        
59    char     *subData;      struct calibstruct output[2];
   char      eventCRC[2];  
   UINT16    subCRC;      //CRC of the data  
   UINT16    readCRC;     //CRC read from the end of the subpacket  
   long int  dataLength;  
     
     //the 2 bytes subtracted belong to the final event CRC bytes  
     dataLength = length - (long int)2;  
   
     subData = new char[dataLength];  
     InputFile->read(subData, sizeof(unsigned char)*dataLength);  
     subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength);  
   
     //took the final CRC to compare it with the previous calculated CRC of the data  
     InputFile->read(eventCRC, sizeof(eventCRC));  
     readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF);  
       
     if (subCRC == readCRC){  
     datastruct output;  
60      int ERROR;      int ERROR;
61      ERROR = ACcalib((unsigned short*)subData, &output);      CalibAc->ERROR = ACcalib(dataLength, (unsigned char*)subData, &(*output));
62        
63      CalibAc->header = output.header;      for (int i = 0; i<2; i++){
64      memcpy(CalibAc->status,     output.status,     sizeof(CalibAc->status));          CalibAc->header[i] = output[i].header;
65      memcpy(CalibAc->DAC,        output.DAC,        sizeof(CalibAc->DAC));          memcpy(CalibAc->status[i],     output[i].status,     sizeof(output[i].status));
66      memcpy(CalibAc->regist,     output.regist,     sizeof(CalibAc->regist));          memcpy(CalibAc->temp[i],       output[i].temp,       sizeof(output[i].temp));
67      memcpy(CalibAc->time,       output.time,       sizeof(CalibAc->time));          memcpy(CalibAc->DAC1[i],       output[i].DAC1,       sizeof(output[i].DAC1));
68      CalibAc->n_tr = output.n_tr;          memcpy(CalibAc->DAC2[i],       output[i].DAC2,       sizeof(output[i].DAC2));
69      memcpy(CalibAc->hitmap_tr,  output.hitmap_tr,  sizeof(CalibAc->hitmap_tr));          memcpy(CalibAc->regist[i],     output[i].regist,     sizeof(output[i].regist));
70      memcpy(CalibAc->curve1,     output.curve1,     sizeof(CalibAc->curve1));          memcpy(CalibAc->time[i],       output[i].time,       sizeof(output[i].time));
71      memcpy(CalibAc->curve2,     output.curve2,     sizeof(CalibAc->curve2));          CalibAc->n_tr[i] = output[i].n_tr;
72      CalibAc->iCRC = output.iCRC;          memcpy(CalibAc->hitmap_tr[i],  output[i].hitmap_tr,  sizeof(output[i].hitmap_tr));
73      CalibAc->tail = output.tail;          memcpy(CalibAc->curve1[i],     output[i].curve1,     sizeof(output[i].curve1));
74      CalibAc->CRC  = output.CRC;          memcpy(CalibAc->curve2[i],     output[i].curve2,     sizeof(output[i].curve2));
75              CalibAc->iCRC[i] = output[i].iCRC;
76      free(subData);          CalibAc->tail[i] = output[i].tail;
77      } else {          CalibAc->CRC[i]  = output[i].CRC;
         cat <<  log4cpp::Priority::ERROR  
             <<  "Wrong CRC on Subpacket in ArrDump Packet "  
             <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
78      }      }
79    
80        delete [] subData;
81    }    }

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

  ViewVC Help
Powered by ViewVC 1.1.23