Skip to content

Commit

Permalink
update on program options
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW committed Jan 12, 2024
1 parent 702879b commit f4ecd74
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 117 deletions.
24 changes: 12 additions & 12 deletions neuland/executables/neulandAna.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ auto main(int argc, const char** argv) -> int
timer.Start();

auto programOptions = R3B::ProgramOptions("options for neuland data analysis");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto paddleName =
programOptions.Create_Option<std::string>("paddle", R"(set the paddle name. e.g. "neuland")", "neuland");
programOptions.create_option<std::string>("paddle", R"(set the paddle name. e.g. "neuland")", "neuland");
auto channelName =
programOptions.Create_Option<std::string>("channel", R"(set the channel name. e.g. "tamex")", "tacquila");
programOptions.create_option<std::string>("channel", R"(set the channel name. e.g. "tamex")", "tacquila");
auto simuFileName =
programOptions.Create_Option<std::string>("simuFile", "set the filename of simulation input", "simu.root");
programOptions.create_option<std::string>("simuFile", "set the filename of simulation input", "simu.root");
auto paraFileName =
programOptions.Create_Option<std::string>("paraFile", "set the filename of parameter sink", "para.root");
programOptions.create_option<std::string>("paraFile", "set the filename of parameter sink", "para.root");
auto paraFileName2 =
programOptions.Create_Option<std::string>("paraFile2", "set the filename of the second parameter sink", "");
programOptions.create_option<std::string>("paraFile2", "set the filename of the second parameter sink", "");
auto digiFileName =
programOptions.Create_Option<std::string>("digiFile", "set the filename of digitization output", "digi.root");
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "error");
auto eventNum = programOptions.Create_Option<int>("eventNum,n", "set total event number", 0);
programOptions.create_option<std::string>("digiFile", "set the filename of digitization output", "digi.root");
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "error");
auto eventNum = programOptions.create_option<int>("eventNum,n", "set total event number", 0);
auto hitLevelPar =
programOptions.Create_Option<std::string>("hitLevelPar", "set the name of hit level parameter if needed.", "");
programOptions.create_option<std::string>("hitLevelPar", "set the name of hit level parameter if needed.", "");

if (!programOptions.Verify(argc, argv))
if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
std::cout << programOptions.get_desc_ref() << std::endl;
return 0;
}

Expand Down
22 changes: 11 additions & 11 deletions neuland/executables/neulandSim.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ int main(int argc, const char** argv)

auto programOptions = R3B::ProgramOptions("options for neuland simulation");

auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto eventNum = programOptions.Create_Option<int>("eventNum", "set total event number", defaultEventNum);
auto eventPrintNum = programOptions.Create_Option<int>("eventPrint", "set event print number", 1);
auto runID = programOptions.Create_Option<int>("runID", "set runID", DEFAULT_RUNID);
auto multi = programOptions.Create_Option<int>("multiplicity", "set particle multiplicity", 1);
auto pEnergy = programOptions.Create_Option<double>("energy", "set energy value (GeV) of the particle", 1);
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto eventNum = programOptions.create_option<int>("eventNum", "set total event number", defaultEventNum);
auto eventPrintNum = programOptions.create_option<int>("eventPrint", "set event print number", 1);
auto runID = programOptions.create_option<int>("runID", "set runID", DEFAULT_RUNID);
auto multi = programOptions.create_option<int>("multiplicity", "set particle multiplicity", 1);
auto pEnergy = programOptions.create_option<double>("energy", "set energy value (GeV) of the particle", 1);
auto simuFileName =
programOptions.Create_Option<std::string>("simuFile", "set the base filename of simulation ouput", "simu.root");
programOptions.create_option<std::string>("simuFile", "set the base filename of simulation ouput", "simu.root");
auto paraFileName =
programOptions.Create_Option<std::string>("paraFile", "set the base filename of parameter sink", "para.root");
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "error");
programOptions.create_option<std::string>("paraFile", "set the base filename of parameter sink", "para.root");
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "error");

