Dear experts,
I am trying to understand why this code doesn’t compile properly. I am failing to understand why this is not working.
Basically i wrote a functor for Reading in a histogram given a input value and return a value , such that i can run MT the weight adding on my tuples using RDataFrame.
This is my class, basically given a input histogram i want to attach a weight in “interpolation” mode or bare mode.
All compiles without Interpolate call, When i try to compile this code i get:
error: no matching member function for call to 'Interpolate'
_val = m_histo.Interpolate( _var);
~~~~~~~~^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.18.04-c767d/x86_64-centos7-gcc8-opt/include/TH1.h:325:21: note: candidate function not viable: no known conversion from 'const TH1D' to 'TH1' for object argument
virtual Double_t Interpolate(Double_t x);
^
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.18.04-c767d/x86_64-centos7-gcc8-opt/include/TH1.h:326:21: note: candidate function not viable: requires 2 arguments, but 1 was provided
virtual Double_t Interpolate(Double_t x, Double_t y);
^
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.18.04-c767d/x86_64-centos7-gcc8-opt/include/TH1.h:327:21: note: candidate function not viable: requires 3 arguments, but 1 was provided
If i try to change the TH1D to TH1. Things improves but maybe my ROOT versions is not yet including the constification of methods?
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.18.04-c767d/x86_64-centos7-gcc8-opt/include/TH1.h:325:21: note: candidate function not viable: 'this' argument has type 'const TH1', but method is not marked const
virtual Double_t Interpolate(Double_t x);
Even if i see from the doxygen that Interpolate is marked const
Hi @eguiraud, is there any way out i can call Interpolate inside the operator() const method ?
I was thinking about making an extension of TH1D which re-implement Interpolate as const . Do you know a safe way to “extend” an existing root class, such as TH1D just adding a new method?
I tried something like
I think all the methods here will work fine, but i am not 100% sure about the fBuffer and BufferEmpty() calls how i can access those information since this is using a protected class member.
Unfortunately change ROOT version is not a solution for me.
Ok, i remove the const of the operator, nevertheless, i am not sure if doing this will prevent MT to work properly. I will ensure that when this is used i run single thread and i think i will be fine.
Thanks
Renato
Yes, if you call that method from multiple threads concurrently, you are in trouble.
I don’t know how TH1DHistoAdder is used in your application, but in RDataFrame typically we duplicate objects we work on, so that each thread has its own copy. That pattern would probably work for you too.
well, the approach i am following is to just make a
vector<TH1DHistoAdder>
housing all the histograms i need to read to attach a branch, then i call a Define in loop for that and finally a snapshot with all weights definitions.
I am moving to this approach to enable in my analysis workflow 2 properties :
do the weight-definitions on the fly and work on temporary tuples
So maybe for the persistency i am fine running single-threaded, for the working on the fly apporach i may will need to upgrade ROOT at some point i believe.
DefineSlot might be useful to make sure you don’t get concurrent calls to a method of the same non-thread-safe object, by providing a different instance of the object to each thread. That might be more memory-consuming but better-performing than just putting a lock to protect the thread-unsafe calls.
Thanks, i think for the moment i will just ensure i run with DisableImplicitMT() the functions adding the weights and persisting the tuples to disk. Once i am fine, i will probably just upgrade ROOT version.