Skip to content

Source · fairmq/

runFairMQDevice.hpublic header

Described in Move from the FairMQ* names.

fairmq/runFairMQDevice.h62 lines · C++GitHub ↗
1/********************************************************************************2 * Copyright (C) 2017-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH  *3 *                                                                              *4 *              This software is distributed under the terms of the             *5 *              GNU Lesser General Public Licence (LGPL) version 3,             *6 *                  copied verbatim in the file "LICENSE"                       *7 ********************************************************************************/8 9#include <fairmq/DeviceRunner.h>10#include <boost/program_options.hpp>11#include <memory>12#include <string>13 14using FairMQDevicePtr = fair::mq::Device*;15 16// to be implemented by the user to return a child class of fair::mq::Device17FairMQDevicePtr getDevice(const fair::mq::ProgOptions& config);18 19// to be implemented by the user to add custom command line options (or just with empty body)20void addCustomOptions(boost::program_options::options_description&);21 22int main(int argc, char* argv[])23{24    using namespace fair::mq;25    using namespace fair::mq::hooks;26 27    try {28        fair::mq::DeviceRunner runner{argc, argv};29 30        // runner.AddHook<LoadPlugins>([](DeviceRunner& r){31        //     // for example:32        //     r.fPluginManager->SetSearchPaths({"/lib", "/lib/plugins"});33        //     r.fPluginManager->LoadPlugin("asdf");34        // });35 36        runner.AddHook<SetCustomCmdLineOptions>([](DeviceRunner& r){37            boost::program_options::options_description customOptions("Custom options");38            addCustomOptions(customOptions);39            r.fConfig.AddToCmdLineOptions(customOptions);40        });41 42        // runner.AddHook<ModifyRawCmdLineArgs>([](DeviceRunner& r){43        //     // for example:44        //     r.fRawCmdLineArgs.push_back("--blubb");45        // });46 47        runner.AddHook<InstantiateDevice>([](DeviceRunner& r){48            r.fDevice = std::unique_ptr<fair::mq::Device>{getDevice(r.fConfig)};49        });50 51        return runner.Run();52 53        // Run with builtin catch all exception handler, just:54        // return runner.RunWithExceptionHandlers();55    } catch (std::exception& e) {56        LOG(error) << "Uncaught exception reached the top of main: " << e.what();57        return 1;58    } catch (...) {59        LOG(error) << "Uncaught exception reached the top of main.";60        return 1;61    }62}