2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #ifndef MUONTESTER_ARRAYBRANCH_IXX
5 #define MUONTESTER_ARRAYBRANCH_IXX
7 #include <MuonTesterTree/MuonTesterTree.h>
8 #include <MuonTesterTree/throwExcept.h>
12 ArrayBranch<T>::ArrayBranch(TTree* t, const std::string& b_name, size_t size) :
13 MuonTesterBranch{t,b_name},
16 m_updated.resize(size);
20 ArrayBranch<T>::ArrayBranch(MuonTesterTree& t, const std::string& b_name, size_t size) :
21 MuonTesterBranch{t, b_name},
24 m_updated.resize(size);
29 ArrayBranch<T>::ArrayBranch(TTree* tree, const std::string& name, size_t size, const T& def_val) :
30 ArrayBranch(tree, name, size) {
34 ArrayBranch<T>::ArrayBranch(MuonTesterTree& tree, const std::string& name, size_t size, const T& def_val) :
35 ArrayBranch(tree, name, size) {
38 template <class T> void ArrayBranch<T>::reset() {
39 for (size_t i = 0; i < size(); ++i) m_updated[i] = false;
41 template <class T> const T& ArrayBranch<T>::operator[](size_t s) const { return get(s); }
42 template <class T> void ArrayBranch<T>::set(size_t s, const T& val) {
44 THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name());
49 template <class T> const T& ArrayBranch<T>::get(size_t s) const {
51 THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name());
55 template <class T> T& ArrayBranch<T>::operator[](size_t s) {
57 THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name());
62 template <class T> size_t ArrayBranch<T>::size() const { return m_size; }
63 template <class T> bool ArrayBranch<T>::init() {
65 ATH_MSG_WARNING("init() -- The branch " << name() << " is already initialized. ");
68 const std::string br_name{std::format("{:}[{:d}]{:}", name(), size(), tree_data_type())};
69 if (name().empty() || !tree()) {
70 ATH_MSG_ERROR("init() -- Empty names are forbidden. ");
72 } else if (tree()->FindBranch(name().c_str())) {
73 ATH_MSG_ERROR("init() -- The branch " << name() << " already exists in TTree " << tree()->GetName() << ".");
75 } else if (!tree()->Branch(br_name.c_str(), m_data.data())) {
76 ATH_MSG_ERROR("init() -- Could not create branch " << name() << " in TTree " << tree()->GetName());
82 template <class T> bool ArrayBranch<T>::initialized() const { return m_init; }
83 template <class T> bool ArrayBranch<T>::fill(const EventContext&) {
85 ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet.");
88 for (size_t i = 0; i < size(); ++i) {
90 if (m_failIfNotUpdated) {
91 ATH_MSG_ERROR("init() -- The " << i << "-th value is has not been updated. ");
94 m_data[i] = m_default;
101 template <class T> const T& ArrayBranch<T>::getDefault() const { return m_default; }
102 template <class T> void ArrayBranch<T>::setDefault(const T& val) {
104 m_failIfNotUpdated = false;