R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BDigitizingEngine.cxx
Go to the documentation of this file.
3#include <cmath>
4#include <range/v3/algorithm/find_if.hpp>
5#include <range/v3/algorithm/min_element.hpp>
6#include <range/v3/view/take.hpp>
7
8namespace R3B::Digitizing
9{
11 {
12 for (auto& paddle : ranges::views::take(paddles_, size_))
13 {
14 paddle->Construct();
15 }
16 }
17 [[nodiscard]] auto EngineInterface::GetTriggerTime() const -> double
18 {
19 auto paddles_view = ranges::views::take(paddles_, size_);
20 auto min_element = ranges::min_element(paddles_view,
21 [](const auto& left, const auto& right)
22 { return left->GetTrigTime() < right->GetTrigTime(); });
23 return (min_element == paddles_view.end()) ? NAN : min_element->get()->GetTrigTime();
24 }
25
26 void EngineInterface::Init(int initial_capacity)
27 {
28 ExtraInit(initial_capacity);
29 reserve_additional_paddles(initial_capacity);
30 }
31
33 {
34 {
35 paddles_.reserve(num + get_capacity());
36 for (int idx{}; idx < num; ++idx)
37 {
38 paddles_.emplace_back(make_new_paddle());
39 }
40 }
41 }
42
44 {
45 // find if a paddle with the paddle_id is already added
46 auto valid_view = ranges::views::take(paddles_, size_);
47 auto iter =
48 ranges::find_if(valid_view, [paddle_id](auto& paddle) { return paddle->GetPaddleID() == paddle_id; });
49 if (iter != valid_view.end())
50 {
51 return *(*iter);
52 }
53 // check if size is still smaller than capacity
54 if (size_ >= get_capacity())
55 {
56 // underlying data storage need to grow
58 }
59 auto* new_paddle = paddles_.at(size_++).get();
60 new_paddle->Reset();
61 new_paddle->SetPaddleID(paddle_id);
62 return *new_paddle;
63 }
64} // namespace R3B::Digitizing
void reserve_additional_paddles(int num)
Reserve memories for additional number of paddles.
virtual void ExtraInit(int initial_capacity)
void Init(int initial_capacity=1)
Initialization of the engine class.
void Construct()
Construct singals from the paddles and channels.
virtual auto make_new_paddle() const -> std::unique_ptr< AbstractPaddle >=0
auto GetTriggerTime() const -> double
Get the trigger time of the current event.
auto add_paddle(int paddle_id) -> AbstractPaddle &
std::vector< std::unique_ptr< AbstractPaddle > > paddles_
main data. This vector should rarely grow in the event loop!
std::atomic< int > size_
size of bars with valid signals in the current event
auto get_capacity() const
The number of preallocated bar objects in the engine.
NeuLAND digitizing finder task.