1 |
/** @file |
2 |
* $Source: /home/cvsmanager/yoda/techmodel/VarDumpReader.cpp,v $ |
3 |
* $Id: VarDumpReader.cpp,v 1.3 2004/07/26 23:09:45 kusanagi Exp $ |
4 |
* $Author: kusanagi $ |
5 |
* |
6 |
* Implementation of the VarDumpReader class. |
7 |
*/ |
8 |
|
9 |
#include <string> |
10 |
#include <log4cpp/Category.hh> |
11 |
#include <fstream> |
12 |
#include "stdio.h" |
13 |
extern "C" { |
14 |
#include "CRC.h" |
15 |
} |
16 |
|
17 |
#include "ReaderAlgorithms.h" |
18 |
|
19 |
using namespace pamela; |
20 |
using namespace pamela::techmodel; |
21 |
|
22 |
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.VarDumpReader"); |
23 |
|
24 |
/** |
25 |
* Constructor. |
26 |
*/ |
27 |
VarDumpReader::VarDumpReader(void): |
28 |
TechmodelAlgorithm(PacketType::VarDump, "TechmodelVarDump") { |
29 |
VarDump = new VarDumpEvent(); |
30 |
} |
31 |
|
32 |
/** |
33 |
* Get a string with the version info of the algorithm. |
34 |
*/ |
35 |
std::string VarDumpReader::GetVersionInfo(void) const { |
36 |
return "$Header: /home/cvsmanager/yoda/techmodel/VarDumpReader.cpp,v 1.3 2004/07/26 23:09:45 kusanagi Exp $\n"; |
37 |
} |
38 |
|
39 |
/** |
40 |
* Initialize the algorithm with a special run. This will initialize the |
41 |
* event reader routines for all packet types. |
42 |
*/ |
43 |
void VarDumpReader::Init(PamelaRun *run) { |
44 |
SetInputStream(run); |
45 |
run->WriteSubPacket(this, &VarDump, VarDump->Class()); |
46 |
} |
47 |
|
48 |
/** |
49 |
* Unpack the VarDump event from an input file. |
50 |
*/ |
51 |
void VarDumpReader::RunEvent(int EventNumber, long int length) { |
52 |
|
53 |
char *subData; |
54 |
char eventCRC[2]; |
55 |
UINT16 subCRC; //CRC of the data |
56 |
UINT16 readCRC; //CRC read from the end of the subpacket |
57 |
long int dataLength; |
58 |
int vars; |
59 |
|
60 |
//the 2 bytes subtracted belong to the final event CRC bytes |
61 |
dataLength = length - (long int)2; |
62 |
|
63 |
subData = new char[dataLength]; |
64 |
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
65 |
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); |
66 |
|
67 |
//took the final CRC to compare it with the previous calculated CRC of the data |
68 |
InputFile->read(eventCRC, sizeof(eventCRC)); |
69 |
readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); |
70 |
|
71 |
//finally check if the RecordCRC is correct and finally update the partialCRC |
72 |
if (subCRC == readCRC){ |
73 |
VarDumpRecord* rec; |
74 |
VarDump->Records->Clear(); |
75 |
TClonesArray &recs = *(VarDump->Records); |
76 |
rec = new(recs[0]) VarDumpRecord(); //add a new TabDump |
77 |
vars = dataLength/4; |
78 |
rec->Data = new UINT32[vars]; |
79 |
memcpy(rec->Data, (UINT32*)subData, sizeof(UINT32)*vars); |
80 |
} else { |
81 |
cat << log4cpp::Priority::ERROR |
82 |
<< "Wrong CRC in VarDump Packet " |
83 |
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
84 |
} |
85 |
delete [] subData; |
86 |
} |
87 |
|