ATLAS Offline Software
Loading...
Searching...
No Matches
Message.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <cstdlib>
14#include <cstring>
15#include <iostream>
16#include <sstream>
17#include <stdexcept>
20
21//
22// method implementations
23//
24
25namespace RCU
26{
27 Message ::
28 Message ()
29 : file (nullptr), line (0), type (MESSAGE_UNSPECIFIED),
30 message (nullptr)
31 {
32 }
33
34
35
36 void Message ::
37 send () const
38 {
39 using namespace msgRootCoreUtils;
40
41 MessageType mytype = type;
42 if (mytype < 0 || mytype > MESSAGE_UNSPECIFIED)
43 mytype = MESSAGE_UNSPECIFIED;
44
45 std::ostringstream str;
46
47 if (file != nullptr)
48 {
49 if (strncmp (file, "../", 3) == 0)
50 str << (file+3) << ":";
51 else
52 str << file << ":";
53 }
54 if (line != 0)
55 str << line << ":";
56
57 if (mytype != MESSAGE_UNSPECIFIED)
58 {
59 static const char * const type_names[MESSAGE_UNSPECIFIED] =
60 {"message", "warning", "error", "exception", "abort"};
61 str << type_names[mytype] << ":";
62 }
63
64 if (!str.str().empty())
65 str << " ";
66 if (message != nullptr)
67 str << message;
68 else
69 str << "(null)";
70
71 const char *envname = nullptr;
72 if (mytype == MESSAGE_ABORT)
73 envname = "ROOTCOREUTILS_ABORT";
74 else if (mytype == MESSAGE_EXCEPTION)
75 envname = "ROOTCOREUTILS_EXCEPTION";
76 if (envname)
77 {
78 const char *abort_type = getenv (envname);
79 const MessageType def_type = MESSAGE_EXCEPTION;
80
81 if (abort_type == nullptr)
82 {
83 mytype = def_type;
84 } else if (strcmp (abort_type, "abort") == 0)
85 {
86 mytype = MESSAGE_ABORT;
87 } else if (strcmp (abort_type, "exception") == 0)
88 {
89 mytype = MESSAGE_EXCEPTION;
90 } else
91 {
92 mytype = def_type;
93
94 ANA_MSG_WARNING (std::string ("unknown value for ") << envname << " " << abort_type);
95 }
96 }
97
98 std::cout << str.str() << std::endl;
99 if (mytype == MESSAGE_EXCEPTION)
100 throw std::runtime_error (str.str());
101 if (mytype == MESSAGE_ABORT)
102 std::abort ();
103 }
104}
#define ANA_MSG_WARNING(xmsg,...)
Macro printing warning messages.
This module defines a variety of assert style macros.
Definition Assert.cxx:23
MessageType
Definition MessageType.h:17
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:31
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition MessageType.h:34
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:28
const char * file
description: the location where the message was send
MessageType type
description: the type of this message
const char * message
description: the actual message we are sending or 0 if there isn't one