| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MessageSvc.h
Go to the documentation of this file.
1 #ifndef GAUDI_MESSAGESVC_H
2 #define GAUDI_MESSAGESVC_H
3
4 // Include files
5 #include <string>
6 #include <vector>
7 #include <map>
8 #include <set>
9 #include <iosfwd>
10
11 #include "GaudiKernel/StatusCode.h"
12 #include "GaudiKernel/Service.h"
13 #include "GaudiKernel/IMessageSvc.h"
14 #include "GaudiKernel/Message.h"
15 #include "GaudiKernel/Property.h"
16
17 #include <boost/thread/recursive_mutex.hpp>
18 #include <boost/array.hpp>
19
20 // Forward declarations
21 class ISvcLocator;
22
23 //
24 // ClassName: MessageSvc
25 //
26 // Description: The MessageSvc service implements the IMessageSvc interface and provides the
27 // basic messaging needed by batch oriented applications.
28 //
29 // Author: Iain Last
30 //
31 class MessageSvc : public extends2<Service, IMessageSvc, IInactiveMessageCounter> {
32 public:
33 typedef std::pair< std::string, std::ostream* > NamedStream;
34 typedef std::multimap< int, NamedStream > StreamMap;
35 typedef std::multimap< StatusCode, Message > MessageMap;
36 typedef std::map< std::string, int > ThresholdMap;
37
38 // Default constructor.
39 MessageSvc( const std::string& name, ISvcLocator* svcloc );
40 // Destructor.
41 virtual ~MessageSvc();
42
43 // Implementation of IService::reinitialize()
44 virtual StatusCode reinitialize();
45 // Implementation of IService::initialize()
46 virtual StatusCode initialize();
47 // Implementation of IService::finalize()
48 virtual StatusCode finalize();
49
50 // Implementation of IMessageSvc::reportMessage()
51 virtual void reportMessage( const Message& message );
52
53 // Implementation of IMessageSvc::reportMessage()
54 virtual void reportMessage( const Message& msg, int outputLevel );
55
56 // Implementation of IMessageSvc::reportMessage()
57 virtual void reportMessage( const StatusCode& code, const std::string& source = "");
58
59 // Implementation of IMessageSvc::reportMessage()
60 virtual void reportMessage( const char* source, int type, const char* message);
61
62 // Implementation of IMessageSvc::reportMessage()
63 virtual void reportMessage( const std::string& source, int type, const std::string& message);
64
65 // Implementation of IMessageSvc::insertMessage()
66 virtual void insertMessage( const StatusCode& code, const Message& message );
67
68 // Implementation of IMessageSvc::eraseMessage()
69 virtual void eraseMessage();
70
71 // Implementation of IMessageSvc::eraseMessage()
72 virtual void eraseMessage( const StatusCode& code ) ;
73
74 // Implementation of IMessageSvc::eraseMessage()
75 virtual void eraseMessage( const StatusCode& code, const Message& message );
76
77 // Implementation of IMessageSvc::insertStream()
78 virtual void insertStream( int message_type, const std::string& name, std::ostream* stream );
79
80 // Implementation of IMessageSvc::eraseStream()
81 virtual void eraseStream();
82
83 // Implementation of IMessageSvc::eraseStream()
84 virtual void eraseStream( int message_type );
85
86 // Implementation of IMessageSvc::eraseStream()
87 virtual void eraseStream( int message_type, std::ostream* stream );
88
89 // Implementation of IMessageSvc::eraseStream()
90 virtual void eraseStream( std::ostream* stream );
91
92 // Implementation of IMessageSvc::desaultStream()
93 virtual std::ostream* defaultStream() const {
94 return m_defaultStream;
95 }
96
97 // Implementation of IMessageSvc::setDefaultStream()
98 virtual void setDefaultStream( std::ostream* stream ) {
99 boost::recursive_mutex::scoped_lock lock(m_reportMutex);
100 m_defaultStream = stream;
101 }
102
103 // Implementation of IMessageSvc::ouputLevel()
104 virtual int outputLevel() const;
105
106 // Implementation of IMessageSvc::ouputLevel()
107 virtual int outputLevel(const std::string& source) const;
108
109 // Implementation of IMessageSvc::setOuputLevel()
110 virtual void setOutputLevel(int new_level);
111
112 // Implementation of IMessageSvc::setOuputLevel()
113 virtual void setOutputLevel(const std::string& source, int new_level);
114
115 // Implementation of IMessageSvc::useColor()
116 virtual bool useColor() const { return m_color; }
117
118 // Implementation of IMessageSvc::getLogColor()
119 virtual std::string getLogColor(int logLevel) const;
120
121 // Implementation of IMessageSvc::messageCount()
122 virtual int messageCount( MSG::Level logLevel ) const;
123
124 // Implementation of IInactiveMessageCounter::incrInactiveCount()
125 virtual void incrInactiveCount( MSG::Level level,
126 const std::string& src );
127
128
129 private:
130 std::ostream* m_defaultStream;
131 Message m_defaultMessage;
132 StreamMap m_streamMap;
133 MessageMap m_messageMap;
134 ThresholdMap m_thresholdMap;
135 std::string m_defaultFormat;
136 std::string m_defaultTimeFormat;
137 StringArrayProperty m_thresholdProp[MSG::NUM_LEVELS];
138 BooleanProperty m_color;
139 BooleanProperty m_stats;
140 UnsignedIntegerProperty m_statLevel;
141 StringArrayProperty m_logColors[MSG::NUM_LEVELS];
142 IntegerProperty m_msgLimit[MSG::NUM_LEVELS];
143
144 std::string m_logColorCodes[MSG::NUM_LEVELS];
145
147 struct MsgAry {
149 typedef boost::array<int,MSG::NUM_LEVELS> ArrayType;
151 ArrayType msg;
153 MsgAry() {
154 // This is a special hack to have a fast initialization of the array
155 // because we cannot use initializer lists in the constructor (should be
156 // possible in C++0X).
157 static const ArrayType zero = {{0}};
158 msg = zero;
159 }
160 };
161
162 std::map<std::string,MsgAry> m_sourceMap, m_inactiveMap;
163 BooleanProperty m_suppress, m_inactCount;
164
165 std::string colTrans(std::string, int);
166 typedef std::map<std::string, MSG::Color> ColorMap;
167 ColorMap m_colMap;
168
169 int m_msgCount[MSG::NUM_LEVELS];
170
171 std::map<std::string, std::string> m_loggedStreamsName;
172 typedef std::map<std::string, std::ostream*> LoggedStreamsMap_t;
173 LoggedStreamsMap_t m_loggedStreams;
174
175 void initColors(Property& prop);
176 void setupColors(Property& prop);
177 void setupLimits(Property& prop);
178 void setupThreshold(Property& prop);
179 void setupInactCount(Property& prop);
180
181 void setupLogStreams();
182
183 void tee( const std::string& sourceName, const std::string& logFileName,
184 const std::set<std::string>& declaredOutFileNames );
185
187 mutable boost::recursive_mutex m_reportMutex;
188
190 mutable boost::recursive_mutex m_messageMapMutex;
191
194 mutable boost::recursive_mutex m_thresholdMapMutex;
195 };
196
197 #endif