DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ers::Issue Class Referenceabstract

Base class for any user define issue. More...

#include <Issue.hpp>

Inheritance diagram for ers::Issue:
[legend]
Collaboration diagram for ers::Issue:
[legend]

Public Member Functions

 Issue (const Context &context, const std::string &message=std::string())
 
 Issue (const Context &context, const std::exception &cause)
 
 Issue (const Context &context, const std::string &message, const std::exception &cause)
 
 Issue (const Issue &other)
 
virtual ~Issue () noexcept
 
virtual Issueclone () const =0
 
virtual const char * get_class_name () const =0
 Get key for class (used for serialisation)
 
virtual inheritance_type get_class_inheritance () const =0
 Get inheritance chain.
 
virtual void raise () const =0
 throws a copy of this issue preserving the real issue type
 
void add_qualifier (const std::string &qualif)
 adds a qualifier to the issue
 
const Issuecause () const
 return the cause Issue of this Issue
 
const Contextcontext () const
 Context of the issue.
 
const std::string & message () const
 General cause of the issue.
 
const std::vector< std::string > & qualifiers () const
 return array of qualifiers
 
const string_mapparameters () const
 return array of parameters
 
ers::Severity severity () const
 severity of the issue
 
template<class Precision = std::chrono::seconds>
std::string time (const std::string &format="%Y-%b-%d %H:%M:%S", bool isUTC=false) const
 string representation of local time of the issue
 
template<class Precision >
std::string localtime (const std::string &format="%Y-%b-%d %H:%M:%S") const
 string representation of UTC time of the issue
 
template<class Precision >
std::string gmtime (const std::string &format="%Y-%b-%d %H:%M:%S") const
 
std::time_t time_t () const
 seconds since 1 Jan 1970
 
const system_clock::time_point & ptime () const
 original time point of the issue
 
const char * what () const noexcept
 General cause of the issue.
 
ers::Severity set_severity (ers::Severity severity) const
 
void wrap_message (const std::string &begin, const std::string &end)
 

Protected Member Functions

 Issue (Severity severity, const system_clock::time_point &time, const ers::Context &context, const std::string &message, const std::vector< std::string > &qualifiers, const std::map< std::string, std::string > &parameters, const ers::Issue *cause=0)
 Gets a value of any type that has an input operator for the standard stream defined.
 
template<typename T >
void get_value (const std::string &key, T &value) const
 
void get_value (const std::string &key, const char *&value) const
 
void get_value (const std::string &key, std::string &value) const
 Sets a value of any type that has an output operator for the standard stream defined.
 
template<typename T >
void set_value (const std::string &key, T value)
 
void set_message (const std::string &message)
 
void prepend_message (const std::string &message)
 

Static Protected Member Functions

static auto _get_inheritance ()
 

Private Member Functions

Issueoperator= (const Issue &other)=delete
 

Private Attributes

std::unique_ptr< const Issuem_cause
 Issue that caused the current issue.
 
std::unique_ptr< Contextm_context
 Context of the current issue.
 
std::string m_message
 Issue's explanation text.
 
std::vector< std::string > m_qualifiers
 List of associated qualifiers.
 
Severity m_severity
 Issue's severity.
 
system_clock::time_point m_time
 Time when issue was thrown.
 
string_map m_values
 List of user defined attributes.
 

Friends

class IssueFactory
 

Detailed Description

Base class for any user define issue.

This is a base class for any user define issue. The class stores all attributes declared in a user define descendant class in a hashmap as sting key/value pairs. The object defines a number of methods for providing access to this map. For an example of how to define a custom subclass of the Issue have a look at the SampleIssues.h file.

See also
ers::IssueFactory
SampleIssues.h

Definition at line 68 of file Issue.hpp.

Constructor & Destructor Documentation

◆ Issue() [1/5]

Issue::Issue ( const Context & context,
const std::string & message = std::string() )

This constructor create a new issue with the given message.

Parameters
contextthe context of the Issue, e.g where in the code the issue appeared
messagethe user message associated with this issue

Definition at line 69 of file Issue.cpp.

