# RDataFrame Snapshot converting all std::vector to RVec

**URL:** <https://root-forum.cern.ch/t/rdataframe-snapshot-converting-all-std-vector-to-rvec/50771>\
**Category:** ROOT\
**Tags:** rdataframe\
**Created:** [July 12, 2022, 2:52pm UTC](https://root-forum.cern.ch/t/rdataframe-snapshot-converting-all-std-vector-to-rvec/50771 "2022-07-12T14:52:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean\_Beaucamp](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jean_beaucamp/32/28180_2.png) [@Jean\_Beaucamp](https://root-forum.cern.ch/u/Jean_Beaucamp)\
**Post date:** [July 12, 2022, 2:52pm UTC](https://root-forum.cern.ch/t/rdataframe-snapshot-converting-all-std-vector-to-rvec/50771/1 "2022-07-12T14:52:22Z")

</div>

Dear ROOT experts,

Ever since updating ROOT to the newest v6.26, when I try to create a Snapshot of a processed RDataFrame, all columns are converted from std::vector\<float/double/int/char\> to RVec\<float/double/int/char\>. I found in [another topic](https://root-forum.cern.ch/t/snapshot-of-rvec-rvec-t-produces-broken-root-file/) that this is the expected behavior in the new ROOT versions.

While this is no doubt good when working with only RDataFrame, it breaks compatibility with other software expecting std::vectors in the TTree. In our case, running the HistFitter statistical framework ([https://github.com/histfitter/histfitter](https://github.com/histfitter/histfitter)) with the validated ROOT version v6.22, results in a ton of “Error in TExMap::Add: key 1 is not unique” error messages and an incorrect output.

Is there a way to prevent the vector → RVec conversion when storing the Snapshot? I tried manually redefining the columns back to RVec with

```auto
    auto df_upd = df.Redefine("colName", [](const RVecI &v) -> std::vector<Int_t> { 
        return std::vector<Int_t>(v.data(), v.data() + v.size());
    }, {"colName"});

```

but it doesn’t work; the stored branches still have the incorrect type.

Cheers,

Jean Yves

ROOT Version: 6.26  
Platform: lxplus CentOS 7

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 12, 2022, 3:58pm UTC](https://root-forum.cern.ch/t/rdataframe-snapshot-converting-all-std-vector-to-rvec/50771/2 "2022-07-12T15:58:58Z")

</div>

Hi @Jean_Beaucamp ,

sorry for the trouble! Although in v6.26 RVecs are written as RVecs, they are written in such a way (using collection proxies) that you can actually read them back as std::vectors – but given your report I guess that mechanism is broken if you write them with v6.26 and read them back with v6.22, which is indeed not a configuration we test.

One way to force `Snapshot` to write `std::vector`s in this case is to manually specifying types and names for all branches that are written out (which I realize is clunky – it’s a workaround, not a fix).  
So, for example, `Snapshot<double, double, std::vector<float>>("t", "f.root", {"x", "y", "vec"});`.

However, your workaround should also work! The following code will save column `x` as a `vector<int>` with the `Redefine` and as a `RVecI` without:

```cpp
#include <ROOT/RDataFrame.hxx>

int main() {
  ROOT::RDataFrame(10)
      .Define("x",
              [] {
                return ROOT::RVecI{1, 2, 3};
              })
      .Redefine("x",
                [](const ROOT::RVecI &v) {
                  return std::vector<int>(v.begin(), v.end());
                },
                {"x"})
      .Snapshot("t", "f.root");
}

```

Is this the case for you too? What am I doing differently?

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 26, 2022, 3:59pm UTC](https://root-forum.cern.ch/t/rdataframe-snapshot-converting-all-std-vector-to-rvec/50771/3 "2022-07-26T15:59:22Z")

</div>

Closed on July 26, 2022, 3:59pm UTC

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