Include external library in root 6.22/02

Hi there!
I ask for your help to be able to include a library written by me in a root file
This is dataclass.h

#define DATACLASS
#include<cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

class Dataset
{
public:
    vector<double> asse_x;
    vector<double> asse_y;
    string description;

    Dataset();
    Dataset(string folder, string fname) { lettura(folder, fname); };
    ~Dataset();

    int find_maximum(vector<double> &vec)
    {
        return max_element(vec.begin(), vec.end()) - vec.begin();
    };
    void erase_and_take(int del_sx, int del_dx,int take,  vector<double> &asse_y_temp)
    {

        int max_y1;
        int max_y2;
        int max_y;

        for (int i = 0; i < abs(del_sx); i++)
        {
            max_y1 = find_maximum(asse_y_temp);
            asse_y_temp.erase(asse_y_temp.begin() + (max_y1 - 1));
        }
        
        for (int i = 0; i < abs(del_dx); i++)
        {
            max_y2 = find_maximum(asse_y_temp);
            asse_y_temp.erase(asse_y_temp.begin() + (max_y2 + 1));
        }

        max_y = find_maximum(asse_y_temp);
        asse_y_temp.erase(asse_y_temp.begin(),asse_y_temp.begin()+max_y-take);
        max_y=find_maximum(asse_y_temp);
        asse_y_temp.erase(asse_y_temp.begin()+max_y+take,asse_y_temp.begin()+asse_y_temp.size());
        asse_y_temp.erase(asse_y_temp.begin() + max_y);
        
    };
};

(The library is 100% functional because i tested it.)
And this is a simple .cxx file that request dataclass.h

#include "TH1.h"
#include "TMath.h"
#include "TF1.h"
#include "TLegend.h"
#include "TCanvas.h"
#include <fstream>

#include "TFitResult.h"
#include "TMatrixD.h"
#include "../Programmi/dataclass.h"

using namespace std;

void fit_for_max()
{
    TCanvas *c1 = new TCanvas("c1", "Canvas", 200, 10, 1000, 700);

    c1->SetGrid();
    c1->SetFillColor(0);


    Dataset *diff;
    vector<double> asse_x_temp;
    vector<double> asse_y_temp;
    diff->lettura("../Dati", "/1f_10p_sgnbkg.xls");
    diff->erase_and_take(10, 10, 8, asse_y_temp);


    TVectorD root_asse_y_temp(asse_y_temp.size(), asse_y_temp.data());
    root_asse_y_temp.Print();
    vector<double> asse_x;
    for (int i =0 ; i<16 ;i++){
        asse_x[i]=i;

    }
    TVectorD root_asse_x(asse_x.size(), asse_x.data());

    TGraph *grafico= new TGraph(root_asse_x, root_asse_y_temp);
    grafico->Draw();
}

Root gives me this error when I run .x fit_for_max.cxx:
IncrementalExecutor::executeFunction: symbol ‘ZStL19__constant_string_pIcEbPKT’ unresolved while linking [cling interface function]!
You are probably missing the definition of bool std::__constant_string_p(char const*)
Maybe you need to load the corresponding shared library?
Is it possible to include a proprietary library in this way? I couldn’t interpret the root error. Thank you very much for your help.
Have a nice day :slight_smile: .

Hello,

It should be fine what you are doing (I don’t get your error but another one because there is no lettura in Dataset). It could be a problem with your ROOT installation.

In what system are you running this? How did you install ROOT?

1 Like

Hi @etejedor thanks for the answer. I’m running that programm in Linux .
Even some things change, it still doesn’t work.
Using the erase_and_take () function in a .cpp program compiles without problems and the function works. Using the same function in a root program I get this error printed:

