ATLAS Offline Software
VectorBranch.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_MUONSVECTORBRANCH_IXX
5 #define MUONTESTER_MUONSVECTORBRANCH_IXX
6 
7 #include <MuonTesterTree/throwExcept.h>
8 namespace MuonVal {
9 template <class T> VectorBranch<T>::VectorBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {}
10 
11 // cppcheck-suppress missingReturn; false positive
12 template <class T> VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name) : MuonTesterBranch(tree, name) {}
13 template <class T> VectorBranch<T>::VectorBranch(TTree* tree, const std::string& name, const T& def) : VectorBranch<T>(tree, name) {
14  VectorBranch<T>::setDefault(def);
15 }
16 template <class T>
17 VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name, const T& def) : VectorBranch<T>(tree, name) {
18  VectorBranch<T>::setDefault(def);
19 }
20 
21 template <class T> bool VectorBranch<T>::fill(const EventContext&) {
22  if (!initialized()) {
23  ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet.");
24  return false;
25  }
26  if (!m_updated) m_variable.clear();
27  m_updated = false;
28  return true;
29 }
30 template <class T> bool VectorBranch<T>::init() { return addToTree(m_variable); }
31 template <class T> size_t VectorBranch<T>::size() const {
32  if (!m_updated) return 0;
33  return m_variable.size();
34 }
35 template <class T> T& VectorBranch<T>::operator[](size_t idx) { return get(idx); }
36 template <class T> T& VectorBranch<T>::get(size_t idx) {
37  if (!m_updated) m_variable.clear();
38  if (idx >= size()) {
39  if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
40  m_variable.resize(idx + 1, getDefault());
41  m_updated = true;
42  }
43  return m_variable[idx];
44 }
45 
46 template <class T> void VectorBranch<T>::push_back(const T& value) {
47  if (!m_updated) m_variable.clear();
48  // Throw an exception in cases where the branch is not initialized
49  if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
50  m_variable.push_back(value);
51  m_updated = true;
52 }
53 template <class T> void VectorBranch<T>::operator+=(const T& value) { push_back(value); }
54 template <class T> bool VectorBranch<T>::isUpdated() const { return m_updated; }
55 template <class T> const T& VectorBranch<T>::getDefault() const { return m_default; }
56 template <class T> void VectorBranch<T>::setDefault(const T& def) { m_default = def; m_hasDefault=true; }
57 template <class T> bool VectorBranch<T>::hasDefault() const { return m_hasDefault; }
58 
59 }
60 #endif