AugerOfflineMain.cc
Go to the documentation of this file.
1 #ifdef _GNU_SOURCE
2 # include <fenv.h>
3 #endif
4 
5 #include <fwk/RunController.h>
6 #include <fwk/CentralConfig.h>
7 #include <fwk/CommandLineOptions.h>
8 #include <fwk/GITGlobalRevision.h>
9 #include <utl/ErrorLogger.h>
10 #include <utl/AugerException.h>
11 #include <utl/TabularStream.h>
12 #include <utl/Deprecator.h>
13 #include <config.h>
14 #ifndef AUGER_SQLITE_ENABLED
15 # include <det/VSQLManager_MySQL.h>
16 #endif
17 
18 #include <boost/filesystem/operations.hpp>
19 #include <boost/program_options.hpp>
20 
21 #include <sstream>
22 #include <algorithm>
23 
24 using namespace fwk;
25 using namespace std;
26 using namespace utl;
27 namespace fs = boost::filesystem;
28 namespace po = boost::program_options;
29 
30 
31 void AugerOfflineUser();
32 
33 
34 namespace fwk {
35 
36  class Trailer {
37  public:
38  Trailer(const string& text) : fText(text) { }
39  ~Trailer() { cerr << fText << endl; }
40  private:
41  string fText;
42  };
43 
44 
45  string
46  Red(const string& str)
47  {
48  if (ErrorLogger::GetInstance().HasColor())
49  return "\033[1;31m" + str + "\033[0m";
50  else
51  return str;
52  }
53 
54 }
55 
56 
71 int
72 main(int argc, char* argv[])
73 {
74  fs::initial_path(); // required for saving startup value
75 
76  string bootstrapFile("bootstrap.xml");
77  string logFile;
78  int verbosity = 0;
79  int fpException = 0;
80  int logDbQueries = 0;
81  po::options_description desc("Usage:");
82  desc.add_options()
83  ("help,h",
84  "write this message")
85  ("bootstrap,b",
86  po::value<string>(&bootstrapFile),
87  "Bootstrap file name. Defaults to './bootstrap.xml' if this option is not used.")
88  ("log,l",
89  po::value<string>(&logFile),
90  "Write out a log file.")
91  ("fingerprintFatal,f",
92  "If option is used, throw exceptions in case of mismatch of config file md5 fingerprints.")
93  ("verbosity,v",
94  po::value<int>(&verbosity)->default_value(Verbosity::eDefault),
95  "Verbosity: -1=default, 0=silent... 3=annoying")
96  ("color,c",
97  "Colorize output")
98  ("fpexception,x",
99  po::value<int>(&fpException),
100  "Unmask specific floating-point exceptions for debugging: 1=invalid-sqrt(-1), 4=div-by-0, 8=overflow.")
101  ("log-db-queries",
102  po::value<int>(&logDbQueries)->default_value(logDbQueries),
103  "switch on logging of all SQL queries")
104  ("show-available-modules",
105  "show available Offline modules")
106  ;
107 
108  po::variables_map vm;
109  try {
110  po::store(po::parse_command_line(argc, argv, desc), vm);
111  po::notify(vm);
112  } catch (po::error& er) {
113  cerr << "Command line error : " << er.what() << '\n'
114  << desc << endl;
115  return EXIT_FAILURE;
116  }
117 
118  if (vm.count("help")) {
119  cerr << desc << endl;
120  return EXIT_SUCCESS;
121  }
122 
123  auto& errorLogger = ErrorLogger::GetInstance();
124  if (vm.count("color"))
125  errorLogger.SetColorOutput(true);
126 
127  errorLogger.SetVerbosity(Verbosity::eDefault);
128  if (vm.count("verbosity")) {
129  const auto v = vm["verbosity"].as<int>();
130  errorLogger.SetVerbosity(static_cast<Verbosity::EVerbosity>(
131  min(int(Verbosity::eDefault), max(int(Verbosity::eDefault), v))
132  ));
133  }
134 
135  if (vm.count("show-available-modules")) {
136  cout << "# list of registered Offline modules:\n";
137  for (auto it = VModuleFactory::Begin(); it != VModuleFactory::End(); ++it)
138  cout << it->first << '\n';
139  cout << endl;
140  return EXIT_SUCCESS;
141  }
142 
143 #ifdef _GNU_SOURCE
144  if (vm.count("fpexception"))
145  feenableexcept(fpException);
146 #else
147  if (vm.count("fpexception"))
148  cerr << "floating-point exceptions will not be enabled on this architecture..." << endl;
149 #endif
150 
151 #ifndef AUGER_SQLITE_ENABLED
152  if (vm.count("log-db-queries"))
153  det::VSQLManager::SetGlobalLogQueries(vm["log-db-queries"].as<int>());
154 #endif
155 
156  // Header
157  {
158  ostringstream os;
159 
160  os << '\n'
161  << Red(
162  " ___________________\n"
163  " __ _ _ / ,\n"
164  " / ) / ` / ` / __ _\n"
165  " / / _/__ _/__ / / / ) /___)\n"
166  " / / / / / / / / (___\n"
167  " (____/ / / __________________\n"
168  )
169  << "\n"
170  " " << OFFLINE_PACKAGE_STRING << "\n"
171  " Reference: Nucl. Instrum. Meth. A 580 (2007) 1485." << "\n"
172  " GIT revision number : " << GITGlobalRevision::GetInstance().GetId() << "\n"
173  " Bug reports to : " << OFFLINE_PACKAGE_BUGREPORT << "\n"
174  " ____________________________________________________\n";
175 
176  INFO(os);
177  }
178 
179  // Trailer
180  TabularStream tab("l");
181  tab << endr << HLine('=')
182  << "End of run: " << OFFLINE_PACKAGE_STRING << endr
183  << "GIT revision number: " << GITGlobalRevision::GetInstance().GetId() << endr
184  << HLine('=');
185  static Trailer trailer(tab.Str());
186 
187  // Create the CentralConfig and parse the bootstrap file
188  if (vm.count("fingerprintFatal"))
189  CentralConfig::GetInstance(bootstrapFile, true);
190  else
191  CentralConfig::GetInstance(bootstrapFile, false);
192 
193  // end parsing options, send to CentralConfig
194  fwk::CommandLineOptions::GetInstance().SetVariablesMap(vm);
195 
196  // Pass control to user for possible custom sequencing
198 
199  // Run the chain
200  auto& myController = RunController::GetInstance();
201 
202  try {
203  myController.Init();
204  } catch (ModuleSequenceException& ex) {
205  ERROR("ModuleSequenceException thrown. Abnormal termination in RunController Init().");
206  return EXIT_FAILURE;
207  }
208 
209  try {
210  myController.Run();
211  } catch (ModuleSequenceException& ex) {
212  ERROR("ModuleSequenceException thrown. Abnormal termination in RunController Run().");
213  return EXIT_FAILURE;
214  }
215 
216  try {
217  myController.Finish();
218  } catch (ModuleSequenceException& ex) {
219  ERROR("ModuleSequenceException thrown. Abnormal termination in RunController Finish()");
220  return EXIT_FAILURE;
221  }
222 
223  if (vm.count("log"))
225 
226  const auto& d = Deprecator::GetInstance();
227  if (!d.IsEmpty()) {
228  WARNING("*** The following deprecated methods were used:\n\n" +
229  d.GetReport() +
230  "Please update your code.");
231  }
232 
233  return EXIT_SUCCESS;
234 }
235 
236 
237 /*
238  Old logo saved for posterity.
239 
240  _/_/ _/_/ _/_/ _/ _/
241  _/ _/ _/ _/ _/ _/_/_/ _/_/
242  _/ _/ _/_/_/_/_/_/_/_/ _/ _/ _/ _/ _/_/_/_/
243  _/ _/ _/ _/ _/ _/ _/ _/ _/
244  _/_/ _/ _/ _/ _/ _/ _/ _/_/_/
245 
246 */
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
Exception to use in case of module sequencing failures.
static Iterator Begin()
Begin iterator over the internal map (read only)
#define max(a, b)
int main(int argc, char *argv[])
Definition: DBSync.cc:58
Trailer(const string &text)
const EndRow endr
const int tab
Definition: SdInspector.cc:35
class that triggers insertion of the line row in the TabularStream
class to format data in tabular form
static Iterator End()
End iterator over the internal map (read only)
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
static void SetGlobalLogQueries(const int q)
std::string Str()
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
string Red(const string &str)
void WriteConfig(const std::string &fileName="")
Get the link name for moduleConfigLink with given id (any)
use default verbosity from error logger
Definition: Verbosity.h:11
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165

, generated on Tue Sep 26 2023.