If you are using GitLab outside of the ILL, then you will need to use HTTPS and not SSH for clone/push/pull operations. SSH will work normally if you are using the VPN.

Commit e30f47ee authored by Tobias WEBER's avatar Tobias WEBER

more debugging

parent b140af43
......@@ -13,7 +13,7 @@ CC = g++
#CC = clang++
# debug or unstable version?
DO_DEBUG = 0
DO_DEBUG = 1
IS_UNSTABLE = 0
# optimise specifically for THIS processor?
......
......@@ -367,9 +367,9 @@ ConvoDlg::~ConvoDlg()
if(m_pSqwParamDlg) { delete m_pSqwParamDlg; m_pSqwParamDlg = nullptr; }
if(m_pFavDlg) { delete m_pFavDlg; m_pFavDlg = nullptr; }
if(m_pSqw) m_pSqw.reset();
if(m_pMenuBar) { delete m_pMenuBar; m_pMenuBar = nullptr; }
if(m_pSqw) m_pSqw.reset();
unload_sqw_plugins();
}
......@@ -404,6 +404,7 @@ void ConvoDlg::createSqwModel(const QString& qstrFile)
//return;
}
m_pSqw.reset();
m_pSqw = construct_sqw(strSqwIdent, strSqwFile);
if(!m_pSqw)
{
......@@ -428,6 +429,7 @@ void ConvoDlg::SqwParamsChanged(const std::vector<SqwBase::t_var>& vecVars,
const std::vector<SqwBase::t_var_fit>* pvecVarsFit)
{
if(!m_pSqw) return;
m_pSqw->SetVars(vecVars);
if(pvecVarsFit) m_pSqw->SetFitVars(*pvecVarsFit);
......
......@@ -383,7 +383,25 @@ std::shared_ptr<SqwBase> sqw_construct(const std::string& strCfgFile)
}
SqwBase* sqw_construct_raw(const std::string& strCfgFile)
{
return new SqwProc<SqwJl>(strCfgFile);
}
void sqw_destruct_raw(SqwBase *sqw)
{
if(sqw) delete sqw;
}
// exports from so file
BOOST_DLL_ALIAS(sqw_info, takin_sqw_info);
// construction interface
BOOST_DLL_ALIAS(sqw_construct, takin_sqw);
// alternate raw construction interface
//BOOST_DLL_ALIAS(sqw_construct_raw, takin_sqw_new);
//BOOST_DLL_ALIAS(sqw_destruct_raw, takin_sqw_del);
// ----------------------------------------------------------------------------
......@@ -390,8 +390,9 @@ SqwProc<t_sqw>::SqwProc(const std::string& strCfg) : SqwProc<t_sqw>::SqwProc(str
template<class t_sqw>
SqwProc<t_sqw>::~SqwProc()
{
// is this instance the last?
if(m_pMem.use_count() > 1) return;
// make sure that this instance is the last
if(m_pMem.use_count() > 1)
return;
try
{
......@@ -408,7 +409,6 @@ SqwProc<t_sqw>::~SqwProc()
ipr::message_queue::remove(("takin_sqw_proc_out_" + m_strProcName).c_str());
ipr::shared_memory_object::remove(("takin_sqw_proc_mem_" + m_strProcName).c_str());
m_pMem->destroy<t_sh_str>(("takin_sqw_proc_params_" + m_strProcName).c_str());
tl::log_debug("Removed process memory \"", "takin_sqw_proc_*_", m_strProcName, "\".");
......@@ -531,6 +531,7 @@ SqwBase* SqwProc<t_sqw>::shallow_copy() const
pSqw->m_strProcName = this->m_strProcName;
pSqw->m_pidChild = this->m_pidChild;
pSqw->m_pSharedPars = this->m_pSharedPars;
pSqw->m_iRefCnt = this->m_iRefCnt;
return pSqw;
}
......
......@@ -360,12 +360,14 @@ SqwBase* SqwPy::shallow_copy() const
static const char* pcModIdent = "py";
static const char* pcModName = "Python Model";
std::tuple<std::string, std::string, std::string> sqw_info()
{
//tl::log_info("In ", __func__, ".");
return std::make_tuple(TAKIN_VER, pcModIdent, pcModName);
}
std::shared_ptr<SqwBase> sqw_construct(const std::string& strCfgFile)
{
//tl::log_info("In ", __func__, ".");
......@@ -374,7 +376,25 @@ std::shared_ptr<SqwBase> sqw_construct(const std::string& strCfgFile)
}
SqwBase* sqw_construct_raw(const std::string& strCfgFile)
{
return new SqwProc<SqwPy>(strCfgFile);
}
void sqw_destruct_raw(SqwBase* sqw)
{
if(sqw) delete sqw;
}
// exports from so file
BOOST_DLL_ALIAS(sqw_info, takin_sqw_info);
// construction interface
BOOST_DLL_ALIAS(sqw_construct, takin_sqw);
// alternate raw construction interface
//BOOST_DLL_ALIAS(sqw_construct_raw, takin_sqw_new);
//BOOST_DLL_ALIAS(sqw_destruct_raw, takin_sqw_del);
// ----------------------------------------------------------------------------
......@@ -8,6 +8,7 @@
#include "sqwfactory.h"
#include "sqw.h"
#include "sqw_uniform_grid.h"
#include "sqwrawdelegate.h"
#include "tlibs/log/log.h"
#include "tlibs/file/file.h"
......@@ -24,13 +25,25 @@
using t_pfkt_info = std::tuple<std::string, std::string, std::string>(*)();
using t_fkt_info = typename std::remove_pointer<t_pfkt_info>::type;
// sqw module function: "takin_sqw"
// sqw module creation function: "takin_sqw"
// old interface returning a shared pointer, which might be dangerous for so files,
// see: https://www.boost.org/doc/libs/1_72_0/doc/html/boost_dll/missuses.html
using t_pfkt = std::shared_ptr<SqwBase>(*)(const std::string&);
using t_fkt = typename std::remove_pointer<t_pfkt>::type;
// new raw pointer constructor interface
using t_pfkt_raw_new = SqwBase*(*)(const std::string&);
using t_fkt_raw_new = typename std::remove_pointer<t_pfkt_raw_new>::type;
using t_pfkt_raw_del = void(*)(SqwBase*);
using t_fkt_raw_del = typename std::remove_pointer<t_pfkt_raw_del>::type;
// key: identifier, value: [func, long name]
using t_mapSqw = std::unordered_map<std::string, std::tuple<t_pfkt, std::string>>;
using t_mapSqwRaw = std::unordered_map<std::string, std::tuple<t_pfkt_raw_new, t_pfkt_raw_del, std::string>>;
// shared_ptr constructors
static t_mapSqw g_mapSqw =
{
{ "kd", t_mapSqw::mapped_type {
......@@ -64,6 +77,10 @@ static t_mapSqw g_mapSqw =
};
// raw pointer constructors
static t_mapSqwRaw g_mapSqwRaw;
std::vector<std::tuple<std::string, std::string>> get_sqw_names()
{
......@@ -80,6 +97,15 @@ std::vector<std::tuple<std::string, std::string>> get_sqw_names()
vec.emplace_back(std::move(tup));
}
for(const t_mapSqwRaw::value_type& val : g_mapSqwRaw)
{
t_tup tup;
std::get<0>(tup) = val.first;
std::get<1>(tup) = std::get<2>(val.second);
vec.emplace_back(std::move(tup));
}
std::sort(vec.begin(), vec.end(), [](const t_tup& tup0, const t_tup& tup1) -> bool
{
const std::string& str0 = std::get<1>(tup0);
......@@ -87,6 +113,7 @@ std::vector<std::tuple<std::string, std::string>> get_sqw_names()
return std::lexicographical_compare(str0.begin(), str0.end(), str1.begin(), str1.end());
});
return vec;
}
......@@ -95,14 +122,37 @@ std::shared_ptr<SqwBase> construct_sqw(const std::string& strName,
const std::string& strConfigFile)
{
typename t_mapSqw::const_iterator iter = g_mapSqw.find(strName);
if(iter == g_mapSqw.end())
typename t_mapSqwRaw::const_iterator iterRaw = g_mapSqwRaw.find(strName);
if(iter != g_mapSqw.end())
{
t_pfkt pFkt = std::get<0>(iter->second);
if(!pFkt)
{
tl::log_err("Invalid constructor function for S(q,w) model.");
return nullptr;
}
tl::log_debug("Constructing \"", iter->first, "\" S(q,w) module.");
return (*pFkt)(strConfigFile);
}
else if(iterRaw != g_mapSqwRaw.end())
{
tl::log_err("No S(q,w) model of name \"", strName, "\" found.");
return nullptr;
t_pfkt_raw_new pFktNew = std::get<0>(iterRaw->second);
t_pfkt_raw_del pFktDel = std::get<1>(iterRaw->second);
if(!pFktNew || !pFktDel)
{
tl::log_err("Invalid constructor function for S(q,w) model.");
return nullptr;
}
tl::log_debug("Constructing \"", iterRaw->first, "\" S(q,w) module via raw interface.");
return std::make_shared<SqwRawDelegate>(pFktNew(strConfigFile));
}
//tl::log_debug("Constructing ", iter->first, ".");
return (*std::get<0>(iter->second))(strConfigFile);
tl::log_err("No S(q,w) model of name \"", strName, "\" found.");
return nullptr;
}
......@@ -139,7 +189,7 @@ void unload_sqw_plugins()
pMod->unload();
pMod.reset();
//tl::log_debug("Unloaded plugin.");
tl::log_debug("Unloaded plugin.");
}
g_vecMods.clear();
......@@ -166,12 +216,16 @@ void load_sqw_plugins()
std::shared_ptr<so::shared_library> pmod =
std::make_shared<so::shared_library>(strPlugin,
so::load_mode::rtld_lazy /*| so::load_mode::rtld_global*/);
if(!pmod) continue;
if(!pmod)
continue;
// import info function
if(!pmod->has("takin_sqw_info"))
continue;
std::function<t_fkt_info> fktInfo =
pmod->get<t_pfkt_info>("takin_sqw_info");
if(!fktInfo) continue;
if(!fktInfo)
continue;
auto tupInfo = fktInfo();
const std::string& strTakVer = std::get<0>(tupInfo);
......@@ -191,27 +245,60 @@ void load_sqw_plugins()
tl::log_err("Skipping S(q,w) plugin \"", strPlugin,
"\" as it was compiled for Takin version ", strTakVer,
", but this is version ", TAKIN_VER, ".");
pmod->unload();
continue;
}
// import factory function
t_pfkt pFkt = pmod->get<t_pfkt>("takin_sqw");
if(!pFkt) continue;
g_mapSqw.insert( t_mapSqw::value_type {
strModIdent,
t_mapSqw::mapped_type { pFkt, strModLongName }
});
if(pmod->has("takin_sqw_new") && pmod->has("takin_sqw_del"))
{
t_pfkt_raw_new pFktNew = pmod->get<t_pfkt_raw_new>("takin_sqw_new");
t_pfkt_raw_del pFktDel = pmod->get<t_pfkt_raw_del>("takin_sqw_del");
if(!pFktNew || !pFktDel)
{
pmod->unload();
continue;
}
// use the raw new/delete interface if it exists
g_mapSqwRaw.insert( t_mapSqwRaw::value_type
{
strModIdent,
t_mapSqwRaw::mapped_type { pFktNew, pFktDel, strModLongName }
});
}
else if(pmod->has("takin_sqw"))
{
// if raw interface does not exist, try the old shared_ptr one
t_pfkt pFkt = pmod->get<t_pfkt>("takin_sqw");
if(!pFkt)
{
pmod->unload();
continue;
}
g_mapSqw.insert( t_mapSqw::value_type
{
strModIdent,
t_mapSqw::mapped_type { pFkt, strModLongName }
});
}
else
{
// no valid constructor interface found
continue;
}
g_vecMods.push_back(pmod);
g_vecMods.emplace_back(std::move(pmod));
tl::log_info("Loaded plugin: ", strPlugin,
" -> ", strModIdent, " (\"", strModLongName, "\").");
}
catch(const std::exception& ex)
{
//tl::log_err("Could not load ", strPlugin, ". Reason: ", ex.what());
tl::log_err("Could not load ", strPlugin, ". Reason: ", ex.what());
}
}
}
......
/**
* interface for S(q,w) models
* @author Tobias Weber <tobias.weber@tum.de>
* @date 6-apr-2020
* @license GPLv2
*/
#ifndef __MCONV_SQW_RAWDELEGATE_H__
#define __MCONV_SQW_RAWDELEGATE_H__
#include "sqwbase.h"
class SqwRawDelegate : public SqwBase
{
public:
SqwRawDelegate() = delete;
SqwRawDelegate(SqwBase* pDelegate) : m_pDelegate{pDelegate}
{
}
virtual ~SqwRawDelegate()
{
}
virtual std::tuple<std::vector<t_real_reso>, std::vector<t_real_reso>>
disp(t_real_reso dh, t_real_reso dk, t_real_reso dl) const override
{
return m_pDelegate->disp(dh, dk, dl);
}
virtual t_real_reso operator()(t_real_reso dh, t_real_reso dk, t_real_reso dl, t_real_reso dE) const override
{
return m_pDelegate->operator()(dh, dk, dl, dE);
}
virtual bool IsOk() const override
{
return m_pDelegate->IsOk();
}
virtual std::vector<t_var> GetVars() const override
{
return m_pDelegate->GetVars();
}
virtual const std::vector<t_var_fit>& GetFitVars() const override
{
return m_pDelegate->GetFitVars();
}
virtual void SetVars(const std::vector<t_var>& vars) override
{
m_pDelegate->SetVars(vars);
}
virtual void SetFitVars(const std::vector<t_var_fit>& vecFit) override
{
m_pDelegate->SetFitVars(vecFit);
}
virtual bool SetVarIfAvail(const std::string& strKey, const std::string& strNewVal) override
{
return m_pDelegate->SetVarIfAvail(strKey, strNewVal);
}
virtual const SqwBase& operator=(const SqwBase& sqw) override
{
return m_pDelegate->operator=(sqw);
}
virtual SqwBase* shallow_copy() const override
{
SqwRawDelegate *pDelegate = new SqwRawDelegate(m_pDelegate->shallow_copy());
return pDelegate;
}
private:
SqwBase* m_pDelegate = nullptr;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment