ATLAS Offline Software
Loading...
Searching...
No Matches
VP1Msg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7// //
8// Implementation of class VP1Msg //
9// //
10// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11// Initial version: March 2008 //
12// //
14
15#include "VP1Base/VP1Msg.h"
16#include "VP1Base/IVP1System.h"
17#include "VP1Base/VP1QtUtils.h"
18#include <iostream>
19
20#ifndef BUILDVP1LIGHT //TODO: Merge the two mechanisms, specifically for VP1
21 std::atomic<bool> VP1Msg::m_verbose = VP1QtUtils::environmentVariableIsOn("VP1_VERBOSE_OUTPUT");
22 std::atomic<bool> VP1Msg::m_debug = VP1QtUtils::environmentVariableIsOn("VP1_DEBUG_OUTPUT");
23#endif
24#ifdef BUILDVP1LIGHT
25 std::atomic<bool> VP1Msg::m_verbose = VP1QtUtils::expertSettingIsSet("general", "ExpertSettings/VP1_VERBOSE_OUTPUT");
26 std::atomic<bool> VP1Msg::m_debug = VP1QtUtils::expertSettingIsSet("general", "ExpertSettings/VP1_DEBUG_OUTPUT");
27#endif
28
29//____________________________________________________________________
30void VP1Msg::message( const QString& str, IVP1System*sys )
31{
32 if (sys)
33 sys->message(str);
34 else
35 std::cout << prefix_msg() << ": "<< str.toStdString()<<std::endl;
36}
37
38//____________________________________________________________________
39void VP1Msg::messageDebug( const QString& str )
40{
41 if (!debug()){
42 return;
43 }
44 std::cout << prefix_debug() << ": "<< str.toStdString()<<std::endl;
45}
46
47//____________________________________________________________________
48void VP1Msg::messageWarning( const QString& str, IVP1System* sys /* defaults to: 0 */ )
49{
50 if (sys)
51 sys->message(str);
52 std::cout << prefix_warning() << ": "<< str.toStdString()<<std::endl;
53}
54
55// only the 'Warning' label is printed in red
56//____________________________________________________________________
57void VP1Msg::messageWarningRed( const QString& str, IVP1System* sys /* defaults to: 0 */ )
58{
59 if (sys)
60 sys->message(str);
61
62 // colors, see:
63 // - http://brianmilco.blogspot.ch/2011/11/color-debug-output-with-qt-and-qdebug.html
64 // - http://misc.flogisoft.com/bash/tip_colors_and_formatting
65 std::string msg = str.toStdString();
66 fprintf(stderr, "\033[1m\033[31mWarning:\033[21m\033[0m: %s\n", msg.c_str() );
67}
68// The whole 'Warning' message is printed in red
69//____________________________________________________________________
70void VP1Msg::messageWarningAllRed( const QString& str, IVP1System* sys /* defaults to: 0 */ )
71{
72 if (sys)
73 sys->message(str);
74
75 // colors, see:
76 // - http://brianmilco.blogspot.ch/2011/11/color-debug-output-with-qt-and-qdebug.html
77 // - http://misc.flogisoft.com/bash/tip_colors_and_formatting
78 std::string msg = str.toStdString();
79 fprintf(stderr, "\033[1m\033[31mWarning:\033[21m %s\033[0m\n", msg.c_str() );
80}
81
82
83//____________________________________________________________________
84void VP1Msg::messageVerbose( const QString& str )
85{
86 if (!verbose()){
87 return;
88 }
89 std::cout<<prefix_verbose()<<": "<<str.toStdString()<<std::endl;
90}
91
92//____________________________________________________________________
93void VP1Msg::message(const QStringList& l, const QString& addtoend, IVP1System*sys )
94{
95 if (addtoend.isEmpty()) {
96 for (const QString& s : l)
97 message(s,sys);
98 } else {
99 for (const QString& s : l)
100 message(s+addtoend,sys);
101 }
102}
103
104//____________________________________________________________________
105void VP1Msg::messageDebug(const QStringList& l, const QString& addtoend )
106{
107 if (!debug()){
108 return;
109 }
110 if (addtoend.isEmpty()) {
111 for (const QString& s : l)
112 messageDebug(s);
113 } else {
114 for (const QString& s : l)
115 messageDebug(s+addtoend);
116 }
117}
118
119//____________________________________________________________________
120void VP1Msg::messageVerbose(const QStringList& l, const QString& addtoend )
121{
122 if (!verbose()){
123 return;
124 }
125 if (addtoend.isEmpty()) {
126 for (const QString& s : l)
128 } else {
129 for (const QString& s : l)
130 messageVerbose(s+addtoend);
131 }
132}
133
134//____________________________________________________________________
135void VP1Msg::message(const QString& addtostart, const QStringList& l,
136 const QString& addtoend, IVP1System*sys )
137{
138 if (addtostart.isEmpty()) {
139 message(l,addtoend,sys);
140 return;
141 }
142 if (addtoend.isEmpty()) {
143 for (const QString& s : l)
144 message(addtostart+s,sys);
145 } else {
146 for (const QString& s : l)
147 message(addtostart+s+addtoend,sys);
148 }
149}
150
151//____________________________________________________________________
152void VP1Msg::messageDebug(const QString& addtostart, const QStringList& l, const QString& addtoend )
153{
154 if (!debug()){
155 return;
156 }
157 if (addtostart.isEmpty()) {
158 messageDebug(l,addtoend);
159 return;
160 }
161 if (addtoend.isEmpty()) {
162 for (const QString& s : l)
163 messageDebug(addtostart+s);
164 } else {
165 for (const QString& s : l)
166 messageDebug(addtostart+s+addtoend);
167 }
168}
169
170//____________________________________________________________________
171void VP1Msg::messageVerbose(const QString& addtostart, const QStringList& l, const QString& addtoend )
172{
173 if (!verbose()){
174 return;
175 }
176 if (addtostart.isEmpty()) {
177 messageVerbose(l,addtoend);
178 return;
179 }
180 if (addtoend.isEmpty()) {
181 for (const QString& s : l)
182 messageVerbose(addtostart+s);
183 } else {
184 for (const QString& s : l)
185 messageVerbose(addtostart+s+addtoend);
186 }
187}
188
189#if defined BUILDVP1LIGHT
190void VP1Msg::enableMsg(const QString& type, const QString& name){
191 if( name == "ExpertSettings/VP1_VERBOSE_OUTPUT"){
193} else {
195}
196}
197#else
198void VP1Msg::enableMsg(const QString& name){
199 if( name == "VP1_VERBOSE_OUTPUT"){
201 } else {
203 }
204}
205#endif
static bool debug()
Definition VP1Msg.h:32
static const char * prefix_warning()
Definition VP1Msg.h:58
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static bool verbose()
Definition VP1Msg.h:31
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static void message(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:30
static std::atomic< bool > m_debug
Definition VP1Msg.h:65
static void messageWarningRed(const QString &str, IVP1System *sys=0)
Definition VP1Msg.cxx:57
static void messageWarningAllRed(const QString &str, IVP1System *sys=0)
Definition VP1Msg.cxx:70
static std::atomic< bool > m_verbose
Definition VP1Msg.h:64
static const char * prefix_msg()
Definition VP1Msg.h:56
static void messageWarning(const QString &, IVP1System *sys=0)
Definition VP1Msg.cxx:48
static const char * prefix_debug()
Definition VP1Msg.h:57
static const char * prefix_verbose()
Definition VP1Msg.h:59
static void enableMsg(const QString &)
Definition VP1Msg.cxx:198
static bool environmentVariableIsOn(const QString &name)
static bool expertSettingIsSet(const QString &type, const QString &name)
static bool environmentVariableIsSet(const QString &name)
MsgStream & msg
Definition testRead.cxx:32