The Gaudi Framework  v36r1 (3e2fb5a8)
Message.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_MESSAGE_H
12 #define GAUDIKERNEL_MESSAGE_H
13 
15 #include "GaudiKernel/Kernel.h" // for GAUDI_API
17 #include <iostream>
18 #include <string>
19 
27 class GAUDI_API Message final {
28 public:
30  Message() = default;
31 
33  Message( const char* src, int type, const char* msg );
34 
36  Message( std::string src, int type, std::string msg );
37 
39  ~Message() = default;
40 
42  const std::string& getMessage() const;
43 
45  void setMessage( std::string msg );
46 
48  int getType() const;
49 
51  void setType( int msg_type );
52 
54  const std::string& getSource() const;
55 
57  void setSource( std::string_view src );
58 
60  const std::string& getFormat() const;
61 
63  static const std::string getDefaultFormat();
64 
66  void setFormat( std::string msg ) const;
67 
69  const std::string& getTimeFormat() const;
70 
72  static const std::string getDefaultTimeFormat();
73 
75  void setTimeFormat( std::string timeFormat ) const;
76 
78  friend bool operator<( const Message& lhs, const Message& rhs );
79 
82 
84  friend bool operator==( const Message& a, const Message& b );
85 
86 private:
88  void invalidFormat() const;
89 
91  void makeFormattedMsg( const std::string& format ) const;
92 
94  void decodeFormat( const std::string& format ) const;
95 
97  void sizeField( const std::string& text, bool middle = false ) const;
98 
100  void setWidth( const std::string& formatArg ) const;
101 
103  std::string m_source{"UNKNOWN"};
104  int m_type{0};
105  mutable std::string m_format{DEFAULT_FORMAT};
106  mutable std::string m_time_format{DEFAULT_TIME_FORMAT};
108  mutable char m_fill{' '};
109  mutable int m_width{0};
110  mutable bool m_left{true};
111 
117  pthread_t m_ecThrd{pthread_self()};
118 
119 
122  static const char FORMAT_PREFIX = '%';
124 
126  static const char JUSTIFY_LEFT = 'L';
127 
129  static const char JUSTIFY_RIGHT = 'R';
130 
132  static const char MESSAGE = 'M';
133 
135  static const char TYPE = 'T';
136 
138  static const char TIME = 't';
139 
141  static const char UTIME = 'u';
142 
144  static const char SOURCE = 'S';
145 
147  static const char COMP = 'C';
148 
150  static const char SLOT = 's';
151 
153  static const char EVTNUM = 'e';
154 
156  static const char THREAD = 'X';
157 
159  static const char EVENTID = 'E';
160 
162  static const char FILL = 'F';
163 
165  static const char WIDTH = 'W';
167 
169  static constexpr const char* DEFAULT_FORMAT = "% F%18W%S%7W%R%T %0W%M";
170 
172  static constexpr const char* DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S,%f";
173 };
174 
175 #endif
EventContext::ContextID_t
size_t ContextID_t
Definition: EventContext.h:36
Write.stream
stream
Definition: Write.py:31
std::string
STL class.
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:30
Message::~Message
~Message()=default
Default destructor.
EventContext::eventID
const EventIDBase & eventID() const
Definition: EventContext.h:55
Gaudi::operator==
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:435
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:18
Message::Message
Message()=default
Default constructor.
GaudiAlg::operator<<
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:142
operator<
bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:255
Message
Definition: Message.h:27
std::ostream
STL class.
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:51
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Message::m_message
std::string m_message
The message text.
Definition: Message.h:102
gaudirun.type
type
Definition: gaudirun.py:154
ThreadLocalContext.h
EventContext.h
Kernel.h
Message::m_formatted_msg
std::string m_formatted_msg
Formatted message.
Definition: Message.h:107
EventIDBase
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventIDBase.h:66
std::size_t
EventContext::evt
ContextEvt_t evt() const
Definition: EventContext.h:50
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81