mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Add orthogonal OK/ERROR states.
Replace state check mutex with atomic. Update DDS example documentation.
This commit is contained in:
committed by
Mohammad Al-Turany
parent
a7ab33a10e
commit
fbf7dbf2ba
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
#include "FairMQParser.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairLogger.h"
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
|
||||
// WARNING : pragma commands to hide boost (1.54.0) warning
|
||||
@@ -34,19 +34,21 @@
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace FairMQParser
|
||||
{
|
||||
|
||||
// TODO : add key-value map<string,string> parameter for replacing/updating values from keys
|
||||
// function that convert property tree (given the xml or json structure) to FairMQMap
|
||||
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& deviceId, const std::string& rootNode, const std::string& formatFlag)
|
||||
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const string& deviceId, const string& rootNode, const string& formatFlag)
|
||||
{
|
||||
// Create fair mq map
|
||||
FairMQMap channelMap;
|
||||
|
||||
// variables to create key for the mq map. Note: maybe device name and id useless here
|
||||
std::string deviceIdKey;
|
||||
std::string channelKey;
|
||||
string deviceIdKey;
|
||||
string channelKey;
|
||||
|
||||
// do a first loop just to print the device-id in xml/json input
|
||||
for(const auto& p : pt.get_child(rootNode))
|
||||
@@ -59,13 +61,13 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
//get id attribute to choose the device
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
deviceIdKey = p.second.get<std::string>("<xmlattr>.id");
|
||||
deviceIdKey = p.second.get<string>("<xmlattr>.id");
|
||||
LOG(DEBUG) << "Found device id '" << deviceIdKey << "' in XML input";
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
deviceIdKey = p.second.get<std::string>("id");
|
||||
deviceIdKey = p.second.get<string>("id");
|
||||
LOG(DEBUG) << "Found device id '"<< deviceIdKey << "' in JSON input";
|
||||
}
|
||||
}
|
||||
@@ -82,12 +84,12 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
//get id attribute to choose the device
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
deviceIdKey = p.second.get<std::string>("<xmlattr>.id");
|
||||
deviceIdKey = p.second.get<string>("<xmlattr>.id");
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
deviceIdKey = p.second.get<std::string>("id");
|
||||
deviceIdKey = p.second.get<string>("id");
|
||||
}
|
||||
|
||||
// if not correct device id, do not fill MQMap
|
||||
@@ -97,9 +99,8 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
}
|
||||
|
||||
// print if DEBUG log level set
|
||||
std::stringstream deviceStream;
|
||||
deviceStream << "[node = " << p.first
|
||||
<< "] id = " << deviceIdKey;
|
||||
stringstream deviceStream;
|
||||
deviceStream << "[node = " << p.first << "] id = " << deviceIdKey;
|
||||
LOG(DEBUG) << deviceStream.str();
|
||||
|
||||
// for each channel in device
|
||||
@@ -113,22 +114,21 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
// get name attribute to form key
|
||||
if (formatFlag == "xml")
|
||||
{
|
||||
channelKey = q.second.get<std::string>("<xmlattr>.name");
|
||||
channelKey = q.second.get<string>("<xmlattr>.name");
|
||||
}
|
||||
|
||||
if (formatFlag == "json")
|
||||
{
|
||||
channelKey = q.second.get<std::string>("name");
|
||||
channelKey = q.second.get<string>("name");
|
||||
}
|
||||
|
||||
// print if DEBUG log level set
|
||||
std::stringstream channelStream;
|
||||
channelStream << "\t [node = " << q.first
|
||||
<< "] name = " << channelKey;
|
||||
stringstream channelStream;
|
||||
channelStream << "\t [node = " << q.first << "] name = " << channelKey;
|
||||
LOG(DEBUG) << channelStream.str();
|
||||
|
||||
// temporary FairMQChannel container
|
||||
std::vector<FairMQChannel> channelList;
|
||||
vector<FairMQChannel> channelList;
|
||||
|
||||
int socketCounter = 0;
|
||||
// for each socket in channel
|
||||
@@ -143,20 +143,19 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
FairMQChannel channel;
|
||||
|
||||
// print if DEBUG log level set
|
||||
std::stringstream socket;
|
||||
socket << "\t \t [node = " << r.first
|
||||
<< "] socket index = " << socketCounter;
|
||||
stringstream socket;
|
||||
socket << "\t \t [node = " << r.first << "] socket index = " << socketCounter;
|
||||
LOG(DEBUG) << socket.str();
|
||||
LOG(DEBUG) << "\t \t \t type = " << r.second.get<std::string>("type", channel.GetType());
|
||||
LOG(DEBUG) << "\t \t \t method = " << r.second.get<std::string>("method", channel.GetMethod());
|
||||
LOG(DEBUG) << "\t \t \t address = " << r.second.get<std::string>("address", channel.GetAddress());
|
||||
LOG(DEBUG) << "\t \t \t type = " << r.second.get<string>("type", channel.GetType());
|
||||
LOG(DEBUG) << "\t \t \t method = " << r.second.get<string>("method", channel.GetMethod());
|
||||
LOG(DEBUG) << "\t \t \t address = " << r.second.get<string>("address", channel.GetAddress());
|
||||
LOG(DEBUG) << "\t \t \t sndBufSize = " << r.second.get<int>("sndBufSize", channel.GetSndBufSize());
|
||||
LOG(DEBUG) << "\t \t \t rcvBufSize = " << r.second.get<int>("rcvBufSize", channel.GetRcvBufSize());
|
||||
LOG(DEBUG) << "\t \t \t rateLogging = " << r.second.get<int>("rateLogging", channel.GetRateLogging());
|
||||
|
||||
channel.UpdateType(r.second.get<std::string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(r.second.get<std::string>("method", channel.GetMethod()));
|
||||
channel.UpdateAddress(r.second.get<std::string>("address", channel.GetAddress()));
|
||||
channel.UpdateType(r.second.get<string>("type", channel.GetType()));
|
||||
channel.UpdateMethod(r.second.get<string>("method", channel.GetMethod()));
|
||||
channel.UpdateAddress(r.second.get<string>("address", channel.GetAddress()));
|
||||
channel.UpdateSndBufSize(r.second.get<int>("sndBufSize", channel.GetSndBufSize())); // int
|
||||
channel.UpdateRcvBufSize(r.second.get<int>("rcvBufSize", channel.GetRcvBufSize())); // int
|
||||
channel.UpdateRateLogging(r.second.get<int>("rateLogging", channel.GetRateLogging())); // int
|
||||
@@ -165,7 +164,7 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
}// end socket loop
|
||||
|
||||
//fill mq map option
|
||||
channelMap.insert(std::make_pair(channelKey,std::move(channelList)));
|
||||
channelMap.insert(make_pair(channelKey, move(channelList)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,37 +181,36 @@ FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string&
|
||||
LOG(WARN) << "---- No channel-keys found for device-id " << deviceId;
|
||||
LOG(WARN) << "---- Check the "<< formatFlag << " inputs and/or command line inputs";
|
||||
}
|
||||
|
||||
return channelMap;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
FairMQMap JSON::UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode)
|
||||
FairMQMap 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,"json");
|
||||
}
|
||||
|
||||
FairMQMap JSON::UserParser(std::stringstream& input, const std::string& deviceId, const std::string& 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,"json");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
FairMQMap XML::UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode)
|
||||
FairMQMap XML::UserParser(const string& filename, const string& deviceId, const string& rootNode)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(filename, pt);
|
||||
return ptreeToMQMap(pt,deviceId,rootNode,"xml");
|
||||
return ptreeToMQMap(pt, deviceId, rootNode, "xml");
|
||||
}
|
||||
|
||||
FairMQMap XML::UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode)
|
||||
FairMQMap XML::UserParser(stringstream& input, const string& deviceId, const string& rootNode)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_xml(input, pt);
|
||||
return ptreeToMQMap(pt,deviceId,rootNode,"xml");
|
||||
return ptreeToMQMap(pt, deviceId, rootNode, "xml");
|
||||
}
|
||||
|
||||
} // end FairMQParser namespace
|
Reference in New Issue
Block a user