5 #ifndef HERALD_ANALYSIS_RUNNER_H
6 #define HERALD_ANALYSIS_RUNNER_H
19 using namespace sampling;
22 template <
typename ValT, std::
size_t Size>
24 using value_type = ValT;
25 static constexpr std::size_t max_size = Size;
31 auto iter = lists.try_emplace(sampled).first;
32 return lists.at(sampled);
39 const std::size_t size()
const {
43 decltype(
auto) begin() {
47 decltype(
auto) end() {
52 std::map<SampledID,SampleList<Sample<ValT>,Size>> lists;
57 template <
typename... ValTs>
59 static constexpr std::size_t Size =
sizeof...(ValTs);
62 createInstances<ValTs...>(0);
67 template <
typename ValT>
69 for (
auto& v : variants) {
70 if (
auto pval = std::get_if<ValT>(&v)) {
74 throw std::bad_variant_access();
77 const std::size_t size()
const {
78 return variants.size();
81 decltype(
auto) begin() {
82 return variants.begin();
85 decltype(
auto) end() {
86 return variants.end();
90 std::array<std::variant<ValTs...>,Size> variants;
91 template <
typename LastT>
92 void createInstances(
int pos) {
93 variants[pos].template emplace<LastT>();
96 template <
typename FirstT,
typename SecondT,
typename... RestT>
97 void createInstances(
int pos) {
98 variants[pos].template emplace<FirstT>();
99 createInstances<SecondT,RestT...>(pos + 1);
104 template <
typename... DelegateTypes>
107 addDelegates(0,dts...);
111 template <
typename ValT>
113 for (
auto& delegateV : delegates) {
114 std::visit([sampled,sample](
auto&& arg) {
115 using noref =
typename std::remove_reference<decltype(arg)>::type;
116 if constexpr (std::is_same_v<ValT,typename noref::value_type>) {
117 ((decltype(arg))arg).newSample(sampled,sample);
124 template <
typename DelegateT>
126 for (
auto& v : delegates) {
127 if (
auto pval = std::get_if<DelegateT>(&v)) {
131 throw std::bad_variant_access();
135 std::array<std::variant<DelegateTypes...>,
sizeof...(DelegateTypes)> delegates;
137 template <
typename LastT>
138 constexpr
void addDelegates(
int nextPos,LastT&& last) {
139 delegates[nextPos] = (std::move(last));
142 template <
typename FirstT,
typename SecondT,
typename... RestT>
143 constexpr
void addDelegates(
int nextPos,FirstT&& first, SecondT&& second, RestT&&... rest) {
144 delegates[nextPos] = std::move(first);
146 addDelegates(nextPos,second,rest...);
151 template <
typename... ProviderTypes>
156 addProviders(0, prvs...);
160 template <
typename InputValT, std::
size_t SrcSz,
typename SourceType, std::
size_t ListSize,
typename CallableForNewSample>
162 bool generated =
false;
163 for (
auto& providerV : providers) {
164 std::visit([&timeNow,&sampled,&src,&lists,&generated,&callable](
auto&& arg) {
165 using noref =
typename std::remove_reference<decltype(arg)>::type;
167 if constexpr (std::is_same_v<InputValT, typename noref::input_value_type>) {
168 auto& listRef = lists.list(sampled);
169 generated = generated | ((decltype(arg))arg).analyse(timeNow,sampled,src,listRef,callable);
177 template <
typename Prov
iderT>
179 for (
auto& v : providers) {
180 if (
auto pval = std::get_if<ProviderT>(&v)) {
184 throw std::bad_variant_access();
187 template <
typename InputT,
typename OutputT>
188 constexpr
bool hasMatchingAnalyser() noexcept {
190 for (
auto& providerV : providers) {
191 std::visit([&match] (
auto&& provider) {
192 using InputValT =
typename InputT::value_type;
193 using InT =
typename std::remove_reference_t<decltype(provider)>::input_value_type;
194 using OutT =
typename std::remove_reference_t<decltype(provider)>::output_value_type;
202 if constexpr (std::is_same_v<InputValT,InT> && std::is_same_v<OutputT,OutT>) {
212 std::array<std::variant<ProviderTypes...>,
sizeof...(ProviderTypes)> providers;
214 template <
typename LastT>
215 constexpr
void addProviders(
int nextPos, LastT&& last) {
216 providers[nextPos] = std::move(last);
219 template <
typename FirstT,
typename SecondT,
typename... RestT>
220 constexpr
void addProviders(
int nextPos, FirstT&& first, SecondT&& second, RestT&&... rest) {
221 providers[nextPos] = std::move(first);
223 addProviders(nextPos,second,rest...);
232 template <
typename AnalysisDelegateManagerT,
typename AnalysisProviderManagerT,
typename... SourceTypes>
234 static constexpr std::size_t ListSize = 25;
237 AnalysisRunner(AnalysisDelegateManagerT& adm, AnalysisProviderManagerT& provds) : lists(), delegates(adm), runners(provds) {}
241 template <
typename ValT>
244 lists.template get<ListManager<ValT,ListSize>>().list(sampled).push(sample);
246 delegates.notify(sampled,sample);
249 template <
typename ValT>
251 newSample(sampled,sample);
264 for (
auto& listManager : lists) {
265 std::visit([timeNow,
this] (
auto&& arg) {
266 for (
auto& mgrPair : arg) {
269 auto& sampled = mgrPair.first;
270 auto& list = mgrPair.second;
272 for (
auto& outputListManagerV : lists) {
273 std::visit([timeNow, &list, &sampled,
this] (
auto&& outputListManager) {
274 using InputValT =
typename std::remove_reference_t<decltype(list)>::value_type;
275 using LMValT =
typename std::remove_reference_t<decltype(outputListManager)>::value_type;
279 if (runners.template hasMatchingAnalyser<InputValT,LMValT>()) {
281 runners.template analyse(timeNow,sampled,list,outputListManager, *
this);
283 }, outputListManagerV);
294 AnalysisDelegateManagerT& delegates;
295 AnalysisProviderManagerT& runners;
std::size_t SampledID
Definition: sampling.h:24
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
Convenience wrapper for all AnalysisDelegate types used by the analysis API.
Definition: runner.h:105
DelegateT & get()
CAN THROW std::bad_variant_access.
Definition: runner.h:125
Convenience wrapper for all AnalysisProvider types used by the analysis API.
Definition: runner.h:152
ProviderT & get()
CAN THROW std::bad_variant_access.
Definition: runner.h:178
Manages all sample lists, sources, sinks, and analysis instances for all data generated within a syst...
Definition: runner.h:233
void newSample(SampledID sampled, sampling::Sample< ValT > sample)
We are an analysis delegate ourselves - this is used by Source types, and by producers (analysis runn...
Definition: runner.h:242
void run(Date timeNow)
Run the relevant analyses given the current time point.
Definition: runner.h:255
Manages a set of lists for a particular Sample Value Type.
Definition: runner.h:23
A fixed size set that holds exactly one instance of the std::variant for each of the specified ValTs ...
Definition: runner.h:58
ValT & get()
CAN THROW std::bad_variant_access.
Definition: runner.h:68
The Sample taken from an object with ID of type SampledID.
Definition: sampling.h:28
Definition: sampling.h:102