BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
sampler.cxx
Go to the documentation of this file.
1
#include <FairRootManager.h>
2
#include <RootSerializer.h>
3
#include <
TFile.h
>
4
#include <
TString.h
>
5
#include <
TTree.h
>
6
#include <fairmq/Device.h>
7
#include <fairmq/runDevice.h>
8
#include <string>
9
#include <thread>
10
11
namespace
bpo = boost::program_options;
12
13
namespace
bmn::online
14
{
15
struct
Sampler
: fair::mq::Device
16
{
17
protected
:
18
static
constexpr
auto
OUTPUT_CHANNEL_NAME
=
"out-channel"
;
19
20
void
Init
()
override
21
{
22
fEventsFilePath
= fConfig->GetValue<std::string>(
"file-path"
);
23
fEventDispatchDelay
= fConfig->GetValue<
UShort_t
>(
"dispatch-delay"
);
24
fCurrentEvent
= fConfig->GetValue<
size_t
>(
"start-event"
);
25
}
26
27
void
InitTask
()
override
28
{
29
fEventFile
= std::unique_ptr<TFile>(
TFile::Open
(
fEventsFilePath
,
"read"
));
30
fEventData
= std::unique_ptr<TTree>(
fEventFile
->Get<
TTree
>(
"bmndata"
));
31
fNEvents
=
fEventData
->GetEntries();
32
33
LOG(info) <<
"Number of events in the file: "
<<
fNEvents
;
34
}
35
36
Bool_t
ConditionalRun
()
override
37
{
38
LOG(info) <<
"Event #"
<<
fCurrentEvent
;
39
40
if
(
fCurrentEvent
>
fNEvents
) {
41
return
kFALSE
;
42
}
43
44
std::unique_ptr<TTree> eventData(
fEventData
->CopyTree(
""
,
""
, 1,
fCurrentEvent
));
45
46
auto
message = NewMessage();
47
RootSerializer().Serialize(*message, eventData);
48
49
if
(Send(message,
OUTPUT_CHANNEL_NAME
) < 0) {
50
LOG(error) <<
"Sending message failed!"
;
51
return
kFALSE
;
52
}
53
54
fCurrentEvent
++;
55
56
std::this_thread::sleep_for(std::chrono::milliseconds(
fEventDispatchDelay
));
57
58
return
kTRUE
;
59
}
60
61
private
:
62
TString
fEventsFilePath
=
""
;
63
UShort_t
fEventDispatchDelay
= 1000;
64
size_t
fCurrentEvent
= 0;
65
66
std::unique_ptr<TFile>
fEventFile
;
67
std::unique_ptr<TTree>
fEventData
;
68
size_t
fNEvents
= 0;
69
};
70
}
// namespace bmn::online
71
72
void
addCustomOptions
(bpo::options_description& options)
73
{
74
auto
op = options.add_options();
75
76
op(
"file-path"
, bpo::value<std::string>()->required(),
"Path to the event file"
);
77
op(
"dispatch-delay"
, bpo::value<UShort_t>()->default_value(1000),
78
"Delay before dispatching an event in milliseconds"
);
79
op(
"start-event"
, bpo::value<size_t>()->default_value(0),
"Start event number"
);
80
}
81
82
std::unique_ptr<fair::mq::Device>
getDevice
(fair::mq::ProgOptions&)
83
{
84
return
std::make_unique<bmn::online::Sampler>();
85
}
Bool_t
bool Bool_t
UShort_t
unsigned short UShort_t
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
TFile.h
TString.h
TTree.h
TFile::Open
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
TString
TTree
bmn::online
Definition
decoder_proxy.cxx:15
getDevice
std::unique_ptr< fair::mq::Device > getDevice(fair::mq::ProgOptions &)
Definition
sampler.cxx:82
addCustomOptions
void addCustomOptions(bpo::options_description &options)
Definition
sampler.cxx:72
bmn::online::Sampler
Definition
sampler.cxx:16
bmn::online::Sampler::fEventData
std::unique_ptr< TTree > fEventData
Definition
sampler.cxx:67
bmn::online::Sampler::fEventDispatchDelay
UShort_t fEventDispatchDelay
Definition
sampler.cxx:63
bmn::online::Sampler::fEventsFilePath
TString fEventsFilePath
Definition
sampler.cxx:62
bmn::online::Sampler::OUTPUT_CHANNEL_NAME
static constexpr auto OUTPUT_CHANNEL_NAME
Definition
sampler.cxx:18
bmn::online::Sampler::fEventFile
std::unique_ptr< TFile > fEventFile
Definition
sampler.cxx:66
bmn::online::Sampler::Init
void Init() override
Definition
sampler.cxx:20
bmn::online::Sampler::fNEvents
size_t fNEvents
Definition
sampler.cxx:68
bmn::online::Sampler::ConditionalRun
Bool_t ConditionalRun() override
Definition
sampler.cxx:36
bmn::online::Sampler::fCurrentEvent
size_t fCurrentEvent
Definition
sampler.cxx:64
bmn::online::Sampler::InitTask
void InitTask() override
Definition
sampler.cxx:27
online
sampler.cxx
Generated on
for BmnRoot by
1.17.0