-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHFC.h
118 lines (96 loc) · 2.5 KB
/
HFC.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
#ifndef __HFC_H
#define __HFC_H
#include <iostream>
#include <list>
#include "global.h"
using namespace std;
//
// HFC for preproccessing a file made by GEB
// (Gretina Event Builder)
// GEB does sometimes odd things:
// 1) In any mode events out of time sequence appear
// 2) In Mode 3 (traces) several digitizer channels
// are packed in one payload with one GEB header
// instead GEB, a channel, GEB, a channel, GEB, ...
//
// HFC takes events (geb header, data) and write them
// in time-ordered manner. It holds a user-defined
// number of events in memory for performing re-ordering.
// If memory is too small, events which do not fit will
// be dicarded.
//
// User methods:
//
// constructers
// HFC(int num, FILE* out)
// HFC(int num)
// HFC(FILE* out)
// HFC()
// num is user-defined memory depth
// out is file pointer where output is written (default NULL)
//
//
// bool add(gebData aGeb, BYTE* data);
// sending event to HFC. TS from aGeb is
// used for time ordering. Returns false
// if event can't be processed as its TS
// is too 'old'
//
// bool add(long long TS, int type, int length, BYTE* data);
// sending event to HFC. TS used for time ordering.
// Same return value as for other add method.
//
// void flush();
// flushs the events held im memory to file. IMPORTANT: This
// method has to be used before closing output file or
// destroying an HFC object.
//
// void printstatus();
// prints statistics
//
struct gebData
{
int type;
int length; // payload in bytes
long long timestamp;
};
struct HFC_item
{
gebData geb;
BYTE* data;
};
class HFC
{
private:
int m_memdepth;
FILE *m_file;
int m_evt;
list<HFC_item*> m_HFClist;
list<HFC_item*>::iterator m_HFClast_it;
int m_discarded;
void init(int num, FILE* out);
// we won't expand list, but discard one
// item by writing it.
bool addToFullList(HFC_item* hfc);
// Well, this actually does the writing
bool writeItem(HFC_item* hfc);
// An item gets inserted at 'right'
// position in list, list gets expanded
bool insert(HFC_item* hfc);
public:
HFC();
HFC(int num); //num == #events in memory
HFC(FILE* out);
HFC(int num, FILE* out);
// 'user' method for adding event to list
// data will be copied, so user can free/
// change data block she/he is pointing to.
bool add(gebData aGeb, BYTE* data);
bool add(long long TS, int type, int length, BYTE* data);
// 'user' method for writing all list items
// stored in memory
void flush();
//
void printstatus();
};
#endif