MaCh3  2.6.1
Reference Guide
PlottingManager.h
Go to the documentation of this file.
1 #pragma once
2 
3 // C++ includes
4 #include <algorithm>
5 #include <iomanip>
6 #include <iostream>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <vector>
11 
12 // MaCh3 Includes
13 #include "Manager/MaCh3Logger.h"
14 #include "Manager/YamlHelper.h"
15 #include "Manager/MaCh3Exception.h"
16 
17 // Other MaCh3Plotting stuff
18 #include "InputManager.h"
19 #include "StyleManager.h"
20 
21 namespace M3 {
22 namespace Plotting {
37 public:
38  // EM: cant make these static as std::getenv("MACH3") not known at compile time
39  const std::string DEFAULT_TRANSLATION_CONFIG =
40  std::string(std::getenv("MACH3")) +
41  "/plotting/universalTranslator.yaml";
44  const std::string DEFAULT_STYLE_CONFIG =
45  std::string(std::getenv("MACH3")) +
46  "/plotting/StyleConfig.yaml";
49  const std::string DEFAULT_PLOTTING_CONFIG =
50  std::string(std::getenv("MACH3")) +
51  "/plotting/PlottingConfig.yaml";
53 
57 
62  PlottingManager(const std::string &PlottingConfigName);
63 
65  void initialise();
66 
68  MACH3LOG_DEBUG("##### Deleting PlottingManager Instance #####");
69  }
70 
74  void parseInputs(int argc, char* const *argv);
75 
76 
80  inline void parseInputsVec(const std::vector<std::string>& argv) {
81  std::vector<char *> charVec;
82  MACH3LOG_DEBUG("Parsing Inputs :: was given vector:");
83  for( const std::string &arg : argv )
84  {
85  charVec.push_back( const_cast<char *>(arg.c_str()) );
86  MACH3LOG_DEBUG(" - {}", arg );
87  }
88  parseInputs(int(argv.size()), charVec.data());
89  }
90 
94  void addUserOption();
95 
97  std::string getUserOption(const std::string& option);
98 
100  void usage() const;
101 
105  void parseFileLabels(std::string labelString, std::vector<std::string> &labelVec);
106 
110  void setOutFileName(const std::string& fileName);
111 
115  void setExec(const std::string& execName);
116 
121  template <typename T> T getOption(const std::string& option) { return _execOptions[option].as<T>(); }
122  YAML::Node getOption(const std::string& option) const { return _execOptions[option]; }
123 
124  // ############# getters ##############
127  const std::string getFileName(int i) const { return _fileNames[i]; }
128 
129  const std::string getFileLabel(int i) const { return _fileLabels[i]; }
130 
131  const std::string getDrawOptions() const { return _extraDrawOptions; }
132 
136  const std::string getOutputName() { return _outputName; }
137 
142  const std::string getOutputName(const std::string &suffix);
143 
144  const std::vector<std::string> getFileNames() const { return _fileNames; }
145 
146  const std::vector<std::string> getFileLabels() const { return _fileLabels; }
147 
148  size_t getNFiles() const { return _fileNames.size(); }
149 
150  bool getSplitBySample() const { return _splitBySample; }
151 
152  bool getPlotRatios() const { return _plotRatios; }
153 
154  bool getDrawGrid() const { return _drawGrid; }
155 
157 
158  // for managers contained in this manager
161  const StyleManager &style() const { return *_styleMan; }
162 
165  const InputManager &input() const { return *_inputMan; }
166 
167 private:
168  // name of the config file to read configs from
169  std::string _configFileName = std::string(std::getenv("MACH3")) + "/plotting/PlottingConfig.yaml";
170  // the parsed config
171  YAML::Node _plottingConfig;
172  // the config object holding the options for the current executable
173  YAML::Node _execOptions;
174 
175  // input file names and labels
176  std::vector<std::string> _fileNames;
177  std::vector<std::string> _fileLabels;
178  std::vector<std::string> _defaultFileLabels;
179 
180  // other string options
181  std::string _outputName = "Plot.pdf";
182  std::string _extraDrawOptions = "";
183 
184  // Generic plotting options
185  bool _splitBySample = false;
186  bool _plotRatios = false;
187  bool _drawGrid = false;
188 
189  // other Manager objects
190  std::unique_ptr<StyleManager> _styleMan;
191  std::unique_ptr<InputManager> _inputMan;
192 };
193 } // namespace Plotting
194 } // namespace M3
Defines the custom exception class used throughout MaCh3.
MaCh3 Logging utilities built on top of SPDLOG.
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:34
Utility functions for handling YAML nodes.
This guy talks to the input files and is intended to smooth over the fact that our OA fitters use suc...
Definition: InputManager.h:222
The main class to be used in plotting scripts.
void setExec(const std::string &execName)
Internally set the name of the executable that manager is being used in.
void initialise()
initalise this PlottingManager.
std::vector< std::string > _fileNames
const std::string getOutputName()
Get the straight up output file name with no bells or whistles, just the file extension.
std::vector< std::string > _defaultFileLabels
const InputManager & input() const
Get the InputManager contained within this PlottingManager, for doing input related things.
const std::string DEFAULT_PLOTTING_CONFIG
const std::string DEFAULT_TRANSLATION_CONFIG
const std::vector< std::string > getFileNames() const
std::string getUserOption(const std::string &option)
Retrieve a command line option you specified using addOption.
T getOption(const std::string &option)
Get a specific option from the config for this executable.
YAML::Node getOption(const std::string &option) const
const std::string getFileLabel(int i) const
PlottingManager()
Construct a new PlottingManager using default plottingConfig config.
void addUserOption()
Describe an option you want to add to the PlottingManager which can be read in from the command line ...
const std::string getFileName(int i) const
const StyleManager & style() const
Get the StyleManager contained within this PlottingManager, for doing style related things.
const std::string DEFAULT_STYLE_CONFIG
const std::vector< std::string > getFileLabels() const
std::unique_ptr< InputManager > _inputMan
std::vector< std::string > _fileLabels
void parseInputs(int argc, char *const *argv)
Parse command line arguments.
void parseFileLabels(std::string labelString, std::vector< std::string > &labelVec)
Parse string of labels into a vector of strings.
void setOutFileName(const std::string &fileName)
Parse and set the output file name, if extension specified, check its one root supports,...
void usage() const
Print a usage message for the current executable.
std::unique_ptr< StyleManager > _styleMan
void parseInputsVec(const std::vector< std::string > &argv)
Parse vector of command line arguments.
const std::string getDrawOptions() const
EW: provides centralized styling utilities for plots, including name prettification and style applica...
Definition: StyleManager.h:21
Main namespace for MaCh3 software.