You are probably missing the definition of __gnu_cxx::__ops::__iter_less_iter()
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZN9__gnu_cxxmiIPKdSt6vectorIdSaIdEEEENS_17__normal_iteratorIT_T0_E15difference_typ
eERKS9_SC_' unresolved while linking [cling interface function]!
You are probably missing the definition of __gnu_cxx::__normal_iterator<double const*, std::vector<double, std::allocator<double>
> >::difference_type __gnu_cxx::operator-<double const*, std::vector<double, std::allocator<double> > >(__gnu_cxx::__normal_iter
ator<double const*, std::vector<double, std::allocator<double> > > const&, __gnu_cxx::__normal_iterator<double const*, std::vecto
r<double, std::allocator<double> > > const&)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZN9__gnu_cxxneIPdSt6vectorIdSaIdEEEEbRKNS_17__normal_iteratorIT_T0_EESA_' unresolv
ed while linking [cling interface function]!
You are probably missing the definition of bool __gnu_cxx::operator!=<double*, std::vector<double, std::allocator<double> > >(__g
nu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > > const&, __gnu_cxx::__normal_iterator<double*, s
td::vector<double, std::allocator<double> > > const&)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZStanSt12memory_orderSt23__memory_order_modifier' unresolved while linking [cling
interface function]!
You are probably missing the definition of std::operator&(std::memory_order, std::__memory_order_modifier)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZSt4moveIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEES6_ET0_T_S8_S7_' unre
solved while linking [cling interface function]!
You are probably missing the definition of __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > > s
td::move<__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<doubl
e*, std::vector<double, std::allocator<double> > > >(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<dou
ble> > >, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<doub
le*, std::vector<double, std::allocator<double> > >)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZSt13__max_elementIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEENS0_5__ops1
5_Iter_less_iterEET_S9_S9_T0_' unresolved while linking [cling interface function]!
You are probably missing the definition of __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > > s
td::__max_element<__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__ops::_Iter_l
ess_iter>(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__normal_iterator<doub
le*, std::vector<double, std::allocator<double> > >, __gnu_cxx::__ops::_Iter_less_iter)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZSt8_DestroyIPddEvT_S1_RSaIT0_E' unresolved while linking [cling interface functio
n]!
You are probably missing the definition of void std::_Destroy<double*, double>(double*, double*, std::allocator<double>&)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZN9__gnu_cxxmiIPdSt6vectorIdSaIdEEEENS_17__normal_iteratorIT_T0_E15difference_type
ERKS8_SB_' unresolved while linking [cling interface function]!
You are probably missing the definition of __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >::
difference_type __gnu_cxx::operator-<double*, std::vector<double, std::allocator<double> > >(__gnu_cxx::__normal_iterator<double*
, std::vector<double, std::allocator<double> > > const&, __gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator
<double> > > const&)
Maybe you need to load the corresponding shared library?

(now the erase_and_take function needs another vector, I just changed the function to dataclass.h)
I installed root following this guide but a year ago:

Thank you so much for the help.

Hi,

I would suggest you try to install a more recent ROOT version following the instructions here:

If that works for you, installing ROOT via conda should be fast and easy. I would then try again to run your macro with that installation.

I tried on a pc that installed to root with conda and it doesn’t work. The same error is returned. However, an empty canvas is generated.

Hey,

Would you be interested in trying the snap package? It’s currently a bit experimental and needing feedback, but I’d be very curious to know if it can help you out here.

sudo snap install root-framework should be all you need, you could then run it with root as usual, making sure it’s not calling your own installation or the Conda package (I.E, make sure which root returns a path with /snap/ in it, you could also launch with snap run root-framework to be more explicit)

I tried and this is the results. Now it create a canvas.
root [0] .x prova.cxx

*** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:

#0 0x00007fb7a957adba in __GI___wait4 (pid=1604651, stat_loc=stat_loc
entry=0x7ffca7046868, options=options
entry=0, usage=usage
entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:27
#1 0x00007fb7a957ad7b in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7ffca7046868, options=options
entry=0) at waitpid.c:38
#2 0x00007fb7a94ea0e7 in do_system (line=) at …/sysdeps/posix/system.c:172
#3 0x00007fb7a9bacf9e in TUnixSystem::StackTrace() () from /opt/root/6.22.02-install/lib/libCore.so
#4 0x00007fb7a9ba9e15 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/6.22.02-install/lib/libCore.so
#5
#6 0x00007fb7a988db00 in ?? ()
#7 0x00007ffca70495d8 in ?? ()
#8 0x00007fb7a988d807 in ?? ()
#9 0x00007ffca7049568 in ?? ()
#10 0x00007ffca70495d0 in ?? ()
#11 0x0000000000000008 in ?? ()
#12 0x0000000000000000 in ?? ()

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#6 0x00007fb7a988db00 in ?? ()
#7 0x00007ffca70495d8 in ?? ()
#8 0x00007fb7a988d807 in ?? ()
#9 0x00007ffca7049568 in ?? ()
#10 0x00007ffca70495d0 in ?? ()
#11 0x0000000000000008 in ?? ()
#12 0x0000000000000000 in ?? ()

