2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #ifndef MUONTESTER_MUONSVECTORBRANCH_IXX
5 #define MUONTESTER_MUONSVECTORBRANCH_IXX
7 #include <MuonTesterTree/throwExcept.h>
9 template <class T> VectorBranch<T>::VectorBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {}
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);
16 VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name, const T& def) : VectorBranch<T>(tree, name) {
17 VectorBranch<T>::setDefault(def);
20 template <class T> bool VectorBranch<T>::fill(const EventContext&) {
22 ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet.");
25 if (!m_updated) m_variable.clear();
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();
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();
38 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
39 m_variable.resize(idx + 1, getDefault());
42 return m_variable[idx];
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);
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; }