The Gaudi Framework  master (37c0b60a)
Message.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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
16 #include <iostream>
17 #include <string>
18 
26 class GAUDI_API Message final {
27 public:
29  Message() = default;
30 
32  Message( const char* src, int type, const char* msg );
33 
35  Message( std::string src, int type, std::string msg );
36 
38  ~Message() = default;
39 
41  const std::string& getMessage() const { return m_message; }
42 
44  void setMessage( std::string msg ) { m_message = std::move( msg ); }
45 
47  int getType() const { return m_type; }
48 
50  void setType( int msg_type ) { m_type = msg_type; }
51 
53  const std::string& getSource() const { return m_source; }
54 
56  void setSource( std::string_view src ) { m_source = src; }
57 
60  EventContext::ContextID_t getEventSlot() const { return m_ecSlot; }
61  EventContext::ContextEvt_t getEventNumber() const { return m_ecEvt; }
62  const EventIDBase& getEventID() const { return m_ecEvtId; }
64 
66  const std::string& getFormat() const { return m_format; }
67 
69  static const std::string getDefaultFormat() { return DEFAULT_FORMAT; }
70 
72  void setFormat( std::string msg ) const;
73 
75  const std::string& getTimeFormat() const { return m_time_format; }
76 
78  static const std::string getDefaultTimeFormat() { return DEFAULT_TIME_FORMAT; }
79 
81  void setTimeFormat( std::string timeFormat ) const;
82 
84  friend bool operator<( const Message& lhs, const Message& rhs );
85 
88 
90  friend bool operator==( const Message& a, const Message& b );
91 
92 private:
94  void invalidFormat() const;
95 
97  void makeFormattedMsg( const std::string& format ) const;
98 
100  void decodeFormat( const std::string& format ) const;
101 
103  void sizeField( const std::string& text, bool middle = false ) const;
104 
106  void setWidth( const std::string& formatArg ) const;
107 
109  std::string m_source{ "UNKNOWN" };
110  int m_type{ 0 };
111  mutable std::string m_format{ DEFAULT_FORMAT };
112  mutable std::string m_time_format{ DEFAULT_TIME_FORMAT };
114  mutable char m_fill{ ' ' };
115  mutable int m_width{ 0 };
116  mutable bool m_left{ true };
117 
123  pthread_t m_ecThrd{};
124 
125 
128  static const char FORMAT_PREFIX = '%';
130 
132  static const char JUSTIFY_LEFT = 'L';
133 
135  static const char JUSTIFY_RIGHT = 'R';
136 
138  static const char MESSAGE = 'M';
139 
141  static const char TYPE = 'T';
142 
144  static const char TIME = 't';
145 
147  static const char UTIME = 'u';
148 
150  static const char SOURCE = 'S';
151 
153  static const char COMP = 'C';
154 
156  static const char SLOT = 's';
157 
159  static const char EVTNUM = 'e';
160 
162  static const char THREAD = 'X';
163 
165  static const char EVENTID = 'E';
166 
168  static const char FILL = 'F';
169 
171  static const char WIDTH = 'W';
173 
175  static constexpr const char* DEFAULT_FORMAT = "% F%18W%S%7W%R%T %0W%M";
176 
178  static constexpr const char* DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S,%f";
179 };
180 
181 #endif
EventContext::ContextID_t
size_t ContextID_t
Definition: EventContext.h:36
Write.stream
stream
Definition: Write.py:32
std::string
STL class.
operator<
bool operator<(backwards_compatibility_hack_time_timespan, backwards_compatibility_hack_time_timespan)
Definition: Time.icpp:220
std::move
T move(T... args)
Message::~Message
~Message()=default
Default destructor.
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
EventContext::INVALID_CONTEXT_ID
static constexpr ContextID_t INVALID_CONTEXT_ID
Definition: EventContext.h:39
Message::Message
Message()=default
Default constructor.
Message::getDefaultFormat
static const std::string getDefaultFormat()
Get the default format string.
Definition: Message.h:69
Message::setMessage
void setMessage(std::string msg)
Set the message string.
Definition: Message.h:44
Message::getTimeFormat
const std::string & getTimeFormat() const
Get the time format string.
Definition: Message.h:75
Message
Definition: Message.h:26
Gaudi::Parsers::operator<<
std::ostream & operator<<(std::ostream &o, const Catalog &c)
printout operator
Definition: Catalog.h:68
std::ostream
STL class.
Message::getEventSlot
EventContext::ContextID_t getEventSlot() const
Definition: Message.h:60
EventContext::INVALID_CONTEXT_EVT
static constexpr ContextEvt_t INVALID_CONTEXT_EVT
Definition: EventContext.h:40
Message::setSource
void setSource(std::string_view src)
Set the message source.
Definition: Message.h:56
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Message::getEventNumber
EventContext::ContextEvt_t getEventNumber() const
Definition: Message.h:61
Message::m_message
std::string m_message
The message text.
Definition: Message.h:108
gaudirun.type
type
Definition: gaudirun.py:160
Message::getEventID
const EventIDBase & getEventID() const
Definition: Message.h:62
EventContext.h
Message::getMessage
const std::string & getMessage() const
Get the message string.
Definition: Message.h:41
Kernel.h
ProduceConsume.Message
Message
Definition: ProduceConsume.py:110
Message::getFormat
const std::string & getFormat() const
Get the format string.
Definition: Message.h:66
Message::m_ecEvtId
EventIDBase m_ecEvtId
Full event ID.
Definition: Message.h:122
Message::m_formatted_msg
std::string m_formatted_msg
Formatted message.
Definition: Message.h:113
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
Message::getDefaultTimeFormat
static const std::string getDefaultTimeFormat()
Get the default time format string.
Definition: Message.h:78
Message::getType
int getType() const
Get the message type.
Definition: Message.h:47
Message::setType
void setType(int msg_type)
Set the message type.
Definition: Message.h:50
Message::getSource
const std::string & getSource() const
Get the message source.
Definition: Message.h:53
Gaudi::Details::operator==
bool operator==(const PropertyId &lhs, const PropertyId &rhs)
Definition: PropertyId.h:111
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81