sqlite_mfPlugin.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 
4 
6 #include "cetlib/sqlite/Ntuple.h"
13 
14 #include <memory>
15 #include <sstream>
16 #include <string>
17 
18 using namespace std;
19 using namespace std::string_literals;
20 
21 namespace {
22 
23  using namespace cet::sqlite;
24 
25  ConnectionFactory factory;
26 
27  class sqlite3Plugin : public mf::service::ELdestination {
28 
29  public:
30  struct Config {
31 
34  };
35 
36  using Parameters = fhicl::WrappedTable<Config>;
37 
38  public:
39  ~sqlite3Plugin();
40  sqlite3Plugin(Parameters const&);
41 
42  private:
43  void
44  fillPrefix(ostringstream&, mf::ErrorObj const&) override
45  {}
46  void
47  fillSuffix(ostringstream&, mf::ErrorObj const&) override
48  {}
49  void routePayload(ostringstream const&, mf::ErrorObj const&) override;
50 
51  private:
52  Connection* connection_;
53  Ntuple<string,
54  string,
55  string,
56  string,
57  string,
58  string,
59  unsigned,
60  string,
61  string,
62  string>* msgTable_;
63  };
64 
65  sqlite3Plugin::~sqlite3Plugin()
66  {
67  delete msgTable_;
68  msgTable_ = nullptr;
69  delete connection_;
70  connection_ = nullptr;
71  }
72 
73  sqlite3Plugin::sqlite3Plugin(Parameters const& ps)
74  : ELdestination{ps().elDestConfig()}
75  , connection_{factory.make_connection(ps().filename())}
76  , msgTable_{new Ntuple<string,
77  string,
78  string,
79  string,
80  string,
81  string,
82  unsigned,
83  string,
84  string,
85  string>{*connection_,
86  "Messages"s,
87  {{"Timestamp"s,
88  "Hostname"s,
89  "Hostaddress"s,
90  "Severity"s,
91  "Category"s,
92  "AppName"s,
93  "ProcessId"s,
94  "RunEventNo"s,
95  "ModuleName"s,
96  "Message"s}}}}
97  {}
98 
99  void
100  sqlite3Plugin::routePayload(ostringstream const& oss, mf::ErrorObj const& msg)
101  {
102  auto const& xid = msg.xid();
103  string const& timestamp = format_.timestamp(msg.timestamp());
104  string const& hostname = xid.hostname();
105  string const& hostaddr = xid.hostaddr();
106  string const& severity = xid.severity().getName();
107  string const& category = xid.id();
108  string const& app = xid.application();
109  long const& pid = xid.pid();
110  string const& iterationNo = mf::GetIteration();
111  string const& modname = xid.module();
112  string const& usrMsg =
113  !oss.str().compare(0, 1, "\n") ? oss.str().erase(0, 1) : oss.str();
114  msgTable_->insert(timestamp,
115  hostname,
116  hostaddr,
117  severity,
118  category,
119  app,
120  pid,
121  iterationNo,
122  modname,
123  usrMsg);
124  }
125 
126 } // unnamed namespace
127 
129 {
130  return make_unique<sqlite3Plugin>(pset);
131 }
133 
void msg(const char *fmt,...)
Definition: message.cpp:107
timeval timestamp() const
Definition: ErrorObj.cc:73
std::string string
Definition: nybbler.cc:12
STL namespace.
auto make_connection(std::string const &file_name, PolicyArgs &&...) -> Connection *
string filename
Definition: train.py:213
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
fhicl::Atom< std::string > filename
Definition: FileConfig.h:13
ELextendedID const & xid() const
Definition: ErrorObj.cc:61
#define MAKE_PLUGIN_END
static constexpr double ps
Definition: Units.h:99
string const & GetIteration()
#define FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass)
MAKE_MFPLUGIN_START(, pset)
std::string const & hostname() const
Definition: ELextendedID.cc:51
static QCString * s
Definition: config.cpp:1042