That looks interesting, to be clear, are you running root there with snap run root-framework?

I notice it’s trying to access /opt/root/6.22.02-install/lib/libCore.so, which should be denied by the snap sandboxing since it’s not actually a file in the snap itself.

More importantly, the snap shouldn’t really be trying to access this file at all, given it’s version 6.22.06, and shouldn’t know 6.22.02 even exists.

Could you give the output of env, my guess here is that there’s something that’s trying to instruct ROOT to access libraries that aren’t ABI compatible for whatever reason, and it’s effecting all 3 installation formats to various degrees. It’s probably worth trying to reboot the system and try again, or look about in .bashrc for something that might be setting ROOT specific variables.

This is the output

SHELL=/bin/bash
WINDOWID=71303175
QT_ACCESSIBILITY=1
JUPYTER_CONFIG_DIR=/opt/root/6.22.02-install/etc/notebook
COLORTERM=truecolor
XDG_CONFIG_DIRS=/etc/xdg/xdg-i3:/etc/xdg
LANGUAGE=
I3SOCK=/run/user/1000/i3/ipc-socket.1031
MATHEMATICA_HOME=/usr/local/Wolfram/Mathematica/12.1
LC_ADDRESS=it_IT.UTF-8
LC_NAME=it_IT.UTF-8
SSH_AUTH_SOCK=/tmp/ssh-M67B35LXu1P1/agent.1031
SHELL_SESSION_ID=feebc4ca034e40079671ab5324387c8a
CLING_STANDARD_PCH=none
DESKTOP_SESSION=i3
LC_MONETARY=it_IT.UTF-8
SSH_AGENT_PID=1097
GTK_MODULES=gail:atk-bridge
XDG_SEAT=seat0
PWD=/home/fabio
XDG_SESSION_DESKTOP=i3
LOGNAME=fabio
QT_QPA_PLATFORMTHEME=qt5ct
XDG_SESSION_TYPE=x11
MANPATH=/opt/root/6.22.02-install/man:/usr/local/man:/usr/local/share/man:/usr/share/man
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
XAUTHORITY=/run/user/1000/gdm/Xauthority
WINDOWPATH=2
HOME=/home/fabio
USERNAME=fabio
SHLIB_PATH=/opt/root/6.22.02-install/lib
LC_PAPER=it_IT.UTF-8
LANG=en_US.UTF-8
DYLD_LIBRARY_PATH=/opt/root/6.22.02-install/lib
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=
30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lz4=01;31:.l
zh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=01;31:.zip=01;31:.z=01;31:.dz=01;31:.gz=01;31:.lrz=01;31:.l
z=01;31:
.lzo=01;31:.xz=01;31:.zst=01;31:.tzst=01;31:.bz2=01;31:.bz=01;31:.tbz=01;31:.tbz2=01;31:.tz=01;31:.deb=01;31:.
rpm=01;31:.jar=01;31:.war=01;31:.ear=01;31:.sar=01;31:.rar=01;31:.alz=01;31:.ace=01;31:.zoo=01;31:.cpio=01;31:.7z=01;31
:.rz=01;31:.cab=01;31:.wim=01;31:.swm=01;31:.dwm=01;31:.esd=01;31:.jpg=01;35:.jpeg=01;35:.mjpg=01;35:.mjpeg=01;35:.gif
=01;35:
.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:
.svg=01;35:.svgz=01;35:.mng=01;35:.pcx=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.m2v=01;35:.mkv=01;35:.webm=01;35:.ogm=0
1;35:.mp4=01;35:.m4v=01;35:.mp4v=01;35:.vob=01;35:.qt=01;35:.nuv=01;35:.wmv=01;35:.asf=01;35:.rm=01;35:.rmvb=01;35:.fl
c=01;35:
.avi=01;35:.fli=01;35:.flv=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.yuv=01;35:.cgm=01;35:.emf=01;35:.o
gv=01;35:.ogx=01;35:.aac=00;36:.au=00;36:.flac=00;36:.m4a=00;36:.mid=00;36:.midi=00;36:.mka=00;36:.mp3=00;36:.mpc=00;36
:.ogg=00;36:.ra=00;36:.wav=00;36:.oga=00;36:.opus=00;36:.spx=00;36:*.xspf=00;36:
XDG_CURRENT_DESKTOP=KDE
KONSOLE_DBUS_SERVICE=:1.202013
KONSOLE_DBUS_SESSION=/Sessions/1
PROFILEHOME=
CMAKE_PREFIX_PATH=/opt/root/6.22.02-install
KONSOLE_VERSION=191203
LESSCLOSE=/usr/bin/lesspipe %s %s
XDG_SESSION_CLASS=user
PYTHONPATH=/opt/root/6.22.02-install/lib
TERM=xterm-256color
LC_IDENTIFICATION=it_IT.UTF-8
LESSOPEN=| /usr/bin/lesspipe %s
USER=fabio
COLORFGBG=0;15
DISPLAY=:0
LIBPATH=/opt/root/6.22.02-install/lib
SHLVL=1
LC_TELEPHONE=it_IT.UTF-8
JUPYTER_PATH=/opt/root/6.22.02-install/etc/notebook
LC_MEASUREMENT=it_IT.UTF-8
XDG_VTNR=2
ROOTSYS=/opt/root/6.22.02-install
XDG_SESSION_ID=1
LD_LIBRARY_PATH=/opt/root/6.22.02-install/lib
XDG_RUNTIME_DIR=/run/user/1000
LC_TIME=it_IT.UTF-8
XDG_DATA_DIRS=/usr/share/i3:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
PATH=/opt/root/6.22.02-install/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap
/bin
GDMSESSION=i3
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
LC_NUMERIC=it_IT.UTF-8
KONSOLE_DBUS_WINDOW=/Windows/1
_=/usr/bin/env

