1 |
kusanagi |
1.1 |
/** @file |
2 |
kusanagi |
1.2 |
* $Source: /home/cvsmanager/yoda/techmodel/TabDumpReader.cpp,v $ |
3 |
kusanagi |
6.1 |
* $Id: TabDumpReader.cpp,v 6.0 2006/02/07 17:11:10 kusanagi Exp $ |
4 |
kusanagi |
6.0 |
* $Author: kusanagi $ |
5 |
kusanagi |
1.1 |
* |
6 |
|
|
* Implementation of the TabDumpReader class. |
7 |
|
|
*/ |
8 |
|
|
|
9 |
|
|
extern "C" { |
10 |
|
|
#include "CRC.h" |
11 |
|
|
} |
12 |
|
|
#include "ReaderAlgorithms.h" |
13 |
|
|
using namespace pamela::techmodel; |
14 |
|
|
|
15 |
kusanagi |
1.6 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.TabDumpReader")); |
16 |
kusanagi |
1.1 |
|
17 |
|
|
/** |
18 |
|
|
* Constructor. |
19 |
|
|
*/ |
20 |
|
|
TabDumpReader::TabDumpReader(void): |
21 |
|
|
TechmodelAlgorithm(PacketType::TabDump, "TechmodelTabDump") { |
22 |
|
|
TabDump = new TabDumpEvent(); |
23 |
kusanagi |
1.6 |
logger->debug(_T("Constructor")); |
24 |
kusanagi |
1.1 |
} |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* Get a string with the version info of the algorithm. |
28 |
|
|
*/ |
29 |
|
|
std::string TabDumpReader::GetVersionInfo(void) const { |
30 |
kusanagi |
6.1 |
return "$Header: /home/cvsmanager/yoda/techmodel/TabDumpReader.cpp,v 6.0 2006/02/07 17:11:10 kusanagi Exp $\n"; |
31 |
kusanagi |
1.1 |
} |
32 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
35 |
|
|
* event reader routines for all packet types. |
36 |
|
|
*/ |
37 |
|
|
void TabDumpReader::Init(PamelaRun *run) { |
38 |
kusanagi |
3.1 |
logger->debug(_T("Initialize")); |
39 |
kusanagi |
1.1 |
SetInputStream(run); |
40 |
|
|
run->WriteSubPacket(this, &TabDump, TabDump->Class()); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
/** |
44 |
|
|
* Unpack the TabDump event from an input file. |
45 |
|
|
*/ |
46 |
kusanagi |
2.1 |
void TabDumpReader::RunEvent(int EventNumber, long int length) throw (WrongCRCException){ |
47 |
kusanagi |
1.1 |
|
48 |
kusanagi |
2.2 |
char subData[length]; |
49 |
kusanagi |
3.1 |
UINT16 subCRC; //calculated CRC of the data |
50 |
kusanagi |
2.2 |
UINT16 readCRC; //CRC read from the end of the subpacket |
51 |
kusanagi |
3.1 |
long int dataLength = length - 2; //the block of data |
52 |
kusanagi |
1.1 |
|
53 |
kusanagi |
3.1 |
InputFile->read(subData, sizeof(subData)); |
54 |
|
|
subCRC = CM_Compute_CRC16(0, (UINT8*)subData, dataLength); |
55 |
kusanagi |
2.2 |
readCRC = (((UINT16)(subData[length - 2]<<8))&0xFF00) + (((UINT16)subData[length - 1])&0x00FF); |
56 |
|
|
|
57 |
kusanagi |
4.5 |
if (subCRC != readCRC) throw WrongCRCException(" Wrong CRC for TabDump Packet "); |
58 |
|
|
/*if (subCRC != readCRC) { |
59 |
kusanagi |
3.1 |
logger->error("WRONG CRC FOR TabDump PACKET. Processed anyway for CPU debugging"); |
60 |
kusanagi |
4.5 |
}*/ |
61 |
kusanagi |
2.1 |
|
62 |
|
|
TabDumpRecord* rec; |
63 |
kusanagi |
2.3 |
TabDump->PARAMETER_STAMP = (((UINT32)subData[0]<<24)&0xFF000000) + (((UINT32)subData[1]<<16)&0x00FF0000) + (((UINT32)subData[2]<<8)&0x0000FF00) + (((UINT32)subData[3])&0x000000FF); |
64 |
|
|
long int offset = 4; |
65 |
kusanagi |
2.1 |
int i = 0; |
66 |
|
|
TabDump->Records->Clear(); |
67 |
|
|
TClonesArray &recs = *(TabDump->Records); |
68 |
|
|
while (offset < dataLength){ |
69 |
|
|
rec = new(recs[i++]) TabDumpRecord(); //add a new TabDump |
70 |
|
|
rec->Tab_ID = ((UINT8)subData[offset])&0xFF; |
71 |
|
|
rec->Nrow = ((UINT8)subData[offset+1])&0xFF; |
72 |
|
|
rec->Ncol = ((UINT8)subData[offset+2])&0xFF; |
73 |
|
|
rec->Data = new TArrayI((int)((rec->Nrow)*(rec->Ncol)), (int*)(subData+offset+3)); |
74 |
kusanagi |
3.1 |
offset = offset + sizeof(UINT32)*(rec->Nrow)*(rec->Ncol) + 3; |
75 |
kusanagi |
1.1 |
} |
76 |
kusanagi |
3.1 |
} |