DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
include
ers
internal
FormattedStandardStream.hxx
Go to the documentation of this file.
1
/*
2
* DUNE DAQ modification notice:
3
* This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
4
* Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
5
* Renamed since fork: yes (from ers/internal/FormattedStandardStream.inc to include/ers/internal/FormattedStandardStream.hxx).
6
*
7
* Original copyright:
8
* Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
9
* Licensed under the Apache License, Version 2.0.
10
*/
11
12
/*
13
* FormattedStandardStream.i
14
* ers
15
*
16
* Created by Serguei Kolos on 02.08.07.
17
* Copyright 2007 CERN. All rights reserved.
18
*
19
*/
20
21
#include <iomanip>
22
#include <iostream>
23
#include <fstream>
24
25
#define FIELD_SEPARATOR "\n\t"
26
#define DELIMITER ','
27
28
template
<
class
Device>
29
typename
ers::FormattedStandardStream<Device>::Fields
ers::FormattedStandardStream<Device>::s_supported_fields
;
30
31
template
<
class
Device>
32
ers::FormattedStandardStream<Device>::Fields::Fields
( )
33
{
34
(*this)[
"severity"
] =
format::Severity
;
35
(*this)[
"time"
] =
format::Time
;
36
(*this)[
"position"
] =
format::Position
;
37
(*this)[
"context"
] =
format::Context
;
38
(*this)[
"pid"
] =
format::PID
;
39
(*this)[
"tid"
] =
format::TID
;
40
(*this)[
"user"
] =
format::User
;
41
(*this)[
"cwd"
] =
format::CWD
;
42
(*this)[
"function"
] =
format::Function
;
43
(*this)[
"line"
] =
format::Line
;
44
(*this)[
"text"
] =
format::Text
;
45
(*this)[
"stack"
] =
format::Stack
;
46
(*this)[
"cause"
] =
format::Cause
;
47
(*this)[
"parameters"
] =
format::Parameters
;
48
(*this)[
"qualifiers"
] =
format::Qualifiers
;
49
}
50
51
template
<
class
Device>
52
std::string
53
ers::FormattedStandardStream<Device>::get_file_name
(
const
std::string & param )
54
{
55
std::string first_token = param.substr( 0, param.find(
','
) );
56
std::map<std::string,ers::format::Token>::iterator it =
s_supported_fields
.find( first_token );
57
if
( it !=
s_supported_fields
.end() )
58
return
""
;
59
else
60
return
first_token;
61
}
62
63
template
<
class
Device>
64
std::string
65
ers::FormattedStandardStream<Device>::get_format
(
const
std::string & param )
66
{
67
std::string first_token = param.substr( 0, param.find(
','
) );
68
std::map<std::string,ers::format::Token>::iterator it =
s_supported_fields
.find( first_token );
69
if
( it !=
s_supported_fields
.end() )
70
return
param;
71
else
72
return
param.substr( first_token.size() < param.size() ? first_token.size() + 1 : param.size() );
73
}
74
75
template
<
class
Device>
76
ers::FormattedStandardStream<Device>::FormattedStandardStream
(
const
std::string & param )
77
: Device(
get_file_name
( param ) )
78
{
79
std::string
format
=
get_format
( param );
80
81
size_t
offset
= 0;
82
size_t
index = std::string::npos;
83
do
{
84
index =
format
.find(
DELIMITER
,
offset
);
85
std::string token =
format
.substr(
offset
, index -
offset
);
86
std::map<std::string,ers::format::Token>::iterator it =
s_supported_fields
.find( token );
87
if
( it !=
s_supported_fields
.end() )
88
m_tokens
.push_back( it->second );
89
90
offset
+= token.size() + 1;
91
}
while
( index != std::string::npos );
92
}
93
94
template
<
class
Device>
95
void
96
ers::FormattedStandardStream<Device>::report
( std::ostream & out,
const
Issue
& issue )
97
{
98
for
(
size_t
i = 0; i <
m_tokens
.size(); i++ )
99
{
100
switch
(
m_tokens
[i] )
101
{
102
case
format::Severity
:
103
out <<
ers::to_string
( issue.
severity
() );
104
break
;
105
case
format::Time
:
106
out << issue.
time
<std::chrono::microseconds>() <<
" "
;
107
break
;
108
case
format::Position
:
109
out <<
"["
<< issue.
context
().
position
( ) <<
"]"
;
110
break
;
111
case
format::Function
:
112
out << issue.
context
().
function_name
();
113
break
;
114
case
format::Line
:
115
out << issue.
context
().
line_number
();
116
break
;
117
case
format::Text
:
118
out << issue.
message
();
119
break
;
120
case
format::Parameters
:
121
{
122
out <<
FIELD_SEPARATOR
<<
"Parameters = "
;
123
for
( ers::string_map::const_iterator it = issue.
parameters
().begin(); it != issue.
parameters
().end(); ++it )
124
{
125
out <<
"'"
<< it->first <<
"="
<< it->second <<
"' "
;
126
}
127
}
128
break
;
129
case
format::Qualifiers
:
130
{
131
out <<
FIELD_SEPARATOR
<<
"Qualifiers = "
;
132
for
( std::vector<std::string>::const_iterator it = issue.
qualifiers
().begin(); it != issue.
qualifiers
().end(); ++it )
133
{
134
out <<
"'"
<< *it <<
"' "
;
135
}
136
}
137
break
;
138
case
format::Context
:
139
out <<
FIELD_SEPARATOR
<<
"host = "
<< issue.
context
().
host_name
()
140
<<
FIELD_SEPARATOR
<<
"user = "
<< issue.
context
().
user_name
()
141
<<
" ("
<< issue.
context
().
user_id
() <<
")"
142
<<
FIELD_SEPARATOR
<<
"process id = "
<< issue.
context
().
process_id
()
143
<<
FIELD_SEPARATOR
<<
"thread id = "
<< issue.
context
().
thread_id
()
144
<<
FIELD_SEPARATOR
<<
"process wd = "
<< issue.
context
().
cwd
();
145
break
;
146
case
format::Host
:
147
out <<
FIELD_SEPARATOR
<<
"host = "
<< issue.
context
().
host_name
();
148
break
;
149
case
format::User
:
150
out <<
FIELD_SEPARATOR
<<
"user = "
<< issue.
context
().
user_name
()
151
<<
" ("
<< issue.
context
().
user_id
() <<
")"
;
152
break
;
153
case
format::PID
:
154
out <<
FIELD_SEPARATOR
<<
"process id = "
<< issue.
context
().
process_id
();
155
break
;
156
case
format::TID
:
157
out <<
FIELD_SEPARATOR
<<
"thread id = "
<< issue.
context
().
thread_id
();
158
break
;
159
case
format::CWD
:
160
out <<
FIELD_SEPARATOR
<<
"process wd = "
<< issue.
context
().
cwd
();
161
break
;
162
case
format::Stack
:
163
{
164
std::vector<std::string> stack = issue.
context
().
stack
();
165
for
(
size_t
i = 0; i < stack.size(); i++ )
166
{
167
out <<
FIELD_SEPARATOR
<<
"#"
<< std::setw(3) << std::left << i << stack[i];
168
}
169
}
170
break
;
171
case
format::Cause
:
172
if
( issue.
cause
() )
173
{
174
out <<
FIELD_SEPARATOR
<<
"was caused by: "
;
175
report
( out, *issue.
cause
() );
176
}
177
break
;
178
default
:
179
break
;
180
}
181
out <<
" "
;
182
}
183
out << std::endl;
184
}
185
186
template
<
class
Device>
187
void
188
ers::FormattedStandardStream<Device>::write
(
const
Issue
& issue )
189
{
190
report
( device().stream(), issue );
191
chained
().write( issue );
192
}
DELIMITER
#define DELIMITER
Definition
FormattedStandardStream.hxx:26
FIELD_SEPARATOR
#define FIELD_SEPARATOR
Definition
FormattedStandardStream.hxx:25
ers::Context::line_number
virtual int line_number() const =0
ers::Context::user_name
virtual const char * user_name() const =0
ers::Context::user_id
virtual int user_id() const =0
ers::Context::thread_id
virtual pid_t thread_id() const =0
ers::Context::host_name
virtual const char * host_name() const =0
ers::Context::position
std::string position(int verbosity=ers::Configuration::instance().verbosity_level()) const
Definition
Context.cpp:116
ers::Context::process_id
virtual pid_t process_id() const =0
ers::Context::cwd
virtual const char * cwd() const =0
ers::Context::stack
std::vector< std::string > stack() const
Definition
Context.cpp:95
ers::Context::function_name
virtual const char * function_name() const =0
ers::Issue
Base class for any user define issue.
Definition
Issue.hpp:80
ers::Issue::context
const Context & context() const
Context of the issue.
Definition
Issue.hpp:111
ers::Issue::severity
ers::Severity severity() const
severity of the issue
Definition
Issue.hpp:123
ers::Issue::qualifiers
const std::vector< std::string > & qualifiers() const
return array of qualifiers
Definition
Issue.hpp:117
ers::Issue::message
const std::string & message() const
General cause of the issue.
Definition
Issue.hpp:114
ers::Issue::parameters
const string_map & parameters() const
return array of parameters
Definition
Issue.hpp:120
ers::Issue::time
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
Definition
Issue.hpp:229
ers::Issue::cause
const Issue * cause() const
return the cause Issue of this Issue
Definition
Issue.hpp:108
ers::OutputStream::chained
OutputStream & chained()
Definition
OutputStream.cpp:29
offset
double offset
Definition
conversions-impl.hh:28
ers::format
Definition
FormattedStandardStream.hpp:28
ers::format::Cause
@ Cause
Definition
FormattedStandardStream.hpp:31
ers::format::Line
@ Line
Definition
FormattedStandardStream.hpp:31
ers::format::User
@ User
Definition
FormattedStandardStream.hpp:30
ers::format::CWD
@ CWD
Definition
FormattedStandardStream.hpp:30
ers::format::Stack
@ Stack
Definition
FormattedStandardStream.hpp:31
ers::format::Qualifiers
@ Qualifiers
Definition
FormattedStandardStream.hpp:31
ers::format::Function
@ Function
Definition
FormattedStandardStream.hpp:31
ers::format::Position
@ Position
Definition
FormattedStandardStream.hpp:30
ers::format::Time
@ Time
Definition
FormattedStandardStream.hpp:30
ers::format::TID
@ TID
Definition
FormattedStandardStream.hpp:30
ers::format::Text
@ Text
Definition
FormattedStandardStream.hpp:31
ers::format::Parameters
@ Parameters
Definition
FormattedStandardStream.hpp:31
ers::format::Context
@ Context
Definition
FormattedStandardStream.hpp:30
ers::format::PID
@ PID
Definition
FormattedStandardStream.hpp:30
ers::format::Severity
@ Severity
Definition
FormattedStandardStream.hpp:30
ers::format::Host
@ Host
Definition
FormattedStandardStream.hpp:30
ers::to_string
std::string to_string(severity s)
ers::FormattedStandardStream::Fields
Definition
FormattedStandardStream.hpp:56
ers::FormattedStandardStream::Fields::Fields
Fields()
Definition
FormattedStandardStream.hxx:32
ers::FormattedStandardStream::report
void report(std::ostream &out, const Issue &issue)
Definition
FormattedStandardStream.hxx:96
ers::FormattedStandardStream::FormattedStandardStream
FormattedStandardStream()=default
ers::FormattedStandardStream::m_tokens
std::vector< format::Token > m_tokens
Definition
FormattedStandardStream.hpp:64
ers::FormattedStandardStream::s_supported_fields
static Fields s_supported_fields
Definition
FormattedStandardStream.hpp:63
ers::FormattedStandardStream::get_file_name
static std::string get_file_name(const std::string ¶m)
Definition
FormattedStandardStream.hxx:53
ers::FormattedStandardStream::get_format
static std::string get_format(const std::string ¶m)
Definition
FormattedStandardStream.hxx:65
ers::FormattedStandardStream::write
void write(const Issue &issue) override
Definition
FormattedStandardStream.hxx:188
Generated on
for DUNE-DAQ by
1.17.0