11// ****************************************************************************
22// * This file is free software: you can redistribute it and/or modify *
33// * it under the terms of the GNU General Public License as published by *
4- // * the Free Software Foundation, either version 3 of the License, or *
5- // * (at your option) any later version. *
4+ // * the Free Software Foundation, either version 3 of the License, or *
5+ // * (at your option) any later version. *
66// * *
77// * Primary Authors: Matthias Richter <richterm@scieq.net> *
88// * *
1919#include " aliceHLTwrapper/Component.h"
2020#include < FairMQLogger.h>
2121#include < FairMQPoller.h>
22+ #include < options/FairProgOptions.h>
23+ #include < options/FairMQProgOptions.h>
2224
2325#include < boost/thread.hpp>
2426#include < boost/bind.hpp>
@@ -36,9 +38,8 @@ using namespace ALICE::HLT;
3638using std::chrono::system_clock;
3739using TimeScale = std::chrono::milliseconds;
3840
39- WrapperDevice::WrapperDevice (int argc, char ** argv, int verbosity)
41+ WrapperDevice::WrapperDevice (int verbosity)
4042 : mComponent(nullptr )
41- , mArgv()
4243 , mMessages()
4344 , mPollingPeriod(10 )
4445 , mSkipProcessing(0 )
@@ -51,12 +52,19 @@ WrapperDevice::WrapperDevice(int argc, char** argv, int verbosity)
5152 , mNSamples(-1 )
5253 , mVerbosity(verbosity)
5354{
54- mArgv .insert (mArgv .end (), argv, argv+argc);
5555}
5656
5757WrapperDevice::~WrapperDevice ()
5858= default ;
5959
60+ bpo::options_description WrapperDevice::GetOptionsDescription ()
61+ {
62+ // assemble the options for the device class and component
63+ bpo::options_description od (" WrapperDevice options" );
64+ od.add (Component::GetOptionsDescription ());
65+ return od;
66+ }
67+
6068void WrapperDevice::Init ()
6169{
6270}
@@ -66,18 +74,55 @@ void WrapperDevice::InitTask()
6674 // / inherited from FairMQDevice
6775
6876 int iResult=0 ;
77+
6978 std::unique_ptr<Component> component (new ALICE ::HLT ::Component);
7079 if (!component.get ()) return /* -ENOMEM*/ ;
7180
81+ // loop over program options, check if the option was used and
82+ // add it together with the parameter to the argument vector.
83+ // would have been easier to iterate over the individual
84+ // option_description entires, but options_description does not
85+ // provide such a functionality
86+ vector<std::string> argstrings;
87+ bpo::options_description descriptions = GetOptionsDescription ();
88+ const auto * config = GetConfig ();
89+ if (config) {
90+ const auto varmap = config->GetVarMap ();
91+ for (const auto varit : varmap) {
92+ // check if this key belongs to the options of the device
93+ const auto * description = descriptions.find_nothrow (varit.first , false );
94+ if (description && varmap.count (varit.first ) && !varit.second .defaulted ()) {
95+ argstrings.push_back (" --" );
96+ argstrings.back () += varit.first ;
97+ // check the semantics of the value
98+ auto semantic = description->semantic ();
99+ if (semantic) {
100+ // the value semantics allows different properties like
101+ // multitoken, zero_token and composing
102+ // currently only the simple case is supported
103+ assert (semantic->min_tokens () <= 1 );
104+ assert (semantic->max_tokens () && semantic->min_tokens ());
105+ if (semantic->min_tokens () > 0 ) {
106+ // add the token
107+ argstrings.push_back (varit.second .as <std::string>());
108+ }
109+ }
110+ }
111+ }
112+ }
113+
114+ // TODO: probably one can get rid of this option, the instance/device
115+ // id is now specified with the --id option of FairMQProgOptions
72116 string idkey=" --instance-id" ;
73117 string id=" " ;
74118 id=GetProperty (FairMQDevice::Id, id);
75119 vector<char *> argv;
76- argv.push_back (mArgv [0 ]);
77120 argv.push_back (&idkey[0 ]);
78121 argv.push_back (&id[0 ]);
79- if (mArgv .size ()>1 )
80- argv.insert (argv.end (), mArgv .begin ()+1 , mArgv .end ());
122+ for (auto & argstringiter : argstrings) {
123+ argv.push_back (&argstringiter[0 ]);
124+ }
125+
81126 if ((iResult=component->init (argv.size (), &argv[0 ]))<0 ) {
82127 LOG (ERROR ) << " component init failed with error code " << iResult;
83128 throw std::runtime_error (" component init failed" );
0 commit comments