Skip to content

Commit

Permalink
[df] Implement rule of five in RDataSource and derived
Browse files Browse the repository at this point in the history
  • Loading branch information
vepadulano committed Dec 11, 2024
1 parent 77c3318 commit 98cb74d
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 16 deletions.
8 changes: 7 additions & 1 deletion tree/dataframe/inc/ROOT/RArrowDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ private:

public:
RArrowDS(std::shared_ptr<arrow::Table> table, std::vector<std::string> const &columns);
~RArrowDS();
// Rule of five
RArrowDS(const RArrowDS &) = delete;
RArrowDS &operator=(const RArrowDS &) = delete;
RArrowDS(RArrowDS &&) = delete;
RArrowDS &operator=(RArrowDS &&) = delete;
~RArrowDS() final;

const std::vector<std::string> &GetColumnNames() const final;
std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() final;
std::string GetTypeName(std::string_view colName) const final;
Expand Down
8 changes: 7 additions & 1 deletion tree/dataframe/inc/ROOT/RCsvDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ public:
RCsvDS(std::string_view fileName, const ROptions &options);
RCsvDS(std::string_view fileName, bool readHeaders = true, char delimiter = ',', Long64_t linesChunkSize = -1LL,
std::unordered_map<std::string, char> &&colTypes = {});
// Rule of five
RCsvDS(const RCsvDS &) = delete;
RCsvDS &operator=(const RCsvDS &) = delete;
RCsvDS(RCsvDS &&) = delete;
RCsvDS &operator=(RCsvDS &&) = delete;
~RCsvDS() final;

void Finalize() final;
~RCsvDS();
std::size_t GetNFiles() const final { return 1; }
const std::vector<std::string> &GetColumnNames() const final;
std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() final;
Expand Down
7 changes: 6 additions & 1 deletion tree/dataframe/inc/ROOT/RDF/RLazyDSImpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ public:
{
}

