mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
- rename tutorial7 and move it to example/MQ/GenericDevices
- rename functions of MQ examples and change directory structures - move FairMQUnpacker.h from example/MQ/LmdSampler to base/MQ/devices - add runSimpleMQStateMachine.h helper function in fairmq/tools
This commit is contained in:
parent
93b82767eb
commit
19b3347ade
74
fairmq/tools/runSimpleMQStateMachine.h
Normal file
74
fairmq/tools/runSimpleMQStateMachine.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* File: runSimpleMQStateMachine.h
|
||||||
|
* Author: winckler
|
||||||
|
*
|
||||||
|
* Created on July 2, 2015, 2:07 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RUNSIMPLEMQSTATEMACHINE_H
|
||||||
|
#define RUNSIMPLEMQSTATEMACHINE_H
|
||||||
|
|
||||||
|
/// std
|
||||||
|
#include <iostream>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/// boost
|
||||||
|
#include "boost/program_options.hpp"
|
||||||
|
|
||||||
|
/// ZMQ/nmsg (in FairSoft)
|
||||||
|
#ifdef NANOMSG
|
||||||
|
#include "nanomsg/FairMQTransportFactoryNN.h"
|
||||||
|
#else
|
||||||
|
#include "zeromq/FairMQTransportFactoryZMQ.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// FairRoot - FairMQ
|
||||||
|
#include "FairMQLogger.h"
|
||||||
|
#include "FairMQParser.h"
|
||||||
|
#include "FairMQProgOptions.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// template function that take any device,
|
||||||
|
// and run a simple MQ state machine configured from a JSON file
|
||||||
|
template<typename TMQDevice>
|
||||||
|
inline int runStateMachine(TMQDevice& device, FairMQProgOptions& config)
|
||||||
|
{
|
||||||
|
device.CatchSignals();
|
||||||
|
std::string jsonfile = config.GetValue<std::string>("config-json-file");
|
||||||
|
std::string id = config.GetValue<std::string>("id");
|
||||||
|
int ioThreads = config.GetValue<int>("io-threads");
|
||||||
|
|
||||||
|
config.UserParser<FairMQParser::JSON>(jsonfile, id);
|
||||||
|
|
||||||
|
device.fChannels = config.GetFairMQMap();
|
||||||
|
|
||||||
|
device.SetProperty(TMQDevice::Id, id);
|
||||||
|
device.SetProperty(TMQDevice::NumIoThreads, ioThreads);
|
||||||
|
|
||||||
|
LOG(INFO) << "PID: " << getpid();
|
||||||
|
|
||||||
|
#ifdef NANOMSG
|
||||||
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryNN();
|
||||||
|
#else
|
||||||
|
FairMQTransportFactory* transportFactory = new FairMQTransportFactoryZMQ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
device.SetTransport(transportFactory);
|
||||||
|
|
||||||
|
device.ChangeState(TMQDevice::INIT_DEVICE);
|
||||||
|
device.WaitForEndOfState(TMQDevice::INIT_DEVICE);
|
||||||
|
|
||||||
|
device.ChangeState(TMQDevice::INIT_TASK);
|
||||||
|
device.WaitForEndOfState(TMQDevice::INIT_TASK);
|
||||||
|
|
||||||
|
device.ChangeState(TMQDevice::RUN);
|
||||||
|
device.InteractiveStateLoop();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* RUNSIMPLEMQSTATEMACHINE_H */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user