Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions madgraph/iolibs/template_files/mg7/madevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@
)
print()

logger = logging.getLogger("madevent7")
logger = logging.getLogger("madgraph7")
LOG_LEVEL_MAP = {
ms.Logger.LogLevel.level_debug: logging.DEBUG,
ms.Logger.LogLevel.level_info: logging.INFO,
ms.Logger.LogLevel.level_warning: logging.WARNING,
ms.Logger.LogLevel.level_error: logging.ERROR,
}
def ms_log_handler(level: ms.Logger.LogLevel, message: str):
logger.log(LOG_LEVEL_MAP[level], message)
ms.Logger.set_log_handler(ms_log_handler)


def get_start_time():
Expand Down Expand Up @@ -1784,7 +1793,7 @@ def _off(value) -> bool:
_TOOL_LOGGING_READY = False


def _setup_tool_logging():
def _setup_logging():
"""Make the reused madevent tool drivers' progress visible on screen.

The drivers already narrate what they do through logger.info /
Expand All @@ -1804,7 +1813,7 @@ def _setup_tool_logging():
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
handler._mg7_tool_handler = True
for name in ("madgraph", "madevent", "cmdprint"):
for name in ("madgraph", "madevent", "cmdprint", "madgraph7"):
lg = logging.getLogger(name)
if not any(getattr(h, "_mg7_tool_handler", False) for h in lg.handlers):
lg.addHandler(handler)
Expand Down Expand Up @@ -1838,9 +1847,6 @@ def run_selected_tools(switch, process) -> None:
process.run_path, ", ".join(sorted(active)))
return

# surface the reused madevent drivers' own progress messages on screen
_setup_tool_logging()

run_name = os.path.basename(os.path.dirname(os.path.abspath(lhe_path)))
run_dir = os.path.dirname(os.path.abspath(lhe_path))

Expand Down Expand Up @@ -2266,10 +2272,13 @@ def force_lhe_output_if_needed(switch) -> None:


def main() -> None:
_setup_logging()

parser = argparse.ArgumentParser()
parser.add_argument("-f", action="store_false", dest="ask_edit_cards")
args = parser.parse_args()
switch = {}

if args.ask_edit_cards:
switch = ask_edit_cards()
force_lhe_output_if_needed(switch)
Expand Down
3 changes: 3 additions & 0 deletions madspace/include/madspace/driver/logger.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <functional>
#include <iostream>
#include <string>

#include "madspace/util.hpp"
Expand Down Expand Up @@ -34,12 +35,14 @@ class Logger {
println("[ERROR] {}", message);
break;
}
std::cout << std::flush;
}
static void debug(const std::string& message) { log(level_debug, message); }
static void info(const std::string& message) { log(level_info, message); }
static void warning(const std::string& message) { log(level_warning, message); }
static void error(const std::string& message) { log(level_error, message); }
static void set_log_handler(LogHandlerFunc func) { _log_handler = func; }
static void clear_log_handler() { _log_handler = std::nullopt; }

private:
static inline std::optional<LogHandlerFunc> _log_handler = std::nullopt;
Expand Down
8 changes: 7 additions & 1 deletion madspace/src/python/madspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,13 @@ PYBIND11_MODULE(_madspace_py, m) {
.def_static("info", &Logger::info, py::arg("message"))
.def_static("warning", &Logger::warning, py::arg("message"))
.def_static("error", &Logger::error, py::arg("message"))
.def_static("set_log_handler", &Logger::set_log_handler, py::arg("func"));
.def_static("set_log_handler", &Logger::set_log_handler, py::arg("func"))
.def_static("clear_log_handler", &Logger::clear_log_handler);

// prevent memory error due to static lifetime of log handler
py::module_::import("atexit").attr("register")(py::cpp_function([]() {
Logger::clear_log_handler();
}));

m.def(
"initialize_vegas_grid",
Expand Down
Loading