mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Refactor FairMQProgOptions
This commit is contained in:
parent
ca694e4054
commit
8b88e67360
|
@ -129,12 +129,10 @@ set(FAIRMQ_SOURCE_FILES
|
|||
devices/FairMQMerger.cxx
|
||||
devices/FairMQMultiplier.cxx
|
||||
devices/FairMQProxy.cxx
|
||||
# devices/FairMQSink.cxx
|
||||
devices/FairMQSplitter.cxx
|
||||
options/FairMQParser.cxx
|
||||
options/FairMQProgOptions.cxx
|
||||
options/FairMQSuboptParser.cxx
|
||||
options/FairProgOptions.cxx
|
||||
Plugin.cxx
|
||||
PluginManager.cxx
|
||||
PluginServices.cxx
|
||||
|
|
|
@ -327,9 +327,7 @@ void FairMQChannel::UpdateTransport(const string& transport)
|
|||
{
|
||||
unique_lock<mutex> lock(fChannelMutex);
|
||||
fIsValid = false;
|
||||
LOG(WARN) << fName << ": " << transport;
|
||||
fTransportType = fair::mq::TransportTypes.at(transport);
|
||||
LOG(WARN) << fName << ": " << fair::mq::TransportNames.at(fTransportType);
|
||||
fModified = true;
|
||||
}
|
||||
catch (exception& e)
|
||||
|
|
|
@ -837,17 +837,17 @@ void FairMQDevice::SetConfig(FairMQProgOptions& config)
|
|||
{
|
||||
fExternalConfig = true;
|
||||
fConfig = &config;
|
||||
for (auto& c : config.GetFairMQMap())
|
||||
for (auto& c : fConfig->GetFairMQMap())
|
||||
{
|
||||
if (!fChannels.insert(c).second)
|
||||
{
|
||||
LOG(warn) << "did not insert channel '" << c.first << "', it is already in the device.";
|
||||
}
|
||||
}
|
||||
fId = config.GetValue<string>("id");
|
||||
fNetworkInterface = config.GetValue<string>("network-interface");
|
||||
fNumIoThreads = config.GetValue<int>("io-threads");
|
||||
fInitializationTimeoutInS = config.GetValue<int>("initialization-timeout");
|
||||
fId = fConfig->GetValue<string>("id");
|
||||
fNetworkInterface = fConfig->GetValue<string>("network-interface");
|
||||
fNumIoThreads = fConfig->GetValue<int>("io-threads");
|
||||
fInitializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout");
|
||||
fRate = fConfig->GetValue<float>("rate");
|
||||
try {
|
||||
fDefaultTransportType = fair::mq::TransportTypes.at(fConfig->GetValue<string>("transport"));
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQSink.cxx
|
||||
*
|
||||
* @since 2013-01-09
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include "FairMQSink.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "../FairMQLogger.h"
|
||||
#include "../options/FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQSink::FairMQSink()
|
||||
: fNumMsgs(0)
|
||||
, fInChannelName()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQSink::InitTask()
|
||||
{
|
||||
fNumMsgs = fConfig->GetValue<uint64_t>("num-msgs");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
}
|
||||
|
||||
void FairMQSink::Run()
|
||||
{
|
||||
uint64_t numReceivedMsgs = 0;
|
||||
// store the channel reference to avoid traversing the map on every loop iteration
|
||||
FairMQChannel& dataInChannel = fChannels.at(fInChannelName).at(0);
|
||||
|
||||
LOG(info) << "Starting the benchmark and expecting to receive " << fNumMsgs << " messages.";
|
||||
auto tStart = chrono::high_resolution_clock::now();
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
FairMQMessagePtr msg(dataInChannel.Transport()->CreateMessage());
|
||||
|
||||
if (dataInChannel.Receive(msg) >= 0)
|
||||
{
|
||||
if (fNumMsgs > 0)
|
||||
{
|
||||
if (numReceivedMsgs >= fNumMsgs)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
numReceivedMsgs++;
|
||||
}
|
||||
}
|
||||
|
||||
auto tEnd = chrono::high_resolution_clock::now();
|
||||
|
||||
LOG(info) << "Leaving RUNNING state. Received " << numReceivedMsgs << " messages in " << chrono::duration<double, milli>(tEnd - tStart).count() << "ms.";
|
||||
}
|
||||
|
||||
FairMQSink::~FairMQSink()
|
||||
{
|
||||
}
|
|
@ -27,11 +27,16 @@ namespace parser
|
|||
{
|
||||
|
||||
// TODO : add key-value map<string,string> parameter for replacing/updating values from keys
|
||||
// function that convert property tree (given the json structure) to FairMQMap
|
||||
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id, const string& rootNode)
|
||||
// function that convert property tree (given the json structure) to FairMQChannelMap
|
||||
FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id, const string& rootNode)
|
||||
{
|
||||
if (id == "")
|
||||
{
|
||||
throw ParserError("no device ID provided. Provide with `--id` cmd option");
|
||||
}
|
||||
|
||||
// Create fair mq map
|
||||
FairMQMap channelMap;
|
||||
FairMQChannelMap channelMap;
|
||||
// boost::property_tree::json_parser::write_json(std::cout, pt);
|
||||
// Helper::PrintDeviceList(pt.get_child(rootNode));
|
||||
// Extract value from boost::property_tree
|
||||
|
@ -46,20 +51,13 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id,
|
|||
return channelMap;
|
||||
}
|
||||
|
||||
FairMQMap JSON::UserParser(const string& filename, const string& deviceId, const string& rootNode)
|
||||
FairMQChannelMap JSON::UserParser(const string& filename, const string& deviceId, const string& rootNode)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_json(filename, pt);
|
||||
return ptreeToMQMap(pt, deviceId, rootNode);
|
||||
}
|
||||
|
||||
FairMQMap JSON::UserParser(stringstream& input, const string& deviceId, const string& rootNode)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_json(input, pt);
|
||||
return ptreeToMQMap(pt, deviceId, rootNode);
|
||||
}
|
||||
|
||||
namespace Helper
|
||||
{
|
||||
|
||||
|
@ -90,7 +88,7 @@ void PrintDeviceList(const boost::property_tree::ptree& tree)
|
|||
}
|
||||
}
|
||||
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const string& deviceId)
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQChannelMap& channelMap, const string& deviceId)
|
||||
{
|
||||
string deviceIdKey;
|
||||
|
||||
|
@ -129,7 +127,7 @@ void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap
|
|||
}
|
||||
}
|
||||
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap)
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& channelMap)
|
||||
{
|
||||
string channelKey;
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <exception>
|
||||
|
||||
#include <boost/property_tree/ptree_fwd.hpp>
|
||||
|
||||
|
@ -24,22 +24,23 @@ namespace mq
|
|||
namespace parser
|
||||
{
|
||||
|
||||
using FairMQMap = std::unordered_map<std::string, std::vector<FairMQChannel>>;
|
||||
using FairMQChannelMap = std::unordered_map<std::string, std::vector<FairMQChannel>>;
|
||||
|
||||
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& deviceId, const std::string& rootNode);
|
||||
struct ParserError : std::runtime_error { using std::runtime_error::runtime_error; };
|
||||
|
||||
FairMQChannelMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& deviceId, const std::string& rootNode);
|
||||
|
||||
struct JSON
|
||||
{
|
||||
FairMQMap UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
FairMQMap UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
FairMQChannelMap UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
};
|
||||
|
||||
namespace Helper
|
||||
{
|
||||
|
||||
void PrintDeviceList(const boost::property_tree::ptree& tree);
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const std::string& deviceId);
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap);
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQChannelMap& channelMap, const std::string& deviceId);
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQChannelMap& channelMap);
|
||||
void SocketParser(const boost::property_tree::ptree& tree, std::vector<FairMQChannel>& channelList, const std::string& channelName, const FairMQChannel& commonChannel);
|
||||
|
||||
} // Helper namespace
|
||||
|
|
|
@ -12,25 +12,70 @@
|
|||
* Created on March 11, 2015, 10:20 PM
|
||||
*/
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
#include "FairProgOptionsHelper.h"
|
||||
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQSuboptParser.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp> // join/split
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
FairMQProgOptions::FairMQProgOptions()
|
||||
: FairProgOptions()
|
||||
, fMQCmdOptions("FairMQ device options")
|
||||
, fMQParserOptions("FairMQ config parser options")
|
||||
, fFairMQMap()
|
||||
: fVarMap()
|
||||
, fFairMQChannelMap()
|
||||
, fAllOptions("FairMQ Command Line Options")
|
||||
, fGeneralOptions("General options")
|
||||
, fMQOptions("FairMQ device options")
|
||||
, fParserOptions("FairMQ channel config parser options")
|
||||
, fConfigMutex()
|
||||
, fChannelInfo()
|
||||
, fMQKeyMap()
|
||||
, fChannelKeyMap()
|
||||
, fUnregisteredOptions()
|
||||
, fEvents()
|
||||
{
|
||||
InitOptionDescription();
|
||||
fGeneralOptions.add_options()
|
||||
("help,h", "Print help")
|
||||
("version,v", "Print version")
|
||||
("severity", po::value<string>()->default_value("debug"), "Log severity level: trace, debug, info, state, warn, error, fatal, nolog")
|
||||
("verbosity", po::value<string>()->default_value("medium"), "Log verbosity level: veryhigh, high, medium, low")
|
||||
("color", po::value<bool >()->default_value(true), "Log color (true/false)")
|
||||
("log-to-file", po::value<string>()->default_value(""), "Log output to a file.")
|
||||
("print-options", po::value<bool >()->implicit_value(true), "Print options in machine-readable format (<option>:<computed-value>:<type>:<description>)");
|
||||
|
||||
fMQOptions.add_options()
|
||||
("id", po::value<string>(), "Device ID (required argument).")
|
||||
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
|
||||
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg'/'shmem') .")
|
||||
("network-interface", po::value<string>()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).")
|
||||
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file.")
|
||||
("initialization-timeout", po::value<int >()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).")
|
||||
("port-range-min", po::value<int >()->default_value(22000), "Start of the port range for dynamic initialization.")
|
||||
("port-range-max", po::value<int >()->default_value(32000), "End of the port range for dynamic initialization.")
|
||||
("print-channels", po::value<bool >()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (<channel name>:<min num subchannels>:<max num subchannels>)")
|
||||
("shm-segment-size", po::value<size_t>()->default_value(2000000000), "Shared memory: size of the shared memory segment (in bytes).")
|
||||
("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.")
|
||||
("rate", po::value<float >()->default_value(0.), "Rate for conditional run loop (Hz).")
|
||||
("session", po::value<string>()->default_value("default"), "Session name.");
|
||||
|
||||
fParserOptions.add_options()
|
||||
("mq-config", po::value<string>(), "JSON input as file.")
|
||||
("channel-config", po::value<vector<string>>()->multitoken()->composing(), "Configuration of single or multiple channel(s) by comma separated key=value list");
|
||||
|
||||
fAllOptions.add(fGeneralOptions);
|
||||
fAllOptions.add(fMQOptions);
|
||||
fAllOptions.add(fParserOptions);
|
||||
|
||||
ParseDefaults();
|
||||
}
|
||||
|
||||
|
@ -52,12 +97,20 @@ int FairMQProgOptions::ParseAll(const vector<string>& cmdLineArgs, bool allowUnr
|
|||
|
||||
int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool allowUnregistered)
|
||||
{
|
||||
if (FairProgOptions::ParseCmdLine(argc, argv, allowUnregistered))
|
||||
ParseCmdLine(argc, argv, allowUnregistered);
|
||||
|
||||
// if this option is provided, handle them and return stop value
|
||||
if (fVarMap.count("help"))
|
||||
{
|
||||
// ParseCmdLine returns 0 if no immediate switches found.
|
||||
cout << fAllOptions << endl;
|
||||
return 1;
|
||||
}
|
||||
// if this option is provided, handle them and return stop value
|
||||
if (fVarMap.count("print-options"))
|
||||
{
|
||||
PrintOptionsRaw();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// if these options are provided, do no further checks and let the device handle them
|
||||
if (fVarMap.count("print-channels") || fVarMap.count("version"))
|
||||
{
|
||||
|
@ -90,7 +143,7 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
|
|||
{
|
||||
id = fVarMap["config-key"].as<string>();
|
||||
}
|
||||
else
|
||||
else if (fVarMap.count("id"))
|
||||
{
|
||||
id = fVarMap["id"].as<string>();
|
||||
}
|
||||
|
@ -101,54 +154,84 @@ int FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool al
|
|||
if (fVarMap.count("mq-config"))
|
||||
{
|
||||
LOG(debug) << "mq-config: Using default JSON parser";
|
||||
Store(fair::mq::parser::JSON().UserParser(fVarMap["mq-config"].as<string>(), id));
|
||||
}
|
||||
else if (fVarMap.count("config-json-string"))
|
||||
{
|
||||
LOG(debug) << "config-json-string: Parsing JSON string";
|
||||
string value = fair::mq::ConvertVariableValue<fair::mq::VarInfoToString>()(fVarMap.at("config-json-string"));
|
||||
stringstream ss;
|
||||
ss << value;
|
||||
Store(fair::mq::parser::JSON().UserParser(ss, id));
|
||||
UpdateChannelMap(parser::JSON().UserParser(fVarMap.at("mq-config").as<string>(), id));
|
||||
}
|
||||
else if (fVarMap.count("channel-config"))
|
||||
{
|
||||
LOG(debug) << "channel-config: Parsing channel configuration";
|
||||
Store(fair::mq::parser::SUBOPT().UserParser(fVarMap.at("channel-config").as<vector<string>>(), id));
|
||||
UpdateChannelMap(parser::SUBOPT().UserParser(fVarMap.at("channel-config").as<vector<string>>(), id));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(warn) << "FairMQProgOptions: no channels configuration provided via neither of:";
|
||||
for (const auto& p : fMQParserOptions.options())
|
||||
for (const auto& p : fParserOptions.options())
|
||||
{
|
||||
LOG(warn) << "--" << p->canonical_display_name();
|
||||
}
|
||||
LOG(warn) << "No channels will be created (You can create them manually).";
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(error) << e.what();
|
||||
return 1;
|
||||
}
|
||||
|
||||
FairProgOptions::PrintOptions();
|
||||
PrintOptions();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FairMQProgOptions::Store(const FairMQMap& channels)
|
||||
void FairMQProgOptions::ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered)
|
||||
{
|
||||
fFairMQMap = channels;
|
||||
UpdateChannelInfo();
|
||||
UpdateMQValues();
|
||||
return 0;
|
||||
// get options from cmd line and store in variable map
|
||||
// here we use command_line_parser instead of parse_command_line, to allow unregistered and positional options
|
||||
if (allowUnregistered)
|
||||
{
|
||||
po::command_line_parser parser{argc, argv};
|
||||
parser.options(fAllOptions).allow_unregistered();
|
||||
po::parsed_options parsed = parser.run();
|
||||
fUnregisteredOptions = po::collect_unrecognized(parsed.options, po::include_positional);
|
||||
|
||||
po::store(parsed, fVarMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
po::store(po::parse_command_line(argc, argv, fAllOptions), fVarMap);
|
||||
}
|
||||
|
||||
po::notify(fVarMap);
|
||||
}
|
||||
|
||||
void FairMQProgOptions::ParseDefaults()
|
||||
{
|
||||
vector<string> emptyArgs;
|
||||
emptyArgs.push_back("dummy");
|
||||
|
||||
vector<const char*> argv(emptyArgs.size());
|
||||
|
||||
transform(emptyArgs.begin(), emptyArgs.end(), argv.begin(), [](const string& str)
|
||||
{
|
||||
return str.c_str();
|
||||
});
|
||||
|
||||
po::store(po::parse_command_line(argv.size(), const_cast<char**>(argv.data()), fAllOptions), fVarMap);
|
||||
}
|
||||
|
||||
unordered_map<string, vector<FairMQChannel>> FairMQProgOptions::GetFairMQMap() const
|
||||
{
|
||||
return fFairMQChannelMap;
|
||||
}
|
||||
|
||||
unordered_map<string, int> FairMQProgOptions::GetChannelInfo() const
|
||||
{
|
||||
return fChannelInfo;
|
||||
}
|
||||
|
||||
// replace FairMQChannelMap, and update variable map accordingly
|
||||
int FairMQProgOptions::UpdateChannelMap(const FairMQMap& channels)
|
||||
int FairMQProgOptions::UpdateChannelMap(const unordered_map<string, vector<FairMQChannel>>& channels)
|
||||
{
|
||||
fFairMQMap = channels;
|
||||
fFairMQChannelMap = channels;
|
||||
UpdateChannelInfo();
|
||||
UpdateMQValues();
|
||||
return 0;
|
||||
|
@ -157,7 +240,7 @@ int FairMQProgOptions::UpdateChannelMap(const FairMQMap& channels)
|
|||
void FairMQProgOptions::UpdateChannelInfo()
|
||||
{
|
||||
fChannelInfo.clear();
|
||||
for (const auto& c : fFairMQMap)
|
||||
for (const auto& c : fFairMQChannelMap)
|
||||
{
|
||||
fChannelInfo.insert(make_pair(c.first, c.second.size()));
|
||||
}
|
||||
|
@ -167,7 +250,7 @@ void FairMQProgOptions::UpdateChannelInfo()
|
|||
// create key for variable map as follow : channelName.index.memberName
|
||||
void FairMQProgOptions::UpdateMQValues()
|
||||
{
|
||||
for (const auto& p : fFairMQMap)
|
||||
for (const auto& p : fFairMQChannelMap)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
|
@ -183,15 +266,15 @@ void FairMQProgOptions::UpdateMQValues()
|
|||
string rcvKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvKernelSize";
|
||||
string rateLoggingKey = "chans." + p.first + "." + to_string(index) + ".rateLogging";
|
||||
|
||||
fMQKeyMap[typeKey] = MQKey{p.first, index, "type"};
|
||||
fMQKeyMap[methodKey] = MQKey{p.first, index, "method"};
|
||||
fMQKeyMap[addressKey] = MQKey{p.first, index, "address"};
|
||||
fMQKeyMap[transportKey] = MQKey{p.first, index, "transport"};
|
||||
fMQKeyMap[sndBufSizeKey] = MQKey{p.first, index, "sndBufSize"};
|
||||
fMQKeyMap[rcvBufSizeKey] = MQKey{p.first, index, "rcvBufSize"};
|
||||
fMQKeyMap[sndKernelSizeKey] = MQKey{p.first, index, "sndKernelSize"};
|
||||
fMQKeyMap[rcvKernelSizeKey] = MQKey{p.first, index, "rcvkernelSize"};
|
||||
fMQKeyMap[rateLoggingKey] = MQKey{p.first, index, "rateLogging"};
|
||||
fChannelKeyMap[typeKey] = ChannelKey{p.first, index, "type"};
|
||||
fChannelKeyMap[methodKey] = ChannelKey{p.first, index, "method"};
|
||||
fChannelKeyMap[addressKey] = ChannelKey{p.first, index, "address"};
|
||||
fChannelKeyMap[transportKey] = ChannelKey{p.first, index, "transport"};
|
||||
fChannelKeyMap[sndBufSizeKey] = ChannelKey{p.first, index, "sndBufSize"};
|
||||
fChannelKeyMap[rcvBufSizeKey] = ChannelKey{p.first, index, "rcvBufSize"};
|
||||
fChannelKeyMap[sndKernelSizeKey] = ChannelKey{p.first, index, "sndKernelSize"};
|
||||
fChannelKeyMap[rcvKernelSizeKey] = ChannelKey{p.first, index, "rcvkernelSize"};
|
||||
fChannelKeyMap[rateLoggingKey] = ChannelKey{p.first, index, "rateLogging"};
|
||||
|
||||
UpdateVarMap<string>(typeKey, channel.GetType());
|
||||
UpdateVarMap<string>(methodKey, channel.GetMethod());
|
||||
|
@ -209,103 +292,56 @@ void FairMQProgOptions::UpdateMQValues()
|
|||
}
|
||||
}
|
||||
|
||||
int FairMQProgOptions::ImmediateOptions()
|
||||
{
|
||||
if (fVarMap.count("help"))
|
||||
{
|
||||
cout << "===== FairMQ Program Options =====" << endl << fAllOptions;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (fVarMap.count("print-options"))
|
||||
{
|
||||
PrintOptionsRaw();
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FairMQProgOptions::InitOptionDescription()
|
||||
{
|
||||
fMQCmdOptions.add_options()
|
||||
("id", po::value<string>(), "Device ID (required argument).")
|
||||
("io-threads", po::value<int >()->default_value(1), "Number of I/O threads.")
|
||||
("transport", po::value<string>()->default_value("zeromq"), "Transport ('zeromq'/'nanomsg').")
|
||||
("config", po::value<string>()->default_value("static"), "Config source ('static'/<config library filename>).")
|
||||
("network-interface", po::value<string>()->default_value("default"), "Network interface to bind on (e.g. eth0, ib0..., default will try to detect the interface of the default route).")
|
||||
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file.")
|
||||
("initialization-timeout", po::value<int >()->default_value(120), "Timeout for the initialization in seconds (when expecting dynamic initialization).")
|
||||
("port-range-min", po::value<int >()->default_value(22000), "Start of the port range for dynamic initialization.")
|
||||
("port-range-max", po::value<int >()->default_value(32000), "End of the port range for dynamic initialization.")
|
||||
("print-channels", po::value<bool >()->implicit_value(true), "Print registered channel endpoints in a machine-readable format (<channel name>:<min num subchannels>:<max num subchannels>)")
|
||||
("shm-segment-size", po::value<size_t>()->default_value(2000000000), "Shared memory: size of the shared memory segment (in bytes).")
|
||||
("shm-monitor", po::value<bool >()->default_value(true), "Shared memory: run monitor daemon.")
|
||||
("rate", po::value<float >()->default_value(0.), "Rate for conditional run loop (Hz).")
|
||||
("session", po::value<string>()->default_value("default"), "Session name.")
|
||||
;
|
||||
|
||||
fMQParserOptions.add_options()
|
||||
("config-json-string", po::value<vector<string>>()->multitoken(), "JSON input as command line string.")
|
||||
("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")
|
||||
("channel-config", po::value<vector<string>>()->multitoken()->composing(), "Configuration of single or multiple channel(s) by comma separated key=value list")
|
||||
;
|
||||
|
||||
AddToCmdLineOptions(fMQCmdOptions);
|
||||
AddToCmdLineOptions(fMQParserOptions);
|
||||
}
|
||||
|
||||
int FairMQProgOptions::UpdateChannelMap(const string& channelName, int index, const string& member, const string& val)
|
||||
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, const string& val)
|
||||
{
|
||||
if (member == "type")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateType(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateType(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "method")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateMethod(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateMethod(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "address")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateAddress(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateAddress(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "transport")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateTransport(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateTransport(val);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if we get there it means something is wrong
|
||||
LOG(error) << "update of FairMQChannel map failed for the following key: "
|
||||
<< channelName << "." << index << "." << member;
|
||||
LOG(error) << "update of FairMQChannel map failed for the following key: " << channelName << "." << index << "." << member;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQProgOptions::UpdateChannelMap(const string& channelName, int index, const string& member, int val)
|
||||
int FairMQProgOptions::UpdateChannelValue(const string& channelName, int index, const string& member, int val)
|
||||
{
|
||||
if (member == "sndBufSize")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateSndBufSize(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateSndBufSize(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "rcvBufSize")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateRcvBufSize(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateRcvBufSize(val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (member == "rateLogging")
|
||||
{
|
||||
fFairMQMap.at(channelName).at(index).UpdateRateLogging(val);
|
||||
fFairMQChannelMap.at(channelName).at(index).UpdateRateLogging(val);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
@ -315,3 +351,135 @@ int FairMQProgOptions::UpdateChannelMap(const string& channelName, int index, co
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
vector<string> FairMQProgOptions::GetPropertyKeys() const
|
||||
{
|
||||
lock_guard<mutex> lock{fConfigMutex};
|
||||
|
||||
vector<string> result;
|
||||
|
||||
for (const auto& it : fVarMap)
|
||||
{
|
||||
result.push_back(it.first.c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Add option descriptions
|
||||
int FairMQProgOptions::AddToCmdLineOptions(const po::options_description optDesc, bool /* visible */)
|
||||
{
|
||||
fAllOptions.add(optDesc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
po::options_description& FairMQProgOptions::GetCmdLineOptions()
|
||||
{
|
||||
return fAllOptions;
|
||||
}
|
||||
|
||||
int FairMQProgOptions::PrintOptions()
|
||||
{
|
||||
// -> loop over variable map and print its content
|
||||
// -> In this example the following types are supported:
|
||||
// string, int, float, double, short, boost::filesystem::path
|
||||
// vector<string>, vector<int>, vector<float>, vector<double>, vector<short>
|
||||
|
||||
map<string, VarValInfo> mapinfo;
|
||||
|
||||
// get string length for formatting and convert varmap values into string
|
||||
int maxLenKey = 0;
|
||||
int maxLenValue = 0;
|
||||
int maxLenType = 0;
|
||||
int maxLenDefault = 0;
|
||||
|
||||
for (const auto& m : fVarMap)
|
||||
{
|
||||
maxLenKey = max(maxLenKey, static_cast<int>(m.first.length()));
|
||||
|
||||
VarValInfo valinfo = ConvertVariableValue<options::ToVarValInfo>()((m.second));
|
||||
mapinfo[m.first] = valinfo;
|
||||
|
||||
maxLenValue = max(maxLenValue, static_cast<int>(valinfo.value.length()));
|
||||
maxLenType = max(maxLenType, static_cast<int>(valinfo.type.length()));
|
||||
maxLenDefault = max(maxLenDefault, static_cast<int>(valinfo.defaulted.length()));
|
||||
}
|
||||
|
||||
// TODO : limit the value len field in a better way
|
||||
if (maxLenValue > 100)
|
||||
{
|
||||
maxLenValue = 100;
|
||||
}
|
||||
|
||||
for (const auto& o : fUnregisteredOptions)
|
||||
{
|
||||
LOG(WARN) << "detected unregistered option: " << o;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss << "Configuration: \n";
|
||||
|
||||
for (const auto& p : mapinfo)
|
||||
{
|
||||
ss << setfill(' ') << left
|
||||
<< setw(maxLenKey) << p.first << " = "
|
||||
<< setw(maxLenValue) << p.second.value
|
||||
<< setw(maxLenType) << p.second.type
|
||||
<< setw(maxLenDefault) << p.second.defaulted
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
LOG(info) << ss.str();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FairMQProgOptions::PrintOptionsRaw()
|
||||
{
|
||||
const vector<boost::shared_ptr<po::option_description>>& options = fAllOptions.options();
|
||||
|
||||
for (const auto& o : options)
|
||||
{
|
||||
VarValInfo value;
|
||||
if (fVarMap.count(o->canonical_display_name()))
|
||||
{
|
||||
value = ConvertVariableValue<options::ToVarValInfo>()((fVarMap[o->canonical_display_name()]));
|
||||
}
|
||||
|
||||
string description = o->description();
|
||||
|
||||
replace(description.begin(), description.end(), '\n', ' ');
|
||||
|
||||
cout << o->long_name() << ":" << value.value << ":" << (value.type == "" ? "<unknown>" : value.type) << ":" << description << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
string FairMQProgOptions::GetStringValue(const string& key)
|
||||
{
|
||||
unique_lock<mutex> lock(fConfigMutex);
|
||||
|
||||
string valueStr;
|
||||
try
|
||||
{
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
valueStr = ConvertVariableValue<options::ToString>()(fVarMap.at(key));
|
||||
}
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(error) << "Exception thrown for the key '" << key << "'";
|
||||
LOG(error) << e.what();
|
||||
}
|
||||
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
int FairMQProgOptions::Count(const string& key) const
|
||||
{
|
||||
unique_lock<mutex> lock(fConfigMutex);
|
||||
|
||||
return fVarMap.count(key);
|
||||
}
|
||||
|
|
|
@ -6,26 +6,22 @@
|
|||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
/*
|
||||
* File: FairMQProgOptions.h
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on March 11, 2015, 10:20 PM
|
||||
*/
|
||||
|
||||
#ifndef FAIRMQPROGOPTIONS_H
|
||||
#define FAIRMQPROGOPTIONS_H
|
||||
|
||||
#include <fairmq/EventManager.h>
|
||||
|
||||
#include "FairProgOptions.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQChannel.h"
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
|
@ -38,10 +34,10 @@ struct PropertyChangeAsString : Event<std::string> {};
|
|||
} /* namespace mq */
|
||||
} /* namespace fair */
|
||||
|
||||
class FairMQProgOptions : public FairProgOptions
|
||||
class FairMQProgOptions
|
||||
{
|
||||
protected:
|
||||
using FairMQMap = std::unordered_map<std::string, std::vector<FairMQChannel>>;
|
||||
private:
|
||||
using FairMQChannelMap = std::unordered_map<std::string, std::vector<FairMQChannel>>;
|
||||
|
||||
public:
|
||||
FairMQProgOptions();
|
||||
|
@ -49,52 +45,11 @@ class FairMQProgOptions : public FairProgOptions
|
|||
|
||||
int ParseAll(const std::vector<std::string>& cmdLineArgs, bool allowUnregistered);
|
||||
// parse command line.
|
||||
// default parser for the mq-configuration file (JSON/XML) is called if command line key mq-config is called
|
||||
int ParseAll(const int argc, char const* const* argv, bool allowUnregistered = false) override;
|
||||
// default parser for the mq-configuration file (JSON) is called if command line key mq-config is called
|
||||
int ParseAll(const int argc, char const* const* argv, bool allowUnregistered = true);
|
||||
|
||||
FairMQMap GetFairMQMap() const
|
||||
{
|
||||
return fFairMQMap;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, int> GetChannelInfo() const
|
||||
{
|
||||
return fChannelInfo;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int UpdateValue(const std::string& key, T val)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
// update variable map
|
||||
UpdateVarMap<typename std::decay<T>::type>(key, val);
|
||||
|
||||
// update FairMQChannel map, check first if data are int or string
|
||||
if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
|
||||
{
|
||||
if (fMQKeyMap.count(key))
|
||||
{
|
||||
UpdateChannelMap(fMQKeyMap.at(key).channel, fMQKeyMap.at(key).index, fMQKeyMap.at(key).member, val);
|
||||
}
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
//if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)//if one wants to restrict type
|
||||
fEvents.Emit<fair::mq::PropertyChange, typename std::decay<T>::type>(key, val);
|
||||
fEvents.Emit<fair::mq::PropertyChangeAsString, std::string>(key, GetStringValue(key));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "UpdateValue failed: key '" << key << "' not found in the variable map";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
FairMQChannelMap GetFairMQMap() const;
|
||||
std::unordered_map<std::string, int> GetChannelInfo() const;
|
||||
|
||||
template<typename T>
|
||||
int SetValue(const std::string& key, T val)
|
||||
|
@ -104,12 +59,12 @@ class FairMQProgOptions : public FairProgOptions
|
|||
// update variable map
|
||||
UpdateVarMap<typename std::decay<T>::type>(key, val);
|
||||
|
||||
// update FairMQChannel map, check first if data are int or string
|
||||
// update FairMQChannel map if the key is a channel key
|
||||
if (std::is_same<T, int>::value || std::is_same<T, std::string>::value)
|
||||
{
|
||||
if (fMQKeyMap.count(key))
|
||||
if (fChannelKeyMap.count(key))
|
||||
{
|
||||
UpdateChannelMap(fMQKeyMap.at(key).channel, fMQKeyMap.at(key).index, fMQKeyMap.at(key).member, val);
|
||||
UpdateChannelValue(fChannelKeyMap.at(key).channel, fChannelKeyMap.at(key).index, fChannelKeyMap.at(key).member, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,57 +110,114 @@ class FairMQProgOptions : public FairProgOptions
|
|||
fEvents.Unsubscribe<fair::mq::PropertyChangeAsString, std::string>(subscriber);
|
||||
}
|
||||
|
||||
// replace FairMQChannelMap, and update variable map accordingly
|
||||
int UpdateChannelMap(const FairMQMap& map);
|
||||
std::vector<std::string> GetPropertyKeys() const;
|
||||
|
||||
protected:
|
||||
struct MQKey
|
||||
// get value corresponding to the key
|
||||
template<typename T>
|
||||
T GetValue(const std::string& key) const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
T val = T();
|
||||
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
val = fVarMap[key].as<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(warn) << "Config has no key: " << key << ". Returning default constructed object.";
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
// Given a key, convert the variable value to string
|
||||
std::string GetStringValue(const std::string& key);
|
||||
|
||||
int Count(const std::string& key) const;
|
||||
|
||||
template<typename T>
|
||||
T ConvertTo(const std::string& strValue)
|
||||
{
|
||||
if (std::is_arithmetic<T>::value)
|
||||
{
|
||||
std::istringstream iss(strValue);
|
||||
T val;
|
||||
iss >> val;
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "the provided string " << strValue << " cannot be converted to the requested type. The target type must be arithmetic type.";
|
||||
}
|
||||
}
|
||||
|
||||
// add options_description
|
||||
int AddToCmdLineOptions(const boost::program_options::options_description optDesc, bool visible = true);
|
||||
boost::program_options::options_description& GetCmdLineOptions();
|
||||
|
||||
const boost::program_options::variables_map& GetVarMap() const { return fVarMap; }
|
||||
|
||||
int PrintOptions();
|
||||
int PrintOptionsRaw();
|
||||
|
||||
private:
|
||||
struct ChannelKey
|
||||
{
|
||||
std::string channel;
|
||||
int index;
|
||||
std::string member;
|
||||
};
|
||||
|
||||
po::options_description fMQCmdOptions;
|
||||
po::options_description fMQParserOptions;
|
||||
FairMQMap fFairMQMap;
|
||||
boost::program_options::variables_map fVarMap; ///< options container
|
||||
FairMQChannelMap fFairMQChannelMap;
|
||||
|
||||
// map of read channel info - channel name - number of subchannels
|
||||
std::unordered_map<std::string, int> fChannelInfo;
|
||||
boost::program_options::options_description fAllOptions; ///< all options descriptions
|
||||
boost::program_options::options_description fGeneralOptions; ///< general options descriptions
|
||||
boost::program_options::options_description fMQOptions; ///< MQ options descriptions
|
||||
boost::program_options::options_description fParserOptions; ///< MQ Parser options descriptions
|
||||
|
||||
std::map<std::string, MQKey> fMQKeyMap;// key=full path - val=key info
|
||||
mutable std::mutex fConfigMutex;
|
||||
|
||||
int ImmediateOptions() override; // for custom help & version printing
|
||||
void InitOptionDescription();
|
||||
std::unordered_map<std::string, int> fChannelInfo; ///< channel name - number of subchannels
|
||||
std::unordered_map<std::string, ChannelKey> fChannelKeyMap;// key=full path - val=key info
|
||||
std::vector<std::string> fUnregisteredOptions; ///< container with unregistered options
|
||||
|
||||
fair::mq::EventManager fEvents;
|
||||
|
||||
void ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered = true);
|
||||
void ParseDefaults();
|
||||
|
||||
// read FairMQChannelMap and insert/update corresponding values in variable map
|
||||
// create key for variable map as follow : channelName.index.memberName
|
||||
void UpdateMQValues();
|
||||
int Store(const FairMQMap& channels);
|
||||
int Store(const FairMQChannelMap& channels);
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
void EmitUpdate(const std::string& key, T val)
|
||||
{
|
||||
//compile time check whether T is const char* or char*, and in that case a compile time error is thrown.
|
||||
// compile time check whether T is const char* or char*, and in that case a compile time error is thrown.
|
||||
static_assert(!std::is_same<T,const char*>::value || !std::is_same<T, char*>::value,
|
||||
"In template member FairMQProgOptions::EmitUpdate<T>(key,val) the types const char* or char* for the calback signatures are not supported.");
|
||||
fEvents.Emit<fair::mq::PropertyChange, T>(key, val);
|
||||
fEvents.Emit<fair::mq::PropertyChangeAsString, std::string>(key, GetStringValue(key));
|
||||
}
|
||||
|
||||
int UpdateChannelMap(const std::string& channelName, int index, const std::string& member, const std::string& val);
|
||||
int UpdateChannelMap(const std::string& channelName, int index, const std::string& member, int val);
|
||||
// for cases other than int and string
|
||||
template<typename T>
|
||||
int UpdateChannelMap(const std::string& /*channelName*/, int /*index*/, const std::string& /*member*/, T /*val*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int UpdateChannelMap(const FairMQChannelMap& map);
|
||||
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, const std::string& val);
|
||||
int UpdateChannelValue(const std::string& channelName, int index, const std::string& member, int val);
|
||||
|
||||
void UpdateChannelInfo();
|
||||
|
||||
fair::mq::EventManager fEvents;
|
||||
// helper to modify the value of variable map after calling boost::program_options::store
|
||||
template<typename T>
|
||||
void UpdateVarMap(const std::string& key, const T& val)
|
||||
{
|
||||
std::map<std::string, boost::program_options::variable_value>& vm = fVarMap;
|
||||
vm[key].value() = boost::any(val);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* FAIRMQPROGOPTIONS_H */
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace parser
|
|||
|
||||
constexpr const char* SUBOPT::channelOptionKeys[];
|
||||
|
||||
FairMQMap SUBOPT::UserParser(const vector<string>& channelConfig, const string& deviceId, const string& rootNode)
|
||||
FairMQChannelMap SUBOPT::UserParser(const vector<string>& channelConfig, const string& deviceId, const string& rootNode)
|
||||
{
|
||||
ptree pt;
|
||||
|
||||
|
|
|
@ -14,14 +14,12 @@
|
|||
#ifndef FAIRMQPARSER_SUBOPT_H
|
||||
#define FAIRMQPARSER_SUBOPT_H
|
||||
|
||||
#include "FairMQParser.h" // for FairMQMap
|
||||
#include "FairMQParser.h" // for FairMQChannelMap
|
||||
#include <boost/program_options.hpp>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
|
@ -78,7 +76,7 @@ struct SUBOPT
|
|||
nullptr
|
||||
};
|
||||
|
||||
FairMQMap UserParser(const std::vector<std::string>& channelConfig, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
FairMQChannelMap UserParser(const std::vector<std::string>& channelConfig, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/*
|
||||
* File: FairProgOptions.cxx
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on March 11, 2015, 5:38 PM
|
||||
*/
|
||||
|
||||
#include "FairProgOptions.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace fair::mq;
|
||||
|
||||
FairProgOptions::FairProgOptions()
|
||||
: fVarMap()
|
||||
, fGeneralOptions("General options")
|
||||
, fAllOptions("Command line options")
|
||||
, fConfigMutex()
|
||||
{
|
||||
fGeneralOptions.add_options()
|
||||
("help,h", "produce help")
|
||||
("version,v", "print version")
|
||||
("severity", po::value<string>()->default_value("debug"), "Log severity level: trace, debug, info, state, warn, error, fatal, nolog")
|
||||
("verbosity", po::value<string>()->default_value("medium"), "Log verbosity level: veryhigh, high, medium, low")
|
||||
("color", po::value<bool>()->default_value(true), "Log color (true/false)")
|
||||
("log-to-file", po::value<string>()->default_value(""), "Log output to a file.")
|
||||
("print-options", po::value<bool>()->implicit_value(true), "print options in machine-readable format (<option>:<computed-value>:<type>:<description>)");
|
||||
|
||||
fAllOptions.add(fGeneralOptions);
|
||||
}
|
||||
|
||||
FairProgOptions::~FairProgOptions()
|
||||
{
|
||||
}
|
||||
|
||||
/// Add option descriptions
|
||||
int FairProgOptions::AddToCmdLineOptions(const po::options_description optDesc, bool /* visible */)
|
||||
{
|
||||
fAllOptions.add(optDesc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
po::options_description& FairProgOptions::GetCmdLineOptions()
|
||||
{
|
||||
return fAllOptions;
|
||||
}
|
||||
|
||||
int FairProgOptions::ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered)
|
||||
{
|
||||
// get options from cmd line and store in variable map
|
||||
// here we use command_line_parser instead of parse_command_line, to allow unregistered and positional options
|
||||
if (allowUnregistered)
|
||||
{
|
||||
po::command_line_parser parser{argc, argv};
|
||||
parser.options(fAllOptions).allow_unregistered();
|
||||
po::parsed_options parsedOptions = parser.run();
|
||||
po::store(parsedOptions, fVarMap);
|
||||
}
|
||||
else
|
||||
{
|
||||
po::store(po::parse_command_line(argc, argv, fAllOptions), fVarMap);
|
||||
}
|
||||
|
||||
// Handles options like "--help" or "--version"
|
||||
// return 1 if switch options found in fVarMap
|
||||
if (ImmediateOptions())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
po::notify(fVarMap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FairProgOptions::ParseDefaults()
|
||||
{
|
||||
vector<string> emptyArgs;
|
||||
emptyArgs.push_back("dummy");
|
||||
|
||||
vector<const char*> argv(emptyArgs.size());
|
||||
|
||||
transform(emptyArgs.begin(), emptyArgs.end(), argv.begin(), [](const string& str)
|
||||
{
|
||||
return str.c_str();
|
||||
});
|
||||
|
||||
po::store(po::parse_command_line(argv.size(), const_cast<char**>(argv.data()), fAllOptions), fVarMap);
|
||||
}
|
||||
|
||||
int FairProgOptions::PrintOptions()
|
||||
{
|
||||
// -> loop over variable map and print its content
|
||||
// -> In this example the following types are supported:
|
||||
// string, int, float, double, short, boost::filesystem::path
|
||||
// vector<string>, vector<int>, vector<float>, vector<double>, vector<short>
|
||||
|
||||
map<string, VarValInfo> mapinfo;
|
||||
|
||||
// get string length for formatting and convert varmap values into string
|
||||
int maxLen1st = 0;
|
||||
int maxLen2nd = 0;
|
||||
int maxLenTypeInfo = 0;
|
||||
int maxLenDefault = 0;
|
||||
int maxLenEmpty = 0;
|
||||
for (const auto& m : fVarMap)
|
||||
{
|
||||
Max(maxLen1st, m.first.length());
|
||||
|
||||
VarValInfo valinfo = GetVariableValueInfo(m.second);
|
||||
mapinfo[m.first] = valinfo;
|
||||
|
||||
Max(maxLen2nd, valinfo.value.length());
|
||||
Max(maxLenTypeInfo, valinfo.type.length());
|
||||
Max(maxLenDefault, valinfo.defaulted.length());
|
||||
Max(maxLenEmpty, valinfo.empty.length());
|
||||
}
|
||||
|
||||
// TODO : limit the value len field in a better way
|
||||
if (maxLen2nd > 100)
|
||||
{
|
||||
maxLen2nd = 100;
|
||||
}
|
||||
|
||||
stringstream ss;
|
||||
ss << "Configuration: \n";
|
||||
|
||||
for (const auto& p : mapinfo)
|
||||
{
|
||||
ss << setfill(' ')
|
||||
<< setw(maxLen1st) << left << p.first << " = "
|
||||
<< setw(maxLen2nd) << p.second.value
|
||||
<< setw(maxLenTypeInfo) << p.second.type
|
||||
<< setw(maxLenDefault) << p.second.defaulted
|
||||
<< setw(maxLenEmpty) << p.second.empty
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
LOG(info) << ss.str();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FairProgOptions::PrintOptionsRaw()
|
||||
{
|
||||
const std::vector<boost::shared_ptr<po::option_description>>& options = fAllOptions.options();
|
||||
|
||||
for (const auto& o : options)
|
||||
{
|
||||
VarValInfo value;
|
||||
if (fVarMap.count(o->canonical_display_name()))
|
||||
{
|
||||
value = GetVariableValueInfo(fVarMap[o->canonical_display_name()]);
|
||||
}
|
||||
|
||||
string description = o->description();
|
||||
|
||||
replace(description.begin(), description.end(), '\n', ' ');
|
||||
|
||||
cout << o->long_name() << ":" << value.value << ":" << (value.type == "" ? "<unknown>" : value.type) << ":" << description << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VarValInfo FairProgOptions::GetVariableValueInfo(const po::variable_value& varValue)
|
||||
{
|
||||
return ConvertVariableValue<ToVarValInfo>()(varValue);
|
||||
}
|
|
@ -1,172 +1 @@
|
|||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
/*
|
||||
* File: FairProgOptions.h
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on March 11, 2015, 5:38 PM
|
||||
*/
|
||||
|
||||
#ifndef FAIRPROGOPTIONS_H
|
||||
#define FAIRPROGOPTIONS_H
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairProgOptionsHelper.h"
|
||||
#include <fairmq/Tools.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
#include <exception>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
class FairProgOptions
|
||||
{
|
||||
public:
|
||||
FairProgOptions();
|
||||
virtual ~FairProgOptions();
|
||||
|
||||
auto GetPropertyKeys() const -> std::vector<std::string>
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{fConfigMutex};
|
||||
|
||||
std::vector<std::string> result;
|
||||
|
||||
for (const auto& it : fVarMap)
|
||||
{
|
||||
result.push_back(it.first.c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// add options_description
|
||||
int AddToCmdLineOptions(const po::options_description optDesc, bool visible = true);
|
||||
po::options_description& GetCmdLineOptions();
|
||||
|
||||
// get value corresponding to the key
|
||||
template<typename T>
|
||||
T GetValue(const std::string& key) const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
T val = T();
|
||||
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
val = fVarMap[key].as<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(warn) << "Config has no key: " << key << ". Returning default constructed object.";
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
// Given a key, convert the variable value to string
|
||||
std::string GetStringValue(const std::string& key)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
std::string valueStr;
|
||||
try
|
||||
{
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
valueStr = fair::mq::ConvertVariableValue<fair::mq::VarInfoToString>()(fVarMap.at(key));
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG(error) << "Exception thrown for the key '" << key << "'";
|
||||
LOG(error) << e.what();
|
||||
}
|
||||
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
int Count(const std::string& key) const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(fConfigMutex);
|
||||
|
||||
return fVarMap.count(key);
|
||||
}
|
||||
|
||||
//restrict conversion to fundamental types
|
||||
template<typename T>
|
||||
T ConvertTo(const std::string& strValue)
|
||||
{
|
||||
if (std::is_arithmetic<T>::value)
|
||||
{
|
||||
std::istringstream iss(strValue);
|
||||
T val;
|
||||
iss >> val;
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(error) << "the provided string " << strValue << " cannot be converted in the requested type. The target types must be arithmetic types";
|
||||
}
|
||||
}
|
||||
|
||||
const po::variables_map& GetVarMap() const { return fVarMap; }
|
||||
|
||||
int ParseCmdLine(const int argc, char const* const* argv, bool allowUnregistered = false);
|
||||
void ParseDefaults();
|
||||
|
||||
virtual int ParseAll(const int argc, char const* const* argv, bool allowUnregistered = false) = 0;
|
||||
|
||||
virtual int PrintOptions();
|
||||
virtual int PrintOptionsRaw();
|
||||
|
||||
protected:
|
||||
// options container
|
||||
po::variables_map fVarMap;
|
||||
|
||||
// options descriptions
|
||||
po::options_description fGeneralOptions;
|
||||
po::options_description fAllOptions;
|
||||
|
||||
mutable std::mutex fConfigMutex;
|
||||
|
||||
virtual int ImmediateOptions() = 0;
|
||||
|
||||
// UpdateVarMap() and Replace() --> helper functions to modify the value of variable map after calling po::store
|
||||
template<typename T>
|
||||
void UpdateVarMap(const std::string& key, const T& val)
|
||||
{
|
||||
Replace(fVarMap, key, val);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Replace(std::map<std::string, po::variable_value>& vm, const std::string& key, const T& val)
|
||||
{
|
||||
vm[key].value() = boost::any(val);
|
||||
}
|
||||
|
||||
private:
|
||||
fair::mq::VarValInfo GetVariableValueInfo(const po::variable_value& varValue);
|
||||
|
||||
static void Max(int& val, const int& comp)
|
||||
{
|
||||
if (comp > val)
|
||||
{
|
||||
val = comp;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FAIRPROGOPTIONS_H */
|
||||
#warning "This header file is deprecated. Use FairMQProgOptions class directly which now contains all FairProgOptions functionality. Note, that FairMQProgOptions is also available if you include FairMQDevice."
|
||||
|
|
|
@ -17,211 +17,171 @@
|
|||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/spirit/home/support/detail/hold_any.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <iterator>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace fair
|
||||
{
|
||||
namespace mq
|
||||
{
|
||||
|
||||
template<class T>
|
||||
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
|
||||
{
|
||||
for (const auto& i : v)
|
||||
{
|
||||
os << i << " ";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
struct VarValInfo
|
||||
{
|
||||
std::string value;
|
||||
std::string type;
|
||||
std::string defaulted;
|
||||
std::string empty;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
|
||||
{
|
||||
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(os, " "));
|
||||
return os;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool typeIs(const boost::program_options::variable_value& varValue)
|
||||
std::string ConvertVariableValueToString(const boost::program_options::variable_value& varVal)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
if (auto q = boost::any_cast<T>(&value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
std::ostringstream oss;
|
||||
if (auto q = boost::any_cast<T>(&varVal.value())) {
|
||||
oss << *q;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string ConvertVariableValueToString(const boost::program_options::variable_value& varValue)
|
||||
namespace options
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::ostringstream ostr;
|
||||
if (auto q = boost::any_cast<T>(&value))
|
||||
{
|
||||
ostr << *q;
|
||||
}
|
||||
std::string valueStr = ostr.str();
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
// string specialization
|
||||
template<>
|
||||
inline std::string ConvertVariableValueToString<std::string>(const boost::program_options::variable_value& varValue)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::string valueStr;
|
||||
if (auto q = boost::any_cast<std::string>(&value))
|
||||
{
|
||||
valueStr = *q;
|
||||
}
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
// boost::filesystem::path specialization
|
||||
template<>
|
||||
inline std::string ConvertVariableValueToString<boost::filesystem::path>(const boost::program_options::variable_value& varValue)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::string valueStr;
|
||||
if (auto q = boost::any_cast<boost::filesystem::path>(&value))
|
||||
{
|
||||
valueStr = (*q).string();
|
||||
}
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
// policy to convert boost variable value into string
|
||||
struct VarInfoToString
|
||||
struct ToString
|
||||
{
|
||||
using returned_type = std::string;
|
||||
|
||||
template<typename T>
|
||||
std::string Value(const boost::program_options::variable_value& varValue, const std::string&, const std::string&, const std::string&)
|
||||
std::string Value(const boost::program_options::variable_value& varVal, const std::string&, const std::string&)
|
||||
{
|
||||
return ConvertVariableValueToString<T>(varValue);
|
||||
return ConvertVariableValueToString<T>(varVal);
|
||||
}
|
||||
|
||||
returned_type DefaultValue(const std::string&, const std::string&)
|
||||
returned_type DefaultValue(const std::string&)
|
||||
{
|
||||
return std::string("empty value");
|
||||
return std::string("[unidentified]");
|
||||
}
|
||||
};
|
||||
|
||||
// policy to convert variable value content into VarValInfo
|
||||
struct ToVarValInfo
|
||||
{
|
||||
using returned_type = fair::mq::VarValInfo;
|
||||
using returned_type = VarValInfo;
|
||||
|
||||
template<typename T>
|
||||
returned_type Value(const boost::program_options::variable_value& varValue, const std::string& type, const std::string& defaulted, const std::string& empty)
|
||||
returned_type Value(const boost::program_options::variable_value& varVal, const std::string& type, const std::string& defaulted)
|
||||
{
|
||||
std::string valueStr = ConvertVariableValueToString<T>(varValue);
|
||||
return fair::mq::VarValInfo{valueStr, type, defaulted, empty};
|
||||
return VarValInfo{ConvertVariableValueToString<T>(varVal), type, defaulted};
|
||||
}
|
||||
|
||||
returned_type DefaultValue(const std::string& defaulted, const std::string& empty)
|
||||
returned_type DefaultValue(const std::string& defaulted)
|
||||
{
|
||||
return fair::mq::VarValInfo{std::string("Unknown value"), std::string(" [Unknown]"), defaulted, empty};
|
||||
return VarValInfo{std::string("[unidentified]"), std::string("[unidentified]"), defaulted};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace options
|
||||
|
||||
// host class that take one of the two policy defined above
|
||||
template<typename T>
|
||||
struct ConvertVariableValue : T
|
||||
{
|
||||
auto operator()(const boost::program_options::variable_value& varValue) -> typename T::returned_type
|
||||
auto operator()(const boost::program_options::variable_value& varVal) -> typename T::returned_type
|
||||
{
|
||||
std::string defaulted;
|
||||
std::string empty;
|
||||
|
||||
if (varValue.empty())
|
||||
if (varVal.defaulted())
|
||||
{
|
||||
empty = " [empty]";
|
||||
defaulted = " [default]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (varValue.defaulted())
|
||||
{
|
||||
defaulted = " [default]";
|
||||
}
|
||||
else
|
||||
{
|
||||
defaulted = " [provided]";
|
||||
}
|
||||
defaulted = " [provided]";
|
||||
}
|
||||
|
||||
if (typeIs<std::string>(varValue))
|
||||
return T::template Value<std::string>(varValue, std::string("<string>"), defaulted, empty);
|
||||
if (typeid(std::string) == varVal.value().type())
|
||||
return T::template Value<std::string>(varVal, std::string("<string>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<std::string>>(varValue))
|
||||
return T::template Value<std::vector<std::string>>(varValue, std::string("<vector<string>>"), defaulted, empty);
|
||||
if (typeid(std::vector<std::string>) == varVal.value().type())
|
||||
return T::template Value<std::vector<std::string>>(varVal, std::string("<vector<string>>"), defaulted);
|
||||
|
||||
if (typeIs<int>(varValue))
|
||||
return T::template Value<int>(varValue, std::string("<int>"), defaulted, empty);
|
||||
if (typeid(int) == varVal.value().type())
|
||||
return T::template Value<int>(varVal, std::string("<int>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<int>>(varValue))
|
||||
return T::template Value<std::vector<int>>(varValue, std::string("<vector<int>>"), defaulted, empty);
|
||||
if (typeid(std::vector<int>) == varVal.value().type())
|
||||
return T::template Value<std::vector<int>>(varVal, std::string("<vector<int>>"), defaulted);
|
||||
|
||||
if (typeIs<float>(varValue))
|
||||
return T::template Value<float>(varValue, std::string("<float>"), defaulted, empty);
|
||||
if (typeid(float) == varVal.value().type())
|
||||
return T::template Value<float>(varVal, std::string("<float>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<float>>(varValue))
|
||||
return T::template Value<std::vector<float>>(varValue, std::string("<vector<float>>"), defaulted, empty);
|
||||
if (typeid(std::vector<float>) == varVal.value().type())
|
||||
return T::template Value<std::vector<float>>(varVal, std::string("<vector<float>>"), defaulted);
|
||||
|
||||
if (typeIs<double>(varValue))
|
||||
return T::template Value<double>(varValue, std::string("<double>"), defaulted, empty);
|
||||
if (typeid(double) == varVal.value().type())
|
||||
return T::template Value<double>(varVal, std::string("<double>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<double>>(varValue))
|
||||
return T::template Value<std::vector<double>>(varValue, std::string("<vector<double>>"), defaulted, empty);
|
||||
if (typeid(std::vector<double>) == varVal.value().type())
|
||||
return T::template Value<std::vector<double>>(varVal, std::string("<vector<double>>"), defaulted);
|
||||
|
||||
if (typeIs<short>(varValue))
|
||||
return T::template Value<short>(varValue, std::string("<short>"), defaulted, empty);
|
||||
if (typeid(short) == varVal.value().type())
|
||||
return T::template Value<short>(varVal, std::string("<short>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<short>>(varValue))
|
||||
return T::template Value<std::vector<short>>(varValue, std::string("<vector<short>>"), defaulted, empty);
|
||||
if (typeid(std::vector<short>) == varVal.value().type())
|
||||
return T::template Value<std::vector<short>>(varVal, std::string("<vector<short>>"), defaulted);
|
||||
|
||||
if (typeIs<long>(varValue))
|
||||
return T::template Value<long>(varValue, std::string("<long>"), defaulted, empty);
|
||||
if (typeid(long) == varVal.value().type())
|
||||
return T::template Value<long>(varVal, std::string("<long>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<long>>(varValue))
|
||||
return T::template Value<std::vector<long>>(varValue, std::string("<vector<long>>"), defaulted, empty);
|
||||
if (typeid(std::vector<long>) == varVal.value().type())
|
||||
return T::template Value<std::vector<long>>(varVal, std::string("<vector<long>>"), defaulted);
|
||||
|
||||
if (typeIs<std::size_t>(varValue))
|
||||
return T::template Value<std::size_t>(varValue, std::string("<std::size_t>"), defaulted, empty);
|
||||
if (typeid(std::size_t) == varVal.value().type())
|
||||
return T::template Value<std::size_t>(varVal, std::string("<std::size_t>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<std::size_t>>(varValue))
|
||||
return T::template Value<std::vector<std::size_t>>(varValue, std::string("<vector<std::size_t>>"), defaulted, empty);
|
||||
if (typeid(std::vector<std::size_t>) == varVal.value().type())
|
||||
return T::template Value<std::vector<std::size_t>>(varVal, std::string("<vector<std::size_t>>"), defaulted);
|
||||
|
||||
if (typeIs<std::uint32_t>(varValue))
|
||||
return T::template Value<std::uint32_t>(varValue, std::string("<std::uint32_t>"), defaulted, empty);
|
||||
if (typeid(std::uint32_t) == varVal.value().type())
|
||||
return T::template Value<std::uint32_t>(varVal, std::string("<std::uint32_t>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<std::uint32_t>>(varValue))
|
||||
return T::template Value<std::vector<std::uint32_t>>(varValue, std::string("<vector<std::uint32_t>>"), defaulted, empty);
|
||||
if (typeid(std::vector<std::uint32_t>) == varVal.value().type())
|
||||
return T::template Value<std::vector<std::uint32_t>>(varVal, std::string("<vector<std::uint32_t>>"), defaulted);
|
||||
|
||||
if (typeIs<std::uint64_t>(varValue))
|
||||
return T::template Value<std::uint64_t>(varValue, std::string("<std::uint64_t>"), defaulted, empty);
|
||||
if (typeid(std::uint64_t) == varVal.value().type())
|
||||
return T::template Value<std::uint64_t>(varVal, std::string("<std::uint64_t>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<std::uint64_t>>(varValue))
|
||||
return T::template Value<std::vector<std::uint64_t>>(varValue, std::string("<vector<std::uint64_t>>"), defaulted, empty);
|
||||
if (typeid(std::vector<std::uint64_t>) == varVal.value().type())
|
||||
return T::template Value<std::vector<std::uint64_t>>(varVal, std::string("<vector<std::uint64_t>>"), defaulted);
|
||||
|
||||
if (typeIs<bool>(varValue))
|
||||
return T::template Value<bool>(varValue, std::string("<bool>"), defaulted, empty);
|
||||
if (typeid(bool) == varVal.value().type())
|
||||
return T::template Value<bool>(varVal, std::string("<bool>"), defaulted);
|
||||
|
||||
if (typeIs<std::vector<bool>>(varValue))
|
||||
return T::template Value<std::vector<bool>>(varValue, std::string("<vector<bool>>"), defaulted, empty);
|
||||
if (typeid(std::vector<bool>) == varVal.value().type())
|
||||
return T::template Value<std::vector<bool>>(varVal, std::string("<vector<bool>>"), defaulted);
|
||||
|
||||
if (typeIs<boost::filesystem::path>(varValue))
|
||||
return T::template Value<boost::filesystem::path>(varValue, std::string("<boost::filesystem::path>"), defaulted, empty);
|
||||
if (typeid(boost::filesystem::path) == varVal.value().type())
|
||||
return T::template Value<boost::filesystem::path>(varVal, std::string("<boost::filesystem::path>"), defaulted);
|
||||
|
||||
if (typeid(std::vector<boost::filesystem::path>) == varVal.value().type())
|
||||
return T::template Value<std::vector<boost::filesystem::path>>(varVal, std::string("<std::vector<boost::filesystem::path>>"), defaulted);
|
||||
|
||||
// if we get here, the type is not supported return unknown info
|
||||
return T::DefaultValue(defaulted, empty);
|
||||
return T::DefaultValue(defaulted);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
################################################################################
|
||||
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
|
||||
# #
|
||||
# This software is distributed under the terms of the #
|
||||
# GNU Lesser General Public Licence (LGPL) version 3, #
|
||||
# copied verbatim in the file "LICENSE" #
|
||||
################################################################################
|
||||
# Create a library called "ProgOptionTest"
|
||||
|
||||
# Test fair-prog-opt
|
||||
|
||||
# scripts
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testMQOptions1.sh.in ${CMAKE_BINARY_DIR}/bin/testMQOptions1.sh )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testMQOptions2.sh.in ${CMAKE_BINARY_DIR}/bin/testMQOptions2.sh )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testMQOptions3.sh.in ${CMAKE_BINARY_DIR}/bin/testMQOptions3.sh )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testMQOptions4.sh.in ${CMAKE_BINARY_DIR}/bin/testMQOptions4.sh )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testMQOptions5.sh.in ${CMAKE_BINARY_DIR}/bin/testMQOptions5.sh )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/start-bsampler-sink.sh.in ${CMAKE_BINARY_DIR}/bin/start-bsampler-sink.sh )
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${CMAKE_BINARY_DIR}/bin/testMQOptions1.sh")
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${CMAKE_BINARY_DIR}/bin/testMQOptions2.sh")
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${CMAKE_BINARY_DIR}/bin/testMQOptions3.sh")
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${CMAKE_BINARY_DIR}/bin/testMQOptions4.sh")
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${CMAKE_BINARY_DIR}/bin/testMQOptions5.sh")
|
||||
EXEC_PROGRAM(/bin/chmod ARGS "u+x ${CMAKE_BINARY_DIR}/bin/start-bsampler-sink.sh")
|
||||
|
||||
# Config/xml/json example file
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/ConfigFileTest.cfg.in ${CMAKE_BINARY_DIR}/bin/ConfigFileTest.cfg)
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testXML.xml ${CMAKE_BINARY_DIR}/bin/testXML.xml )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/testJSON.json ${CMAKE_BINARY_DIR}/bin/testJSON.json )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/bsampler-sink.json ${CMAKE_BINARY_DIR}/bin/bsampler-sink.json )
|
||||
|
||||
|
||||
|
||||
set(INCLUDE_DIRECTORIES
|
||||
${CMAKE_SOURCE_DIR}/fairmq
|
||||
${CMAKE_SOURCE_DIR}/fairmq/options
|
||||
${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/lib
|
||||
${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/run
|
||||
)
|
||||
|
||||
Set(SYSTEM_INCLUDE_DIRECTORIES
|
||||
${SYSTEM_INCLUDE_DIRECTORIES}
|
||||
)
|
||||
|
||||
include_directories(${INCLUDE_DIRECTORIES})
|
||||
include_directories(${SYSTEM_INCLUDE_DIRECTORIES})
|
||||
|
||||
set(LINK_DIRECTORIES
|
||||
${Boost_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
link_directories(${LINK_DIRECTORIES})
|
||||
|
||||
Set(SRCS
|
||||
lib/FairMQParserExample.cxx
|
||||
)
|
||||
|
||||
Set(LIBRARY_NAME ProgOptionTest)
|
||||
|
||||
If (Boost_FOUND)
|
||||
Set(DEPENDENCIES
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||
FairMQ
|
||||
)
|
||||
EndIf (Boost_FOUND)
|
||||
|
||||
GENERATE_LIBRARY()
|
||||
|
||||
|
||||
If (Boost_FOUND)
|
||||
Set(Exe_Names
|
||||
runtestMQOption1
|
||||
runtestMQOption2
|
||||
runOptTestSampler
|
||||
runOptTestSink
|
||||
)
|
||||
|
||||
|
||||
set(Exe_Source
|
||||
run/testMQoptions1.cxx
|
||||
run/testMQoptions2.cxx
|
||||
run/runOptTestSampler.cxx
|
||||
run/runOptTestSink.cxx
|
||||
)
|
||||
|
||||
List(LENGTH Exe_Names _length)
|
||||
Math(EXPR _length ${_length}-1)
|
||||
|
||||
ForEach(_file RANGE 0 ${_length})
|
||||
List(GET Exe_Names ${_file} _name)
|
||||
List(GET Exe_Source ${_file} _src)
|
||||
Set(EXE_NAME ${_name})
|
||||
Set(SRCS ${_src})
|
||||
Set(DEPENDENCIES ProgOptionTest)
|
||||
GENERATE_EXECUTABLE()
|
||||
EndForEach(_file RANGE 0 ${_length})
|
||||
EndIf (Boost_FOUND)
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* File: FairMQParserExample.cxx
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on May 14, 2015, 5:01 PM
|
||||
*/
|
||||
|
||||
#include "FairMQParserExample.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
|
||||
|
||||
namespace FairMQParser
|
||||
{
|
||||
|
||||
// other xml examples
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
boost::property_tree::ptree MQXML2::UserParser(const std::string& filename)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(filename, pt);
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO : finish implementation
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
boost::property_tree::ptree MQXML3::UserParser(const std::string& filename, const std::string& devicename)
|
||||
{
|
||||
// Create an empty property tree object
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(filename, pt);
|
||||
|
||||
|
||||
// Create fair mq map
|
||||
|
||||
auto xml = pt.get_child("");
|
||||
std::vector<std::pair<std::string, boost::property_tree::ptree>> match;
|
||||
std::pair<std::string, boost::property_tree::ptree> device_match;
|
||||
|
||||
ProcessTree(xml.begin (), xml.end (), std::back_inserter(match),
|
||||
[] (const std::string& key) { return key == "device"; });
|
||||
|
||||
|
||||
// for each device
|
||||
for (const auto& pair: match)
|
||||
{
|
||||
if(pair.second.get<std::string>("<xmlattr>.name") == devicename)
|
||||
{
|
||||
device_match=pair;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//match.erase(std::remove(match.begin(), match.end(), pair), match.end());
|
||||
continue;
|
||||
}
|
||||
|
||||
//std::cout << "pair.first " << pair.first << std::endl;//device
|
||||
//std::cout << "\t node = " << pair.first
|
||||
// << "\t name = " << pair.second.get<std::string>("<xmlattr>.name")
|
||||
// << "\t id = " << pair.second.get<std::string>("<xmlattr>.id");
|
||||
//std::cout<<std::endl;
|
||||
}
|
||||
|
||||
return device_match.second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // end FairMQParser namespace
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* File: FairMQParserExample.h
|
||||
* Author: winckler
|
||||
*
|
||||
* Created on May 14, 2015, 5:01 PM
|
||||
*/
|
||||
|
||||
#ifndef FAIRMQPARSEREXAMPLE_H
|
||||
#define FAIRMQPARSEREXAMPLE_H
|
||||
|
||||
// FairRoot
|
||||
#include "FairMQChannel.h"
|
||||
#include "FairMQParser.h"
|
||||
|
||||
// Boost
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
// std
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace FairMQParser
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////// XML ////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// xml example 2
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
struct MQXML2
|
||||
{
|
||||
boost::property_tree::ptree UserParser(const std::string& filename);
|
||||
};
|
||||
|
||||
// xml example 3
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
struct MQXML3
|
||||
{
|
||||
boost::property_tree::ptree UserParser(const std::string& filename, const std::string& root_node);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// template function iterating over the whole boost property tree
|
||||
template <typename Input_tree_It, typename Output_tree_It, typename Compare_key>
|
||||
void ProcessTree(Input_tree_It first, Input_tree_It last, Output_tree_It dest, Compare_key compare)
|
||||
{
|
||||
//typedef typename std::iterator_traits<Input_tree_It>::reference reference;
|
||||
|
||||
if (first == last)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto begin = first->second.begin ();
|
||||
auto end = first->second.end ();
|
||||
|
||||
if (begin != end)
|
||||
{
|
||||
ProcessTree (begin, end, dest, compare);
|
||||
}
|
||||
|
||||
if (compare (first->first))
|
||||
{
|
||||
dest = *first;
|
||||
}
|
||||
|
||||
ProcessTree (++first, last, dest, compare);
|
||||
}
|
||||
|
||||
class no_id_exception: public std::exception
|
||||
{
|
||||
virtual const char* what() const throw()
|
||||
{
|
||||
return "Empty string for the device-id in FairMQParser::ptreeToMQMap(...) function";
|
||||
}
|
||||
};
|
||||
|
||||
} // end FairMQParser namespace
|
||||
#endif /* FAIRMQPARSEREXAMPLE_H */
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#----------------------------------------------------
|
||||
# comments :
|
||||
# brackets [] are used to group options. For example :
|
||||
#
|
||||
# [xml.config]
|
||||
# node.root = fairMQOptions
|
||||
#
|
||||
# is equivalent to
|
||||
# xml.config.node.root = fairMQOptions
|
||||
#----------------------------------------------------
|
||||
|
||||
config-json-file = @CMAKE_BINARY_DIR@/bin/testJSON.json
|
||||
config-xml-file = @CMAKE_BINARY_DIR@/bin/testXML.xml
|
||||
|
||||
#
|
||||
device-id = merger
|
||||
|
||||
#-------------------
|
||||
[xml.config]
|
||||
|
||||
#filename = @CMAKE_BINARY_DIR@/bin/testXML.xml
|
||||
node.root = fairMQOptions
|
||||
|
||||
|
||||
#-------------------
|
||||
[input.file]
|
||||
|
||||
name = sampler_file_name.root
|
||||
tree = sampler_tree
|
||||
branch = sampler_branch
|
||||
|
||||
|
||||
#-------------------
|
||||
[output.file]
|
||||
|
||||
name = sink_filename.root
|
||||
tree = sink_tree
|
||||
branch = sink_branch
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
JSONFILE="@CMAKE_BINARY_DIR@/bin/bsampler-sink.json"
|
||||
|
||||
# Note: device-id value must correspond to the device id given in the json file
|
||||
|
||||
BSAMPLER="runOptTestSampler"
|
||||
BSAMPLER+=" --config-json-file $JSONFILE"
|
||||
BSAMPLER+=" --id bsampler1"
|
||||
|
||||
xterm -geometry 150x23+0+0 -hold -e @CMAKE_BINARY_DIR@/bin/$BSAMPLER &
|
||||
|
||||
|
||||
SINK="runOptTestSink"
|
||||
SINK+=" --config-json-file $JSONFILE"
|
||||
SINK+=" --id sink1"
|
||||
|
||||
xterm -geometry 150x23+0+350 -hold -e @CMAKE_BINARY_DIR@/bin/$SINK &
|
|
@ -1,63 +0,0 @@
|
|||
{
|
||||
"fairMQOptions": {
|
||||
"devices": [
|
||||
{
|
||||
"id": "merger1",
|
||||
"channels": [
|
||||
{
|
||||
"name": "two_inputs_channel",
|
||||
"sockets": [
|
||||
{
|
||||
"type": "pull",
|
||||
"method": "",
|
||||
"address": "tcp://*:5569",
|
||||
"sndBufSize": 1000,
|
||||
"rcvBufSize": 1000,
|
||||
"rateLogging": 1
|
||||
},
|
||||
{
|
||||
"type": "pull",
|
||||
"method": "bind",
|
||||
"address": "tcp://*:5570",
|
||||
"sndBufSize": 1000,
|
||||
"rcvBufSize": 1000,
|
||||
"rateLogging": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "one_output_channel",
|
||||
"sockets": [
|
||||
{
|
||||
"type": "push",
|
||||
"method": "connect",
|
||||
"address": "tcp://*:5571",
|
||||
"sndBufSize": 1000,
|
||||
"rcvBufSize": 1000,
|
||||
"rateLogging": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "sink1",
|
||||
"channels": [
|
||||
{
|
||||
"name": "one_input",
|
||||
"sockets": [
|
||||
{
|
||||
"type": "pull",
|
||||
"method": "bind",
|
||||
"address": "tcp://localhost:5571",
|
||||
"sndBufSize": 1000,
|
||||
"rcvBufSize": 1000,
|
||||
"rateLogging": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
RUN_TEST="runtestMQOption1"
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
RUN_TEST+=" $*"
|
||||
fi
|
||||
|
||||
RUN_TEST+=" --config-xml-file @CMAKE_BINARY_DIR@/bin/testXML.xml"
|
||||
|
||||
@CMAKE_BINARY_DIR@/bin/$RUN_TEST
|
|
@ -1,59 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
RUN_TEST="runtestMQOption1"
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
RUN_TEST+=" $*"
|
||||
fi
|
||||
|
||||
XML_CMD_LINE="<fairMQOptions>"
|
||||
XML_CMD_LINE+="<device name=\"merger\" id=\"1234\" >"
|
||||
XML_CMD_LINE+=" <channel name=\"two_inputs_channel\" >"
|
||||
XML_CMD_LINE+=" <socket name=\"input1\" >"
|
||||
XML_CMD_LINE+=" <type>pull</type>"
|
||||
XML_CMD_LINE+=" <method>bind</method>"
|
||||
XML_CMD_LINE+=" <address>tcp://*:5569</address>"
|
||||
XML_CMD_LINE+=" <sndBufSize>1000</sndBufSize>"
|
||||
XML_CMD_LINE+=" <rcvBufSize>1000</rcvBufSize>"
|
||||
XML_CMD_LINE+=" <rateLogging>1</rateLogging>"
|
||||
XML_CMD_LINE+=" </socket>"
|
||||
XML_CMD_LINE+=" <socket name=\"input2\" >"
|
||||
XML_CMD_LINE+=" <type>pull</type>"
|
||||
XML_CMD_LINE+=" <method>bind</method>"
|
||||
XML_CMD_LINE+=" <address>tcp://*:5570</address>"
|
||||
XML_CMD_LINE+=" <sndBufSize>1000</sndBufSize>"
|
||||
XML_CMD_LINE+=" <rcvBufSize>1000</rcvBufSize>"
|
||||
XML_CMD_LINE+=" <rateLogging>1</rateLogging>"
|
||||
XML_CMD_LINE+=" </socket>"
|
||||
XML_CMD_LINE+=" </channel>"
|
||||
XML_CMD_LINE+=" <channel name=\"one_output_channel\" >"
|
||||
XML_CMD_LINE+=" <socket name=\"output1\" >"
|
||||
XML_CMD_LINE+=" <type>push</type>"
|
||||
XML_CMD_LINE+=" <method>connect</method>"
|
||||
XML_CMD_LINE+=" <address>tcp://*:5571</address>"
|
||||
XML_CMD_LINE+=" <sndBufSize>1000</sndBufSize>"
|
||||
XML_CMD_LINE+=" <rcvBufSize>1000</rcvBufSize>"
|
||||
XML_CMD_LINE+=" <rateLogging>1</rateLogging>"
|
||||
XML_CMD_LINE+=" </socket>"
|
||||
XML_CMD_LINE+=" </channel>"
|
||||
XML_CMD_LINE+=" </device>"
|
||||
XML_CMD_LINE+=" <device name=\"sink\" id=\"4567\" >"
|
||||
XML_CMD_LINE+=" <channel name=\"one_input\" >"
|
||||
XML_CMD_LINE+=" <socket name=\"input1\" >"
|
||||
XML_CMD_LINE+=" <type>pull</type>"
|
||||
XML_CMD_LINE+=" <method>bind</method>"
|
||||
XML_CMD_LINE+=" <address>tcp://localhost:5571</address>"
|
||||
XML_CMD_LINE+=" <sndBufSize>1000</sndBufSize>"
|
||||
XML_CMD_LINE+=" <rcvBufSize>1000</rcvBufSize>"
|
||||
XML_CMD_LINE+=" <rateLogging>1</rateLogging>"
|
||||
XML_CMD_LINE+=" </socket>"
|
||||
XML_CMD_LINE+=" </channel>"
|
||||
XML_CMD_LINE+=" </device>"
|
||||
XML_CMD_LINE+="</fairmq_option>"
|
||||
|
||||
|
||||
|
||||
RUN_TEST+=" --config-xml-string $XML_CMD_LINE"
|
||||
|
||||
|
||||
@CMAKE_BINARY_DIR@/bin/$RUN_TEST
|
|
@ -1,10 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
RUN_TEST="runtestMQOption2"
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
RUN_TEST+=" $*"
|
||||
fi
|
||||
RUN_TEST+=" --config @CMAKE_BINARY_DIR@/bin/ConfigFileTest.cfg"
|
||||
|
||||
@CMAKE_BINARY_DIR@/bin/$RUN_TEST
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
RUN_TEST="runtestMQOption1"
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
RUN_TEST+=" $*"
|
||||
fi
|
||||
|
||||
RUN_TEST+=" --config-json-file @CMAKE_BINARY_DIR@/bin/testJSON.json"
|
||||
|
||||
@CMAKE_BINARY_DIR@/bin/$RUN_TEST
|
|
@ -1,77 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
RUN_TEST="runtestMQOption1"
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
RUN_TEST+=" $*"
|
||||
fi
|
||||
|
||||
JSON_CMD_LINE="{"
|
||||
JSON_CMD_LINE+=" \"fairMQOptions\": {"
|
||||
JSON_CMD_LINE+=" \"device\": "
|
||||
JSON_CMD_LINE+=" {"
|
||||
JSON_CMD_LINE+=" \"name\": \"merger\","
|
||||
JSON_CMD_LINE+=" \"id\": \"1234\","
|
||||
JSON_CMD_LINE+=" \"channel\": "
|
||||
JSON_CMD_LINE+=" {"
|
||||
JSON_CMD_LINE+=" \"name\": \"two_inputs_channel\","
|
||||
JSON_CMD_LINE+=" \"socket\": "
|
||||
JSON_CMD_LINE+=" {"
|
||||
JSON_CMD_LINE+=" \"name\": \"input1\","
|
||||
JSON_CMD_LINE+=" \"type\": \"pull\","
|
||||
JSON_CMD_LINE+=" \"method\": \"bind\","
|
||||
JSON_CMD_LINE+=" \"address\": \"tcp://*:5569\","
|
||||
JSON_CMD_LINE+=" \"sndBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rcvBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rateLogging\": \"1\" "
|
||||
JSON_CMD_LINE+=" },"
|
||||
JSON_CMD_LINE+=" \"socket\": "
|
||||
JSON_CMD_LINE+=" {"
|
||||
JSON_CMD_LINE+=" \"name\": \"input2\","
|
||||
JSON_CMD_LINE+=" \"type\": \"pull\","
|
||||
JSON_CMD_LINE+=" \"method\": \"bind\","
|
||||
JSON_CMD_LINE+=" \"address\": \"tcp://*:5570\","
|
||||
JSON_CMD_LINE+=" \"sndBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rcvBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rateLogging\": \"1\" "
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+=" },"
|
||||
JSON_CMD_LINE+=" \"channel\":"
|
||||
JSON_CMD_LINE+=" {"
|
||||
JSON_CMD_LINE+=" \"name\": \"one_output_channel\","
|
||||
JSON_CMD_LINE+=" \"socket\": {"
|
||||
JSON_CMD_LINE+=" \"name\": \"output1\","
|
||||
JSON_CMD_LINE+=" \"type\": \"push\","
|
||||
JSON_CMD_LINE+=" \"method\": \"connect\","
|
||||
JSON_CMD_LINE+=" \"address\": \"tcp://*:5571\","
|
||||
JSON_CMD_LINE+=" \"sndBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rcvBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rateLogging\": \"1\" "
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+=" },"
|
||||
JSON_CMD_LINE+=" \"device\":"
|
||||
JSON_CMD_LINE+=" {"
|
||||
JSON_CMD_LINE+=" \"name\": \"sink\","
|
||||
JSON_CMD_LINE+=" \"id\": \"4567\","
|
||||
JSON_CMD_LINE+=" \"channel\": {"
|
||||
JSON_CMD_LINE+=" \"name\": \"one_input\","
|
||||
JSON_CMD_LINE+=" \"socket\": {"
|
||||
JSON_CMD_LINE+=" \"name\": \"input1\","
|
||||
JSON_CMD_LINE+=" \"type\": \"pull\","
|
||||
JSON_CMD_LINE+=" \"method\": \"bind\","
|
||||
JSON_CMD_LINE+=" \"address\": \"tcp://localhost:5571\","
|
||||
JSON_CMD_LINE+=" \"sndBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rcvBufSize\": \"1000\","
|
||||
JSON_CMD_LINE+=" \"rateLogging\": \"1\" "
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+=" }"
|
||||
JSON_CMD_LINE+="}"
|
||||
|
||||
|
||||
RUN_TEST+=" --config-json-string $JSON_CMD_LINE"
|
||||
|
||||
|
||||
@CMAKE_BINARY_DIR@/bin/$RUN_TEST
|
|
@ -1,44 +0,0 @@
|
|||
<fairMQOptions>
|
||||
<device name="merger" id="merger">
|
||||
<channel name="two_inputs_channel">
|
||||
<socket name="input1">
|
||||
<type>pull</type>
|
||||
<method>bind</method>
|
||||
<address>tcp://*:5569</address>
|
||||
<sndBufSize>1000</sndBufSize>
|
||||
<rcvBufSize>1000</rcvBufSize>
|
||||
<rateLogging>1</rateLogging>
|
||||
</socket>
|
||||
<socket name="input2">
|
||||
<type>pull</type>
|
||||
<method>bind</method>
|
||||
<address>tcp://*:5570</address>
|
||||
<sndBufSize>1000</sndBufSize>
|
||||
<rcvBufSize>1000</rcvBufSize>
|
||||
<rateLogging>1</rateLogging>
|
||||
</socket>
|
||||
</channel>
|
||||
<channel name="one_output_channel">
|
||||
<socket name="output1">
|
||||
<type>push</type>
|
||||
<method>connect</method>
|
||||
<address>tcp://*:5571</address>
|
||||
<sndBufSize>1000</sndBufSize>
|
||||
<rcvBufSize>1000</rcvBufSize>
|
||||
<rateLogging>1</rateLogging>
|
||||
</socket>
|
||||
</channel>
|
||||
</device>
|
||||
<device name="sink" id="sink">
|
||||
<channel name="one_input">
|
||||
<socket name="input1">
|
||||
<type>pull</type>
|
||||
<method>bind</method>
|
||||
<address>tcp://localhost:5571</address>
|
||||
<sndBufSize>1000</sndBufSize>
|
||||
<rcvBufSize>1000</rcvBufSize>
|
||||
<rateLogging>1</rateLogging>
|
||||
</socket>
|
||||
</channel>
|
||||
</device>
|
||||
</fairMQOptions>
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* 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-file");
|
||||
string deviceID=config.GetValue<string>("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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* 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-file");
|
||||
string deviceID=config.GetValue<string>("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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/// std
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/// boost
|
||||
#include "boost/program_options.hpp"
|
||||
|
||||
/// FairRoot/FairMQ
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
// 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-file");
|
||||
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
|
||||
std::string id=config->GetValue<std::string>("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>("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>("id");
|
||||
|
||||
filename=config->GetValue<std::string>("config-json-file");
|
||||
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>("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;
|
||||
}
|
||||
|
||||
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 severity = config->GetValue<int>("severity");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(severity);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
// Parse xml or json from cmd line or file
|
||||
if (config->GetVarMap().count("config-xml-file"))
|
||||
{
|
||||
testXML1(config);
|
||||
}
|
||||
|
||||
if (config->GetVarMap().count("config-xml-string"))
|
||||
{
|
||||
testXML2(config);
|
||||
}
|
||||
|
||||
if (config->GetVarMap().count("config-json-file"))
|
||||
{
|
||||
testJSON1(config);
|
||||
}
|
||||
|
||||
if (config->GetVarMap().count("config-json-string"))
|
||||
{
|
||||
testJSON2(config);
|
||||
}
|
||||
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG(error) << e.what();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/// 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);
|
||||
config.AddToCmdLineOptions(io_file_opt_desc);
|
||||
|
||||
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 severity = config.GetValue<int>("severity");
|
||||
FairMQLogger::Level lvl = static_cast<FairMQLogger::Level>(severity);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
// parse XML file
|
||||
std::string filename;
|
||||
std::string XMLrootNode;
|
||||
|
||||
filename=config.GetValue<std::string>("config-xml-file");
|
||||
XMLrootNode=config.GetValue<std::string>("xml.config.node.root");
|
||||
std::string id=config.GetValue<std::string>("id");
|
||||
config.UserParser<FairMQParser::XML>(filename,id,XMLrootNode);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG(error) << e.what();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -63,21 +63,18 @@ int main(int argc, char** argv)
|
|||
{
|
||||
try
|
||||
{
|
||||
// create option manager object
|
||||
FairMQProgOptions config;
|
||||
|
||||
// add key description to cmd line options
|
||||
config.GetCmdLineOptions().add_options()
|
||||
("data-rate", po::value<double>()->default_value(0.5), "Data rate");
|
||||
("data-rate", boost::program_options::value<double>()->default_value(0.5), "Data rate");
|
||||
|
||||
// parse command lines, parse json file and init FairMQMap
|
||||
config.ParseAll(argc, argv, true);
|
||||
|
||||
// // get FairMQMap
|
||||
// auto map1 = config.GetFairMQMap();
|
||||
|
||||
// // update value in variable map, and propagate the update to the FairMQMap
|
||||
// config.UpdateValue<string>("chans.data.0.address","tcp://localhost:1234");
|
||||
// config.SetValue<string>("chans.data.0.address","tcp://localhost:1234");
|
||||
|
||||
// // get the updated FairMQMap
|
||||
// auto map2 = config.GetFairMQMap();
|
||||
|
@ -89,7 +86,6 @@ int main(int argc, char** argv)
|
|||
// config.UpdateChannelMap(map2);
|
||||
|
||||
MyDevice device;
|
||||
// device.CatchSignals();
|
||||
device.SetConfig(config);
|
||||
|
||||
// getting as string and conversion helpers
|
||||
|
@ -130,45 +126,30 @@ int main(int argc, char** argv)
|
|||
|
||||
LOG(info) << "Starting value updates...\n";
|
||||
|
||||
config.UpdateValue<string>("chans.data.0.address", "tcp://localhost:4321");
|
||||
config.SetValue<string>("chans.data.0.address", "tcp://localhost:4321");
|
||||
LOG(info) << "config: " << config.GetValue<string>("chans.data.0.address");
|
||||
LOG(info) << "device: " << device.fChannels.at("data").at(0).GetAddress() << endl;
|
||||
|
||||
config.UpdateValue<int>("chans.data.0.rcvBufSize", 100);
|
||||
config.SetValue<int>("chans.data.0.rcvBufSize", 100);
|
||||
LOG(info) << "config: " << config.GetValue<int>("chans.data.0.rcvBufSize");
|
||||
LOG(info) << "device: " << device.fChannels.at("data").at(0).GetRcvBufSize() << endl;
|
||||
|
||||
config.UpdateValue<double>("data-rate", 0.9);
|
||||
config.SetValue<double>("data-rate", 0.9);
|
||||
LOG(info) << "config: " << config.GetValue<double>("data-rate");
|
||||
LOG(info) << "device: " << device.GetRate() << endl;
|
||||
// device.Print();
|
||||
device.Print();
|
||||
|
||||
LOG(info) << "nase: " << config.GetValue<double>("nase");
|
||||
|
||||
config.Unsubscribe<string>("test");
|
||||
config.Unsubscribe<int>("test");
|
||||
config.Unsubscribe<double>("test");
|
||||
// advanced commands
|
||||
|
||||
// LOG(info) << "-------------------- start custom 1";
|
||||
|
||||
// config.Connect<EventId::Custom, MyDevice&, double>("myNewKey", [](MyDevice& d, double val)
|
||||
// {
|
||||
// d.SetRate(val);
|
||||
// d.Print();
|
||||
// });
|
||||
|
||||
// config.Emit<EventId::Custom, MyDevice&, double>("myNewKey", device, 0.123);
|
||||
|
||||
// LOG(info) << "-------------------- start custom 2 with function";
|
||||
// config.Connect<EventId::Custom, MyDevice&, double>("function example", &MyCallBack);
|
||||
|
||||
// config.Emit<EventId::Custom, MyDevice&, double>("function example", device, 6.66);
|
||||
device.ChangeState("END");
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
LOG(error) << "Unhandled Exception reached the top of main: "
|
||||
<< e.what() << ", application will now exit";
|
||||
LOG(error) << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
TRANSPORT="zeromq"
|
||||
VERBOSE="DEBUG"
|
||||
|
||||
JSONCONFIGFILE="@CMAKE_BINARY_DIR@/bin/config/ex1-sampler-sink.json"
|
||||
|
||||
########################## start DEVICE
|
||||
DEVICE="runConfigExample --transport $TRANSPORT --severity $VERBOSE"
|
||||
DEVICE+=" --id sampler1 --mq-config $JSONCONFIGFILE"
|
||||
@CMAKE_BINARY_DIR@/bin/$DEVICE
|
||||
DEVICE="runConfigExample"
|
||||
DEVICE+=" --id sampler1 --channel-config name=data,type=push,method=bind,address=tcp://*:5555,rateLogging=0"
|
||||
@CMAKE_CURRENT_BINARY_DIR@/$DEVICE
|
||||
|
|
|
@ -149,14 +149,14 @@ void FairMQTransportFactorySHM::StartMonitor()
|
|||
|
||||
auto env = boost::this_process::environment();
|
||||
|
||||
vector<boost::filesystem::path> ownPath = boost::this_process::path();
|
||||
vector<bfs::path> ownPath = boost::this_process::path();
|
||||
|
||||
if (const char* fmqp = getenv("FAIRMQ_PATH"))
|
||||
{
|
||||
ownPath.insert(ownPath.begin(), boost::filesystem::path(fmqp));
|
||||
ownPath.insert(ownPath.begin(), bfs::path(fmqp));
|
||||
}
|
||||
|
||||
boost::filesystem::path p = boost::process::search_path("fairmq-shmmonitor", ownPath);
|
||||
bfs::path p = boost::process::search_path("fairmq-shmmonitor", ownPath);
|
||||
|
||||
if (!p.empty())
|
||||
{
|
||||
|
@ -184,7 +184,7 @@ void FairMQTransportFactorySHM::StartMonitor()
|
|||
}
|
||||
else
|
||||
{
|
||||
LOG(WARN) << "could not find fairmq-shmmonitor in the path";
|
||||
LOG(warn) << "could not find fairmq-shmmonitor in the path";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ Region::Region(Manager& manager, uint64_t id, uint64_t size, bool remote, FairMQ
|
|||
LOG(debug) << "shmem: created region queue: " << fQueueName;
|
||||
}
|
||||
fRegion = bipc::mapped_region(fShmemObject, bipc::read_write); // TODO: add HUGEPAGES flag here
|
||||
// fRegion = bipc::mapped_region(fShmemObject, bipc::read_write, 0, 0, 0, MAP_HUGETLB | MAP_HUGE_1GB);
|
||||
// fRegion = bipc::mapped_region(fShmemObject, bipc::read_write, 0, 0, 0, MAP_ANONYMOUS | MAP_HUGETLB);
|
||||
}
|
||||
|
||||
void Region::StartReceivingAcks()
|
||||
|
|
Loading…
Reference in New Issue
Block a user