DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ers Namespace Reference

Namespaces

namespace  format
 

Classes

struct  AbortStream
 Aborts the current application. More...
 
class  AnyIssue
 
class  Configuration
 Manager of ERS streams configuration. More...
 
class  Context
 An abstract interface to access an Issue context. More...
 
struct  erstraceStream
 
struct  ExitStream
 Terminates the current application. More...
 
class  FilterStream
 Filtering stream implementation. More...
 
struct  FormattedStandardStream
 
struct  GlobalLockStream
 Lock for ERS streams. More...
 
class  InputStream
 ERS Issue input stream interface. More...
 
class  Issue
 Base class for any user define issue. More...
 
class  IssueCatcherHandler
 Implements issue catcher lifetime management. More...
 
class  IssueFactory
 Implements factory pattern for user defined Issues. More...
 
class  IssueReceiver
 ERS Issue receiver interface. More...
 
class  IssueRegistrator
 
class  LocalContext
 
struct  LocalProcessContext
 
struct  LockStream
 Lock implementation for an ERS stream. More...
 
struct  NullStream
 Null stream. More...
 
class  OutputStream
 ERS abstract output stream interface. More...
 
class  PluginException
 
class  PluginManager
 
class  PyContext
 
class  PyIssue
 
class  RemoteContext
 
struct  RemoteProcessContext
 
class  RFilterStream
 Filtering stream implementation. More...
 
struct  Severity
 
class  SingletonCreator
 
struct  StandardStream
 Single line, human readable format stream. More...
 
struct  StandardStreamOutput
 
class  StreamInitializer
 
class  StreamManager
 This class manages and provides access to ERS streams. More...
 
class  ThrottleStream
 Throws issues as exceptions. More...
 
struct  ThrowStream
 Throws issues as exceptions. More...
 

Typedefs

typedef Issue Exception
 
typedef std::map< std::string, std::string > string_map
 
using inheritance_type = std::list<std::string>
 

Enumerations

enum  severity {
  Debug , Log , Information , Warning ,
  Error , Fatal
}
 

Functions

std::ostream & operator<< (std::ostream &, const ers::Configuration &)
 
IssueCatcherHandlerset_issue_catcher (const std::function< void(const ers::Issue &)> &catcher)
 
int debug_level ()
 
void debug (const Issue &issue, int level=debug_level())
 
void error (const Issue &issue)
 
void fatal (const Issue &issue)
 
void info (const Issue &issue)
 
void log (const Issue &issue)
 
int verbosity_level ()
 
void warning (const Issue &issue)
 
int enable_core_dump ()
 
void tokenize (const std::string &text, const std::string &separators, std::vector< std::string > &tokens)
 
int read_from_environment (const char *name, int default_value)
 
const char * read_from_environment (const char *name, const char *default_value)
 
std::ostream & operator<< (std::ostream &, const ers::Issue &)
 
std::ostream & operator<< (std::ostream &, const IssueFactory &factory)
 streaming operator
 
dunedaq::ersschema::Context to_schema (const Context &c)
 
dunedaq::ersschema::SimpleIssue to_schema (const Issue &i)
 
dunedaq::ersschema::IssueChain to_schema_chain (const Issue &i)
 
void to_schema (const Context &c, dunedaq::ersschema::Context &out)
 
void to_schema (const Issue &i, dunedaq::ersschema::SimpleIssue &out)
 
void to_schema (const Issue &i, dunedaq::ersschema::IssueChain &out)
 
severity parse (const std::string &s, severity &)
 
Severity parse (const std::string &s, Severity &)
 
std::string to_string (severity s)
 
std::string to_string (Severity s)
 Transforms a severity type into the corresponding string.
 
std::ostream & operator<< (std::ostream &out, ers::severity severity)
 
std::ostream & operator<< (std::ostream &out, const ers::Severity &severity)
 
std::istream & operator>> (std::istream &in, ers::severity &severity)
 
std::istream & operator>> (std::istream &in, ers::Severity &severity)
 
std::ostream & operator<< (std::ostream &, const ers::StreamManager &)
 
 message (message)
 
 pydebug (msg, lvl)
 
 pylog (msg)
 
 pyinfo (msg)
 
 pywarning (issue)
 
 pyerror (issue)
 
 pyfatal (issue)
 

