2#ifndef _NTUPLE_MANAGER_H_
3#define _NTUPLE_MANAGER_H_
10#include <unordered_map>
20#include "Framework/Bus.h"
21#include "Framework/Exception/Exception.h"
22#include "Framework/Logger.h"
45 void create(
const std::string& tname);
57 template <
typename VarType>
58 void addVar(
const std::string& tname,
const std::string& vname) {
61 if (
trees_.count(tname) == 0)
62 EXCEPTION_RAISE(
"NtupleManager",
"A tree with name " + tname +
63 " has not been been created.");
68 EXCEPTION_RAISE(
"NtupleManager",
"A variable with name " + vname +
69 " has already been defined.");
92 void setVar(
const std::string& vname,
const T& value) {
97 ldmx_log(warn) <<
"The variable " << vname
98 <<
" does not exist in the tree. Skipping.";
105 }
catch (
const std::bad_cast&) {
106 EXCEPTION_RAISE(
"TypeMismatch",
"Ntuple variable '" + vname +
107 "' is being set by the wrong type '" +
108 typeid(value).name() +
"'.");
134 std::unordered_map<std::string, TTree*>
trees_;
143 enableLogging(
"NtupleManager")
void update(const std::string &name, const BaggageType &obj)
Update the object a passenger is carrying.
bool isOnBoard(const std::string &name)
Check if a passenger is on the bus.
TBranch * attach(TTree *tree, const std::string &name, bool can_create)
Attach the input tree to the object a passenger is carrying.
void board(const std::string &name)
Board a new passenger onto the bus.
Singleton class used to manage the creation and pooling of ntuples.
void addVar(const std::string &tname, const std::string &vname)
Add a variable of type VarType to the ROOT tree with name 'tname'.
NtupleManager()
Private constructor to prevent instantiation.
void create(const std::string &tname)
Create a ROOT tree to hold the ntuple variables (ROOT leaves).
framework::Bus bus_
Container for buffering variables.
void clear()
Reset all of the variables to their limits.
static NtupleManager & getInstance()
void reset()
Reset NtupleManager to blank state.
void operator=(const NtupleManager &)=delete
Hide Assignment Operator.
std::unordered_map< std::string, TTree * > trees_
Container for output ROOT trees.
void setVar(const std::string &vname, const T &value)
Set the value of the variable named 'vname'.
NtupleManager(const NtupleManager &)=delete
Hide Copy Constructor.
All classes in the ldmx-sw project use this namespace.