Commit 18f53656 authored by legoc's avatar legoc
Browse files

Modified Cameo apps to us JSON data

parent 0ec202f7
......@@ -152,17 +152,17 @@ int main(int argc, char * argv[]) {
time_t t1 = time(0);
time_t last = time(0);
// string data;
// while (subscriber->receiveBinary(data)) {
string data;
while (subscriber->receiveBinary(data)) {
while (true) {
std::optional<string> data = subscriber->receiveBinary();
if (!data.has_value()) {
break;
}
// while (true) {
// std::optional<string> data = subscriber->receiveBinary();
// if (!data.has_value()) {
// break;
// }
int32_t blockSize = data.value().size() / sizeof(int32_t);
int32_t * block = const_cast<int32_t *>(reinterpret_cast<const int32_t *>(data.value().c_str()));
int32_t blockSize = data.size() / sizeof(int32_t);
int32_t * block = const_cast<int32_t *>(reinterpret_cast<const int32_t *>(data.c_str()));
// processing block
algorithm.process(block, blockSize, blocks);
......@@ -172,16 +172,16 @@ int main(int argc, char * argv[]) {
cout << "#events read " << algorithm.processor().numberOfGoodEvents() << endl;
// publish results
// publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
// publisher->send(algorithm.processor().getCoincidenceRates(), algorithm.processor().getNumberOfCoincidenceRates());
publisher->send(toJSONArray(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels()));
publisher->send(toJSONArray(algorithm.processor().getCoincidenceRates(), algorithm.processor().getNumberOfCoincidenceRates()));
last = current;
}
}
// publish results at the end
// publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
// publisher->send(algorithm.processor().getCoincidenceRates(), algorithm.processor().getNumberOfCoincidenceRates());
publisher->send(toJSONArray(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels()));
publisher->send(toJSONArray(algorithm.processor().getCoincidenceRates(), algorithm.processor().getNumberOfCoincidenceRates()));
time_t t2 = time(0);
......
......@@ -135,17 +135,17 @@ int main(int argc, char * argv[]) {
time_t t1 = time(0);
time_t last = time(0);
// string data;
// while (subscriber->receiveBinary(data)) {
string data;
while (subscriber->receiveBinary(data)) {
while (true) {
std::optional<string> data = subscriber->receiveBinary();
if (!data.has_value()) {
break;
}
// while (true) {
// std::optional<string> data = subscriber->receiveBinary();
// if (!data.has_value()) {
// break;
// }
int32_t blockSize = data.value().size() / sizeof(int32_t);
int32_t * block = const_cast<int32_t *>(reinterpret_cast<const int32_t *>(data.value().c_str()));
int32_t blockSize = data.size() / sizeof(int32_t);
int32_t * block = const_cast<int32_t *>(reinterpret_cast<const int32_t *>(data.c_str()));
// processing block
algorithm.process(block, blockSize, blocks);
......@@ -155,16 +155,16 @@ int main(int argc, char * argv[]) {
cout << "#events read " << algorithm.processor().numberOfGoodEvents() << endl;
// publish results
// publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
// publisher->send(algorithm.processor().getHistograms(), algorithm.processor().getTotalHistogramSize());
publisher->send(toJSONArray(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels()));
publisher->send(toJSONArray(algorithm.processor().getHistograms(), algorithm.processor().getTotalHistogramSize()));
last = current;
}
}
// publish results at the end
// publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
// publisher->send(algorithm.processor().getHistograms(), algorithm.processor().getTotalHistogramSize());
publisher->send(toJSONArray(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels()));
publisher->send(toJSONArray(algorithm.processor().getHistograms(), algorithm.processor().getTotalHistogramSize()));
time_t t2 = time(0);
......
......@@ -67,4 +67,36 @@ void readListModeContextFromPropertyTree(ListModeContext & listModeContext, cons
}
}
std::string toJSONArray(double * data, int size) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartArray();
for (int i = 0; i < size; ++i) {
writer.Double(data[i]);
}
writer.EndArray();
return buffer.GetString();
}
std::string toJSONArray(int32_t * data, int size) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartArray();
for (int i = 0; i < size; ++i) {
writer.Int(data[i]);
}
writer.EndArray();
return buffer.GetString();
}
}
......@@ -22,6 +22,12 @@
#include "../../CrateBoard.h"
#include <boost/property_tree/ptree.hpp>
#include <rapidjson/rapidjson.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/reader.h>
#include <rapidjson/document.h>
namespace lstdpp128 {
/**
......@@ -29,6 +35,16 @@ namespace lstdpp128 {
*/
void readListModeContextFromPropertyTree(ListModeContext & listModeContext, const boost::property_tree::ptree& data);
/**
* Converts a double array into a JSON array.
*/
std::string toJSONArray(double * data, int size);
/**
* Converts an integer array into a JSON array.
*/
std::string toJSONArray(int32_t * data, int size);
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment