ATLAS Offline Software
Message.cxx
Go to the documentation of this file.
1 //
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Please feel free to contact me (krumnack@iastate.edu) for bug
7 // reports, feature suggestions, praise and complaints.
8 
9 
10 //
11 // includes
12 //
13 
14 #include <RootCoreUtils/Message.h>
15 
16 #include <cstdlib>
17 #include <cstring>
18 #include <iostream>
19 #include <sstream>
20 #include <RootCoreUtils/Assert.h>
22 #include <RootCoreUtils/PrintMsg.h>
23 
24 //
25 // method implementations
26 //
27 
28 namespace RCU
29 {
31  Message ()
32  : package (0), file (0), line (0), type (MESSAGE_UNSPECIFIED),
33  message (0)
34  {
35  }
36 
37 
38 
40  send () const
41  {
42  MessageType mytype = type;
43  if (mytype < 0 || mytype > MESSAGE_UNSPECIFIED)
44  mytype = MESSAGE_UNSPECIFIED;
45 
46  std::ostringstream str;
47 
48  if (package != 0)
49  {
50  str << package << ":";
51  }
52  if (file != 0)
53  {
54  if (strncmp (file, "../", 3) == 0)
55  str << (file+3) << ":";
56  else
57  str << file << ":";
58  }
59  if (line != 0)
60  str << line << ":";
61 
62  if (mytype != MESSAGE_UNSPECIFIED)
63  {
64  static const char * const type_names[MESSAGE_UNSPECIFIED] =
65  {"message", "warning", "error", "exception", "abort"};
66  str << type_names[mytype] << ":";
67  }
68 
69  if (!str.str().empty())
70  str << " ";
71  if (message != 0)
72  str << message;
73  else
74  str << "(null)";
75 
76  const char *envname = 0;
77  if (mytype == MESSAGE_ABORT)
78  envname = "ROOTCOREUTILS_ABORT";
79  else if (mytype == MESSAGE_EXCEPTION)
80  envname = "ROOTCOREUTILS_EXCEPTION";
81  if (envname)
82  {
83  const char *abort_type = getenv (envname);
84  const MessageType def_type = MESSAGE_EXCEPTION;
85 
86  if (abort_type == 0)
87  {
88  mytype = def_type;
89  } else if (strcmp (abort_type, "abort") == 0)
90  {
91  mytype = MESSAGE_ABORT;
92  } else if (strcmp (abort_type, "exception") == 0)
93  {
94  mytype = MESSAGE_EXCEPTION;
95  } else
96  {
97  mytype = def_type;
98 
99  RCU_WARN_MSG (std::string ("unknown value for ROOTCOREUTILS_ABORT ") + abort_type);
100  }
101  }
102 
103  std::cout << str.str() << std::endl;
104  if (mytype == MESSAGE_EXCEPTION)
105  throw ExceptionMsg (file, line, str.str());
106  if (mytype == MESSAGE_ABORT)
107  std::abort ();
108  }
109 }
checkFileSG.line
line
Definition: checkFileSG.py:75
ExceptionMsg.h
RCU::Message::line
unsigned line
Definition: PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h:37
RCU::MESSAGE_UNSPECIFIED
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition: MessageType.h:41
RCU
This module defines a variety of assert style macros.
Definition: Assert.cxx:26
Assert.h
Message.h
ReweightUtils.message
message
Definition: ReweightUtils.py:15
RCU::Message::Message
Message()
effects: standard constructor guarantee: no-fail
Definition: Message.cxx:31
RCU_WARN_MSG
#define RCU_WARN_MSG(message)
Definition: PrintMsg.h:52
RunTileMonitoring.type_names
type_names
Definition: RunTileMonitoring.py:293
RCU::ExceptionMsg
Definition: ExceptionMsg.h:29
file
TFile * file
Definition: tile_monitor.h:29
RCU::MESSAGE_EXCEPTION
@ MESSAGE_EXCEPTION
description: send out an exception
Definition: MessageType.h:35
RCU::Message::type
MessageType type
description: the type of this message
Definition: PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h:41
RCU::Message::file
const char * file
Definition: PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h:35
RCU::Message::package
const char * package
description: the location where the message was send
Definition: PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h:33
RCU::MessageType
MessageType
Definition: MessageType.h:24
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
RCU::MESSAGE_ABORT
@ MESSAGE_ABORT
description: print and abort
Definition: MessageType.h:38
RCU::Message::message
const char * message
description: the actual message we are sending or 0 if there isn't one
Definition: PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h:46
str
Definition: BTagTrackIpAccessor.cxx:11
PrintMsg.h
RCU::Message::send
void send() const
effects: print the given message guarantee: basic failures: i/o errors
Definition: Message.cxx:40