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