Add FairMQProgOptions for configuring MQDevices

This commit is contained in:
winckler
2015-05-21 14:32:05 +02:00
parent ccd04fc54b
commit f54fbb0f59
25 changed files with 2271 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
################################################################################
# Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence version 3 (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/FairMQParser.cxx
)
Set(LIBRARY_NAME ProgOptionTest)
If (Boost_FOUND)
Set(DEPENDENCIES
boost_system boost_program_options 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)

View File

@@ -0,0 +1,252 @@
/*
* File: FairMQParser.cxx
* Author: winckler
*
* Created on May 14, 2015, 5:01 PM
*/
#include "FairMQParser.h"
#include "FairMQLogger.h"
#include <boost/property_tree/xml_parser.hpp>
// WARNING : pragma commands to hide boost (1.54.0) warning
// TODO : remove these pragma commands when boost will fix this issue in future release
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#include <boost/property_tree/json_parser.hpp>
#pragma clang diagnostic pop
namespace FairMQParser
{
no_id_exception NoIdErr;
// 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 boost_ptree_to_MQMap(const boost::property_tree::ptree& pt, const std::string& device_id, const std::string& root_node, const std::string& format_flag)
{
// Create fair mq map
FairMQMap MQChannelMap;
// variables to create key for the mq map. Note: maybe device name and id useless here
std::string kdevice_id;
std::string kchannel;
if(device_id.empty())
throw NoIdErr;
// do a first loop just to print the device-id in xml/json input
for(const auto& p : pt.get_child(root_node))
{
if (p.first != "device")
continue;
//get id attribute to choose the device
if(format_flag=="xml")
{
kdevice_id=p.second.get<std::string>("<xmlattr>.id");
MQLOG(DEBUG)<<"Found device id '"<< kdevice_id <<"' in XML input";
}
if(format_flag=="json")
{
kdevice_id=p.second.get<std::string>("id");
MQLOG(DEBUG)<<"Found device id '"<< kdevice_id <<"' in JSON input";
}
}
// Extract value from boost::property_tree
// For each device in fairMQOptions
for(const auto& p : pt.get_child(root_node))
{
if (p.first != "device")
continue;
//get id attribute to choose the device
if(format_flag=="xml")
kdevice_id=p.second.get<std::string>("<xmlattr>.id");
if(format_flag=="json")
kdevice_id=p.second.get<std::string>("id");
// if not correct device id, do not fill MQMap
if(device_id != kdevice_id)
continue;
// print if DEBUG log level set
std::stringstream ss_device;
ss_device << "[node = " << p.first
<< "] id = " << kdevice_id;
MQLOG(DEBUG)<<ss_device.str();
// for each channel in device
for(const auto& q : p.second.get_child(""))
{
if (q.first != "channel")
continue;
//get name attribute to form key
if(format_flag=="xml")
kchannel=q.second.get<std::string>("<xmlattr>.name");
if(format_flag=="json")
kchannel=q.second.get<std::string>("name");
// print if DEBUG log level set
std::stringstream ss_chan;
ss_chan << "\t [node = " << q.first
<< "] name = " << kchannel;
MQLOG(DEBUG)<<ss_chan.str();
// temporary FairMQChannel container
std::vector<FairMQChannel> channel_list;
int count_socket=0;
// for each socket in channel
for(const auto& r : q.second.get_child(""))
{
if (r.first != "socket")
continue;
count_socket++;
FairMQChannel channel;
// print if DEBUG log level set
std::stringstream ss_sock;
ss_sock << "\t \t [node = " << r.first
<< "] socket index = " << count_socket;
MQLOG(DEBUG)<<ss_sock.str();
MQLOG(DEBUG)<< "\t \t \t type = " << r.second.get<std::string>("type",channel.fType);
MQLOG(DEBUG)<< "\t \t \t method = " << r.second.get<std::string>("method",channel.fMethod);
MQLOG(DEBUG)<< "\t \t \t address = " << r.second.get<std::string>("address",channel.fAddress);
MQLOG(DEBUG)<< "\t \t \t sndBufSize = " << r.second.get<int>("sndBufSize",channel.fSndBufSize);
MQLOG(DEBUG)<< "\t \t \t rcvBufSize = " << r.second.get<int>("rcvBufSize",channel.fRcvBufSize);
MQLOG(DEBUG)<< "\t \t \t rateLogging = " << r.second.get<int>("rateLogging",channel.fRateLogging);
channel.fType = r.second.get<std::string>("type",channel.fType);
channel.fMethod = r.second.get<std::string>("method",channel.fMethod);
channel.fAddress = r.second.get<std::string>("address",channel.fAddress);
channel.fSndBufSize = r.second.get<int>("sndBufSize",channel.fSndBufSize);//int
channel.fRcvBufSize = r.second.get<int>("rcvBufSize",channel.fRcvBufSize);//int
channel.fRateLogging = r.second.get<int>("rateLogging",channel.fRateLogging);//int
channel_list.push_back(channel);
}// end socket loop
//fill mq map option
MQChannelMap.insert(std::make_pair(kchannel,std::move(channel_list)));
}
}
if(MQChannelMap.size()>0)
{
MQLOG(DEBUG)<<"---- Channel-keys found are :";
for(const auto& p : MQChannelMap)
MQLOG(DEBUG)<<p.first;
}
else
{
MQLOG(WARN)<<"---- No channel-keys found for device-id "<<device_id;
MQLOG(WARN)<<"---- Check the "<< format_flag <<" inputs and/or command line inputs";
}
return MQChannelMap;
}
////////////////////////////////////////////////////////////////////////////
//----------- filename version
FairMQMap XML::UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node)
{
boost::property_tree::ptree pt;
boost::property_tree::read_xml(filename, pt);
return boost_ptree_to_MQMap(pt,device_id,root_node,"xml");
}
//----------- stringstream version
FairMQMap XML::UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node)
{
boost::property_tree::ptree pt;
boost::property_tree::read_xml(input_ss, pt);
return boost_ptree_to_MQMap(pt,device_id,root_node,"xml");
}
////////////////////////////////////////////////////////////////////////////
FairMQMap JSON::UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node)
{
boost::property_tree::ptree pt;
boost::property_tree::read_json(filename, pt);
return boost_ptree_to_MQMap(pt,device_id,root_node,"json");
}
FairMQMap JSON::UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node)
{
boost::property_tree::ptree pt;
boost::property_tree::read_json(input_ss, pt);
return boost_ptree_to_MQMap(pt,device_id,root_node,"json");
}
// 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

