LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Prescaler_module.cc
Go to the documentation of this file.
1
// ======================================================================
2
//
3
// Prescaler_plugin
4
//
5
// ======================================================================
6
7
#include "
art/Framework/Core/SharedFilter.h
"
8
#include "
art/Framework/Core/fwd.h
"
9
#include "
fhiclcpp/types/Atom.h
"
10
11
#include <mutex>
12
13
namespace
art
{
14
class
Prescaler
;
15
}
16
using namespace
fhicl
;
17
using
art::Prescaler
;
18
19
// ======================================================================
20
21
class
art::Prescaler
:
public
SharedFilter
{
22
public
:
23
struct
Config
{
24
Atom<size_t>
prescaleFactor{
Name
(
"prescaleFactor"
)};
25
Atom<size_t>
prescaleOffset{
Name
(
"prescaleOffset"
)};
26
};
27
28
using
Parameters
=
Table<Config>
;
29
explicit
Prescaler
(
Parameters
const
&,
ProcessingFrame
const
&);
30
31
private
:
32
bool
filter
(
Event
&,
ProcessingFrame
const
&)
override
;
33
34
size_t
count_{};
35
// Accept one in n events.
36
size_t
const
n_
;
37
// An offset is allowed--i.e. sequence of events does not have to
38
// start at first event.
39
size_t
const
offset_
;
40
std::mutex mutex_{};
41
42
};
// Prescaler
43
44
// ======================================================================
45
46
Prescaler::Prescaler
(
Parameters
const
& config,
ProcessingFrame
const
&)
47
:
SharedFilter
{config}
48
,
n_
{config().prescaleFactor()}
49
,
offset_
{config().prescaleOffset()}
50
{
51
async<InEvent>();
52
}
53
54
bool
55
Prescaler::filter
(
Event
&,
ProcessingFrame
const
&)
56
{
57
// The combination of incrementing, modulo dividing, and equality
58
// comparing must be synchronized. Changing count_ to the type
59
// std::atomic<size_t> would not help since the entire combination
60
// of operations must be atomic. Using a mutex here is cheaper than
61
// calling serialize(), since that will also serialize any of the
62
// module-level service callbacks invoked before and after this
63
// function is called.
64
std::lock_guard lock{
mutex_
};
65
++
count_
;
66
return
count_
%
n_
==
offset_
;
67
}
68
69
DEFINE_ART_MODULE
(
Prescaler
)
art::Prescaler::count_
size_t count_
Definition:
Prescaler_module.cc:34
art::Prescaler::n_
size_t const n_
Definition:
Prescaler_module.cc:36
art::SharedFilter
Definition:
SharedFilter.h:17
SharedFilter.h
art::ProducerTable
Definition:
ProducerTable.h:19
art::Prescaler::mutex_
std::mutex mutex_
Definition:
Prescaler_module.cc:40
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:65
fwd.h
fhicl
parameter set interface
Definition:
BeamFlashTrackMatchTaggerAlg.h:17
art::Prescaler::offset_
size_t const offset_
Definition:
Prescaler_module.cc:39
art::ProcessingFrame
Definition:
ProcessingFrame.h:8
fhicl::Atom< size_t >
art::Prescaler::Config
Definition:
Prescaler_module.cc:23
art::ModuleType::filter
art::Prescaler::Prescaler
Prescaler(Parameters const &, ProcessingFrame const &)
Definition:
Prescaler_module.cc:46
art::Prescaler
Definition:
Prescaler_module.cc:21
art::Event
Definition:
Event.h:26
Atom.h
art
Definition:
MVAAlg.h:12
art::Prescaler::filter
bool filter(Event &, ProcessingFrame const &) override
Definition:
Prescaler_module.cc:55
fhicl::Name
Definition:
Name.h:10
art
Framework
Modules
Prescaler_module.cc
Generated on Thu May 2 2024 20:59:29 for LArSoft by
1.8.11