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 <TObject.h>
12#include <TNamed.h>
13#include <TCanvas.h>
14
15#include <vector>
16#include <string>
17#include <map>
18#include <framework/logging/Logger.h>
19
20namespace Belle2 {
31 class MonitoringObject : public TNamed {
32
33 public:
39 explicit MonitoringObject(const std::string& name)
40 {
41 fName = name;
42 }
43
48 void addCanvas(TCanvas* canv)
49 {
50 for (auto cc : m_Canvases) {
51 if (cc->GetName() == canv->GetName()) {
52 B2ERROR("Canvas with name " << canv->GetName() << " already in the " << fName <<
53 " MonitoringObject! Use different name (or call getCanvas(name) to access pointer to the existing TCanvas).");
54 return;
55 }
56 }
57 m_Canvases.push_back(canv);
58 };
59
63 const std::map<std::string, float>& getVariables()
64 {
65 return m_vars;
66 }
67
71 const std::map<std::string, float>& getUpError()
72 {
73 return m_upErr;
74 }
75
79 const std::map<std::string, float>& getLowError()
80 {
81 return m_dwErr;
82 }
83
87 const std::vector<std::pair<std::string, std::string>>& getStringVariables()
88 {
89 return m_strVars;
90 }
91
95 TCanvas* getCanvas(const std::string& name)
96 {
97 for (auto cc : m_Canvases) {
98 if (cc->GetName() == name) return cc;
99 }
100 B2WARNING("TCanvas with name " << name << " not found in MonitoringObject " << fName);
101 return NULL;
102 };
103
107 const std::vector<TCanvas*>& getListOfCanvases()
108 {
109 return m_Canvases;
110 }
111
115 void print() const;
116
124 void setVariable(const std::string& var, float val, float upErr = -1., float dwErr = -1)
125 {
126
127 auto vv = m_vars.find(var);
128 if (vv != m_vars.end()) vv->second = val;
129 else m_vars.insert({var, val});
130
131 if (upErr > 0) {
132 auto vvE = m_upErr.find(var);
133 if (vvE != m_upErr.end()) vvE->second = upErr;
134 else m_upErr.insert({var, upErr});
135 }
136
137 if (dwErr > 0) {
138 auto vvE = m_dwErr.find(var);
139 if (vvE != m_dwErr.end()) vvE->second = dwErr;
140 else m_dwErr.insert({var, dwErr});
141 }
142
143 }
144
150 void setVariable(const std::string& var, const std::string& val)
151 {
152
153 for (auto& pair : m_strVars) {
154 if (pair.first == var) {
155 pair.second = val;
156 return;
157 }
158 }
159 m_strVars.push_back(std::pair<std::string, std::string>(var, val));
160 }
161
162
163 private:
164
165 std::vector<TCanvas*> m_Canvases;
167 std::map<std::string, float> m_vars;
168 std::map<std::string, float> m_upErr;
169 std::map<std::string, float> m_dwErr;
171 std::vector<std::pair<std::string, std::string>> m_strVars;
175 }; //class
176
178} // 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.