forked from frmeier/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastream.h
120 lines (87 loc) · 2.59 KB
/
datastream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// datastream.h
#pragma once
#include <stdint.h>
#include <list>
#include <vector>
#include "config.h"
#include "psi46test.h"
#include "datapipe.h"
#include "protocol.h"
using namespace std;
// === Binary Data Record Format ============================================
struct CDataRecord
{
unsigned int eventNr;
vector<uint16_t> data;
void Print(CProtocol &f);
};
struct CPixel
{
int raw;
int x;
int y;
int pulseheight;
void DecodeRaw();
};
struct CRocEvent
{
unsigned long eventNr;
unsigned short header;
list<CPixel> pixel;
};
// === Data Sources =========================================================
// --- pixelDTB
#define DTB_SOURCE_BLOCK_SIZE 16384
class CBinaryDTBSource : public CSource<uint16_t>
{
CTestboard *tb;
uint16_t lastSample;
unsigned int pos;
vector<uint16_t> buffer;
uint16_t FillBuffer();
uint16_t Read() { return (pos < buffer.size()) ? lastSample = buffer[pos++] : FillBuffer(); }
uint16_t ReadLast() { return lastSample; }
public:
CBinaryDTBSource(CTestboard &src) : tb(&src), lastSample(0), pos(0) { buffer.reserve(DTB_SOURCE_BLOCK_SIZE); }
};
// --- File
#define FILE_SOURCE_BLOCK_SIZE 16384
class CBinaryFileSource : public CSource<uint16_t>
{
FILE *f;
uint16_t lastSample;
unsigned int size;
unsigned int pos;
vector<uint16_t> buffer;
uint16_t FillBuffer();
uint16_t Read() { return (pos < size) ? lastSample = buffer[pos++] : FillBuffer(); }
uint16_t ReadLast() { return lastSample; }
public:
CBinaryFileSource() : f(0), lastSample(0), size(0), pos(0) { buffer.reserve(FILE_SOURCE_BLOCK_SIZE); }
~CBinaryFileSource() { Close(); }
bool Open(const char *filename) { return (f = fopen(filename, "rb")) != 0; }
void Close() { if (f) { fclose(f); f = 0; } }
};
// === CDataRecordScanner (CDataPipe<uint16_t, CRecord*>) ===================
class CDataRecordScanner : public CDataPipe<uint16_t, CDataRecord*>
{
unsigned long currentEventNr;
CDataRecord record;
CDataRecord* Read();
CDataRecord* ReadLast() { return &record; }
public:
CDataRecordScanner() : currentEventNr(0) {}
};
// === CDecoder (CDataRecord*, CRocEvent*) ==================================
class CRocDecoder : public CDataPipe<CDataRecord*, CRocEvent*>
{
CRocEvent roc_event;
CRocEvent* Read();
CRocEvent* ReadLast() { return &roc_event; }
};
// === CAnalyzer (CRocEvent*, CRocEvent*) ===================================
class CAnalyzer : public CDataPipe<CRocEvent*, CRocEvent*>
{
CRocEvent* Read() { return Get(); };
CRocEvent* ReadLast() { return GetLast(); }
};