Retreiving an observable value using TRestAnalysisTree::GetObservableValue method

REST version : v2.2.12_dev
REST commit : 82122695

Hi,

how we should now retrieve the value from the analysis tree if we know explicitly the name?

I tried the following but it didn’t work

root [0] run0->GetEntry(0)
root [1] Double_t a;
root [2] run0->GetAnalysisTree()->GetObservableValue("rawAna_FullIntegral",  a);
In file included from input_line_130:1:
In file included from /programas/REST/v2.2.12_dev/macros/general/REST_Fit.C:6:
In file included from /programas/REST/v2.2.12_dev/include/TRestRun.h:10:
/programas/REST/v2.2.12_dev/include/TRestAnalysisTree.h:101:10: error: cannot cast from type 'void' to pointer type 'double *'
        *(T*)fObservableMemory[n].GetValue(obs);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/programas/REST/v2.2.12_dev/include/TRestAnalysisTree.h:106:9: note: in instantiation of function template specialization 'TRestAnalysisTree::GetObservableValue<double>' requested here
        GetObservableValue(id, obs);
        ^
ROOT_prompt_2:1:26: note: in instantiation of function template specialization 'TRestAnalysisTree::GetObservableValue<double>' requested here
run0->GetAnalysisTree()->GetObservableValue("rawAna_FullIntegral",  a);
1 Like

It seems the old GetObservableValue method was missing. I have re-implemented it in the last commit of v2.2.12_dev, then it works the following.

root [0] run0->GetEntry(0)
root [1] run0->GetAnalysisTree()->GetObservableValue("rawAna_FullIntegral")
(double) 7466.2769
root [2] 

Could we run into troubles if we try to get a map variable? What are the others (safer) ways to access this information? Can we check if the variable we are interested in is a map then return an error in that method?

Perhaps we may adopt the convention to end observable name using _map?

I spotted the bug in the old template method GetObservableValue(). Now I updated its logic: the returned value is directly the observable. We shall specify the data type when calling the method, therefore map observable is also supported:

If you input a wrong type, if it is a basic datatype(int, double, float, long, etc. ), there shall be no seg.falut. Just return a wrong value. For others, you may get a seg.fault.

In this case, I introduced a new method: GetObservableValueSafe. It will check the type matching before retrieving the data.

The old method call run0->GetAnalysisTree()->GetObservableValue("rawAna_FullIntegral") is updated to run0->GetAnalysisTree()->GetDblObservableValue("rawAna_FullIntegral")

I see, that’s perfect now.