-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprenexusrenderer.cpp
192 lines (157 loc) · 4.74 KB
/
prenexusrenderer.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <boost/date_time/gregorian/greg_date.hpp>
#include <boost/date_time/posix_time/posix_time_config.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/posix_time/time_formatters.hpp>
#include <boost/date_time/time.hpp>
#include <stdint.h>
#include <sys/types.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include "allowedtypes.hpp"
#include "bin_file.hpp"
//include <time.h>
#include "prenexusrenderer.hpp"
#include "prenexustypes.hpp"
using allowed::AllowedTypes;
using std::ostream;
using std::runtime_error;
using std::size_t;
using std::string;
using std::stringstream;
using std::vector;
namespace prenexus {
namespace { // anonymous namespace
static const string EOL("\n");
static const size_t BLOCK_SIZE = 4096;
AllowedTypes getTypes() {
AllowedTypes types;
types.append("event");
types.append("pulseid");
types.append("oldpulseid");
types.append("rtdl");
return types;
}
} // anonymous namespace
const string getKnownDataDescr()
{
stringstream msg;
msg << getTypes();
return msg.str();
}
const bool hasDataDescr(const std::string & descr) {
return (getTypes().has(descr));
}
PrenexusRenderer::PrenexusRenderer()
{
this->types = getTypes();
}
PrenexusRenderer::~PrenexusRenderer()
{
}
void PrenexusRenderer::setDataDescr(const string &descr)
{
if (! this->types.has(descr)) {
std::stringstream msg;
msg << "Encountered unknown type \"" << descr << "\". Allowed types are: "
<< this->types;
throw runtime_error(msg.str());
}
this->m_dataDescr = descr;
}
/// Max allowed nanoseconds in the time; 2^62-1
static int64_t MAX_NANOSECONDS = 4611686018427387903LL;
/// Max allowed seconds in the time
static int64_t MAX_SECONDS = 4611686017LL;
/// Min allowed nanoseconds in the time; -2^62+1
static int64_t MIN_NANOSECONDS = -4611686018427387903LL;
/// Min allowed seconds in the time
static int64_t MIN_SECONDS = -4611686017LL;
/// The epoch for GPS times.
static const boost::posix_time::ptime GPS_EPOCH(boost::gregorian::date(1990, 1, 1));
string toStr(const uint32_t seconds, const uint32_t nanoseconds)
{
// turn it into a ptime
boost::posix_time::ptime ptime_version
= GPS_EPOCH + boost::posix_time::time_duration(0,0,seconds, nanoseconds);
return to_iso_extended_string(ptime_version);
}
void printValue(ostream & os, const DasEvent & value)
{
os << value.tof << " \t" << value.pid;
}
void printValue(ostream & os, const Pulse & value)
{
os << toStr(value.seconds, value.nanoseconds) << " \t"
<< value.event_index << " \t" << value.pCurrent;
}
void printValue(ostream & os, const OldPulse & value)
{
os << toStr(value.seconds, value.nanoseconds) << " \t" << value.event_index;
}
void printValue(ostream & os, const Rtdl & value)
{
os << toStr(value.seconds, value.nanoseconds) << " \t"
<< value.pulseType << "\t"
<< value.vetoStatus << "\t"
<< value.pulseCurrent << "\t"
<< value.spare;
}
template <typename ComplexT>
void PrenexusRenderer::innerShowData(BinFile &file, size_t offset, size_t length)
{
// length is required by the interface but not used
(void)length;
// cache whether or not to show the data
bool showLines = this->showLines();
// this is used for printing line numbers
size_t myOffset = 0;
if ((offset % sizeof(ComplexT)) == 0)
myOffset = offset / sizeof(ComplexT);
// set up to do a streaming read
size_t size = file.num_items(sizeof(ComplexT));
size_t num_read = BLOCK_SIZE;
if (size < num_read)
num_read = size;
// parse the file and print
size_t pos = 0;
vector<ComplexT> data;
data.reserve(num_read);
while (pos < size) {
file.read(data, num_read);
if (!(data.empty())) {
if (!this->quiet())
{
for (size_t i = 0; i < num_read; i++)
{
if (showLines)
std::cout << (myOffset + i + 1) << " \t";
printValue(std::cout, data[i]);
std::cout << EOL;
}
}
}
// increment for the next time through the loop
myOffset += num_read;
pos += num_read;
if (pos + num_read > size)
num_read = size - pos;
}
}
void PrenexusRenderer::showData(BinFile & file, size_t offset, size_t length)
{
file.seek(offset);
if (this->m_dataDescr.empty())
throw runtime_error("Have an empty data description");
if (this->m_dataDescr == "event")
this->innerShowData<DasEvent>(file, offset, length);
else if (this->m_dataDescr == "pulseid")
this->innerShowData<Pulse>(file, offset, length);
else if (this->m_dataDescr == "oldpulseid")
this->innerShowData<OldPulse>(file, offset, length);
else if (this->m_dataDescr == "rtdl")
this->innerShowData<Rtdl>(file, offset, length);
else
throw runtime_error("The code should have never gotten to this place");
}
} // namespace prenexus