ATLAS Offline Software
Loading...
Searching...
No Matches
SetBranch.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef MUONTESTER_MUONSSetBranch_IXX
5#define MUONTESTER_MUONSSetBranch_IXX
6
7#include "MuonTesterTree/throwExcept.h"
8namespace MuonVal {
9template <class T> SetBranch<T>::SetBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {}
10
11template <class T> SetBranch<T>::SetBranch(MuonTesterTree& tree, const std::string& name) : MuonTesterBranch(tree, name) {}
12
13template <class T> bool SetBranch<T>::fill(const EventContext&) {
14 if (!initialized()) {
15 ATH_MSG_ERROR("fill() -- The set branch " << name() << " is not initialized yet.");
16 return false;
17 }
18 if (!m_updated) m_variable.clear();
19 m_updated = false;
20 return true;
21}
22template <class T> bool SetBranch<T>::init() { return addToTree(m_variable); }
23template <class T> size_t SetBranch<T>::size() const {
24 if (!m_updated) return 0;
25 return m_variable.size();
26}
27template <class T> std::set<T>& SetBranch<T>::operator->(){ return get();}
28template <class T> std::set<T>& SetBranch<T>::get() {
29 if(!m_updated) m_variable.clear();
30 m_updated = true;
31 return m_variable;
32}
33template <class T> void SetBranch<T>::operator=(const std::set<T>& other) {
34 get() = other;
35}
36template <class T> const std::set<T>& SetBranch<T>::operator->() const{ return get();}
37template <class T> const std::set<T>& SetBranch<T>::get() const {
38 if (!m_updated) {
39 static const std::set<T> dummy{};
40 return dummy;
41 }
42 return m_variable;
43}
44template <class T> void SetBranch<T>::insert(const T& value) {
45 if (!m_updated) m_variable.clear();
46 // Throw an exception in cases where the branch is not initialized
47 if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); }
48 m_variable.insert(value);
49 m_updated = true;
50}
51template <class T> void SetBranch<T>::operator+=(const T& value) { insert(value); }
52template <class T> bool SetBranch<T>::isUpdated() const { return m_updated; }
53}
54#endif