DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Severity.cpp
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 src/Severity.cxx to src/Severity.cpp).
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#include <assert.h>
13#include <ers/ers.hpp>
14#include <sstream>
15
16namespace {
17const char* SeverityNames[] = { "DEBUG", "LOG", "INFO", "WARNING", "ERROR", "FATAL" };
18}
19
21 BadSeverity,
22 "string \"" << severity << "\" does not contain valid severity",
23 ((std::string)severity))
24
25
30std::string
32{
33 assert(ers::Debug <= severity && severity <= ers::Fatal);
34 return SeverityNames[severity];
35}
36
42std::string
44{
45 assert(ers::Debug <= severity && severity <= ers::Fatal);
46
47 if (severity.type == ers::Debug) {
48 std::ostringstream out;
49 out << SeverityNames[severity] << "_" << severity.rank;
50 return out.str();
51 }
52 return SeverityNames[severity.type];
53}
54
60ers::parse(const std::string& string, ers::severity& s)
61{
62 for (short ss = ers::Debug; ss <= ers::Fatal; ++ss) {
63 if (string == SeverityNames[ss]) {
64 return (s = (ers::severity)ss);
65 }
66 }
67 throw ers::BadSeverity(ERS_HERE, string);
68}
69
75ers::parse(const std::string& string, ers::Severity& s)
76{
77 int level = 0;
79 std::string::size_type pos = string.find('_');
80 if (pos) {
81 std::istringstream in(string.substr(pos + 1));
82 in >> level;
83 ers::parse(string.substr(0, pos), type);
84 } else {
85 ers::parse(string, type);
86 }
87 return (s = ers::Severity(type, level));
88}
#define ERS_HERE
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message_, attributes)
Definition macro.hpp:71
std::string to_string(severity s)
severity parse(const std::string &s, severity &)
Definition Severity.cpp:60
severity
Definition Severity.hpp:37
@ Debug
Definition Severity.hpp:38
@ Fatal
Definition Severity.hpp:43