Hi all, First of all, sorry for bothering.
I’m trying to hook a function into compiled objects:. I have a hook_class:
#ifndef libstat_hook_h
#define libstat_hook_h
//#include "TH1F.h"
using namespace std;
class libstat_hook{
public:
libstat_hook()
{
};
virtual ~libstat_hook()
{};
virtual bool include(double cdata=0,double csm=0,double sigma=0, /*const TH1F* const hData=0,*/ int range_low=0, int range_up=0)
{
//Write your function here
//Example:
return true;
//your function
}
};
I have two compiled libraries , compiled to .SO. Both have #include “libstat_hook.h”.
Now I’m trying to run a root program.
#include "../Libraries/libstat_hook.h"
/*
class select: public libstat_hook
{
public:
select()
{
};
virtual ~select()
{
};
bool include(double cdata,double csm,double sigma, int range_low, int range_up)
{
cout<<"overwrite"<<endl;
return cdata>=csm;
};
};
*/
void test_only_statistic(TString number="1", TString stream="All")
{
//TString stream="Muon";
TString variable = "_all_minv";
//TString variable ="_MET";
TString suffix="_"+number;
//gSystem->Load("../Libraries/binning2_C.so");
gSystem->Load("../Libraries/libstat_C.so");
gSystem->Load("../Libraries/only_statistic_C.so");
TString dir="/scratch/jvamen/Output/Toys_test/no_signal/minv";
TFile* Toy=new TFile("/scratch/jvamen/Output/Toys_test/no_signal/minv/Toys_"+stream+suffix+".root");
libstat_hook* a = new libstat_hook();
// libstat_hook a;
//cout<<a->include(9,10,10)<<endl; //This works
statistic t(2);
t.insert_hook(a); //this doesn't
t.setOutputFileName("Statistic_"+stream+suffix);
//t.setOutputDirectory(dir);
t.setOutputDirectory(".");
t.setStream(stream);
t.get_toy_file(Toy);
t.findDataTopologies(variable, "../topo/topolist_mc_"+stream+".txt");
t.Calculate_all_pvalues(variable+suffix);
//t.pvalue(topo,variable+suff ix);
exit();
}
The code then crashes in these lines:
void statistic::insert_hook(libstat_hook* input_hook)
{
cout<<input_hook<<endl;
if(input_hook->include(1,10,10)) cout<<"true"<<endl;
else cout<<"false"<<endl;
getchar();
stat->insert_hook(input_hook);
cout<<"Inserted hook"<<endl;
}
With these errors:
root [0]
Processing test_only_statistic.C...
0x1430c00
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f7b4870e5cc in __libc_waitpid (pid=44154, stat_loc=stat_loc
entry=0x7ffff5118b40, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00007f7b486931d2 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2 0x00007f7b493c1893 in TUnixSystem::StackTrace() () from /scratch/jvamen/root/lib/libCore.so
#3 0x00007f7b493c359c in TUnixSystem::DispatchSignals(ESignals) () from /scratch/jvamen/root/lib/libCore.so
#4 <signal handler called>
#5 0x00007f7b458ceb2c in statistic::insert_hook(libstat_hook*) () from /scratch/jvamen/GSstat/Run_scripts/./../Libraries/only_statistic_C.so
#6 0x00007f7b458cecc8 in G__only_statistic_C_ACLiC_dict_3427_0_14(G__value*, char const*, G__param*, int) () from /scratch/jvamen/GSstat/Run_scripts/./../Libraries/only_statistic_C.so
#7 0x00007f7b4769d94d in Cint::G__ExceptionWrapper(int (*)(G__value*, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /scratch/jvamen/root/lib/libCint.so
#8 0x00007f7b47741bc7 in G__execute_call () from /scratch/jvamen/root/lib/libCint.so
#9 0x00007f7b47741f85 in G__call_cppfunc () from /scratch/jvamen/root/lib/libCint.so
#10 0x00007f7b477214ff in G__interpret_func () from /scratch/jvamen/root/lib/libCint.so
#11 0x00007f7b4770ec89 in G__getfunction () from /scratch/jvamen/root/lib/libCint.so
#12 0x00007f7b477f7fd5 in G__getstructmem(int, G__FastAllocString&, char*, int, char*, int*, G__var_array*, int) () from /scratch/jvamen/root/lib/libCint.so
#13 0x00007f7b477eef9c in G__getvariable () from /scratch/jvamen/root/lib/libCint.so
#14 0x00007f7b476e8b0f in G__getitem () from /scratch/jvamen/root/lib/libCint.so
#15 0x00007f7b476ee4b5 in G__getexpr () from /scratch/jvamen/root/lib/libCint.so
#16 0x00007f7b4777148d in G__exec_statement () from /scratch/jvamen/root/lib/libCint.so
#17 0x00007f7b47722a5c in G__interpret_func () from /scratch/jvamen/root/lib/libCint.so
#18 0x00007f7b4770ece7 in G__getfunction () from /scratch/jvamen/root/lib/libCint.so
#19 0x00007f7b476e9012 in G__getitem () from /scratch/jvamen/root/lib/libCint.so
#20 0x00007f7b476ee4b5 in G__getexpr () from /scratch/jvamen/root/lib/libCint.so
#21 0x00007f7b476f9d8b in G__calc_internal () from /scratch/jvamen/root/lib/libCint.so
#22 0x00007f7b47780b9f in G__process_cmd () from /scratch/jvamen/root/lib/libCint.so
#23 0x00007f7b49389530 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /scratch/jvamen/root/lib/libCore.so
#24 0x00007f7b493824ab in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /scratch/jvamen/root/lib/libCore.so
#25 0x00007f7b492f080c in TApplication::ExecuteFile(char const*, int*, bool) () from /scratch/jvamen/root/lib/libCore.so
#26 0x00007f7b492efd40 in TApplication::ProcessLine(char const*, bool, int*) () from /scratch/jvamen/root/lib/libCore.so
#27 0x00007f7b48f401bd in TRint::Run(bool) () from /scratch/jvamen/root/lib/libRint.so
#28 0x0000000000400fdc in main ()
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug 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.
===========================================================
#5 0x00007f7b458ceb2c in statistic::insert_hook(libstat_hook*) () from /scratch/jvamen/GSstat/Run_scripts/./../Libraries/only_statistic_C.so
===========================================================
This is even without handing a custom hook routine, why does this crash? It is just an allocated object that should always return true anyway? I can’t figure it out.
Greetings,
JElmer
Edit: Found the error and fixxed