-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the option to print values in the print action #63
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ namespace multio::action { | |
Print::Print(const ComponentConfiguration& compConf) : ChainedAction(compConf) { | ||
stream_ = compConf.parsedConfig().getString("stream", "info"); | ||
onlyFields_ = compConf.parsedConfig().getBool("only-fields", false); | ||
includeValues_ = compConf.parsedConfig().getBool("include-data-values",false); | ||
numberOfValues_ = compConf.parsedConfig().getInt("value-count",0); | ||
|
||
if (stream_ == "info") { | ||
os_ = &eckit::Log::info(); | ||
|
@@ -45,7 +47,24 @@ void Print::executeImpl(message::Message msg) { | |
if (!prefix_.empty()) { | ||
(*os_) << prefix_ << ": "; | ||
} | ||
(*os_) << msg << std::endl; | ||
(*os_) << msg << "\n"; | ||
if(includeValues_) { | ||
const auto* data = static_cast<const double*>(msg.payload().data()); | ||
const auto* end = data + (msg.payload().size() / sizeof(double)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our data can also be in 32 bits float instead of 64 bits double. In that case we should check the precision key and handle floats slightly different from doubles. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah you're right. That was a hack that I did because I knew it was a double field that came in. We should discuss if we want to have this in at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think this would only be useful for tiny payloads. I guess there may not be harm including it, but the code will need a bit of tightening up beforehand. Apart from the precision support, we may want to make sure that we always use reference to |
||
|
||
if (!data || data == end) { | ||
throw eckit::SeriousBug{ | ||
"Payload is empty: Cannot print data: " + msg.metadata().toString(), Here()}; | ||
} | ||
|
||
// Print the payload data | ||
int count = 0; | ||
for (auto it = data; (it != end) && count<numberOfValues_; ++it) { | ||
(*os_) << *it << " "; | ||
++count; | ||
} | ||
(*os_) << std::endl; | ||
} | ||
} | ||
executeNext(std::move(msg)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a
start-index
option (default to 0) to indicate at which index to start printing? I think this would be especially useful if the data starts with missing values.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know from which index missing values begin/end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you can look at the bitmap and count. We could automate this and accept this option to be set to "first-non-missing", but that requires a bit more work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably rather just have a mechanism to print missing values, i.e. write the string 'missing' or 'n/a' instead of a numeric value.