2 Copyright (C) 2002-2025 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("fill() -- The branch " << name() << " is not initialized yet.");
29 ATH_MSG_VERBOSE("Fill "<<name()<< " with "<<m_variable<<", "<<m_variable.size()<<" elements. ");
33 template <class T> bool VectorBranch<T>::init() { return addToTree(m_variable); }
34 template <class T> size_t VectorBranch<T>::size() const {
35 if (!m_updated) return 0;
36 return m_variable.size();
38 template <class T> T& VectorBranch<T>::operator[](size_t idx) { return get(idx); }
39 template <class T> T& VectorBranch<T>::get(size_t idx) {
40 if (!m_updated) m_variable.clear();
42 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
43 m_variable.resize(idx + 1, getDefault());
46 return m_variable[idx];
49 const std::vector<T>& VectorBranch<T>::operator=(const std::vector<T>& values) {
50 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
56 template <class T> void VectorBranch<T>::push_back(const T& value) {
57 if (!m_updated) m_variable.clear();
58 // Throw an exception in cases where the branch is not initialized
59 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
60 m_variable.push_back(value);
63 template <class T> void VectorBranch<T>::operator+=(const T& value) { push_back(value); }
64 template <class T> bool VectorBranch<T>::isUpdated() const { return m_updated; }
65 template <class T> const T& VectorBranch<T>::getDefault() const { return m_default; }
66 template <class T> void VectorBranch<T>::setDefault(const T& def) { m_default = def; m_hasDefault=true; }
67 template <class T> bool VectorBranch<T>::hasDefault() const { return m_hasDefault; }