| 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 2.3 2004/12/16 17:32:57 kusanagi Exp $ |
* $Id: CalibS4Reader.cpp,v 6.0 2006/02/07 17:11:09 kusanagi Exp $ |
| 4 |
* $Author: kusanagi $ |
* $Author: kusanagi $ |
| 5 |
* |
* |
| 6 |
* Implementation of the LogReader class. |
* Implementation of the LogReader class. |
| 8 |
* Control the CRC for the entire data Packet not just for single records |
* Control the CRC for the entire data Packet not just for single records |
| 9 |
*/ |
*/ |
| 10 |
|
|
| 11 |
#define UINT unsigned int |
|
|
#define BYTE unsigned char |
|
|
#include <string> |
|
|
#include <log4cxx/logger.h> |
|
| 12 |
extern "C" { |
extern "C" { |
|
#include <sys/time.h> |
|
| 13 |
#include "CRC.h" |
#include "CRC.h" |
| 14 |
} |
} |
|
|
|
|
#include <fstream> |
|
|
#include "stdio.h" |
|
| 15 |
#include "ReaderAlgorithms.h" |
#include "ReaderAlgorithms.h" |
|
#include "event/physics/S4/S4Event.h" |
|
|
//#include "event/CalibS4Event.h" |
|
| 16 |
|
|
|
|
|
|
using namespace pamela; |
|
| 17 |
using namespace pamela::techmodel; |
using namespace pamela::techmodel; |
| 18 |
|
|
| 19 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibS4Reader")); |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibS4Reader")); |
| 32 |
*/ |
*/ |
| 33 |
std::string CalibS4Reader::GetVersionInfo(void) const { |
std::string CalibS4Reader::GetVersionInfo(void) const { |
| 34 |
return |
return |
| 35 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v 2.3 2004/12/16 17:32:57 kusanagi Exp $\n"; |
"$Header: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v 6.0 2006/02/07 17:11:09 kusanagi Exp $\n"; |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
/** |
/** |
| 51 |
void CalibS4Reader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ |
void CalibS4Reader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ |
| 52 |
|
|
| 53 |
int offset; |
int offset; |
| 54 |
char subData[3074]; //impulse*(11 + 10 + 01 + 00)*eventLength + CRC = 128*4*6 + UINT16 |
char subData[length]; //impulse*(11 + 10 + 01 + 00)*eventLength + CRC = 128*4*6 + UINT16 |
| 55 |
UINT16 subCRC; //CRC of the data |
UINT16 subCRC; //CRC of the data |
| 56 |
UINT16 readCRC; //CRC read from the end of the subpacket |
UINT16 readCRC; //CRC read from the end of the subpacket |
| 57 |
|
|
| 62 |
TClonesArray &recs = *(calibS4->Records); |
TClonesArray &recs = *(calibS4->Records); |
| 63 |
|
|
| 64 |
InputFile->read(subData, sizeof(unsigned char)*length); |
InputFile->read(subData, sizeof(unsigned char)*length); |
|
|
|
| 65 |
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, length - 2); |
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, length - 2); |
| 66 |
readCRC = (((UINT16)(subData[3072]<<8))&0xFF00) + (((UINT16)subData[3073])&0x00FF); |
readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF); |
| 67 |
|
|
| 68 |
if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for CalibS4 Packet "); |
if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for CalibS4 Packet "); |
| 69 |
|
|