/[PAMELA software]/yoda/techmodel/CalibAcReader.cpp
ViewVC logotype

Contents of /yoda/techmodel/CalibAcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Tue Sep 21 20:24:33 2004 UTC (20 years, 2 months ago) by kusanagi
Branch: MAIN
Changes since 1.4: +7 -9 lines
Commit toward log4cxx plus new packets types Reader

1 /** @file
2 * $Source: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v $
3 * $Id: CalibAcReader.cpp,v 1.4 2004/08/25 10:14:26 kusanagi Exp $
4 * $Author: kusanagi $
5 *
6 * Implementation of the ArrDumpReader class.
7 */
8
9 #include <string>
10 #include <log4cxx/logger.h>
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 static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibAcReader"));
25
26 /**
27 * Constructor.
28 */
29 CalibAcReader::CalibAcReader(void):
30 TechmodelAlgorithm(PacketType::CalibAc, "TechmodelCalibAc") {
31 logger->debug(_T("Constructor"));
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.4 2004/08/25 10:14:26 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 logger->debug(_T("Initialize"));
48 SetInputStream(run);
49 run->WriteSubPacket(this, &CalibAc, CalibAc->Class());
50 }
51
52 /**
53 * Unpack the CalibAc event from an input file.
54 */
55 void CalibAcReader::RunEvent(int EventNumber, long int length) {
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->temp, output.temp, sizeof(CalibAc->temp));
81 memcpy(CalibAc->DAC1, output.DAC1, sizeof(CalibAc->DAC1));
82 memcpy(CalibAc->DAC2, output.DAC2, sizeof(CalibAc->DAC2));
83 memcpy(CalibAc->regist, output.regist, sizeof(CalibAc->regist));
84 memcpy(CalibAc->time, output.time, sizeof(CalibAc->time));
85 CalibAc->n_tr = output.n_tr;
86 memcpy(CalibAc->hitmap_tr, output.hitmap_tr, sizeof(CalibAc->hitmap_tr));
87 memcpy(CalibAc->curve1, output.curve1, sizeof(CalibAc->curve1));
88 memcpy(CalibAc->curve2, output.curve2, sizeof(CalibAc->curve2));
89 CalibAc->iCRC = output.iCRC;
90 CalibAc->tail = output.tail;
91 CalibAc->CRC = output.CRC;
92 } else {
93 logger->warn(_T("Wrong CRC on Subpacket in ArrDump Packet "));
94 }
95 delete [] subData;
96 }

  ViewVC Help
Powered by ViewVC 1.1.23