View File

@@ -0,0 +1,103 @@
/*
* File: FairMQParser.h
* Author: winckler
*
* Created on May 14, 2015, 5:01 PM
*/
#ifndef FAIRMQPARSER_H
#define FAIRMQPARSER_H
// FairRoot
#include "FairMQChannel.h"
// Boost
#include <boost/property_tree/ptree.hpp>
// std
#include <string>
#include <vector>
#include <map>
namespace FairMQParser
{
typedef std::map<std::string, std::vector<FairMQChannel> > FairMQMap;
FairMQMap boost_ptree_to_MQMap(const boost::property_tree::ptree& pt, const std::string& device_id, const std::string& root_node, const std::string& format_flag="json");
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// XML ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// xml example 1
////////////////////////////////////////////////////////////////////////////
struct XML
{
FairMQMap UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node="fairMQOptions");
FairMQMap UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node="fairMQOptions");
};
// 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);
};
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// JSON ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////
struct JSON
{
FairMQMap UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node="fairMQOptions");
FairMQMap UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node="fairMQOptions");
};
////////////////////////////////////////////////////////////////////////////
// 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::boost_ptree_to_MQMap(...) function";
}
};
} // end FairMQParser namespace
#endif /* FAIRMQPARSER_H */

View File

@@ -0,0 +1,38 @@
#----------------------------------------------------
# comments :
# brackets [] are used to group options. For example :
#
# [xml.config]
# node.root = fairMQOptions
#
# is equivalent to
# xml.config.node.root = fairMQOptions
#----------------------------------------------------
config-json-filename = @CMAKE_BINARY_DIR@/bin/testJSON.json
config-xml-filename = @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

View File