~RLazyDS()
// Rule of five
RLazyDS(const RLazyDS &) = delete;
RLazyDS &operator=(const RLazyDS &) = delete;
RLazyDS(RLazyDS &&) = delete;
RLazyDS &operator=(RLazyDS &&) = delete;
~RLazyDS() final
{
for (auto &&ptrHolderv : fPointerHolders) {
for (auto &&ptrHolder : ptrHolderv) {
Expand Down
6 changes: 6 additions & 0 deletions tree/dataframe/inc/ROOT/RDataSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ protected:
virtual std::string AsString() { return "generic data source"; };

public:
RDataSource() = default;
// Rule of five
RDataSource(const RDataSource &) = delete;
RDataSource &operator=(const RDataSource &) = delete;
RDataSource(RDataSource &&) = delete;
RDataSource &operator=(RDataSource &&) = delete;
virtual ~RDataSource() = default;

// clang-format off
Expand Down
7 changes: 6 additions & 1 deletion tree/dataframe/inc/ROOT/RNTupleDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ public:
RNTupleDS(std::string_view ntupleName, std::string_view fileName);
RNTupleDS(ROOT::RNTuple *ntuple);
RNTupleDS(std::string_view ntupleName, const std::vector<std::string> &fileNames);
~RNTupleDS();
// Rule of five
RNTupleDS(const RNTupleDS &) = delete;
RNTupleDS &operator=(const RNTupleDS &) = delete;
RNTupleDS(RNTupleDS &&) = delete;
RNTupleDS &operator=(RNTupleDS &&) = delete;
~RNTupleDS() final;

void SetNSlots(unsigned int nSlots) final;
std::size_t GetNFiles() const final { return fFileNames.empty() ? 1 : fFileNames.size(); }
Expand Down
8 changes: 7 additions & 1 deletion tree/dataframe/inc/ROOT/RRootDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ protected:

public:
RRootDS(std::string_view treeName, std::string_view fileNameGlob);
~RRootDS();
// Rule of five
RRootDS(const RRootDS &) = delete;
RRootDS &operator=(const RRootDS &) = delete;
RRootDS(RRootDS &&) = delete;
RRootDS &operator=(RRootDS &&) = delete;
~RRootDS() final;

std::size_t GetNFiles() const final;
std::string GetTypeName(std::string_view colName) const final;
const std::vector<std::string> &GetColumnNames() const final;
Expand Down
8 changes: 7 additions & 1 deletion tree/dataframe/inc/ROOT/RSqliteDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ private:

public:
RSqliteDS(const std::string &fileName, const std::string &query);
~RSqliteDS();
// Rule of five
RSqliteDS(const RSqliteDS &) = delete;
RSqliteDS &operator=(const RSqliteDS &) = delete;
RSqliteDS(RSqliteDS &&) = delete;
RSqliteDS &operator=(RSqliteDS &&) = delete;
~RSqliteDS() final;

void SetNSlots(unsigned int nSlots) final;
const std::vector<std::string> &GetColumnNames() const final;
bool HasColumn(std::string_view colName) const final;
Expand Down
8 changes: 7 additions & 1 deletion tree/dataframe/inc/ROOT/RTrivialDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public:
RTrivialDS(ULong64_t size, bool skipEvenEntries = false);
/// This ctor produces a data-source that returns infinite entries
RTrivialDS();
~RTrivialDS();
// Rule of five
RTrivialDS(const RTrivialDS &) = delete;
RTrivialDS &operator=(const RTrivialDS &) = delete;
RTrivialDS(RTrivialDS &&) = delete;
RTrivialDS &operator=(RTrivialDS &&) = delete;
~RTrivialDS() final = default;

const std::vector<std::string> &GetColumnNames() const final;
bool HasColumn(std::string_view colName) const final;
std::string GetTypeName(std::string_view) const final;
Expand Down
7 changes: 6 additions & 1 deletion tree/dataframe/inc/ROOT/RVecDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ public:
{
}

~RVecDS()
// Rule of five
RVecDS(const RVecDS &) = delete;
RVecDS &operator=(const RVecDS &) = delete;
RVecDS(RVecDS &&) = delete;
RVecDS &operator=(RVecDS &&) = delete;
~RVecDS() final
{
for (auto &&ptrHolderv : fPointerHolders) {
for (auto &&ptrHolder : ptrHolderv) {
Expand Down
4 changes: 0 additions & 4 deletions tree/dataframe/src/RTrivialDS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ RTrivialDS::RTrivialDS() : fSize(std::numeric_limits<ULong64_t>::max()), fSkipEv
{
}

RTrivialDS::~RTrivialDS()
{
}

const std::vector<std::string> &RTrivialDS::GetColumnNames() const
{
return fColNames;
Expand Down
10 changes: 9 additions & 1 deletion tree/dataframe/test/RArraysDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ public:
};

/// A RDataSource to test the `#var` feature
class RArraysDS : public ROOT::RDF::RDataSource {
class RArraysDS final : public ROOT::RDF::RDataSource {
std::vector<int> fVar = {42};
std::vector<std::string> fColumnNames = {"R_rdf_sizeof_var", "var"};
std::vector<std::pair<ULong64_t, ULong64_t>> fRanges = {{0ull, 1ull}};

bool IsSizeColumn(std::string_view colName) const { return colName.substr(0, 13) == "R_rdf_sizeof_"; }

public:
RArraysDS() = default;
// Rule of five
RArraysDS(const RArraysDS &) = delete;
RArraysDS &operator=(const RArraysDS &) = delete;
RArraysDS(RArraysDS &&) = delete;
RArraysDS &operator=(RArraysDS &&) = delete;
~RArraysDS() final = default;

void SetNSlots(unsigned int) final { }

const std::vector<std::string> &GetColumnNames() const final { return fColumnNames; }
Expand Down
11 changes: 9 additions & 2 deletions tree/dataframe/test/RNonCopiableColumnDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ private:
public:
using NonCopiable_t = RNonCopiable;
constexpr const static auto fgColumnName = "nonCopiable";
RNonCopiableColumnDS(){};
~RNonCopiableColumnDS() override {};

RNonCopiableColumnDS() = default;
// Rule of five
RNonCopiableColumnDS(const RNonCopiableColumnDS &) = delete;
RNonCopiableColumnDS &operator=(const RNonCopiableColumnDS &) = delete;
RNonCopiableColumnDS(RNonCopiableColumnDS &&) = delete;
RNonCopiableColumnDS &operator=(RNonCopiableColumnDS &&) = delete;
~RNonCopiableColumnDS() final = default;

const std::vector<std::string> &GetColumnNames() const final { return fColNames; };
bool HasColumn(std::string_view colName) const final { return colName == fColNames[0]; };
std::string GetTypeName(std::string_view) const final { return "RNonCopiable"; };
Expand Down
10 changes: 9 additions & 1 deletion tree/dataframe/test/RStreamingDS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@
#include <type_traits>

/// A RDataSource that provides multiple entry ranges
class RStreamingDS : public ROOT::RDF::RDataSource {
class RStreamingDS final : public ROOT::RDF::RDataSource {
unsigned int fNSlots = 0u;
unsigned int fCounter = 0u;
const int fAns = 42;
const int *fAnsPtr = &fAns;
const std::vector<std::string> fColumnNames = {"ans"};

public:
RStreamingDS() = default;
// Rule of five
RStreamingDS(const RStreamingDS &) = delete;
RStreamingDS &operator=(const RStreamingDS &) = delete;
RStreamingDS(RStreamingDS &&) = delete;
RStreamingDS &operator=(RStreamingDS &&) = delete;
~RStreamingDS() final = default;

void SetNSlots(unsigned int nSlots) final { fNSlots = nSlots; }
const std::vector<std::string> &GetColumnNames() const final { return fColumnNames; }
bool HasColumn(std::string_view name) const final { return std::string(name) == "ans" ? true : false; }
Expand Down

0 comments on commit 98cb74d

Please sign in to comment.