LDMX Software
fire.cxx
1
2//----------------//
3// C++ StdLib //
4//----------------//
5#include <signal.h>
6#include <stdio.h>
7#include <string.h>
8#include <unistd.h>
9
10#include <iostream>
11
12//-------------//
13// ldmx-sw //
14//-------------//
15#include "Framework/Configure/Python.h"
16#include "Framework/Process.h"
17
22// using namespace framework;
23
24// This code allows ldmx-app to exit gracefully when Ctrl-c is used. It is
25// currently causing segfaults when certain processors are used. The code
26// will remain commented out until these issues are investigated further.
27/*
28static Process* p { 0 };
29
30static void softFinish (int sig, siginfo_t *siginfo, void *context) {
31if (p) p->requestFinish();
32}
33*/
34
40void printUsage();
41
51int main(int argc, char* argv[]) try {
52 if (argc < 2) {
53 printUsage();
54 return 1;
55 }
56
57 int ptrpy = 1;
58 for (ptrpy = 1; ptrpy < argc; ptrpy++) {
59 if (strstr(argv[ptrpy], ".py")) break;
60 }
61
62 if (ptrpy == argc) {
63 printUsage();
64 std::cout << " ** No python configuration script provided (must end in "
65 "'.py'). ** "
66 << std::endl;
67 return 1;
68 }
69
70 std::cout << "---- LDMXSW: Loading configuration --------" << std::endl;
71
73 try {
75 framework::config::run("ldmxcfg.Process.lastProcess", argv[ptrpy],
76 argv + ptrpy + 1, argc - ptrpy - 1)};
77 p = std::make_unique<framework::Process>(config);
78 } catch (const framework::exception::Exception& e) {
79 // Error message currently printed twice since the stack trace code
80 // sometimes crashes. Once this is fixed, the output above the stack trace
81 // can be removed
82 // https://github.com/LDMX-Software/Framework/issues/50
83 std::cerr << "Configuration Error [" << e.name() << "] : " << e.message()
84 << std::endl;
85 std::cerr << " at " << e.module() << ":" << e.line() << " in "
86 << e.function() << std::endl;
87 return 1;
88 }
89
90 std::cout << "---- LDMXSW: Configuration load complete --------"
91 << std::endl;
92
93 // If Ctrl-c is used, immediately exit the application.
94 struct sigaction act;
95 memset(&act, '\0', sizeof(act));
96 if (sigaction(SIGINT, &act, NULL) < 0) {
97 perror("sigaction");
98 return 1;
99 }
100
101 // See comment above for reason why this code is commented out.
102 /* Use the sa_sigaction field because the handles has two additional
103 * parameters */
104 // act.sa_sigaction = &softFinish;
105
106 /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not
107 * sa_handler. */
108 // act.sa_flags = SA_SIGINFO;
109
110 std::cout << "---- LDMXSW: Starting event processing --------" << std::endl;
111
112 try {
113 p->run();
114 } catch (const framework::exception::Exception& e) {
115 // Process::run opens up the logging using the parameters passed to it from
116 // python
117 // if an Exception is thrown, we haven't gotten to the end of Process::run
118 // where logging is closed, so we can do one more error message and then
119 // close it.
120 // ldmx_log macro needs this variable to be named 'theLog_'
121 auto theLog_{framework::logging::makeLogger("fire")};
122 ldmx_log(fatal) << "[" << e.name() << "] : " << e.message() << "\n"
123 << " at " << e.module() << ":" << e.line() << " in "
124 << e.function();
125 ldmx_log(debug) << e.stackTrace();
126 framework::logging::close();
127 return 1; // return non-zero error-status
128 }
129
130 std::cout << "---- LDMXSW: Event processing complete --------" << std::endl;
131 return 0;
132} catch (const std::exception& e) {
133 std::cerr << "Unrecognized Exception: " << e.what() << std::endl;
134 return 127;
135}
136
137void printUsage() {
138 std::cout << "Usage: fire {configuration_script.py} [arguments to "
139 "configuration script]"
140 << std::endl;
141 std::cout << " configuration_script.py (required) python script to "
142 "configure the processing"
143 << std::endl;
144 std::cout << " arguments (optional) passed to "
145 "configuration script when run in python"
146 << std::endl;
147}
Class which represents the process under execution.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Standard base exception class with some useful output information.
Definition Exception.h:20
const std::string & function() const
Get the function name where the exception occurred.
Definition Exception.h:74
int line() const
Get the source line number where the exception occurred.
Definition Exception.h:80
const std::string & message() const
Get the message of the exception.
Definition Exception.h:62
const std::string & name() const
Get the name of the exception.
Definition Exception.h:56
const std::string & stackTrace() const
Get the full stack trace.
Definition Exception.h:91
const std::string & module() const
Get the source filename where the exception occurred.
Definition Exception.h:68
Parameters run(const std::string &root_object, const std::string &pythonScript, char *args[], int nargs)
run the python script and extract the parameters
Definition Python.cxx:292
std::unique_ptr< Process > ProcessHandle
A handle to the current process Used to pass a process from ConfigurePython to fire....
Definition Process.h:233