27 #ifndef NIDAS_DYNLD_RAF_SYNCRECORDREADER_H
28 #define NIDAS_DYNLD_RAF_SYNCRECORDREADER_H
39 #ifdef SYNC_RECORD_JSON_OUTPUT
40 #include <json/json.h>
43 namespace nidas {
namespace dynld {
namespace raf {
49 nidas::util::
Exception(
"SyncRecHeaderException",
50 std::string(
"expected: \"") + expect +
51 "\", got: \"" + got +
"\"")
55 nidas::util::
Exception(
"SyncRecHeaderException",msg)
120 const std::list<const SyncRecordVariable*>
getVariables()
121 throw(nidas::util::Exception);
166 getSyncRecOffset(const nidas::core::
Variable* var)
170 getLagOffset(const nidas::core::
Variable* var)
171 throw (SyncRecHeaderException);
244 #ifdef SYNC_RECORD_JSON_OUTPUT
246 write_sync_record_header_as_json(std::ostream& json,
247 const std::string& textheader)
251 std::istringstream iss(textheader);
252 std::vector<std::string> lines;
254 while (getline(iss, line))
259 lines.push_back(line);
263 header.resize(lines.size());
264 for (
unsigned int i = 0; i < lines.size(); ++i)
266 header[i] = lines[i];
268 root[
"header"] = header;
274 json_sync_record_header_as_string(Json::Value& root)
276 Json::Value& header = root[
"header"];
278 std::ostringstream oss;
279 for (
unsigned int i = 0; i < header.size(); ++i)
281 oss << header[i].asString() <<
"\n";
288 write_sync_record_data_as_json(std::ostream& json,
294 root[
"time"] = Json::UInt64(tt);
295 root[
"numValues"] = (int)numValues;
302 data.resize(numValues);
304 for (
unsigned int i = 0; i < numValues; ++i)
306 snprintf(buf,
sizeof(buf),
"%.16g", rec[i]);
314 double_to_string(
double value)
317 snprintf(buf,
sizeof(buf),
"%.16g", value);
323 write_sync_variable_as_json(
const SyncRecordVariable* var,
327 Json::Value variable;
328 Json::Value values(Json::arrayValue);
335 size_t varoffset = var->getSyncRecOffset();
336 int irate = (int)ceil(var->getSampleRate());
337 int vlen = var->getLength();
339 values.resize(vlen*irate);
340 for (
int i = 0; i < vlen*irate; ++i)
342 values[i] = double_to_string(rec[varoffset+i]);
344 variable[
"name"] = var->getName();
345 variable[
"values"] = values;
347 size_t lagoffset = var->getLagOffset();
350 if (!std::isnan(rec[lagoffset]))
351 vtime += (int) rec[lagoffset];
352 variable[
"time"] = Json::UInt64(vtime);
353 variable[
"lagoffset"] = double_to_string(rec[lagoffset]);
359 write_sync_record_as_json(std::ostream& json,
dsm_time_t tt,
360 const double* record,
int nvalues,
361 std::vector<const SyncRecordVariable*>& vars)
364 root[
"time"] = Json::UInt64(tt);
365 root[
"numValues"] = nvalues;
366 Json::Value& data = root[
"data"];
367 std::vector<const SyncRecordVariable*>::const_iterator it;
368 for (it = vars.begin(); it != vars.end(); ++it)
370 Json::Value variable = write_sync_variable_as_json(*it, tt, record);
371 data.append(variable);
const std::string & textHeader()
Definition: SyncRecordReader.h:147
const std::list< const SyncRecordVariable * > getVariables()
Get the list of variables in a sync record.
Definition: SyncRecordReader.cc:634
Definition: SyncServer.h:56
std::string flightName
Definition: SyncRecordReader.h:219
std::string _header
Definition: SyncRecordReader.h:227
SyncRecHeaderException * headException
Definition: SyncRecordReader.h:205
bool _debug
Definition: SyncRecordReader.h:225
void endOfStream()
Signal the end of the sample stream, meaning EOF is reached once the queue is empty.
Definition: SyncRecordReader.cc:718
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
Class describing a sampled variable.
Definition: Variable.h:46
const std::string & getProjectName() const
Definition: SyncRecordReader.h:104
void init()
Definition: SyncRecordReader.cc:112
SampleInputStream * inputStream
Definition: SyncRecordReader.h:192
const SyncRecordVariable * getVariable(const std::string &name) const
Get a pointer to a SyncRecordVariable, searching by name.
Definition: SyncRecordReader.cc:643
virtual void flush()
Ask that this SampleClient send out any buffered Samples that it may be holding.
Definition: SyncRecordReader.cc:709
void scanHeader(const Sample *samp)
Definition: SyncRecordReader.cc:207
size_t read(dsm_time_t *tt, double *ptr, size_t len)
Read a sync record.
Definition: SyncRecordReader.cc:568
std::string getQuotedString(std::istringstream &str)
Definition: SyncRecordReader.cc:532
std::list< SampleTag * > sampleTags
Definition: SyncRecordReader.h:207
const std::string & getFlightName() const
Definition: SyncRecordReader.h:108
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
SyncRecordReader handles sync samples and provides an interface to access Variables and read sync rec...
Definition: SyncRecordReader.h:85
A Variable associated with a SyncRecord.
Definition: SyncRecordVariable.h:38
const std::string & getConfigName()
After creating a SyncRecordReader on a socket, this method returns the config name from the SampleInp...
Definition: SyncRecordReader.h:178
A channel for Input or Output of data.
Definition: IOChannel.h:64
SyncRecordReader & operator=(const SyncRecordReader &)
No assignment.
size_t getNumValues() const
Get number of data values in a sync record.
Definition: SyncRecordReader.h:133
int throw(SyncRecHeaderException)
Definition: SyncRecordReader.cc:761
Definition: Exception.h:35
const std::string & getSoftwareVersion() const
Definition: SyncRecordReader.h:110
std::deque< const Sample * > _syncRecords
Place to stash sample records received as a SampleClient.
Definition: SyncRecordReader.h:233
nidas::util::Cond _qcond
Definition: SyncRecordReader.h:229
std::map< std::string, const SyncRecordVariable * > variableMap
Definition: SyncRecordReader.h:211
void readKeyedQuotedValues(std::istringstream &header)
Definition: SyncRecordReader.cc:541
virtual ~SyncRecordReader()
Definition: SyncRecordReader.cc:166
std::string softwareVersion
Definition: SyncRecordReader.h:221
std::list< const SyncRecordVariable * > variables
Definition: SyncRecordReader.h:209
int len
Definition: sing.cc:934
Interface to a data sample.
Definition: Sample.h:189
bool _eoq
Definition: SyncRecordReader.h:230
Definition: IOException.h:37
time_t startTime
Definition: SyncRecordReader.h:223
A wrapper class for a Posix condition variable.
Definition: ThreadSupport.h:245
Exception(const std::string &type, const std::string &n, const std::string &m)
Definition: Exception.h:41
std::string projectName
Definition: SyncRecordReader.h:215
SyncRecordReader(IOChannel *iochan)
Constructor of a SyncRecordReader to a connected IOChannel.
Definition: SyncRecordReader.cc:64
std::string _sampleStreamConfigName
Definition: SyncRecordReader.h:235
const Sample * nextSample()
Definition: SyncRecordReader.cc:654
const std::string & getTailNumber() const
Definition: SyncRecordReader.h:106
time_t getStartTime() const
Get UNIX time of the start time of data in the SyncRecords.
Definition: SyncRecordReader.h:115
std::string aircraftName
Definition: SyncRecordReader.h:217
bool _read_sync_server
When true, explicitly read from the SyncServer, if given.
Definition: SyncRecordReader.h:198
SyncServer * syncServer
Definition: SyncRecordReader.h:193
size_t numDataValues
Definition: SyncRecordReader.h:213
virtual bool receive(const Sample *s)
Method called to pass a sample to this client.
Definition: SyncRecordReader.cc:684