Detailed Description

This is a wrapping namespace for all ERS classes and global functions.

Typedef Documentation

◆ Exception

Definition at line 40 of file ers.hpp.

◆ inheritance_type

using ers::inheritance_type = std::list<std::string>

Definition at line 44 of file Issue.hpp.

◆ string_map

typedef std::map<std::string, std::string> ers::string_map

Definition at line 42 of file Issue.hpp.

Enumeration Type Documentation

◆ severity

Enumerator
Debug 
Log 
Information 
Warning 
Error 
Fatal 

Definition at line 26 of file Severity.hpp.

@ Debug
Definition Severity.hpp:26
@ Error
Definition Severity.hpp:26
@ Fatal
Definition Severity.hpp:26
@ Log
Definition Severity.hpp:26
@ Warning
Definition Severity.hpp:26
@ Information
Definition Severity.hpp:26

Function Documentation

◆ debug()

void ers::debug ( const Issue & issue,
int level = debug_level() )
inline

This function sends the issue to the ERS DEBUG stream which corresponds to the given debug level.

Parameters
issuethe issue to be reported \level debug level which will be associated with the reported issue

Definition at line 74 of file ers.hpp.

75 { StreamManager::instance().debug( issue, level ); }

◆ debug_level()

int ers::debug_level ( )
inline

This function returns the current debug level for ERS.

Definition at line 66 of file ers.hpp.

67 { return Configuration::instance().debug_level( ); }

◆ enable_core_dump()

int ers::enable_core_dump ( )
inline

Definition at line 118 of file ers.hpp.

118 {
119 rlimit core_limit = { RLIM_INFINITY, RLIM_INFINITY };
120 return setrlimit( RLIMIT_CORE, &core_limit );
121 }

◆ error()

void ers::error ( const Issue & issue)
inline

This function sends the issue to the ERS ERROR stream.

Parameters
issuethe issue to be reported

Definition at line 81 of file ers.hpp.

82 { LocalStream::instance().error( issue ); }

◆ fatal()

void ers::fatal ( const Issue & issue)
inline

This function sends the issue to the ERS FATAL stream.

Parameters
issuethe issue to be reported

Definition at line 88 of file ers.hpp.

89 { LocalStream::instance().fatal( issue ); }

◆ info()

void ers::info ( const Issue & issue)
inline

This function sends the issue to the ERS INFO stream.

Parameters
issuethe issue to be reported

Definition at line 95 of file ers.hpp.

96 { StreamManager::instance().information( issue ); }

◆ log()

void ers::log ( const Issue & issue)
inline

This function sends the issue to the ERS LOG stream.

Parameters
issuethe issue to be reported

Definition at line 102 of file ers.hpp.

103 { StreamManager::instance().log( issue ); }

◆ message()

ers.message ( message)

Definition at line 84 of file __init__.py.

84def message(message):
85 # This class collects information needed for message context
86 ct = PyContext(message)
87 # Still need to do something about these
88 package_name = "erspy"
89 type="Warning"
90 # Create Context using the ers-python bindings
91 rpc = ers.RemoteProcessContext(ct.host_name,ct.process_id,ct.thread_id,ct.cwd,ct.user_id,ct.user_name,ct.application_name)
92 rc = ers.RemoteContext(package_name,ct.file_name,ct.line_number,ct.function_name,rpc)
93 # Create and return an ers issue
94 return ers.AnyIssue(type, rc, message)
95
96
97'''Bunch of functions to wrap a text string and inject it as an ers message of different types'''

◆ operator<<() [1/6]

std::ostream & ers::operator<< ( std::ostream & out,
const ers::Configuration & conf )

Definition at line 48 of file Configuration.cpp.

50{
51 out << "debug level = " << conf.m_debug_level << " verbosity level = " << conf.m_verbosity_level;
52 return out;
53}
int m_debug_level
current active level for the debug stream
int m_verbosity_level
current verbosity level for all streams

◆ operator<<() [2/6]

std::ostream & ers::operator<< ( std::ostream & out,
const ers::Issue & issue )

Standard streaming operator - puts the issue in human readable format into the standard out stream.

Parameters
outthe destination out stream
issuethe Issue to be printed

Definition at line 212 of file Issue.cpp.

