2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #ifndef MUONTESTER_MUONTESTERTREE_IXX
5 #define MUONTESTER_MUONTESTERTREE_IXX
7 #include <MuonTesterTree/throwExcept.h>
10 //these are the template implementations included to MuonTesterTree.h
12 template <typename T> VectorBranch<T>& MuonTesterTree::newVector(const std::string& b_name) {
13 if (!addBranch(std::make_shared<VectorBranch<T>>(*this, b_name))) {
14 THROW_EXCEPTION("Failed to create vector branch " + b_name);
16 std::shared_ptr<VectorBranch<T>> b = getBranch<VectorBranch<T>>(b_name);
19 template <typename T> ScalarBranch<T>& MuonTesterTree::newScalar(const std::string& b_name) {
20 if (!addBranch(std::make_shared<ScalarBranch<T>>(*this, b_name))) {
21 THROW_EXCEPTION("Failed to create scalar branch " + b_name);
23 std::shared_ptr<ScalarBranch<T>> b = getBranch<ScalarBranch<T>>(b_name);
26 template <typename T> MatrixBranch<T>& MuonTesterTree::newMatrix(const std::string& b_name) {
27 if (!addBranch(std::make_shared<MatrixBranch<T>>(*this, b_name))) {
28 THROW_EXCEPTION("Failed to create matrix branch " + b_name);
30 std::shared_ptr<MatrixBranch<T>> b = getBranch<MatrixBranch<T>>(b_name);
34 template <typename T> VectorBranch<T>& MuonTesterTree::newVector(const std::string& b_name, const T def_val) {
35 if (!addBranch(std::make_shared<VectorBranch<T>>(*this, b_name, def_val))) {
36 THROW_EXCEPTION("Failed to create vector branch " + b_name);
38 std::shared_ptr<VectorBranch<T>> b = getBranch<VectorBranch<T>>(b_name);
41 template <typename T> ScalarBranch<T>& MuonTesterTree::newScalar(const std::string& b_name, const T def_val) {
42 if (!addBranch(std::make_shared<ScalarBranch<T>>(*this, b_name, def_val))) {
43 THROW_EXCEPTION("Failed to create scalar branch " + b_name);
45 std::shared_ptr<ScalarBranch<T>> b = getBranch<ScalarBranch<T>>(b_name);
48 template <typename T> MatrixBranch<T>& MuonTesterTree::newMatrix(const std::string& b_name, const T def_val) {
49 if (!addBranch(std::make_shared<MatrixBranch<T>>(*this, b_name, def_val))) {
50 THROW_EXCEPTION("Failed to create matrix branch " + b_name);
52 std::shared_ptr<MatrixBranch<T>> b = getBranch<MatrixBranch<T>>(b_name);
55 template <typename T> SetBranch<T>& MuonTesterTree::newSet(const std::string& b_name) {
56 if (!addBranch(std::make_shared<SetBranch<T>>(*this, b_name))) {
57 THROW_EXCEPTION("Failed to create matrix branch " + b_name);
59 std::shared_ptr<SetBranch<T>> b = getBranch<SetBranch<T>>(b_name);
63 template <typename T> T& MuonTesterTree::newBranch(std::shared_ptr<T> br) {
64 if (!addBranch(br)) { THROW_EXCEPTION("Failed to create generic branch " + br->name()); }
65 br = getBranch<T>(br->name());
68 template <class T> std::shared_ptr<T> MuonTesterTree::getBranch(const std::string& br_name) const {
69 for (const auto& br : m_branches) {
70 if (br->name() == br_name) return std::dynamic_pointer_cast<T>(br);
72 for (const FriendTreePtr& friend_tree : getFriends()) {
73 std::shared_ptr<T> br = friend_tree->getBranch<T>(br_name);
79 template <class OWNER,
81 StatusCode MuonTesterTree::init(OWNER* instance) {
82 ATH_CHECK(init(instance->histSvc()));
83 for ( ; m_depCounter < m_dependencies.size(); ++m_depCounter ){
84 auto p = instance->declareProperty( "DataDep_"+name()+"No"+ std::to_string(m_depCounter),
85 *m_dependencies[m_depCounter]);
86 p->template setOwnerType<OWNER>();
88 for (const FriendTreePtr& friend_tree : getFriends()) {
89 ATH_CHECK(friend_tree->init(instance));
91 return StatusCode::SUCCESS;