The environment variables there make sense as to why the snap is loooking there. That’s a pretty big oversight on my part so thanks for that, I’ll patch it tomorrow to make sure those variables are cleared automatically for the snap.

Try running the snap without those variables set, I.E, avoid running any “thisroot.sh” scripts prior to executing it, whether manually or via .bashrc or anything equivilent. You could also try running ROOT from the desktop icon that should now be in your start menu, since it might inherit different variables than the terminal.

If it could help i found this in my .bashrc :

#exec_always root
source /opt/root/6.22.02-install/bin/thisroot.sh

After deleting this line of text I tried to restart root.
Now I get the same error as before but with some differences:

*** Break *** segmentation violation
0x00007f3b5e15a40a in from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5d93e210 in from /snap/root-framework/14/lib/x86_64-linux-gnu/libc.so.6
0x00007f3b4cc1ae7e in ZNK9__gnu_cxx5__ops15_Iter_less_iterclINS_17__normal_iteratorIPdSt6vectorIdSaIdEEEES8_EEbT_T0 + 0x24 from /snap/root-framework/14/usr/local/lib/libMathCore.so
0x00007f3b4cc4af87 in ZSt13__max_elementIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEENS0_5__ops15_Iter_less_iterEET_S9_S9_T0 + 0x81 from /snap/root-framework/14/usr/local/lib/libMathCore.so
0x00007f3b4cc49dba in ZSt11max_elementIN9__gnu_cxx17__normal_iteratorIPdSt6vectorIdSaIdEEEEET_S7_S7 + 0x3b from /snap/root-framework/14/usr/local/lib/libMathCore.so
0x00007f3b5d8358ac in
0x00007f3b5d83596f in
0x00007f3b5d8351a7 in
0x00007f3b5d83906a in
0x00007f3b59ea2074 in _ZNK5cling19IncrementalExecutor14executeWrapperEN4llvm9StringRefEPNS_5ValueE + 0x344 from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59e29e37 in _ZN5cling11Interpreter11RunFunctionEPKN5clang12FunctionDeclEPNS_5ValueE + 0x97 from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59e2b73d in _ZN5cling11Interpreter16EvaluateInternalERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS_18CompilationOptionsEPNS_5ValueEPPNS_11TransactionEm + 0x1cd from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59efb716 in _ZN5cling8MetaSema13actOnxCommandEN4llvm9StringRefES2_PNS_5ValueE + 0x446 from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59f093ca in _ZN5cling10MetaParser10isXCommandERNS_8MetaSema12ActionResultEPNS_5ValueE + 0x19a from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59f0a84e in _ZN5cling10MetaParser9isCommandERNS_8MetaSema12ActionResultEPNS_5ValueE + 0x9e from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59ef4c21 in _ZN5cling13MetaProcessor7processEN4llvm9StringRefERNS_11Interpreter17CompilationResultEPNS_5ValueEb + 0x191 from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59ceda81 in from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59cee555 in from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b59cf23bf in from /snap/root-framework/14/usr/local/lib/libCling.so
0x00007f3b5dfc7f4e in _ZN12TApplication11ExecuteFileEPKcPib + 0x8a0 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5dfc76ac in _ZN12TApplication11ProcessFileEPKcPib + 0x34 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5dfc7497 in _ZN12TApplication11ProcessLineEPKcbPi + 0xd35 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5e37e72f in _ZN5TRint13ProcessLineNrEPKcS1_Pi + 0x24f from /snap/root-framework/14/usr/local/lib/libRint.so
0x00007f3b5e37de51 in _ZN5TRint15HandleTermInputEv + 0x345 from /snap/root-framework/14/usr/local/lib/libRint.so
0x00007f3b5e37b73e in _ZN17TTermInputHandler6NotifyEv + 0x36 from /snap/root-framework/14/usr/local/lib/libRint.so
0x00007f3b5e37ffc1 in _ZN17TTermInputHandler10ReadNotifyEv + 0x29 from /snap/root-framework/14/usr/local/lib/libRint.so
0x00007f3b5e164a9d in _ZN11TUnixSystem16CheckDescriptorsEv + 0x121 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5e163cec in _ZN11TUnixSystem16DispatchOneEventEb + 0x17c from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5e0421d9 in _ZN7TSystem9InnerLoopEv + 0x45 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5e041f47 in _ZN7TSystem3RunEv + 0xf5 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5dfc8113 in _ZN12TApplication3RunEb + 0x55 from /snap/root-framework/14/usr/local/lib/libCore.so
0x00007f3b5e37d1d3 in _ZN5TRint3RunEb + 0x8dd from /snap/root-framework/14/usr/local/lib/libRint.so
0x000055726310c241 in from /snap/root-framework/14/usr/local/bin/root.exe
0x00007f3b5d91f0b3 in __libc_start_main + 0xf3 from /snap/root-framework/14/lib/x86_64-linux-gnu/libc.so.6
0x000055726310c10e in _start + 0x2e from /snap/root-framework/14/usr/local/bin/root.exe

