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