mana: add c test plugin and make plugin loading work
This commit is contained in:
parent
da8f52730f
commit
edf0d291a9
5 changed files with 90 additions and 28 deletions
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
|
@ -9,9 +9,12 @@
|
|||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/mana_auto_replay",
|
||||
"args": ["~/Documents/is690-9Li_3H_run094_241020_124254_part001.zip"],
|
||||
"args": [
|
||||
"~/Documents/is690-9Li_3H_run094_241020_124254_part001.zip",
|
||||
"--plugin=src/libmana-plugin-c-test.so"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"cwd": "${workspaceFolder}/build",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
|
|
|
@ -25,7 +25,11 @@ if (MNODE_BUILD_TESTS)
|
|||
endif()
|
||||
|
||||
|
||||
add_library(rxi-logc INTERFACE)
|
||||
target_sources(rxi-logc INTERFACE internal/rxi/log.c)
|
||||
|
||||
add_library(mana-plugin-c-test SHARED mana_plugin_c_test.c)
|
||||
target_link_libraries(mana-plugin-c-test PRIVATE rxi-logc)
|
||||
|
||||
find_package(ROOT COMPONENTS Hist)
|
||||
if (ROOT_FOUND)
|
||||
|
|
|
@ -141,7 +141,7 @@ struct ManaCPlugin: public ManaPlugin
|
|||
mana_plugin_t plugin_;
|
||||
void *context_ = nullptr;
|
||||
|
||||
ManaCPlugin(mana_plugin_t plugin)
|
||||
explicit ManaCPlugin(mana_plugin_t plugin)
|
||||
: plugin_(plugin)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,27 +1,47 @@
|
|||
#include "internal/mana_api.h"
|
||||
#include "internal/rxi/log.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct Context
|
||||
{
|
||||
};
|
||||
|
||||
struct Context ctx_;
|
||||
|
||||
MANA_DEFINE_PLUGIN_INIT(init)
|
||||
{
|
||||
memset(&ctx_, 0, sizeof(ctx_));
|
||||
return &ctx_;
|
||||
struct Context *ctx = calloc(1, sizeof(*ctx));
|
||||
log_debug("init: ctx=%p", ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown) {}
|
||||
MANA_DEFINE_PLUGIN_SHUTDOWN(shutdown)
|
||||
{
|
||||
(void)context;
|
||||
log_debug("shutdown");
|
||||
}
|
||||
|
||||
MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run) {}
|
||||
MANA_DEFINE_PLUGIN_BEGIN_RUN(begin_run)
|
||||
{
|
||||
log_debug("begin_run: ctx=%p, descriptor_json=%s", context, descriptor_json);
|
||||
/* pretty useless as the json needs to be parsed back into some c structure describing the input
|
||||
*/
|
||||
}
|
||||
|
||||
MANA_DEFINE_PLUGIN_END_RUN(end_run) {}
|
||||
MANA_DEFINE_PLUGIN_END_RUN(end_run)
|
||||
{
|
||||
log_debug("end: ctx=%p, descriptor_json=%s", context, descriptor_json);
|
||||
}
|
||||
|
||||
MANA_DEFINE_PLUGIN_EVENT_DATA(process_event) {}
|
||||
MANA_DEFINE_PLUGIN_EVENT_DATA(process_event)
|
||||
{
|
||||
log_trace("event: ctx=%p, eventIndex=%d, arrayCount=%zu, totalBytes=%zu", context, eventIndex,
|
||||
arrayCount, totalBytes);
|
||||
}
|
||||
|
||||
MANA_DEFINE_PLUGIN_SYSTEM_EVENT(process_system_event) {}
|
||||
MANA_DEFINE_PLUGIN_SYSTEM_EVENT(process_system_event)
|
||||
{
|
||||
log_debug("system_event: ctx=%p, size=%zu", context, size);
|
||||
}
|
||||
|
||||
MANA_DEFINE_GET_PLUGIN(mana_get_plugin)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
// - create root trees or the new rntuples(?)
|
||||
// -> want plugins. similar to the mvme listfile_reader but on analysis data
|
||||
|
||||
#include <boost/dll.hpp>
|
||||
#include <cmrc/cmrc.hpp> // mnode::resources
|
||||
#include <mesytec-mvlc/mesytec-mvlc.h>
|
||||
#include <mesytec-mnode/mnode_cpp_types.h>
|
||||
|
@ -38,6 +39,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include "internal/argh.h"
|
||||
#include "internal/mana_arena.h"
|
||||
#include "internal/mana_lib.hpp"
|
||||
#include "internal/mana_analysis.h"
|
||||
|
@ -157,21 +159,50 @@ int main(int argc, char *argv[])
|
|||
auto f = cmrc::mnode::resources::get_filesystem().open("data/vme_module_data_sources.json");
|
||||
const auto jModuleDataSources = nlohmann::json::parse(f.begin(), f.end());
|
||||
|
||||
if (argc < 2)
|
||||
argh::parser parser({"-h", "--help", "--plugin"});
|
||||
parser.parse(argv);
|
||||
|
||||
auto filename = parser[1];
|
||||
|
||||
if (parser["-h"] || parser["--help"] || filename.empty())
|
||||
{
|
||||
std::cout << fmt::format("Usage: {} <listfile.zip>\n", argv[0]);
|
||||
return 1;
|
||||
std::cout << fmt::format("usage: {} [--plugin=<plugin.so>] <zipfile>\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string filename = argv[1];
|
||||
auto listfileContext = make_listfile_context(filename);
|
||||
|
||||
if (!listfileContext)
|
||||
{
|
||||
std::cerr << fmt::format("Error: could not open {}\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::unique_ptr<mana::ManaPlugin> manaPlugin;
|
||||
boost::dll::shared_library pluginHandle;
|
||||
|
||||
if (parser("--plugin"))
|
||||
{
|
||||
auto pluginFile = parser("--plugin").str();
|
||||
try
|
||||
{
|
||||
pluginHandle = boost::dll::shared_library(pluginFile);
|
||||
manaPlugin = std::make_unique<mana::ManaCPlugin>(
|
||||
pluginHandle.get<mana_plugin_t()>("mana_get_plugin")());
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << fmt::format("Error loading plugin: {}\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
manaPlugin = std::make_unique<mana::ManaCountingSink>();
|
||||
}
|
||||
|
||||
mana::ManaCountingSink manaPlugin;
|
||||
auto mana = mana::make_module_data_stage(filename, mana::Arena(), listfileContext->crateConfig,
|
||||
jModuleDataSources, &manaPlugin, nullptr);
|
||||
jModuleDataSources, manaPlugin.get(), nullptr);
|
||||
|
||||
auto event_data = [](void *ctx_, int crateIndex, int eventIndex,
|
||||
const mvlc::readout_parser::ModuleData *moduleDataList,
|
||||
|
@ -235,18 +266,22 @@ int main(int argc, char *argv[])
|
|||
mana.sink->end_run(mana.sinkContext, mana.runDescriptor.dump().c_str());
|
||||
mana.sink->shutdown(mana.sinkContext);
|
||||
|
||||
spdlog::info(
|
||||
"ManaCountingSink: eventCounts=[{}], totalBytes={}, systemEvents={}, systemEventBytes={}",
|
||||
fmt::join(manaPlugin.eventCounts, ", "), manaPlugin.totalBytes, manaPlugin.systemEventCount,
|
||||
manaPlugin.systemEventBytes);
|
||||
|
||||
for (size_t ei = 0; ei < manaPlugin.eventArrayHits.size(); ++ei)
|
||||
if (auto cp = dynamic_cast<mana::ManaCountingSink *>(manaPlugin.get()))
|
||||
{
|
||||
spdlog::info("event[{}]: {} hits", ei, manaPlugin.eventCounts[ei]);
|
||||
for (size_t ai = 0; ai < manaPlugin.eventArrayHits[ei].size(); ++ai)
|
||||
|
||||
spdlog::info("ManaCountingSink: eventCounts=[{}], totalBytes={}, systemEvents={}, "
|
||||
"systemEventBytes={}",
|
||||
fmt::join(cp->eventCounts, ", "), cp->totalBytes, cp->systemEventCount,
|
||||
cp->systemEventBytes);
|
||||
|
||||
for (size_t ei = 0; ei < cp->eventArrayHits.size(); ++ei)
|
||||
{
|
||||
auto name = mana.runDescriptor["events"][ei]["outputs"][ai]["name"];
|
||||
spdlog::info(" {}: {}", name, manaPlugin.eventArrayHits[ei][ai]);
|
||||
spdlog::info("event[{}]: {} hits", ei, cp->eventCounts[ei]);
|
||||
for (size_t ai = 0; ai < cp->eventArrayHits[ei].size(); ++ai)
|
||||
{
|
||||
auto name = mana.runDescriptor["events"][ei]["outputs"][ai]["name"];
|
||||
spdlog::info(" {}: {}", name, cp->eventArrayHits[ei][ai]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue