ATLAS Offline Software
Loading...
Searching...
No Matches
ScalarBranch.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MUONTESTER_MUONSCALARBRANCH_IXX
5#define MUONTESTER_MUONSCALARBRANCH_IXX
6
7
8namespace MuonVal {
9template <class T> ScalarBranch<T>::ScalarBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {}
10template <class T> ScalarBranch<T>::ScalarBranch(MuonTesterTree& tree, const std::string& name) : MuonTesterBranch(tree, name) {}
11template <class T> ScalarBranch<T>::ScalarBranch(TTree* tree, const std::string& name, const T& default_value) : ScalarBranch(tree, name) {
12 setDefault(default_value);
13}
14template <class T>
15ScalarBranch<T>::ScalarBranch(MuonTesterTree& tree, const std::string& name, const T& default_value) : ScalarBranch(tree, name) {
16 setDefault(default_value);
17}
18template <class T> bool ScalarBranch<T>::fill(const EventContext&) {
19 if (!initialized()) {
20 ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet.");
21 return false;
22 }
23 if (!m_updated) {
24 if (mustBeUpdated()) {
25 ATH_MSG_ERROR("The scalar variable " << name() << " must always be filled between a fill call ");
26 return false;
27 } else
28 m_variable = getDefault();
29 }
30 m_updated = false;
31 return true;
32}
33template <class T> bool ScalarBranch<T>::init() { return addToTree(m_variable); }
34template <class T> const T& ScalarBranch<T>::setValue(const T& value) { return this->operator=(value); }
35template <class T> const T& ScalarBranch<T>::operator=(const T& value) {
36 if (initialized()) {
37 m_variable = value;
38 m_updated = true;
39 }
40 return m_variable;
41}
42template <class T> void ScalarBranch<T>::setDefault(const T& def) {
43 if (!initialized()) {
44 m_default = def;
45 disableFailing();
46 }
47}
48template <class T> void ScalarBranch<T>::disableFailing() {
49 if (!initialized()) m_failIfNotUpdated = false;
50}
51template <class T> const T& ScalarBranch<T>::getDefault() const { return m_default; }
52template <class T> const T& ScalarBranch<T>::getVariable() const { return m_variable; }
53template <class T> bool ScalarBranch<T>::mustBeUpdated() const { return m_failIfNotUpdated; }
54template <class T> bool ScalarBranch<T>::isUpdated() const { return m_updated; }
55
56template <typename T> std::ostream& operator<<(std::ostream& out, const ScalarBranch<T>& B) {
57 out << B.getVariable();
58 return out;
59}
60}
61#endif