mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
Enable new callback API
- OnData() channel data handler. - ConditionalRun() for devices without incoming data. - Header file with common main(), to be extended with getDevice/addCustomOptions. - Update examples (MQ/Tutorial3) to use the new API and config. - NewSimpleMessage() for simpler creation of small messages (additional copy). - Replace SetProperty/GetProperty with fConfig access. - Runtime configurable channel names for common devices. - Configurable logging interval per channel. - FairMQMultiplier for distributing same data to multiple outputs. - Cleanup state machine messages. - Cmd option to toggle signal handling. - Simpler API for send/receive timeouts. - Enable --log-to-file. - Fix coverity issues, warnings. - Various code cleanup and minor tweaks.
This commit is contained in:
@@ -26,41 +26,36 @@
|
||||
#include <boost/signals2.hpp>
|
||||
#include <boost/signals2/signal.hpp>
|
||||
|
||||
|
||||
|
||||
|
||||
enum class EventId : uint32_t
|
||||
enum class EventId : uint32_t
|
||||
{
|
||||
// Place your new EventManager events here
|
||||
UpdateParam = 0,
|
||||
Custom = 1,
|
||||
|
||||
};
|
||||
|
||||
namespace Events
|
||||
namespace Events
|
||||
{
|
||||
|
||||
template <EventId,typename ...Args> struct Traits;
|
||||
template <typename T> struct Traits<EventId::UpdateParam, T> { using signal_type = boost::signals2::signal<void(const std::string&, T)>; } ;
|
||||
template <typename T> struct Traits<EventId::UpdateParam, std::vector<T> > { using signal_type = boost::signals2::signal<void(const std::string&, const std::vector<T>& )>; } ;
|
||||
|
||||
template <EventId,typename ...Args> struct Traits;
|
||||
template <typename T> struct Traits<EventId::UpdateParam, T> { using signal_type = boost::signals2::signal<void(const std::string&, T)>; } ;
|
||||
template <typename T> struct Traits<EventId::UpdateParam, std::vector<T> > { using signal_type = boost::signals2::signal<void(const std::string&, const std::vector<T>& )>; } ;
|
||||
|
||||
template <> struct Traits<EventId::UpdateParam, std::string> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
|
||||
|
||||
template<std::size_t N> struct Traits<EventId::UpdateParam, const char[N]> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
|
||||
|
||||
template <typename ...T> struct Traits<EventId::Custom,T...> { using signal_type = boost::signals2::signal<void(T...)>; } ;
|
||||
|
||||
/*
|
||||
template <EventId, typename ...Args> struct Traits2;
|
||||
template <> struct Traits2<EventId::UpdateParam> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
|
||||
template <typename ...T> struct Traits2<EventId::UpdateParam,T...> { using signal_type = boost::signals2::signal<void(const std::string&, T...)>; } ;
|
||||
template <> struct Traits2<EventId::UpdateParamInt> { using signal_type = boost::signals2::signal<void(const std::string&, int)>; } ;
|
||||
// */
|
||||
}
|
||||
template <> struct Traits<EventId::UpdateParam, std::string> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
|
||||
|
||||
template<std::size_t N> struct Traits<EventId::UpdateParam, const char[N]> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
|
||||
|
||||
class FairMQEventManager
|
||||
template <typename ...T> struct Traits<EventId::Custom,T...> { using signal_type = boost::signals2::signal<void(T...)>; } ;
|
||||
|
||||
/*
|
||||
template <EventId, typename ...Args> struct Traits2;
|
||||
template <> struct Traits2<EventId::UpdateParam> { using signal_type = boost::signals2::signal<void(const std::string&, const std::string&)>; } ;
|
||||
template <typename ...T> struct Traits2<EventId::UpdateParam,T...> { using signal_type = boost::signals2::signal<void(const std::string&, T...)>; } ;
|
||||
template <> struct Traits2<EventId::UpdateParamInt> { using signal_type = boost::signals2::signal<void(const std::string&, int)>; } ;
|
||||
// */
|
||||
|
||||
} // Events namespace
|
||||
|
||||
class FairMQEventManager
|
||||
{
|
||||
public:
|
||||
typedef std::pair<EventId,std::string> EventKey;
|
||||
@@ -99,16 +94,13 @@ class FairMQEventManager
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
std::map<EventKey, boost::any> fEventMap;
|
||||
|
||||
|
||||
template <EventId event, typename... T, typename Slot = typename Events::Traits<event,T...>::signal_type,
|
||||
typename SlotPtr = boost::shared_ptr<Slot> >
|
||||
Slot& GetSlot(const std::string& key)
|
||||
Slot& GetSlot(const std::string& key)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
EventKey eventKey = std::make_pair(event,key);
|
||||
//static_assert(std::is_same<decltype(boost::make_shared<Slot>()),SlotPtr>::value, "");
|
||||
@@ -119,7 +111,7 @@ class FairMQEventManager
|
||||
// auto &&tmp = boost::any_cast<SlotPtr>(fEventMap.at(eventKey));
|
||||
// return *tmp;
|
||||
}
|
||||
catch (boost::bad_any_cast const &e)
|
||||
catch (boost::bad_any_cast const &e)
|
||||
{
|
||||
LOG(ERROR) << "Caught instance of boost::bad_any_cast: "
|
||||
<< e.what() << " on event #" << static_cast<uint32_t>(event) << " and key" << key;
|
||||
@@ -128,6 +120,4 @@ class FairMQEventManager
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FAIRMQEVENTMANAGER_H */
|
||||
|
||||
|
@@ -30,7 +30,8 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& id,
|
||||
FairMQMap channelMap;
|
||||
// helper::PrintDeviceList(pt.get_child(rootNode));
|
||||
// Extract value from boost::property_tree
|
||||
helper::DeviceParser(pt.get_child(rootNode), channelMap, id, formatFlag);
|
||||
Helper::DeviceParser(pt.get_child(rootNode), channelMap, id, formatFlag);
|
||||
|
||||
if (channelMap.size() > 0)
|
||||
{
|
||||
stringstream channelKeys;
|
||||
@@ -77,119 +78,86 @@ FairMQMap XML::UserParser(stringstream& input, const string& deviceId, const str
|
||||
return ptreeToMQMap(pt, deviceId, rootNode, "xml");
|
||||
}
|
||||
|
||||
namespace helper
|
||||
namespace Helper
|
||||
{
|
||||
void PrintDeviceList(const boost::property_tree::ptree& tree, const std::string& formatFlag)
|
||||
{
|
||||
string deviceIdKey;
|
||||
|
||||
// do a first loop just to print the device-id in json input
|
||||
for (const auto& p : tree)
|
||||
void PrintDeviceList(const boost::property_tree::ptree& tree, const std::string& formatFlag)
|
||||
{
|
||||
string deviceIdKey;
|
||||
|
||||
// do a first loop just to print the device-id in json input
|
||||
for (const auto& p : tree)
|
||||
{
|
||||
if (p.first == "devices")
|
||||
{
|
||||
if (p.first == "devices")
|
||||
for (const auto& q : p.second.get_child(""))
|
||||
{
|
||||
for (const auto& q : p.second.get_child(""))
|
||||
string key = q.second.get<string>("key", "");
|
||||
if (key != "")
|
||||
{
|
||||
string key = q.second.get<string>("key", "");
|
||||
if (key != "")
|
||||
{
|
||||
deviceIdKey = key;
|
||||
LOG(TRACE) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = q.second.get<string>("id");
|
||||
LOG(TRACE) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
deviceIdKey = key;
|
||||
LOG(TRACE) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = q.second.get<string>("id");
|
||||
LOG(TRACE) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (p.first == "device")
|
||||
if (p.first == "device")
|
||||
{
|
||||
//get id attribute to choose the device
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
//get id attribute to choose the device
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
deviceIdKey = p.second.get<string>("<xmlattr>.id");
|
||||
LOG(TRACE) << "Found config for '" << deviceIdKey << "' in XML input";
|
||||
}
|
||||
deviceIdKey = p.second.get<string>("<xmlattr>.id");
|
||||
LOG(TRACE) << "Found config for '" << deviceIdKey << "' in XML input";
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
string key = p.second.get<string>("key", "");
|
||||
if (key != "")
|
||||
{
|
||||
string key = p.second.get<string>("key", "");
|
||||
if (key != "")
|
||||
{
|
||||
deviceIdKey = key;
|
||||
LOG(TRACE) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = p.second.get<string>("id");
|
||||
LOG(TRACE) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
deviceIdKey = key;
|
||||
LOG(TRACE) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = p.second.get<string>("id");
|
||||
LOG(TRACE) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const string& deviceId, const string& formatFlag)
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const string& deviceId, const string& formatFlag)
|
||||
{
|
||||
string deviceIdKey;
|
||||
|
||||
LOG(DEBUG) << "Looking for '" << deviceId << "' id/key in the provided config file...";
|
||||
|
||||
// For each node in fairMQOptions
|
||||
for (const auto& p : tree)
|
||||
{
|
||||
string deviceIdKey;
|
||||
|
||||
LOG(DEBUG) << "Looking for '" << deviceId << "' id/key in the provided config file...";
|
||||
|
||||
// For each node in fairMQOptions
|
||||
for (const auto& p0 : tree)
|
||||
if (p.first == "devices")
|
||||
{
|
||||
if (p0.first == "devices")
|
||||
for (const auto& q : p.second)
|
||||
{
|
||||
for (const auto& p : p0.second)
|
||||
// check if key is provided, otherwise use id
|
||||
string key = q.second.get<string>("key", "");
|
||||
|
||||
if (key != "")
|
||||
{
|
||||
// check if key is provided, otherwise use id
|
||||
string key = p.second.get<string>("key", "");
|
||||
if (key != "")
|
||||
{
|
||||
deviceIdKey = key;
|
||||
// LOG(DEBUG) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = p.second.get<string>("id");
|
||||
// LOG(DEBUG) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
|
||||
// if not correct device id, do not fill MQMap
|
||||
if (deviceId != deviceIdKey)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "[" << p0.first << "] " << deviceIdKey;
|
||||
ChannelParser(p.second, channelMap, formatFlag);
|
||||
deviceIdKey = key;
|
||||
// LOG(DEBUG) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
}
|
||||
|
||||
if (p0.first == "device")
|
||||
{
|
||||
if (formatFlag == "xml")
|
||||
else
|
||||
{
|
||||
deviceIdKey = p0.second.get<string>("<xmlattr>.id");
|
||||
LOG(DEBUG) << "Found config for '" << deviceIdKey << "' in XML input";
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
// check if key is provided, otherwise use id
|
||||
string key = p0.second.get<string>("key", "");
|
||||
if (key != "")
|
||||
{
|
||||
deviceIdKey = key;
|
||||
// LOG(DEBUG) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = p0.second.get<string>("id");
|
||||
// LOG(DEBUG) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
deviceIdKey = q.second.get<string>("id");
|
||||
// LOG(DEBUG) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
|
||||
// if not correct device id, do not fill MQMap
|
||||
@@ -198,167 +166,255 @@ namespace helper
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "[" << p0.first << "] " << deviceIdKey;
|
||||
LOG(DEBUG) << "Found with following channels:";
|
||||
|
||||
ChannelParser(p0.second, channelMap, formatFlag);
|
||||
ChannelParser(q.second, channelMap, formatFlag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const string& formatFlag)
|
||||
{
|
||||
string channelKey;
|
||||
|
||||
for (const auto& p : tree)
|
||||
if (p.first == "device")
|
||||
{
|
||||
if (p.first == "channels")
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
for (const auto& q : p.second)
|
||||
deviceIdKey = p.second.get<string>("<xmlattr>.id");
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
// check if key is provided, otherwise use id
|
||||
string key = p.second.get<string>("key", "");
|
||||
|
||||
if (key != "")
|
||||
{
|
||||
channelKey = q.second.get<string>("name");
|
||||
|
||||
// try to get common properties to use for all subChannels
|
||||
FairMQChannel commonChannel;
|
||||
commonChannel.UpdateType(q.second.get<string>("type", commonChannel.GetType()));
|
||||
commonChannel.UpdateMethod(q.second.get<string>("method", commonChannel.GetMethod()));
|
||||
commonChannel.UpdateAddress(q.second.get<string>("address", commonChannel.GetAddress()));
|
||||
commonChannel.UpdateProperty(q.second.get<string>("property", commonChannel.GetProperty()));
|
||||
commonChannel.UpdateSndBufSize(q.second.get<int>("sndBufSize", commonChannel.GetSndBufSize()));
|
||||
commonChannel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
|
||||
commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
|
||||
|
||||
LOG(DEBUG) << "\t[" << p.first << "] " << channelKey;
|
||||
|
||||
// temporary FairMQChannel container
|
||||
vector<FairMQChannel> channelList;
|
||||
SocketParser(q.second.get_child(""), channelList, commonChannel);
|
||||
|
||||
channelMap.insert(make_pair(channelKey, move(channelList)));
|
||||
deviceIdKey = key;
|
||||
// LOG(DEBUG) << "Found config for device key '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceIdKey = p.second.get<string>("id");
|
||||
// LOG(DEBUG) << "Found config for device id '" << deviceIdKey << "' in JSON input";
|
||||
}
|
||||
}
|
||||
|
||||
if (p.first == "channel")
|
||||
// if not correct device id, do not fill MQMap
|
||||
if (deviceId != deviceIdKey)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Found with following channels:";
|
||||
|
||||
ChannelParser(p.second, channelMap, formatFlag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const string& formatFlag)
|
||||
{
|
||||
string channelKey;
|
||||
|
||||
for (const auto& p : tree)
|
||||
{
|
||||
if (p.first == "channels")
|
||||
{
|
||||
for (const auto& q : p.second)
|
||||
{
|
||||
channelKey = q.second.get<string>("name");
|
||||
|
||||
int numSockets = q.second.get<int>("numSockets", 0);
|
||||
|
||||
// try to get common properties to use for all subChannels
|
||||
FairMQChannel commonChannel;
|
||||
|
||||
// get name attribute to form key
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
channelKey = p.second.get<string>("<xmlattr>.name");
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
channelKey = p.second.get<string>("name");
|
||||
|
||||
// try to get common properties to use for all subChannels
|
||||
commonChannel.UpdateType(p.second.get<string>("type", commonChannel.GetType()));
|
||||
commonChannel.UpdateMethod(p.second.get<string>("method", commonChannel.GetMethod()));
|
||||
commonChannel.UpdateAddress(p.second.get<string>("address", commonChannel.GetAddress()));
|
||||
commonChannel.UpdateProperty(p.second.get<string>("property", commonChannel.GetProperty()));
|
||||
commonChannel.UpdateSndBufSize(p.second.get<int>("sndBufSize", commonChannel.GetSndBufSize()));
|
||||
commonChannel.UpdateRcvBufSize(p.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
|
||||
commonChannel.UpdateRateLogging(p.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "\t[" << p.first << "] " << channelKey;
|
||||
commonChannel.UpdateType(q.second.get<string>("type", commonChannel.GetType()));
|
||||
commonChannel.UpdateMethod(q.second.get<string>("method", commonChannel.GetMethod()));
|
||||
commonChannel.UpdateAddress(q.second.get<string>("address", commonChannel.GetAddress()));
|
||||
commonChannel.UpdateProperty(q.second.get<string>("property", commonChannel.GetProperty()));
|
||||
commonChannel.UpdateSndBufSize(q.second.get<int>("sndBufSize", commonChannel.GetSndBufSize()));
|
||||
commonChannel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
|
||||
commonChannel.UpdateRateLogging(q.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
|
||||
|
||||
// temporary FairMQChannel container
|
||||
vector<FairMQChannel> channelList;
|
||||
SocketParser(p.second.get_child(""), channelList, commonChannel);
|
||||
|
||||
if (numSockets > 0)
|
||||
{
|
||||
LOG(DEBUG) << "" << channelKey << ":";
|
||||
LOG(DEBUG) << "\tnumSockets of " << numSockets << " specified,";
|
||||
LOG(DEBUG) << "\tapplying common settings to each:";
|
||||
|
||||
LOG(DEBUG) << "\ttype = " << commonChannel.GetType();
|
||||
LOG(DEBUG) << "\tmethod = " << commonChannel.GetMethod();
|
||||
LOG(DEBUG) << "\taddress = " << commonChannel.GetAddress();
|
||||
LOG(DEBUG) << "\tproperty = " << commonChannel.GetProperty();
|
||||
LOG(DEBUG) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\trateLogging = " << commonChannel.GetRateLogging();
|
||||
|
||||
for (int i = 0; i < numSockets; ++i)
|
||||
{
|
||||
FairMQChannel channel(commonChannel);
|
||||
channelList.push_back(channel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SocketParser(q.second.get_child(""), channelList, channelKey, commonChannel);
|
||||
}
|
||||
|
||||
channelMap.insert(make_pair(channelKey, move(channelList)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>& channelList, const FairMQChannel& commonChannel)
|
||||
{
|
||||
// for each socket in channel
|
||||
int socketCounter = 0;
|
||||
for (const auto& p : tree)
|
||||
if (p.first == "channel")
|
||||
{
|
||||
if (p.first == "sockets")
|
||||
// try to get common properties to use for all subChannels
|
||||
FairMQChannel commonChannel;
|
||||
int numSockets = 0;
|
||||
|
||||
// get name attribute to form key
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
for (const auto& q : p.second)
|
||||
channelKey = p.second.get<string>("<xmlattr>.name");
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
channelKey = p.second.get<string>("name");
|
||||
|
||||
numSockets = p.second.get<int>("numSockets", 0);
|
||||
|
||||
// try to get common properties to use for all subChannels
|
||||
commonChannel.UpdateType(p.second.get<string>("type", commonChannel.GetType()));
|
||||
commonChannel.UpdateMethod(p.second.get<string>("method", commonChannel.GetMethod()));
|
||||
commonChannel.UpdateAddress(p.second.get<string>("address", commonChannel.GetAddress()));
|
||||
commonChannel.UpdateProperty(p.second.get<string>("property", commonChannel.GetProperty()));
|
||||
commonChannel.UpdateSndBufSize(p.second.get<int>("sndBufSize", commonChannel.GetSndBufSize()));
|
||||
commonChannel.UpdateRcvBufSize(p.second.get<int>("rcvBufSize", commonChannel.GetRcvBufSize()));
|
||||
commonChannel.UpdateRateLogging(p.second.get<int>("rateLogging", commonChannel.GetRateLogging()));
|
||||
}
|
||||
|
||||
// temporary FairMQChannel container
|
||||
vector<FairMQChannel> channelList;
|
||||
|
||||
if (numSockets > 0)
|
||||
{
|
||||
LOG(DEBUG) << "" << channelKey << ":";
|
||||
LOG(DEBUG) << "\tnumSockets of " << numSockets << " specified,";
|
||||
LOG(DEBUG) << "\tapplying common settings to each:";
|
||||
|
||||
LOG(DEBUG) << "\ttype = " << commonChannel.GetType();
|
||||
LOG(DEBUG) << "\tmethod = " << commonChannel.GetMethod();
|
||||
LOG(DEBUG) << "\taddress = " << commonChannel.GetAddress();
|
||||
LOG(DEBUG) << "\tproperty = " << commonChannel.GetProperty();
|
||||
LOG(DEBUG) << "\tsndBufSize = " << commonChannel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\trcvBufSize = " << commonChannel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\trateLogging = " << commonChannel.GetRateLogging();
|
||||
|
||||
for (int i = 0; i < numSockets; ++i)
|
||||
{
|
||||
++socketCounter;
|
||||
// create new channel and apply setting from the common channel
|
||||
FairMQChannel channel(commonChannel);
|
||||
|
||||
// if the socket field specifies or overrides something from the common channel, apply those settings
|
||||
channel.UpdateType(q.second.get<string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(q.second.get<string>("method", channel.GetMethod()));
|
||||
channel.UpdateAddress(q.second.get<string>("address", channel.GetAddress()));
|
||||
channel.UpdateProperty(q.second.get<string>("property", channel.GetProperty()));
|
||||
channel.UpdateSndBufSize(q.second.get<int>("sndBufSize", channel.GetSndBufSize()));
|
||||
channel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
|
||||
channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging()));
|
||||
|
||||
LOG(DEBUG) << "\t\t[" << p.first << "] " << socketCounter;
|
||||
LOG(DEBUG) << "\t\t\ttype = " << channel.GetType();
|
||||
LOG(DEBUG) << "\t\t\tmethod = " << channel.GetMethod();
|
||||
LOG(DEBUG) << "\t\t\taddress = " << channel.GetAddress();
|
||||
LOG(DEBUG) << "\t\t\tproperty = " << channel.GetProperty();
|
||||
LOG(DEBUG) << "\t\t\tsndBufSize = " << channel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\t\t\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\t\t\trateLogging = " << channel.GetRateLogging();
|
||||
|
||||
channelList.push_back(channel);
|
||||
}
|
||||
}
|
||||
|
||||
if (p.first == "socket")
|
||||
else
|
||||
{
|
||||
SocketParser(p.second.get_child(""), channelList, channelKey, commonChannel);
|
||||
}
|
||||
|
||||
channelMap.insert(make_pair(channelKey, move(channelList)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SocketParser(const boost::property_tree::ptree& tree, vector<FairMQChannel>& channelList, const string& channelName, const FairMQChannel& commonChannel)
|
||||
{
|
||||
// for each socket in channel
|
||||
int socketCounter = 0;
|
||||
|
||||
for (const auto& p : tree)
|
||||
{
|
||||
if (p.first == "sockets")
|
||||
{
|
||||
for (const auto& q : p.second)
|
||||
{
|
||||
++socketCounter;
|
||||
// create new channel and apply setting from the common channel
|
||||
FairMQChannel channel(commonChannel);
|
||||
|
||||
// if the socket field specifies or overrides something from the common channel, apply those settings
|
||||
channel.UpdateType(p.second.get<string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(p.second.get<string>("method", channel.GetMethod()));
|
||||
channel.UpdateAddress(p.second.get<string>("address", channel.GetAddress()));
|
||||
channel.UpdateProperty(p.second.get<string>("property", channel.GetProperty()));
|
||||
channel.UpdateSndBufSize(p.second.get<int>("sndBufSize", channel.GetSndBufSize()));
|
||||
channel.UpdateRcvBufSize(p.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
|
||||
channel.UpdateRateLogging(p.second.get<int>("rateLogging", channel.GetRateLogging()));
|
||||
channel.UpdateType(q.second.get<string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(q.second.get<string>("method", channel.GetMethod()));
|
||||
channel.UpdateAddress(q.second.get<string>("address", channel.GetAddress()));
|
||||
channel.UpdateProperty(q.second.get<string>("property", channel.GetProperty()));
|
||||
channel.UpdateSndBufSize(q.second.get<int>("sndBufSize", channel.GetSndBufSize()));
|
||||
channel.UpdateRcvBufSize(q.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
|
||||
channel.UpdateRateLogging(q.second.get<int>("rateLogging", channel.GetRateLogging()));
|
||||
|
||||
LOG(DEBUG) << "\t\t[" << p.first << "] " << socketCounter;
|
||||
LOG(DEBUG) << "\t\t\ttype = " << channel.GetType();
|
||||
LOG(DEBUG) << "\t\t\tmethod = " << channel.GetMethod();
|
||||
LOG(DEBUG) << "\t\t\taddress = " << channel.GetAddress();
|
||||
LOG(DEBUG) << "\t\t\tproperty = " << channel.GetProperty();
|
||||
LOG(DEBUG) << "\t\t\tsndBufSize = " << channel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\t\t\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\t\t\trateLogging = " << channel.GetRateLogging();
|
||||
LOG(DEBUG) << "" << channelName << "[" << socketCounter << "]:";
|
||||
LOG(DEBUG) << "\ttype = " << channel.GetType();
|
||||
LOG(DEBUG) << "\tmethod = " << channel.GetMethod();
|
||||
LOG(DEBUG) << "\taddress = " << channel.GetAddress();
|
||||
LOG(DEBUG) << "\tproperty = " << channel.GetProperty();
|
||||
LOG(DEBUG) << "\tsndBufSize = " << channel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\trateLogging = " << channel.GetRateLogging();
|
||||
|
||||
channelList.push_back(channel);
|
||||
++socketCounter;
|
||||
}
|
||||
} // end socket loop
|
||||
|
||||
if (socketCounter)
|
||||
{
|
||||
LOG(DEBUG) << "Found " << socketCounter << " socket(s) in channel.";
|
||||
}
|
||||
else
|
||||
|
||||
if (p.first == "socket")
|
||||
{
|
||||
LOG(DEBUG) << "\t\t\tNo subChannels specified,";
|
||||
LOG(DEBUG) << "\t\t\tapplying common settings to the channel:";
|
||||
// create new channel and apply setting from the common channel
|
||||
FairMQChannel channel(commonChannel);
|
||||
|
||||
LOG(DEBUG) << "\t\t\ttype = " << channel.GetType();
|
||||
LOG(DEBUG) << "\t\t\tmethod = " << channel.GetMethod();
|
||||
LOG(DEBUG) << "\t\t\taddress = " << channel.GetAddress();
|
||||
LOG(DEBUG) << "\t\t\tproperty = " << channel.GetProperty();
|
||||
LOG(DEBUG) << "\t\t\tsndBufSize = " << channel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\t\t\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\t\t\trateLogging = " << channel.GetRateLogging();
|
||||
// if the socket field specifies or overrides something from the common channel, apply those settings
|
||||
channel.UpdateType(p.second.get<string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(p.second.get<string>("method", channel.GetMethod()));
|
||||
channel.UpdateAddress(p.second.get<string>("address", channel.GetAddress()));
|
||||
channel.UpdateProperty(p.second.get<string>("property", channel.GetProperty()));
|
||||
channel.UpdateSndBufSize(p.second.get<int>("sndBufSize", channel.GetSndBufSize()));
|
||||
channel.UpdateRcvBufSize(p.second.get<int>("rcvBufSize", channel.GetRcvBufSize()));
|
||||
channel.UpdateRateLogging(p.second.get<int>("rateLogging", channel.GetRateLogging()));
|
||||
|
||||
LOG(DEBUG) << "" << channelName << "[" << socketCounter << "]:";
|
||||
LOG(DEBUG) << "\ttype = " << channel.GetType();
|
||||
LOG(DEBUG) << "\tmethod = " << channel.GetMethod();
|
||||
LOG(DEBUG) << "\taddress = " << channel.GetAddress();
|
||||
LOG(DEBUG) << "\tproperty = " << channel.GetProperty();
|
||||
LOG(DEBUG) << "\tsndBufSize = " << channel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\trateLogging = " << channel.GetRateLogging();
|
||||
|
||||
channelList.push_back(channel);
|
||||
++socketCounter;
|
||||
}
|
||||
} // end socket loop
|
||||
|
||||
if (socketCounter)
|
||||
{
|
||||
LOG(DEBUG) << "Found " << socketCounter << " socket(s) in channel.";
|
||||
}
|
||||
} // end helper namespace
|
||||
else
|
||||
{
|
||||
LOG(DEBUG) << "" << channelName << ":";
|
||||
LOG(DEBUG) << "\tNo sockets specified,";
|
||||
LOG(DEBUG) << "\tapplying common settings to the channel:";
|
||||
|
||||
} // end FairMQParser namespace
|
||||
FairMQChannel channel(commonChannel);
|
||||
|
||||
LOG(DEBUG) << "\ttype = " << channel.GetType();
|
||||
LOG(DEBUG) << "\tmethod = " << channel.GetMethod();
|
||||
LOG(DEBUG) << "\taddress = " << channel.GetAddress();
|
||||
LOG(DEBUG) << "\tproperty = " << channel.GetProperty();
|
||||
LOG(DEBUG) << "\tsndBufSize = " << channel.GetSndBufSize();
|
||||
LOG(DEBUG) << "\trcvBufSize = " << channel.GetRcvBufSize();
|
||||
LOG(DEBUG) << "\trateLogging = " << channel.GetRateLogging();
|
||||
|
||||
channelList.push_back(channel);
|
||||
}
|
||||
}
|
||||
|
||||
} // Helper namespace
|
||||
|
||||
} // FairMQParser namespace
|
||||
|
@@ -8,16 +8,13 @@
|
||||
#ifndef FAIRMQPARSER_H
|
||||
#define FAIRMQPARSER_H
|
||||
|
||||
// std
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
// Boost
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
// FairMQ
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
namespace FairMQParser
|
||||
@@ -39,13 +36,15 @@ struct XML
|
||||
FairMQMap UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||
};
|
||||
|
||||
namespace helper
|
||||
namespace Helper
|
||||
{
|
||||
void PrintDeviceList(const boost::property_tree::ptree& tree, const std::string& formatFlag = "json");
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const std::string& deviceId, const std::string& formatFlag);
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const std::string& formatFlag);
|
||||
void SocketParser(const boost::property_tree::ptree& tree, std::vector<FairMQChannel>& channelList, const FairMQChannel& commonChannel);
|
||||
}
|
||||
|
||||
void PrintDeviceList(const boost::property_tree::ptree& tree, const std::string& formatFlag = "json");
|
||||
void DeviceParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const std::string& deviceId, const std::string& formatFlag);
|
||||
void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMap, const std::string& formatFlag);
|
||||
void SocketParser(const boost::property_tree::ptree& tree, std::vector<FairMQChannel>& channelList, const std::string& channelName, const FairMQChannel& commonChannel);
|
||||
|
||||
} // Helper namespace
|
||||
|
||||
} // FairMQParser namespace
|
||||
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <algorithm>
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQProgOptions::FairMQProgOptions()
|
||||
@@ -41,7 +42,6 @@ FairMQProgOptions::~FairMQProgOptions()
|
||||
|
||||
void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregistered)
|
||||
{
|
||||
|
||||
// init description
|
||||
InitOptionDescription();
|
||||
// parse command line options
|
||||
@@ -71,33 +71,37 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
|
||||
}
|
||||
}
|
||||
|
||||
// set log level before printing (default is 0 = DEBUG level)
|
||||
std::string verbosity = GetValue<std::string>("verbose");
|
||||
std::string verbosity = GetValue<std::string>("verbosity");
|
||||
std::string logFile = GetValue<std::string>("log-to-file");
|
||||
bool color = GetValue<bool>("log-color");
|
||||
if (!color)
|
||||
|
||||
// check if the provided verbosity level is valid, otherwise set to DEBUG
|
||||
if (fSeverityMap.count(verbosity) == 0)
|
||||
{
|
||||
reinit_logger(false);
|
||||
LOG(ERROR) << " verbosity level '" << verbosity << "' unknown, it will be set to DEBUG";
|
||||
verbosity = "DEBUG";
|
||||
}
|
||||
|
||||
if (fSeverityMap.count(verbosity))
|
||||
if (logFile != "")
|
||||
{
|
||||
DefaultConsoleSetFilter(fSeverityMap.at(verbosity));// return 1 if not success
|
||||
//set_global_log_level(log_op::operation::GREATER_EQ_THAN, fSeverityMap.at(verbosity));
|
||||
reinit_logger(false, logFile, fSeverityMap.at(verbosity));
|
||||
DefaultConsoleSetFilter(fSeverityMap.at("NOLOG"));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << " verbosity level '" << verbosity << "' unknown, it will be set to DEBUG";
|
||||
//set_global_log_level(log_op::operation::GREATER_EQ_THAN, fSeverityMap.at("DEBUG"));
|
||||
DefaultConsoleSetFilter(fSeverityMap.at("DEBUG"));
|
||||
if (!color)
|
||||
{
|
||||
reinit_logger(false);
|
||||
}
|
||||
|
||||
DefaultConsoleSetFilter(fSeverityMap.at(verbosity));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// check if one of required MQ config option is there
|
||||
auto parserOption_shptr = fMQParserOptions.options();
|
||||
auto parserOptions = fMQParserOptions.options();
|
||||
bool optionExists = false;
|
||||
vector<string> MQParserKeys;
|
||||
for (const auto& p : parserOption_shptr)
|
||||
for (const auto& p : parserOptions)
|
||||
{
|
||||
MQParserKeys.push_back(p->canonical_display_name());
|
||||
if (fVarMap.count(p->canonical_display_name()))
|
||||
@@ -164,9 +168,18 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
|
||||
{
|
||||
LOG(DEBUG) << "config-json-string: Parsing JSON string";
|
||||
|
||||
std::string id = fVarMap["id"].as<std::string>();
|
||||
std::string id;
|
||||
|
||||
std::string value = fairmq::ConvertVariableValue<fairmq::ToString>().Run(fVarMap.at("config-json-string"));
|
||||
if (fVarMap.count("config-key"))
|
||||
{
|
||||
id = fVarMap["config-key"].as<std::string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
id = fVarMap["id"].as<std::string>();
|
||||
}
|
||||
|
||||
std::string value = FairMQ::ConvertVariableValue<FairMQ::ToString>().Run(fVarMap.at("config-json-string"));
|
||||
std::stringstream ss;
|
||||
ss << value;
|
||||
UserParser<FairMQParser::JSON>(ss, id);
|
||||
@@ -175,14 +188,24 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
|
||||
{
|
||||
LOG(DEBUG) << "config-json-string: Parsing XML string";
|
||||
|
||||
std::string id = fVarMap["id"].as<std::string>();
|
||||
std::string id;
|
||||
|
||||
std::string value = fairmq::ConvertVariableValue<fairmq::ToString>().Run(fVarMap.at("config-xml-string"));
|
||||
if (fVarMap.count("config-key"))
|
||||
{
|
||||
id = fVarMap["config-key"].as<std::string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
id = fVarMap["id"].as<std::string>();
|
||||
}
|
||||
|
||||
std::string value = FairMQ::ConvertVariableValue<FairMQ::ToString>().Run(fVarMap.at("config-xml-string"));
|
||||
std::stringstream ss;
|
||||
ss << value;
|
||||
UserParser<FairMQParser::XML>(ss, id);
|
||||
}
|
||||
}
|
||||
|
||||
FairProgOptions::PrintOptions();
|
||||
}
|
||||
|
||||
@@ -301,6 +324,8 @@ void FairMQProgOptions::InitOptionDescription()
|
||||
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
|
||||
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
|
||||
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file")
|
||||
("catch-signals", po::value<int >()->default_value(1), "Enable signal handling (1/0)")
|
||||
("log-to-file", po::value<string>()->default_value(""), "Log output to a file")
|
||||
;
|
||||
|
||||
fMQOptionsInCfg.add_options()
|
||||
@@ -311,6 +336,8 @@ void FairMQProgOptions::InitOptionDescription()
|
||||
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
|
||||
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
|
||||
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file")
|
||||
("catch-signals", po::value<int >()->default_value(1), "Enable signal handling (1/0)")
|
||||
("log-to-file", po::value<string>()->default_value(""), "Log output to a file")
|
||||
;
|
||||
}
|
||||
else
|
||||
@@ -323,6 +350,8 @@ void FairMQProgOptions::InitOptionDescription()
|
||||
("control", po::value<string>()->default_value("interactive"), "States control ('interactive'/'static'/'dds').")
|
||||
("network-interface", po::value<string>()->default_value("eth0"), "Network interface to bind on (e.g. eth0, ib0, wlan0, en0, lo...).")
|
||||
("config-key", po::value<string>(), "Use provided value instead of device id for fetching the configuration from the config file")
|
||||
("catch-signals", po::value<int >()->default_value(1), "Enable signal handling (1/0)")
|
||||
("log-to-file", po::value<string>()->default_value(""), "Log output to a file")
|
||||
;
|
||||
}
|
||||
|
||||
|
@@ -20,13 +20,10 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
#include "FairProgOptions.h"
|
||||
#include "FairMQEventManager.h"
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
|
||||
|
||||
class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
{
|
||||
protected:
|
||||
@@ -98,7 +95,7 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
{
|
||||
|
||||
|
||||
if(!fairmq::is_this_type<std::string>(fVarMap.at(key)))
|
||||
if(!FairMQ::is_this_type<std::string>(fVarMap.at(key)))
|
||||
{
|
||||
LOG(ERROR) << "You try to update a value as string (for key="<< key <<") while it has been defined with a different type in the option description.";
|
||||
abort();
|
||||
@@ -238,9 +235,6 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
std::string fHelpTitle;
|
||||
std::string fVersion;
|
||||
|
||||
|
||||
|
||||
|
||||
bool EventKeyFound(const std::string& key)
|
||||
{
|
||||
if (
|
||||
@@ -251,8 +245,6 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef std::tuple<std::string,int,std::string> MQKey;//store key info
|
||||
std::map<std::string,MQKey> fMQKeyMap;// key=full path - val=key info
|
||||
|
||||
@@ -264,9 +256,7 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
void UpdateMQValues();
|
||||
int Store(const FairMQMap& channels);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/*
|
||||
// string API
|
||||
std::map<std::string, signal_type_ptr > fSignalMap;
|
||||
@@ -299,6 +289,4 @@ class FairMQProgOptions : public FairProgOptions , public FairMQEventManager
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FAIRMQPROGOPTIONS_H */
|
||||
|
||||
|
@@ -28,7 +28,7 @@ FairProgOptions::FairProgOptions() :
|
||||
fConfigFileOptions("Configuration file options"),
|
||||
fSeverityMap(),
|
||||
fVisibleOptions("Visible options"),
|
||||
fVerboseLvl("INFO"),
|
||||
fVerbosityLevel("INFO"),
|
||||
fUseConfigFile(false),
|
||||
fConfigFile()
|
||||
{
|
||||
@@ -37,27 +37,27 @@ FairProgOptions::FairProgOptions() :
|
||||
fGenericDesc.add_options()
|
||||
("help,h", "produce help")
|
||||
("version,v", "print version")
|
||||
("verbose", po::value<std::string>(&fVerboseLvl)->default_value("DEBUG"), "Verbosity level : \n"
|
||||
" TRACE \n"
|
||||
" DEBUG \n"
|
||||
" RESULTS \n"
|
||||
" INFO \n"
|
||||
" WARN \n"
|
||||
" ERROR \n"
|
||||
" STATE \n"
|
||||
" NOLOG"
|
||||
("verbosity", po::value<std::string>(&fVerbosityLevel)->default_value("DEBUG"), "Verbosity level : \n"
|
||||
" TRACE \n"
|
||||
" DEBUG \n"
|
||||
" RESULTS \n"
|
||||
" INFO \n"
|
||||
" WARN \n"
|
||||
" ERROR \n"
|
||||
" STATE \n"
|
||||
" NOLOG"
|
||||
)
|
||||
("log-color", po::value<bool>()->default_value(true), "logger color: true or false")
|
||||
;
|
||||
|
||||
fSeverityMap["TRACE"] = fairmq::severity_level::TRACE;
|
||||
fSeverityMap["DEBUG"] = fairmq::severity_level::DEBUG;
|
||||
fSeverityMap["RESULTS"] = fairmq::severity_level::RESULTS;
|
||||
fSeverityMap["INFO"] = fairmq::severity_level::INFO;
|
||||
fSeverityMap["WARN"] = fairmq::severity_level::WARN;
|
||||
fSeverityMap["ERROR"] = fairmq::severity_level::ERROR;
|
||||
fSeverityMap["STATE"] = fairmq::severity_level::STATE;
|
||||
fSeverityMap["NOLOG"] = fairmq::severity_level::NOLOG;
|
||||
fSeverityMap["TRACE"] = FairMQ::severity_level::TRACE;
|
||||
fSeverityMap["DEBUG"] = FairMQ::severity_level::DEBUG;
|
||||
fSeverityMap["RESULTS"] = FairMQ::severity_level::RESULTS;
|
||||
fSeverityMap["INFO"] = FairMQ::severity_level::INFO;
|
||||
fSeverityMap["WARN"] = FairMQ::severity_level::WARN;
|
||||
fSeverityMap["ERROR"] = FairMQ::severity_level::ERROR;
|
||||
fSeverityMap["STATE"] = FairMQ::severity_level::STATE;
|
||||
fSeverityMap["NOLOG"] = FairMQ::severity_level::NOLOG;
|
||||
}
|
||||
|
||||
/// Destructor
|
||||
@@ -221,7 +221,7 @@ string FairProgOptions::GetStringValue(const string& key)
|
||||
{
|
||||
if (fVarMap.count(key))
|
||||
{
|
||||
valueStr=fairmq::ConvertVariableValue<fairmq::ToString>().Run(fVarMap.at(key));
|
||||
valueStr=FairMQ::ConvertVariableValue<FairMQ::ToString>().Run(fVarMap.at(key));
|
||||
}
|
||||
}
|
||||
catch(exception& e)
|
||||
@@ -288,8 +288,8 @@ int FairProgOptions::PrintOptions()
|
||||
|
||||
// formatting and printing
|
||||
|
||||
LOG(INFO) << setfill ('*') << setw (totalLength + 3) << "*";// +3 because of string " = "
|
||||
string PrintOptionsTitle = " Program options found ";
|
||||
LOG(DEBUG) << setfill ('*') << setw (totalLength + 3) << "*";// +3 because of string " = "
|
||||
string PrintOptionsTitle = " Configuration ";
|
||||
|
||||
int leftSpaceLength = 0;
|
||||
int rightSpaceLength = 0;
|
||||
@@ -313,11 +313,11 @@ int FairProgOptions::PrintOptions()
|
||||
rightSpaceLength = (totalLength + 3) / 2 - rightTitleShiftLength;
|
||||
}
|
||||
|
||||
LOG(INFO) << setfill ('*') << setw(leftSpaceLength) << "*"
|
||||
LOG(DEBUG) << setfill ('*') << setw(leftSpaceLength) << "*"
|
||||
<< setw(PrintOptionsTitle.length()) << PrintOptionsTitle
|
||||
<< setfill ('*') << setw(rightSpaceLength) << "*";
|
||||
|
||||
LOG(INFO) << setfill ('*') << setw (totalLength+3) << "*";
|
||||
LOG(DEBUG) << setfill ('*') << setw (totalLength+3) << "*";
|
||||
|
||||
for (const auto& p : mapinfo)
|
||||
{
|
||||
@@ -328,7 +328,7 @@ int FairProgOptions::PrintOptions()
|
||||
string emptyStr;
|
||||
keyStr = p.first;
|
||||
tie(valueStr, typeInfoStr, defaultStr, emptyStr) = p.second;
|
||||
LOG(INFO) << std::setfill(' ')
|
||||
LOG(DEBUG) << std::setfill(' ')
|
||||
<< setw(maxLength1st) << left
|
||||
<< p.first << " = "
|
||||
<< setw(maxLength2nd)
|
||||
@@ -340,7 +340,7 @@ int FairProgOptions::PrintOptions()
|
||||
<< setw(maxLengthEmpty)
|
||||
<< emptyStr;
|
||||
}
|
||||
LOG(INFO) << setfill ('*') << setw (totalLength + 3) << "*";// +3 for " = "
|
||||
LOG(DEBUG) << setfill ('*') << setw (totalLength + 3) << "*";// +3 for " = "
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -365,5 +365,5 @@ int FairProgOptions::NotifySwitchOption()
|
||||
|
||||
FairProgOptions::VarValInfo_t FairProgOptions::GetVariableValueInfo(const po::variable_value& varValue)
|
||||
{
|
||||
return fairmq::ConvertVariableValue<fairmq::ToVarInfo>().Run(varValue);
|
||||
return FairMQ::ConvertVariableValue<FairMQ::ToVarInfo>().Run(varValue);
|
||||
}
|
||||
|
@@ -54,7 +54,6 @@
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
namespace po = boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
@@ -150,10 +149,10 @@ class FairProgOptions
|
||||
|
||||
// Description which is printed in help command line
|
||||
// to handle logger severity
|
||||
std::map<std::string,fairmq::severity_level> fSeverityMap;
|
||||
std::map<std::string, FairMQ::severity_level> fSeverityMap;
|
||||
po::options_description fVisibleOptions;
|
||||
|
||||
std::string fVerboseLvl;
|
||||
std::string fVerbosityLevel;
|
||||
bool fUseConfigFile;
|
||||
boost::filesystem::path fConfigFile;
|
||||
virtual int NotifySwitchOption();
|
||||
|
@@ -32,213 +32,205 @@ std::ostream& operator<<(std::ostream& os, const std::vector<T>& v)
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace fairmq
|
||||
namespace FairMQ
|
||||
{
|
||||
namespace po = boost::program_options;
|
||||
|
||||
//_____________________________________________________________________________________________________________________________
|
||||
namespace po = boost::program_options;
|
||||
|
||||
template<typename T>
|
||||
bool is_this_type(const po::variable_value& varValue)
|
||||
template<typename T>
|
||||
bool is_this_type(const po::variable_value& varValue)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
if (auto q = boost::any_cast<T>(&value))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::string ConvertVariableValueToString(const po::variable_value& varValue)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::ostringstream ostr;
|
||||
if (auto q = boost::any_cast<T>(&value))
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
if (auto q = boost::any_cast<T>(&value))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
ostr << *q;
|
||||
}
|
||||
std::string valueStr = ostr.str();
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________________________________________________________
|
||||
|
||||
template<typename T>
|
||||
std::string ConvertVariableValueToString(const po::variable_value& varValue)
|
||||
// string specialization
|
||||
template<>
|
||||
inline std::string ConvertVariableValueToString<std::string>(const po::variable_value& varValue)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::string valueStr;
|
||||
if (auto q = boost::any_cast<std::string>(&value))
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::ostringstream ostr;
|
||||
if (auto q = boost::any_cast<T>(&value))
|
||||
{
|
||||
ostr << *q;
|
||||
}
|
||||
std::string valueStr = ostr.str();
|
||||
return valueStr;
|
||||
valueStr = *q;
|
||||
}
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
// string specialization
|
||||
template<>
|
||||
inline std::string ConvertVariableValueToString<std::string>(const po::variable_value& varValue)
|
||||
// boost::filesystem::path specialization
|
||||
template<>
|
||||
inline std::string ConvertVariableValueToString<boost::filesystem::path>(const po::variable_value& varValue)
|
||||
{
|
||||
auto& value = varValue.value();
|
||||
std::string valueStr;
|
||||
if (auto q = boost::any_cast<boost::filesystem::path>(&value))
|
||||
{
|
||||
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 po::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;
|
||||
valueStr = (*q).string();
|
||||
}
|
||||
return valueStr;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
#endif
|
||||
//_____________________________________________________________________________________________________________________________
|
||||
// policy to convert boost variable value into string
|
||||
struct ToString
|
||||
{
|
||||
typedef std::string returned_type;
|
||||
template<typename T>
|
||||
std::string Value(const po::variable_value& varValue,const std::string&, const std::string&, const std::string&)
|
||||
{
|
||||
return ConvertVariableValueToString<T>(varValue);
|
||||
}
|
||||
|
||||
returned_type DefaultValue(const std::string&, const std::string&)
|
||||
{
|
||||
return std::string("empty value");
|
||||
}
|
||||
};
|
||||
|
||||
//_____________________________________________________________________________________________________________________________
|
||||
|
||||
// policy to convert variable value content into a tuple with value, type, defaulted, empty information
|
||||
struct ToVarInfo
|
||||
{
|
||||
typedef std::tuple<std::string, std::string,std::string, std::string> returned_type;
|
||||
template<typename T>
|
||||
returned_type Value(const po::variable_value& varValue,const std::string& type, const std::string& defaulted, const std::string& empty)
|
||||
{
|
||||
std::string valueStr = ConvertVariableValueToString<T>(varValue);
|
||||
return make_tuple(valueStr, type, defaulted, empty);
|
||||
}
|
||||
|
||||
returned_type DefaultValue(const std::string& defaulted, const std::string& empty)
|
||||
{
|
||||
return make_tuple(std::string("Unknown value"), std::string(" [Type=Unknown]"), defaulted, empty);
|
||||
}
|
||||
};
|
||||
|
||||
//_____________________________________________________________________________________________________________________________
|
||||
|
||||
// host class that take one of the two policy defined above
|
||||
// policy to convert boost variable value into string
|
||||
struct ToString
|
||||
{
|
||||
typedef std::string returned_type;
|
||||
template<typename T>
|
||||
struct ConvertVariableValue : T
|
||||
std::string Value(const po::variable_value& varValue,const std::string&, const std::string&, const std::string&)
|
||||
{
|
||||
//typename T::returned_type Run(const po::variable_value& varValue) //-> decltype(T::returned_type)
|
||||
auto Run(const po::variable_value& varValue) -> typename T::returned_type
|
||||
{
|
||||
std::string defaultedValue;
|
||||
std::string emptyValue;
|
||||
return ConvertVariableValueToString<T>(varValue);
|
||||
}
|
||||
|
||||
if (varValue.empty())
|
||||
returned_type DefaultValue(const std::string&, const std::string&)
|
||||
{
|
||||
return std::string("empty value");
|
||||
}
|
||||
};
|
||||
|
||||
// policy to convert variable value content into a tuple with value, type, defaulted, empty information
|
||||
struct ToVarInfo
|
||||
{
|
||||
typedef std::tuple<std::string, std::string,std::string, std::string> returned_type;
|
||||
template<typename T>
|
||||
returned_type Value(const po::variable_value& varValue,const std::string& type, const std::string& defaulted, const std::string& empty)
|
||||
{
|
||||
std::string valueStr = ConvertVariableValueToString<T>(varValue);
|
||||
return make_tuple(valueStr, type, defaulted, empty);
|
||||
}
|
||||
|
||||
returned_type DefaultValue(const std::string& defaulted, const std::string& empty)
|
||||
{
|
||||
return make_tuple(std::string("Unknown value"), std::string(" [Unknown]"), defaulted, empty);
|
||||
}
|
||||
};
|
||||
|
||||
// host class that take one of the two policy defined above
|
||||
template<typename T>
|
||||
struct ConvertVariableValue : T
|
||||
{
|
||||
//typename T::returned_type Run(const po::variable_value& varValue) //-> decltype(T::returned_type)
|
||||
auto Run(const po::variable_value& varValue) -> typename T::returned_type
|
||||
{
|
||||
std::string defaultedValue;
|
||||
std::string emptyValue;
|
||||
|
||||
if (varValue.empty())
|
||||
{
|
||||
emptyValue = " [empty]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (varValue.defaulted())
|
||||
{
|
||||
emptyValue = " [empty]";
|
||||
defaultedValue = " [default]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (varValue.defaulted())
|
||||
{
|
||||
defaultedValue = " [default value]";
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultedValue = " [provided value]";
|
||||
}
|
||||
defaultedValue = " [provided]";
|
||||
}
|
||||
|
||||
emptyValue += " *";
|
||||
|
||||
//////////////////////////////// std types
|
||||
// std::string albeit useless here
|
||||
if (is_this_type<std::string>(varValue))
|
||||
return T::template Value<std::string>(varValue,std::string(" [Type=string]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector<std::string>
|
||||
if (is_this_type<std::vector<std::string>>(varValue))
|
||||
return T::template Value<std::vector<std::string>>(varValue,std::string(" [Type=vector<string>]"),defaultedValue,emptyValue);
|
||||
|
||||
// int
|
||||
if (is_this_type<int>(varValue))
|
||||
return T::template Value<int>(varValue,std::string(" [Type=int]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector<int>
|
||||
if (is_this_type<std::vector<int>>(varValue))
|
||||
return T::template Value<std::vector<int>>(varValue,std::string(" [Type=vector<int>]"),defaultedValue,emptyValue);
|
||||
|
||||
// float
|
||||
if (is_this_type<float>(varValue))
|
||||
return T::template Value<float>(varValue,std::string(" [Type=float]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector float
|
||||
if (is_this_type<std::vector<float>>(varValue))
|
||||
return T::template Value<std::vector<float>>(varValue,std::string(" [Type=vector<float>]"),defaultedValue,emptyValue);
|
||||
|
||||
// double
|
||||
if (is_this_type<double>(varValue))
|
||||
return T::template Value<double>(varValue,std::string(" [Type=double]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector double
|
||||
if (is_this_type<std::vector<double>>(varValue))
|
||||
return T::template Value<std::vector<double>>(varValue,std::string(" [Type=vector<double>]"),defaultedValue,emptyValue);
|
||||
|
||||
// short
|
||||
if (is_this_type<short>(varValue))
|
||||
return T::template Value<short>(varValue,std::string(" [Type=short]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector short
|
||||
if (is_this_type<std::vector<short>>(varValue))
|
||||
return T::template Value<std::vector<short>>(varValue,std::string(" [Type=vector<short>]"),defaultedValue,emptyValue);
|
||||
|
||||
// long
|
||||
if (is_this_type<long>(varValue))
|
||||
return T::template Value<long>(varValue,std::string(" [Type=long]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector short
|
||||
if (is_this_type<std::vector<long>>(varValue))
|
||||
return T::template Value<std::vector<long>>(varValue,std::string(" [Type=vector<long>]"),defaultedValue,emptyValue);
|
||||
|
||||
// size_t
|
||||
if (is_this_type<std::size_t>(varValue))
|
||||
return T::template Value<std::size_t>(varValue,std::string(" [Type=std::size_t]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector size_t
|
||||
if (is_this_type<std::vector<std::size_t>>(varValue))
|
||||
return T::template Value<std::vector<std::size_t>>(varValue,std::string(" [Type=vector<std::size_t>]"),defaultedValue,emptyValue);
|
||||
|
||||
// bool
|
||||
if (is_this_type<bool>(varValue))
|
||||
return T::template Value<bool>(varValue,std::string(" [Type=bool]"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector bool
|
||||
if (is_this_type<std::vector<bool>>(varValue))
|
||||
return T::template Value<std::vector<bool>>(varValue,std::string(" [Type=vector<bool>]"),defaultedValue,emptyValue);
|
||||
|
||||
//////////////////////////////// boost types
|
||||
// boost::filesystem::path
|
||||
if (is_this_type<boost::filesystem::path>(varValue))
|
||||
return T::template Value<boost::filesystem::path>(varValue,std::string(" [Type=boost::filesystem::path]"),defaultedValue,emptyValue);
|
||||
|
||||
// if we get here, the type is not supported return unknown info
|
||||
return T::DefaultValue(defaultedValue,emptyValue);
|
||||
}
|
||||
|
||||
};
|
||||
// emptyValue += " *";
|
||||
|
||||
//////////////////////////////// std types
|
||||
// std::string albeit useless here
|
||||
if (is_this_type<std::string>(varValue))
|
||||
return T::template Value<std::string>(varValue,std::string(" <string>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector<std::string>
|
||||
if (is_this_type<std::vector<std::string>>(varValue))
|
||||
return T::template Value<std::vector<std::string>>(varValue,std::string(" <vector<string>>"),defaultedValue,emptyValue);
|
||||
|
||||
// int
|
||||
if (is_this_type<int>(varValue))
|
||||
return T::template Value<int>(varValue,std::string(" <int>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector<int>
|
||||
if (is_this_type<std::vector<int>>(varValue))
|
||||
return T::template Value<std::vector<int>>(varValue,std::string(" <vector<int>>"),defaultedValue,emptyValue);
|
||||
|
||||
// float
|
||||
if (is_this_type<float>(varValue))
|
||||
return T::template Value<float>(varValue,std::string(" <float>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector float
|
||||
if (is_this_type<std::vector<float>>(varValue))
|
||||
return T::template Value<std::vector<float>>(varValue,std::string(" <vector<float>>"),defaultedValue,emptyValue);
|
||||
|
||||
// double
|
||||
if (is_this_type<double>(varValue))
|
||||
return T::template Value<double>(varValue,std::string(" <double>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector double
|
||||
if (is_this_type<std::vector<double>>(varValue))
|
||||
return T::template Value<std::vector<double>>(varValue,std::string(" <vector<double>>"),defaultedValue,emptyValue);
|
||||
|
||||
// short
|
||||
if (is_this_type<short>(varValue))
|
||||
return T::template Value<short>(varValue,std::string(" <short>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector short
|
||||
if (is_this_type<std::vector<short>>(varValue))
|
||||
return T::template Value<std::vector<short>>(varValue,std::string(" <vector<short>>"),defaultedValue,emptyValue);
|
||||
|
||||
// long
|
||||
if (is_this_type<long>(varValue))
|
||||
return T::template Value<long>(varValue,std::string(" <long>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector short
|
||||
if (is_this_type<std::vector<long>>(varValue))
|
||||
return T::template Value<std::vector<long>>(varValue,std::string(" <vector<long>>"),defaultedValue,emptyValue);
|
||||
|
||||
// size_t
|
||||
if (is_this_type<std::size_t>(varValue))
|
||||
return T::template Value<std::size_t>(varValue,std::string(" <std::size_t>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector size_t
|
||||
if (is_this_type<std::vector<std::size_t>>(varValue))
|
||||
return T::template Value<std::vector<std::size_t>>(varValue,std::string(" <vector<std::size_t>>"),defaultedValue,emptyValue);
|
||||
|
||||
// bool
|
||||
if (is_this_type<bool>(varValue))
|
||||
return T::template Value<bool>(varValue,std::string(" <bool>"),defaultedValue,emptyValue);
|
||||
|
||||
// std::vector bool
|
||||
if (is_this_type<std::vector<bool>>(varValue))
|
||||
return T::template Value<std::vector<bool>>(varValue,std::string(" <vector<bool>>"),defaultedValue,emptyValue);
|
||||
|
||||
//////////////////////////////// boost types
|
||||
// boost::filesystem::path
|
||||
if (is_this_type<boost::filesystem::path>(varValue))
|
||||
return T::template Value<boost::filesystem::path>(varValue,std::string(" <boost::filesystem::path>"),defaultedValue,emptyValue);
|
||||
|
||||
// if we get here, the type is not supported return unknown info
|
||||
return T::DefaultValue(defaultedValue,emptyValue);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
} // FairMQ namespace
|
||||
|
||||
};
|
||||
#endif /* FAIRPROGOPTIONSHELPER_H */
|
||||
#endif /* FAIRPROGOPTIONSHELPER_H */
|
||||
|
@@ -115,8 +115,8 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
|
||||
// Set severity level (Default is 0=DEBUG)
|
||||
int verbose=config->GetValue<int>("verbose");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbose);
|
||||
int verbosity = config->GetValue<int>("verbosity");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbosity);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
|
||||
|
@@ -49,8 +49,8 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
|
||||
// Set severity level (Default is 0=DEBUG)
|
||||
int verbose=config.GetValue<int>("verbose");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbose);
|
||||
int verbosity=config.GetValue<int>("verbosity");
|
||||
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbosity);
|
||||
SET_LOGGER_LEVEL(lvl);
|
||||
|
||||
// parse XML file
|
||||
|
@@ -6,6 +6,6 @@ VERBOSE="DEBUG"
|
||||
JSONCONFIGFILE="@CMAKE_BINARY_DIR@/bin/config/ex1-sampler-sink.json"
|
||||
|
||||
########################## start DEVICE
|
||||
DEVICE="runConfigExample --transport $TRANSPORT --verbose $VERBOSE"
|
||||
DEVICE="runConfigExample --transport $TRANSPORT --verbosity $VERBOSE"
|
||||
DEVICE+=" --id sampler1 --mq-config $JSONCONFIGFILE"
|
||||
@CMAKE_BINARY_DIR@/bin/$DEVICE
|
||||
|
Reference in New Issue
Block a user