if (!programOptions.Verify(argc, argv))
if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
std::cout << programOptions.get_desc_ref() << std::endl;
return 0;
}

Expand Down
12 changes: 6 additions & 6 deletions neuland/executables/templates/ex_digi.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ auto main(int argc, const char** argv) -> int
timer.Start();

auto programOptions = R3B::ProgramOptions("options for neuland data analysis");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto paraFileName =
programOptions.Create_Option<std::string>("paraFile", "set the filename of parameter sink", "para.root");
programOptions.create_option<std::string>("paraFile", "set the filename of parameter sink", "para.root");
auto digiFileName =
programOptions.Create_Option<std::string>("digiFile", "set the filename of digitization output", "digi.root");
programOptions.create_option<std::string>("digiFile", "set the filename of digitization output", "digi.root");
auto simuFileName =
programOptions.Create_Option<std::string>("simuFile", "set the filename of simulation input", "simu.root");
if (!programOptions.Verify(argc, argv))
programOptions.create_option<std::string>("simuFile", "set the filename of simulation input", "simu.root");
if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
std::cout << programOptions.get_desc_ref() << std::endl;
return 0;
}

Expand Down
18 changes: 9 additions & 9 deletions neuland/executables/templates/neuland_cal_to_hit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ auto main(int argc, const char** argv) -> int
timer.Start();

auto programOptions = R3B::ProgramOptions("options for neuland exp cal to hit analysis");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "error");
auto input_dir = programOptions.Create_Option<std::string>("inDir,i", "set the input directory", "");
auto output_dir = programOptions.Create_Option<std::string>("outDir,o", "set the output directory", "");
auto inputRunID = programOptions.Create_Option<int>("runid,r", "set the input runID", 0);
auto eventNum = programOptions.Create_Option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);

if (!programOptions.Verify(argc, argv))
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "error");
auto input_dir = programOptions.create_option<std::string>("inDir,i", "set the input directory", "");
auto output_dir = programOptions.create_option<std::string>("outDir,o", "set the output directory", "");
auto inputRunID = programOptions.create_option<int>("runid,r", "set the input runID", 0);
auto eventNum = programOptions.create_option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);

if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
std::cout << programOptions.get_desc_ref() << std::endl;
return 0;
}
FairLogger::GetLogger()->SetLogScreenLevel(logLevel->value().c_str());
Expand Down
28 changes: 14 additions & 14 deletions neuland/executables/templates/neuland_lmd_to_map.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ auto main(int argc, const char** argv) -> int
//====================================================================================
// Program options:
auto programOptions = R3B::ProgramOptions("options for neuland data analysis");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto auto_id = programOptions.Create_Option<bool>("autoTrigID", "auto detect trigID", false);
auto no_trig_neuland = programOptions.Create_Option<bool>("no-trig", "auto detect trigID", false);
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "info");
auto eventNum = programOptions.Create_Option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);
auto input_dir = programOptions.Create_Option<std::string>("inDir,i", "set the input directory", "");
auto output_dir = programOptions.Create_Option<std::string>("outDir,o", "set the output directory", ".");
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto auto_id = programOptions.create_option<bool>("autoTrigID", "auto detect trigID", false);
auto no_trig_neuland = programOptions.create_option<bool>("no-trig", "auto detect trigID", false);
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "info");
auto eventNum = programOptions.create_option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);
auto input_dir = programOptions.create_option<std::string>("inDir,i", "set the input directory", "");
auto output_dir = programOptions.create_option<std::string>("outDir,o", "set the output directory", ".");
auto jsonName =
programOptions.Create_Option<std::string>("json", "set the json filename of trigIDMap", "TrigMapping.json");
auto inputRunID = programOptions.Create_Option<int>("runID,r", "set the input runID", 0);
auto neulandDP = programOptions.Create_Option<int>(
programOptions.create_option<std::string>("json", "set the json filename of trigIDMap", "TrigMapping.json");
auto inputRunID = programOptions.create_option<int>("runID,r", "set the input runID", 0);
auto neulandDP = programOptions.create_option<int>(
"dp", "set the number of double planes for neuland", NEULAND_DEFAULT_DOUBLE_PLANE);
auto wr_ID = programOptions.Create_Option<std::string>("wrID", "set the white rabbit id", "0x1000U");
auto unpacker_path = programOptions.Create_Option<std::string>(
auto wr_ID = programOptions.create_option<std::string>("wrID", "set the white rabbit id", "0x1000U");
auto unpacker_path = programOptions.create_option<std::string>(
"unpack", "set the path of unpacker executable relative to ${UCESB_DIR}/../unexps/", DEFAULT_UNPACKER_PATH);
if (!programOptions.Verify(argc, argv))
if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
std::cout << programOptions.get_desc_ref() << std::endl;
return 0;
}

Expand Down
18 changes: 9 additions & 9 deletions neuland/executables/templates/neuland_map_to_cal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ auto main(int argc, const char** argv) -> int
timer.Start();

auto programOptions = R3B::ProgramOptions("options for neuland exp data analysis");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "error");
auto input_dir = programOptions.Create_Option<std::string>("inDir,i", "set the input directory", "");
auto output_dir = programOptions.Create_Option<std::string>("outDir,o", "set the output directory", "");
auto inputRunID = programOptions.Create_Option<int>("runid,r", "set the input runID", 0);
auto eventNum = programOptions.Create_Option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);

