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 < FairMQLogger.h>
2020#include < FairMQPoller.h>
2121#include " aliceHLTwrapper/AliHLTDataTypes.h"
22+ #include < options/FairMQProgOptions.h>
2223
2324#include < boost/thread.hpp>
2425#include < boost/bind.hpp>
@@ -44,22 +45,55 @@ const std::chrono::time_point<system_clock, PeriodDay> dayref=std::chrono::time_
4445using namespace ALICE ::HLT ;
4546
4647EventSampler::EventSampler (int verbosity)
47- : mEventPeriod(1000 )
48- , mInitialDelay(1000 )
48+ : mEventPeriod(- 1 )
49+ , mInitialDelay(- 1 )
4950 , mNEvents(-1 )
50- , mPollingTimeout(10 )
51+ , mPollingTimeout(- 1 )
5152 , mSkipProcessing(0 )
5253 , mVerbosity(verbosity)
53- , mOutputFile ()
54+ , mLatencyLogFileName ()
5455{
5556}
5657
5758EventSampler::~EventSampler ()
5859= default ;
5960
60- void EventSampler::Init ()
61+ constexpr const char * EventSampler::OptionKeys[];
62+
63+ bpo::options_description EventSampler::GetOptionsDescription ()
64+ {
65+ // assemble the options for the device class and component
66+ bpo::options_description od (" EventSampler options" );
67+ od.add_options ()
68+ (OptionKeys[OptionKeyEventPeriod],
69+ bpo::value<int >()->default_value (1000 ),
70+ " event period in us" )
71+ (OptionKeys[OptionKeyInitialDelay],
72+ bpo::value<int >()->default_value (1000 ),
73+ " initial delay before the first event in ms" )
74+ (OptionKeys[OptionKeyPollTimeout],
75+ bpo::value<int >()->default_value (10 ),
76+ " timeout for the input socket poller in ms" )
77+ ((std::string (OptionKeys[OptionKeyLatencyLog]) + " ,l" ).c_str (),
78+ bpo::value<std::string>()->default_value (" " ),
79+ " output file name for logging of latency" )
80+ ((std::string (OptionKeys[OptionKeyDryRun]) + " ,n" ).c_str (),
81+ bpo::value<bool >()->zero_tokens ()->default_value (false ),
82+ " skip component processing" );
83+ return od;
84+ }
85+
86+ void EventSampler::InitTask ()
6187{
6288 // / inherited from FairMQDevice
89+ const auto * config = GetConfig ();
90+ if (config) {
91+ mEventPeriod = config->GetValue <int >(OptionKeys[OptionKeyEventPeriod]);
92+ mInitialDelay = config->GetValue <int >(OptionKeys[OptionKeyInitialDelay]);
93+ mPollingTimeout = config->GetValue <int >(OptionKeys[OptionKeyPollTimeout]);
94+ mSkipProcessing = config->GetValue <bool >(OptionKeys[OptionKeyDryRun]);
95+ mLatencyLogFileName = config->GetValue <std::string>(OptionKeys[OptionKeyLatencyLog]);
96+ }
6397 mNEvents =0 ;
6498}
6599
@@ -86,7 +120,7 @@ void EventSampler::Run()
86120 vector<int > inputMessageCntPerSocket (numInputs, 0 );
87121 int nReadCycles=0 ;
88122
89- std::ofstream latencyLog (mOutputFile );
123+ std::ofstream latencyLog (mLatencyLogFileName );
90124
91125 while (CheckCurrentState (RUNNING )) {
92126
@@ -168,63 +202,6 @@ void EventSampler::Pause()
168202 FairMQDevice::Pause ();
169203}
170204
171- void EventSampler::SetProperty (const int key, const string& value)
172- {
173- // / inherited from FairMQDevice
174- // / handle device specific properties and forward to FairMQDevice::SetProperty
175- switch (key) {
176- case OutputFile:
177- mOutputFile = value;
178- return ;
179- }
180- return FairMQDevice::SetProperty (key, value);
181- }
182-
183- string EventSampler::GetProperty (const int key, const string& default_)
184- {
185- // / inherited from FairMQDevice
186- // / handle device specific properties and forward to FairMQDevice::GetProperty
187- return FairMQDevice::GetProperty (key, default_);
188- }
189-
190- void EventSampler::SetProperty (const int key, const int value)
191- {
192- // / inherited from FairMQDevice
193- // / handle device specific properties and forward to FairMQDevice::SetProperty
194- switch (key) {
195- case EventPeriod:
196- mEventPeriod = value;
197- return ;
198- case InitialDelay:
199- mInitialDelay = value;
200- return ;
201- case PollingTimeout:
202- mPollingTimeout = value;
203- return ;
204- case SkipProcessing:
205- mSkipProcessing = value;
206- return ;
207- }
208- return FairMQDevice::SetProperty (key, value);
209- }
210-
211- int EventSampler::GetProperty (const int key, const int default_)
212- {
213- // / inherited from FairMQDevice
214- // / handle device specific properties and forward to FairMQDevice::GetProperty
215- switch (key) {
216- case EventPeriod:
217- return mEventPeriod ;
218- case InitialDelay:
219- return mInitialDelay ;
220- case PollingTimeout:
221- return mPollingTimeout ;
222- case SkipProcessing:
223- return mSkipProcessing ;
224- }
225- return FairMQDevice::GetProperty (key, default_);
226- }
227-
228205void EventSampler::samplerLoop ()
229206{
230207 // / sampler loop
0 commit comments