ATLAS Offline Software
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 
18 namespace MSG {
20 }
21 
22 class PortableMsgStream;
23 PortableMsgStream& endmsg( PortableMsgStream& s );
24 
25 
26 class PortableMsgStream {
27 public:
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 
89 private:
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 
101 inline PortableMsgStream& endmsg( PortableMsgStream& s ) { return s.doOutput(); }
102 
103 
104 #endif //LAR_PORTABLE_SHAPE
105 #endif // __LArWheelCalculator_Impl_PortableMsgStream_H__
106 
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
python.Constants.ERROR
int ERROR
Definition: Control/AthenaCommon/python/Constants.py:18
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
MSG
Definition: MsgLevel.h:28
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
python.Constants.WARNING
int WARNING
Definition: Control/AthenaCommon/python/Constants.py:17
threshold
Definition: chainparser.cxx:74
operator<<
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
Definition: TestGaudiProperty.cxx:69
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:16
DEBUG
#define DEBUG
Definition: page_access.h:11
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35