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