2#ifndef _NTUPLE_MANAGER_H_
3#define _NTUPLE_MANAGER_H_
9#include <unordered_map>
19#include "Framework/Bus.h"
20#include "Framework/Exception/Exception.h"
21#include "Framework/Logger.h"
44 void create(
const std::string& tname);
56 template <
typename VarType>
57 void addVar(
const std::string& tname,
const std::string& vname) {
60 if (
trees_.count(tname) == 0)
61 EXCEPTION_RAISE(
"NtupleManager",
"A tree with name " + tname +
62 " has not been been created.");
67 EXCEPTION_RAISE(
"NtupleManager",
"A variable with name " + vname +
68 " has already been defined.");
91 void setVar(
const std::string& vname,
const T& value) {
96 ldmx_log(warn) <<
"The variable " << vname
97 <<
" does not exist in the tree. Skipping.";
104 }
catch (
const std::bad_cast&) {
105 EXCEPTION_RAISE(
"TypeMismatch",
"Ntuple variable '" + vname +
106 "' is being set by the wrong type '" +
107 typeid(value).name() +
"'.");
133 std::unordered_map<std::string, TTree*>
trees_;
142 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.