MaCh3  2.2.3
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 MaCh3Plotting {
34 public:
35  // EM: cant make these static as std::getenv("MACH3") not known at compile time
36  const std::string DEFAULT_TRANSLATION_CONFIG =
37  std::string(std::getenv("MACH3")) +
38  "/plotting/universalTranslator.yaml";
41  const std::string DEFAULT_STYLE_CONFIG =
42  std::string(std::getenv("MACH3")) +
43  "/plotting/StyleConfig.yaml";
46  const std::string DEFAULT_PLOTTING_CONFIG =
47  std::string(std::getenv("MACH3")) +
48  "/plotting/PlottingConfig.yaml";
50 
54 
59  PlottingManager(const std::string &PlottingConfigName);
60 
62  void initialise();
63 
65  MACH3LOG_DEBUG("##### Deleting PlottingManager Instance #####");
66  }
67 
71  void parseInputs(int argc, char* const *argv);
72 
73 
77  inline void parseInputsVec(std::vector<std::string> argv) {
78  std::vector<char *> charVec;
79  MACH3LOG_DEBUG("Parsing Inputs :: was given vector:");
80  for( const std::string &arg : argv )
81  {
82  charVec.push_back( const_cast<char *>(arg.c_str()) );
83  MACH3LOG_DEBUG(" - {}", arg );
84  }
85  parseInputs(int(argv.size()), charVec.data());
86  }
87 
91  void addUserOption();
92 
94  std::string getUserOption(std::string option);
95 
97  void usage();
98 
102  void parseFileLabels(std::string labelString, std::vector<std::string> &labelVec);
103 
107  void setOutFileName(const std::string& fileName);
108 
112  void setExec(const std::string& execName);
113 
118  template <typename T> T getOption(const std::string& option) { return _execOptions[option].as<T>(); }
119  YAML::Node getOption(std::string option) { return _execOptions[option]; }
120 
121  // ############# getters ##############
124  const std::string getFileName(int i) const { return _fileNames[i]; }
125 
126  const std::string getFileLabel(int i) const { return _fileLabels[i]; }
127 
128  const std::string getDrawOptions() const { return _extraDrawOptions; }
129 
133  const std::string getOutputName() const { return _outputName; }
134 
139  const std::string getOutputName(const std::string &suffix);
140 
141  const std::vector<std::string> getFileNames() const { return _fileNames; }
142 
143  const std::vector<std::string> getFileLabels() const { return _fileLabels; }
144 
145  size_t getNFiles() const { return _fileNames.size(); }
146 
147  bool getSplitBySample() const { return _splitBySample; }
148 
149  bool getPlotRatios() const { return _plotRatios; }
150 
151  bool getDrawGrid() const { return _drawGrid; }
152 
154 
155  // for managers contained in this manager
158  const StyleManager &style() const { return *_styleMan; }
159 
162  const InputManager &input() const { return *_inputMan; }
163 
164 private:
165  // name of the config file to read configs from
166  std::string _configFileName = std::string(std::getenv("MACH3")) + "/plotting/PlottingConfig.yaml";
167  // the parsed config
168  YAML::Node _plottingConfig;
169  // the config object holding the options for the current executable
170  YAML::Node _execOptions;
171 
172  // input file names and labels
173  std::vector<std::string> _fileNames;
174  std::vector<std::string> _fileLabels;
175  std::vector<std::string> _defaultFileLabels;
176 
177  // other string options
178  std::string _outputName = "Plot.pdf";
179  std::string _extraDrawOptions = "";
180 
181  // Generic plotting options
182  bool _splitBySample = false;
183  bool _plotRatios = false;
184  bool _drawGrid = false;
185 
186  // other Manager objects
187  std::unique_ptr<StyleManager> _styleMan;
188  std::unique_ptr<InputManager> _inputMan;
189 };
190 } // namespace MaCh3Plotting
KS: Based on this https://github.com/gabime/spdlog/blob/a2b4262090fd3f005c2315dcb5be2f0f1774a005/incl...
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:24
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:218
The main class to be used in plotting scripts.
void setOutFileName(const std::string &fileName)
Parse and set the output file name, if extension specified, check its one root supports,...
YAML::Node getOption(std::string option)
const std::string DEFAULT_PLOTTING_CONFIG
const std::string getFileName(int i) const
void initialise()
initalise this PlottingManager.
const std::string DEFAULT_STYLE_CONFIG
void setExec(const std::string &execName)
Internally set the name of the executable that manager is being used in.
void parseInputsVec(std::vector< std::string > argv)
Parse vector of command line arguments.
std::vector< std::string > _defaultFileLabels
const std::string getFileLabel(int i) const
std::vector< std::string > _fileLabels
const InputManager & input() const
Get the InputManager contained within this PlottingManager, for doing input related things.
const std::string DEFAULT_TRANSLATION_CONFIG
std::vector< std::string > _fileNames
const std::string getOutputName() const
Get the straight up output file name with no bells or whistles, just the file extension.
std::unique_ptr< InputManager > _inputMan
void parseInputs(int argc, char *const *argv)
Parse command line arguments.
T getOption(const std::string &option)
Get a specific option from the config for this executable.
void usage()
Print a usage message for the current executable.
const StyleManager & style() const
Get the StyleManager contained within this PlottingManager, for doing style related things.
const std::vector< std::string > getFileNames() const
PlottingManager()
Construct a new PlottingManager using default plottingConfig config.
const std::string getDrawOptions() const
const std::vector< std::string > getFileLabels() const
void parseFileLabels(std::string labelString, std::vector< std::string > &labelVec)
Parse string of labels into a vector of strings.
std::unique_ptr< StyleManager > _styleMan
void addUserOption()
Describe an option you want to add to the PlottingManager which can be read in from the command line ...
std::string getUserOption(std::string option)
Retrieve a command line option you specified using addOption.
EW: provides centralized styling utilities for plots, including name prettification and style applica...
Definition: styleManager.h:20