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

Annotation of /yoda/techmodel/CalibAcReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Sat Jul 17 20:03:38 2004 UTC (20 years, 5 months ago) by kusanagi
Branch: MAIN
CVS Tags: Rev040729
Changes since 1.1: +22 -22 lines
*** empty log message ***

1 kusanagi 1.1 /** @file
2 kusanagi 1.2 * $Source: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v $
3     * $Id: CalibAcReader.cpp,v 1.1 2004/07/08 12:31:42 kusanagi Exp $
4 kusanagi 1.1 * $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 kusanagi 1.2 #include "forroutines/anticounter/ACcalib.h"
16     extern int ACcalib(int length, unsigned short* datapointer, struct datastruct* calibpointer);
17 kusanagi 1.1 }
18    
19     #include "ReaderAlgorithms.h"
20    
21     using namespace pamela;
22     using namespace pamela::techmodel;
23    
24 kusanagi 1.2
25 kusanagi 1.1 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 kusanagi 1.2 return "$Header: /home/cvsmanager/yoda/techmodel/CalibAcReader.cpp,v 1.1 2004/07/08 12:31:42 kusanagi Exp $\n";
40 kusanagi 1.1 }
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 kusanagi 1.2 datastruct output;
75     int ERROR;
76     ERROR = ACcalib(dataLength, (unsigned short*)subData, &output);
77 kusanagi 1.1
78 kusanagi 1.2 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     free(subData);
91 kusanagi 1.1 } else {
92     cat << log4cpp::Priority::ERROR
93     << "Wrong CRC on Subpacket in ArrDump Packet "
94     << "\n " << log4cpp::CategoryStream::ENDLINE;
95     }
96     }

  ViewVC Help
Powered by ViewVC 1.1.23