Skip to content
Snippets Groups Projects
Commit 130f8834 authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2: Committed by Edward Moyse
Browse files

MuonTesterTree --- Use MSG macros and inherit from AthMessasing

Use MSG macros and inherit from AthMessasing

message
parent ba092933
No related branches found
No related tags found
No related merge requests found
Showing
with 124 additions and 145 deletions
/*
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);
......
/*
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();
}
......
/*
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;
......
/*
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
/*
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>
......
/*
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
/*
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
......
/*
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;
}
}
......
/*
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;
}
......
/*
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();
......
/*
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;
}
......
/*
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;
}
......
/*
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
/*
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;
}
......
/*
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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment