Macros | Functions
ELdestinationTester.cc File Reference
#include "boost/filesystem.hpp"
#include "boost/program_options.hpp"
#include "cetlib/filepath_maker.h"
#include "fhiclcpp/ParameterSet.h"
#include "fhiclcpp/types/detail/validationException.h"
#include "messagefacility/MessageLogger/MessageLogger.h"
#include "messagefacility/Utilities/exception.h"
#include <iostream>
#include <string>

Go to the source code of this file.

Macros

#define MF_DEBUG
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define MF_DEBUG

Definition at line 3 of file ELdestinationTester.cc.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 60 of file ELdestinationTester.cc.

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
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
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)
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)