if (!programOptions.Verify(argc, argv))
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "error");
auto input_dir = programOptions.create_option<std::string>("inDir,i", "set the input directory", "");
auto output_dir = programOptions.create_option<std::string>("outDir,o", "set the output directory", "");
auto inputRunID = programOptions.create_option<int>("runid,r", "set the input runID", 0);
auto eventNum = programOptions.create_option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);

if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
std::cout << programOptions.get_desc_ref() << std::endl;
return 0;
}
FairLogger::GetLogger()->SetLogScreenLevel(logLevel->value().c_str());
Expand Down
32 changes: 13 additions & 19 deletions neuland/executables/templates/neuland_online_monitor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,33 +61,27 @@ auto main(int argc, const char** argv) -> int
//====================================================================================
// Program options:
auto programOptions = R3B::ProgramOptions("Online monitor for neuland data");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto no_trig_neuland = programOptions.Create_Option<bool>("no-trig", "auto detect trigID", false);
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "info");
auto eventNum = programOptions.Create_Option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);
auto inputRunID = programOptions.Create_Option<int>("runID,r", "set the input runID", DEFAULT_RUNID);
auto neulandDP = programOptions.Create_Option<int>(
auto input_fstream = programOptions.create_option<std::string>("inStream,i", "set the input data stream");
auto parameter_file =
programOptions.create_option<std::string>("par", "set the path of the parameter file (only one allowed)");
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto no_trig_neuland = programOptions.create_option<bool>("no-trig", "NeuLAND trigger times are disabled", false);
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "info");
auto eventNum = programOptions.create_option<int>("eventNum,n", "set the event number", DEFAULT_EVENT_NUM);
auto inputRunID = programOptions.create_option<int>("runID,r", "set the input runID", DEFAULT_RUNID);
auto neulandDP = programOptions.create_option<int>(
"dp", "set the number of double planes for neuland", NEULAND_DEFAULT_DOUBLE_PLANE);
auto wr_ID = programOptions.Create_Option<std::string>("wrID", "set the white rabbit id", "0x1000U");
auto unpacker_path = programOptions.Create_Option<std::string>(
auto wr_ID = programOptions.create_option<std::string>("wrID", "set the white rabbit id", "0x1000U");
auto unpacker_path = programOptions.create_option<std::string>(
"unpack", "set the path of unpacker executable relative to ${UCESB_DIR}/../unexps/", DEFAULT_UNPACKER_PATH);
auto input_fstream = programOptions.Create_Option<std::string>("inStream,i", "set the input data stream", "");
auto parameter_file =
programOptions.Create_Option<std::string>("par", "set the path of the parameter file (only one allowed)", "");
auto port_number =
programOptions.Create_Option<int>("port,p", "set the path of the parameter file", DEFAULT_PORT_NUM);
programOptions.create_option<int>("port,p", "set the port number of the output https server", DEFAULT_PORT_NUM);

if (!programOptions.Verify(argc, argv))
if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
return 0;
}

