ATLAS Offline Software
MuonTesterBranch.icc
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
5 #ifndef MUONTESTER_MUONTESTERBRANCH_IXX
6 #define MUONTESTER_MUONTESTERBRANCH_IXX
7 #include <TTree.h>
8 #include <algorithm> //for std::find
9 namespace MuonVal {
10 template <class T> bool MuonTesterBranch::addToTree(T& variable) {
11  if (initialized()) {
12  ATH_MSG_INFO("init() -- " << name() << " is already initialized.");
13  return true;
14  }
15  std::string bName = eraseWhiteSpaces(name());
16  if (bName.empty() || !m_tree) {
17  ATH_MSG_ERROR("init() -- Empty names are forbidden.");
18  return false;
19  } else if (m_tree->FindBranch(bName.c_str())) {
20  ATH_MSG_ERROR("The branch " << name() << " already exists in TTree " << m_tree->GetName() << ".");
21  return false;
22  } else if (!m_tree->Branch(bName.c_str(), &variable)) {
23  ATH_MSG_ERROR("Could not create the branch " << name() << " in TTree " << m_tree->GetName() << ".");
24  return false;
25  }
26  m_init = true;
27  return true;
28 }
29 template <class Key>
30 bool MuonTesterBranch::declare_dependency(Key& key) {
31  if (std::find(m_dependencies.begin(), m_dependencies.end(),&key) != m_dependencies.end()) return true;
32  if (!key.initialize(!key.empty())) return false;
33  m_dependencies.emplace_back(&key);
34  ATH_MSG_DEBUG("Declared new dependency "<<key.fullKey()<<" to "<<name());
35  return true;
36 }
37 }
38 #endif