213 {
215 }
int verbosity_level()
Definition ers.hpp:108
static std::ostream & print(std::ostream &out, const Issue &issue, int verbosity)

◆ operator<<() [3/6]

std::ostream & ers::operator<< ( std::ostream & out,
const ers::StreamManager &  )

Definition at line 372 of file StreamManager.cpp.

374{
375 for( short ss = ers::Debug; ss <= ers::Fatal; ++ss )
376 {
377 out << (ers::severity)ss << "\t\""
378 << get_stream_description( (ers::severity)ss ) << "\"" << std::endl;
379 }
380 return out;
381}
severity
Definition Severity.hpp:26

◆ operator<<() [4/6]

std::ostream & ers::operator<< ( std::ostream & ,
const IssueFactory & factory )

streaming operator

◆ operator<<() [5/6]

std::ostream & ers::operator<< ( std::ostream & out,
const ers::Severity & severity )
inline

Definition at line 53 of file Severity.hpp.

54 {
55 out << to_string( severity );
56 return out;
57 }
std::string to_string(severity s)

◆ operator<<() [6/6]

std::ostream & ers::operator<< ( std::ostream & out,
ers::severity severity )
inline

Definition at line 47 of file Severity.hpp.

48 {
49 out << to_string( severity );
50 return out;
51 }

◆ operator>>() [1/2]

std::istream & ers::operator>> ( std::istream & in,
ers::Severity & severity )
inline

Definition at line 67 of file Severity.hpp.

68 {
69 std::string string;
70 in >> string;
71 parse( string, severity );
72 return in;
73 }
severity parse(const std::string &s, severity &)
Definition Severity.cpp:60

◆ operator>>() [2/2]

std::istream & ers::operator>> ( std::istream & in,
ers::severity & severity )
inline

Definition at line 59 of file Severity.hpp.

60 {
61 std::string string;
62 in >> string;
63 parse( string, severity );
64 return in;
65 }

◆ parse() [1/2]

ers::Severity ers::parse ( const std::string & string,
ers::Severity & s )

Parses a string and extracts a severity

Parameters
sthe string to parse
Returns
a severity value

Definition at line 77 of file Severity.cpp.

78{
79 int level = 0;
81 std::string::size_type pos = string.find( '_' );
82 if ( pos )
83 {
84 std::istringstream in( string.substr( pos + 1 ) );
85 in >> level;
86 ers::parse( string.substr( 0, pos ), type );
87 }
88 else
89 {
90 ers::parse( string, type );
91 }
92 return ( s = ers::Severity( type, level ) );
93}

◆ parse() [2/2]

ers::severity ers::parse ( const std::string & string,
ers::severity & s )

Parses a string and extracts a severity

Parameters
sthe string to parse
Returns
a severity value

Definition at line 60 of file Severity.cpp.

61{
62 for( short ss = ers::Debug; ss <= ers::Fatal; ++ss )
63 {
64 if ( string == SeverityNames[ss] )
65 {
66 return ( s = (ers::severity)ss );
67 }
68 }
69 throw ers::BadSeverity( ERS_HERE, string );
70}
#define ERS_HERE

◆ pydebug()

ers.pydebug ( msg,
lvl )

Definition at line 98 of file __init__.py.

98def pydebug( msg, lvl ):
99 "sends msg to the debug stream"
100 ers.debug( isinstance( msg, ers.AnyIssue ) and msg or message( msg ), lvl )
101
void debug(const Issue &issue, int level=debug_level())
Definition ers.hpp:74

◆ pyerror()

ers.pyerror ( issue)

Definition at line 121 of file __init__.py.

121def pyerror( issue ):
122 "sends issue to the error stream"
123 assert isinstance(issue, ers.AnyIssue), \
124 'Only an instance of ers.Issue sub-class can be sent to the ers.error stream'
125 ers.error( issue )
126
void error(const Issue &issue)
Definition ers.hpp:81

◆ pyfatal()

ers.pyfatal ( issue)

Definition at line 127 of file __init__.py.

127def pyfatal( issue ):
128 "sends issue to the fatal stream"
129 assert isinstance(issue,ers.AnyIssue), \
130 'Only an instance of ers.Issue sub-class can be sent to the ers.fatal stream'
131 ers.fatal( issue )
void fatal(const Issue &issue)
Definition ers.hpp:88

