Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
duneana
duneana
EventFilters
DuneEventFilter_module.cc
Go to the documentation of this file.
1
// DuneEventFilter_module.cc
2
//
3
// Module to select or reject events based on event number.
4
//
5
// David Adams
6
// October 2018
7
// June 2019: Update using event range "events" from the job IndexRangeTool.
8
//
9
// Configuration:
10
// LogLevel: 0=quiet, 1=ctor message, 2=status of each event
11
// SelectEvents: If this has entries, the event must be among them
12
// RejectEvents: Event is rejected if it is in this list.
13
// EventBegin, EventEnd: if EventEnd > EventBegin, event must be in (EventBegin, EventEnd].
14
// EventModFreq, EventModVal: keep events for which ievt%EventModFreq == EventModVal
15
// JobIndexRangeTool: Name of the job IndexRangeTool, e.g. jobRanges.
16
// SkipEventTool: Name of a tool (IndexVectorTool) that lists events to be skipped
17
// indexed by run number. Blank means no tool.
18
//
19
// The range of event to process is (EventBegin, EventEnd] if EventEnd > EventBegin.
20
// Otherwise the range is taken from the index range "events" in the job IndexRangeTool.
21
// If that range does not exist or is not valid, all events are processed.
22
23
#include <iostream>
24
#include <vector>
25
#include <set>
26
27
#include "
dunecore/DuneInterface/Tool/IndexRangeTool.h
"
28
#include "
dunecore/DuneInterface/Tool/IndexVectorMapTool.h
"
29
#include "
dunecore/ArtSupport/DuneToolManager.h
"
30
#include "
art/Framework/Core/EDFilter.h
"
31
#include "
art/Framework/Core/ModuleMacros.h
"
32
#include "
art/Framework/Principal/Event.h
"
33
34
class
DuneEventFilter
:
public
art::EDFilter
{
35
36
public
:
37
38
using
Index
=
unsigned
int
;
39
using
IndexVector
= std::vector<Index>;
40
using
IndexSet
= std::set<Index>;
41
using
Name
=
std::string
;
42
43
explicit
DuneEventFilter
(
fhicl::ParameterSet
const
& pset);
44
virtual
~DuneEventFilter
();
45
virtual
bool
filter
(
art::Event
&
e
);
46
47
private
:
48
49
// Configuration parameters.
50
Index
m_LogLevel
;
51
IndexVector
m_SelectEventVector
;
52
IndexVector
m_RejectEventVector
;
53
Index
m_EventBegin
;
54
Index
m_EventEnd
;
55
Index
m_EventModFreq
;
56
Index
m_EventModVal
;
57
Name
m_JobIndexRangeTool
;
58
Name
m_SkipEventTool
;
59
60
// Derived from configuration.
61
Index
m_beginEvent
;
62
Index
m_endEvent
;
63
IndexSet
m_SelectEvents
;
64
IndexSet
m_RejectEvents
;
65
const
IndexVectorMapTool
*
m_pSkipEventTool
;
66
67
// Counters.
68
Index
m_nproc
;
69
Index
m_nsel
;
70
71
};
72
73
//*****************************************************************************
74
75
DuneEventFilter::DuneEventFilter
(
fhicl::ParameterSet
const
& pset)
76
:
EDFilter
(pset),
77
m_LogLevel
(pset.
get
<
Index
>(
"LogLevel"
)),
78
m_SelectEventVector
(pset.
get
<
IndexVector
>(
"SelectEvents"
)),
79
m_RejectEventVector
(pset.
get
<
IndexVector
>(
"RejectEvents"
)),
80
m_EventBegin
(pset.
get
<
Index
>(
"EventBegin"
)),
81
m_EventEnd
(pset.
get
<
Index
>(
"EventEnd"
)),
82
m_EventModFreq
(pset.
get
<
Index
>(
"EventModFreq"
)),
83
m_EventModVal
(pset.
get
<
Index
>(
"EventModVal"
)),
84
m_JobIndexRangeTool
(pset.
get
<
Name
>(
"JobIndexRangeTool"
)),
85
m_SkipEventTool
(pset.
get
<
Name
>(
"SkipEventTool"
)),
86
m_beginEvent
(0),
m_endEvent
(0),
87
m_pSkipEventTool
(nullptr),
88
m_nproc
(0),
m_nsel
(0) {
89
using
std::cout;
90
using
std::endl
;
91
using
std::string
;
92
const
string
myname =
"DuneEventFilter::ctor: "
;
93
for
(
Index
ievt :
m_SelectEventVector
)
m_SelectEvents
.insert(ievt);
94
for
(
Index
ievt :
m_RejectEventVector
)
m_RejectEvents
.insert(ievt);
95
if
(
m_LogLevel
>= 1 ) {
96
cout << myname <<
" LogLevel: "
<<
m_LogLevel
<<
endl
;
97
cout << myname <<
" SelectEvents: ["
;
98
bool
first =
true
;
99
for
(
unsigned
int
ievt :
m_SelectEvents
) {
100
if
( first ) first =
false
;
101
else
cout <<
", "
;
102
cout << ievt;
103
}
104
cout <<
"]"
<<
endl
;
105
cout << myname <<
" RejectEvents: ["
;
106
first =
true
;
107
for
(
unsigned
int
ievt :
m_RejectEvents
) {
108
if
( first ) first =
false
;
109
else
cout <<
", "
;
110
cout << ievt;
111
}
112
cout <<
"]"
<<
endl
;
113
cout << myname <<
" EventBegin: "
<<
m_EventBegin
<<
endl
;
114
cout << myname <<
" EventEnd: "
<<
m_EventEnd
<<
endl
;
115
cout << myname <<
" EventModVal: "
<<
m_EventModVal
<<
endl
;
116
cout << myname <<
" EventModFreq: "
<<
m_EventModFreq
<<
endl
;
117
cout << myname <<
" JobIndexRangeTool: "
<<
m_JobIndexRangeTool
<<
endl
;
118
cout << myname <<
" SkipEventTool: "
<<
m_SkipEventTool
<<
endl
;
119
}
120
if
(
m_EventEnd
>
m_EventBegin
) {
121
m_beginEvent
=
m_EventBegin
;
122
m_endEvent
=
m_EventEnd
;
123
}
else
if
(
m_JobIndexRangeTool
.size() ) {
124
DuneToolManager
* ptm =
DuneToolManager::instance
();
125
const
IndexRangeTool
* pjrt = ptm->
getShared
<
IndexRangeTool
>(
m_JobIndexRangeTool
);
126
if
( pjrt ==
nullptr
) {
127
cout << myname <<
"ERROR: Job index range tool not found: "
<<
m_JobIndexRangeTool
<<
endl
;
128
}
else
{
129
IndexRange
ran = pjrt->
get
(
"events"
);
130
if
( ! ran.
isValid
() ) {
131
cout << myname <<
"Event range is unrestricted."
<<
endl
;
132
}
else
{
133
m_beginEvent
= ran.
begin
;
134
m_endEvent
= ran.
end
;
135
}
136
}
137
}
138
if
(
m_endEvent
>
m_beginEvent
) {
139
cout << myname <<
"Event selection range is ["
<<
m_beginEvent
<<
", "
140
<<
m_endEvent
<<
")."
<<
endl
;
141
}
else
{
142
cout << myname <<
"No event selection range."
<<
endl
;
143
}
144
if
(
m_SkipEventTool
.size() ) {
145
DuneToolManager
* ptm =
DuneToolManager::instance
();
146
m_pSkipEventTool
= ptm->
getShared
<
IndexVectorMapTool
>(
m_SkipEventTool
);
147
if
(
m_pSkipEventTool
==
nullptr
) {
148
cout <<
"WARNING: Unable to find SkipEventTool "
<<
m_SkipEventTool
<<
endl
;
149
}
else
{
150
cout << myname <<
"Using SkipEventTool @"
<<
m_pSkipEventTool
<<
endl
;
151
}
152
}
153
}
154
155
//*****************************************************************************
156
157
bool
DuneEventFilter::filter
(
art::Event
&
evt
) {
158
using
std::cout;
159
using
std::endl
;
160
using
std::string
;
161
const
string
myname =
"DuneEventFilter::filter: "
;
162
Index
ievt = evt.
event
();
163
++
m_nproc
;
164
bool
keep =
true
;
165
if
( keep &&
m_SelectEvents
.size() ) keep =
m_SelectEvents
.count(ievt);
166
if
( keep ) keep =
m_RejectEvents
.count(ievt) == 0;
167
if
( keep &&
m_endEvent
>
m_beginEvent
) keep = ievt >=
m_beginEvent
&& ievt <
m_endEvent
;
168
if
( keep &&
m_EventModFreq
) keep = (ievt %
m_EventModFreq
) ==
m_EventModVal
;
169
if
( keep &&
m_pSkipEventTool
!=
nullptr
) {
170
const
IndexVector
& skipEvents =
m_pSkipEventTool
->
get
(evt.
run
());
171
if
( find(skipEvents.begin(), skipEvents.end(), ievt) != skipEvents.end() ) {
172
keep =
false
;
173
if
(
m_LogLevel
>= 3 ) {
174
cout << myname <<
" Event "
<< ievt <<
" rejected by SkipEventTool"
<<
endl
;
175
}
176
}
177
}
178
if
(
m_LogLevel
>= 2 ) {
179
cout << myname << (keep ?
"Sel"
:
"Rej"
) <<
"ecting event "
<< ievt <<
endl
;
180
}
181
if
( keep ) ++
m_nsel
;
182
return
keep;
183
}
184
185
//*****************************************************************************
186
187
DuneEventFilter::~DuneEventFilter
() {
188
using
std::cout;
189
using
std::endl
;
190
using
std::string
;
191
const
string
myname =
"DuneEventFilter::dtor: "
;
192
if
(
m_LogLevel
>= 1 ) {
193
float
fsel = double(
m_nsel
)/double(
m_nproc
);
194
cout << myname <<
" Events processed: "
<<
m_nproc
<<
endl
;
195
cout << myname <<
" Events selected: "
<<
m_nsel
<<
" ("
<< fsel <<
")"
<<
endl
;
196
}
197
}
198
199
//*****************************************************************************
200
201
DEFINE_ART_MODULE
(
DuneEventFilter
)
art::DataViewImpl::event
EventNumber_t event() const
Definition:
DataViewImpl.cc:85
art::EDFilter
Definition:
EDFilter.h:16
DuneEventFilter::m_SelectEvents
IndexSet m_SelectEvents
Definition:
DuneEventFilter_module.cc:63
string
std::string string
Definition:
nybbler.cc:12
IndexRange::begin
Index begin
Definition:
IndexRange.h:34
IndexVectorMapTool::get
virtual IndexVector get(Index idx) const =0
DuneEventFilter::m_beginEvent
Index m_beginEvent
Definition:
DuneEventFilter_module.cc:61
DuneEventFilter::filter
virtual bool filter(art::Event &e)
Definition:
DuneEventFilter_module.cc:157
DuneEventFilter::m_pSkipEventTool
const IndexVectorMapTool * m_pSkipEventTool
Definition:
DuneEventFilter_module.cc:65
DuneEventFilter::m_endEvent
Index m_endEvent
Definition:
DuneEventFilter_module.cc:62
IndexRange::isValid
bool isValid() const
Definition:
IndexRange.h:94
IndexRange::end
Index end
Definition:
IndexRange.h:35
IndexRangeTool.h
DuneEventFilter::m_LogLevel
Index m_LogLevel
Definition:
DuneEventFilter_module.cc:50
DuneEventFilter::m_RejectEventVector
IndexVector m_RejectEventVector
Definition:
DuneEventFilter_module.cc:52
DuneEventFilter
Definition:
DuneEventFilter_module.cc:34
e
const double e
Definition:
gUpMuFluxGen.cxx:165
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:67
EDFilter.h
DuneEventFilter::m_SelectEventVector
IndexVector m_SelectEventVector
Definition:
DuneEventFilter_module.cc:51
IndexVectorMapTool.h
DuneEventFilter::IndexVector
std::vector< Index > IndexVector
Definition:
DuneEventFilter_module.cc:39
DuneToolManager.h
DuneEventFilter::m_EventModFreq
Index m_EventModFreq
Definition:
DuneEventFilter_module.cc:55
IndexRangeTool
Definition:
IndexRangeTool.h:13
DuneEventFilter::m_EventEnd
Index m_EventEnd
Definition:
DuneEventFilter_module.cc:54
DuneEventFilter::m_JobIndexRangeTool
Name m_JobIndexRangeTool
Definition:
DuneEventFilter_module.cc:57
IndexVectorMapTool
Definition:
IndexVectorMapTool.h:15
art::DataViewImpl::run
RunNumber_t run() const
Definition:
DataViewImpl.cc:71
ModuleMacros.h
DuneEventFilter::m_SkipEventTool
Name m_SkipEventTool
Definition:
DuneEventFilter_module.cc:58
keras_to_tensorflow.int
int
Definition:
keras_to_tensorflow.py:69
DuneEventFilter::m_nsel
Index m_nsel
Definition:
DuneEventFilter_module.cc:69
DuneEventFilter::~DuneEventFilter
virtual ~DuneEventFilter()
Definition:
DuneEventFilter_module.cc:187
DuneEventFilter::m_RejectEvents
IndexSet m_RejectEvents
Definition:
DuneEventFilter_module.cc:64
art::Event
Definition:
Event.h:22
DuneToolManager
Definition:
DuneToolManager.h:34
IndexRange
Definition:
IndexRange.h:23
DuneEventFilter::m_EventModVal
Index m_EventModVal
Definition:
DuneEventFilter_module.cc:56
art::EDFilter::EDFilter
EDFilter(fhicl::ParameterSet const &pset)
Definition:
EDFilter.h:21
DuneEventFilter::Name
std::string Name
Definition:
DuneEventFilter_module.cc:41
DuneEventFilter::DuneEventFilter
DuneEventFilter(fhicl::ParameterSet const &pset)
Definition:
DuneEventFilter_module.cc:75
DuneEventFilter::m_nproc
Index m_nproc
Definition:
DuneEventFilter_module.cc:68
tca::evt
TCEvent evt
Definition:
DataStructs.cxx:7
Event.h
DuneEventFilter::IndexSet
std::set< Index > IndexSet
Definition:
DuneEventFilter_module.cc:40
art::get
auto const & get(AssnsNode< L, R, D > const &r)
Definition:
AssnsNode.h:115
DuneEventFilter::m_EventBegin
Index m_EventBegin
Definition:
DuneEventFilter_module.cc:53
DuneToolManager::instance
static DuneToolManager * instance(std::string fclname="", int dbg=1)
Definition:
DuneToolManager.cxx:95
DuneToolManager::getShared
T * getShared(std::string name)
Definition:
DuneToolManager.h:101
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
fhicl::ParameterSet
Definition:
ParameterSet.h:36
IndexRangeTool::get
virtual IndexRange get(Name nam) const =0
DuneEventFilter::Index
unsigned int Index
Definition:
DuneEventFilter_module.cc:38
Generated by
1.8.11