1 |
kusanagi |
5.1 |
/** @file |
2 |
kusanagi |
6.0 |
* $Author: kusanagi $ |
3 |
mocchiut |
6.3 |
* $Date: 2006/05/30 19:10:03 $ |
4 |
|
|
* $Revision: 6.2 $ |
5 |
kusanagi |
5.1 |
* |
6 |
|
|
* Implementation of the InitHeaderReader class. |
7 |
|
|
*/ |
8 |
kusanagi |
1.1 |
|
9 |
|
|
#include "ReaderAlgorithms.h" |
10 |
|
|
|
11 |
|
|
using namespace pamela::techmodel; |
12 |
|
|
|
13 |
kusanagi |
1.2 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.InitHeaderReader")); |
14 |
kusanagi |
1.1 |
|
15 |
|
|
/** |
16 |
|
|
* Constructor. |
17 |
|
|
*/ |
18 |
|
|
InitHeaderReader::InitHeaderReader(void): |
19 |
|
|
TechmodelAlgorithm(PacketType::InitHeader, "TechmodelInitHeaderReader") { |
20 |
kusanagi |
1.2 |
logger->debug(_T("Constructor")); |
21 |
kusanagi |
1.1 |
initHeader = new InitHeaderEvent(); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
/** |
25 |
|
|
* Get a string with the version info of the algorithm. |
26 |
|
|
*/ |
27 |
|
|
std::string InitHeaderReader::GetVersionInfo(void) const { |
28 |
|
|
return |
29 |
mocchiut |
6.3 |
"$Header: /afs/ba.infn.it/user/pamela/src/CVS/yoda/techmodel/InitHeaderReader.cpp,v 6.2 2006/05/30 19:10:03 kusanagi Exp $\n"; |
30 |
kusanagi |
1.1 |
} |
31 |
|
|
|
32 |
|
|
/** |
33 |
kusanagi |
5.1 |
Initialize the algorithm with a special run. This will initialize the |
34 |
kusanagi |
1.1 |
* event reader routines for all packet types. |
35 |
kusanagi |
5.1 |
* |
36 |
|
|
* @param run |
37 |
kusanagi |
1.1 |
*/ |
38 |
|
|
void InitHeaderReader::Init(PamelaRun *run) { |
39 |
kusanagi |
1.2 |
logger->debug(_T("Initialize")); |
40 |
kusanagi |
1.1 |
SetInputStream(run); |
41 |
|
|
run->WriteSubPacket(this, &initHeader, initHeader->Class()); |
42 |
|
|
} |
43 |
|
|
|
44 |
kusanagi |
5.1 |
|
45 |
kusanagi |
1.1 |
/** |
46 |
|
|
* Unpack the InitHeader event from an input file. |
47 |
kusanagi |
5.1 |
* @param EventNumber |
48 |
|
|
* @param dataLength |
49 |
kusanagi |
1.1 |
*/ |
50 |
kusanagi |
5.1 |
void InitHeaderReader::RunEvent(int EventNumber, long int dataLength) throw (WrongCRCException){ |
51 |
|
|
|
52 |
|
|
char subData[dataLength]; |
53 |
|
|
UINT16 subCRC; //calculated CRC of the data |
54 |
|
|
UINT16 readCRC; //CRC read from the end of the subpacket |
55 |
|
|
long int length = dataLength - 2; //the block of data |
56 |
mocchiut |
6.3 |
memset(subData, 0, dataLength*sizeof(char)); |
57 |
kusanagi |
5.1 |
InputFile->read(subData, sizeof(subData)); |
58 |
|
|
subCRC = CM_Compute_CRC16(0, (UINT8*)subData, length); |
59 |
|
|
readCRC = (((UINT16)(subData[dataLength - 2]<<8))&0xFF00) + (((UINT16)subData[dataLength - 1])&0x00FF); |
60 |
|
|
|
61 |
|
|
if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for InitHeader Packet "); |
62 |
kusanagi |
6.1 |
initHeader->initHeaderData = new TArrayC(length, subData); |
63 |
kusanagi |
1.1 |
} |
64 |
|
|
|