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 // 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);
17 VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name, const T& def) : VectorBranch<T>(tree, name) {
18 VectorBranch<T>::setDefault(def);
21 template <class T> bool VectorBranch<T>::fill(const EventContext&) {
23 ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet.");
26 if (!m_updated) m_variable.clear();
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();
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();
39 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
40 m_variable.resize(idx + 1, getDefault());
43 return m_variable[idx];
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);
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; }