Unable To Access Elements Using Take Action


Please read tips for efficient and successful posting and posting code

_ROOT Version:6.22.06
Platform: Not Provided
Compiler: Not Provided


Hi,

I’m trying to create a RooDataSet and part of this means making columns into std::vectors so I can fill the dataset. I don’t use ImplicitMT. My code is as follows


auto id_frame = frame.Filter("(Dst_ReFit_D0_M_best > 1810.0) && (Dst_ReFit_D0_M_best < 1920.0)").Define("unique_id","rdfentry_");

auto var1 = id_frame.Take<double>("deltam_ReFit");
auto var2 = id_frame.Take<double>("Dst_ReFit_D0_M_best");
auto var3 = id_frame.Take<int>("unique_id");
RooRealVar deltaM("deltam_ReFit","deltaM",139.5,160.5);
RooRealVar D0_M("Dst_ReFit_D0_M_best","D0_M",1810,1920);
RooRealVar candidate_index("unique_id","unique_id",0,(int)1e30);
RooDataSet * _data = new RooDataSet("data", "data", RooArgSet(deltaM, D0_M, candidate_index));

for(int i =0; i < var1->size(); ++i){
    deltaM.setVal( var1->At(i)); 
    D0_M.setVal( var2->At(i)); 
    candidate_index.setVal( var3->At(i)); 
   _data->add( RooArgSet( deltaM,D0_M,candidate_index));
}

This fails when accessing var1/2/3 with the following errors

input_line_90:2:24: error: member reference type 'ROOT::RDF::RResultPtr<std::vector<double, std::allocator<double> > >' is not a pointer;
      did you mean to use '.'?
 for(int i =0; i < var1->size(); ++i){
                   ~~~~^~
          .
input_line_90:2:26: error: no member named 'size' in 'ROOT::RDF::RResultPtr<std::vector<double, std::allocator<double> > >'
 for(int i =0; i < var1->size(); ++i){
                   ~~~~  ^
input_line_90:3:24: error: member reference type 'ROOT::RDF::RResultPtr<std::vector<double, std::allocator<double> > >' is not a pointer;
      did you mean to use '.'?
    deltaM.setVal( var1->At(i)); 
                   ~~~~^~
                       .
input_line_90:3:26: error: no member named 'At' in 'ROOT::RDF::RResultPtr<std::vector<double, std::allocator<double> > >'
    deltaM.setVal( var1->At(i)); 
                   ~~~~  ^

I have omitted the errors for var2 and var3 since they are the same.
Why is this happening? I am able to filter and make histograms of the relevant columns

Thanks in advance

Hi @jcob,
At should be at, but other than that I don’t see an issue with your code (and RResultPtrs certainly have a -> operator!). I tried to reproduce the problem and failed: can you run the following macro successfully?

void repro() {
   {
   // create a TTree with a double branch, write it to file
   ROOT::RDataFrame(10).Define("d", [] { return 42.; }).Snapshot<double>("t", "f.root", {"d"});
   }

   // try to reproduce issue
   ROOT::RDataFrame frame("t", "f.root");
   auto var1 = frame.Take<double>("d");

   for(int i = 0; i < var1->size(); ++i) {
       var1->at(i);
   }
}

If yes, can you please try to “bisect” and figure out what exactly makes the error appear? Could it be that there are previous compilation errors printed that ultimately cause these weird ones?

Cheers,
Enrico

Hi @eguiraud,

I was able run your reproducible example fine. I managed to fix these errors. It seems there are issues with what data type is used with Take. The line which seems to be the root of the problem is

auto var3 = id_frame.Take<int>("unique_id");

I changed this to

auto var3 = id_frame.Take<ULong64_t>("unique_id");

and the code runs with no problems (in RooFit as well). This arose because the unique ID is just rdfentry_. Does Take not automatically cast the data to whatever type specified if it can?

Thanks.

Alright,
so I guess the problem was indeed that there were other compilation errors before those you report in the first post, right?

It cannot: the template parameter is a compile-time information but the on-disk type of the column will only be known at runtime, when the code is already compiled and the input file is opened. Throughout RDF, column types used as template parameters need to match the real column types exactly – but we do try to produce clear error messages in case of mismatches, that’s why I’m asking whether you saw such error messages or not.

Cheers,
Enrico

I was using a Jupyter notebook and this seems to suppress this output. Interestingly doing

auto var1 = (id_frame.Take<double>("deltam_ReFit")).GetPtr()

for example, does show a type mismatch.

Error in <TTreeReaderValueBase::CreateProxy()>: The branch deltam_ReFit contains data of type float. It cannot be accessed by a TTreeReaderValue<double>

This kind of error seems kind of trivial to me, casting a float to a double but as you explained this is isn’t possible.

Thanks for your help!

1 Like

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