mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Introduce <fairmq/runDevice.h>
This commit is contained in:
parent
cef6d0afcd
commit
978191fa6c
|
@ -170,6 +170,7 @@ if(BUILD_FAIRMQ)
|
||||||
Plugin.h
|
Plugin.h
|
||||||
PluginManager.h
|
PluginManager.h
|
||||||
PluginServices.h
|
PluginServices.h
|
||||||
|
runDevice.h
|
||||||
runFairMQDevice.h
|
runFairMQDevice.h
|
||||||
shmem/Monitor.h
|
shmem/Monitor.h
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (C) 2017-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
* *
|
* *
|
||||||
* This software is distributed under the terms of the *
|
* This software is distributed under the terms of the *
|
||||||
* GNU Lesser General Public Licence (LGPL) version 3, *
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
@ -9,10 +9,10 @@
|
||||||
#ifndef FAIR_MQ_DEVICERUNNER_H
|
#ifndef FAIR_MQ_DEVICERUNNER_H
|
||||||
#define FAIR_MQ_DEVICERUNNER_H
|
#define FAIR_MQ_DEVICERUNNER_H
|
||||||
|
|
||||||
|
#include <fairmq/Device.h>
|
||||||
#include <fairmq/EventManager.h>
|
#include <fairmq/EventManager.h>
|
||||||
#include <fairmq/PluginManager.h>
|
#include <fairmq/PluginManager.h>
|
||||||
#include <fairmq/ProgOptions.h>
|
#include <fairmq/ProgOptions.h>
|
||||||
#include <FairMQDevice.h>
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -73,7 +73,7 @@ class DeviceRunner
|
||||||
|
|
||||||
std::vector<std::string> fRawCmdLineArgs;
|
std::vector<std::string> fRawCmdLineArgs;
|
||||||
fair::mq::ProgOptions fConfig;
|
fair::mq::ProgOptions fConfig;
|
||||||
std::unique_ptr<FairMQDevice> fDevice;
|
std::unique_ptr<Device> fDevice;
|
||||||
PluginManager fPluginManager;
|
PluginManager fPluginManager;
|
||||||
const bool fPrintLogo;
|
const bool fPrintLogo;
|
||||||
|
|
||||||
|
|
59
fairmq/runDevice.h
Normal file
59
fairmq/runDevice.h
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/********************************************************************************
|
||||||
|
* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||||
|
* *
|
||||||
|
* This software is distributed under the terms of the *
|
||||||
|
* GNU Lesser General Public Licence (LGPL) version 3, *
|
||||||
|
* copied verbatim in the file "LICENSE" *
|
||||||
|
********************************************************************************/
|
||||||
|
|
||||||
|
#include <fairmq/DeviceRunner.h>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
// to be implemented by the user to return a child class of FairMQDevice
|
||||||
|
std::unique_ptr<fair::mq::Device> getDevice(const fair::mq::ProgOptions& config);
|
||||||
|
|
||||||
|
// to be implemented by the user to add custom command line options (or just with empty body)
|
||||||
|
void addCustomOptions(boost::program_options::options_description&);
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
using namespace fair::mq;
|
||||||
|
using namespace fair::mq::hooks;
|
||||||
|
|
||||||
|
try {
|
||||||
|
DeviceRunner runner(argc, argv);
|
||||||
|
|
||||||
|
// runner.AddHook<LoadPlugins>([](DeviceRunner& r){
|
||||||
|
// // for example:
|
||||||
|
// r.fPluginManager->SetSearchPaths({"/lib", "/lib/plugins"});
|
||||||
|
// r.fPluginManager->LoadPlugin("asdf");
|
||||||
|
// });
|
||||||
|
|
||||||
|
runner.AddHook<SetCustomCmdLineOptions>([](DeviceRunner& r){
|
||||||
|
boost::program_options::options_description customOptions("Custom options");
|
||||||
|
addCustomOptions(customOptions);
|
||||||
|
r.fConfig.AddToCmdLineOptions(customOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
// runner.AddHook<ModifyRawCmdLineArgs>([](DeviceRunner& r){
|
||||||
|
// // for example:
|
||||||
|
// r.fRawCmdLineArgs.push_back("--blubb");
|
||||||
|
// });
|
||||||
|
|
||||||
|
runner.AddHook<InstantiateDevice>([](DeviceRunner& r){
|
||||||
|
r.fDevice = getDevice(r.fConfig);
|
||||||
|
});
|
||||||
|
|
||||||
|
return runner.Run();
|
||||||
|
|
||||||
|
// Run with builtin catch all exception handler, just:
|
||||||
|
// return runner.RunWithExceptionHandlers();
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
LOG(error) << "Uncaught exception reached the top of main: " << e.what();
|
||||||
|
return 1;
|
||||||
|
} catch (...) {
|
||||||
|
LOG(error) << "Uncaught exception reached the top of main.";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user