Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
8 namespace MuonVal {
9 template <class T> ScalarBranch<T>::ScalarBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {}
10 template <class T> ScalarBranch<T>::ScalarBranch(MuonTesterTree& tree, const std::string& name) : MuonTesterBranch(tree, name) {}
11 template <class T> ScalarBranch<T>::ScalarBranch(TTree* tree, const std::string& name, const T& default_value) : ScalarBranch(tree, name) {
12  setDefault(default_value);
13 }
14 template <class T>
15 ScalarBranch<T>::ScalarBranch(MuonTesterTree& tree, const std::string& name, const T& default_value) : ScalarBranch(tree, name) {
16  setDefault(default_value);
17 }
18 template <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 }
33 template <class T> bool ScalarBranch<T>::init() { return addToTree(m_variable); }
34 template <class T> const T& ScalarBranch<T>::setValue(const T& value) { return this->operator=(value); }
35 template <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 }
42 template <class T> void ScalarBranch<T>::setDefault(const T& def) {
43  if (!initialized()) {
44  m_default = def;
45  disableFailing();
46  }
47 }
48 template <class T> void ScalarBranch<T>::disableFailing() {
49  if (!initialized()) m_failIfNotUpdated = false;
50 }
51 template <class T> const T& ScalarBranch<T>::getDefault() const { return m_default; }
52 template <class T> const T& ScalarBranch<T>::getVariable() const { return m_variable; }
53 template <class T> bool ScalarBranch<T>::mustBeUpdated() const { return m_failIfNotUpdated; }
54 template <class T> bool ScalarBranch<T>::isUpdated() const { return m_updated; }
55 
56 template <typename T> std::ostream& operator<<(std::ostream& out, const ScalarBranch<T>& B) {
57  out << B.getVariable();
58  return out;
59 }
60 }
61 #endif