DAS  3.0
Das Analysis System
Darwin::Exceptions Namespace Reference

Classes

struct  AnomalousEvent
 
struct  BadInput
 

Functions

std::string intercept_printf (std::function< void()> const lambda=[]() { printf(__func__);})
 
void Diagnostic (const boost::exception &e)
 

Variables

 git_error_category
 

Detailed Description

Handling of exceptions.

Function Documentation

◆ Diagnostic()

void Diagnostic ( const boost::exception &  e)
inline

Standard exception diagnostic, including the expanded command, software versions, and link to the documentation.

Parameters
eargument of `catch` block
132 {
133  using namespace std;
134  namespace DT = Darwin::Tools;
135  cerr << red << boost::diagnostic_information(e);
136  if (!DT::Options::full_cmd.empty())
137  cerr << "To reproduce error, you may run:\n"
138  << highlight << DT::Options::full_cmd << def << '\n';
139  cerr << def;
140 }

◆ intercept_printf()

std::string intercept_printf ( std::function< void()> const  lambda = []() { printf(__func__); })
inline

Solution found on Stackoverflow to intercept the output of printf (which is still used by ROOT in several places, e.g. TTree::Show()).

https://stackoverflow.com/questions/5911147/how-to-redirect-printf-output-back-into-code

Note
This function only collects the first 16kB printed by the intercepted function. If the output is longer, the return value is truncated.
Bug:

This function will deadlock if the intercepted function produces more output than a system-dependent limit (the size of a pipe buffer, which can be as low as 4kB on some systems).

This function leaks file descriptors if the intercepted function throws.

Solution found on Stackoverflow to intercept the output of printf (which is still used by ROOT in several places, e.g. TTree::Show()).

https://stackoverflow.com/questions/5911147/how-to-redirect-printf-output-back-into-code

Note
This function only collects the first 16kB printed by the intercepted function. If the output is longer, the return value is truncated.
Bug:

This function will deadlock if the intercepted function produces more output than a system-dependent limit (the size of a pipe buffer, which can be as low as 4kB on some systems).

This function leaks file descriptors if the intercepted function throws.

33  { printf(__func__); })
34 {
35  char buffer[16384] = {0};
36  int out_pipe[2];
37 
38  // Get rid of anything still present in the stdout buffer. If there were
39  // something left in the buffer, we would "intercept" it.
40  fflush(stdout);
41 
42  int saved_stdout = dup(STDOUT_FILENO); /* save stdout for display later */
43 
44  if (pipe(out_pipe) != 0) // make a pipe
45  return "[`printf()` couldn't be intercepted]";
46 
47  dup2(out_pipe[1], STDOUT_FILENO); /* redirect stdout to the pipe */
48  close(out_pipe[1]);
49 
50  lambda();
51  fflush(stdout);
52 
53  read(out_pipe[0], buffer, sizeof(buffer)-1); /* read from pipe into buffer */
54  close(out_pipe[0]);
55 
56  dup2(saved_stdout, STDOUT_FILENO); /* reconnect stdout for testing */
57 
58  return buffer;
59 }

Variable Documentation

◆ git_error_category

git_error_category

Error category for libgit2.

highlight
static const char * highlight
Definition: colours.h:9
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
Step::def
static const char * def
Definition: Step.h:36
Step::red
static const char * red
Definition: Step.h:34
Darwin::Tools
Classes and functions related to the framework.
Definition: Dict_rdict.cxx:990
Darwin::Tools::Options::full_cmd
static std::string full_cmd
extended version of the command for reproducibility
Definition: Options.h:277