1 |
kusanagi |
1.1 |
/** @file |
2 |
kusanagi |
1.2 |
* $Source: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v $ |
3 |
kusanagi |
2.3 |
* $Id: CalibS4Reader.cpp,v 2.2 2004/12/03 22:08:00 kusanagi Exp $ |
4 |
kusanagi |
1.2 |
* $Author: kusanagi $ |
5 |
kusanagi |
1.1 |
* |
6 |
|
|
* Implementation of the LogReader class. |
7 |
|
|
* ToBeDone: |
8 |
|
|
* Control the CRC for the entire data Packet not just for single records |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
#define UINT unsigned int |
12 |
|
|
#define BYTE unsigned char |
13 |
|
|
#include <string> |
14 |
kusanagi |
1.3 |
#include <log4cxx/logger.h> |
15 |
kusanagi |
1.1 |
extern "C" { |
16 |
|
|
#include <sys/time.h> |
17 |
|
|
#include "CRC.h" |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
#include <fstream> |
21 |
|
|
#include "stdio.h" |
22 |
|
|
#include "ReaderAlgorithms.h" |
23 |
kusanagi |
2.3 |
#include "event/physics/S4/S4Event.h" |
24 |
|
|
//#include "event/CalibS4Event.h" |
25 |
kusanagi |
1.1 |
|
26 |
|
|
|
27 |
|
|
using namespace pamela; |
28 |
|
|
using namespace pamela::techmodel; |
29 |
|
|
|
30 |
kusanagi |
1.3 |
static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.CalibS4Reader")); |
31 |
kusanagi |
1.1 |
|
32 |
|
|
/** |
33 |
|
|
* Constructor. |
34 |
|
|
*/ |
35 |
|
|
CalibS4Reader::CalibS4Reader(void): |
36 |
|
|
TechmodelAlgorithm(PacketType::Log, "TechmodelCalibS4Reader") { |
37 |
kusanagi |
1.3 |
logger->debug(_T("Constructor")); |
38 |
kusanagi |
2.3 |
calibS4 = new CalibS4Event(); |
39 |
kusanagi |
1.1 |
} |
40 |
|
|
|
41 |
|
|
/** |
42 |
|
|
* Get a string with the version info of the algorithm. |
43 |
|
|
*/ |
44 |
|
|
std::string CalibS4Reader::GetVersionInfo(void) const { |
45 |
|
|
return |
46 |
kusanagi |
2.3 |
"$Header: /home/cvsmanager/yoda/techmodel/CalibS4Reader.cpp,v 2.2 2004/12/03 22:08:00 kusanagi Exp $\n"; |
47 |
kusanagi |
1.1 |
} |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* Initialize the algorithm with a special run. This will initialize the |
51 |
|
|
* event reader routines for all packet types. |
52 |
|
|
*/ |
53 |
|
|
void CalibS4Reader::Init(PamelaRun *run) { |
54 |
kusanagi |
1.3 |
logger->debug(_T("Initialize")); |
55 |
kusanagi |
1.1 |
SetInputStream(run); |
56 |
kusanagi |
2.3 |
run->WriteSubPacket(this, &calibS4, calibS4->Class()); |
57 |
kusanagi |
1.1 |
} |
58 |
|
|
|
59 |
|
|
/** |
60 |
|
|
* Unpack the CalibS4 event from an input file. |
61 |
|
|
*/ |
62 |
kusanagi |
2.2 |
void CalibS4Reader::RunEvent(int EventNumber, long int dataLength) throw (Exception){ |
63 |
kusanagi |
2.3 |
|
64 |
|
|
int offset; |
65 |
|
|
char subData[2304]; //impulse*(11 + 10 + 01)*eventLength = 128*3*6 |
66 |
|
|
int numRecords = (dataLength/6); |
67 |
|
|
|
68 |
|
|
S4::S4Event* rec; |
69 |
|
|
calibS4->Records->Clear(); |
70 |
|
|
TClonesArray &recs = *(calibS4->Records); |
71 |
|
|
|
72 |
|
|
InputFile->read(subData, sizeof(subData)); |
73 |
|
|
|
74 |
|
|
for(int i = 0; i < numRecords; i++) { |
75 |
|
|
offset = i*6; |
76 |
|
|
rec = new(recs[i]) S4::S4Event(); //add a new S4Event |
77 |
|
|
|
78 |
|
|
rec->S4_REG_STATUS = (((UINT8)subData[offset])&0xF0); |
79 |
|
|
rec->S4_DATA = ((((UINT16)subData[offset]<<8)&0x0FFF) + (((UINT16)subData[offset+1])&0x00FF)); |
80 |
|
|
rec->S4_CMD_NUM = (((UINT8)subData[offset+2])&0xFF); |
81 |
|
|
rec->S4_RESP_LENGHT = ((((UINT16)subData[offset+3]<<8)&0xFF00) + (((UINT16)subData[offset+4])&0x00FF)); |
82 |
|
|
rec->S4_OVERALL_CHKCODE = (((UINT8)subData[offset+5])&0xFF); |
83 |
|
|
} |
84 |
kusanagi |
1.1 |
} |
85 |
|
|
|