mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
Use FairMQProgOptions for Sink and BenchmarkSampler
This commit is contained in:
parent
7fda980710
commit
a3d919b763
|
@ -5,8 +5,7 @@
|
||||||
# GNU Lesser General Public Licence version 3 (LGPL) version 3, #
|
# GNU Lesser General Public Licence version 3 (LGPL) version 3, #
|
||||||
# copied verbatim in the file "LICENSE" #
|
# copied verbatim in the file "LICENSE" #
|
||||||
################################################################################
|
################################################################################
|
||||||
#Temporary for test
|
|
||||||
#add_subdirectory (options/ProgOptionTest)
|
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/bsampler-sink.json ${CMAKE_BINARY_DIR}/bin/bsampler-sink.json)
|
configure_file(${CMAKE_SOURCE_DIR}/fairmq/options/ProgOptionTest/macro/bsampler-sink.json ${CMAKE_BINARY_DIR}/bin/bsampler-sink.json)
|
||||||
|
|
||||||
Set(INCLUDE_DIRECTORIES
|
Set(INCLUDE_DIRECTORIES
|
||||||
|
|
|
@ -108,7 +108,7 @@ void FairMQDevice::InitWrapper()
|
||||||
fInitializingFinished = true;
|
fInitializingFinished = true;
|
||||||
fInitializingCondition.notify_one();
|
fInitializingCondition.notify_one();
|
||||||
|
|
||||||
ChangeState(DEVICE_READY);
|
ChangeState(internal_DEVICE_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQDevice::Init()
|
void FairMQDevice::Init()
|
||||||
|
@ -178,7 +178,7 @@ void FairMQDevice::InitTaskWrapper()
|
||||||
fInitializingTaskFinished = true;
|
fInitializingTaskFinished = true;
|
||||||
fInitializingTaskCondition.notify_one();
|
fInitializingTaskCondition.notify_one();
|
||||||
|
|
||||||
ChangeState(READY);
|
ChangeState(internal_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQDevice::InitTask()
|
void FairMQDevice::InitTask()
|
||||||
|
@ -283,7 +283,7 @@ void FairMQDevice::ResetTaskWrapper()
|
||||||
fResetTaskFinished = true;
|
fResetTaskFinished = true;
|
||||||
fResetTaskCondition.notify_one();
|
fResetTaskCondition.notify_one();
|
||||||
|
|
||||||
ChangeState(DEVICE_READY);
|
ChangeState(internal_DEVICE_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQDevice::ResetTask()
|
void FairMQDevice::ResetTask()
|
||||||
|
@ -299,7 +299,7 @@ void FairMQDevice::ResetWrapper()
|
||||||
fResetFinished = true;
|
fResetFinished = true;
|
||||||
fResetCondition.notify_one();
|
fResetCondition.notify_one();
|
||||||
|
|
||||||
ChangeState(IDLE);
|
ChangeState(internal_IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQDevice::Reset()
|
void FairMQDevice::Reset()
|
||||||
|
|
|
@ -48,14 +48,14 @@ bool FairMQStateMachine::ChangeState(int event)
|
||||||
case INIT_DEVICE:
|
case INIT_DEVICE:
|
||||||
process_event(FairMQFSM::INIT_DEVICE());
|
process_event(FairMQFSM::INIT_DEVICE());
|
||||||
return true;
|
return true;
|
||||||
case DEVICE_READY:
|
case internal_DEVICE_READY:
|
||||||
process_event(FairMQFSM::DEVICE_READY());
|
process_event(FairMQFSM::internal_DEVICE_READY());
|
||||||
return true;
|
return true;
|
||||||
case INIT_TASK:
|
case INIT_TASK:
|
||||||
process_event(FairMQFSM::INIT_TASK());
|
process_event(FairMQFSM::INIT_TASK());
|
||||||
return true;
|
return true;
|
||||||
case READY:
|
case internal_READY:
|
||||||
process_event(FairMQFSM::READY());
|
process_event(FairMQFSM::internal_READY());
|
||||||
return true;
|
return true;
|
||||||
case RUN:
|
case RUN:
|
||||||
process_event(FairMQFSM::RUN());
|
process_event(FairMQFSM::RUN());
|
||||||
|
@ -75,8 +75,8 @@ bool FairMQStateMachine::ChangeState(int event)
|
||||||
case RESET_TASK:
|
case RESET_TASK:
|
||||||
process_event(FairMQFSM::RESET_TASK());
|
process_event(FairMQFSM::RESET_TASK());
|
||||||
return true;
|
return true;
|
||||||
case IDLE:
|
case internal_IDLE:
|
||||||
process_event(FairMQFSM::IDLE());
|
process_event(FairMQFSM::internal_IDLE());
|
||||||
return true;
|
return true;
|
||||||
case END:
|
case END:
|
||||||
process_event(FairMQFSM::END());
|
process_event(FairMQFSM::END());
|
||||||
|
@ -99,18 +99,10 @@ bool FairMQStateMachine::ChangeState(std::string event)
|
||||||
{
|
{
|
||||||
return ChangeState(INIT_DEVICE);
|
return ChangeState(INIT_DEVICE);
|
||||||
}
|
}
|
||||||
if (event == "DEVICE_READY")
|
|
||||||
{
|
|
||||||
return ChangeState(DEVICE_READY);
|
|
||||||
}
|
|
||||||
if (event == "INIT_TASK")
|
if (event == "INIT_TASK")
|
||||||
{
|
{
|
||||||
return ChangeState(INIT_TASK);
|
return ChangeState(INIT_TASK);
|
||||||
}
|
}
|
||||||
if (event == "READY")
|
|
||||||
{
|
|
||||||
return ChangeState(READY);
|
|
||||||
}
|
|
||||||
else if (event == "RUN")
|
else if (event == "RUN")
|
||||||
{
|
{
|
||||||
return ChangeState(RUN);
|
return ChangeState(RUN);
|
||||||
|
@ -135,10 +127,6 @@ bool FairMQStateMachine::ChangeState(std::string event)
|
||||||
{
|
{
|
||||||
return ChangeState(RESET_TASK);
|
return ChangeState(RESET_TASK);
|
||||||
}
|
}
|
||||||
else if (event == "IDLE")
|
|
||||||
{
|
|
||||||
return ChangeState(IDLE);
|
|
||||||
}
|
|
||||||
else if (event == "END")
|
else if (event == "END")
|
||||||
{
|
{
|
||||||
return ChangeState(END);
|
return ChangeState(END);
|
||||||
|
@ -212,18 +200,10 @@ void FairMQStateMachine::WaitForEndOfState(std::string event)
|
||||||
{
|
{
|
||||||
return WaitForEndOfState(INIT_DEVICE);
|
return WaitForEndOfState(INIT_DEVICE);
|
||||||
}
|
}
|
||||||
if (event == "DEVICE_READY")
|
|
||||||
{
|
|
||||||
return WaitForEndOfState(DEVICE_READY);
|
|
||||||
}
|
|
||||||
if (event == "INIT_TASK")
|
if (event == "INIT_TASK")
|
||||||
{
|
{
|
||||||
return WaitForEndOfState(INIT_TASK);
|
return WaitForEndOfState(INIT_TASK);
|
||||||
}
|
}
|
||||||
if (event == "READY")
|
|
||||||
{
|
|
||||||
return WaitForEndOfState(READY);
|
|
||||||
}
|
|
||||||
else if (event == "RUN")
|
else if (event == "RUN")
|
||||||
{
|
{
|
||||||
return WaitForEndOfState(RUN);
|
return WaitForEndOfState(RUN);
|
||||||
|
@ -248,10 +228,6 @@ void FairMQStateMachine::WaitForEndOfState(std::string event)
|
||||||
{
|
{
|
||||||
return WaitForEndOfState(RESET_TASK);
|
return WaitForEndOfState(RESET_TASK);
|
||||||
}
|
}
|
||||||
else if (event == "IDLE")
|
|
||||||
{
|
|
||||||
return WaitForEndOfState(IDLE);
|
|
||||||
}
|
|
||||||
else if (event == "END")
|
else if (event == "END")
|
||||||
{
|
{
|
||||||
return WaitForEndOfState(END);
|
return WaitForEndOfState(END);
|
||||||
|
|
|
@ -40,16 +40,16 @@ namespace FairMQFSM
|
||||||
|
|
||||||
// defining events for the boost MSM state machine
|
// defining events for the boost MSM state machine
|
||||||
struct INIT_DEVICE {};
|
struct INIT_DEVICE {};
|
||||||
struct DEVICE_READY {};
|
struct internal_DEVICE_READY {};
|
||||||
struct INIT_TASK {};
|
struct INIT_TASK {};
|
||||||
struct READY {};
|
struct internal_READY {};
|
||||||
struct RUN {};
|
struct RUN {};
|
||||||
struct PAUSE {};
|
struct PAUSE {};
|
||||||
struct RESUME {};
|
struct RESUME {};
|
||||||
struct STOP {};
|
struct STOP {};
|
||||||
struct RESET_TASK {};
|
struct RESET_TASK {};
|
||||||
struct RESET_DEVICE {};
|
struct RESET_DEVICE {};
|
||||||
struct IDLE {};
|
struct internal_IDLE {};
|
||||||
struct END {};
|
struct END {};
|
||||||
|
|
||||||
// defining the boost MSM state machine
|
// defining the boost MSM state machine
|
||||||
|
@ -259,19 +259,19 @@ struct FairMQFSM_ : public msm::front::state_machine_def<FairMQFSM_>
|
||||||
// Transition table for FairMQFMS
|
// Transition table for FairMQFMS
|
||||||
struct transition_table : mpl::vector<
|
struct transition_table : mpl::vector<
|
||||||
// Start Event Next Action Guard
|
// Start Event Next Action Guard
|
||||||
// +-------------------------+-------------+------------------------+---------------+---------+
|
// +-------------------------+----------------------+------------------------+---------------+---------+
|
||||||
msmf::Row<IDLE_FSM, INIT_DEVICE, INITIALIZING_DEVICE_FSM, InitDeviceFct, msmf::none>,
|
msmf::Row<IDLE_FSM, INIT_DEVICE, INITIALIZING_DEVICE_FSM, InitDeviceFct, msmf::none>,
|
||||||
msmf::Row<INITIALIZING_DEVICE_FSM, DEVICE_READY, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
msmf::Row<INITIALIZING_DEVICE_FSM, internal_DEVICE_READY, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
||||||
msmf::Row<DEVICE_READY_FSM, INIT_TASK, INITIALIZING_TASK_FSM, InitTaskFct, msmf::none>,
|
msmf::Row<DEVICE_READY_FSM, INIT_TASK, INITIALIZING_TASK_FSM, InitTaskFct, msmf::none>,
|
||||||
msmf::Row<INITIALIZING_TASK_FSM, READY, READY_FSM, ReadyFct, msmf::none>,
|
msmf::Row<INITIALIZING_TASK_FSM, internal_READY, READY_FSM, ReadyFct, msmf::none>,
|
||||||
msmf::Row<READY_FSM, RUN, RUNNING_FSM, RunFct, msmf::none>,
|
msmf::Row<READY_FSM, RUN, RUNNING_FSM, RunFct, msmf::none>,
|
||||||
msmf::Row<RUNNING_FSM, PAUSE, PAUSED_FSM, PauseFct, msmf::none>,
|
msmf::Row<RUNNING_FSM, PAUSE, PAUSED_FSM, PauseFct, msmf::none>,
|
||||||
msmf::Row<PAUSED_FSM, RESUME, RUNNING_FSM, ResumeFct, msmf::none>,
|
msmf::Row<PAUSED_FSM, RESUME, RUNNING_FSM, ResumeFct, msmf::none>,
|
||||||
msmf::Row<RUNNING_FSM, STOP, READY_FSM, StopFct, msmf::none>,
|
msmf::Row<RUNNING_FSM, STOP, READY_FSM, StopFct, msmf::none>,
|
||||||
msmf::Row<READY_FSM, RESET_TASK, RESETTING_TASK_FSM, ResetTaskFct, msmf::none>,
|
msmf::Row<READY_FSM, RESET_TASK, RESETTING_TASK_FSM, ResetTaskFct, msmf::none>,
|
||||||
msmf::Row<RESETTING_TASK_FSM, DEVICE_READY, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
msmf::Row<RESETTING_TASK_FSM, internal_DEVICE_READY, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
||||||
msmf::Row<DEVICE_READY_FSM, RESET_DEVICE, RESETTING_DEVICE_FSM, ResetDeviceFct, msmf::none>,
|
msmf::Row<DEVICE_READY_FSM, RESET_DEVICE, RESETTING_DEVICE_FSM, ResetDeviceFct, msmf::none>,
|
||||||
msmf::Row<RESETTING_DEVICE_FSM, IDLE, IDLE_FSM, IdleFct, msmf::none>,
|
msmf::Row<RESETTING_DEVICE_FSM, internal_IDLE, IDLE_FSM, IdleFct, msmf::none>,
|
||||||
msmf::Row<RUNNING_FSM, END, EXITING_FSM, ExitingRunFct, msmf::none>, // temporary
|
msmf::Row<RUNNING_FSM, END, EXITING_FSM, ExitingRunFct, msmf::none>, // temporary
|
||||||
msmf::Row<IDLE_FSM, END, EXITING_FSM, ExitingFct, msmf::none> >
|
msmf::Row<IDLE_FSM, END, EXITING_FSM, ExitingFct, msmf::none> >
|
||||||
{};
|
{};
|
||||||
|
@ -349,16 +349,16 @@ class FairMQStateMachine : public FairMQFSM::FairMQFSM
|
||||||
enum Event
|
enum Event
|
||||||
{
|
{
|
||||||
INIT_DEVICE,
|
INIT_DEVICE,
|
||||||
DEVICE_READY,
|
internal_DEVICE_READY,
|
||||||
INIT_TASK,
|
INIT_TASK,
|
||||||
READY,
|
internal_READY,
|
||||||
RUN,
|
RUN,
|
||||||
PAUSE,
|
PAUSE,
|
||||||
RESUME,
|
RESUME,
|
||||||
STOP,
|
STOP,
|
||||||
RESET_TASK,
|
RESET_TASK,
|
||||||
RESET_DEVICE,
|
RESET_DEVICE,
|
||||||
IDLE,
|
internal_IDLE,
|
||||||
END
|
END
|
||||||
};
|
};
|
||||||
FairMQStateMachine();
|
FairMQStateMachine();
|
||||||
|
|
|
@ -127,8 +127,10 @@ class GenericProcessor : public FairMQDevice, public InputPolicy, public OutputP
|
||||||
{
|
{
|
||||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||||
|
|
||||||
receivedMsgs++;
|
++receivedMsgs;
|
||||||
|
|
||||||
|
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||||
|
{
|
||||||
// InputPolicy::DeSerializeMsg(msg) --> deserialize data of msg and fill output container
|
// InputPolicy::DeSerializeMsg(msg) --> deserialize data of msg and fill output container
|
||||||
// TaskPolicy::ExecuteTask( ... ) --> process output container
|
// TaskPolicy::ExecuteTask( ... ) --> process output container
|
||||||
TaskPolicy::ExecuteTask(InputPolicy::DeSerializeMsg(msg));
|
TaskPolicy::ExecuteTask(InputPolicy::DeSerializeMsg(msg));
|
||||||
|
@ -136,8 +138,6 @@ class GenericProcessor : public FairMQDevice, public InputPolicy, public OutputP
|
||||||
// OutputPolicy::fMessage point to msg
|
// OutputPolicy::fMessage point to msg
|
||||||
OutputPolicy::SetMessage(msg);
|
OutputPolicy::SetMessage(msg);
|
||||||
|
|
||||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
|
||||||
{
|
|
||||||
// TaskPolicy::GetOutputData() --> Get processed output container
|
// TaskPolicy::GetOutputData() --> Get processed output container
|
||||||
// OutputPolicy::message(...) --> Serialize output container and fill fMessage
|
// OutputPolicy::message(...) --> Serialize output container and fill fMessage
|
||||||
fChannels["data-out"].at(0).Send(OutputPolicy::SerializeMsg(TaskPolicy::GetOutputData()));
|
fChannels["data-out"].at(0).Send(OutputPolicy::SerializeMsg(TaskPolicy::GetOutputData()));
|
||||||
|
|
|
@ -1,143 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* FairMQChannel.cxx
|
|
||||||
*
|
|
||||||
* @since 2015-06-02
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include "FairMQChannel.h"
|
|
||||||
#include "FairMQLogger.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
FairMQChannel::FairMQChannel()
|
|
||||||
: fType("unspecified")
|
|
||||||
, fMethod("unspecified")
|
|
||||||
, fProtocol("unspecified")
|
|
||||||
, fAddress("unspecified")
|
|
||||||
, fPort("unspecified")
|
|
||||||
, fSndBufSize(1000)
|
|
||||||
, fRcvBufSize(1000)
|
|
||||||
, fRateLogging(1)
|
|
||||||
, fSocket()
|
|
||||||
, fIsValid(false)
|
|
||||||
, fChannelName("")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FairMQChannel::FairMQChannel(string type, string method, string protocol, string address, string port)
|
|
||||||
: fType(type)
|
|
||||||
, fMethod(method)
|
|
||||||
, fProtocol(protocol)
|
|
||||||
, fAddress(address)
|
|
||||||
, fPort(port)
|
|
||||||
, fSndBufSize(1000)
|
|
||||||
, fRcvBufSize(1000)
|
|
||||||
, fRateLogging(1)
|
|
||||||
, fSocket()
|
|
||||||
, fIsValid(false)
|
|
||||||
, fChannelName("")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FairMQChannel::ValidateChannel()
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "Validating channel " << fChannelName << "... ";
|
|
||||||
if (fIsValid)
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "Channel is already valid";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string socketTypeNames[] = { "sub", "pub", "pull", "push", "req", "rep", "xsub", "xpub", "dealer", "router", "pair" };
|
|
||||||
const set<string> socketTypes(socketTypeNames, socketTypeNames + sizeof(socketTypeNames) / sizeof(string));
|
|
||||||
if (socketTypes.find(fType) == socketTypes.end())
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "Invalid channel type: " << fType;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string socketMethodNames[] = { "bind", "connect" };
|
|
||||||
const set<string> socketMethods(socketMethodNames, socketMethodNames + sizeof(socketMethodNames) / sizeof(string));
|
|
||||||
if (socketMethods.find(fMethod) == socketMethods.end())
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "Invalid channel method: " << fMethod;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string socketProtocolNames[] = { "tcp", "ipc", "inproc" };
|
|
||||||
const set<string> socketProtocols(socketProtocolNames, socketProtocolNames + sizeof(socketProtocolNames) / sizeof(string));
|
|
||||||
if (socketProtocols.find(fProtocol) == socketProtocols.end())
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "Invalid channel protocol: " << fProtocol;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fAddress == "unspecified" && fAddress == "")
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "invalid channel address: " << fAddress;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fPort == "unspecified" && fPort == "")
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "invalid channel port: " << fPort;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fSndBufSize < 0)
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "invalid channel send buffer size: " << fSndBufSize;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fRcvBufSize < 0)
|
|
||||||
{
|
|
||||||
LOG(DEBUG) << "invalid channel receive buffer size: " << fRcvBufSize;
|
|
||||||
fIsValid = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(DEBUG) << "Channel is valid";
|
|
||||||
fIsValid = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Send(FairMQMessage* msg, const string& flag)
|
|
||||||
{
|
|
||||||
return fSocket->Send(msg, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Send(FairMQMessage* msg, const int flags)
|
|
||||||
{
|
|
||||||
return fSocket->Send(msg, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Receive(FairMQMessage* msg, const string& flag)
|
|
||||||
{
|
|
||||||
return fSocket->Receive(msg, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
int FairMQChannel::Receive(FairMQMessage* msg, const int flags)
|
|
||||||
{
|
|
||||||
return fSocket->Receive(msg, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
FairMQChannel::~FairMQChannel()
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
/********************************************************************************
|
|
||||||
* 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" *
|
|
||||||
********************************************************************************/
|
|
||||||
/**
|
|
||||||
* FairMQChannel.h
|
|
||||||
*
|
|
||||||
* @since 2015-06-02
|
|
||||||
* @author A. Rybalchenko
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FAIRMQCHANNEL_H_
|
|
||||||
#define FAIRMQCHANNEL_H_
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "FairMQSocket.h"
|
|
||||||
|
|
||||||
class FairMQChannel
|
|
||||||
{
|
|
||||||
friend class FairMQDevice;
|
|
||||||
|
|
||||||
public:
|
|
||||||
FairMQChannel();
|
|
||||||
FairMQChannel(std::string type, std::string method, std::string protocol, std::string address, std::string port);
|
|
||||||
virtual ~FairMQChannel();
|
|
||||||
|
|
||||||
bool ValidateChannel();
|
|
||||||
|
|
||||||
// Wrappers for the socket methods to simplify the usage of channels
|
|
||||||
int Send(FairMQMessage* msg, const std::string& flag="");
|
|
||||||
int Send(FairMQMessage* msg, const int flags);
|
|
||||||
int Receive(FairMQMessage* msg, const std::string& flag="");
|
|
||||||
int Receive(FairMQMessage* msg, const int flags);
|
|
||||||
|
|
||||||
std::string fType;
|
|
||||||
std::string fMethod;
|
|
||||||
std::string fProtocol;
|
|
||||||
std::string fAddress;
|
|
||||||
std::string fPort;
|
|
||||||
int fSndBufSize;
|
|
||||||
int fRcvBufSize;
|
|
||||||
int fRateLogging;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FairMQSocket* fSocket;
|
|
||||||
bool fIsValid;
|
|
||||||
std::string fChannelName;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* FAIRMQCHANNEL_H_ */
|
|
|
@ -20,95 +20,114 @@ namespace FairMQParser
|
||||||
|
|
||||||
// TODO : add key-value map<string,string> parameter for replacing/updating values from keys
|
// 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
|
// function that convert property tree (given the xml or json structure) to FairMQMap
|
||||||
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& device_id, const std::string& root_node, const std::string& format_flag)
|
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& deviceId, const std::string& rootNode, const std::string& formatFlag)
|
||||||
{
|
{
|
||||||
// Create fair mq map
|
// Create fair mq map
|
||||||
FairMQMap MQChannelMap;
|
FairMQMap MQChannelMap;
|
||||||
|
|
||||||
// variables to create key for the mq map. Note: maybe device name and id useless here
|
// variables to create key for the mq map. Note: maybe device name and id useless here
|
||||||
std::string kdevice_id;
|
std::string deviceIdKey;
|
||||||
std::string kchannel;
|
std::string channelKey;
|
||||||
|
|
||||||
// do a first loop just to print the device-id in xml/json input
|
// do a first loop just to print the device-id in xml/json input
|
||||||
for(const auto& p : pt.get_child(root_node))
|
for(const auto& p : pt.get_child(rootNode))
|
||||||
{
|
{
|
||||||
if (p.first != "device")
|
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");
|
continue;
|
||||||
MQLOG(DEBUG)<<"Found device id '"<< kdevice_id <<"' in XML input";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(format_flag=="json")
|
//get id attribute to choose the device
|
||||||
|
if (formatFlag == "xml")
|
||||||
{
|
{
|
||||||
kdevice_id=p.second.get<std::string>("id");
|
deviceIdKey = p.second.get<std::string>("<xmlattr>.id");
|
||||||
MQLOG(DEBUG)<<"Found device id '"<< kdevice_id <<"' in JSON input";
|
MQLOG(DEBUG) << "Found device id '" << deviceIdKey << "' in XML input";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formatFlag == "json")
|
||||||
|
{
|
||||||
|
deviceIdKey = p.second.get<std::string>("id");
|
||||||
|
MQLOG(DEBUG) << "Found device id '"<< deviceIdKey << "' in JSON input";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract value from boost::property_tree
|
// Extract value from boost::property_tree
|
||||||
// For each device in fairMQOptions
|
// For each device in fairMQOptions
|
||||||
for(const auto& p : pt.get_child(root_node))
|
for(const auto& p : pt.get_child(rootNode))
|
||||||
{
|
{
|
||||||
if (p.first != "device")
|
if (p.first != "device")
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//get id attribute to choose the device
|
//get id attribute to choose the device
|
||||||
if(format_flag=="xml")
|
if (formatFlag == "xml")
|
||||||
kdevice_id=p.second.get<std::string>("<xmlattr>.id");
|
{
|
||||||
|
deviceIdKey = p.second.get<std::string>("<xmlattr>.id");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formatFlag == "json")
|
||||||
|
{
|
||||||
|
deviceIdKey = p.second.get<std::string>("id");
|
||||||
|
}
|
||||||
|
|
||||||
if(format_flag=="json")
|
|
||||||
kdevice_id=p.second.get<std::string>("id");
|
|
||||||
// if not correct device id, do not fill MQMap
|
// if not correct device id, do not fill MQMap
|
||||||
if(device_id != kdevice_id)
|
if (deviceId != deviceIdKey)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// print if DEBUG log level set
|
// print if DEBUG log level set
|
||||||
std::stringstream ss_device;
|
std::stringstream deviceStream;
|
||||||
ss_device << "[node = " << p.first
|
deviceStream << "[node = " << p.first
|
||||||
<< "] id = " << kdevice_id;
|
<< "] id = " << deviceIdKey;
|
||||||
MQLOG(DEBUG)<<ss_device.str();
|
MQLOG(DEBUG) << deviceStream.str();
|
||||||
|
|
||||||
// for each channel in device
|
// for each channel in device
|
||||||
for(const auto& q : p.second.get_child(""))
|
for(const auto& q : p.second.get_child(""))
|
||||||
{
|
{
|
||||||
if (q.first != "channel")
|
if (q.first != "channel")
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//get name attribute to form key
|
//get name attribute to form key
|
||||||
if(format_flag=="xml")
|
if (formatFlag == "xml")
|
||||||
kchannel=q.second.get<std::string>("<xmlattr>.name");
|
{
|
||||||
|
channelKey = q.second.get<std::string>("<xmlattr>.name");
|
||||||
|
}
|
||||||
|
|
||||||
if(format_flag=="json")
|
if (formatFlag=="json")
|
||||||
kchannel=q.second.get<std::string>("name");
|
{
|
||||||
|
channelKey = q.second.get<std::string>("name");
|
||||||
|
}
|
||||||
|
|
||||||
// print if DEBUG log level set
|
// print if DEBUG log level set
|
||||||
std::stringstream ss_chan;
|
std::stringstream channelStream;
|
||||||
ss_chan << "\t [node = " << q.first
|
channelStream << "\t [node = " << q.first
|
||||||
<< "] name = " << kchannel;
|
<< "] name = " << channelKey;
|
||||||
MQLOG(DEBUG)<<ss_chan.str();
|
MQLOG(DEBUG) << channelStream.str();
|
||||||
|
|
||||||
// temporary FairMQChannel container
|
// temporary FairMQChannel container
|
||||||
std::vector<FairMQChannel> channel_list;
|
std::vector<FairMQChannel> channelList;
|
||||||
|
|
||||||
int count_socket=0;
|
int socketCounter = 0;
|
||||||
// for each socket in channel
|
// for each socket in channel
|
||||||
for (const auto& r : q.second.get_child(""))
|
for (const auto& r : q.second.get_child(""))
|
||||||
{
|
{
|
||||||
if (r.first != "socket")
|
if (r.first != "socket")
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
count_socket++;
|
++socketCounter;
|
||||||
FairMQChannel channel;
|
FairMQChannel channel;
|
||||||
|
|
||||||
// print if DEBUG log level set
|
// print if DEBUG log level set
|
||||||
std::stringstream ss_sock;
|
std::stringstream socket;
|
||||||
ss_sock << "\t \t [node = " << r.first
|
socket << "\t \t [node = " << r.first
|
||||||
<< "] socket index = " << count_socket;
|
<< "] socket index = " << socketCounter;
|
||||||
MQLOG(DEBUG)<<ss_sock.str();
|
MQLOG(DEBUG) << socket.str();
|
||||||
MQLOG(DEBUG) << "\t \t \t type = " << r.second.get<std::string>("type", channel.fType);
|
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 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 address = " << r.second.get<std::string>("address", channel.fAddress);
|
||||||
|
@ -116,7 +135,6 @@ namespace FairMQParser
|
||||||
MQLOG(DEBUG) << "\t \t \t rcvBufSize = " << r.second.get<int>("rcvBufSize", channel.fRcvBufSize);
|
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);
|
MQLOG(DEBUG) << "\t \t \t rateLogging = " << r.second.get<int>("rateLogging", channel.fRateLogging);
|
||||||
|
|
||||||
|
|
||||||
channel.fType = r.second.get<std::string>("type", channel.fType);
|
channel.fType = r.second.get<std::string>("type", channel.fType);
|
||||||
channel.fMethod = r.second.get<std::string>("method", channel.fMethod);
|
channel.fMethod = r.second.get<std::string>("method", channel.fMethod);
|
||||||
channel.fAddress = r.second.get<std::string>("address", channel.fAddress);
|
channel.fAddress = r.second.get<std::string>("address", channel.fAddress);
|
||||||
|
@ -124,11 +142,11 @@ namespace FairMQParser
|
||||||
channel.fRcvBufSize = r.second.get<int>("rcvBufSize", channel.fRcvBufSize); // int
|
channel.fRcvBufSize = r.second.get<int>("rcvBufSize", channel.fRcvBufSize); // int
|
||||||
channel.fRateLogging = r.second.get<int>("rateLogging", channel.fRateLogging); // int
|
channel.fRateLogging = r.second.get<int>("rateLogging", channel.fRateLogging); // int
|
||||||
|
|
||||||
channel_list.push_back(channel);
|
channelList.push_back(channel);
|
||||||
}// end socket loop
|
}// end socket loop
|
||||||
|
|
||||||
//fill mq map option
|
//fill mq map option
|
||||||
MQChannelMap.insert(std::make_pair(kchannel,std::move(channel_list)));
|
MQChannelMap.insert(std::make_pair(channelKey,std::move(channelList)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,33 +154,31 @@ namespace FairMQParser
|
||||||
{
|
{
|
||||||
MQLOG(DEBUG) << "---- Channel-keys found are :";
|
MQLOG(DEBUG) << "---- Channel-keys found are :";
|
||||||
for (const auto& p : MQChannelMap)
|
for (const auto& p : MQChannelMap)
|
||||||
|
{
|
||||||
MQLOG(DEBUG) << p.first;
|
MQLOG(DEBUG) << p.first;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MQLOG(WARN)<<"---- No channel-keys found for device-id "<<device_id;
|
MQLOG(WARN) << "---- No channel-keys found for device-id " << deviceId;
|
||||||
MQLOG(WARN)<<"---- Check the "<< format_flag <<" inputs and/or command line inputs";
|
MQLOG(WARN) << "---- Check the "<< formatFlag << " inputs and/or command line inputs";
|
||||||
}
|
}
|
||||||
return MQChannelMap;
|
return MQChannelMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
FairMQMap JSON::UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node)
|
FairMQMap JSON::UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode)
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
boost::property_tree::read_json(filename, pt);
|
boost::property_tree::read_json(filename, pt);
|
||||||
return ptreeToMQMap(pt,device_id,root_node,"json");
|
return ptreeToMQMap(pt, deviceId, rootNode,"json");
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQMap JSON::UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node)
|
FairMQMap JSON::UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode)
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree pt;
|
boost::property_tree::ptree pt;
|
||||||
boost::property_tree::read_json(input_ss, pt);
|
boost::property_tree::read_json(input, pt);
|
||||||
return ptreeToMQMap(pt,device_id,root_node,"json");
|
return ptreeToMQMap(pt, deviceId, rootNode,"json");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end FairMQParser namespace
|
} // end FairMQParser namespace
|
|
@ -8,31 +8,30 @@
|
||||||
#ifndef FAIRMQPARSER_H
|
#ifndef FAIRMQPARSER_H
|
||||||
#define FAIRMQPARSER_H
|
#define FAIRMQPARSER_H
|
||||||
|
|
||||||
// FairRoot
|
|
||||||
#include "FairMQChannel.h"
|
|
||||||
|
|
||||||
// Boost
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
|
||||||
|
|
||||||
// std
|
// std
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
// Boost
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
|
||||||
|
// FairMQ
|
||||||
|
#include "FairMQChannel.h"
|
||||||
|
|
||||||
namespace FairMQParser
|
namespace FairMQParser
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef std::map< std::string,std::vector<FairMQChannel> > FairMQMap;
|
typedef std::map< std::string,std::vector<FairMQChannel> > FairMQMap;
|
||||||
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& device_id, const std::string& root_node, const std::string& format_flag="json");
|
|
||||||
|
FairMQMap ptreeToMQMap(const boost::property_tree::ptree& pt, const std::string& deviceId, const std::string& rootNode, const std::string& formatFlag = "json");
|
||||||
|
|
||||||
struct JSON
|
struct JSON
|
||||||
{
|
{
|
||||||
FairMQMap UserParser(const std::string& filename, const std::string& device_id, const std::string& root_node="fairMQOptions");
|
FairMQMap UserParser(const std::string& filename, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||||
FairMQMap UserParser(std::stringstream& input_ss, const std::string& device_id, const std::string& root_node="fairMQOptions");
|
FairMQMap UserParser(std::stringstream& input, const std::string& deviceId, const std::string& rootNode = "fairMQOptions");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // FairMQParser namespace
|
||||||
} // end FairMQParser namespace
|
|
||||||
#endif /* FAIRMQPARSER_H */
|
#endif /* FAIRMQPARSER_H */
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
#include "FairMQProgOptions.h"
|
#include "FairMQProgOptions.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
FairMQProgOptions::FairMQProgOptions() :
|
FairMQProgOptions::FairMQProgOptions()
|
||||||
FairProgOptions(),
|
: FairProgOptions()
|
||||||
fMQParserOptions("MQ-Device parser options"),
|
, fMQParserOptions("MQ-Device parser options")
|
||||||
fMQtree(),
|
, fMQtree()
|
||||||
fFairMQmap()
|
, fFairMQmap()
|
||||||
{
|
{
|
||||||
InitOptionDescription();
|
InitOptionDescription();
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,6 @@ FairMQProgOptions::~FairMQProgOptions()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregistered)
|
int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregistered)
|
||||||
{
|
{
|
||||||
// before parsing, define cmdline and optionally cfgfile description,
|
// before parsing, define cmdline and optionally cfgfile description,
|
||||||
|
@ -40,16 +38,19 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregiste
|
||||||
("device-id", po::value< std::string >()->required(), "Device ID");
|
("device-id", po::value< std::string >()->required(), "Device ID");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
fCmdline_options.add_options()
|
fCmdline_options.add_options()
|
||||||
("device-id", po::value< std::string >()->required(), "Device ID");
|
("device-id", po::value< std::string >()->required(), "Device ID");
|
||||||
|
}
|
||||||
|
|
||||||
fVisible_options.add_options()
|
fVisible_options.add_options()
|
||||||
("device-id", po::value< std::string >()->required(), "Device ID (required value)");
|
("device-id", po::value< std::string >()->required(), "Device ID (required value)");
|
||||||
|
|
||||||
|
|
||||||
// parse command line
|
// parse command line
|
||||||
if (ParseCmdLine(argc,argv,fCmdline_options,fvarmap,AllowUnregistered))
|
if (ParseCmdLine(argc,argv,fCmdline_options,fvarmap,AllowUnregistered))
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// if txt/INI configuration file enabled then parse it
|
// if txt/INI configuration file enabled then parse it
|
||||||
if (fUseConfigFile && !fConfigFile.empty())
|
if (fUseConfigFile && !fConfigFile.empty())
|
||||||
|
@ -57,9 +58,10 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregiste
|
||||||
AddToCfgFileOptions(fMQParserOptions,false);
|
AddToCfgFileOptions(fMQParserOptions,false);
|
||||||
|
|
||||||
if (ParseCfgFile(fConfigFile, fConfig_file_options, fvarmap, AllowUnregistered))
|
if (ParseCfgFile(fConfigFile, fConfig_file_options, fvarmap, AllowUnregistered))
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set log level before printing (default is 0 = DEBUG level)
|
// set log level before printing (default is 0 = DEBUG level)
|
||||||
int verbose=GetValue<int>("verbose");
|
int verbose=GetValue<int>("verbose");
|
||||||
|
@ -70,9 +72,6 @@ int FairMQProgOptions::ParseAll(const int argc, char** argv, bool AllowUnregiste
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int FairMQProgOptions::NotifySwitchOption()
|
int FairMQProgOptions::NotifySwitchOption()
|
||||||
{
|
{
|
||||||
if ( fvarmap.count("help") )
|
if ( fvarmap.count("help") )
|
||||||
|
@ -102,5 +101,4 @@ void FairMQProgOptions::InitOptionDescription()
|
||||||
// ("ini.config.string", po::value< std::vector<std::string> >()->multitoken(), "INI input as command line string.")
|
// ("ini.config.string", po::value< std::vector<std::string> >()->multitoken(), "INI input as command line string.")
|
||||||
// ("ini.config.filename", po::value< std::string >(), "INI input as file.")
|
// ("ini.config.filename", po::value< std::string >(), "INI input as file.")
|
||||||
;
|
;
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@ public:
|
||||||
virtual ~FairMQProgOptions();
|
virtual ~FairMQProgOptions();
|
||||||
virtual int ParseAll(const int argc, char** argv, bool AllowUnregistered = false);
|
virtual int ParseAll(const int argc, char** argv, bool AllowUnregistered = false);
|
||||||
|
|
||||||
|
|
||||||
// external parser, store function
|
// external parser, store function
|
||||||
template <typename T, typename ...Args>
|
template <typename T, typename ...Args>
|
||||||
int UserParser(Args &&... args)
|
int UserParser(Args &&... args)
|
||||||
|
@ -59,13 +58,11 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FairMQMap GetFairMQMap()
|
FairMQMap GetFairMQMap()
|
||||||
{
|
{
|
||||||
return fFairMQmap;
|
return fFairMQmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
po::options_description fMQParserOptions;
|
po::options_description fMQParserOptions;
|
||||||
pt::ptree fMQtree;
|
pt::ptree fMQtree;
|
||||||
|
|
|
@ -53,10 +53,8 @@ template<class T>
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
|
||||||
class FairProgOptions
|
class FairProgOptions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -72,23 +70,28 @@ public:
|
||||||
{
|
{
|
||||||
fUseConfigFile = true;
|
fUseConfigFile = true;
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
|
{
|
||||||
fCmdline_options.add_options()
|
fCmdline_options.add_options()
|
||||||
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
|
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
|
||||||
else
|
|
||||||
fConfigFile=filename;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fConfigFile = filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UseConfigFile(const std::string& filename = "")
|
void UseConfigFile(const std::string& filename = "")
|
||||||
{
|
{
|
||||||
fUseConfigFile = true;
|
fUseConfigFile = true;
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
|
{
|
||||||
fCmdline_options.add_options()
|
fCmdline_options.add_options()
|
||||||
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
|
("config,c", po::value<std::string>(&fConfigFile)->required(), "Path to configuration file");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
fConfigFile = filename;
|
fConfigFile = filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set value corresponding to the key
|
// set value corresponding to the key
|
||||||
|
@ -99,7 +102,9 @@ public:
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (fvarmap.count(key))
|
if (fvarmap.count(key))
|
||||||
|
{
|
||||||
val = fvarmap[key].as<T>();
|
val = fvarmap[key].as<T>();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG(ERROR) << "Key '"<< key <<"' not found in boost variable map";
|
LOG(ERROR) << "Key '"<< key <<"' not found in boost variable map";
|
||||||
|
@ -130,7 +135,6 @@ public:
|
||||||
int ParseCfgFile(std::ifstream& ifs, const po::options_description& desc, po::variables_map& varmap, bool AllowUnregistered = false);
|
int ParseCfgFile(std::ifstream& ifs, const po::options_description& desc, po::variables_map& varmap, bool AllowUnregistered = false);
|
||||||
int ParseCfgFile(std::ifstream& ifs, const po::options_description& desc, bool AllowUnregistered = false);
|
int ParseCfgFile(std::ifstream& ifs, const po::options_description& desc, bool AllowUnregistered = false);
|
||||||
|
|
||||||
|
|
||||||
int ParseEnvironment(const std::function<std::string(std::string)>&);
|
int ParseEnvironment(const std::function<std::string(std::string)>&);
|
||||||
|
|
||||||
virtual int ParseAll(const int argc, char** argv, bool AllowUnregistered = false) = 0;
|
virtual int ParseAll(const int argc, char** argv, bool AllowUnregistered = false) = 0;
|
||||||
|
@ -139,7 +143,6 @@ public:
|
||||||
int PrintHelp() const;
|
int PrintHelp() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// options container
|
// options container
|
||||||
po::variables_map fvarmap;
|
po::variables_map fvarmap;
|
||||||
|
|
||||||
|
@ -175,7 +178,6 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// /////////////////////////////////////////////
|
// /////////////////////////////////////////////
|
||||||
// Methods below are helper functions used in the PrintOptions method
|
// Methods below are helper functions used in the PrintOptions method
|
||||||
typedef std::tuple<std::string, std::string,std::string, std::string> VarValInfo_t;
|
typedef std::tuple<std::string, std::string,std::string, std::string> VarValInfo_t;
|
||||||
|
@ -189,7 +191,9 @@ private:
|
||||||
auto& value = var_val.value();
|
auto& value = var_val.value();
|
||||||
std::ostringstream ostr;
|
std::ostringstream ostr;
|
||||||
if (auto q = boost::any_cast<T>(&value))
|
if (auto q = boost::any_cast<T>(&value))
|
||||||
|
{
|
||||||
ostr << *q;
|
ostr << *q;
|
||||||
|
}
|
||||||
std::string val_str = ostr.str();
|
std::string val_str = ostr.str();
|
||||||
return val_str;
|
return val_str;
|
||||||
}
|
}
|
||||||
|
@ -197,8 +201,10 @@ private:
|
||||||
static void Max(int &val, const int &comp)
|
static void Max(int &val, const int &comp)
|
||||||
{
|
{
|
||||||
if (comp > val)
|
if (comp > val)
|
||||||
|
{
|
||||||
val = comp;
|
val = comp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include "boost/program_options.hpp"
|
#include "boost/program_options.hpp"
|
||||||
|
|
||||||
#include "FairMQLogger.h"
|
#include "FairMQLogger.h"
|
||||||
|
#include "FairMQParser.h"
|
||||||
|
#include "FairMQProgOptions.h"
|
||||||
#include "FairMQBenchmarkSampler.h"
|
#include "FairMQBenchmarkSampler.h"
|
||||||
|
|
||||||
#ifdef NANOMSG
|
#ifdef NANOMSG
|
||||||
|
@ -27,6 +29,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace FairMQParser;
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
FairMQBenchmarkSampler sampler;
|
FairMQBenchmarkSampler sampler;
|
||||||
|
|
||||||
|
@ -36,7 +40,7 @@ static void s_signal_handler(int signal)
|
||||||
|
|
||||||
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
||||||
|
|
||||||
LOG(INFO) << "Shutdown complete";
|
LOG(INFO) << "Shutdown complete.";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,98 +54,39 @@ static void s_catch_signals(void)
|
||||||
sigaction(SIGTERM, &action, NULL);
|
sigaction(SIGTERM, &action, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct DeviceOptions
|
|
||||||
{
|
|
||||||
DeviceOptions() :
|
|
||||||
id(), eventSize(0), eventRate(0), ioThreads(0),
|
|
||||||
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress()
|
|
||||||
{}
|
|
||||||
|
|
||||||
string id;
|
|
||||||
int eventSize;
|
|
||||||
int eventRate;
|
|
||||||
int ioThreads;
|
|
||||||
string outputSocketType;
|
|
||||||
int outputBufSize;
|
|
||||||
string outputMethod;
|
|
||||||
string outputAddress;
|
|
||||||
} DeviceOptions_t;
|
|
||||||
|
|
||||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|
||||||
{
|
|
||||||
if (_options == NULL)
|
|
||||||
throw runtime_error("Internal error: options' container is empty.");
|
|
||||||
|
|
||||||
namespace bpo = boost::program_options;
|
|
||||||
bpo::options_description desc("Options");
|
|
||||||
desc.add_options()
|
|
||||||
("id", bpo::value<string>()->required(), "Device ID")
|
|
||||||
("event-size", bpo::value<int>()->default_value(1000), "Event size in bytes")
|
|
||||||
("event-rate", bpo::value<int>()->default_value(0), "Event rate limit in maximum number of events per second")
|
|
||||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
|
||||||
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
|
|
||||||
("output-buff-size", bpo::value<int>()->default_value(1000), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
|
||||||
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
|
|
||||||
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://*:5555\"")
|
|
||||||
("help", "Print help messages");
|
|
||||||
|
|
||||||
bpo::variables_map vm;
|
|
||||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
|
||||||
|
|
||||||
if (vm.count("help"))
|
|
||||||
{
|
|
||||||
LOG(INFO) << "FairMQ Benchmark Sampler" << endl << desc;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bpo::notify(vm);
|
|
||||||
|
|
||||||
if (vm.count("id"))
|
|
||||||
_options->id = vm["id"].as<string>();
|
|
||||||
|
|
||||||
if (vm.count("event-size"))
|
|
||||||
_options->eventSize = vm["event-size"].as<int>();
|
|
||||||
|
|
||||||
if (vm.count("event-rate"))
|
|
||||||
_options->eventRate = vm["event-rate"].as<int>();
|
|
||||||
|
|
||||||
if (vm.count("io-threads"))
|
|
||||||
_options->ioThreads = vm["io-threads"].as<int>();
|
|
||||||
|
|
||||||
if (vm.count("output-socket-type"))
|
|
||||||
_options->outputSocketType = vm["output-socket-type"].as<string>();
|
|
||||||
|
|
||||||
if (vm.count("output-buff-size"))
|
|
||||||
_options->outputBufSize = vm["output-buff-size"].as<int>();
|
|
||||||
|
|
||||||
if (vm.count("output-method"))
|
|
||||||
_options->outputMethod = vm["output-method"].as<string>();
|
|
||||||
|
|
||||||
if (vm.count("output-address"))
|
|
||||||
_options->outputAddress = vm["output-address"].as<string>();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
s_catch_signals();
|
s_catch_signals();
|
||||||
|
|
||||||
DeviceOptions_t options;
|
FairMQProgOptions config;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!parse_cmd_line(argc, argv, &options))
|
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");
|
||||||
|
|
||||||
|
config.AddToCmdLineOptions(sampler_options);
|
||||||
|
|
||||||
|
if (config.ParseAll(argc, argv))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (exception& e)
|
|
||||||
{
|
string filename = config.GetValue<string>("config-json-filename");
|
||||||
LOG(ERROR) << e.what();
|
string id = config.GetValue<string>("device-id");
|
||||||
return 1;
|
|
||||||
}
|
config.UserParser<JSON>(filename, id);
|
||||||
|
|
||||||
|
sampler.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
LOG(INFO) << "PID: " << getpid();
|
LOG(INFO) << "PID: " << getpid();
|
||||||
LOG(INFO) << "CONFIG: " << "id: " << options.id << ", event size: " << options.eventSize << ", event rate: " << options.eventRate << ", I/O threads: " << options.ioThreads;
|
|
||||||
LOG(INFO) << "OUTPUT: " << options.outputSocketType << " " << options.outputBufSize << " " << options.outputMethod << " " << options.outputAddress;
|
|
||||||
|
|
||||||
#ifdef NANOMSG
|
#ifdef NANOMSG
|
||||||
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||||
|
@ -151,17 +96,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
sampler.SetTransport(transportFactory);
|
sampler.SetTransport(transportFactory);
|
||||||
|
|
||||||
FairMQChannel channel(options.outputSocketType, options.outputMethod, options.outputAddress);
|
sampler.SetProperty(FairMQBenchmarkSampler::Id, id);
|
||||||
channel.fSndBufSize = options.outputBufSize;
|
sampler.SetProperty(FairMQBenchmarkSampler::EventSize, eventSize);
|
||||||
channel.fRcvBufSize = options.outputBufSize;
|
sampler.SetProperty(FairMQBenchmarkSampler::EventRate, eventRate);
|
||||||
channel.fRateLogging = 1;
|
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, ioThreads);
|
||||||
|
|
||||||
sampler.fChannels["data-out"].push_back(channel);
|
|
||||||
|
|
||||||
sampler.SetProperty(FairMQBenchmarkSampler::Id, options.id);
|
|
||||||
sampler.SetProperty(FairMQBenchmarkSampler::EventSize, options.eventSize);
|
|
||||||
sampler.SetProperty(FairMQBenchmarkSampler::EventRate, options.eventRate);
|
|
||||||
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, options.ioThreads);
|
|
||||||
|
|
||||||
sampler.ChangeState(FairMQBenchmarkSampler::INIT_DEVICE);
|
sampler.ChangeState(FairMQBenchmarkSampler::INIT_DEVICE);
|
||||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_DEVICE);
|
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_DEVICE);
|
||||||
|
@ -182,5 +120,14 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
LOG(ERROR) << e.what();
|
||||||
|
LOG(INFO) << "Command line options are the following : ";
|
||||||
|
config.PrintHelp();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* runSink.cxx
|
* runSink.cxx
|
||||||
*
|
*
|
||||||
* @since 2013-01-21
|
* @since 2013-01-21
|
||||||
* @author D. Klein, A. Rybalchenko
|
* @author: D. Klein, A. Rybalchenko
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -18,6 +18,8 @@
|
||||||
#include "boost/program_options.hpp"
|
#include "boost/program_options.hpp"
|
||||||
|
|
||||||
#include "FairMQLogger.h"
|
#include "FairMQLogger.h"
|
||||||
|
#include "FairMQParser.h"
|
||||||
|
#include "FairMQProgOptions.h"
|
||||||
#include "FairMQSink.h"
|
#include "FairMQSink.h"
|
||||||
|
|
||||||
#ifdef NANOMSG
|
#ifdef NANOMSG
|
||||||
|
@ -27,6 +29,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace FairMQParser;
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
FairMQSink sink;
|
FairMQSink sink;
|
||||||
|
|
||||||
|
@ -50,84 +54,33 @@ static void s_catch_signals(void)
|
||||||
sigaction(SIGTERM, &action, NULL);
|
sigaction(SIGTERM, &action, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct DeviceOptions
|
|
||||||
{
|
|
||||||
DeviceOptions() :
|
|
||||||
id(), ioThreads(0),
|
|
||||||
inputSocketType(), inputBufSize(0), inputMethod(), inputAddress()
|
|
||||||
{}
|
|
||||||
|
|
||||||
string id;
|
|
||||||
int ioThreads;
|
|
||||||
string inputSocketType;
|
|
||||||
int inputBufSize;
|
|
||||||
string inputMethod;
|
|
||||||
string inputAddress;
|
|
||||||
} DeviceOptions_t;
|
|
||||||
|
|
||||||
inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|
||||||
{
|
|
||||||
if (_options == NULL)
|
|
||||||
throw runtime_error("Internal error: options' container is empty.");
|
|
||||||
|
|
||||||
namespace bpo = boost::program_options;
|
|
||||||
bpo::options_description desc("Options");
|
|
||||||
desc.add_options()
|
|
||||||
("id", bpo::value<string>()->required(), "Device ID")
|
|
||||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
|
||||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
|
||||||
("input-buff-size", bpo::value<int>()->default_value(1000), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
|
||||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
|
||||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://*:5555\"")
|
|
||||||
("help", "Print help messages");
|
|
||||||
|
|
||||||
bpo::variables_map vm;
|
|
||||||
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
|
|
||||||
|
|
||||||
if ( vm.count("help") )
|
|
||||||
{
|
|
||||||
LOG(INFO) << "FairMQ Sink" << endl << desc;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bpo::notify(vm);
|
|
||||||
|
|
||||||
if ( vm.count("id") )
|
|
||||||
_options->id = vm["id"].as<string>();
|
|
||||||
|
|
||||||
if ( vm.count("io-threads") )
|
|
||||||
_options->ioThreads = vm["io-threads"].as<int>();
|
|
||||||
|
|
||||||
if ( vm.count("input-socket-type") )
|
|
||||||
_options->inputSocketType = vm["input-socket-type"].as<string>();
|
|
||||||
|
|
||||||
if ( vm.count("input-buff-size") )
|
|
||||||
_options->inputBufSize = vm["input-buff-size"].as<int>();
|
|
||||||
|
|
||||||
if ( vm.count("input-method") )
|
|
||||||
_options->inputMethod = vm["input-method"].as<string>();
|
|
||||||
|
|
||||||
if ( vm.count("input-address") )
|
|
||||||
_options->inputAddress = vm["input-address"].as<string>();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
s_catch_signals();
|
s_catch_signals();
|
||||||
|
|
||||||
DeviceOptions_t options;
|
FairMQProgOptions config;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!parse_cmd_line(argc, argv, &options))
|
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");
|
||||||
|
|
||||||
|
config.AddToCmdLineOptions(sink_options);
|
||||||
|
|
||||||
|
if (config.ParseAll(argc, argv))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (exception& e)
|
|
||||||
{
|
string filename = config.GetValue<string>("config-json-filename");
|
||||||
LOG(ERROR) << e.what();
|
string id = config.GetValue<string>("device-id");
|
||||||
return 1;
|
|
||||||
}
|
config.UserParser<JSON>(filename, id);
|
||||||
|
|
||||||
|
sink.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
LOG(INFO) << "PID: " << getpid();
|
LOG(INFO) << "PID: " << getpid();
|
||||||
|
|
||||||
|
@ -139,15 +92,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
sink.SetTransport(transportFactory);
|
sink.SetTransport(transportFactory);
|
||||||
|
|
||||||
FairMQChannel channel(options.inputSocketType, options.inputMethod, options.inputAddress);
|
sink.SetProperty(FairMQSink::Id, id);
|
||||||
channel.fSndBufSize = options.inputBufSize;
|
sink.SetProperty(FairMQSink::NumIoThreads, ioThreads);
|
||||||
channel.fRcvBufSize = options.inputBufSize;
|
|
||||||
channel.fRateLogging = 1;
|
|
||||||
|
|
||||||
sink.fChannels["data-in"].push_back(channel);
|
|
||||||
|
|
||||||
sink.SetProperty(FairMQSink::Id, options.id);
|
|
||||||
sink.SetProperty(FairMQSink::NumIoThreads, options.ioThreads);
|
|
||||||
|
|
||||||
sink.ChangeState(FairMQSink::INIT_DEVICE);
|
sink.ChangeState(FairMQSink::INIT_DEVICE);
|
||||||
sink.WaitForEndOfState(FairMQSink::INIT_DEVICE);
|
sink.WaitForEndOfState(FairMQSink::INIT_DEVICE);
|
||||||
|
@ -168,5 +114,14 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
sink.ChangeState(FairMQSink::END);
|
sink.ChangeState(FairMQSink::END);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
LOG(ERROR) << e.what();
|
||||||
|
LOG(INFO) << "Started with: ";
|
||||||
|
config.PrintHelp();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user