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/ConfigurePython.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 {
74 framework::ConfigurePython cfg(argv[ptrpy], argv + ptrpy + 1,
75 argc - ptrpy - 1);
76 p = cfg.makeProcess();
77 } catch (const framework::exception::Exception& e) {
78 // Error message currently printed twice since the stack trace code
79 // sometimes crashes. Once this is fixed, the output above the stack trace
80 // can be removed
81 // https://github.com/LDMX-Software/Framework/issues/50
82 std::cerr << "Configuration Error [" << e.name() << "] : " << e.message()
83 << std::endl;
84 std::cerr << " at " << e.module() << ":" << e.line() << " in "
85 << e.function() << std::endl;
86 return 1;
87 }
88
89 std::cout << "---- LDMXSW: Configuration load complete --------"
90 << std::endl;
91
92 // If Ctrl-c is used, immediately exit the application.
93 struct sigaction act;
94 memset(&act, '\0', sizeof(act));
95 if (sigaction(SIGINT, &act, NULL) < 0) {
96 perror("sigaction");
97 return 1;
98 }
99
100 // See comment above for reason why this code is commented out.
101 /* Use the sa_sigaction field because the handles has two additional
102 * parameters */
103 // act.sa_sigaction = &softFinish;
104
105 /* The SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not
106 * sa_handler. */
107 // act.sa_flags = SA_SIGINFO;
108
109 std::cout << "---- LDMXSW: Starting event processing --------" << std::endl;
110
111 try {
112 p->run();
113 } catch (const framework::exception::Exception& e) {
114 // Process::run opens up the logging using the parameters passed to it from
115 // python
116 // if an Exception is thrown, we haven't gotten to the end of Process::run
117 // where logging is closed, so we can do one more error message and then
118 // close it.
119 auto theLog_{framework::logging::makeLogger(
120 "fire")}; // ldmx_log macro needs this variable to be named 'theLog_'
121 ldmx_log(fatal) << "[" << e.name() << "] : " << e.message() << "\n"
122 << " at " << e.module() << ":" << e.line() << " in "
123 << e.function() << std::endl;
124 framework::logging::close();
125 return 1; // return non-zero error-status
126 }
127
128 std::cout << "---- LDMXSW: Event processing complete --------" << std::endl;
129 return 0;
130} catch (const std::exception& e) {
131 std::cerr << "Unrecognized Exception: " << e.what() << std::endl;
132 return 127;
133}
134
135void printUsage() {
136 std::cout << "Usage: fire {configuration_script.py} [arguments to "
137 "configuration script]"
138 << std::endl;
139 std::cout << " configuration_script.py (required) python script to "
140 "configure the processing"
141 << std::endl;
142 std::cout << " arguments (optional) passed to "
143 "configuration script when run in python"
144 << std::endl;
145}
Class which represents the process under execution.
Utility class which reads/executes a python script and creates a Process object based on the input.
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 & module() const
Get the source filename where the exception occurred.
Definition Exception.h:68
std::unique_ptr< Process > ProcessHandle
A handle to the current process Used to pass a process from ConfigurePython to fire....
Definition Process.h:248