ATLAS Offline Software
ScalarBranch.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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> void ScalarBranch<T>::setValue(const T& value) { this->operator=(value); }
35 template <class T> void ScalarBranch<T>::operator=(const T& value) {
36  if (!initialized()) return;
37  m_variable = value;
38  m_updated = true;
39 }
40 template <class T> void ScalarBranch<T>::setDefault(const T& def) {
41  if (!initialized()) {
42  m_default = def;
43  disableFailing();
44  }
45 }
46 template <class T> void ScalarBranch<T>::disableFailing() {
47  if (!initialized()) m_failIfNotUpdated = false;
48 }
49 template <class T> const T& ScalarBranch<T>::getDefault() const { return m_default; }
50 template <class T> const T& ScalarBranch<T>::getVariable() const { return m_variable; }
51 template <class T> bool ScalarBranch<T>::mustBeUpdated() const { return m_failIfNotUpdated; }
52 template <class T> bool ScalarBranch<T>::isUpdated() const { return m_updated; }
53 
54 template <typename T> std::ostream& operator<<(std::ostream& out, const ScalarBranch<T>& B) {
55  out << B.getVariable();
56  return out;
57 }
58 }
59 #endif