◆ pyinfo()

ers.pyinfo ( msg)

Definition at line 106 of file __init__.py.

106def pyinfo( msg ):
107 "sends msg to the information stream"
108 ers.info( isinstance( msg, ers.AnyIssue ) and msg or message( msg ) )
109
110'''These just inject an issue into the more serious streams.
111 The only thing these add over just calling the bound ers function directly is that they
112 warn you if you use the wrong type of argument.
113 Mainly here because the old ers.py had them, and they provide a consistency of interface
114 rather than forcing the user to use these calls for some things and direct ers calls for others'''
void info(const Issue &issue)
Definition ers.hpp:95

◆ pylog()

ers.pylog ( msg)

Definition at line 102 of file __init__.py.

102def pylog( msg ):
103 "sends msg to the log stream"
104 ers.log( isinstance( msg, ers.AnyIssue ) and msg or message( msg ) )
105
void log(const Issue &issue)
Definition ers.hpp:102

◆ pywarning()

ers.pywarning ( issue)

Definition at line 115 of file __init__.py.

115def pywarning( issue ):
116 "sends issue to the warning stream"
117 assert isinstance(issue,ers.AnyIssue), \
118 'Only an instance of ers.Issue sub-class can be sent to the ers.warning stream'
119 ers.warning( issue )
120
void warning(const Issue &issue)
Definition ers.hpp:115

◆ read_from_environment() [1/2]

const char * ers::read_from_environment ( const char * name,
const char * default_value )

Definition at line 43 of file Util.cpp.

44{
45 const char * env = ::getenv( name );
46 return ( env ? env : default_value);
47}

◆ read_from_environment() [2/2]

int ers::read_from_environment ( const char * name,
int default_value )

Definition at line 27 of file Util.cpp.

28{
29 int value = default_value;
30 const char * env = ::getenv( name );
31 if ( env )
32 {
33 if ( sscanf( env, "%d", &value ) != 1 )
34 {
35 ERS_INTERNAL_ERROR( "Wrong value \"" << env
36 << "\" is given for the \"" << name << "\" environment" )
37 }
38 }
39 return value;
40}
#define ERS_INTERNAL_ERROR(message)
Definition macro.hpp:52

◆ set_issue_catcher()

ers::IssueCatcherHandler * ers::LocalStream::set_issue_catcher ( const std::function< void(const ers::Issue &)> & catcher)
inline

This function sets up the local issue handler function. This function will be executed in the context of dedicated thread which will be created as a result of this call. All the issues which are reported via the ers::error, ers::fatal and ers::warning functions will be forwarded to this thread.

Parameters
issuethe issue to be reported
Returns
pointer to the handler object, which allows to remove the catcher by just destroying this object. If an applications ignores this return value there will no way of de installing the issue catcher.
Exceptions
ers::IssueCatcherAlreadySetfor safety reasons local issue handler can be set only once
See also
ers::error()
ers::fatal()
ers::warning()

Definition at line 60 of file ers.hpp.

61 { return LocalStream::instance().set_issue_catcher( catcher ); }

◆ to_schema() [1/5]

dunedaq::ersschema::Context ers::to_schema ( const Context & c)

Definition at line 5 of file Schema.cpp.

5 {
6
8 to_schema( c, out);
9 return out;
10 }
dunedaq::ersschema::Context to_schema(const Context &c)
Definition Schema.cpp:5

◆ to_schema() [2/5]

void ers::to_schema ( const Context & c,
dunedaq::ersschema::Context & out )

Definition at line 27 of file Schema.cpp.

27 {
28
29 out.set_cwd( c.cwd() );
30 out.set_file_name( c.file_name() );
31 out.set_function_name( c.function_name() );
32 out.set_host_name( c.host_name() );
33 out.set_line_number( c.line_number() );
34 out.set_package_name( c.package_name() );
35
36 out.set_process_id( c.process_id() );
37 out.set_thread_id( c.thread_id() );
38 out.set_user_id( c.user_id() );
39 out.set_user_name( c.user_name() );
40 out.set_application_name( c.application_name() );
41
42}

◆ to_schema() [3/5]

dunedaq::ersschema::SimpleIssue ers::to_schema ( const Issue & i)