I’ve just run your code now in the ROOT snap, and I get the same error as etejedor above

root [0] .x work.cxx
In file included from input_line_11:1:
In file included from /home/james/work.cxx:10:
/home/james/dataclass.h:19:44: error: use of undeclared identifier 'lettura'
    Dataset(string folder, string fname) { lettura(folder, fname); };
                                           ^
In file included from input_line_11:1:
/home/james/work.cxx:25:11: error: no member named 'lettura' in 'Dataset'
    diff->lettura("../Dati", "/1f_10p_sgnbkg.xls");

I’d still wager that there’s something about environment variables causing an issue. As an extreme measure, you could try creating a new user account on the system and trying to run ROOT there. Otherwise I’ll try patch the snap to be a bit more resiliant tomorrow, and perhaps someone else can chime in in the meantime with some other advice :slight_smile:

I accidentally deleted lettura() while copying the code. It should now be correct.

This is dataclass.h:

#pragma once
#define DATACLASS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

class Dataset
{
public:
    vector<double> asse_x;
    vector<double> asse_y;
    string description;

    Dataset();
    Dataset(string folder, string fname) { lettura(folder, fname); };
    ~Dataset();
    void set_description(string desc)
    {
        description = description + desc;
    };
    void lettura(string folder, string fname)
    {
        set_description(fname);
        ifstream fin(folder + fname);
        if (!fin)
        {
            cout << "Errore lettura file: " + folder + fname;
        }

        string temp_line;
        while (getline(fin, temp_line))
        {
            if (temp_line.rfind("#", 0) == 0 || temp_line.size() < 5)
            {
                continue;
            }
            else
            {
                istringstream iss(temp_line); //spezza la stringa in valori "22 33 44"-> 22 poi 33 poi 44
                vector<double> measures(2);
                iss >> measures[0] >> measures[1];
                asse_x.push_back(measures[0]); //se non metti le referenze qua fa il push_b siolamente nei vettori della funzione
                asse_y.push_back(measures[1]);
            }
        }
    };
    int find_maximum(vector<double> &vec)
    {
        return max_element(vec.begin(), vec.end()) - vec.begin();
    };
    void erase_and_take(int del_sx, int del_dx, int take, vector<double> &asse_y_temp, vector<double> &asse_x_temp)
    {

        int max_y1;
        int max_y2;
        int max_y;

        for (int i = 0; i < abs(del_sx); i++)
        {
            max_y1 = find_maximum(asse_y_temp);
            asse_y_temp.erase(asse_y_temp.begin() + (max_y1 - 1));
            asse_x_temp.erase(asse_x_temp.begin() + (max_y1 - 1));
        }

        for (int i = 0; i < abs(del_dx) - 1; i++) //occhio al meno 1
        {
            max_y2 = find_maximum(asse_y_temp);
            asse_y_temp.erase(asse_y_temp.begin() + (max_y2 + 1));
            asse_x_temp.erase(asse_x_temp.begin() + (max_y2 + 1));
        }

        max_y = find_maximum(asse_y_temp);
        asse_y_temp.erase(asse_y_temp.begin(), asse_y_temp.begin() + max_y - take);
        asse_x_temp.erase(asse_x_temp.begin(), asse_x_temp.begin() + max_y - take);

        max_y = find_maximum(asse_y_temp);
        asse_y_temp.erase(asse_y_temp.begin() + max_y + take + 1, asse_y_temp.begin() + asse_y_temp.size());
        asse_x_temp.erase(asse_x_temp.begin() + max_y + take + 1, asse_x_temp.begin() + asse_x_temp.size());

        asse_y_temp.erase(asse_y_temp.begin() + max_y);
        asse_x_temp.erase(asse_x_temp.begin() + max_y);
    };
};

