1 |
/** @file |
2 |
* $Source: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/RunTrailerReader.cpp,v $ |
3 |
* $Id: RunTrailerReader.cpp,v 6.2 2006/05/30 19:10:03 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
5 |
* |
6 |
* Implementation of the RunHeader class. |
7 |
*/ |
8 |
|
9 |
|
10 |
extern "C" { |
11 |
#include "CRC.h" |
12 |
} |
13 |
#include "ReaderAlgorithms.h" |
14 |
using namespace pamela::techmodel; |
15 |
|
16 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.RunTrailerReader")); |
17 |
|
18 |
/** |
19 |
* Constructor. |
20 |
*/ |
21 |
RunTrailerReader::RunTrailerReader(void): |
22 |
TechmodelAlgorithm(PacketType::Log, "TechmodelRunTrailerReader") { |
23 |
logger->debug(_T("Constructor")); |
24 |
RunTrailer = new RunTrailerEvent(); |
25 |
} |
26 |
|
27 |
/** |
28 |
* Get a string with the version info of the algorithm. |
29 |
*/ |
30 |
std::string RunTrailerReader::GetVersionInfo(void) const { |
31 |
return |
32 |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/RunTrailerReader.cpp,v 6.2 2006/05/30 19:10:03 kusanagi Exp $\n"; |
33 |
} |
34 |
|
35 |
/** |
36 |
* Initialize the algorithm with a special run. This will initialize the |
37 |
* event reader routines for all packet types. |
38 |
*/ |
39 |
void RunTrailerReader::Init(PamelaRun *run) { |
40 |
SetInputStream(run); |
41 |
run->WriteSubPacket(this, &RunTrailer, RunTrailer->Class()); |
42 |
logger->debug(_T("Initialize")); |
43 |
} |
44 |
|
45 |
/** |
46 |
* Unpack the RunTrailer event from an input file. |
47 |
*/ |
48 |
void RunTrailerReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ |
49 |
char *subData; |
50 |
char eventCRC[2]; |
51 |
UINT16 subCRC; //CRC of the data |
52 |
UINT16 readCRC; //CRC read from the end of the subpacket |
53 |
long int dataLength; |
54 |
|
55 |
//the 2 bytes subtracted belong to the final event CRC bytes |
56 |
dataLength = length - (long int)2; |
57 |
|
58 |
subData = new char[dataLength]; |
59 |
memset(subData, 0, dataLength*sizeof(char)); |
60 |
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
61 |
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); |
62 |
|
63 |
//took the final CRC to compare it with the previous calculated CRC of the data |
64 |
InputFile->read(eventCRC, sizeof(eventCRC)); |
65 |
readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); |
66 |
|
67 |
if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for RunTrailer Packet "); |
68 |
|
69 |
RunTrailer->PKT_COUNTER = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF); |
70 |
RunTrailer->PKT_ReadyCounter = (((UINT32)subData[4]<<24)&0xFF000000) + (((UINT32)subData[5]<<16)&0x00FF0000) + (((UINT32)subData[6]<<8)&0x0000FF00) + (((UINT32)subData[7])&0x000000FF); |
71 |
RunTrailer->OBT_TYME_SYNC = (((UINT32)subData[8]<<24)&0xFF000000) + (((UINT32)subData[9]<<16)&0x00FF0000) + (((UINT32)subData[10]<<8)&0x0000FF00) + (((UINT32)subData[11])&0x000000FF); |
72 |
RunTrailer->LAST_TYME_SYNC_INFO = (((UINT32)subData[12]<<24)&0xFF000000) + (((UINT32)subData[13]<<16)&0x00FF0000) + (((UINT32)subData[14]<<8)&0x0000FF00) + (((UINT32)subData[15])&0x000000FF); |
73 |
|
74 |
} |
75 |
|