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