mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 10:01:47 +00:00
Port DDS plugin to the new plugin system.
This commit is contained in:
committed by
Mohammad Al-Turany
parent
2db114bc5c
commit
01327426c3
@@ -33,16 +33,7 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id,
|
||||
// Extract value from boost::property_tree
|
||||
Helper::DeviceParser(pt.get_child(rootNode), channelMap, id, formatFlag);
|
||||
|
||||
if (channelMap.size() > 0)
|
||||
{
|
||||
stringstream channelKeys;
|
||||
for (const auto& p : channelMap)
|
||||
{
|
||||
channelKeys << "'" << p.first << "' ";
|
||||
}
|
||||
LOG(DEBUG) << "---- Found following channel keys: " << channelKeys.str();
|
||||
}
|
||||
else
|
||||
if (channelMap.empty())
|
||||
{
|
||||
LOG(WARN) << "---- No channel keys found for " << id;
|
||||
LOG(WARN) << "---- Check the JSON inputs and/or command line inputs";
|
||||
|
@@ -29,6 +29,7 @@ FairMQProgOptions::FairMQProgOptions()
|
||||
, fFairMQMap()
|
||||
, fHelpTitle("***** FAIRMQ Program Options ***** ")
|
||||
, fVersion("Beta version 0.1")
|
||||
, fChannelInfo()
|
||||
, fMQKeyMap()
|
||||
// , fSignalMap() //string API
|
||||
{
|
||||
@@ -114,7 +115,7 @@ void FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool a
|
||||
DefaultConsoleSetFilter(fSeverityMap.at(verbosity));
|
||||
}
|
||||
|
||||
// check if one of required MQ config option is there
|
||||
// check if one of required MQ config option is there
|
||||
auto parserOptions = fMQParserOptions.options();
|
||||
bool optionExists = false;
|
||||
vector<string> MQParserKeys;
|
||||
@@ -157,24 +158,24 @@ void FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool a
|
||||
|
||||
string file = fVarMap["mq-config"].as<string>();
|
||||
|
||||
string fileExtension = boost::filesystem::extension(file);
|
||||
string ext = boost::filesystem::extension(file);
|
||||
|
||||
transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower);
|
||||
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
|
||||
|
||||
if (fileExtension == ".json")
|
||||
if (ext == ".json")
|
||||
{
|
||||
UserParser<FairMQParser::JSON>(file, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fileExtension == ".xml")
|
||||
if (ext == ".xml")
|
||||
{
|
||||
UserParser<FairMQParser::XML>(file, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "mq-config command line called but file extension '"
|
||||
<< fileExtension
|
||||
<< ext
|
||||
<< "' not recognized. Program will now exit";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -211,6 +212,7 @@ void FairMQProgOptions::ParseAll(const int argc, char const* const* argv, bool a
|
||||
int FairMQProgOptions::Store(const FairMQMap& channels)
|
||||
{
|
||||
fFairMQMap = channels;
|
||||
UpdateChannelInfo();
|
||||
UpdateMQValues();
|
||||
return 0;
|
||||
}
|
||||
@@ -219,10 +221,20 @@ int FairMQProgOptions::Store(const FairMQMap& channels)
|
||||
int FairMQProgOptions::UpdateChannelMap(const FairMQMap& channels)
|
||||
{
|
||||
fFairMQMap = channels;
|
||||
UpdateChannelInfo();
|
||||
UpdateMQValues();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FairMQProgOptions::UpdateChannelInfo()
|
||||
{
|
||||
fChannelInfo.clear();
|
||||
for (const auto& c : fFairMQMap)
|
||||
{
|
||||
fChannelInfo.insert(std::make_pair(c.first, c.second.size()));
|
||||
}
|
||||
}
|
||||
|
||||
// read FairMQChannelMap and insert/update corresponding values in variable map
|
||||
// create key for variable map as follow : channelName.index.memberName
|
||||
void FairMQProgOptions::UpdateMQValues()
|
||||
@@ -233,15 +245,15 @@ void FairMQProgOptions::UpdateMQValues()
|
||||
|
||||
for (const auto& channel : p.second)
|
||||
{
|
||||
string typeKey = p.first + "." + to_string(index) + ".type";
|
||||
string methodKey = p.first + "." + to_string(index) + ".method";
|
||||
string addressKey = p.first + "." + to_string(index) + ".address";
|
||||
string transportKey = p.first + "." + to_string(index) + ".transport";
|
||||
string sndBufSizeKey = p.first + "." + to_string(index) + ".sndBufSize";
|
||||
string rcvBufSizeKey = p.first + "." + to_string(index) + ".rcvBufSize";
|
||||
string sndKernelSizeKey = p.first + "." + to_string(index) + ".sndKernelSize";
|
||||
string rcvKernelSizeKey = p.first + "." + to_string(index) + ".rcvKernelSize";
|
||||
string rateLoggingKey = p.first + "." + to_string(index) + ".rateLogging";
|
||||
string typeKey = "chans." + p.first + "." + to_string(index) + ".type";
|
||||
string methodKey = "chans." + p.first + "." + to_string(index) + ".method";
|
||||
string addressKey = "chans." + p.first + "." + to_string(index) + ".address";
|
||||
string transportKey = "chans." + p.first + "." + to_string(index) + ".transport";
|
||||
string sndBufSizeKey = "chans." + p.first + "." + to_string(index) + ".sndBufSize";
|
||||
string rcvBufSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvBufSize";
|
||||
string sndKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".sndKernelSize";
|
||||
string rcvKernelSizeKey = "chans." + p.first + "." + to_string(index) + ".rcvKernelSize";
|
||||
string rateLoggingKey = "chans." + p.first + "." + to_string(index) + ".rateLogging";
|
||||
|
||||
fMQKeyMap[typeKey] = make_tuple(p.first, index, "type");
|
||||
fMQKeyMap[methodKey] = make_tuple(p.first, index, "method");
|
||||
@@ -258,7 +270,6 @@ void FairMQProgOptions::UpdateMQValues()
|
||||
UpdateVarMap<string>(addressKey, channel.GetAddress());
|
||||
UpdateVarMap<string>(transportKey, channel.GetTransport());
|
||||
|
||||
|
||||
//UpdateVarMap<string>(sndBufSizeKey, to_string(channel.GetSndBufSize()));// string API
|
||||
UpdateVarMap<int>(sndBufSizeKey, channel.GetSndBufSize());
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "FairProgOptions.h"
|
||||
#include "FairMQEventManager.h"
|
||||
@@ -37,11 +38,11 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
FairMQProgOptions();
|
||||
virtual ~FairMQProgOptions();
|
||||
|
||||
// parse command line and txt/INI configuration file.
|
||||
// parse command line and txt/INI configuration file.
|
||||
// default parser for the mq-configuration file (JSON/XML) is called if command line key mq-config is called
|
||||
virtual void ParseAll(const int argc, char const* const* argv, bool allowUnregistered = false);
|
||||
|
||||
// external parser, store function
|
||||
// external parser, store function
|
||||
template <typename T, typename ...Args>
|
||||
int UserParser(Args &&... args)
|
||||
{
|
||||
@@ -57,11 +58,16 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
return 0;
|
||||
}
|
||||
|
||||
FairMQMap GetFairMQMap()
|
||||
FairMQMap GetFairMQMap() const
|
||||
{
|
||||
return fFairMQMap;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, int> GetChannelInfo() const
|
||||
{
|
||||
return fChannelInfo;
|
||||
}
|
||||
|
||||
// to customize title of the executable help command line
|
||||
void SetHelpTitle(const std::string& title)
|
||||
{
|
||||
@@ -257,7 +263,6 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
|
||||
Disconnect<EventId::UpdateParam, T>(key);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
template <typename F>
|
||||
@@ -284,6 +289,9 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
std::string fHelpTitle;
|
||||
std::string fVersion;
|
||||
|
||||
// map of read channel info - channel name - number of subchannels
|
||||
std::unordered_map<std::string, int> fChannelInfo;
|
||||
|
||||
bool EventKeyFound(const std::string& key)
|
||||
{
|
||||
if (FairMQEventManager::EventKeyFound<EventId::UpdateParam>(key))
|
||||
@@ -338,6 +346,8 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UpdateChannelInfo();
|
||||
};
|
||||
|
||||
#endif /* FAIRMQPROGOPTIONS_H */
|
||||
|
@@ -201,9 +201,9 @@ class FairProgOptions
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void replace(std::map<std::string, po::variable_value>& vm, const std::string& opt, const T& val)
|
||||
void replace(std::map<std::string, po::variable_value>& vm, const std::string& key, const T& val)
|
||||
{
|
||||
vm[opt].value() = boost::any(val);
|
||||
vm[key].value() = boost::any(val);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -71,13 +71,13 @@ int main(int argc, char** argv)
|
||||
("data-rate", po::value<double>()->default_value(0.5), "Data rate");
|
||||
|
||||
// parse command lines, parse json file and init FairMQMap
|
||||
config.ParseAll(argc, argv);
|
||||
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>("data.0.address","tcp://localhost:1234");
|
||||
// config.UpdateValue<string>("chans.data.0.address","tcp://localhost:1234");
|
||||
|
||||
// // get the updated FairMQMap
|
||||
// auto map2 = config.GetFairMQMap();
|
||||
@@ -98,15 +98,15 @@ int main(int argc, char** argv)
|
||||
// double dataRate = config.ConvertTo<double>(dataRateStr);
|
||||
// LOG(INFO) << "dataRate: " << dataRate;
|
||||
|
||||
LOG(INFO) << "Subscribing: <string>(data.0.address)";
|
||||
config.Subscribe<string>("data.0.address", [&device](const string& key, const string& value)
|
||||
LOG(INFO) << "Subscribing: <string>(chans.data.0.address)";
|
||||
config.Subscribe<string>("chans.data.0.address", [&device](const string& key, const string& value)
|
||||
{
|
||||
LOG(INFO) << "[callback] Updating device parameter " << key << " = " << value;
|
||||
device.fChannels.at("data").at(0).UpdateAddress(value);
|
||||
});
|
||||
|
||||
LOG(INFO) << "Subscribing: <int>(data.0.rcvBufSize)";
|
||||
config.Subscribe<int>("data.0.rcvBufSize", [&device](const string& key, int value)
|
||||
LOG(INFO) << "Subscribing: <int>(chans.data.0.rcvBufSize)";
|
||||
config.Subscribe<int>("chans.data.0.rcvBufSize", [&device](const string& key, int value)
|
||||
{
|
||||
LOG(INFO) << "[callback] Updating device parameter " << key << " = " << value;
|
||||
device.fChannels.at("data").at(0).UpdateRcvBufSize(value);
|
||||
@@ -121,12 +121,12 @@ int main(int argc, char** argv)
|
||||
|
||||
LOG(INFO) << "Starting value updates...\n";
|
||||
|
||||
config.UpdateValue<string>("data.0.address", "tcp://localhost:4321");
|
||||
LOG(INFO) << "config: " << config.GetValue<string>("data.0.address");
|
||||
config.UpdateValue<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>("data.0.rcvBufSize", 100);
|
||||
LOG(INFO) << "config: " << config.GetValue<int>("data.0.rcvBufSize");
|
||||
config.UpdateValue<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);
|
||||
|
Reference in New Issue
Block a user