ATLAS Offline Software
Loading...
Searching...
No Matches
PortableMsgStream.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JFB Feb 2022
6// This is an ersatz message stream class. It directs messages to cout.
7// This is not used within Athena. It is for portability (e.g. to FullSimLight).
8//
9
10#ifndef __LArWheelCalculator_Impl_PortableMsgStream_H__
11#define __LArWheelCalculator_Impl_PortableMsgStream_H__
12#ifdef PORTABLE_LAR_SHAPE
13#include <iostream>
14#include <sstream>
15#include <string>
16
17
18namespace MSG {
20}
21
22class PortableMsgStream;
23PortableMsgStream& endmsg( PortableMsgStream& s );
24
25
26class PortableMsgStream {
27public:
28
29 PortableMsgStream(const std::string label="",MSG::Level threshold=MSG::INFO,std::ostream & stream=std::cout) :
30 m_ostream(stream),
31 m_label(label),
32 m_threshold(threshold)
33 {
34 }
35
36 template<typename T> PortableMsgStream & operator << (const T & t) {
37 if (m_level>=m_threshold) m_sstream << t;
38 return *this;
39 }
40
41 PortableMsgStream& operator<<( PortableMsgStream& ( *t )(PortableMsgStream&)) {
42 if (t==endmsg) {
43 if (m_level>=m_threshold) {
44 return doOutput();
45 }
46 else {
47 m_ostream.clear();
48 return *this;
49 }
50 }
51 return *this;
52 }
53
54 PortableMsgStream& operator << (MSG::Level level) {
55 m_level=level;
56 return *this;
57 }
58
59 PortableMsgStream & doOutput() {
60
61 switch (m_level) {
62 case MSG::VERBOSE:
63 m_ostream << "VERBOSE: ";
64 break;
65 case MSG::DEBUG:
66 m_ostream << "DEBUG : ";
67 break;
68 case MSG::INFO:
69 m_ostream << "INFO : ";
70 break;
71 case MSG::WARNING:
72 m_ostream << "WARNING: ";
73 break;
74 case MSG::ERROR:
75 m_ostream << "ERROR : ";
76 break;
77 case MSG::FATAL:
78 m_ostream << "FATAL : ";
79 break;
80 };
81 m_ostream << m_label;
82 m_ostream << m_sstream.str() << std::endl;
83 m_sstream.str("");
84 m_sstream.clear();
85 return *this;
86 }
87
88
89private:
90
91 PortableMsgStream (const PortableMsgStream &) = delete;
92 PortableMsgStream & operator=(const PortableMsgStream &) = delete;
93
94 std::ostringstream m_sstream;
95 std::ostream & m_ostream;
96 const std::string m_label;
97 MSG::Level m_level;
98 MSG::Level m_threshold;
99};
100
101inline PortableMsgStream& endmsg( PortableMsgStream& s ) { return s.doOutput(); }
102
103
104#endif //LAR_PORTABLE_SHAPE
105#endif // __LArWheelCalculator_Impl_PortableMsgStream_H__
106
#define endmsg
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
std::string label(const std::string &format, int i)
Definition label.h:19
Definition MsgLevel.h:28
#define DEBUG
Definition page_access.h:11