ATLAS Offline Software
Loading...
Searching...
No Matches
HistUtil.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef HISTUTIL_H
5#define HISTUTIL_H
6#include "TVirtualMutex.h"
7#include "TH1.h"
8#include <string>
9#include <string_view>
10
11namespace HistUtil {
12// Helper class to avoid that newly created histograms are added to random
13// root TDirectories
15public:
17 TVirtualMutex *root_global_mutex ATLAS_THREAD_SAFE = gGlobalMutex;
18 if (root_global_mutex) {
19 root_global_mutex->Lock();
20 }
21 m_addDirectory=TH1::AddDirectoryStatus();
22 if (m_addDirectory) {
23 TH1::AddDirectory(kFALSE);
24 }
25 }
27 if (m_addDirectory) {
28 TH1::AddDirectory(m_addDirectory);
29 }
30 TVirtualMutex *root_global_mutex ATLAS_THREAD_SAFE = gGlobalMutex;
31 if (root_global_mutex) {
32 root_global_mutex->UnLock();
33 }
34 }
35private:
36 bool m_addDirectory = false;
37};
38
39// Helper class to compose strings in a stringstream-way but only with the overhead of
40// string concatenation
41class StringCat {
42public:
43 StringCat(const std::string &a) :m_str(a) {}
44 StringCat(std::string &&a) :m_str(std::move(a)) {}
45 StringCat() = default;
46
47 const std::string &str() const { return m_str; }
48 std::string release() { return std::move(m_str); }
49 StringCat &operator<<(const std::string &a) { m_str += a; return *this;}
50 StringCat &operator<<(const char *a) { m_str += a; return *this;}
51 StringCat &operator<<(const std::string_view &a) { m_str += a; return *this;}
52 template <typename T>
53 StringCat &operator<<(const T &a) { m_str += std::to_string(a); return *this;}
54private:
55 std::string m_str;
56};
57
58}
59#endif
static Double_t a
#define ATLAS_THREAD_SAFE
StringCat & operator<<(const std::string &a)
Definition HistUtil.h:49
StringCat & operator<<(const std::string_view &a)
Definition HistUtil.h:51
StringCat & operator<<(const T &a)
Definition HistUtil.h:53
std::string m_str
Definition HistUtil.h:55
StringCat(std::string &&a)
Definition HistUtil.h:44
const std::string & str() const
Definition HistUtil.h:47
StringCat(const std::string &a)
Definition HistUtil.h:43
StringCat & operator<<(const char *a)
Definition HistUtil.h:50
std::string release()
Definition HistUtil.h:48
STL namespace.