71 : m_context( context.clone() ),
72 m_message( message ),
74 m_time( system_clock::now() )
75{
76 add_qualifier( m_context->package_name() );
77 add_default_qualifiers( *this );
78}
virtual Context * clone() const =0
const Context & context() const
Context of the issue.
Definition Issue.hpp:100
Severity m_severity
Issue's severity.
Definition Issue.hpp:177
std::unique_ptr< Context > m_context
Context of the current issue.
Definition Issue.hpp:174
system_clock::time_point m_time
Time when issue was thrown.
Definition Issue.hpp:178
std::string m_message
Issue's explanation text.
Definition Issue.hpp:175
void add_qualifier(const std::string &qualif)
adds a qualifier to the issue
Definition Issue.cpp:172
@ Error
Definition Severity.hpp:26

◆ Issue() [2/5]

Issue::Issue ( const Context & context,
const std::exception & cause )

This constructor takes another exceptions as its cause.

Parameters
contextthe context of the Issue, e.g where in the code the issue appeared
causethe other exception that has caused this one

Definition at line 84 of file Issue.cpp.

86 : m_context( context.clone() ),
88 m_time( system_clock::now() )
89{
90 const Issue * issue = dynamic_cast<const Issue *>( &cause );
91 m_cause.reset( issue ? issue->clone() : new StdIssue( ERS_HERE, cause.what() ) );
92 add_qualifier( m_context->package_name() );
93 add_default_qualifiers( *this );
94}
#define ERS_HERE
Base class for any user define issue.
Definition Issue.hpp:69
virtual Issue * clone() const =0
std::unique_ptr< const Issue > m_cause
Issue that caused the current issue.
Definition Issue.hpp:173
const char * what() const noexcept
General cause of the issue.
Definition Issue.hpp:133
const Issue * cause() const
return the cause Issue of this Issue
Definition Issue.hpp:97

◆ Issue() [3/5]

Issue::Issue ( const Context & context,
const std::string & message,
const std::exception & cause )

This constructor takes another exceptions as its cause.

Parameters
contextthe context of the Issue, e.g where in the code did the issue appear
messagethe user message associated with this issue
causeexception that caused the current issue

Definition at line 101 of file Issue.cpp.

104 : m_context( context.clone() ),
105 m_message( message ),
107 m_time( system_clock::now() )
108{
109 const Issue * issue = dynamic_cast<const Issue *>( &cause );
110 m_cause.reset( issue ? issue->clone() : new StdIssue( ERS_HERE, cause.what() ) );
111 add_qualifier( m_context->package_name() );
112 add_default_qualifiers( *this );
113}

◆ Issue() [4/5]

Issue::Issue ( const Issue & other)

Definition at line 53 of file Issue.cpp.

54 : std::exception( other ),
55 m_cause( other.m_cause.get() ? other.m_cause->clone() : 0 ),
56 m_context( other.m_context->clone() ),
57 m_message( other.m_message ),
59 m_severity( other.m_severity ),
60 m_time( other.m_time ),
61 m_values( other.m_values )
62{ ; }
string_map m_values
List of user defined attributes.
Definition Issue.hpp:179
std::vector< std::string > m_qualifiers
List of associated qualifiers.
Definition Issue.hpp:176

◆ ~Issue()

ers::Issue::~Issue ( )
virtualnoexcept

Definition at line 131 of file Issue.cpp.

132{ ; }

◆ Issue() [5/5]

Issue::Issue ( Severity severity,
const system_clock::time_point & time,
const ers::Context & context,
const std::string & message,
const std::vector< std::string > & qualifiers,
const std::map< std::string, std::string > & parameters,
const ers::Issue * cause = 0 )
protected

Gets a value of any type that has an input operator for the standard stream defined.

Definition at line 115 of file Issue.cpp.

122 : m_cause( cause ),
124 m_message( message ),
127 m_time( time ),
129{ ; }
const std::vector< std::string > & qualifiers() const
return array of qualifiers
Definition Issue.hpp:106
const string_map & parameters() const
return array of parameters
Definition Issue.hpp:109
severity
Definition Severity.hpp:26

Member Function Documentation

◆ _get_inheritance()

