From 3b985cd2cd72b4281d3b8540c5896ad0221f7dd1 Mon Sep 17 00:00:00 2001 From: winckler Date: Tue, 5 Apr 2016 17:52:10 +0200 Subject: [PATCH] encapsulate and use fairmq default xml and json parser if command line mq-config file.extension is called. The .xml and .json files are recognized internally. Remove explicit json parsing in runSimpleMQStateMAchine.h. Propagate the new commandline mq-config where the runstatemachine function is used --- fairmq/options/FairMQProgOptions.cxx | 38 +++++++++++++++++++++++--- fairmq/options/FairMQProgOptions.h | 15 ++++++++++ fairmq/tools/runSimpleMQStateMachine.h | 6 ---- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index b0a114f5..f45c4b6c 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -14,7 +14,7 @@ #include "FairMQProgOptions.h" #include - +#include "FairMQParser.h" using namespace std; FairMQProgOptions::FairMQProgOptions() @@ -24,6 +24,8 @@ FairMQProgOptions::FairMQProgOptions() , fMQOptionsInCmd("MQ-Device options") , fMQtree() , fFairMQMap() + , fHelpTitle("***** FAIRMQ Program Options ***** ") + , fVersion("Beta version 0.1") { } @@ -104,6 +106,32 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregiste LOG(WARN) << "No channels will be created (You can create them manually)."; // return 1; } + else + { + if(fVarMap.count("mq-config")) + { + LOG(DEBUG)<<"mq-config command line called : default xml/json parser will be used"; + std::string file = fVarMap["mq-config"].as(); + std::string id = fVarMap["id"].as(); + + std::string file_extension = boost::filesystem::extension(file); + + std::transform(file_extension.begin(), file_extension.end(), file_extension.begin(), ::tolower); + + if(file_extension==".json") + UserParser(file, id); + else + if(file_extension==".xml") + UserParser(file, id); + else + { + LOG(ERROR) <<"mq-config command line called but file extension '" + <>()->multitoken(), "XML input as command line string.") ("config-xml-file", po::value(), "XML input as file.") ("config-json-string", po::value>()->multitoken(), "JSON input as command line string.") - ("config-json-file", po::value(), "JSON input as file."); + ("config-json-file", po::value(), "JSON input as file.") + ("mq-config", po::value(), "JSON/XML input as file. The configuration object will check xml or json file extention and will call the json or xml parser accordingly") + ; AddToCmdLineOptions(fGenericDesc); AddToCmdLineOptions(fMQOptionsInCmd); diff --git a/fairmq/options/FairMQProgOptions.h b/fairmq/options/FairMQProgOptions.h index 55141367..5282cd84 100644 --- a/fairmq/options/FairMQProgOptions.h +++ b/fairmq/options/FairMQProgOptions.h @@ -34,6 +34,8 @@ class FairMQProgOptions : public FairProgOptions FairMQProgOptions(); virtual ~FairMQProgOptions(); + // parse command line and txt/INI configuration file. + // default parser for the mq-configuration file (JSON/XML) is called if command line key mq-config is called virtual int ParseAll(const int argc, char** argv, bool allowUnregistered = false); // external parser, store function @@ -75,12 +77,25 @@ class FairMQProgOptions : public FairProgOptions return fFairMQMap; } + // to customize title of the executable help command line + void SetHelpTitle(const std::string& title) + { + fHelpTitle=title; + } + // to customize the executable version command line + void SetVersion(const std::string& version) + { + fVersion=version; + } + protected: po::options_description fMQParserOptions; po::options_description fMQOptionsInCfg; po::options_description fMQOptionsInCmd; pt::ptree fMQtree; FairMQMap fFairMQMap; + std::string fHelpTitle; + std::string fVersion; virtual int NotifySwitchOption(); // for custom help & version printing void InitOptionDescription(); diff --git a/fairmq/tools/runSimpleMQStateMachine.h b/fairmq/tools/runSimpleMQStateMachine.h index ef9d9ca8..d743c247 100644 --- a/fairmq/tools/runSimpleMQStateMachine.h +++ b/fairmq/tools/runSimpleMQStateMachine.h @@ -27,12 +27,9 @@ template inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config) { device.CatchSignals(); - std::string jsonfile = config.GetValue("config-json-file"); std::string id = config.GetValue("id"); int ioThreads = config.GetValue("io-threads"); - config.UserParser(jsonfile, id); - device.fChannels = config.GetFairMQMap(); device.SetProperty(TMQDevice::Id, id); @@ -58,12 +55,9 @@ template inline int runNonInteractiveStateMachine(TMQDevice& device, FairMQProgOptions& config) { device.CatchSignals(); - std::string jsonfile = config.GetValue("config-json-file"); std::string id = config.GetValue("id"); int ioThreads = config.GetValue("io-threads"); - config.UserParser(jsonfile, id); - device.fChannels = config.GetFairMQMap(); device.SetProperty(TMQDevice::Id, id);