From 978191fa6c252714b73dde70d6737ac1cc4e529a Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Wed, 24 Mar 2021 12:59:34 +0100 Subject: [PATCH] Introduce --- fairmq/CMakeLists.txt | 1 + fairmq/DeviceRunner.cxx | 2 +- fairmq/DeviceRunner.h | 6 ++--- fairmq/runDevice.h | 59 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 fairmq/runDevice.h diff --git a/fairmq/CMakeLists.txt b/fairmq/CMakeLists.txt index b7d2a450..905aaeec 100644 --- a/fairmq/CMakeLists.txt +++ b/fairmq/CMakeLists.txt @@ -170,6 +170,7 @@ if(BUILD_FAIRMQ) Plugin.h PluginManager.h PluginServices.h + runDevice.h runFairMQDevice.h shmem/Monitor.h ) diff --git a/fairmq/DeviceRunner.cxx b/fairmq/DeviceRunner.cxx index 513df012..525faaec 100644 --- a/fairmq/DeviceRunner.cxx +++ b/fairmq/DeviceRunner.cxx @@ -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 * * GNU Lesser General Public Licence (LGPL) version 3, * diff --git a/fairmq/DeviceRunner.h b/fairmq/DeviceRunner.h index 4f9931f2..9e09aa6a 100644 --- a/fairmq/DeviceRunner.h +++ b/fairmq/DeviceRunner.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 * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -9,10 +9,10 @@ #ifndef FAIR_MQ_DEVICERUNNER_H #define FAIR_MQ_DEVICERUNNER_H +#include #include #include #include -#include #include #include @@ -73,7 +73,7 @@ class DeviceRunner std::vector fRawCmdLineArgs; fair::mq::ProgOptions fConfig; - std::unique_ptr fDevice; + std::unique_ptr fDevice; PluginManager fPluginManager; const bool fPrintLogo; diff --git a/fairmq/runDevice.h b/fairmq/runDevice.h new file mode 100644 index 00000000..70bda441 --- /dev/null +++ b/fairmq/runDevice.h @@ -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 +#include +#include + +// to be implemented by the user to return a child class of FairMQDevice +std::unique_ptr 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([](DeviceRunner& r){ + // // for example: + // r.fPluginManager->SetSearchPaths({"/lib", "/lib/plugins"}); + // r.fPluginManager->LoadPlugin("asdf"); + // }); + + runner.AddHook([](DeviceRunner& r){ + boost::program_options::options_description customOptions("Custom options"); + addCustomOptions(customOptions); + r.fConfig.AddToCmdLineOptions(customOptions); + }); + + // runner.AddHook([](DeviceRunner& r){ + // // for example: + // r.fRawCmdLineArgs.push_back("--blubb"); + // }); + + runner.AddHook([](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; + } +}