LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
BlockingPrescaler_module.cc
Go to the documentation of this file.
1
// BlockingPrescaler.
3
//
4
// Accept m in n events with offset. So, for blockSize (m) = 5,
5
// stepSize (n) = 7 and offset = 4, the filter will accept events 5-9
6
// inclusive, 12-16 inclusive, 19-23 inclusive, etc.
7
//
8
// Note that BlockingPrescaler prescales based on the number of events
9
// seen by this module, *not* the event number as recorded by EventID.
11
12
#include "
art/Framework/Core/SharedFilter.h
"
13
#include "
art/Framework/Core/fwd.h
"
14
#include "
fhiclcpp/types/Atom.h
"
15
16
#include <mutex>
17
18
using namespace
fhicl
;
19
20
namespace
art
{
21
class
BlockingPrescaler;
22
}
23
24
// ======================================================================
25
26
class
art::BlockingPrescaler
:
public
SharedFilter
{
27
public
:
28
struct
Config
{
29
Atom<size_t>
blockSize{
Name
(
"blockSize"
), 1};
30
Atom<size_t>
stepSize{
31
Name
(
"stepSize"
),
32
Comment
(
33
"The value of 'stepSize' cannot be less than that of 'blockSize'."
)};
34
Atom<size_t>
offset{
Name
(
"offset"
), 0};
35
};
36
37
using
Parameters
=
Table<Config>
;
38
explicit
BlockingPrescaler
(
Parameters
const
&,
ProcessingFrame
const
&);
39
40
private
:
41
bool
filter
(
Event
&,
ProcessingFrame
const
&)
override
;
42
43
size_t
count_{};
44
size_t
const
m_
;
// accept m in n (sequentially).
45
size_t
const
n_
;
46
size_t
const
offset_
;
// First accepted event is 1 + offset.
47
std::mutex mutex_{};
48
};
// BlockingPrescaler
49
50
// ======================================================================
51
52
art::BlockingPrescaler::BlockingPrescaler
(
Parameters
const
& config,
53
ProcessingFrame
const
&)
54
:
SharedFilter
{config}
55
,
m_
{config().blockSize()}
56
,
n_
{config().stepSize()}
57
,
offset_
{config().offset()}
58
{
59
if
(
n_
<
m_
) {
60
throw
art::Exception
{
art::errors::Configuration
,
61
"There was an error configuring Blocking Prescaler.\n"
}
62
<<
"The specified step size ("
<<
n_
<<
") is less than the block size ("
63
<<
m_
<<
")\n"
;
64
}
65
async<InEvent>();
66
}
67
68
bool
69
art::BlockingPrescaler::filter
(
Event
&,
ProcessingFrame
const
&)
70
{
71
// This sequence of operations/comparisons must be serialized.
72
// Changing 'count_' to be of type std::atomic<size_t> will not
73
// help. Using a mutex here is cheaper than calling serialize(),
74
// since that will also serialize any of the module-level service
75
// callbacks invoked before and after this function is called.
76
std::lock_guard lock{
mutex_
};
77
bool
const
result{(
count_
>=
offset_
) && ((
count_
-
offset_
) %
n_
) <
m_
};
78
++
count_
;
79
return
result;
80
}
81
82
DEFINE_ART_MODULE
(
art::BlockingPrescaler
)
art::BlockingPrescaler::mutex_
std::mutex mutex_
Definition:
BlockingPrescaler_module.cc:47
art::BlockingPrescaler::BlockingPrescaler
BlockingPrescaler(Parameters const &, ProcessingFrame const &)
Definition:
BlockingPrescaler_module.cc:52
art::BlockingPrescaler
Definition:
BlockingPrescaler_module.cc:26
art::SharedFilter
Definition:
SharedFilter.h:17
SharedFilter.h
art::ProducerTable
Definition:
ProducerTable.h:19
filter
Framework includes.
Definition:
ADCFilter_module.cc:27
art::errors::Configuration
Definition:
Exception.h:32
art::BlockingPrescaler::Config
Definition:
BlockingPrescaler_module.cc:28
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:65
fwd.h
fhicl
parameter set interface
Definition:
BeamFlashTrackMatchTaggerAlg.h:17
art::ProcessingFrame
Definition:
ProcessingFrame.h:8
fhicl::Atom< size_t >
art::Exception
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition:
Exception.h:66
art::BlockingPrescaler::offset_
size_t const offset_
Definition:
BlockingPrescaler_module.cc:46
art::Event
Definition:
Event.h:26
Atom.h
art
Definition:
MVAAlg.h:12
art::BlockingPrescaler::filter
bool filter(Event &, ProcessingFrame const &) override
Definition:
BlockingPrescaler_module.cc:69
fhicl::Comment
Definition:
Comment.h:33
art::BlockingPrescaler::n_
size_t const n_
Definition:
BlockingPrescaler_module.cc:45
art::BlockingPrescaler::count_
size_t count_
Definition:
BlockingPrescaler_module.cc:43
fhicl::Name
Definition:
Name.h:10
art::BlockingPrescaler::m_
size_t const m_
Definition:
BlockingPrescaler_module.cc:44
art
Framework
Modules
BlockingPrescaler_module.cc
Generated on Thu May 2 2024 20:59:29 for LArSoft by
1.8.11