38namespace triqs::utility {
47 std::string filename_;
48 std::vector<
scope_guard<std::function<void()>>> guards;
49 std::vector<std::string> names;
56 crash_logger(std::string filename) : filename_(std::move(filename)) {}
75 swap(guards, x.guards);
89 names.push_back(name);
90 guards.emplace_back([&obj,
this, name]() {
93 h5_write(h5::group(h5::file(this->filename_.c_str(),
'a')), name, obj);
95 std::cerr <<
"An exception has occurred in crash_logger for an object of type " <<
typeid_name(obj) <<
" named " << name << std::endl;
103 if ((guards.size() > 0) && (guards.front().active())) {
104 std::cerr <<
"crash_logger : I am destroyed without being dismissed. Dumping the objects : ";
105 for (
auto &x : names) std::cerr <<
"\"" << x <<
"\" ";
106 std::cerr << std::endl;
107 h5::file(this->filename_.c_str(),
'w');
113 for (
auto &g : guards) g.dismiss();
friend void h5_write(h5::group fg, std::string const &subgroup_name, this_t const &g)
Write a block Green's function to HDF5.
crash_logger & operator=(crash_logger &&x) noexcept
Move-assignment takes over guards and names from x.
~crash_logger() noexcept
Destructor writes all registered objects to the dump file if there has not been a call to dismiss().
crash_logger & operator=(const crash_logger &)=delete
Deleted copy-assignment.
crash_logger(std::string filename)
Construct a crash logger that will write to an HDF5 file on abnormal exit.
crash_logger(crash_logger &&)=default
Default move constructor.
crash_logger(const crash_logger &)=delete
Deleted copy constructor.
void dismiss()
Dismiss the logger by suppressing scope-exit dumps and by releasing registered objects.
crash_logger & operator()(T const &obj, std::string name)
Register an object to be dumped to a given HDF5 path on abnormal exit.
RAII wrapper that invokes a callable when it goes out of scope, unless dismissed.
std::string typeid_name()
Human-readable name of a given static type.
RAII helper that runs a user-provided cleanup on scope exit.
Helper functions built around std::type_info.