ATLAS Offline Software
Loading...
Searching...
No Matches
VectorBranch.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MUONTESTER_MUONSVECTORBRANCH_IXX
5#define MUONTESTER_MUONSVECTORBRANCH_IXX
6
7#include <MuonTesterTree/throwExcept.h>
8namespace MuonVal {
9template <class T> VectorBranch<T>::VectorBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {}
10
11// cppcheck-suppress missingReturn; false positive
12template <class T> VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name) : MuonTesterBranch(tree, name) {}
13template <class T> VectorBranch<T>::VectorBranch(TTree* tree, const std::string& name, const T& def) : VectorBranch<T>(tree, name) {
14 VectorBranch<T>::setDefault(def);
15}
16template <class T>
17VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name, const T& def) : VectorBranch<T>(tree, name) {
18 VectorBranch<T>::setDefault(def);
19}
20
21template <class T> bool VectorBranch<T>::fill(const EventContext&) {
22 if (!initialized()) {
23 ATH_MSG_ERROR("fill() -- The branch " << name() << " is not initialized yet.");
24 return false;
25 }
26 if (!m_updated) {
27 m_variable.clear();
28 }
29 ATH_MSG_VERBOSE("Fill "<<name()<< " with "<<m_variable<<", "<<m_variable.size()<<" elements. ");
30 m_updated = false;
31 return true;
32}
33template <class T> bool VectorBranch<T>::init() { return addToTree(m_variable); }
34template <class T> size_t VectorBranch<T>::size() const {
35 if (!m_updated) return 0;
36 return m_variable.size();
37}
38template <class T> T& VectorBranch<T>::operator[](size_t idx) { return get(idx); }
39template <class T> T& VectorBranch<T>::get(size_t idx) {
40 if (!m_updated) m_variable.clear();
41 if (idx >= size()) {
42 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
43 m_variable.resize(idx + 1, getDefault());
44 m_updated = true;
45 }
46 return m_variable[idx];
47}
48template <class T>
49const std::vector<T>& VectorBranch<T>::operator=(const std::vector<T>& values) {
50 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
51 m_variable = values;
52 m_updated = true;
53 return m_variable;
54}
55
56template <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);
61 m_updated = true;
62}
63template <class T> void VectorBranch<T>::operator+=(const T& value) { push_back(value); }
64template <class T> bool VectorBranch<T>::isUpdated() const { return m_updated; }
65template <class T> const T& VectorBranch<T>::getDefault() const { return m_default; }
66template <class T> void VectorBranch<T>::setDefault(const T& def) { m_default = def; m_hasDefault=true; }
67template <class T> bool VectorBranch<T>::hasDefault() const { return m_hasDefault; }
68
69}
70#endif