Skip to content

Commit 63f56d2

Browse files
Implemented customization of help messages of the DPL driver app
An optional argument can be specified to the `--help,-h` option, to create different versions of the help printout: - `full`: the full printout with executor, workflow and processor options - `short`: executor and workflow options, as well as a summary of the processors - `workflow`: workflow options only - `executor`: executor options only - by specifying a valid name for a process which defines option, its options are printed Default behaviour is `short`. The definition of processors might depend on the specified workflow options. The help message is adjusted to workflow options if specified in addition to the `--help` option.
1 parent f59c7e2 commit 63f56d2

File tree

2 files changed

+64
-19
lines changed

2 files changed

+64
-19
lines changed

Framework/Core/include/Framework/ConfigParamsHelper.h

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,59 @@ struct ConfigParamsHelper
4242
);
4343

4444
/// populate boost program options for a complete workflow
45-
template<typename ContainerType>
45+
template <typename ContainerType>
4646
static boost::program_options::options_description
47-
prepareOptionDescriptions(const ContainerType &workflow,
48-
const std::vector<ConfigParamSpec> &workflowOptions,
49-
options_description vetos = options_description()
50-
)
47+
prepareOptionDescriptions(const ContainerType& workflow,
48+
const std::vector<ConfigParamSpec>& workflowOptions,
49+
options_description vetos = options_description(),
50+
std::string mode = "full")
5151
{
5252
boost::program_options::options_description toplevel;
5353
boost::program_options::options_description wo("Global workflow options");
5454
if (prepareOptionsDescription(workflowOptions, wo, vetos)) {
5555
toplevel.add(wo);
5656
}
57-
boost::program_options::options_description specOptions("Available data processors");
57+
std::string specOptionsDescription = "Available data processors";
58+
if (mode == "short") {
59+
specOptionsDescription += " (full info with '--help full')";
60+
}
61+
options_description specOptions(specOptionsDescription);
5862
for (const auto & spec : workflow) {
59-
std::string help = "Usage: --" + spec.name + R"( "<data processor options>")";
60-
specOptions.add_options()(spec.name.c_str(),
61-
boost::program_options::value<std::string>(),
62-
help.c_str());
6363
std::string name = "Data processor options: " + spec.name;
64-
boost::program_options::options_description options(name);
65-
if (prepareOptionsDescription(spec.options, options, vetos)) {
66-
specOptions.add(options);
64+
boost::program_options::options_description processorOptions(name);
65+
if (prepareOptionsDescription(spec.options, processorOptions, vetos)) {
6766
// if vetos have been provided to the function we also need to make
6867
// sure that there are no duplicate option definitions for the individual
6968
// processor specs, so we add in order to be vetos for all subsequent specs.
7069
// Note: this only concerns the main parser, all individual options are
7170
// handled when starting individual processors.
7271
if (vetos.options().size() > 0) {
73-
vetos.add(options);
72+
vetos.add(processorOptions);
73+
}
74+
if (mode == "full") {
75+
specOptions.add(processorOptions);
76+
} else if (mode == spec.name) {
77+
toplevel.add(processorOptions);
78+
break;
7479
}
7580
}
81+
if (mode == "full" || mode == "short") {
82+
std::string help;
83+
if (mode == "full") {
84+
help = "Option groups by process name: --" + spec.name + R"( "<processor options>")";
85+
} else if (mode == "short" && processorOptions.options().size() > 0) {
86+
help = "Use '--help " + spec.name + "' to display processor options";
87+
} else if (mode == "short" && processorOptions.options().size() == 0) {
88+
help = "No processor options";
89+
}
90+
specOptions.add_options()(spec.name.c_str(),
91+
boost::program_options::value<std::string>(),
92+
help.c_str());
93+
}
94+
}
95+
if (workflow.size() > 0 && (mode == "full" || mode == "short")) {
96+
toplevel.add(specOptions);
7697
}
77-
toplevel.add(specOptions);
7898
return toplevel;
7999
}
80100

Framework/Core/src/runDataProcessing.cxx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,9 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& workflow,
10121012
{
10131013
enum TerminationPolicy policy;
10141014
bpo::options_description executorOptions("Executor options");
1015+
const char* helpDescription = "print help: short, full, executor, or processor name";
10151016
executorOptions.add_options() //
1016-
("help,h", "print this help") //
1017+
("help,h", bpo::value<std::string>()->implicit_value("short"), helpDescription) //
10171018
("quiet,q", bpo::value<bool>()->zero_tokens()->default_value(false), "quiet operation") //
10181019
("stop,s", bpo::value<bool>()->zero_tokens()->default_value(false), "stop before device start") //
10191020
("single-step", bpo::value<bool>()->zero_tokens()->default_value(false), "start in single step mode") //
@@ -1061,11 +1062,35 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& workflow,
10611062
}
10621063

10631064
if (varmap.count("help")) {
1065+
auto mode = varmap["help"].as<std::string>();
10641066
bpo::options_description helpOptions;
1065-
helpOptions.add(executorOptions);
1067+
if (mode == "full" || mode == "short" || mode == "executor") {
1068+
helpOptions.add(executorOptions);
1069+
}
10661070
// this time no veto is applied, so all the options are added for printout
1067-
helpOptions.add(ConfigParamsHelper::prepareOptionDescriptions(physicalWorkflow, workflowOptions));
1068-
std::cout << helpOptions << std::endl;
1071+
if (mode == "executor") {
1072+
// nothing more
1073+
} else if (mode == "workflow") {
1074+
// executor options and workflow options, skip the actual workflow
1075+
o2::framework::WorkflowSpec emptyWorkflow;
1076+
helpOptions.add(ConfigParamsHelper::prepareOptionDescriptions(emptyWorkflow, workflowOptions));
1077+
} else if (mode == "full" || mode == "short") {
1078+
helpOptions.add(ConfigParamsHelper::prepareOptionDescriptions(physicalWorkflow, workflowOptions,
1079+
bpo::options_description(),
1080+
mode));
1081+
} else {
1082+
helpOptions.add(ConfigParamsHelper::prepareOptionDescriptions(physicalWorkflow, {},
1083+
bpo::options_description(),
1084+
mode));
1085+
}
1086+
if (helpOptions.options().size() == 0) {
1087+
// the specified argument is invalid, add at leat the executor options
1088+
mode += " is an invalid argument, please use correct argument for";
1089+
helpOptions.add(executorOptions);
1090+
}
1091+
std::cout << "ALICE O2 DPL workflow driver" //
1092+
<< " (" << mode << " help)" << std::endl //
1093+
<< helpOptions << std::endl; //
10691094
exit(0);
10701095
}
10711096

0 commit comments

Comments
 (0)