Fill RDataFrame how to

Dear experts,
I have a very basic question related to RDataFrame:
I would like to create branches and fill them in a loop within my c++ code.
Just like we used to do with TTrees.

  1. what do I need to import in order to create a RDataFrame object?
  2. How can I translate this code in an RDataFrame:
    Sign in to CERN

Many thanks,

  • Mauro.

_ROOT Version: 6.24
_Platform: CENT OS7
_Compiler: g++ (GCC) 10.2.1


If you can’t access the link the code is very simple:

    TFile theFile(fileName.c_str(), "RECREATE");
    TTree theTree("theTree", "Ntuple with event data");

    uint16_t FW_block_size, FW_tlu_trigger_id, FW_data_format_ver, FW_tdc;
    uint32_t event, FW_l1a_counter, FW_bx_counter, FW_event_status, FW_nframes;

    theTree.Branch("event", &event, "event/i");
    theTree.Branch("FW_block_size", &FW_block_size, "FW_block_size/i");
    theTree.Branch("FW_tlu_trigger_id", &FW_tlu_trigger_id, "FW_tlu_trigger_id/i");
...
    theTree.Fill();
    theTree.Write();
    theFile.Close();

At least:

    theTree.Branch("FW_block_size", &FW_block_size, "FW_block_size/s");
    theTree.Branch("FW_tlu_trigger_id", &FW_tlu_trigger_id, "FW_tlu_trigger_id/s");

I don’t fully understand the nuisance 32 vs 16 bits, but ok.

Hi,
I might be starting to understand… :slight_smile:
RDataFrame are just a way to manipulate a TTree

How can I easily make a TTree Branch containing a std::vector<std::vector<uint32_t>> ?
Basically, I would like to create a jagged array in a TTree

Many thanks,

  • Mauro.

Dear @mauroroot ,

RDataFrame is an interface for data analysis and it is not a data format like TTree. I suggest you read the thorough documentation and try out a couple of tutorials. There is one in particular which might give you insights on creation of jagged arrays.

As an extremely simple kickstarter, consider

import ROOT

# Need this here because the type std::vector<std::vector<std::uint32_t>>
# is not automatically generated by ROOT. In general this may not be needed
ROOT.gInterpreter.GenerateDictionary(
    "std::vector<std::vector<std::uint32_t>>","vector")

df = ROOT.RDataFrame(10)
snapdf = (
    df.Define("myvec",
              "std::vector<std::vector<std::uint32_t>>{{1,2,3}, {4,5,6}}")
      .Snapshot("mytree", "myfile.root")
)

Cheers,
Vincenzo

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