ELdestinationTester.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 
3 #define MF_DEBUG // always enable debug
4 
5 #include "boost/filesystem.hpp"
6 #include "boost/program_options.hpp"
12 
13 #include <iostream>
14 #include <string>
15 
16 namespace bpo = boost::program_options;
17 
18 using namespace std;
19 using namespace std::string_literals;
20 
21 namespace {
22 
23  void
24  runModule(string const& modulename)
25  {
26  mf::SetModuleName(modulename);
27  // Post begin job
28  mf::SetIteration("postBeginJob"s);
29  mf::LogAbsolute("TimeReport"s)
30  << "TimeReport> Report activated\n"
31  "TimeReport> Report columns headings for events: "
32  "eventnum runnum timetaken\n"
33  "TimeReport> Report columns headings for modules: "
34  "eventnum runnum modulelabel modulename timetaken";
35  // Post end job
36  mf::SetIteration("postEndJob"s);
37  mf::LogAbsolute("TimeReport"s)
38  << "TimeReport> Time report complete in " << 0.0402123 << " seconds\n"
39  << " Time Summary: \n"
40  << " Min: " << 303 << "\n"
41  << " Max: " << 5555 << "\n"
42  << " Avg: " << 4000 << "\n";
43  // Post event processing
44  mf::SetIteration("postEventProcessing"s);
45  mf::LogAbsolute("TimeEvent"s)
46  << "TimeEvent> "
47  << "run: 1 subRun: 2 event: 456 " << .0440404;
48  // Post Module
49  mf::SetIteration("postModule"s);
50  mf::LogAbsolute("TimeModule"s)
51  << "TimeModule> "
52  << "run: 1 subRun: 2 event: 456 "
53  << "someString " << modulename << " " << 0.04404;
54  mf::LogSystem("system"s) << "This would be a major problem, I guess.";
55  }
56 
57 } // unnamed namespace
58 
59 int
60 main(int argc, char* argv[])
61 {
62  ostringstream descstr;
63  descstr << "\nELdestinationTester is a sample program that can be used\n"
64  << "to test how messages are logged using different destinations\n"
65  << "and configurations. This can be particularly helpful for\n"
66  << "users who wish to supply their own plugin destinations.\n\n"
67  << "The configuration file should look like\n"
68  << "\n"
69  << " message: {\n"
70  << " destinations: {\n"
71  << " dest1: {\n"
72  << " ...\n"
73  << " }\n"
74  << " ...\n"
75  << " }\n"
76  << " }\n\n";
77  descstr << "Usage: " << boost::filesystem::path(argv[0]).filename().native()
78  << " -c <config-file> \n\n"
79  << "Allowed options";
80  bpo::options_description desc{descstr.str()};
81  desc.add_options()("config,c", bpo::value<string>(), "Configuration file.")(
82  "help,h", "produce help message");
83  bpo::variables_map vm;
84  try {
85  bpo::store(bpo::parse_command_line(argc, argv, desc), vm);
86  bpo::notify(vm);
87  }
88  catch (bpo::error const& e) {
89  cerr << "Exception from command line processing in " << argv[0] << ": "
90  << e.what() << "\n";
91  return 2;
92  }
93  if (vm.count("help")) {
94  cout << desc << endl;
95  return 1;
96  }
97  if (!vm.count("config")) {
98  cerr << "ERROR: No configuration specified ( -c <config_file> )" << endl;
99  return 3;
100  }
101  string const config_string = vm["config"].as<string>();
102  cet::filepath_lookup_nonabsolute filepath{"FHICL_FILE_PATH"};
103  fhicl::ParameterSet main_pset;
104  try {
105  // create an intermediate table from the input string
106  main_pset = fhicl::ParameterSet::make(config_string, filepath);
107  }
108  catch (cet::exception const& e) {
109  cerr << "ERROR: Failed to create a parameter set from an input "
110  "configuration string with exception "
111  << e.what() << ".\n";
112  cerr << " Input configuration string follows:\n"
113  << "------------------------------------"
114  << "------------------------------------"
115  << "\n";
116  cerr << config_string << "\n";
117  cerr << "------------------------------------"
118  << "------------------------------------"
119  << "\n";
120  return 7003;
121  }
122  // Start MessageFacility Service
123  try {
124  mf::StartMessageFacility(main_pset.get<fhicl::ParameterSet>("message"s),
125  "MessageFacility"s);
126  }
127  catch (mf::Exception const& e) {
128  cerr << e.what() << '\n';
129  return 4;
130  }
131  catch (fhicl::detail::validationException const& e) {
132  cerr << e.what() << '\n';
133  return 6;
134  }
135  catch (cet::exception const& e) {
136  cerr << e.what() << '\n';
137  return 7;
138  }
139  catch (...) {
140  cerr << "Caught unknown exception from mf::StartMessageFacility\n";
141  return 5;
142  }
143  // Set module name for the main thread
144  mf::SetModuleName("MFTest"s);
145  mf::SetIteration("pre-event"s);
146  // Memory Check output
147  mf::LogWarning("MemoryCheck"s)
148  << "MemoryCheck: module G4:g4run VSIZE 1030.34 0 RSS 357.043 0.628906"s;
149  mf::LogWarning("MemoryCheck"s)
150  << "MemoryCheck: module G4:g4run VSIZE 1030.34 0 RSS 357.25 0.199219"s;
151  mf::LogWarning("MemoryCheck"s)
152  << "MemoryCheck: module G4:g4run VSIZE 1030.34 5.2 RSS 357.453 0.1875"s;
153  mf::LogInfo linfo("info"s);
154  linfo << " vint contains: "s;
155  vector<int> vint{1, 2, 5, 89, 3};
156  auto i = begin(vint);
157  auto const e = end(vint);
158  while (i != e) {
159  linfo << *i;
160  if (++i != e) {
161  linfo << ", ";
162  }
163  }
164  // Issue messages with different severity levels
165  mf::LogError("err1"s) << "This is an ERROR message."s;
166  mf::LogError("err2"s) << "This is an ERROR message."s;
167  mf::LogWarning("warning"s) << "Followed by a WARNING message."s;
168  // Switch context
169  mf::SetIteration("pro-event"s);
170  // Log Debugs
171  for (int i = 0; i != 5; ++i) {
172  mf::LogError("catError"s) << "Error information."s;
173  mf::LogWarning("catWarning"s) << "Warning information."s;
174  mf::LogInfo("catInfo"s) << "Info information."s;
175  MF_LOG_DEBUG("debug"s) << "DEBUG information."s;
176  }
177  // Test move operations
178  {
179  // normal macro
180  auto logPROBLEM = MF_LOG_PROBLEM("problem"s);
181  logPROBLEM << "clever way to ensure persistence of temporary object"s;
182  // macro w/ternary operator
183  auto log = MF_LOG_DEBUG("debug2"s) << "first line.\n"s;
184  log << "second line."s;
185  }
186  runModule("module1"s);
187  runModule("module5"s);
189 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void SetIteration(string const &val)
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
error
Definition: include.cc:26
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
cet::coded_exception< errors::error, detail::translate > Exception
Definition: exception.h:16
void StartMessageFacility(fhicl::ParameterSet const &pset, string const &applicationName)
const double e
T get(std::string const &key) const
Definition: ParameterSet.h:271
MaybeLogger_< ELseverityLevel::ELsev_severe, false > LogSystem
void LogStatistics()
string filepath
Definition: train.py:371
char const * what() const noexcept override
#define MF_LOG_PROBLEM(category)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
#define MF_LOG_DEBUG(id)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
void SetModuleName(string const &val)
MaybeLogger_< ELseverityLevel::ELsev_severe, true > LogAbsolute
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
int main(int argc, char *argv[])