static auto ers::Issue::_get_inheritance ( )
inlinestaticprotected

Definition at line 164 of file Issue.hpp.

164 {
165 inheritance_type chain;
166 chain.push_back( "ers::Issue" ) ;
167 return chain;
168 }
std::list< std::string > inheritance_type
Definition Issue.hpp:44

◆ add_qualifier()

void Issue::add_qualifier ( const std::string & qualifier)

adds a qualifier to the issue

Add a new qualifier to the qualifiers list of this issue

Parameters
qualifierthe qualifier to add

Definition at line 172 of file Issue.cpp.

173{
174 if ( std::find( m_qualifiers.begin(), m_qualifiers.end(), qualifier ) == m_qualifiers.end() ) {
175 m_qualifiers.push_back( qualifier );
176 }
177}

◆ cause()

const Issue * ers::Issue::cause ( ) const
inline

return the cause Issue of this Issue

<

Definition at line 97 of file Issue.hpp.

98 { return m_cause.get(); }

◆ clone()

virtual Issue * ers::Issue::clone ( ) const
pure virtual

◆ context()

const Context & ers::Issue::context ( ) const
inline

Context of the issue.

<

Definition at line 100 of file Issue.hpp.

101 { return *(m_context.get()); }

◆ get_class_inheritance()

virtual inheritance_type ers::Issue::get_class_inheritance ( ) const
pure virtual

Get inheritance chain.

Implemented in ers::AnyIssue.

◆ get_class_name()

virtual const char * ers::Issue::get_class_name ( ) const
pure virtual

Get key for class (used for serialisation)

Implemented in dunedaq::logging::Logging::InternalMessage, and ers::AnyIssue.

◆ get_value() [1/3]

void ers::Issue::get_value ( const std::string & key,
const char *& value ) const
protected

Definition at line 141 of file Issue.cpp.

142{
143 string_map::const_iterator it = m_values.find(key);
144 if ( it != m_values.end() )
145 {
146 value = it->second.c_str();
147 }
148 else
149 {
150 throw ers::NoValue( ERS_HERE, key );
151 }
152}

◆ get_value() [2/3]

void ers::Issue::get_value ( const std::string & key,
std::string & value ) const
protected

Sets a value of any type that has an output operator for the standard stream defined.

Definition at line 155 of file Issue.cpp.

156{
157 string_map::const_iterator it = m_values.find(key);
158 if ( it != m_values.end() )
159 {
160 value = it->second;
161 }
162 else
163 {
164 throw ers::NoValue( ERS_HERE, key );
165 }
166}

◆ get_value() [3/3]

template<typename T >
void ers::Issue::get_value ( const std::string & key,
T & value ) const
protected

◆ gmtime()

template<class Precision >
std::string ers::Issue::gmtime ( const std::string & format = "%Y-%b-%d %H:%M:%S") const
inline

Definition at line 125 of file Issue.hpp.

125 :%M:%S") const
126 { return time<Precision>(format, true); }

◆ localtime()

template<class Precision >
std::string ers::Issue::localtime ( const std::string & format = "%Y-%b-%d %H:%M:%S") const
inline

string representation of UTC time of the issue

Definition at line 120 of file Issue.hpp.

◆ message()

const std::string & ers::Issue::message ( ) const
inline

General cause of the issue.

<

Definition at line 103 of file Issue.hpp.

104 { return m_message; }

◆ operator=()

Issue & ers::Issue::operator= ( const Issue & other)
privatedelete

◆ parameters()

const string_map & ers::Issue::parameters ( ) const
inline

return array of parameters

<

Definition at line 109 of file Issue.hpp.

110 { return m_values; }

◆ prepend_message()

void Issue::prepend_message ( const std::string & msg)
protected

Adds the given text to the beginning of the issue's message

Parameters
msgtext to be prepended

Definition at line 191 of file Issue.cpp.

192{
193 m_message = msg + m_message;
194}

◆ ptime()

const system_clock::time_point & ers::Issue::ptime ( ) const
inline

original time point of the issue

<

Definition at line 130 of file Issue.hpp.

131 { return m_time; }

◆ qualifiers()