And this is prova.cxx :

#include "TMath.h"
#include "TF1.h"
#include "TLegend.h"
#include "TCanvas.h"
#include <fstream>
#include <cmath>
#include "TFitResult.h"
#include "TMatrixD.h"
#include "../Programmi/dataclass.h"

using namespace std;

void prova()
{
    TCanvas *c1 = new TCanvas("c1", "Canvas", 200, 10, 1000, 700);

    c1->SetGrid();
    c1->SetFillColor(0);

    Dataset *diff;
    vector<double> asse_x_temp;
    vector<double> asse_y_temp;
    diff->erase_and_take(10, 10, 8, asse_y_temp,asse_x_temp);


    TVectorD root_asse_y_temp(asse_y_temp.size(), asse_y_temp.data());
    TVectorD root_asse_x_temp(asse_x_temp.size(), asse_x_temp.data());

    TGraph *grafico = new TGraph(root_asse_x_temp, root_asse_y_temp);
    grafico->Draw("AP");

}```
Thanks so much for the help!

As pointed out by @James-Carroll there must be something in the environment that is causing the issue.

When you tried the conda installation and obtained the same result, did you activate the conda environment after installation? Info here:

I wonder if it is still the other ROOT that is picked up. You can also check what version of ROOT you are running with root --version.

It worked with conda, thank you very much! :slight_smile:

Glad to see it’s working with Conda! And thanks for the feedback from the snap, I’ve pushed an update now that means it should clear out environment variables from other ROOT installations proactively so they don’t intefere with it, which would hopefully fix it for that format too. (On the offchance you try use it later, you can run sudo snap refresh to make sure it’s updated first).

Thanks again :)!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.