SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEFramework
src
lib
Pipeline
SourceGrouping.cpp
Go to the documentation of this file.
1
23
#include "
SEFramework/Pipeline/SourceGrouping.h
"
24
#include <vector>
25
26
27
namespace
SourceXtractor
{
28
29
SourceGrouping::SourceGrouping
(
std::shared_ptr<GroupingCriteria>
grouping_criteria
,
30
std::shared_ptr<SourceGroupFactory>
group_factory,
31
unsigned
int
hard_limit
)
32
: m_grouping_criteria(
grouping_criteria
), m_group_factory(group_factory), m_hard_limit(
hard_limit
) {
33
}
34
35
void
SourceGrouping::receiveSource
(
std::unique_ptr<SourceInterface>
source
) {
36
// Pointer which points to the group of the source
37
SourceGroupInterface
*
matched_group
=
nullptr
;
38
39
auto
source_ptr
=
source
.get();
40
std::vector<std::list<std::unique_ptr<SourceGroupInterface>
>::iterator>
groups_to_remove
{};
41
42
for
(
auto
group_it
=
m_source_groups
.begin();
group_it
!=
m_source_groups
.end(); ++
group_it
) {
43
44
if
(
m_hard_limit
> 0) {
45
unsigned
int
current_group_size
= (
matched_group
!=
nullptr
) ?
matched_group
->size() : 1;
46
if
(
current_group_size
>=
m_hard_limit
) {
47
break
;
// no need to try to find matching groups anymore, we have reached the limit
48
}
49
50
if
(
current_group_size
+ (*group_it)->size() >
m_hard_limit
) {
51
continue
;
// we can't merge groups without hitting the limit, so skip it
52
}
53
}
54
55
// Search if the source meets the grouping criteria with any of the sources in the group
56
bool
in_group
=
false
;
57
for
(
auto
& s : **
group_it
) {
58
if
(
m_grouping_criteria
->shouldGroup(*
source_ptr
, s)) {
59
in_group
=
true
;
60
break
;
// No need to check the rest of the group sources
61
}
62
}
63
64
if
(
in_group
) {
65
if
(
matched_group
==
nullptr
) {
66
matched_group
=
group_it
->get();
67
matched_group
->addSource(
std::move
(
source
));
68
}
else
{
69
matched_group
->merge(
std::move
(**
group_it
));
70
groups_to_remove
.emplace_back(
group_it
);
71
}
72
}
73
}
74
75
// If there was no group the source should be grouped in, we create a new one
76
if
(
matched_group
==
nullptr
) {
77
auto
new_group
=
m_group_factory
->createSourceGroup();
78
new_group
->addSource(
std::move
(
source
));
79
m_source_groups
.emplace_back(
std::move
(
new_group
));
80
}
81
82
for
(
auto
&
group_it
:
groups_to_remove
) {
83
m_source_groups
.erase(
group_it
);
84
}
85
}
86
87
void
SourceGrouping::receiveProcessSignal
(
const
ProcessSourcesEvent
&
process_event
) {
88
std::vector<std::list<std::unique_ptr<SourceGroupInterface>
>::iterator>
groups_to_process
;
89
90
// We iterate through all the SourceGroups we have
91
for
(
auto
group_it
=
m_source_groups
.begin();
group_it
!=
m_source_groups
.end(); ++
group_it
) {
92
// We look at its Sources and if we find at least one that needs to be processed we put it in groups_to_process
93
for
(
auto
&
source
: **
group_it
) {
94
if
(
process_event
.m_selection_criteria->mustBeProcessed(
source
)) {
95
groups_to_process
.push_back(
group_it
);
96
break
;
97
}
98
}
99
}
100
101
// For each SourceGroup that we put in groups_to_process,
102
for
(
auto
&
group
:
groups_to_process
) {
103
// we remove it from our list of stored SourceGroups and notify our observers
104
sendSource
(
std::move
(*
group
));
105
m_source_groups
.erase(
group
);
106
}
107
}
108
109
std::set<PropertyId>
SourceGrouping::requiredProperties
()
const
{
110
return
m_grouping_criteria
->requiredProperties();
111
}
112
113
}
// SEFramework namespace
114
115
116
SourceGrouping.h
SourceXtractor::PipelineEmitter< SourceGroupInterface >::sendSource
void sendSource(std::unique_ptr< SourceGroupInterface > source) const
Definition
PipelineStage.h:85
SourceXtractor::SourceGroupInterface
Defines the interface used to group sources.
Definition
SourceGroupInterface.h:38
SourceXtractor::SourceGrouping::m_group_factory
std::shared_ptr< SourceGroupFactory > m_group_factory
Definition
SourceGrouping.h:114
SourceXtractor::SourceGrouping::m_source_groups
std::list< std::unique_ptr< SourceGroupInterface > > m_source_groups
Definition
SourceGrouping.h:115
SourceXtractor::SourceGrouping::receiveSource
void receiveSource(std::unique_ptr< SourceInterface > source) override
Handles a new Source.
Definition
SourceGrouping.cpp:35
SourceXtractor::SourceGrouping::requiredProperties
std::set< PropertyId > requiredProperties() const
Returns the set of required properties to compute the grouping.
Definition
SourceGrouping.cpp:109
SourceXtractor::SourceGrouping::SourceGrouping
SourceGrouping(std::shared_ptr< GroupingCriteria > grouping_criteria, std::shared_ptr< SourceGroupFactory > group_factory, unsigned int hard_limit)
Definition
SourceGrouping.cpp:29
SourceXtractor::SourceGrouping::m_grouping_criteria
std::shared_ptr< GroupingCriteria > m_grouping_criteria
Definition
SourceGrouping.h:113
SourceXtractor::SourceGrouping::m_hard_limit
unsigned int m_hard_limit
Definition
SourceGrouping.h:116
SourceXtractor::SourceGrouping::receiveProcessSignal
void receiveProcessSignal(const ProcessSourcesEvent &event) override
Handles a ProcessSourcesEvent to trigger the processing of some of the Sources stored in SourceGroupi...
Definition
SourceGrouping.cpp:87
std::function
std::move
T move(T... args)
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::ProcessSourcesEvent
Event received by SourceGrouping to request the processing of some of the Sources stored.
Definition
PipelineStage.h:33
Generated by
1.10.0