93 lines
2.9 KiB
C
93 lines
2.9 KiB
C
|
#ifndef B63F110F_BB53_46E7_AA8E_FF6BE10CAB40
|
||
|
#define B63F110F_BB53_46E7_AA8E_FF6BE10CAB40
|
||
|
|
||
|
#include "mana_arena.h"
|
||
|
#include "mana_lib.hpp"
|
||
|
#include <mesytec-mvlc/mesytec-mvlc.h>
|
||
|
|
||
|
namespace mesytec::mnode::mana
|
||
|
{
|
||
|
|
||
|
struct BitFilterExtractor
|
||
|
{
|
||
|
mvlc::util::DataFilter filter;
|
||
|
mvlc::util::CacheEntry fAddress;
|
||
|
mvlc::util::CacheEntry fValue;
|
||
|
mana_offset_array_t *dest;
|
||
|
};
|
||
|
|
||
|
struct ModuleDataStage
|
||
|
{
|
||
|
mana::Arena arena;
|
||
|
nlohmann::json runDescriptor;
|
||
|
// eventindex -> list of pointers to output offset arrays
|
||
|
std::vector<std::vector<mana_offset_array_t *>> eventArrayPointers;
|
||
|
// eventIndex, moduleIndex -> list of filters attached to the module.
|
||
|
std::vector<std::vector<std::vector<BitFilterExtractor>>> dataSources;
|
||
|
mana_sink_t sink = {};
|
||
|
void *sinkContext = nullptr;
|
||
|
};
|
||
|
|
||
|
inline ModuleDataStage make_module_data_stage(const std::string &runName,
|
||
|
const mvlc::CrateConfig &crateConfig,
|
||
|
nlohmann::json moduleDb, mana_sink_t sink,
|
||
|
void *sinkContext)
|
||
|
{
|
||
|
ModuleDataStage result;
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
inline void module_data_stage_begin_run(ModuleDataStage &ctx)
|
||
|
{
|
||
|
ctx.sink.begin_run(ctx.sinkContext, ctx.runDescriptor.dump().c_str());
|
||
|
}
|
||
|
|
||
|
inline void module_data_stage_end_run(ModuleDataStage &ctx)
|
||
|
{
|
||
|
ctx.sink.end_run(ctx.sinkContext, ctx.runDescriptor.dump().c_str());
|
||
|
}
|
||
|
|
||
|
inline void
|
||
|
module_data_stage_process_module_data(ModuleDataStage &ctx, int eventIndex,
|
||
|
const mvlc::readout_parser::ModuleData *moduleDataList,
|
||
|
unsigned moduleCount)
|
||
|
{
|
||
|
auto extract_module_data =
|
||
|
[](const mvlc::readout_parser::DataBlock &data, BitFilterExtractor &ex)
|
||
|
{
|
||
|
auto dest = get_span<float>(*ex.dest);
|
||
|
|
||
|
std::fill(std::begin(dest), std::end(dest), mnode::make_quiet_nan());
|
||
|
|
||
|
for (const u32 *word = data.data, *end = data.data + data.size; word < end; ++word)
|
||
|
{
|
||
|
if (mvlc::util::matches(ex.filter, *word))
|
||
|
{
|
||
|
u32 address = mvlc::util::extract(ex.fAddress, *word);
|
||
|
u32 value = mvlc::util::extract(ex.fValue, *word);
|
||
|
assert(address < dest.size());
|
||
|
dest[address] = value;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
auto &eventSources = ctx.dataSources.at(eventIndex);
|
||
|
|
||
|
for (unsigned mi = 0; mi < moduleCount; ++mi)
|
||
|
{
|
||
|
auto &moduleData = moduleDataList[mi];
|
||
|
auto dataBlock = moduleData.hasDynamic ? dynamic_span(moduleData) : prefix_span(moduleData);
|
||
|
|
||
|
for (auto &source: eventSources.at(mi))
|
||
|
extract_module_data(dataBlock, source);
|
||
|
}
|
||
|
|
||
|
// auto arrays = ctx.eventArrayPointers.at(eventIndex);
|
||
|
// ctx.sink.process_event(ctx.sinkContext, eventIndex,
|
||
|
}
|
||
|
|
||
|
} // namespace mesytec::mnode::mana
|
||
|
|
||
|
#endif /* B63F110F_BB53_46E7_AA8E_FF6BE10CAB40 */
|