1 |
/** @file |
2 |
* $Author: messineo $ |
3 |
* $Date: 2008-03-04 18:09:30 $ |
4 |
* $Revision: 1.4 $ |
5 |
* |
6 |
* Implementation of the InitHeaderReader class. |
7 |
*/ |
8 |
|
9 |
#include "ReaderAlgorithms.h" |
10 |
|
11 |
using namespace pamela::techmodel; |
12 |
|
13 |
|
14 |
/** |
15 |
* Constructor. |
16 |
*/ |
17 |
InitHeaderReader::InitHeaderReader(void): |
18 |
TechmodelAlgorithm(PacketType::InitHeader, "TechmodelInitHeaderReader") { |
19 |
initHeader = new InitHeaderEvent(); |
20 |
} |
21 |
|
22 |
/** |
23 |
* Get a string with the version info of the algorithm. |
24 |
*/ |
25 |
std::string InitHeaderReader::GetVersionInfo(void) const { |
26 |
return |
27 |
"$Header: /repository/PamOffLineSW/techmodel/InitHeaderReader.cpp,v 1.4 2008-03-04 18:09:30 messineo Exp $\n"; |
28 |
} |
29 |
|
30 |
/** |
31 |
Initialize the algorithm with a special run. This will initialize the |
32 |
* event reader routines for all packet types. |
33 |
* |
34 |
* @param run |
35 |
*/ |
36 |
void InitHeaderReader::Init(PamelaRun *run) { |
37 |
run->WriteSubPacket(this, &initHeader, initHeader->Class()); |
38 |
} |
39 |
|
40 |
|
41 |
/** |
42 |
* Unpack the InitHeader event from an input file. |
43 |
* @param EventNumber |
44 |
* @param dataLength |
45 |
*/ |
46 |
void InitHeaderReader::PKT_RunEvent(char* subData, long int dataLength) throw (WrongCRCException){ |
47 |
std::stringstream oss; |
48 |
string msg; |
49 |
|
50 |
UINT16 subCRC; //calculated CRC of the data |
51 |
UINT16 readCRC; //CRC read from the end of the subpacket |
52 |
long int length = dataLength - 2; //the block of data |
53 |
subCRC = CM_Compute_CRC16(0, (UINT8*)subData, length); |
54 |
readCRC = (((UINT16)(subData[dataLength - 2]<<8))&0xFF00) + (((UINT16)subData[dataLength - 1])&0x00FF); |
55 |
|
56 |
//if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for InitHeader Packet "); |
57 |
if (subCRC != readCRC) |
58 |
{ |
59 |
oss.str(""); |
60 |
oss<<"Wrong CRC for InitHeader Packet: "<<" CRC COMPUTED= "<< subCRC<<" CRC READ= "<< readCRC; |
61 |
msg=oss.str(); |
62 |
PamOffLineSW::mainLogUtil->logError(msg); |
63 |
throw WrongCRCException(" Wrong CRC for InitHeader Packet. THE PACKET IS DISCARDED "); |
64 |
} |
65 |
|
66 |
initHeader->initHeaderData = new TArrayC(length, subData); |
67 |
|
68 |
/* |
69 |
if (subCRC != readCRC) |
70 |
{ |
71 |
oss.str(""); |
72 |
oss<<"Wrong CRC for InitHeader Packet: "<<" CRC COMPUTED= "<< subCRC<<" CRC READ= "<< readCRC; |
73 |
msg=oss.str(); |
74 |
PamOffLineSW::mainLogUtil->logWarning(msg); |
75 |
throw WrongCRCException_PKTUsed(" Wrong CRC for InitHeader Packet. "); |
76 |
} |
77 |
*/ |
78 |
} |