FairLogger::GetLogger()->SetLogScreenLevel(logLevel->value().c_str());

auto random_gen = TRandom3{};
Expand Down
35 changes: 21 additions & 14 deletions neuland/executables/templates/neuland_par_merger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,35 @@ void merge_into_rootfile(TFile* output, const std::vector<std::string>& filename
}
}

void initialize_output_file(TFile* output, std::string_view base)
{
auto base_file = std::make_unique<TFile>(base.data(), "READ");
auto* par_run = get_par_run(base_file.get());
if (par_run == nullptr)
{
throw R3B::runtime_error(fmt::format(R"(Base file {} doesn't contain any FairRtdbRun!)", base));
}
output->WriteObject<FairRtdbRun>(par_run, par_run->GetName(), "overwrite");
}

auto main(int argc, const char** argv) -> int
{

using namespace std::string_literals;
//====================================================================================
// Program options:
auto programOptions = R3B::ProgramOptions("Online monitor for neuland data");
auto help = programOptions.Create_Option<bool>("help,h", "help message", false);
auto logLevel = programOptions.Create_Option<std::string>("logLevel,v", "set log level of fairlog", "info");
auto parameter_out = programOptions.Create_Option<std::string>(
"par-out", "set the path of the parameter file to merge into (only one allowed)", "output_par.root");
auto parameter_in = programOptions.Create_Option<std::string>(
"par-in", "set the path of the parameter files to merge from (semicolon seperated)", "");
if (!programOptions.Verify(argc, argv))
auto programOptions = R3B::ProgramOptions("Parameter merge");
auto help = programOptions.create_option<bool>("help,h", "help message", false);
auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "info");
auto parameter_out = programOptions.create_option<std::string>(
"par-out", "set the path of the parameter file to merge into (only one allowed)");
auto parameter_in = programOptions.create_option<std::string>(
"par-in", "set the path of the parameter files to merge from (semicolon seperated)");
if (!programOptions.verify(argc, argv))
{
return EXIT_FAILURE;
}

if (help->value())
{
std::cout << programOptions.Get_DescRef() << std::endl;
return 0;
}
FairLogger::GetLogger()->SetLogScreenLevel(logLevel->value().c_str());

const auto input_files = filenames_split(parameter_in->value());
Expand All @@ -137,10 +143,11 @@ auto main(int argc, const char** argv) -> int
R3BLOG(error, "empty input parameter file!");
}

auto output_rootfile = std::make_unique<TFile>(output_file.c_str(), "UPDATE");
auto output_rootfile = std::make_unique<TFile>(output_file.c_str(), "RECREATE");

try
{
initialize_output_file(output_rootfile.get(), input_files.front());
merge_into_rootfile(output_rootfile.get(), input_files);
}
catch (const std::exception& ex)
Expand Down
9 changes: 8 additions & 1 deletion neuland/shared/R3BProgramOptions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

namespace R3B
{
bool ProgramOptions::Verify(int argc, const char** argv)
auto ProgramOptions::verify(int argc, const char** argv) -> bool
{

try
{
po::store(po::command_line_parser(argc, argv).positional(pos_desc_).options(desc_).run(), varMap_);
po::notify(varMap_);

if (varMap_.count("help") == 1)
{
std::cout << get_desc_ref() << std::endl;
return false;
}

for (auto& registrie : registries_)
{
registrie.second->Retrieve(varMap_);
Expand Down
Loading

0 comments on commit f4ecd74

Please sign in to comment.