artdaq_mfextensions  v1_05_00
MsgAnalyzer.cc
1 #include <QtCore/QSettings>
2 #include <QtWidgets/QApplication>
3 
4 #include "ErrorHandler/MsgAnalyzerDlg.h"
5 
6 #include <fhiclcpp/make_ParameterSet.h>
7 #include <messagefacility/MessageLogger/MessageLogger.h>
8 #include <iostream>
9 
10 using namespace novadaq::errorhandler;
11 using namespace std;
12 
13 void printUsage()
14 {
15  std::cout << "MsgAnalyzer usage:\n"
16  << " -h, --help \tdisplay help message\n"
17  << " -c, --configuration [file]\tspecify the path and filename to the message analyzer conf file\n"
18  << " -l, --log [file] \tspecify the path and filename to the log (messagefacility) conf file\n";
19 }
20 
21 int main(int argc, char* argv[])
22 {
23  QApplication app(argc, argv);
24 
25  std::string cfg("msganalyzer.fcl");
26  std::string mf_cfg("msganalyzer_mf.fcl");
27 
28  int partition = 0;
29  // The following lines will cause the application not working properly.
30  // There is a hidden error involving pointers in QT in this code.
31  auto partenv = getenv("ARTDAQ_PARTITION_NUMBER");
32  if (partenv != nullptr)
33  {
34  partition = atoi(partenv);
35  }
36 
37  if (argc > 1)
38  {
39  for (int i = 0; i < argc; ++i)
40  {
41  if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
42  {
43  printUsage();
44  return 0;
45  }
46 
47  if ((!strcmp(argv[i], "-c") || !strcmp(argv[i], "--configuration")) && i < argc - 1)
48  {
49  cfg = std::string(argv[i + 1]);
50  ++i;
51  continue;
52  }
53 
54  if ((!strcmp(argv[i], "-l") || !strcmp(argv[i], "--log")) && i < argc - 1)
55  {
56  mf_cfg = std::string(argv[i + 1]);
57  ++i;
58  continue;
59  }
60  }
61  }
62 
63  // message facility
64  //putenv((char*)"FHICL_FILE_PATH=.");
65  fhicl::ParameterSet pset;
66  try
67  {
68  cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
69  make_ParameterSet(mf_cfg, lookup_policy, pset);
70  }
71  catch (cet::exception const& ex)
72  {
73  TLOG(TLVL_ERROR) << "Unable to load configuration file " << mf_cfg << ": " << ex.explain_self();
74  }
75 
76  mf::StartMessageFacility(pset, "MsgAnalyzer");
77 
78  mf::SetIteration("context");
79  mf::SetModuleName("module");
80 
81  // first log
82  TLOG_DEBUG("category") << "DEBUG: MessageFacility service started";
83  TLOG_INFO("category") << "INFO: MessageFacility service started";
84 
85  // start MA dialog
86  MsgAnalyzerDlg dialog(cfg, partition);
87 
88  QSettings settings("artdaq", "MsgAnalyzer");
89  dialog.restoreGeometry(settings.value("geometry").toByteArray());
90  dialog.show();
91 
92  return app.exec();
93 }