[go: up one dir, main page]

Menu

[5c152e]: / test / DataLogger.cc  Maximize  Restore  History

Download this file

93 lines (76 with data), 2.2 kB

 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
#include <iostream>
#include <unistd.h>
#include <DAQ++/logger.h>
#include "DataLogger.h"
DataLogger::DataLogger(DAQpp::RunManager *r,
int buffer_size,
bool compress, unsigned long mx_size)
: DAQpp::FileIOManager(compress, mx_size),
fifo(buffer_size),
stoplogging(false) , plogger(this)
{
}
DataLogger::~DataLogger()
{}
void DataLogger::start_logging()
{
stoplogging = false;
fifo.reset();
plogger.start();
}
void DataLogger::stop_logging()
{
if ( plogger.is_running() )
{
unsigned long dummy = 0xdeaddead;
stoplogging = true;
// we write this to wake-up the fifo
fifo.write((char *)&dummy, sizeof(unsigned long));
plogger.stop();
}
stoplogging = false;
}
void DataLogger::log_data()
{
unsigned long *data = 0, *zbuf = 0;
size_t sz, bfsiz;
bfsiz = 1;
zbuf = (unsigned long *)realloc(zbuf, bfsiz * sizeof(unsigned long));
data = (unsigned long *)realloc(data, bfsiz * sizeof(unsigned long));
do
{
// get the size of the buffer
fifo.read((char *)data, sizeof(unsigned long));
if ( stoplogging )
break;
plogger.test_cancel();
// paranoia
if ( (data[0]&0xffff0000) != 0xcafe0000)
{
DAQpp::ostream os;
os << DAQpp::loglevel(DAQpp::Log::critical) << "bad event" << std::endl;
continue;
}
sz = data[0] & 0xfff;
// realloc the arrays
if ( bfsiz < sz )
{
zbuf = (unsigned long *)realloc(zbuf, sz * sizeof(unsigned long));
data = (unsigned long *)realloc(data, sz * sizeof(unsigned long));
bfsiz = sz;
}
// Get the real data
fifo.read((char *)(data + 1), (sz - 1)*sizeof(unsigned long));
if ( sz != data[sz-1] )
{
DAQpp::ostream os;
os << DAQpp::loglevel(DAQpp::Log::critical) << "data corrupted" << std::endl;
continue;
}
write((char *)data, sz*sizeof(unsigned long));
}
while (1);
// close the file
close();
return;
}