17DalFactory::get_known_class_name_ref(
const std::string& name)
19 std::lock_guard<std::mutex> scoped_lock(m_known_class_mutex);
20 return *m_known_classes.emplace(name).first;
24DalFactory::try_load_class_library(
Configuration& db,
const std::string& class_name)
27 auto&
c = db.get_class_info(class_name);
28 TLOG_DEBUG(1) <<
"Resolvung dal library for class " << class_name;
30 std::string
file =
c.p_schema_path;
31 std::string search{
"/schema/" };
32 auto start =
file.rfind(search);
33 if (start == std::string::npos) {
34 throw(DalPackageNameNotFound(
ERS_HERE, class_name, file));
36 start += search.size();
37 auto end =
file.find(
"/", start);
38 if (end == std::string::npos) {
39 throw(DalPackageNameNotFound(
ERS_HERE, class_name, file));
42 std::string
package = file.substr(start, end - start);
43 std::string library =
"lib" +
package + "_dal.so";
44 TLOG_DEBUG(1) <<
"Loading dal library " << library <<
" for class " << class_name;
46 auto handle = dlopen(library.c_str(), RTLD_LAZY | RTLD_GLOBAL);
47 if (handle ==
nullptr) {
51 return handle !=
nullptr;
58DalFactory::make(conffwk::DalRegistry& reg, conffwk::ConfigObject& o,
bool upcast_unregistered)
61 TLOG_DEBUG(50) <<
"Building object " << o.UID() <<
" of class " << o.class_name();
63 auto it = m_creators.find(o.class_name());
65 if (it == m_creators.end()) {
66 TLOG_DEBUG(50) <<
"Constructor for class " << o.class_name() <<
" not found";
68 if (!this->try_load_class_library(reg.configuration(), o.class_name())) {
71 it = m_creators.find(o.class_name());
72 if (it == m_creators.end()) {
73 throw dunedaq::conffwk::NotFound(
ERS_HERE,
"class", o.class_name().c_str());
76 TLOG() <<
">>> Constructor for class " << o.class_name() <<
" found";
79 auto dal_obj = it->second(reg, o);
80 TLOG_DEBUG(50) <<
"Object " << o.UID() <<
" of class " << o.class_name() <<
" created " << (
void*)dal_obj;
89DalFactory::make(conffwk::DalRegistry& reg, conffwk::ConfigObject& o,
const std::string& fallback_unregistred)
92 TLOG_DEBUG(50) <<
"Building object " << o.UID() <<
" of class " << o.class_name();
94 auto it = m_creators.find(o.class_name());
96 if (it == m_creators.end()) {
97 if (!this->try_load_class_library(reg.configuration(), o.class_name())) {
100 it = m_creators.find(o.class_name());
101 if (it == m_creators.end()) {
102 throw dunedaq::conffwk::NotFound(
ERS_HERE,
"class", o.class_name().c_str());
106 auto dal_obj = it->second(reg, o);
107 TLOG_DEBUG(50) <<
"Object " << o.UID() <<
" of class " << o.class_name() <<
" created " << (
void*)dal_obj;
113DalFactory::instance()
120DalFactory::get(Configuration& db, ConfigObject& obj,
const std::string& uid,
bool upcast_unregistered)
const
122 return (*instance().functions(db,
obj.class_name(), upcast_unregistered).m_creator_fn)(db,
obj, uid);
126DalFactory::get(Configuration& db, ConfigObject& obj,
const std::string& uid,
const std::string& class_name)
const
128 return (*instance().functions(db, class_name,
false).m_creator_fn)(db,
obj, uid);
131const DalFactoryFunctions&
132DalFactory::functions(Configuration& db,
const std::string& name,
bool upcast_unregistered)
134 auto it = m_classes.find(name);
136 if (it == m_classes.end()) {
137 if (!this->try_load_class_library(db, name)) {
140 it = m_classes.find(name);
141 if (it == m_classes.end()) {
142 throw dunedaq::conffwk::NotFound(
ERS_HERE,
"class", name.c_str());
150DalFactory::class4algo(Configuration& db,
const std::string& name,
const std::string&
algorithm)
const
152 for (
const auto& x : m_classes)
153 if (x.second.m_algorithms.find(
algorithm) != x.second.m_algorithms.end() && db.try_cast(x.first, name))
156 static const std::string empty;
160const DalFactoryFunctions&
161DalFactory::functions(
const std::string& name)
const
163 auto it = m_classes.find(name);
165 ERS_ASSERT_MSG((it != m_classes.end()),
"writer lock was not initialized");
#define ERS_ASSERT_MSG(expression, message)
Defines base class for cache of template objects.
#define TLOG_DEBUG(lvl,...)