Skip to content

Commit 77cd1ab

Browse files
matthiasrichterktf
authored andcommitted
Applying FairMQDevice boiler plate code and program options.
Simlify the EventSampler device by using the FairMQ boiler plate code and program options.
1 parent 497aa36 commit 77cd1ab

3 files changed

Lines changed: 77 additions & 652 deletions

File tree

Utilities/aliceHLTwrapper/include/aliceHLTwrapper/EventSampler.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//****************************************************************************
66
//* This file is free software: you can redistribute it and/or modify *
77
//* it under the terms of the GNU General Public License as published by *
8-
//* the Free Software Foundation, either version 3 of the License, or *
9-
//* (at your option) any later version. *
8+
//* the Free Software Foundation, either version 3 of the License, or *
9+
//* (at your option) any later version. *
1010
//* *
1111
//* Primary Authors: Matthias Richter <richterm@scieq.net> *
1212
//* *
@@ -21,6 +21,9 @@
2121

2222
#include <FairMQDevice.h>
2323
#include <vector>
24+
#include <boost/program_options.hpp>
25+
26+
namespace bpo = boost::program_options;
2427

2528
namespace ALICE {
2629
namespace HLT {
@@ -38,27 +41,36 @@ class EventSampler : public FairMQDevice {
3841
/// destructor
3942
~EventSampler() override;
4043

44+
/// get description of options
45+
static bpo::options_description GetOptionsDescription();
46+
47+
enum /*class*/ OptionKeyIds /*: int*/ {
48+
OptionKeyEventPeriod = 0,
49+
OptionKeyInitialDelay,
50+
OptionKeyPollTimeout,
51+
OptionKeyDryRun,
52+
OptionKeyLatencyLog,
53+
OptionKeyLast
54+
};
55+
56+
constexpr static const char* OptionKeys[] = {
57+
"eventperiod",
58+
"initialdelay",
59+
"polltimeout",
60+
"dry-run",
61+
"latency-log",
62+
nullptr
63+
};
64+
4165
/////////////////////////////////////////////////////////////////
4266
// the FairMQDevice interface
4367

4468
/// inherited from FairMQDevice
45-
void Init() override;
69+
void InitTask() override;
4670
/// inherited from FairMQDevice
4771
void Run() override;
4872
/// inherited from FairMQDevice
4973
void Pause() override;
50-
/// inherited from FairMQDevice
51-
/// handle device specific properties and forward to FairMQDevice::SetProperty
52-
void SetProperty(const int key, const std::string& value) override;
53-
/// inherited from FairMQDevice
54-
/// handle device specific properties and forward to FairMQDevice::GetProperty
55-
std::string GetProperty(const int key, const std::string& default_ = "") override;
56-
/// inherited from FairMQDevice
57-
/// handle device specific properties and forward to FairMQDevice::SetProperty
58-
void SetProperty(const int key, const int value) override;
59-
/// inherited from FairMQDevice
60-
/// handle device specific properties and forward to FairMQDevice::GetProperty
61-
int GetProperty(const int key, const int default_ = 0) override;
6274

6375
/// sampler loop started in a separate thread
6476
void samplerLoop();
@@ -81,7 +93,7 @@ class EventSampler : public FairMQDevice {
8193
int mPollingTimeout; // period of polling on input sockets in ms
8294
int mSkipProcessing; // skip component processing
8395
int mVerbosity; // verbosity level
84-
std::string mOutputFile; // output file for logging of latency
96+
std::string mLatencyLogFileName; // output file for logging of latency
8597
};
8698

8799
} // namespace hlt

Utilities/aliceHLTwrapper/src/EventSampler.cxx

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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
//* *
@@ -19,6 +19,7 @@
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_
4445
using namespace ALICE::HLT;
4546

4647
EventSampler::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

5758
EventSampler::~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-
228205
void EventSampler::samplerLoop()
229206
{
230207
/// sampler loop

0 commit comments

Comments
 (0)