ATLAS Offline Software
|
Run a MT piece of code with an alternate root error handler. More...
#include <WithRootErrorHandler.h>
Public Types | |
using | Handler_t = std::function< bool(int, Bool_t, const char *, const char *)> |
Type of handler to register. More... | |
Public Member Functions | |
WithRootErrorHandler (Handler_t errhand) | |
Temporarily install a thread-local root error handler. More... | |
~WithRootErrorHandler () | |
Destructor. More... | |
WithRootErrorHandler (const WithRootErrorHandler &)=delete | |
WithRootErrorHandler (WithRootErrorHandler &&)=delete | |
WithRootErrorHandler & | operator= (const WithRootErrorHandler &)=delete |
WithRootErrorHandler & | operator= (WithRootErrorHandler &&)=delete |
Static Public Member Functions | |
static void * | operator new (size_t)=delete |
static void * | operator new[] (size_t)=delete |
static void | operator delete (void *)=delete |
static void | operator delete[] (void *)=delete |
Private Attributes | |
size_t | m_size |
For error checking. More... | |
Run a MT piece of code with an alternate root error handler.
Sometimes we want to run a piece of code with an alternate root error handler. This is however problematic in MT jobs since the root error handler pointer is just a global variable visible in all threads. We also frequently need to introduce additional globals if we need to communicate with the handler.
This piece of code tries to get around these limitations. It installs a single root error handler during initialization. This handler will then dispatch to other handlers stored in thread-local storage. This effectively makes changing the root error handler thread-local. We also manage the handler as a std::function, allowing it to have associated state, and clean up the change using RAII.
To change the root error handler, create an instance of this class, passing it a function object, which should have signature:
The arguments are the same as for standard root error handlers. The handler should return true if previous handlers should also be called. If a handler returns false, no further handlers will be called.
The change in the error handler is visible only in the current thread, and the revious handler will be restored when the object is deleted.
Definition at line 55 of file WithRootErrorHandler.h.
using RootUtils::WithRootErrorHandler::Handler_t = std::function<bool (int, Bool_t, const char*, const char*)> |
Type of handler to register.
Like a ROOT error handler, except that it returns a bool.
Definition at line 63 of file WithRootErrorHandler.h.
RootUtils::WithRootErrorHandler::WithRootErrorHandler | ( | Handler_t | errhand | ) |
Temporarily install a thread-local root error handler.
errhand | The handler to be installed. |
The installed handler will only run in the current thread, and it will be removed when this object is deleted. In addition to the usual arguments for a root error handler, it returns a bool. If the returned value is true, previous handlers will also be executed; otherwise, no further handlers will be executed.
Definition at line 65 of file WithRootErrorHandler.cxx.
RootUtils::WithRootErrorHandler::~WithRootErrorHandler | ( | ) |
|
delete |
|
delete |
|
staticdelete |
|
staticdelete |
|
staticdelete |
|
staticdelete |
|
delete |
|
delete |
|
private |
For error checking.
Definition at line 101 of file WithRootErrorHandler.h.