1#ifndef __JROOT__JBINSMAP__
2#define __JROOT__JBINSMAP__
24namespace JPP {
using namespace JROOT; }
39 public std::map<std::string, std::map<char, std::vector<double> > >
83 for (
string name; is >> name; ) {
85 if (name.back() ==
SEPARATOR) { name.pop_back(); }
89 for (
char axis; is >> axis; ) {
98 is.seekg(-1, ios::cur);
102 axis = char(tolower(axis));
104 if (is.peek() == (
int)
SEPARATOR) { is.ignore(); }
108 for (
double value; is >> value; ) {
110 vector<double>::const_iterator i = std::lower_bound(bins.cbegin(), bins.cend(), value);
112 if (i == bins.cend() || *i != value) {
113 bins.insert(i, value);
117 binsMap.insert(make_pair(axis, bins));
122 binning.insert(make_pair(name, binsMap));
139 for (
const_iterator i = binning.begin(); i != binning.end(); ++i) {
143 for (
typename mapped_type::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
147 for (vector<double>::const_iterator k = j->second.begin(); k != j->second.end(); ++k) {
188 std::unique_ptr<TH1D>
operator()(
const std::string& name)
const
195 if (i == binsMap.cend()) {
196 THROW(
JNoValue,
"JBinsMapHelper<TH1D>::operator(): No bin configuration found for " << name);
201 typename JBinsMap::mapped_type::const_iterator p = bins.find(
'x');
203 if (p != bins.cend()) {
207 return std::make_unique<TH1D>(name.c_str(),
"",
208 Xbins.size()-1, Xbins.data());
211 THROW(
JNoValue,
"JBinsMapHelper<TH1D>::operator(): Missing x-axis binning for " << name);
242 std::unique_ptr<TH2D>
operator()(
const std::string& name)
const
249 if (i == binsMap.cend()) {
250 THROW(
JNoValue,
"JBinsMapHelper<TH2D>::operator(): No bin configuration found for " << name);
255 typename JBinsMap::mapped_type::const_iterator p = bins.find(
'x');
257 if (p != bins.cend()) {
261 typename JBinsMap::mapped_type::const_iterator q = bins.find(
'y');
263 if (q != bins.cend()) {
267 return std::make_unique<TH2D>(name.c_str(),
"",
268 Xbins.size()-1, Xbins.data(),
269 Ybins.size()-1, Ybins.data());
272 THROW(
JNoValue,
"JBinsMapHelper<TH2D>::operator(): Missing y-axis binning for " << name);
275 THROW(
JNoValue,
"JBinsMapHelper<TH2D>::operator(): Missing x-axis binning for " << name);
306 std::unique_ptr<TH3D>
operator()(
const std::string& name)
const
313 if (i == binsMap.cend()) {
314 THROW(
JNoValue,
"JBinsMapHelper<TH3D>::operator(): No bin configuration found for " << name);
319 typename JBinsMap::mapped_type::const_iterator p = bins.find(
'x');
321 if (p != bins.cend()) {
325 typename JBinsMap::mapped_type::const_iterator q = bins.find(
'y');
327 if (q != bins.cend()) {
331 typename JBinsMap::mapped_type::const_iterator r = bins.find(
'z');
333 if (r != bins.cend()) {
337 return std::make_unique<TH3D>(name.c_str(),
"",
338 Xbins.size()-1, Xbins.data(),
339 Ybins.size()-1, Ybins.data(),
340 Zbins.size()-1, Zbins.data());
343 THROW(
JNoValue,
"JBinsMapHelper<TH3D>::operator(): Missing z-axis binning for " << name);
346 THROW(
JNoValue,
"JBinsMapHelper<TH3D>::operator(): Missing y-axis binning for " << name);
349 THROW(
JNoValue,
"JBinsMapHelper<TH3D>::operator(): Missing x-axis binning for " << name);
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for missing value.
Wrapper class around STL stringstream class to facilitate optional loading of data from file.
Template declaration of auxiliary class for retrieving histograms corresponding to a given histogram ...
Class for I/O of variable-width binning of multiple histograms.
friend std::ostream & operator<<(std::ostream &out, const JBinsMap &binning)
Write binning to output.
map_type::value_type value_type
map_type::const_iterator const_iterator
static const char SEPARATOR
Separator for axis label.
map_type::reverse_iterator reverse_iterator
std::map< std::string, std::map< char, std::vector< double > > > map_type
map_type::iterator iterator
map_type::mapped_type mapped_type
std::unique_ptr< T > getHistogram(const std::string &name) const
Get histogram with binning corresponding to a given histogram name.
friend std::istream & operator>>(std::istream &in, JBinsMap &binning)
Read binning from stream.
map_type::const_reverse_iterator const_reverse_iterator
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
std::unique_ptr< TH1D > operator()(const std::string &name) const
Get 1D histogram with binning corresponding to a given histogram name.
const JBinsMap & binsMap
Bins map.
JBinsMapHelper(const JBinsMap &binsMap)
Constructor.
const JBinsMap & binsMap
Bins map.
std::unique_ptr< TH2D > operator()(const std::string &name) const
Get 2D histogram with binning corresponding to a given histogram name.
JBinsMapHelper(const JBinsMap &binsMap)
Constructor.
JBinsMapHelper(const JBinsMap &binsMap)
Constructor.
std::unique_ptr< TH3D > operator()(const std::string &name) const
Get 3D histogram with binning corresponding to a given histogram name.
const JBinsMap & binsMap
Bins map.