SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SourceGroupWithOnDemandProperties.cpp
Go to the documentation of this file.
1
22
23#include "ElementsKernel/Logging.h"
24
27
28namespace SourceXtractor {
29
30static Elements::Logging logger = Elements::Logging::getLogger("SourceGroupWithOnDemandProperties");
31
35
39
43
47
51
55
59
64
70
72 auto& other_group = dynamic_cast<SourceGroupWithOnDemandProperties&>(other);
73 // We go through the EntangledSources of the other group and we create new ones
74 // locally, pointing to the same wrapped sources. This is necessary, so the
75 // new EntangledSources have a reference to the correct group.
76 for (auto& source : other_group.m_sources) {
77 auto& entangled_source = dynamic_cast<EntangledSource&>(source.getRef());
78 m_sources.emplace_back(Euclid::make_unique<EntangledSource>(std::move(entangled_source.m_source), *this));
79 }
80 other_group.m_sources.clear();
82}
83
85 // If we already have the property, return it
86 if (m_property_holder.isPropertySet(property_id)) {
87 return m_property_holder.getProperty(property_id);
88 }
89
90 try {
91 // If not, get the task for that property, use it to compute the property then return it
92 auto task = m_task_provider->getTask<GroupTask>(property_id);
93 if (task) {
94 task->computeProperties(const_cast<SourceGroupWithOnDemandProperties&>(*this));
95 return m_property_holder.getProperty(property_id);
96 }
97 }
98 catch (Elements::Exception& e) {
99 logger.debug() << e.what();
100 }
101
102 // No task available to make that property, we throw an exception
103 throw PropertyNotFoundException(property_id);
104}
105
107 m_property_holder.setProperty(std::move(property), property_id);
108}
109
111 m_property_holder.clear();
112 for (auto& source : m_sources) {
113 dynamic_cast<EntangledSource&>(source.getRef()).m_property_holder.clear();
114 }
115}
116
118 return m_sources.size();
119}
120
121} // SourceXtractor namespace
122
123
124
static Logging getLogger(const std::string &name="")
A Task that acts on a SourceGroup to compute one or more properties.
Definition GroupTask.h:36
Identifier used to set and retrieve properties.
Definition PropertyId.h:40
An exception indicating that a Property was not available and could not be computed on demand.
Base class for all Properties. (has no actual content).
Definition Property.h:33
Defines the interface used to group sources.
std::list< SourceWrapper >::const_iterator const_iterator
std::list< SourceWrapper >::iterator iterator
SourceGroupWithOnDemandProperties(std::shared_ptr< TaskProvider > task_provider)
const Property & getProperty(const PropertyId &property_id) const override
void setProperty(std::unique_ptr< Property > property, const PropertyId &property_id) override
void addSource(std::unique_ptr< SourceInterface > source) override
T move(T... args)
static Elements::Logging logger
std::unique_ptr< T > make_unique(Args &&... args)