Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
parser.h File Reference
#include <map>
#include <string>
#include <vector>
#include <optional>
#include <iostream>

Go to the source code of this file.

Classes

class  Parser
 
struct  Waveform< T >
 
struct  ProbeConfig
 A pair (id,threshold) representing basic information about one probe. More...
 
struct  DOMConfig
 The configuration information for one DOM. More...
 

Functions

template<typename T >
std::optional< Waveform< T > > parseWaveformSamples (const std::string &adf_waveform_line)
 
std::optional< DOMConfigparseDOMConfiguration (const std::string &dom_configuration_line)
 Parse a line that should contain the ADF configuration for a single DOM.
 

Function Documentation

◆ parseWaveformSamples()

template<typename T >
std::optional< Waveform< T > > parseWaveformSamples ( const std::string & adf_waveform_line)

Definition at line 46 of file parser.cc.

47{
48 // remove multiple spaces, if any
49 std::string str(adf_waveform_line);
50
51 std::string::iterator new_end = std::unique(str.begin(), str.end(), [](char a, char b)
52 { return a == b && a == ' '; });
53
54 str.erase(new_end, str.end());
55
56 // now decode the string
57 std::istringstream ins(str);
58 std::string line;
59
60 std::vector<T> waveform_samples;
61 int waveform_id{};
62
63 std::getline(ins, line, ' ');
64 try {
65 waveform_id = std::stoi(line);
66 }
67 catch (std::exception const& ex) {
68 std::cerr << "could not parse the waveform_id:" << ex.what() << "\n";
69 return std::nullopt;
70 }
71
72 size_t nsamples{};
73
74 std::getline(ins, line, ' ');
75 try {
76 nsamples = std::stoi(line);
77 }
78 catch (std::exception const& ex) {
79 std::cerr << "could not parse the waveform_id:" << ex.what() << "\n";
80 return std::nullopt;
81 }
82
83 waveform_samples.reserve(nsamples);
84
85 while (std::getline(ins, line, ' ')) {
86 T sample = atof(line.c_str());
87 waveform_samples.push_back(sample);
88 }
89 if (waveform_samples.size() != nsamples) {
90 std::cerr << "mismatched number of samples : expecting " << nsamples << " but got " << waveform_samples.size() << "\n";
91 return std::nullopt;
92 }
93
94 return Waveform<T>{waveform_id, waveform_samples};
95}

◆ parseDOMConfiguration()

std::optional< DOMConfig > parseDOMConfiguration ( const std::string & dom_configuration_line)

Parse a line that should contain the ADF configuration for a single DOM.

Parameters
linethe DOM configuration for a single DOM, which should be of the form :

DOMID N id_0 threshold_0 ... id_(N-1) threshold_(N-1) debug_write

where N is the number of (id,threshold) pairs to be found on the line (id = probe id, threshold = where to cut the signal)

write_to_debug_flag is an integer that indicate (if non zero) to write the acoustic data from this DOM should be written to a debug file

Returns
a DOMConfig object if the line is valid DOM configuration, otherwise std::nullopt

Definition at line 102 of file parser.cc.

103{
104 if (dom_configuration_line.empty()) {
105 return std::nullopt;
106 }
107 std::stringstream iss(dom_configuration_line);
108 int dom_id;
109 iss >> dom_id;
110 if (iss.eof()) {
111 return std::nullopt;
112 }
113 int number_of_probes;
114 iss >> number_of_probes;
115 if (iss.eof() || number_of_probes <= 0) {
116 return std::nullopt;
117 }
118 std::vector<ProbeConfig> probe_configs;
119 while (probe_configs.size() < number_of_probes) {
120 int id;
121 iss >> id;
122 if (iss.eof()) {
123 return std::nullopt;
124 }
125 int threshold;
126 iss >> threshold;
127 if (iss.eof()) {
128 return std::nullopt;
129 }
130 probe_configs.push_back(ProbeConfig{id, threshold});
131 }
132 if (iss.eof()) {
133 return std::nullopt;
134 }
135 int debug_write;
136 iss >> debug_write;
137 if (!iss.eof()) {
138 return std::nullopt;
139 }
140 return DOMConfig{dom_id, probe_configs, debug_write};
141}
uint32_t dom_id(frame_idx_t idx)
The configuration information for one DOM.
Definition parser.h:66
A pair (id,threshold) representing basic information about one probe.
Definition parser.h:58