[go: up one dir, main page]

Menu

[0a098c]: / daq / DataLogger.cc  Maximize  Restore  History

Download this file

96 lines (77 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
93
94
95
#include <iostream>
#include <unistd.h>
#include <sys/resource.h>
#include "DataLogger.h"
#include "../data/DataFormat.h"
char *DataLogger::LoggerDie = (char *)0xdeaddead;
DataLogger::DataLogger(DAQpp::RunManager *r,
int buffer_size,
bool compress, unsigned long mx_size)
: DAQpp::FileIOManager(compress, mx_size),
run_manager(r), 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())
{
stoplogging = true;
// We write this to wake-up the fifo
std::cout << "Stopping logger" << std::endl;
fifo.write(LoggerDie, sizeof(unsigned int));
plogger.stop();
}
stoplogging = false;
}
void DataLogger::log_data()
{
static int evtn = -1;
unsigned int *data = 0, *zbuf = 0;
size_t sz, bfsiz;
bfsiz = 1;
zbuf = (unsigned int *)realloc(zbuf, bfsiz * sizeof(unsigned int));
data = (unsigned int *)realloc(data, bfsiz * sizeof(unsigned int));
do
{
// get the size of the buffer
fifo.read((char *)data, sizeof(unsigned int));
if ( stoplogging )
break;
plogger.test_cancel();
// paranoia
if ( (data[0]&0xffff0000) != DataHeader)
continue;
sz = data[0] & 0xfff;
// realloc the arrays
if ( bfsiz < sz )
{
zbuf = (unsigned int *)realloc(zbuf, sz * sizeof(unsigned int));
data = (unsigned int *)realloc(data, sz * sizeof(unsigned int));
bfsiz = sz;
}
// Get the real data
fifo.read((char *)(data + 1), (sz - 1)*sizeof(unsigned int));
plogger.test_cancel();
if ( sz != data[sz-1] )
continue;
write((char *)data, sz*sizeof(unsigned int));
if ( evtn != run_manager->get_event_number() )
{
run_manager->get_status().new_written();
evtn = run_manager->get_event_number();
}
}
while (1);
/// close the file
close();
return;
}