80 #include <TObjString.h>
83 #include <RAT/FatalError.hh>
84 #include <RAT/json.hh>
90 #include "dprintf.hpp"
92 #include "multiio.hpp"
93 #include "string_utilities.hpp"
94 #include "stringio.hpp"
134 [[noreturn]]
static void Die(std::string message,
int return_code = 1);
138 static void Assert(
bool condition, std::string message,
int return_code = 1);
149 static void AddObject(
const std::string &name, TObject *obj) {
150 objects.push_back(std::pair<std::string, TObject *>(name, obj));
167 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
170 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
173 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
174 const std::string &value);
177 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
178 const std::vector<int> &value);
180 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
181 const std::vector<double> &value);
183 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
184 const std::vector<std::string> &value);
187 inline static void TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
190 static TMap *GetDBTraceMap() {
return dbtrace; };
197 inline static void AddDBEntry(
const std::string &key,
const std::string &value);
224 static std::vector<std::pair<std::string, TObject *>>
objects;
236 dbtrace->Add(
new TObjString(key.c_str()),
new TObjString(value.c_str()));
241 inline std::string to_ratdb_float_string(
double value) {
243 return std::string(
"0.0");
245 return ::to_string(value);
248 inline std::string to_ratdb_double_string(
double value) {
249 std::string str = to_ratdb_float_string(value);
250 size_t pos = str.find(
"d");
251 if (pos == std::string::npos) str +=
"d";
255 inline std::string escape_ratdb_string(
const std::string &value) {
256 if (value.find(
"\"") != std::string::npos)
Log::Die(
"RATDB Trace Eror: value string with quotes inside!");
257 return "\"" + value +
"\"";
260 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
int value) {
261 AddDBEntry(table +
"[" + index +
"]." + field, ::to_string(value));
264 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
double value) {
265 AddDBEntry(table +
"[" + index +
"]." + field, to_ratdb_double_string(value));
268 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
269 const std::string &value) {
270 AddDBEntry(table +
"[" + index +
"]." + field, escape_ratdb_string(value));
273 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
274 const std::vector<int> &value) {
275 std::string key = table +
"[" + index +
"]." + field;
278 std::string str_value(
"[ ");
279 for (
unsigned i = 0; i < value.size(); i++) {
280 str_value += ::to_string(value[i]) +
", ";
287 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
288 const std::vector<double> &value) {
289 std::string key = table +
"[" + index +
"]." + field;
292 std::string str_value(
"[ ");
293 for (
unsigned i = 0; i < value.size(); i++) {
294 str_value += to_ratdb_double_string(value[i]) +
", ";
301 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
302 const std::vector<std::string> &value) {
303 std::string key = table +
"[" + index +
"]." + field;
306 std::string str_value(
"[ ");
307 for (
unsigned i = 0; i < value.size(); i++) {
308 str_value += escape_ratdb_string(value[i]) +
", ";
315 void Log::TraceDBAccess(
const std::string &table,
const std::string &index,
const std::string &field,
317 std::string key = table +
"[" + index +
"]." + field;
320 std::stringstream ss;
322 writer.putValue(value);
static int log_level
Definition: Log.hh:217
static std::vector< std::pair< std::string, TObject * > > objects
Definition: Log.hh:224
static void AddDBEntry(const std::string &key, const std::string &value)
Inline functions.
Definition: Log.hh:234
static void SetDBTraceState(bool state=true)
Definition: Log.hh:161
static void AddObject(const std::string &name, TObject *obj)
Definition: Log.hh:149
static const std::string GetLogBuffer()
Definition: Log.cc:119
static bool GetDBTraceState()
Definition: Log.hh:164
static void Die(std::string message, int return_code=1)
Definition: Log.cc:90
static const std::string & GetMacro()
Definition: Log.hh:146
static void SetLogLevel(Level level)
Definition: Log.cc:85
static omtext * outstreams[4]
Definition: Log.hh:212
static std::vector< std::pair< std::string, TObject * > > GetObjects()
Definition: Log.hh:155
static int GetDisplayLevel()
Definition: Log.hh:119
static void TraceDBAccess(const std::string &table, const std::string &index, const std::string &field, int value)
Definition: Log.hh:260
Level
Definition: Log.hh:101
@ INFO
Definition: Log.hh:103
@ DETAIL
Definition: Log.hh:104
@ DEBUG
Definition: Log.hh:106
@ WARN
Definition: Log.hh:102
static TMap * dbtrace
Definition: Log.hh:222
static int GetLogLevel()
Definition: Log.hh:125
static std::string filename
Definition: Log.hh:214
static oftext logfile
Definition: Log.hh:215
static void AddMacro(const std::string &contents)
Definition: Log.hh:144
static std::string macro
Definition: Log.hh:219
static void Assert(bool condition, std::string message, int return_code=1)
Definition: Log.cc:95
static void SetupIO()
Definition: Log.cc:99
static bool enable_dbtrace
Definition: Log.hh:221
static void SetDisplayLevel(Level level)
Definition: Log.cc:80
static int display_level
Definition: Log.hh:216
static void ClearOMText(omtext *out)
Definition: Log.cc:114
Log()
Definition: Log.cc:59
static bool Init(std::string _filename, Level display=INFO, Level log=DETAIL)
Definition: Log.cc:63
Definition: fileio.hpp:22
Definition: multiio.hpp:18
Definition: CCCrossSecMessenger.hh:29