Belle II Software development
MonitoringObject.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <TNamed.h>
12#include <TCanvas.h>
13
14#include <vector>
15#include <string>
16#include <map>
17#include <framework/logging/Logger.h>
18
19namespace Belle2 {
30 class MonitoringObject : public TNamed {
31
32 public:
38 explicit MonitoringObject(const std::string& name)
39 {
40 fName = name;
41 }
42
47 void addCanvas(TCanvas* canv)
48 {
49 for (auto cc : m_Canvases) {
50 if (cc->GetName() == canv->GetName()) {
51 B2ERROR("Canvas with name " << canv->GetName() << " already in the " << fName <<
52 " MonitoringObject! Use different name (or call getCanvas(name) to access pointer to the existing TCanvas).");
53 return;
54 }
55 }
56 m_Canvases.push_back(canv);
57 };
58
62 const std::map<std::string, float>& getVariables()
63 {
64 return m_vars;
65 }
66
70 const std::map<std::string, float>& getUpError()
71 {
72 return m_upErr;
73 }
74
78 const std::map<std::string, float>& getLowError()
79 {
80 return m_dwErr;
81 }
82
86 const std::vector<std::pair<std::string, std::string>>& getStringVariables()
87 {
88 return m_strVars;
89 }
90
94 TCanvas* getCanvas(const std::string& name)
95 {
96 for (auto cc : m_Canvases) {
97 if (cc->GetName() == name) return cc;
98 }
99 B2WARNING("TCanvas with name " << name << " not found in MonitoringObject " << fName);
100 return NULL;
101 };
102
106 const std::vector<TCanvas*>& getListOfCanvases()
107 {
108 return m_Canvases;
109 }
110
114 void print() const;
115
123 void setVariable(const std::string& var, float val, float upErr = -1., float dwErr = -1)
124 {
125
126 auto vv = m_vars.find(var);
127 if (vv != m_vars.end()) vv->second = val;
128 else m_vars.insert({var, val});
129
130 if (upErr > 0) {
131 auto vvE = m_upErr.find(var);
132 if (vvE != m_upErr.end()) vvE->second = upErr;
133 else m_upErr.insert({var, upErr});
134 }
135
136 if (dwErr > 0) {
137 auto vvE = m_dwErr.find(var);
138 if (vvE != m_dwErr.end()) vvE->second = dwErr;
139 else m_dwErr.insert({var, dwErr});
140 }
141
142 }
143
149 void setVariable(const std::string& var, const std::string& val)
150 {
151
152 for (auto& pair : m_strVars) {
153 if (pair.first == var) {
154 pair.second = val;
155 return;
156 }
157 }
158 m_strVars.push_back(std::pair<std::string, std::string>(var, val));
159 }
160
161
162 private:
163
164 std::vector<TCanvas*> m_Canvases;
166 std::map<std::string, float> m_vars;
167 std::map<std::string, float> m_upErr;
168 std::map<std::string, float> m_dwErr;
170 std::vector<std::pair<std::string, std::string>> m_strVars;
174 }; //class
175
177} // namespace Belle2
MonitoringObject is a basic object to hold data for the run-dependency monitoring Run summary TCanvas...
MonitoringObject(const std::string &name)
Constructor with name (always use this)
std::vector< TCanvas * > m_Canvases
vector of all TCanvases
MonitoringObject()
Constructor.
void setVariable(const std::string &var, const std::string &val)
set value to string variable (new variable is made if not yet existing)
TCanvas * getCanvas(const std::string &name)
Get pointer to existing canvas with given name (NULL is returned if not existing)
ClassDefOverride(MonitoringObject, 1)
classdef
void setVariable(const std::string &var, float val, float upErr=-1., float dwErr=-1)
set value to float variable (new variable is made if not yet existing)
std::map< std::string, float > m_upErr
map of upper errors of variables
const std::map< std::string, float > & getUpError()
Get map of all float variables upper errors.
void addCanvas(TCanvas *canv)
Add Canvas to monitoring object.
std::map< std::string, float > m_dwErr
map of lower errors of variables
std::map< std::string, float > m_vars
map of all float variables
const std::map< std::string, float > & getVariables()
Get map of all float variables.
void print() const
Print content of MonitoringObject.
const std::vector< TCanvas * > & getListOfCanvases()
Get list of all canvases.
std::vector< std::pair< std::string, std::string > > m_strVars
map of all string variables
const std::vector< std::pair< std::string, std::string > > & getStringVariables()
Get vector of all string variables.
const std::map< std::string, float > & getLowError()
Get map of all float variables lower errors.
Abstract base class for different kinds of events.