diff --git a/MuonSpectrometer/MuonValidation/MuonPRDTest/MuonPRDTest/PrdTesterModule.h b/MuonSpectrometer/MuonValidation/MuonPRDTest/MuonPRDTest/PrdTesterModule.h index 1ac822f98aab65a7054f512d4a1ac72a8210336c..07f65551eaf1d638c8efe682891810fb83ca77d7 100644 --- a/MuonSpectrometer/MuonValidation/MuonPRDTest/MuonPRDTest/PrdTesterModule.h +++ b/MuonSpectrometer/MuonValidation/MuonPRDTest/MuonPRDTest/PrdTesterModule.h @@ -1,11 +1,10 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef PRDTESTER_PrdTesterModule_H #define PRDTESTER_PrdTesterModule_H -#include "AthenaBaseComps/AthMessaging.h" #include "MuonIdHelpers/IMuonIdHelperSvc.h" #include "MuonReadoutGeometry/MuonDetectorManager.h" #include "MuonTesterTree/MuonTesterTreeDict.h" @@ -13,7 +12,7 @@ namespace MuonPRDTest { using namespace MuonVal; - class PrdTesterModule : public MuonTesterBranch, public AthMessaging { + class PrdTesterModule : public MuonTesterBranch { public: PrdTesterModule(MuonTesterTree& tree, const std::string& grp_name, bool useCondGeo, MSG::Level msglvl); diff --git a/MuonSpectrometer/MuonValidation/MuonPRDTest/Root/PrdTesterModule.cxx b/MuonSpectrometer/MuonValidation/MuonPRDTest/Root/PrdTesterModule.cxx index 114006f15d298b52166239c036831abf00f82c09..df6a212ba79893ba04044ed19194bc1b6c2dd56b 100644 --- a/MuonSpectrometer/MuonValidation/MuonPRDTest/Root/PrdTesterModule.cxx +++ b/MuonSpectrometer/MuonValidation/MuonPRDTest/Root/PrdTesterModule.cxx @@ -1,12 +1,13 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include <MuonPRDTest/PrdTesterModule.h> #include <StoreGate/ReadCondHandle.h> namespace MuonPRDTest { PrdTesterModule::PrdTesterModule(MuonTesterTree& tree, const std::string& grp_name, bool useCondGeo, MSG::Level msglvl) : - MuonTesterBranch(tree, " prd module " + grp_name), AthMessaging(grp_name), m_useCondDetMgr{useCondGeo} { + MuonTesterBranch(tree, " prd module " + grp_name), + m_useCondDetMgr{useCondGeo} { setLevel(msglvl); m_idHelperSvc.retrieve().ignore(); } diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.h b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.h index 5fa797ff1ae36a25a90fdf7745b38e4eb614a330..2c64bcde4fcf02cea68a5825920feb7f4fe7893f 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.h +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.h @@ -1,16 +1,17 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_ARRAYBRANCH_H #define MUONTESTER_ARRAYBRANCH_H #include <MuonTesterTree/IMuonTesterBranch.h> +#include <MuonTesterTree/MuonTesterBranch.h> #include <TTree.h> /// Class to store array like branches into the n-tuples namespace MuonVal { class MuonTesterTree; -template <class T> class ArrayBranch : public IMuonTesterBranch { +template <class T> class ArrayBranch : public MuonTesterBranch, virtual public IMuonTesterBranch { public: /// Constructor ArrayBranch(TTree* tree, const std::string& name, size_t size); @@ -20,23 +21,12 @@ public: ArrayBranch(TTree* tree, const std::string& name, size_t size, const T& def_val); ArrayBranch(MuonTesterTree& tree, const std::string& name, size_t size, const T& def_val); - ArrayBranch(const ArrayBranch&) = delete; - void operator=(const ArrayBranch&) = delete; - virtual ~ArrayBranch(); + virtual ~ArrayBranch() = default; /// Returns false if one of the array values is not updated bool fill(const EventContext&) override final; /// Connects the branch with the tree bool init() override final; - /// Returns the name of the branch - std::string name() const override final; - /// Returns the data dependencies of the branch (empty) - std::vector<DataDependency> data_dependencies() override final; - - /// Underlying tree object - const TTree* tree() const override final; - TTree* tree() override final; - /// Is the branch initialized bool initialized() const; @@ -64,21 +54,15 @@ private: std::string tree_data_type() const; /// Resets the check mask void reset(); - - TTree* m_tree{nullptr}; - std::string m_name{}; - size_t m_size{0}; - std::unique_ptr<T[]> m_data{nullptr}; - std::unique_ptr<bool[]> m_updated{nullptr}; + std::unique_ptr<T[]> m_data{new T[m_size]}; + std::unique_ptr<bool[]> m_updated{new bool[m_size]}; bool m_init{false}; /// Default value in cases where the part are not updated T m_default{}; bool m_failIfNotUpdated{true}; - - MuonTesterTree* m_parent{nullptr}; }; /// Specification of the branch data_type for the TTree initialize routine template <> std::string ArrayBranch<char*>::tree_data_type() const; diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.icc index a20bed56619ec508f80ab8e0c029255852a2f2fc..9f86bbfd68a263eabb820e90a188bfe7f5d29fb9 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ArrayBranch.icc @@ -1,63 +1,55 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_ARRAYBRANCH_IXX #define MUONTESTER_ARRAYBRANCH_IXX -#include <AthenaKernel/getMessageSvc.h> -#include <GaudiKernel/MsgStream.h> #include <MuonTesterTree/MuonTesterTree.h> - +#include <MuonTesterTree/throwExcept.h> namespace MuonVal { template <class T> ArrayBranch<T>::ArrayBranch(TTree* t, const std::string& b_name, size_t size) : - m_tree(t), m_name(b_name), m_size(size), m_data(new T[size]), m_updated(new bool[size]) { + MuonTesterBranch{t,b_name}, + m_size{size} { reset(); } template <class T> -ArrayBranch<T>::ArrayBranch(MuonTesterTree& t, const std::string& b_name, size_t size) : ArrayBranch(t.tree(), b_name, size) { - m_parent = &t; - m_parent->addBranch(this); +ArrayBranch<T>::ArrayBranch(MuonTesterTree& t, const std::string& b_name, size_t size) : + MuonTesterBranch{t, b_name}, + m_size{size} { + reset(); } template <class T> -ArrayBranch<T>::ArrayBranch(TTree* tree, const std::string& name, size_t size, const T& def_val) : ArrayBranch(tree, name, size) { +ArrayBranch<T>::ArrayBranch(TTree* tree, const std::string& name, size_t size, const T& def_val) : + ArrayBranch(tree, name, size) { setDefault(def_val); } template <class T> -ArrayBranch<T>::ArrayBranch(MuonTesterTree& tree, const std::string& name, size_t size, const T& def_val) : ArrayBranch(tree, name, size) { +ArrayBranch<T>::ArrayBranch(MuonTesterTree& tree, const std::string& name, size_t size, const T& def_val) : + ArrayBranch(tree, name, size) { setDefault(def_val); } -template <class T> ArrayBranch<T>::~ArrayBranch() { - if (m_parent) m_parent->removeBranch(this); -} template <class T> void ArrayBranch<T>::reset() { for (size_t i = 0; i < size(); ++i) m_updated[i] = false; } -template <class T> std::string ArrayBranch<T>::name() const { return m_name; } template <class T> const T& ArrayBranch<T>::operator[](size_t s) const { return get(s); } template <class T> void ArrayBranch<T>::set(size_t s, const T& val) { if (s >= size()) { - std::stringstream overflow{}; - overflow<<"Index "<<s<<" is out of range for "<<name()<<"."; - throw std::overflow_error(overflow.str()); + THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name()); } m_updated[s] = true; m_data[s] = val; } template <class T> const T& ArrayBranch<T>::get(size_t s) const { if (s >= size()) { - std::stringstream overflow{}; - overflow<<"Index "<<s<<" is out of range for "<<name()<<"."; - throw std::overflow_error(overflow.str()); + THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name()); } return m_data[s]; } template <class T> T& ArrayBranch<T>::operator[](size_t s) { if (s >= size()) { - std::stringstream overflow{}; - overflow<<"Index "<<s<<" is out of range for "<<name()<<"."; - throw std::overflow_error(overflow.str()); + THROW_EXCEPTION("Index "<<s<<" is out of range for "<<name()); } m_updated[s] = true; return m_data[s]; @@ -65,42 +57,34 @@ template <class T> T& ArrayBranch<T>::operator[](size_t s) { template <class T> size_t ArrayBranch<T>::size() const { return m_size; } template <class T> bool ArrayBranch<T>::init() { if (initialized()) { - MsgStream log(Athena::getMessageSvc(), "ArrayBranch()"); - log << MSG::WARNING << "init() -- The branch " << name() << " is already initialized. " << endmsg; + ATH_MSG_WARNING("init() -- The branch " << name() << " is already initialized. "); return true; } std::stringstream br_name{}; br_name<<name()<<"["<<size()<<"]/"<<tree_data_type(); - if (name().empty() || !m_tree) { - MsgStream log(Athena::getMessageSvc(), "ArrayBranch()"); - log << MSG::ERROR << "init() -- Empty names are forbidden. " << endmsg; + if (name().empty() || !tree()) { + ATH_MSG_ERROR("init() -- Empty names are forbidden. "); return false; - } else if (m_tree->FindBranch(name().c_str())) { - MsgStream log(Athena::getMessageSvc(), "ArrayBranch()"); - log << MSG::ERROR << "init() -- The branch " << name() << " already exists in TTree " << m_tree->GetName() << "." << endmsg; + } else if (tree()->FindBranch(name().c_str())) { + ATH_MSG_ERROR("init() -- The branch " << name() << " already exists in TTree " << tree()->GetName() << "."); return false; - } else if (!m_tree->Branch(name().c_str(), m_data.get(), br_name.str().c_str())) { - MsgStream log(Athena::getMessageSvc(), "ArrayBranch()"); - log << MSG::ERROR << "init() -- Could not create branch " << name() << " in TTree " << m_tree->GetName() << endmsg; + } else if (!tree()->Branch(name().c_str(), m_data.get(), br_name.str().c_str())) { + ATH_MSG_ERROR("init() -- Could not create branch " << name() << " in TTree " << tree()->GetName()); return false; } m_init = true; return true; } -template <class T> const TTree* ArrayBranch<T>::tree() const {return m_tree;} -template <class T> TTree* ArrayBranch<T>::tree(){ return m_tree;} template <class T> bool ArrayBranch<T>::initialized() const { return m_init; } template <class T> bool ArrayBranch<T>::fill(const EventContext&) { if (!initialized()) { - MsgStream log(Athena::getMessageSvc(), "ArrayBranch()"); - log << MSG::ERROR << "init() -- The branch " << name() << " is not initialized yet." << endmsg; + ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet."); return false; } for (size_t i = 0; i < size(); ++i) { if (!m_updated[i]) { if (m_failIfNotUpdated) { - MsgStream log(Athena::getMessageSvc(), "ArrayBranch()"); - log << MSG::ERROR << "init() -- The " << i << "-th value is has not been updated. " << endmsg; + ATH_MSG_ERROR("init() -- The " << i << "-th value is has not been updated. "); return false; } else { m_data[i] = m_default; @@ -115,6 +99,5 @@ template <class T> void ArrayBranch<T>::setDefault(const T& val) { m_default = val; m_failIfNotUpdated = false; } -template <class T> std::vector<IMuonTesterBranch::DataDependency> ArrayBranch<T>::data_dependencies() { return {};} } #endif diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.h b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.h index bf910d80624e8f8244501fedcc1e97c03ead0ef8..9c8a497cbca33d3036bd27a4405e266479c55897 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.h +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MATRIXBRANCH_H #define MUONTESTER_MATRIXBRANCH_H @@ -9,7 +9,7 @@ class TTree; namespace MuonVal { class MuonTesterTree; -template <class T> class MatrixBranch : public IMuonTesterBranch { +template <class T> class MatrixBranch : public MuonTesterBranch, virtual public IMuonTesterBranch { public: /// Standard constructor MatrixBranch(TTree* tree, const std::string& name); @@ -19,18 +19,11 @@ public: MatrixBranch(TTree* tree, const std::string& b_name, const T& def); MatrixBranch(MuonTesterTree& tree, const std::string& b_name, const T& def); - MatrixBranch(const MatrixBranch&) = delete; - void operator=(const MatrixBranch&) = delete; + virtual ~MatrixBranch() = default; bool fill(const EventContext& ctx) override final; bool init() override final; - std::string name() const override final; - - std::vector<DataDependency> data_dependencies() override final; - - const TTree* tree() const override final; - TTree* tree() override final; bool initialized() const; @@ -56,6 +49,7 @@ public: private: VectorBranch<std::vector<T>> m_Vec; T m_default; + MuonTesterTree* m_parent{nullptr}; }; } #include <MuonTesterTree/MatrixBranch.icc> diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.icc index 4c8011de075cf541c57035d315989fb07157a777..bfa7acb3ccb03815a24ba35eca6672523fcd6a73 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MatrixBranch.icc @@ -1,16 +1,27 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONSMATRIXBRANCH_IXX #define MUONTESTER_MUONSMATRIXBRANCH_IXX + namespace MuonVal { -template <class T> MatrixBranch<T>::MatrixBranch(TTree* tree, const std::string& name) : m_Vec(tree, name) {} -template <class T> MatrixBranch<T>::MatrixBranch(TTree* tree, const std::string& b_name, const T& def) : MatrixBranch<T>(tree, b_name) { + + +template <class T> MatrixBranch<T>::MatrixBranch(TTree* tree, const std::string& name) : + MuonTesterBranch{tree, name}, + m_Vec(tree, name) {} +template <class T> MatrixBranch<T>::MatrixBranch(TTree* tree, const std::string& b_name, const T& def) : + MatrixBranch<T>(tree, b_name) { setDefault(def); } -template <class T> MatrixBranch<T>::MatrixBranch(MuonTesterTree& tree, const std::string& name) : m_Vec(tree, name) {} +template <class T> MatrixBranch<T>::MatrixBranch(MuonTesterTree& parent, const std::string& name) : + MuonTesterBranch{parent, name}, + m_Vec(tree(), name), + m_parent{&parent} { +} template <class T> -MatrixBranch<T>::MatrixBranch(MuonTesterTree& tree, const std::string& b_name, const T& def) : MatrixBranch<T>(tree, b_name) { +MatrixBranch<T>::MatrixBranch(MuonTesterTree& tree, const std::string& b_name, const T& def) : + MatrixBranch<T>(tree, b_name) { setDefault(def); } template <class T> void MatrixBranch<T>::push_back(size_t i, const T& value) { m_Vec[i].push_back(value); } @@ -22,9 +33,10 @@ template <class T> T& MatrixBranch<T>::get(size_t i, size_t j) { } template <class T> std::vector<T>& MatrixBranch<T>::operator[](size_t i) { return m_Vec[i]; } template <class T> std::vector<T>& MatrixBranch<T>::get(size_t i) { return m_Vec.get(i); } -template <class T> bool MatrixBranch<T>::fill(const EventContext& ctx) { return m_Vec.fill(ctx); } +template <class T> bool MatrixBranch<T>::fill(const EventContext& ctx) { + return m_Vec.fill(ctx); +} template <class T> bool MatrixBranch<T>::init() { return m_Vec.init(); } -template <class T> std::string MatrixBranch<T>::name() const { return m_Vec.name(); } template <class T> size_t MatrixBranch<T>::nrows() const { return m_Vec.size(); } template <class T> size_t MatrixBranch<T>::ncols(size_t row) const { if (row >= nrows()) { return 0; } @@ -32,9 +44,7 @@ template <class T> size_t MatrixBranch<T>::ncols(size_t row) const { } template <class T> const T& MatrixBranch<T>::getDefault() const { return m_default; } template <class T> void MatrixBranch<T>::setDefault(const T& def) { m_default = def; } -template <class T> const TTree* MatrixBranch<T>::tree() const { return m_Vec.tree(); } -template <class T> TTree* MatrixBranch<T>::tree() { return m_Vec.tree(); } template <class T> bool MatrixBranch<T>::initialized() const { return m_Vec.initialized(); } -template <class T> std::vector<IMuonTesterBranch::DataDependency> MatrixBranch<T>::data_dependencies() { return {};} + } #endif \ No newline at end of file diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.h b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.h index 03d01b6f25747159a5467ee45ec478f5f055dd48..051a3a0d50ececba24faf9e24a8a962315b92093 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.h +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.h @@ -1,10 +1,11 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONTESTERBRANCH_H #define MUONTESTER_MUONTESTERBRANCH_H #include <MuonTesterTree/IMuonTesterBranch.h> +#include <AthenaBaseComps/AthMessaging.h> // #include <string> #include <vector> @@ -17,7 +18,7 @@ class TTree; /// to the TTree in the initialization stage namespace MuonVal { class MuonTesterTree; -class MuonTesterBranch : virtual public IMuonTesterBranch { +class MuonTesterBranch : public AthMessaging, virtual public IMuonTesterBranch { public: MuonTesterBranch(MuonTesterTree& tree, const std::string& br_name); /// Standard constructor taking the TTree object and the name of the branch to be added to the TTree diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.icc index fd2cf32d574c3a9a9a453addd8d2a4b0ea14ddeb..d2d8e392006451d635007f23c26ff4a84d24da00 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterBranch.icc @@ -1,32 +1,26 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONTESTERBRANCH_IXX #define MUONTESTER_MUONTESTERBRANCH_IXX -#include <AthenaKernel/getMessageSvc.h> -#include <GaudiKernel/MsgStream.h> #include <TTree.h> #include <algorithm> //for std::find namespace MuonVal { template <class T> bool MuonTesterBranch::addToTree(T& variable) { if (initialized()) { - MsgStream log(Athena::getMessageSvc(), "MuonTesterBranch()"); - log << MSG::INFO << "init() -- " << name() << " is already initialized." << endmsg; + ATH_MSG_INFO("init() -- " << name() << " is already initialized."); return true; } std::string bName = eraseWhiteSpaces(name()); if (bName.empty() || !m_tree) { - MsgStream log(Athena::getMessageSvc(), "MuonTesterBranch()"); - log << MSG::ERROR << "init() -- Empty names are forbidden." << endmsg; + ATH_MSG_ERROR("init() -- Empty names are forbidden."); return false; } else if (m_tree->FindBranch(bName.c_str())) { - MsgStream log(Athena::getMessageSvc(), "MuonTesterBranch()"); - log << MSG::ERROR << "The branch " << name() << " already exists in TTree " << m_tree->GetName() << "." << endmsg; + ATH_MSG_ERROR("The branch " << name() << " already exists in TTree " << m_tree->GetName() << "."); return false; } else if (!m_tree->Branch(bName.c_str(), &variable)) { - MsgStream log(Athena::getMessageSvc(), "MuonTesterBranch()"); - log << MSG::ERROR << "Could not create the branch " << name() << " in TTree " << m_tree->GetName() << "." << endmsg; + ATH_MSG_ERROR("Could not create the branch " << name() << " in TTree " << m_tree->GetName() << "."); return false; } m_init = true; @@ -37,6 +31,7 @@ bool MuonTesterBranch::declare_dependency(Key& key) { if (std::find(m_dependencies.begin(), m_dependencies.end(),&key) != m_dependencies.end()) return true; if (!key.initialize(!key.empty())) return false; m_dependencies.emplace_back(&key); + ATH_MSG_DEBUG("Declared new dependency "<<key.fullKey()<<" to "<<name()); return true; } } diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterTree.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterTree.icc index 6398abe3165ae143f243fd2aed8ef273d168df0c..d2a20f75d335cecd39b26aa84100db4d27df7f59 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterTree.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/MuonTesterTree.icc @@ -1,30 +1,31 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONTESTERTREE_IXX #define MUONTESTER_MUONTESTERTREE_IXX #include <TTree.h> +#include <MuonTesterTree/throwExcept.h> //these are the template implementations included to MuonTesterTree.h namespace MuonVal { template <typename T> VectorBranch<T>& MuonTesterTree::newVector(const std::string& b_name) { if (!addBranch(std::make_shared<VectorBranch<T>>(*this, b_name))) { - throw std::runtime_error("Failed to create vector branch " + b_name); + THROW_EXCEPTION("Failed to create vector branch " + b_name); } std::shared_ptr<VectorBranch<T>> b = getBranch<VectorBranch<T>>(b_name); return *b; } template <typename T> ScalarBranch<T>& MuonTesterTree::newScalar(const std::string& b_name) { if (!addBranch(std::make_shared<ScalarBranch<T>>(*this, b_name))) { - throw std::runtime_error("Failed to create scalar branch " + b_name); + THROW_EXCEPTION("Failed to create scalar branch " + b_name); } std::shared_ptr<ScalarBranch<T>> b = getBranch<ScalarBranch<T>>(b_name); return *b; } template <typename T> MatrixBranch<T>& MuonTesterTree::newMatrix(const std::string& b_name) { if (!addBranch(std::make_shared<MatrixBranch<T>>(*this, b_name))) { - throw std::runtime_error("Failed to create matrix branch " + b_name); + THROW_EXCEPTION("Failed to create matrix branch " + b_name); } std::shared_ptr<MatrixBranch<T>> b = getBranch<MatrixBranch<T>>(b_name); return *b; @@ -32,35 +33,35 @@ template <typename T> MatrixBranch<T>& MuonTesterTree::newMatrix(const std::stri template <typename T> VectorBranch<T>& MuonTesterTree::newVector(const std::string& b_name, const T def_val) { if (!addBranch(std::make_shared<VectorBranch<T>>(*this, b_name, def_val))) { - throw std::runtime_error("Failed to create vector branch " + b_name); + THROW_EXCEPTION("Failed to create vector branch " + b_name); } std::shared_ptr<VectorBranch<T>> b = getBranch<VectorBranch<T>>(b_name); return *b; } template <typename T> ScalarBranch<T>& MuonTesterTree::newScalar(const std::string& b_name, const T def_val) { if (!addBranch(std::make_shared<ScalarBranch<T>>(*this, b_name, def_val))) { - throw std::runtime_error("Failed to create scalar branch " + b_name); + THROW_EXCEPTION("Failed to create scalar branch " + b_name); } std::shared_ptr<ScalarBranch<T>> b = getBranch<ScalarBranch<T>>(b_name); return *b; } template <typename T> MatrixBranch<T>& MuonTesterTree::newMatrix(const std::string& b_name, const T def_val) { if (!addBranch(std::make_shared<MatrixBranch<T>>(*this, b_name, def_val))) { - throw std::runtime_error("Failed to create matrix branch " + b_name); + THROW_EXCEPTION("Failed to create matrix branch " + b_name); } std::shared_ptr<MatrixBranch<T>> b = getBranch<MatrixBranch<T>>(b_name); return *b; } template <typename T> SetBranch<T>& MuonTesterTree::newSet(const std::string& b_name) { if (!addBranch(std::make_shared<SetBranch<T>>(*this, b_name))) { - throw std::runtime_error("Failed to create matrix branch " + b_name); + THROW_EXCEPTION("Failed to create matrix branch " + b_name); } std::shared_ptr<SetBranch<T>> b = getBranch<SetBranch<T>>(b_name); return *b; } template <typename T> T& MuonTesterTree::newBranch(std::shared_ptr<T> br) { - if (!addBranch(br)) { throw std::runtime_error("Failed to create generic branch " + br->name()); } + if (!addBranch(br)) { THROW_EXCEPTION("Failed to create generic branch " + br->name()); } br = getBranch<T>(br->name()); return *br; } diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ScalarBranch.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ScalarBranch.icc index dc599dc82efcd0b89aaadc8c6293482f1f6eb452..82c85dd1e00de11d16fb2cf6fbdbaa8c851edbd4 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ScalarBranch.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/ScalarBranch.icc @@ -1,10 +1,10 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONSCALARBRANCH_IXX #define MUONTESTER_MUONSCALARBRANCH_IXX -#include <AthenaKernel/getMessageSvc.h> -#include <GaudiKernel/MsgStream.h> + + namespace MuonVal { template <class T> ScalarBranch<T>::ScalarBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {} template <class T> ScalarBranch<T>::ScalarBranch(MuonTesterTree& tree, const std::string& name) : MuonTesterBranch(tree, name) {} @@ -17,14 +17,12 @@ ScalarBranch<T>::ScalarBranch(MuonTesterTree& tree, const std::string& name, con } template <class T> bool ScalarBranch<T>::fill(const EventContext&) { if (!initialized()) { - MsgStream log(Athena::getMessageSvc(), "ScalarBranch()"); - log << MSG::ERROR << "init() -- The branch " << name() << " is not initialized yet." << endmsg; + ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet."); return false; } if (!m_updated) { if (mustBeUpdated()) { - MsgStream log(Athena::getMessageSvc(), "ScalarBranch()"); - log << MSG::ERROR << "The variable " << name() << " must always be filled between a fill call " << endmsg; + ATH_MSG_ERROR("The scalar variable " << name() << " must always be filled between a fill call "); return false; } else m_variable = getDefault(); diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/SetBranch.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/SetBranch.icc index 41f64f86cc87e150bcf385e039eba49cea20b52a..1519eaf1a4fe3030a0e7936f4b4e77091c7ec0f3 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/SetBranch.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/SetBranch.icc @@ -1,11 +1,10 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONSSetBranch_IXX #define MUONTESTER_MUONSSetBranch_IXX -#include <AthenaKernel/getMessageSvc.h> -#include <GaudiKernel/MsgStream.h> +#include "MuonTesterTree/throwExcept.h" namespace MuonVal { template <class T> SetBranch<T>::SetBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {} @@ -13,8 +12,7 @@ template <class T> SetBranch<T>::SetBranch(MuonTesterTree& tree, const std::stri template <class T> bool SetBranch<T>::fill(const EventContext&) { if (!initialized()) { - MsgStream log(Athena::getMessageSvc(), "SetBranch()"); - log << MSG::ERROR << "init() -- The branch " << name() << " is not initialized yet." << endmsg; + ATH_MSG_ERROR("fill() -- The set branch " << name() << " is not initialized yet."); return false; } if (!m_updated) m_variable.clear(); @@ -46,7 +44,7 @@ template <class T> const std::set<T>& SetBranch<T>::get() const { template <class T> void SetBranch<T>::insert(const T& value) { if (!m_updated) m_variable.clear(); // Throw an exception in cases where the branch is not initialized - if (!initialized()) { throw std::runtime_error(name() + " is not initialized yet"); } + if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); } m_variable.insert(value); m_updated = true; } diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/VectorBranch.icc b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/VectorBranch.icc index cf2d115c3b7290451927d270ff66414620866235..fd9f1403eb5e03404769dae06ee6da51944315a8 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/VectorBranch.icc +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/VectorBranch.icc @@ -1,11 +1,10 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef MUONTESTER_MUONSVECTORBRANCH_IXX #define MUONTESTER_MUONSVECTORBRANCH_IXX -#include <AthenaKernel/getMessageSvc.h> -#include <GaudiKernel/MsgStream.h> +#include <MuonTesterTree/throwExcept.h> namespace MuonVal { template <class T> VectorBranch<T>::VectorBranch(TTree* tree, const std::string& name) : MuonTesterBranch(tree, name) {} @@ -20,8 +19,7 @@ VectorBranch<T>::VectorBranch(MuonTesterTree& tree, const std::string& name, con template <class T> bool VectorBranch<T>::fill(const EventContext&) { if (!initialized()) { - MsgStream log(Athena::getMessageSvc(), "VectorBranch()"); - log << MSG::ERROR << "init() -- The branch " << name() << " is not initialized yet." << endmsg; + ATH_MSG_ERROR("init() -- The branch " << name() << " is not initialized yet."); return false; } if (!m_updated) m_variable.clear(); @@ -37,7 +35,7 @@ template <class T> T& VectorBranch<T>::operator[](size_t idx) { return get(idx); template <class T> T& VectorBranch<T>::get(size_t idx) { if (!m_updated) m_variable.clear(); if (idx >= size()) { - if (!initialized()) { throw std::runtime_error(name() + " is not initialized yet"); } + if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); } m_variable.resize(idx + 1, getDefault()); m_updated = true; } @@ -47,7 +45,7 @@ template <class T> T& VectorBranch<T>::get(size_t idx) { template <class T> void VectorBranch<T>::push_back(const T& value) { if (!m_updated) m_variable.clear(); // Throw an exception in cases where the branch is not initialized - if (!initialized()) { throw std::runtime_error(name() + " is not initialized yet"); } + if (!initialized()) { THROW_EXCEPTION(name() + " is not initialized yet"); } m_variable.push_back(value); m_updated = true; } diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/throwExcept.h b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/throwExcept.h new file mode 100644 index 0000000000000000000000000000000000000000..afcf21f8c9a25e2f8d1f08be08d63fa467237736 --- /dev/null +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/MuonTesterTree/throwExcept.h @@ -0,0 +1,17 @@ +/* + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration +*/ +#ifndef MuonTesterTree_THROWEXCEPT_H +#define MuonTesterTree_THROWEXCEPT_H + +#include <exception> +#include <sstream> + +#define THROW_EXCEPTION(MESSAGE) \ + { \ + std::stringstream except_str{}; \ + except_str<<__FILE__<<":"<<__LINE__<<" --- "; \ + except_str<<MESSAGE; \ + throw std::runtime_error(except_str.str()); \ + } +#endif \ No newline at end of file diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/EventInfoBranch.cxx b/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/EventInfoBranch.cxx index 71e47aec7ae3a2e42b32d8592bfc2583f6bf58b8..62740f7136ca75f72ece28e356b4f9bec376278f 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/EventInfoBranch.cxx +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/EventInfoBranch.cxx @@ -1,10 +1,9 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ -#include <AthenaKernel/getMessageSvc.h> -#include <GaudiKernel/MsgStream.h> #include <MuonTesterTree/EventInfoBranch.h> #include <StoreGate/ReadHandle.h> +#include <MuonTesterTree/throwExcept.h> #include <stdexcept> namespace { static const SG::AuxElement::ConstAccessor<unsigned int> acc_Random("RandomRunNumber"); @@ -23,15 +22,15 @@ EventInfoBranch::EventInfoBranch(MuonTesterTree& tree, unsigned int write_mask): for (unsigned int lhe = 1; lhe < s_num_lhe ; ++lhe ) { std::shared_ptr<ScalarBranch<double>>& new_br = m_lhe_weights[lhe]; new_br = std::make_shared<ScalarBranch<double>>(tree.tree(), "mcEventWeight_LHE_" + std::to_string(lhe),0.); - if (not tree.addBranch(new_br)) { - throw std::runtime_error("EventInfoBranch: Failed to create Scalar branch in c'tor"); - }; + if (!tree.addBranch(new_br)) { + THROW_EXCEPTION("EventInfoBranch: Failed to create Scalar branch in c'tor"); + } } } } else { tree.disableBranch(m_mcChannel.name()); tree.disableBranch(m_weight.name()); - m_writemask&= ~(WriteOpts::writePRW | WriteOpts::writeBeamSpot); + m_writemask&= ~(WriteOpts::writePRW | WriteOpts::writeBeamSpot); } if (m_writemask & WriteOpts::writePRW) { @@ -56,8 +55,7 @@ EventInfoBranch::EventInfoBranch(MuonTesterTree& tree, unsigned int write_mask): bool EventInfoBranch::fill(const EventContext& ctx) { SG::ReadHandle<xAOD::EventInfo> evt_info{m_key, ctx}; if (!evt_info.isValid()) { - MsgStream log(Athena::getMessageSvc(), "EventInfoBranch"); - log << MSG::ERROR << "Could not retrieve the EventInfo " << m_key.fullKey() << endmsg; + ATH_MSG_ERROR("Could not retrieve the EventInfo " << m_key.fullKey()); return false; } diff --git a/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/MuonTesterBranch.cxx b/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/MuonTesterBranch.cxx index a9dac747210720d68896e7c6cc70ded1857ebf08..4e9bf4fb9a408ac87a4965b1a828912134c676f4 100644 --- a/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/MuonTesterBranch.cxx +++ b/MuonSpectrometer/MuonValidation/MuonTesterTree/Root/MuonTesterBranch.cxx @@ -1,5 +1,5 @@ /* -Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration +Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include <AthenaKernel/getMessageSvc.h> #include <GaudiKernel/MsgStream.h> @@ -8,6 +8,7 @@ Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration #include <MuonTesterTree/MuonTesterTree.h> #include <MuonTesterTree/ScalarBranch.h> #include <MuonTesterTree/VectorBranch.h> +#include <MuonTesterTree/throwExcept.h> #include <functional> @@ -29,21 +30,22 @@ SET_BRANCHSTRING(Float_t, "/F") SET_BRANCHSTRING(Double_t, "/D") SET_BRANCHSTRING(Bool_t, "/o") -MuonTesterBranch::MuonTesterBranch(MuonTesterTree& tree, const std::string& br_name) : MuonTesterBranch(tree.tree(), br_name) { +MuonTesterBranch::MuonTesterBranch(MuonTesterTree& tree, const std::string& br_name) : + MuonTesterBranch(tree.tree(), br_name) { m_parent = &tree; m_parent->addBranch(this); } MuonTesterTree& MuonTesterBranch::parent() { if (!m_parent) { - MsgStream log(Athena::getMessageSvc(), "MuonTesterBranch()"); - log << MSG::WARNING << "The parent of " << name() << " is null." << endmsg; + ATH_MSG_WARNING("The parent of " << name() << " is null."); } return *m_parent; } MuonTesterBranch::~MuonTesterBranch() { if (m_parent) m_parent->removeBranch(this); } -MuonTesterBranch::MuonTesterBranch(TTree* tree, const std::string& br_name) : m_tree(tree), m_name(br_name) {} +MuonTesterBranch::MuonTesterBranch(TTree* tree, const std::string& br_name) : + AthMessaging{"MuonTesterBranch"}, m_tree(tree), m_name(br_name) {} std::string MuonTesterBranch::name() const { return m_name; } bool MuonTesterBranch::initialized() const { return m_init; } TTree* MuonTesterBranch::tree() { return m_tree; } @@ -57,7 +59,7 @@ std::string MuonTesterBranch::eraseWhiteSpaces(const std::string& In) { std::vector<MuonTesterBranch::DataDependency> MuonTesterBranch::data_dependencies() { return m_dependencies;} template <> bool& VectorBranch<bool>::get(size_t) { - throw std::runtime_error("For boolean branches the get() operator is cumbersome"); + THROW_EXCEPTION("For boolean branches the get() operator is cumbersome"); return m_default; } }