# Using RVecB with Foreach in PyROOT

**URL:** <https://root-forum.cern.ch/t/using-rvecb-with-foreach-in-pyroot/57054>\
**Category:** Newbie\
**Created:** [November 9, 2023, 12:12pm UTC](https://root-forum.cern.ch/t/using-rvecb-with-foreach-in-pyroot/57054 "2023-11-09T12:12:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaan\_Guven](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kaan_guven/32/34986_2.png) [@Kaan\_Guven](https://root-forum.cern.ch/u/Kaan_Guven)\
**Post date:** [November 9, 2023, 12:12pm UTC](https://root-forum.cern.ch/t/using-rvecb-with-foreach-in-pyroot/57054/1 "2023-11-09T12:12:33Z")

</div>

EDIT: Unfortunately, I had previously copied and pasted an incorrect error message. Now, it is accurate.

Dear experts,

I cannot succeed in applying a function on each entry of an RDataframe in PyRoot.  
The columns that I am dealing with is of type `vector<ROOT::VecOps::RVec<bool>>`.  
I managed to have results with the columns of type: `vector<double>`, but for some reason that I don’t understand this doesn’t work. Can you help me?

**Code:**

```python
import ROOT
ROOT.gInterpreter.Declare('#include "RDF_helper.h"')

df = ROOT.RDataFrame("Events", "/users/alikaan.gueven/AOD_to_nanoAOD/data/dataFromFelix-NanoAODv9.root")

df = df.Define("cut_deltaPhi_MET_Lxy", "mask_deltaPhi_MET_Lxy(SDVSecVtx_L_phi, RawMET_phi)", cols=["SDVSecVtx_L_phi", "RawMET_phi"])

ROOT.gInterpreter.Declare("""
    void print_size(ROOT::VecOps::RVec<bool> arr){
        std::cout << arr.size() << std::endl;
    };
""")

print("")
print(type(df.Take["ROOT::RVecB"]("cut_deltaPhi_MET_Lxy")))
print("")

df.Foreach["std::function<void(ROOT::RVecB)>"](ROOT.print_size, ["cut_deltaPhi_MET_Lxy"])

```

**Output:**

```auto
(<my_env>) [<username>@<hostname> Plotter]$ python tmp_printer.py 
TClass::Init:0: RuntimeWarning: no dictionary for class edm::Hash<1> is available
TClass::Init:0: RuntimeWarning: no dictionary for class edm::ProcessHistory is available
TClass::Init:0: RuntimeWarning: no dictionary for class edm::ProcessConfiguration is available
TClass::Init:0: RuntimeWarning: no dictionary for class edm::ParameterSetBlob is available
TClass::Init:0: RuntimeWarning: no dictionary for class pair<edm::Hash<1>,edm::ParameterSetBlob> is available

<class cppyy.gbl.ROOT.RDF.RResultPtr<vector<ROOT::VecOps::RVec<bool> > > at 0x560988dc3140>

Traceback (most recent call last):
  File "<path_to_file>", line 19, in <module>
    df.Foreach["std::function<void(ROOT::RVecB)>"](ROOT.print_size, ["cut_deltaPhi_MET_Lxy"])
NotImplementedError: Could not instantiate Foreach<std::function<void(ROOT::RVecB)>>:
  void ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void>::Foreach(function<void(RVec<bool> > f, const vector<string>& columns = {}) =>
    NotImplementedError: could not convert argument 1 (this method cannot (yet) be called)

```

* * *

_ROOT Version:_ 6.28/00  
_Platform:_ Version 7 CentOS  
_Compiler:_ C++17

* * *

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [November 17, 2023, 9:56am UTC](https://root-forum.cern.ch/t/using-rvecb-with-foreach-in-pyroot/57054/2 "2023-11-17T09:56:25Z")

</div>

Hello,  
Apologies for the late reply, @vpadulan should be able to help you here