const std::vector< std::string > & ers::Issue::qualifiers ( ) const
inline

return array of qualifiers

<

Definition at line 106 of file Issue.hpp.

107 { return m_qualifiers; }

◆ raise()

virtual void ers::Issue::raise ( ) const
pure virtual

throws a copy of this issue preserving the real issue type

Implemented in dunedaq::logging::Logging::InternalMessage, and ers::AnyIssue.

◆ set_message()

void ers::Issue::set_message ( const std::string & message)
inlineprotected

Definition at line 159 of file Issue.hpp.

160 { m_message = message; }
const std::string & message() const
General cause of the issue.
Definition Issue.hpp:103

◆ set_severity()

ers::Severity Issue::set_severity ( ers::Severity severity) const

Definition at line 180 of file Issue.cpp.

181{
182 ers::Severity old_severity = m_severity;
184 return old_severity;
185}
ers::Severity severity() const
severity of the issue
Definition Issue.hpp:112

◆ set_value()

template<typename T >
void ers::Issue::set_value ( const std::string & key,
T value )
protected

◆ severity()

ers::Severity ers::Issue::severity ( ) const
inline

severity of the issue

<

Definition at line 112 of file Issue.hpp.

113 { return m_severity; }

◆ time()

template<class Precision >
std::string ers::Issue::time ( const std::string & format = "%Y-%b-%d %H:%M:%S",
bool isUTC = false ) const

string representation of local time of the issue

Definition at line 218 of file Issue.hpp.

219{
220 static const int width(::log10(Precision::period::den));
221
222 std::time_t t = time_t();
223 std::tm tm = isUTC ? *gmtime_r(&t, &tm) : *localtime_r(&t, &tm);
224
225 char buff[128];
226 std::strftime(buff, 128 - 16, format.c_str(), &tm);
227
228 auto c = std::chrono::duration_cast<Precision>(
229 m_time.time_since_epoch()).count();
230 double frac = c - (double)t*Precision::period::den;
231 sprintf(buff + strlen(buff), ",%0*.0f", width, frac);
232
233 return buff;
234}
std::time_t time_t() const
seconds since 1 Jan 1970
Definition Issue.cpp:135

◆ time_t()

std::time_t ers::Issue::time_t ( ) const

seconds since 1 Jan 1970

Definition at line 135 of file Issue.cpp.

136{
137 return system_clock::to_time_t(m_time);
138}

◆ what()

const char * ers::Issue::what ( ) const
inlinenoexcept

General cause of the issue.

<

Definition at line 133 of file Issue.hpp.

134 { return m_message.c_str(); }

◆ wrap_message()

void Issue::wrap_message ( const std::string & begin,
const std::string & end )

Adds the given text strings to the beginning and to the end of the issue's message

Parameters
begintext to be prepended
begintext to be appended

Definition at line 201 of file Issue.cpp.

202{
203 m_message = begin + m_message + end;
204}

Friends And Related Symbol Documentation

◆ IssueFactory

friend class IssueFactory
friend

Definition at line 70 of file Issue.hpp.

Member Data Documentation

◆ m_cause

std::unique_ptr<const Issue> ers::Issue::m_cause
private

Issue that caused the current issue.

Definition at line 173 of file Issue.hpp.

◆ m_context

std::unique_ptr<Context> ers::Issue::m_context
private

Context of the current issue.

Definition at line 174 of file Issue.hpp.

◆ m_message

std::string ers::Issue::m_message
private

Issue's explanation text.

Definition at line 175 of file Issue.hpp.

◆ m_qualifiers

std::vector<std::string> ers::Issue::m_qualifiers
private

List of associated qualifiers.

Definition at line 176 of file Issue.hpp.

◆ m_severity

Severity ers::Issue::m_severity
mutableprivate

Issue's severity.

Definition at line 177 of file Issue.hpp.

◆ m_time

system_clock::time_point ers::Issue::m_time
private

Time when issue was thrown.

Definition at line 178 of file Issue.hpp.

◆ m_values

string_map ers::Issue::m_values
private

List of user defined attributes.

Definition at line 179 of file Issue.hpp.


The documentation for this class was generated from the following files: