Skip to content

Commit 638565a

Browse files
committed
[TDF] Add TDataSource abstract class
1 parent 353af50 commit 638565a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Author: Enrico Guiraud, Danilo Piparo CERN 09/2017
2+
3+
/*************************************************************************
4+
* Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
5+
* All rights reserved. *
6+
* *
7+
* For the licensing terms see $ROOTSYS/LICENSE. *
8+
* For the list of contributors see $ROOTSYS/README/CREDITS. *
9+
*************************************************************************/
10+
11+
#ifndef ROOT_TDATASOURCE
12+
#define ROOT_TDATASOURCE
13+
14+
#include "RStringView.h"
15+
#include "RtypesCore.h" // ULong64_t
16+
#include <algorithm> // std::transform
17+
#include <vector>
18+
#include <typeinfo>
19+
20+
namespace ROOT {
21+
namespace Experimental {
22+
namespace TDF {
23+
24+
class TDataSource {
25+
public:
26+
virtual ~TDataSource(){};
27+
virtual const std::vector<std::string> &GetColumnNames() const = 0;
28+
virtual bool HasColumn(std::string_view) const = 0;
29+
/// Type of a column as a string, e.g. `GetTypeName("x") == "double"`. Required for jitting e.g. `df.Filter("x>0")`.
30+
virtual std::string GetTypeName(std::string_view) const = 0;
31+
/// Called at most once per column by TDF. Return vector of pointers to pointers to column values - one per slot.
32+
template <typename T>
33+
std::vector<T **> GetColumnReaders(std::string_view name, unsigned int nSlots)
34+
{
35+
auto typeErasedVec = GetColumnReadersImpl(name, nSlots, typeid(T));
36+
std::vector<T **> typedVec(typeErasedVec.size());
37+
std::transform(typeErasedVec.begin(), typeErasedVec.end(), typedVec.begin(),
38+
[](void *p) { return static_cast<T **>(p); });
39+
return typedVec;
40+
}
41+
/// Return chunks of entries to distribute to tasks. They are required to be continguous intervals with no entries
42+
/// skipped, starting at 0 and ending at nEntries, e.g. [0-5],[5-10] for 10 entries.
43+
virtual const std::vector<std::pair<ULong64_t, ULong64_t>> &GetEntryRanges() const = 0;
44+
/// Different threads will loop over different ranges and will pass different "slot" values.
45+
virtual void SetEntry(ULong64_t entry, unsigned int slot) = 0;
46+
/// Convenience method called at the start of each task, before processing a range of entries.
47+
/// DataSources can implement it if needed (does nothing by default).
48+
/// firstEntry is the first entry of the range that the task will process.
49+
virtual void InitSlot(unsigned int slot, ULong64_t firstEntry) {}
50+
51+
protected:
52+
/// type-erased vector of pointers to pointers to column values - one per slot
53+
virtual std::vector<void *>
54+
GetColumnReadersImpl(std::string_view name, unsigned int nSlots, const std::type_info &) = 0;
55+
};
56+
57+
} // ns TDF
58+
} // ns Experimental
59+
} // ns ROOT
60+
61+
#endif // ROOT_TDATASOURCE

0 commit comments

Comments
 (0)