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