11 #include <fmt/format.h>
20 std::ostream&
operator<<(std::ostream& os, std::shared_ptr<daqif::DaqStatus>
const& s) {
21 os << std::setprecision(std::numeric_limits<long double>::digits10 + 1);
23 <<
" id: " << s->getId() <<
"\n"
24 <<
" file_id: " << s->getFileId() <<
"\n"
25 <<
" state: \"" <<
ToString(s->getState()) <<
"\"\n"
26 <<
" substate: \"" <<
ToString(s->getSubState()) <<
"\"\n"
27 <<
" error: \"" << (s->getError() ?
"true" :
"false") <<
"\n"
28 <<
" message: " << s->getMessage() <<
"\n"
29 <<
" result: " << s->getResult() <<
"\n"
30 <<
" timestamp: " << s->getTimestamp();
36 std::ostream&
operator<<(std::ostream& os, std::shared_ptr<daqif::DaqReply>
const& s) {
38 <<
" id: " << s->getId() <<
"\n"
39 <<
" error: " << (s->getError() ?
"true" :
"false") <<
"\n";
43 std::ostream&
operator<<(std::ostream& os, std::shared_ptr<daqif::AwaitDaqReply>
const& s) {
44 os <<
"AwaitDaqReply:\n"
45 <<
" timeout: " << (s->getTimeout() ?
"true" :
"false") <<
"\n"
46 <<
" status: " << s->getStatus() <<
"\n";
51 operator<<(std::ostream& os, std::vector<std::shared_ptr<daqif::DaqStatus>>
const& vec) {
52 for (
auto const& s : vec) {
60 os << std::setprecision(std::numeric_limits<long double>::digits10 + 1);
75 << (s.t->getError() ?
"true" :
"false")
81 << s.t->getTimestamp() <<
"\n"
87 operator<<(std::ostream& os,
JsonPrint<std::vector<std::shared_ptr<daqif::DaqStatus>>>
const& vec) {
90 for (
auto const& s : vec.t) {
93 if (num < vec.t.size()) {
107 << (s.t->getError() ?
"true" :
"false") <<
"\n";
117 << (s.t->getTimeout() ?
"true" :
"false")
127 os <<
"\"" << s.
t <<
"\"";
138 sub->add_option(
"logger", m_logger,
"Logger name");
139 sub->add_option(
"level", m_level,
"Log level");
143 ::daqif::OcmDaqControlSync& daq_cmds,
145 auto log_info =
m_args.
mal->createDataEntity<stdif::LogInfo>();
146 log_info->setLogger(m_logger);
147 log_info->setLevel(m_level);
148 auto reply = std_cmds.SetLogLevel(log_info);
152 std::cout <<
"Reply: " << reply << std::endl;
157 sub->add_option(
"--id",
m_id,
"DAQ ID");
158 sub->add_option(
"--prefix",
m_prefix,
"File prefix");
159 sub->add_option(
"--properties",
m_properties,
"JSON properties");
165 ::daqif::OcmDaqControlSync& daq_cmds,
172 std::cout <<
"Reply: " << reply << std::endl;
177 auto file_or_json = [](std::string
const& arg) -> std::string {
178 if (arg.size() > 1 && arg.front() ==
'@') {
179 auto path = arg.substr(1);
181 std::string file_body((std::istreambuf_iterator<char>(std::cin)),
182 (std::istreambuf_iterator<char>()));
185 std::ifstream f(path);
187 throw std::invalid_argument(
188 fmt::format(
"File not found or readable: {}", arg.substr(1)));
190 std::string file_body((std::istreambuf_iterator<char>(f)),
191 (std::istreambuf_iterator<char>()));
198 sub->add_option(
"specification",
200 "JSON specification. Load from file by prefixing with '@', e.g. @file.json\n"
201 "or from stdin '-' with @-")
202 ->transform(file_or_json)
207 ::daqif::OcmDaqControlSync& daq_cmds,
209 auto reply = daq_cmds.StartDaqV2(
m_spec);
213 std::cout <<
"Reply: " << reply << std::endl;
218 sub->add_option(
"id", m_id,
"DAQ ID");
219 sub->add_option(
"keywords", m_keywords,
"JSON encoded list of keywords");
223 ::daqif::OcmDaqControlSync& daq_cmds,
225 auto reply = daq_cmds.UpdateKeywords(m_id, m_keywords);
229 std::cout <<
"Reply: " << reply << std::endl;
234 sub->add_option(
"id", m_id,
"DAQ ID");
235 sub->add_option(
"state", m_state,
"State to await");
236 sub->add_option(
"substate", m_substate,
"Substate to await");
237 sub->add_option(
"timeout", m_timeout,
"timeout in [fractional] seconds");
239 auto min_timeout = m_timeout + 2;
241 std::cerr <<
"Note: Setting request timeout to " << min_timeout
242 <<
"s due to await timeout exceeding request timeout\n";
243 m_args.timeout = min_timeout;
249 ::daqif::OcmDaqControlSync& daq_cmds,
251 auto state = daqif::FromString<daqif::DaqState>(m_state);
252 auto substate = daqif::FromString<daqif::DaqSubState>(m_substate);
253 auto reply = daq_cmds.AwaitDaqState(m_id, state, substate, m_timeout);
257 std::cout <<
"Reply: " << reply << std::endl;
Contains support functions for daqif.
std::string_view ToString(daqif::DaqState state) noexcept
Contains parse functions for daqif.
std::ostream & operator<<(std::ostream &os, std::shared_ptr< daqif::DaqStatus > const &s)
void Handle(::stdif::StdCmdsSync &std_cmds, ::daqif::OcmDaqControlSync &daq_cmds, CLI::App *arg) override
Receives a parsed variables_map that include the options added with AddOptions.
void AddOptions(CLI::App *app) override
Add arguments to command.
virtual void AddOptions(CLI::App *app)
Add arguments to command.
Requestor(CommonArgs &args)
virtual void Handle(::stdif::StdCmdsSync &std_cmds, ::daqif::OcmDaqControlSync &daq_cmds, CLI::App *arg) override
Receives a parsed variables_map that include the options added with AddOptions.
virtual void AddOptions(CLI::App *app) override
Add arguments to command.
std::string m_primary_sources
void AddOptions(CLI::App *app) override
Add arguments to command.
void Handle(::stdif::StdCmdsSync &std_cmds, ::daqif::OcmDaqControlSync &daq_cmds, CLI::App *arg) override
Receives a parsed variables_map that include the options added with AddOptions.
std::string m_metadata_sources
void Handle(::stdif::StdCmdsSync &std_cmds, ::daqif::OcmDaqControlSync &daq_cmds, CLI::App *arg) override
Receives a parsed variables_map that include the options added with AddOptions.
void AddOptions(CLI::App *app) override
Add arguments to command.
void AddOptions(CLI::App *app) override
Add arguments to command.
void Handle(::stdif::StdCmdsSync &std_cmds, ::daqif::OcmDaqControlSync &daq_cmds, CLI::App *arg) override
Receives a parsed variables_map that include the options added with AddOptions.