-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[DF] Cannot pass an lvalue to Fill, Book #8465
Copy link
Copy link
Closed
Labels
Description
This does not compile although it should:
#include <ROOT/RDataFrame.hxx>
class SimpleFiller {
TH1D fHisto;
public:
SimpleFiller() : fHisto("", "", 128, 0., 0.) {}
SimpleFiller(const SimpleFiller &) = default;
SimpleFiller(SimpleFiller &&) = default;
void Fill(double x) { fHisto.Fill(x); }
void Merge(const std::vector<SimpleFiller *> &others)
{
TList l;
for (auto *o : others)
l.Add(&o->GetHisto());
fHisto.Merge(&l);
}
TH1D &GetHisto() { return fHisto; }
};
class MaxSlotHelper : public ROOT::Detail::RDF::RActionImpl<MaxSlotHelper> {
const std::shared_ptr<unsigned int> fMaxSlot; // final result
std::vector<unsigned int> fMaxSlots; // per-thread partial results
public:
MaxSlotHelper(unsigned int nSlots)
: fMaxSlot(std::make_shared<unsigned int>(std::numeric_limits<unsigned int>::lowest())),
fMaxSlots(nSlots, std::numeric_limits<unsigned int>::lowest())
{
}
MaxSlotHelper(MaxSlotHelper &&) = default;
MaxSlotHelper(const MaxSlotHelper &) = delete;
using Result_t = unsigned int;
std::shared_ptr<unsigned int> GetResultPtr() const { return fMaxSlot; }
void Initialize() {}
void InitTask(TTreeReader *, unsigned int) {}
void Exec(unsigned int slot, unsigned int /*slot2*/) { fMaxSlots[slot] = std::max(fMaxSlots[slot], slot); }
void Finalize() { *fMaxSlot = *std::max_element(fMaxSlots.begin(), fMaxSlots.end()); }
std::string GetActionName() { return "MaxSlot"; }
};
int main() {
auto df = ROOT::RDataFrame(1).Define("x", [] { return 1; });
SimpleFiller sf;
auto filled = df.Fill(sf, {"x"});
MaxSlotHelper ms(1);
auto max = df.Book<int>(ms, {"x"});
}The problem is with the template type deduction using forwarding references, we probably need to pass the T through std::decay to remove ref/const qualifiers.
Reactions are currently unavailable