Definition at line 12 of file Schema.cpp.

12 {
13
15 to_schema( i, out);
16 return out;
17}

◆ to_schema() [4/5]

void ers::to_schema ( const Issue & i,
dunedaq::ersschema::IssueChain & out )

Definition at line 71 of file Schema.cpp.

71 {
72
73 (* out.mutable_final()) = to_schema(i);
74
75 auto cause_ptr = i.cause();
76
77 while ( cause_ptr ) {
78 auto ptr = out.add_causes() ;
79 to_schema( *cause_ptr, *ptr);
80 ptr -> set_severity(ers::to_string(i.severity())); // severity is forced to be the same as the top issue
81 cause_ptr = cause_ptr -> cause();
82 }
83
84 }
ers::Severity severity() const
severity of the issue
Definition Issue.hpp:112
const Issue * cause() const
return the cause Issue of this Issue
Definition Issue.hpp:97

◆ to_schema() [5/5]

void ers::to_schema ( const Issue & i,
dunedaq::ersschema::SimpleIssue & out )

Definition at line 45 of file Schema.cpp.

45 {
46
47 auto c = to_schema( i.context() ) ;
48
49 (*out.mutable_context())=c;
50
51 out.set_name( i.get_class_name() );
52
53 auto inheritance = i.get_class_inheritance();
54 for ( auto & c : inheritance ) {
55 out.add_inheritance(c);
56 }
57
58 out.set_message( i.message() ) ;
59 out.set_severity( ers::to_string( i.severity() ) );
60 auto time = std::chrono::duration_cast<std::chrono::nanoseconds>(i.ptime().time_since_epoch()).count();
61 out.set_time(time);
62
63 auto & params = (* out.mutable_parameters());
64 for ( auto p : i.parameters() ) {
65 params[p.first] = p.second;
66 }
67
68}
const Context & context() const
Context of the issue.
Definition Issue.hpp:100
virtual const char * get_class_name() const =0
Get key for class (used for serialisation)
const system_clock::time_point & ptime() const
original time point of the issue
Definition Issue.hpp:130
const std::string & message() const
General cause of the issue.
Definition Issue.hpp:103
const string_map & parameters() const
return array of parameters
Definition Issue.hpp:109
virtual inheritance_type get_class_inheritance() const =0
Get inheritance chain.

◆ to_schema_chain()

dunedaq::ersschema::IssueChain ers::to_schema_chain ( const Issue & i)

Definition at line 20 of file Schema.cpp.

20 {
21
23 to_schema( i, out );
24 return out;
25}

◆ to_string() [1/2]

std::string ers::to_string ( ers::Severity severity)

Transforms a severity type into the corresponding string.

Parameters
sseverity
Returns
pointer to string with associated text

Definition at line 42 of file Severity.cpp.

43{
44 assert( ers::Debug <= severity && severity <= ers::Fatal );
45
46 if ( severity.type == ers::Debug )
47 {
48 std::ostringstream out;
49 out << SeverityNames[severity] << "_" << severity.rank;
50 return out.str();
51 }
52 return SeverityNames[severity.type];
53}

◆ to_string() [2/2]

std::string ers::to_string ( severity s)

◆ tokenize()

void ers::tokenize ( const std::string & text,
const std::string & separators,
std::vector< std::string > & tokens )

Definition at line 7 of file Util.cpp.

10{
11 std::string::size_type start_p, end_p;
12 start_p = 0;
13 do
14 {
15 end_p = text.find_first_of(separators,start_p);
16 if (end_p == std::string::npos)
17 {
18 end_p = text.length();
19 }
20 result.push_back( text.substr( start_p, end_p - start_p ) );
21 start_p = text.find_first_not_of( separators, end_p );
22 }
23 while( start_p != std::string::npos );
24}

◆ verbosity_level()

int ers::verbosity_level ( )
inline

This function returns the current verbosity level for ERS.

Definition at line 108 of file ers.hpp.

109 { return Configuration::instance().verbosity_level( ); }

◆ warning()

void ers::warning ( const Issue & issue)
inline

This function sends the issue to the ERS WARNING stream.

Parameters
issuethe issue to be reported

Definition at line 115 of file ers.hpp.

116 { LocalStream::instance().warning( issue ); }