ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTesterTree.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_MUONTESTERTREE_IXX
5#define MUONTESTER_MUONTESTERTREE_IXX
6#include <TTree.h>
7#include <MuonTesterTree/throwExcept.h>
8
9
10//these are the template implementations included to MuonTesterTree.h
11namespace MuonVal {
12template <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);
15 }
16 std::shared_ptr<VectorBranch<T>> b = getBranch<VectorBranch<T>>(b_name);
17 return *b;
18}
19template <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);
22 }
23 std::shared_ptr<ScalarBranch<T>> b = getBranch<ScalarBranch<T>>(b_name);
24 return *b;
25}
26template <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);
29 }
30 std::shared_ptr<MatrixBranch<T>> b = getBranch<MatrixBranch<T>>(b_name);
31 return *b;
32}
33
34template <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);
37 }
38 std::shared_ptr<VectorBranch<T>> b = getBranch<VectorBranch<T>>(b_name);
39 return *b;
40}
41template <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);
44 }
45 std::shared_ptr<ScalarBranch<T>> b = getBranch<ScalarBranch<T>>(b_name);
46 return *b;
47}
48template <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);
51 }
52 std::shared_ptr<MatrixBranch<T>> b = getBranch<MatrixBranch<T>>(b_name);
53 return *b;
54}
55template <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);
58 }
59 std::shared_ptr<SetBranch<T>> b = getBranch<SetBranch<T>>(b_name);
60 return *b;
61}
62
63template <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());
66 return *br;
67}
68template <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);
71 }
72 for (const FriendTreePtr& friend_tree : getFriends()) {
73 std::shared_ptr<T> br = friend_tree->getBranch<T>(br_name);
74 if (br) return br;
75 }
76 return nullptr;
77}
78
79template <class OWNER,
80 typename >
81StatusCode 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>();
87 }
88 for (const FriendTreePtr& friend_tree : getFriends()) {
89 ATH_CHECK(friend_tree->init(instance));
90 }
91 return StatusCode::SUCCESS;
92}
93}
94#endif