11 #include <fmt/format.h>
12 #include <nlohmann/json.hpp>
23 void to_json(nlohmann::json& j, daqif::DaqStatus
const& status) {
24 j = nlohmann::json{{
"id", status.getId()},
25 {
"fileId", status.getFileId()},
26 {
"state",
ToString(status.getState())},
27 {
"substate",
ToString(status.getSubState())},
28 {
"error", status.getError()},
29 {
"result", status.getResult()},
30 {
"message", status.getMessage()},
31 {
"timestamp", status.getTimestamp()}};
36 std::ostream&
operator<<(std::ostream& os, std::shared_ptr<daqif::DaqStatus>
const& s) {
37 os << std::setprecision(std::numeric_limits<long double>::digits10 + 1);
39 <<
" id: " << s->getId() <<
"\n"
40 <<
" file_id: " << s->getFileId() <<
"\n"
41 <<
" state: \"" <<
ToString(s->getState()) <<
"\"\n"
42 <<
" substate: \"" <<
ToString(s->getSubState()) <<
"\"\n"
43 <<
" error: \"" << (s->getError() ?
"true" :
"false") <<
"\n"
44 <<
" message: " << s->getMessage() <<
"\n"
45 <<
" result: " << s->getResult() <<
"\n"
46 <<
" timestamp: " << s->getTimestamp();
52 std::ostream&
operator<<(std::ostream& os, std::shared_ptr<daqif::DaqReply>
const& s) {
54 <<
" id: " << s->getId() <<
"\n"
55 <<
" error: " << (s->getError() ?
"true" :
"false") <<
"\n";
59 std::ostream&
operator<<(std::ostream& os, std::shared_ptr<daqif::AwaitDaqReply>
const& s) {
60 os <<
"AwaitDaqReply:\n"
61 <<
" timeout: " << (s->getTimeout() ?
"true" :
"false") <<
"\n"
62 <<
" status: " << s->getStatus() <<
"\n";
67 operator<<(std::ostream& os, std::vector<std::shared_ptr<daqif::DaqStatus>>
const& vec) {
68 for (
auto const& s : vec) {
76 nlohmann::json j_status;
78 os << j_status.dump(2);
83 operator<<(std::ostream& os,
JsonPrint<std::vector<std::shared_ptr<daqif::DaqStatus>>>
const& vec) {
84 nlohmann::json j_array = nlohmann::json::array();
85 for (
auto const& s : vec.t) {
86 nlohmann::json j_status;
88 j_array.push_back(j_status);
90 os << j_array.dump(2);
100 << (s.t->getError() ?
"true" :
"false") <<
"\n";
108 auto const& reply = *s.t;
109 auto const& rep = *reply.getStatus();
110 nlohmann::json j_status;
112 nlohmann::json j{{
"timeout", reply.getTimeout()}, {
"status", j_status}};
118 os <<
"\"" << s.
t <<
"\"";
129 sub->add_option(
"logger", m_logger,
"Logger name");
130 sub->add_option(
"level", m_level,
"Log level");
134 ::daqif::OcmDaqControlSync& daq_cmds,
136 auto log_info =
m_args.
mal->createDataEntity<stdif::LogInfo>();
137 log_info->setLogger(m_logger);
138 log_info->setLevel(m_level);
139 auto reply = std_cmds.SetLogLevel(log_info);
143 std::cout << reply << std::endl;
148 sub->add_option(
"--id",
m_id,
"DAQ ID");
149 sub->add_option(
"--prefix",
m_prefix,
"File prefix");
150 sub->add_option(
"--properties",
m_properties,
"JSON properties");
151 sub->add_option(
"primary",
153 "Space separated list of primary data sources, each in the form `name@uri`, "
154 "e.g. \"dcs1@zpb.rr://10.207.214.220:1234/RecCmds\"");
155 sub->add_option(
"metadata",
157 "Space separated list of metadata data sources, each in the form `name@uri`, "
158 "e.g. \"fcf1@zpb.rr://10.207.214.218:1234/MetaDaq\"");
162 ::daqif::OcmDaqControlSync& daq_cmds,
169 std::cout << reply << std::endl;
174 auto file_or_json = [](std::string
const& arg) -> std::string {
175 if (arg.size() > 1 && arg.front() ==
'@') {
176 auto path = arg.substr(1);
178 std::string file_body((std::istreambuf_iterator<char>(std::cin)),
179 (std::istreambuf_iterator<char>()));
182 std::ifstream f(path);
184 throw std::invalid_argument(
185 fmt::format(
"File not found or readable: {}", arg.substr(1)));
187 std::string file_body((std::istreambuf_iterator<char>(f)),
188 (std::istreambuf_iterator<char>()));
195 sub->add_option(
"specification",
197 "JSON specification. Load from file by prefixing with '@', e.g. @file.json\n"
198 "or from stdin '-' with @-")
199 ->transform(file_or_json)
204 ::daqif::OcmDaqControlSync& daq_cmds,
206 auto reply = daq_cmds.StartDaqV2(
m_spec);
210 std::cout << reply << std::endl;
215 sub->add_option(
"id", m_id,
"DAQ ID");
216 sub->add_option(
"keywords", m_keywords,
"JSON encoded list of keywords");
220 ::daqif::OcmDaqControlSync& daq_cmds,
222 auto reply = daq_cmds.UpdateKeywords(m_id, m_keywords);
226 std::cout << reply << std::endl;
231 sub->add_option(
"id", m_id,
"DAQ ID");
232 sub->add_option(
"state", m_state,
"State to await");
233 sub->add_option(
"substate", m_substate,
"Substate to await");
234 sub->add_option(
"timeout", m_timeout,
"timeout in [fractional] seconds");
236 auto min_timeout = m_timeout + 2;
238 std::cerr <<
"Note: Setting request timeout to " << min_timeout
239 <<
"s due to await timeout exceeding request timeout\n";
240 m_args.timeout = min_timeout;
246 ::daqif::OcmDaqControlSync& daq_cmds,
248 auto state = daqif::FromString<daqif::DaqState>(m_state);
249 auto substate = daqif::FromString<daqif::DaqSubState>(m_substate);
250 auto reply = daq_cmds.AwaitDaqState(m_id, state, substate, m_timeout);
254 std::cout << reply << std::endl;
Contains support functions for daqif.
std::string_view ToString(daqif::DaqState state) noexcept
void to_json(nlohmann::json &j, daqif::DaqStatus const &status)
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.