otsdaq_utilities  v2_05_02_indev
ECLTest.cc
1 #include "TRACE/trace.h"
2 #define TRACE_NAME "ECLTest"
3 
4 #include "otsdaq-utilities/ECLWriter/ECLConnection.h"
5 
6 #include <boost/program_options.hpp>
7 namespace bpo = boost::program_options;
8 
9 int main(int argc, char* argv[])
10 {
11  std::ostringstream descstr;
12  descstr << argv[0]
13  << " --host <ECL host> --user <Username> --pwd <Password> [--title <Message "
14  "title>] [message]";
15  bpo::options_description desc(descstr.str());
16  desc.add_options()("host,i", bpo::value<std::string>(), "ECL Instance Address")(
17  "user,u", bpo::value<std::string>(), "ECL Username")(
18  "pwd,p", bpo::value<std::string>(), "ECL Password")(
19  "title,t", bpo::value<std::string>(), "Message title")(
20  "msg,m", bpo::value<std::string>(), "Log Message")("help,h",
21  "produce help message");
22  bpo::positional_options_description p;
23  p.add("msg", -1);
24  bpo::variables_map vm;
25  try
26  {
27  bpo::store(bpo::command_line_parser(argc, argv).options(desc).positional(p).run(),
28  vm);
29  bpo::notify(vm);
30  }
31  catch(bpo::error const& e)
32  {
33  TLOG(TLVL_ERROR) << "Exception from command line processing in " << argv[0]
34  << ": " << e.what() << "\n";
35  exit(-1);
36  }
37  if(vm.count("help"))
38  {
39  std::cout << desc << std::endl;
40  exit(1);
41  }
42 
43  std::string ECLUser = "", ECLPwd = "", ECLHost = "", title = "ECL Test Message",
44  message = "";
45  if(vm.count("user"))
46  {
47  ECLUser = vm["user"].as<std::string>();
48  }
49  if(vm.count("pwd"))
50  {
51  ECLPwd = vm["pwd"].as<std::string>();
52  }
53  if(vm.count("host"))
54  {
55  ECLHost = vm["host"].as<std::string>();
56  }
57  if(vm.count("title"))
58  {
59  title = vm["title"].as<std::string>();
60  }
61  if(vm.count("msg"))
62  {
63  message = vm["msg"].as<std::string>();
64  }
65 
66  ECLEntry_t eclEntry;
67  eclEntry.author(ECLUser);
68  eclEntry.category("TDAQ");
69  eclEntry.subject(title);
70  Form_t form;
71  Field_t field;
72  Form_t::field_sequence fields;
73 
74  form.name("default");
75 
76  field = Field_t(message, "text");
77  fields.push_back(field);
78 
79  form.field(fields);
80 
81  eclEntry.form(form);
82 
83  ECLConnection eclConn(ECLUser, ECLPwd, ECLHost);
84  if(!eclConn.Post(eclEntry))
85  {
86  return -1;
87  }
88 
89  return 0;
90 }
Definition: ECL.hxx:547
Definition: ECL.hxx:410
Definition: ECL.hxx:474