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>
11 ArrayBranch<T>::ArrayBranch(TTree* t, const std::string& b_name, size_t size) :
12 MuonTesterBranch{t,b_name},
15 m_updated.resize(size);
19 ArrayBranch<T>::ArrayBranch(MuonTesterTree& t, const std::string& b_name, size_t size) :
20 MuonTesterBranch{t, b_name},
23 m_updated.resize(size);
28 ArrayBranch<T>::ArrayBranch(TTree* tree, const std::string& name, size_t size, const T& def_val) :
29 ArrayBranch(tree, name, size) {
33 ArrayBranch<T>::ArrayBranch(MuonTesterTree& tree, const std::string& name, size_t size, const T& def_val) :
34 ArrayBranch(tree, name, size) {
37 template <class T> void ArrayBranch<T>::reset() {
38 for (size_t i = 0; i < size(); ++i) m_updated[i] = false;
40 template <class T> const T& ArrayBranch<T>::operator[](size_t s) const { return get(s); }
41 template <class T> void ArrayBranch<T>::set(size_t s, const T& val) {
43 THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name());
48 template <class T> const T& ArrayBranch<T>::get(size_t s) const {
50 THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name());
54 template <class T> T& ArrayBranch<T>::operator[](size_t s) {
56 THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name());
61 template <class T> size_t ArrayBranch<T>::size() const { return m_size; }
62 template <class T> bool ArrayBranch<T>::init() {
64 ATH_MSG_WARNING("init() -- The branch " << name() << " is already initialized. ");
67 std::stringstream br_name{};
68 br_name<<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(name().c_str(), m_data.data(), br_name.str().c_str())) {
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;