mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Add FairMQProgOptions for configuring MQDevices
This commit is contained in:
83
fairmq/options/ProgOptionTest/run/runOptTestSampler.cxx
Normal file
83
fairmq/options/ProgOptionTest/run/runOptTestSampler.cxx
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* File: runOptTestSampler.cxx
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on June 10, 2015, 3:34 PM
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
/// std
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/// boost
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
/// FairRoot/FairMQ
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// main
|
||||
//////////////////////////////////////////////////////////////
|
||||
using namespace std;
|
||||
using namespace FairMQParser;
|
||||
using namespace boost::program_options;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FairMQProgOptions config;
|
||||
try
|
||||
{
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// define key specific to the BenchmarkSampler in options_description
|
||||
|
||||
int eventSize;
|
||||
int eventRate;
|
||||
int ioThreads;
|
||||
options_description sampler_options("Sampler options");
|
||||
sampler_options.add_options()
|
||||
("event-size", value<int>(&eventSize)->default_value(1000), "Event size in bytes")
|
||||
("event-rate", value<int>(&eventRate)->default_value(0), "Event rate limit in maximum number of events per second")
|
||||
("io-threads", value<int>(&ioThreads)->default_value(1), "Number of I/O threads");
|
||||
|
||||
// and add it to cmdline option of FairMQProgOptions
|
||||
config.AddToCmdLineOptions(sampler_options);
|
||||
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// enable simple config txt/INI file
|
||||
//config.EnableCfgFile();
|
||||
//config.AddToCfgFileOptions(sampler_options,false);
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// Parse command line options and store in variable map
|
||||
if(config.ParseAll(argc,argv,true))
|
||||
return 0;
|
||||
|
||||
// keys defined in FairMQProgOptions
|
||||
string filename=config.GetValue<string>("config-json-filename");
|
||||
string deviceID=config.GetValue<string>("device-id");
|
||||
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// User defined parsing method.
|
||||
|
||||
config.UserParser<JSON>(filename,deviceID);
|
||||
FairMQMap channels=config.GetFairMQMap();
|
||||
//set device here
|
||||
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
LOG(INFO) << "Command line options are the following : ";
|
||||
config.PrintHelp();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
77
fairmq/options/ProgOptionTest/run/runOptTestSink.cxx
Normal file
77
fairmq/options/ProgOptionTest/run/runOptTestSink.cxx
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* File: runOptTestSink.cxx
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on June 10, 2015, 3:34 PM
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
/// std
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/// boost
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
/// FairRoot/FairMQ
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// main
|
||||
//////////////////////////////////////////////////////////////
|
||||
using namespace std;
|
||||
using namespace FairMQParser;
|
||||
using namespace boost::program_options;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FairMQProgOptions config;
|
||||
try
|
||||
{
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// define key specific to the BenchmarkSampler in options_description
|
||||
|
||||
int eventSize;
|
||||
int eventRate;
|
||||
int ioThreads;
|
||||
options_description Sink_options("Sink options");
|
||||
Sink_options.add_options()
|
||||
("io-threads", value<int>(&ioThreads)->default_value(1), "Number of I/O threads");
|
||||
|
||||
// and add it to cmdline option of FairMQProgOptions
|
||||
config.AddToCmdLineOptions(Sink_options);
|
||||
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// Parse command line options and store in variable map
|
||||
if(config.ParseAll(argc,argv,true))
|
||||
return 0;
|
||||
|
||||
// keys defined in FairMQProgOptions
|
||||
string filename=config.GetValue<string>("config-json-filename");
|
||||
string deviceID=config.GetValue<string>("device-id");
|
||||
|
||||
// //////////////////////////////////////////////////////////////
|
||||
// User defined parsing method.
|
||||
|
||||
config.UserParser<JSON>(filename,deviceID);
|
||||
FairMQMap channels=config.GetFairMQMap();
|
||||
//set device here
|
||||
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
LOG(INFO) << "Command line options are the following : ";
|
||||
config.PrintHelp();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
150
fairmq/options/ProgOptionTest/run/testMQoptions1.cxx
Normal file
150
fairmq/options/ProgOptionTest/run/testMQoptions1.cxx
Normal file
@@ -0,0 +1,150 @@
|
||||
/// std
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/// boost
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
/// FairRoot/FairMQ
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// tests
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// Parse xml from file
|
||||
int testXML1(FairMQProgOptions* config)
|
||||
{
|
||||
LOG(INFO)<<"--------- test XML1 ---------\n";
|
||||
std::string filename;
|
||||
std::string XMLrootNode;
|
||||
|
||||
filename=config->GetValue<std::string>("config-xml-filename");
|
||||
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
|
||||
std::string id=config->GetValue<std::string>("device-id");
|
||||
config->UserParser<FairMQParser::XML>(filename,id,XMLrootNode);
|
||||
// other xml parser test
|
||||
config->UserParser<FairMQParser::MQXML2>(filename);
|
||||
config->UserParser<FairMQParser::MQXML3>(filename,"merger");
|
||||
|
||||
LOG(INFO)<<"--------- test XML1 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Parse xml from command line
|
||||
int testXML2(FairMQProgOptions* config)
|
||||
{
|
||||
LOG(INFO)<<"--------- test XML2 ---------\n";
|
||||
std::string XML;
|
||||
std::string XMLrootNode;
|
||||
std::string id=config->GetValue<std::string>("device-id");
|
||||
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
|
||||
|
||||
// Note: convert the vector<string> into one string with GetStringValue(key)
|
||||
XML=config->GetStringValue("config-xml-string");
|
||||
|
||||
std::stringstream iss;
|
||||
iss << XML;
|
||||
config->UserParser<FairMQParser::XML>(iss,id,XMLrootNode);
|
||||
|
||||
LOG(INFO)<<"--------- test XML2 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Parse json from file
|
||||
int testJSON1(FairMQProgOptions* config)
|
||||
{
|
||||
LOG(INFO)<<"--------- test JSON1 ---------\n";
|
||||
std::string filename;
|
||||
std::string JSONrootNode;
|
||||
std::string id=config->GetValue<std::string>("device-id");
|
||||
|
||||
filename=config->GetValue<std::string>("config-json-filename");
|
||||
JSONrootNode=config->GetValue<std::string>("json.config.node.root");
|
||||
|
||||
config->UserParser<FairMQParser::JSON>(filename,id,JSONrootNode);
|
||||
|
||||
LOG(INFO)<<"--------- test JSON1 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Parse json from command line
|
||||
int testJSON2(FairMQProgOptions* config)
|
||||
{
|
||||
LOG(INFO)<<"--------- test JSON2 ---------\n";
|
||||
std::string JSON;
|
||||
std::string JSONrootNode;
|
||||
std::string id=config->GetValue<std::string>("device-id");
|
||||
JSONrootNode=config->GetValue<std::string>("json.config.node.root");
|
||||
|
||||
// Note: convert the vector<string> into one string with GetStringValue(key)
|
||||
JSON=config->GetStringValue("config-json-string");
|
||||
|
||||
std::stringstream iss;
|
||||
iss << JSON;
|
||||
config->UserParser<FairMQParser::JSON>(iss,id,JSONrootNode);
|
||||
|
||||
LOG(INFO)<<"--------- test JSON2 end ---------\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// main
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FairMQProgOptions* config= new FairMQProgOptions();
|
||||
try
|
||||
{
|
||||
po::options_description format_desc("XML or JSON input");
|
||||
format_desc.add_options()
|
||||
("xml.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "xml root node ")
|
||||
("json.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "json root node ")
|
||||
;
|
||||
|
||||
config->AddToCmdLineOptions(format_desc);
|
||||
|
||||
// Parse command line
|
||||
if(config->ParseAll(argc,argv))
|
||||
return 0;
|
||||
|
||||
// Set severity level (Default is 0=DEBUG)
|
||||
int verbose=config->GetValue<int>("verbose");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbose);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
|
||||
// Parse xml or json from cmd line or file
|
||||
|
||||
if(config->GetVarMap().count("config-xml-filename"))
|
||||
testXML1(config);
|
||||
|
||||
if(config->GetVarMap().count("config-xml-string"))
|
||||
testXML2(config);
|
||||
|
||||
if(config->GetVarMap().count("config-json-filename"))
|
||||
testJSON1(config);
|
||||
|
||||
if(config->GetVarMap().count("config-json-string"))
|
||||
testJSON2(config);
|
||||
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
79
fairmq/options/ProgOptionTest/run/testMQoptions2.cxx
Normal file
79
fairmq/options/ProgOptionTest/run/testMQoptions2.cxx
Normal file
@@ -0,0 +1,79 @@
|
||||
/// std
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/// boost
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
/// FairRoot/FairMQ
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// main
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
FairMQProgOptions config;
|
||||
|
||||
po::options_description format_desc("XML input");
|
||||
format_desc.add_options()
|
||||
("xml.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "xml root node ")
|
||||
;
|
||||
|
||||
po::options_description io_file_opt_desc("I/O file Options");
|
||||
io_file_opt_desc.add_options()
|
||||
("input.file.name", po::value<std::string>(), "input file name")
|
||||
("input.file.tree", po::value<std::string>(), "input tree name")
|
||||
("input.file.branch", po::value<std::string>(), "input branch name")
|
||||
("output.file.name", po::value<std::string>(), "output file name")
|
||||
("output.file.tree", po::value<std::string>(), "output tree name")
|
||||
("output.file.branch", po::value<std::string>(), "output branch name")
|
||||
;
|
||||
|
||||
config.AddToCmdLineOptions(format_desc,true);
|
||||
config.AddToCmdLineOptions(io_file_opt_desc,true);
|
||||
|
||||
|
||||
config.EnableCfgFile();// UseConfigFile (by default config file is not defined)
|
||||
config.AddToCfgFileOptions(format_desc,false);//false because already added to visible
|
||||
config.AddToCfgFileOptions(io_file_opt_desc,false);
|
||||
|
||||
// Parse command line and config file
|
||||
if(config.ParseAll(argc,argv))
|
||||
return 0;
|
||||
|
||||
// Set severity level (Default is 0=DEBUG)
|
||||
int verbose=config.GetValue<int>("verbose");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbose);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
// parse XML file
|
||||
std::string filename;
|
||||
std::string XMLrootNode;
|
||||
|
||||
filename=config.GetValue<std::string>("config-xml-filename");
|
||||
XMLrootNode=config.GetValue<std::string>("xml.config.node.root");
|
||||
std::string id=config.GetValue<std::string>("device-id");
|
||||
config.UserParser<FairMQParser::XML>(filename,id,XMLrootNode);
|
||||
|
||||
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user