@@ -0,0 +1,40 @@
{
"fairMQOptions":
{
"device":
{
"id": "bsampler1",
"channel":
{
"name": "data-out",
"socket":
{
"type": "pub",
"method": "bind",
"address": "tcp://*:5555",
"sndBufSize": "1000",
"rcvBufSize": "1000",
"rateLogging": "1"
}
}
},
"device":
{
"id": "sink1",
"channel":
{
"name": "data-in",
"socket":
{
"type": "sub",
"method": "connect",
"address": "tcp://localhost:5555",
"sndBufSize": "1000",
"rcvBufSize": "1000",
"rateLogging": "1"
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
#!/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-sjson-filename $JSONFILE"
BSAMPLER+=" --device-id bsampler1"
xterm -geometry 150x23+0+0 -hold -e @CMAKE_BINARY_DIR@/bin/$BSAMPLER &
SINK="runOptTestSink"
SINK+=" --config-json-filename $JSONFILE"
SINK+=" --device-id sink1"
xterm -geometry 150x23+0+350 -hold -e @CMAKE_BINARY_DIR@/bin/$SINK &

View File

@@ -0,0 +1,60 @@
{
"fairMQOptions": {
"device":
{
"id": "merger1",
"channel":
{
"name": "two_inputs_channel",
"socket":
{
"type": "pull",
"address": "tcp://*:5569",
"sndBufSize": "1000",
"rcvBufSize": "1000",
"rateLogging": "1"
},
"socket":
{
"type": "pull",
"method": "bind",
"address": "tcp://*:5570",
"sndBufSize": "1000",
"rcvBufSize": "1000",
"rateLogging": "1"
}
},
"channel":
{
"name": "one_output_channel",
"socket": {
"type": "push",
"method": "connect",
"address": "tcp://*:5571",
"sndBufSize": "1000",
"rcvBufSize": "1000",
"rateLogging": "1"
}
}
},
"device":
{
"id": "sink1",
"channel": {
"name": "one_input",
"socket": {
"name": "input1",
"type": "pull",
"method": "bind",
"address": "tcp://localhost:5571",
"sndBufSize": "1000",
"rcvBufSize": "1000",
"rateLogging": "1"
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
#!/bin/bash
RUN_TEST="runtestMQOption1"
if [ "$#" -gt 0 ]; then
RUN_TEST+=" $*"
fi
RUN_TEST+=" --config-xml-filename @CMAKE_BINARY_DIR@/bin/testXML.xml"
@CMAKE_BINARY_DIR@/bin/$RUN_TEST

View File

@@ -0,0 +1,59 @@
#!/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

View File

@@ -0,0 +1,10 @@
#!/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

View File

@@ -0,0 +1,11 @@
#!/bin/bash
RUN_TEST="runtestMQOption1"
if [ "$#" -gt 0 ]; then
RUN_TEST+=" $*"
fi
RUN_TEST+=" --config-json-filename @CMAKE_BINARY_DIR@/bin/testJSON.json"
@CMAKE_BINARY_DIR@/bin/$RUN_TEST

View File

@@ -0,0 +1,77 @@
#!/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

View File

@@ -0,0 +1,48 @@
<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>

View File

@@ -0,0 +1,83 @@
/*
* File: runOptTestSampler.cxx
* Author: winckler
*
* Created on June 10, 2015, 3:34 PM
*/
#include <cstdlib>
/// std
#include <iostream>
#include <string>
/// boost
#include "boost/program_options.hpp"
/// FairRoot/FairMQ
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
//////////////////////////////////////////////////////////////
/// main
//////////////////////////////////////////////////////////////
using namespace std;
using namespace FairMQParser;
using namespace boost::program_options;
int main(int argc, char** argv)
{
FairMQProgOptions config;
try
{
// //////////////////////////////////////////////////////////////
// define key specific to the BenchmarkSampler in options_description
int eventSize;
int eventRate;
int ioThreads;
options_description sampler_options("Sampler options");
sampler_options.add_options()
("event-size", value<int>(&eventSize)->default_value(1000), "Event size in bytes")
("event-rate", value<int>(&eventRate)->default_value(0), "Event rate limit in maximum number of events per second")
("io-threads", value<int>(&ioThreads)->default_value(1), "Number of I/O threads");
// and add it to cmdline option of FairMQProgOptions
config.AddToCmdLineOptions(sampler_options);
// //////////////////////////////////////////////////////////////
// enable simple config txt/INI file
//config.EnableCfgFile();
//config.AddToCfgFileOptions(sampler_options,false);
// //////////////////////////////////////////////////////////////
// Parse command line options and store in variable map
if(config.ParseAll(argc,argv,true))
return 0;
// keys defined in FairMQProgOptions
string filename=config.GetValue<string>("config-json-filename");
string deviceID=config.GetValue<string>("device-id");
// //////////////////////////////////////////////////////////////
// User defined parsing method.
config.UserParser<JSON>(filename,deviceID);
FairMQMap channels=config.GetFairMQMap();
//set device here
}
catch (exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following : ";
config.PrintHelp();
return 1;
}
return 0;
}

View File

@@ -0,0 +1,77 @@
/*
* File: runOptTestSink.cxx
* Author: winckler
*
* Created on June 10, 2015, 3:34 PM
*/
#include <cstdlib>
/// std
#include <iostream>
#include <string>
/// boost
#include "boost/program_options.hpp"
/// FairRoot/FairMQ
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
//////////////////////////////////////////////////////////////
/// main
//////////////////////////////////////////////////////////////
using namespace std;
using namespace FairMQParser;
using namespace boost::program_options;
int main(int argc, char** argv)
{
FairMQProgOptions config;
try
{
// //////////////////////////////////////////////////////////////
// define key specific to the BenchmarkSampler in options_description
int eventSize;
int eventRate;
int ioThreads;
options_description Sink_options("Sink options");
Sink_options.add_options()
("io-threads", value<int>(&ioThreads)->default_value(1), "Number of I/O threads");
// and add it to cmdline option of FairMQProgOptions
config.AddToCmdLineOptions(Sink_options);
// //////////////////////////////////////////////////////////////
// Parse command line options and store in variable map
if(config.ParseAll(argc,argv,true))
return 0;
// keys defined in FairMQProgOptions
string filename=config.GetValue<string>("config-json-filename");
string deviceID=config.GetValue<string>("device-id");
// //////////////////////////////////////////////////////////////
// User defined parsing method.
config.UserParser<JSON>(filename,deviceID);
FairMQMap channels=config.GetFairMQMap();
//set device here
}
catch (exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following : ";
config.PrintHelp();
return 1;
}
return 0;
}

View File

@@ -0,0 +1,150 @@
/// std
#include <iostream>
#include <string>
/// boost
#include "boost/program_options.hpp"
/// FairRoot/FairMQ
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
//////////////////////////////////////////////////////////////
// tests
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Parse xml from file
int testXML1(FairMQProgOptions* config)
{
LOG(INFO)<<"--------- test XML1 ---------\n";
std::string filename;
std::string XMLrootNode;
filename=config->GetValue<std::string>("config-xml-filename");
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
std::string id=config->GetValue<std::string>("device-id");
config->UserParser<FairMQParser::XML>(filename,id,XMLrootNode);
// other xml parser test
config->UserParser<FairMQParser::MQXML2>(filename);
config->UserParser<FairMQParser::MQXML3>(filename,"merger");
LOG(INFO)<<"--------- test XML1 end ---------\n";
return 0;
}
// Parse xml from command line
int testXML2(FairMQProgOptions* config)
{
LOG(INFO)<<"--------- test XML2 ---------\n";
std::string XML;
std::string XMLrootNode;
std::string id=config->GetValue<std::string>("device-id");
XMLrootNode=config->GetValue<std::string>("xml.config.node.root");
// Note: convert the vector<string> into one string with GetStringValue(key)
XML=config->GetStringValue("config-xml-string");
std::stringstream iss;
iss << XML;
config->UserParser<FairMQParser::XML>(iss,id,XMLrootNode);
LOG(INFO)<<"--------- test XML2 end ---------\n";
return 0;
}
// Parse json from file
int testJSON1(FairMQProgOptions* config)
{
LOG(INFO)<<"--------- test JSON1 ---------\n";
std::string filename;
std::string JSONrootNode;
std::string id=config->GetValue<std::string>("device-id");
filename=config->GetValue<std::string>("config-json-filename");
JSONrootNode=config->GetValue<std::string>("json.config.node.root");
config->UserParser<FairMQParser::JSON>(filename,id,JSONrootNode);
LOG(INFO)<<"--------- test JSON1 end ---------\n";
return 0;
}
// Parse json from command line
int testJSON2(FairMQProgOptions* config)
{
LOG(INFO)<<"--------- test JSON2 ---------\n";
std::string JSON;
std::string JSONrootNode;
std::string id=config->GetValue<std::string>("device-id");
JSONrootNode=config->GetValue<std::string>("json.config.node.root");
// Note: convert the vector<string> into one string with GetStringValue(key)
JSON=config->GetStringValue("config-json-string");
std::stringstream iss;
iss << JSON;
config->UserParser<FairMQParser::JSON>(iss,id,JSONrootNode);
LOG(INFO)<<"--------- test JSON2 end ---------\n";
return 0;
}
//////////////////////////////////////////////////////////////
/// main
//////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
FairMQProgOptions* config= new FairMQProgOptions();
try
{
po::options_description format_desc("XML or JSON input");
format_desc.add_options()
("xml.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "xml root node ")
("json.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "json root node ")
;
config->AddToCmdLineOptions(format_desc);
// Parse command line
if(config->ParseAll(argc,argv))
return 0;
// Set severity level (Default is 0=DEBUG)
int verbose=config->GetValue<int>("verbose");
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbose);
SET_LOGGER_LEVEL(lvl);
// Parse xml or json from cmd line or file
if(config->GetVarMap().count("config-xml-filename"))
testXML1(config);
if(config->GetVarMap().count("config-xml-string"))
testXML2(config);
if(config->GetVarMap().count("config-json-filename"))
testJSON1(config);
if(config->GetVarMap().count("config-json-string"))
testJSON2(config);
}
catch (std::exception& e)
{
LOG(ERROR) << e.what();
return 1;
}
return 0;
}

View File

@@ -0,0 +1,79 @@
/// std
#include <iostream>
#include <string>
/// boost
#include "boost/program_options.hpp"
/// FairRoot/FairMQ
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
//////////////////////////////////////////////////////////////
/// main
//////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
try
{
FairMQProgOptions config;
po::options_description format_desc("XML input");
format_desc.add_options()
("xml.config.node.root", po::value<std::string>()->default_value("fairMQOptions"), "xml root node ")
;
po::options_description io_file_opt_desc("I/O file Options");
io_file_opt_desc.add_options()
("input.file.name", po::value<std::string>(), "input file name")
("input.file.tree", po::value<std::string>(), "input tree name")
("input.file.branch", po::value<std::string>(), "input branch name")
("output.file.name", po::value<std::string>(), "output file name")
("output.file.tree", po::value<std::string>(), "output tree name")
("output.file.branch", po::value<std::string>(), "output branch name")
;
config.AddToCmdLineOptions(format_desc,true);
config.AddToCmdLineOptions(io_file_opt_desc,true);
config.EnableCfgFile();// UseConfigFile (by default config file is not defined)
config.AddToCfgFileOptions(format_desc,false);//false because already added to visible
config.AddToCfgFileOptions(io_file_opt_desc,false);
// Parse command line and config file
if(config.ParseAll(argc,argv))
return 0;
// Set severity level (Default is 0=DEBUG)
int verbose=config.GetValue<int>("verbose");
FairMQLogger::Level lvl=static_cast<FairMQLogger::Level>(verbose);
SET_LOGGER_LEVEL(lvl);
// parse XML file
std::string filename;
std::string XMLrootNode;
filename=config.GetValue<std::string>("config-xml-filename");
XMLrootNode=config.GetValue<std::string>("xml.config.node.root");
std::string id=config.GetValue<std::string>("device-id");
config.UserParser<FairMQParser::XML>(filename,id,XMLrootNode);
}
catch (std::exception& e)
{
MQLOG(ERROR) << e.what();
return 1;
}
return 0;
}