mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
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
This commit is contained in:
parent
8df656a302
commit
3b985cd2cd
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include "FairMQProgOptions.h"
|
#include "FairMQProgOptions.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "FairMQParser.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
FairMQProgOptions::FairMQProgOptions()
|
FairMQProgOptions::FairMQProgOptions()
|
||||||
|
@ -24,6 +24,8 @@ FairMQProgOptions::FairMQProgOptions()
|
||||||
, fMQOptionsInCmd("MQ-Device options")
|
, fMQOptionsInCmd("MQ-Device options")
|
||||||
, fMQtree()
|
, fMQtree()
|
||||||
, fFairMQMap()
|
, 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).";
|
LOG(WARN) << "No channels will be created (You can create them manually).";
|
||||||
// return 1;
|
// 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>();
|
||||||
|
std::string id = fVarMap["id"].as<std::string>();
|
||||||
|
|
||||||
|
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<FairMQParser::JSON>(file, id);
|
||||||
|
else
|
||||||
|
if(file_extension==".xml")
|
||||||
|
UserParser<FairMQParser::XML>(file, id);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG(ERROR) <<"mq-config command line called but file extension '"
|
||||||
|
<<file_extension
|
||||||
|
<< "' not recognized. Program will now exit";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -112,13 +140,13 @@ int FairMQProgOptions::NotifySwitchOption()
|
||||||
{
|
{
|
||||||
if (fVarMap.count("help"))
|
if (fVarMap.count("help"))
|
||||||
{
|
{
|
||||||
LOG(INFO) << "***** FAIRMQ Program Options ***** \n" << fVisibleOptions;
|
LOG(INFO) << fHelpTitle << "\n" << fVisibleOptions;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fVarMap.count("version"))
|
if (fVarMap.count("version"))
|
||||||
{
|
{
|
||||||
LOG(INFO) << "Beta version 0.1\n";
|
LOG(INFO) << fVersion << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +180,9 @@ void FairMQProgOptions::InitOptionDescription()
|
||||||
("config-xml-string", po::value<vector<string>>()->multitoken(), "XML input as command line string.")
|
("config-xml-string", po::value<vector<string>>()->multitoken(), "XML input as command line string.")
|
||||||
("config-xml-file", po::value<string>(), "XML input as file.")
|
("config-xml-file", po::value<string>(), "XML input as file.")
|
||||||
("config-json-string", po::value<vector<string>>()->multitoken(), "JSON input as command line string.")
|
("config-json-string", po::value<vector<string>>()->multitoken(), "JSON input as command line string.")
|
||||||
("config-json-file", po::value<string>(), "JSON input as file.");
|
("config-json-file", po::value<string>(), "JSON input as file.")
|
||||||
|
("mq-config", po::value<string>(), "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(fGenericDesc);
|
||||||
AddToCmdLineOptions(fMQOptionsInCmd);
|
AddToCmdLineOptions(fMQOptionsInCmd);
|
||||||
|
|
|
@ -34,6 +34,8 @@ class FairMQProgOptions : public FairProgOptions
|
||||||
FairMQProgOptions();
|
FairMQProgOptions();
|
||||||
virtual ~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);
|
virtual int ParseAll(const int argc, char** argv, bool allowUnregistered = false);
|
||||||
|
|
||||||
// external parser, store function
|
// external parser, store function
|
||||||
|
@ -75,12 +77,25 @@ class FairMQProgOptions : public FairProgOptions
|
||||||
return fFairMQMap;
|
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:
|
protected:
|
||||||
po::options_description fMQParserOptions;
|
po::options_description fMQParserOptions;
|
||||||
po::options_description fMQOptionsInCfg;
|
po::options_description fMQOptionsInCfg;
|
||||||
po::options_description fMQOptionsInCmd;
|
po::options_description fMQOptionsInCmd;
|
||||||
pt::ptree fMQtree;
|
pt::ptree fMQtree;
|
||||||
FairMQMap fFairMQMap;
|
FairMQMap fFairMQMap;
|
||||||
|
std::string fHelpTitle;
|
||||||
|
std::string fVersion;
|
||||||
|
|
||||||
virtual int NotifySwitchOption(); // for custom help & version printing
|
virtual int NotifySwitchOption(); // for custom help & version printing
|
||||||
void InitOptionDescription();
|
void InitOptionDescription();
|
||||||
|
|
|
@ -27,12 +27,9 @@ template<typename TMQDevice>
|
||||||
inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
|
inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
|
||||||
{
|
{
|
||||||
device.CatchSignals();
|
device.CatchSignals();
|
||||||
std::string jsonfile = config.GetValue<std::string>("config-json-file");
|
|
||||||
std::string id = config.GetValue<std::string>("id");
|
std::string id = config.GetValue<std::string>("id");
|
||||||
int ioThreads = config.GetValue<int>("io-threads");
|
int ioThreads = config.GetValue<int>("io-threads");
|
||||||
|
|
||||||
config.UserParser<FairMQParser::JSON>(jsonfile, id);
|
|
||||||
|
|
||||||
device.fChannels = config.GetFairMQMap();
|
device.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
device.SetProperty(TMQDevice::Id, id);
|
device.SetProperty(TMQDevice::Id, id);
|
||||||
|
@ -58,12 +55,9 @@ template<typename TMQDevice>
|
||||||
inline int runNonInteractiveStateMachine(TMQDevice& device, FairMQProgOptions& config)
|
inline int runNonInteractiveStateMachine(TMQDevice& device, FairMQProgOptions& config)
|
||||||
{
|
{
|
||||||
device.CatchSignals();
|
device.CatchSignals();
|
||||||
std::string jsonfile = config.GetValue<std::string>("config-json-file");
|
|
||||||
std::string id = config.GetValue<std::string>("id");
|
std::string id = config.GetValue<std::string>("id");
|
||||||
int ioThreads = config.GetValue<int>("io-threads");
|
int ioThreads = config.GetValue<int>("io-threads");
|
||||||
|
|
||||||
config.UserParser<FairMQParser::JSON>(jsonfile, id);
|
|
||||||
|
|
||||||
device.fChannels = config.GetFairMQMap();
|
device.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
device.SetProperty(TMQDevice::Id, id);
|
device.SetProperty(TMQDevice::Id, id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user