1 |
kusanagi |
1.1 |
/** @file |
2 |
|
|
* $Source: /home/cvsmanager/yoda/techmodel/ArrDumpReader.cpp,v $ |
3 |
|
|
* $Id: ArrDumpReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $ |
4 |
|
|
* $Author: kusanagi $ |
5 |
|
|
* |
6 |
|
|
* Implementation of the ArrDumpReader 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 |
|
|
#include "forroutines/anticoinc/ACcalib.h" |
16 |
|
|
int ACcalib(unsigned short* datapointer, struct datastruct* calibpointer); |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
#include "ReaderAlgorithms.h" |
20 |
|
|
|
21 |
|
|
using namespace pamela; |
22 |
|
|
using namespace pamela::techmodel; |
23 |
|
|
|
24 |
|
|
static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.CalibAcReader"); |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* Constructor. |
28 |
|
|
*/ |
29 |
|
|
CalibAcReader::CalibAcReader(void): |
30 |
|
|
TechmodelAlgorithm(PacketType::CalibAc, "TechmodelCalibAc") { |
31 |
|
|
CalibAc = new CalibAcEvent(); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* Get a string with the version info of the algorithm. |
36 |
|
|
*/ |
37 |
|
|
std::string CalibAcReader::GetVersionInfo(void) const { |
38 |
|
|
return "$Header: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n"; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
43 |
|
|
* event reader routines for all packet types. |
44 |
|
|
*/ |
45 |
|
|
void CalibAcReader::Init(PamelaRun *run) { |
46 |
|
|
SetInputStream(run); |
47 |
|
|
run->WriteSubPacket(this, &CalibAc, CalibAc->Class()); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Unpack the CalibAc event from an input file. |
52 |
|
|
*/ |
53 |
|
|
void CalibAcReader::RunEvent(int EventNumber, long int length) { |
54 |
|
|
|
55 |
|
|
char *subData; |
56 |
|
|
char eventCRC[2]; |
57 |
|
|
UINT16 subCRC; //CRC of the data |
58 |
|
|
UINT16 readCRC; //CRC read from the end of the subpacket |
59 |
|
|
long int dataLength; |
60 |
|
|
|
61 |
|
|
//the 2 bytes subtracted belong to the final event CRC bytes |
62 |
|
|
dataLength = length - (long int)2; |
63 |
|
|
|
64 |
|
|
subData = new char[dataLength]; |
65 |
|
|
InputFile->read(subData, sizeof(unsigned char)*dataLength); |
66 |
|
|
subCRC = CM_Compute_CRC16(0, (BYTE*)subData, dataLength); |
67 |
|
|
|
68 |
|
|
//took the final CRC to compare it with the previous calculated CRC of the data |
69 |
|
|
InputFile->read(eventCRC, sizeof(eventCRC)); |
70 |
|
|
readCRC = (((UINT16)(eventCRC[0]<<8))&0xFF00) + (((UINT16)eventCRC[1])&0x00FF); |
71 |
|
|
|
72 |
|
|
if (subCRC == readCRC){ |
73 |
|
|
datastruct output; |
74 |
|
|
int ERROR; |
75 |
|
|
ERROR = ACcalib((unsigned short*)subData, &output); |
76 |
|
|
|
77 |
|
|
CalibAc->header = output.header; |
78 |
|
|
memcpy(CalibAc->status, output.status, sizeof(CalibAc->status)); |
79 |
|
|
memcpy(CalibAc->DAC, output.DAC, sizeof(CalibAc->DAC)); |
80 |
|
|
memcpy(CalibAc->regist, output.regist, sizeof(CalibAc->regist)); |
81 |
|
|
memcpy(CalibAc->time, output.time, sizeof(CalibAc->time)); |
82 |
|
|
CalibAc->n_tr = output.n_tr; |
83 |
|
|
memcpy(CalibAc->hitmap_tr, output.hitmap_tr, sizeof(CalibAc->hitmap_tr)); |
84 |
|
|
memcpy(CalibAc->curve1, output.curve1, sizeof(CalibAc->curve1)); |
85 |
|
|
memcpy(CalibAc->curve2, output.curve2, sizeof(CalibAc->curve2)); |
86 |
|
|
CalibAc->iCRC = output.iCRC; |
87 |
|
|
CalibAc->tail = output.tail; |
88 |
|
|
CalibAc->CRC = output.CRC; |
89 |
|
|
|
90 |
|
|
free(subData); |
91 |
|
|
} else { |
92 |
|
|
cat << log4cpp::Priority::ERROR |
93 |
|
|
<< "Wrong CRC on Subpacket in ArrDump Packet " |
94 |
|
|
<< "\n " << log4cpp::CategoryStream::ENDLINE; |
95 |
|
|
} |
96 |
|
|
} |