4 #include <boost/regex.hpp>
15 fArgc(argc), fArgv(argv),
16 fOptions(
"Available program options", 120),
25 (
"help,h",
"Print this help message")
26 (
"input-file,f", po::value<std::string>(&
fInFilePath),
"Full path to a ROOT file containing a TTree " \
27 "OR a text file with a list of such ROOT files")
28 (
"prefix,o", po::value<std::string>(&
fOutPrefix)->default_value(
"./"),
"Absolute or relative path to prefix output files")
29 (
"max-events,n", po::value<unsigned int>(&
fMaxEventsUser)->default_value(0),
"Maximum number of events to process")
30 (
"sparsity,s", po::value<float>(&
fSparsity)->default_value(1),
"Approximate fraction of events to read and process")
31 (
"save-graph,g", po::value<bool>(&
fSaveGraphics)->default_value(
false)->implicit_value(
true),
"Use this option to save histograms and such as images")
46 }
catch(
const std::exception& ex) {
59 std::cout <<
"Program options set to following values:\n";
61 for (
const std::pair< std::string, po::variable_value >& option :
fOptionsValues)
63 std::cout <<
"\t" << option.first <<
":\t" << option.second.value() <<
"\n";
83 std::string inputFileName = boost::any_cast<std::string>(
fOptionsValues[
"input-file"].value());
85 std::ifstream tmpFileCheck(inputFileName.c_str());
86 if (!tmpFileCheck.good()) {
87 TVX_FATAL(
"File \"%s\" does not exist", inputFileName.c_str());
98 TVX_WARNING(
"VerifyOptions",
"Sparsity specified value outside allowed limits. Set to 1");
116 boost::regex extension_regex(
"^(.*)\\.root$");
118 if ( boost::regex_match(
fInFilePath, extension_regex) ) {
119 return boost::regex_replace(
fInFilePath, extension_regex,
"\\1." + suffix +
".root");
129 if(!out_to_stream<int>(os, any_value))
130 if(!out_to_stream<unsigned int>(os, any_value))
131 if(!out_to_stream<float>(os, any_value))
132 if(!out_to_stream<bool>(os, any_value))
133 if(!out_to_stream<std::string>(os, any_value))
void Print() const
Prints the options and their values.
float fSparsity
An approximate fraction of events to read and process.
std::string fInFilePath
Full path to either a root file with event tree or a text file with a list of such root files...
unsigned int fMaxEventsUser
The maximum number of input events to process.
po::variables_map fOptionsValues
void ProcessOptions()
Takes the standard command line arguments and parses them with the boost program_options utility...
bool fSaveGraphics
This flag controls whether to produce images for created histograms.
ProgramOptions(int argc, char **argv)
po::options_description fOptions
std::string fOutPrefix
A prefix to specify the location of the output files.
std::string GetOutFileName(std::string suffix="hist") const
Form the name of the output file from the input file name by appending a suffix to it...
std::ostream & operator<<(std::ostream &os, const boost::any &any_value)
void VerifyOptions()
Verifies user submitted values.