Commit 0385e792 authored by Alexander Ferk's avatar Alexander Ferk
Browse files

JSONWriter will now seperate events

parent 13ca596f
......@@ -53,6 +53,12 @@ StatusCode JSONWriter::run(std::shared_ptr<Clipboard> clipboard) {
auto data = clipboard->getAll();
LOG(DEBUG) << "Clipboard has " << data.size() << " different object types.";
// open a new subarray for this event
if(m_eventNumber == 0)
*output_file_ << "[" << std::endl;
else
*output_file_ << "," << std::endl << "[" << std::endl;
for(auto& block : data) {
try {
auto type_idx = block.first;
......@@ -77,7 +83,12 @@ StatusCode JSONWriter::run(std::shared_ptr<Clipboard> clipboard) {
auto objects = std::static_pointer_cast<ObjectVector>(detector_block.second);
for(auto& object : *objects) {
*output_file_ << TBufferJSON::ToJSON(object) << "," << std::endl;
*output_file_ << TBufferJSON::ToJSON(object);
// add delimiter for all but the last element
if(object == objects->back() && detector_block == *(--block.second.end()) && block == *(--data.end())) {
*output_file_ << std::endl;
} else
*output_file_ << "," << std::endl;
}
}
} catch(...) {
......@@ -85,7 +96,8 @@ StatusCode JSONWriter::run(std::shared_ptr<Clipboard> clipboard) {
return StatusCode::NoData;
}
}
// close event array
*output_file_ << "]";
// Increment event counter
m_eventNumber++;
......@@ -96,7 +108,7 @@ StatusCode JSONWriter::run(std::shared_ptr<Clipboard> clipboard) {
void JSONWriter::finalise() {
// finalize the JSON Array, add one empty Object to satisfy JSON Rules
*output_file_ << "{" << std::endl << "}" << std::endl << "]";
*output_file_ << std::endl << "]";
// Print statistics
LOG(STATUS) << "Wrote " << m_eventNumber - 1 << " events to file:" << output_file_name_ << std::endl;
LOG(STATUS) << "Wrote " << m_eventNumber << " events to file:" << output_file_name_ << std::endl;
}
......@@ -4,14 +4,14 @@
**Status**: Functional
### Description
This module writes objects to a file as JSON array using `TBufferJSON::ToJASON(object)`. For this, the data content of the selected objects available on the clipboard are printed to the specified file. Beware that this results in a flat structure unlike the root file.
This module writes objects to a file as JSON array using `TBufferJSON::ToJASON(object)`. The data of the selected objects available on the clipboard is written to a new sub-array for each event. Beware that this results in a flat structure unlike the root file.
With `include` and `exclude` certain object types can be selected to be printed.
### Parameters
* `file_name` : Name of the data file to create, relative to the output directory of the framework. The file extension `.json` will be appended if not present.
* `include` : Array of object names to write to the ASCII text file, all other object names are ignored (cannot be used together simultaneously with the *exclude* parameter).
* `exclude`: Array of object names that are not written to the ASCII text file (cannot be used together simultaneously with the *include* parameter).
* `include` : Array of object names to write to the JSON file, all other object names are ignored (cannot be used together simultaneously with the *exclude* parameter).
* `exclude`: Array of object names that are not written to the JSON file (cannot be used together simultaneously with the *include* parameter).
### Usage
```toml
......
......@@ -31,4 +31,4 @@ chi2ndof_cut = 8
time_cut_frameedge = 10ns
#DATASET timepix3tel_ebeam120
#PASS [F:JSONWriter] Wrote 15000 events to file:
#PASS [F:JSONWriter] Wrote 15001 events to file:
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