91 return "CSV data source";
101const std::map<RCsvDS::ColType_t, std::string>
102 RCsvDS::fgColTypeMap({{
'b',
"bool"}, {
'd',
"double"}, {
'l',
"Long64_t"}, {
's',
"std::string"}});
107 for (
auto &col : columns) {
114 std::istringstream lineStream(
line);
119 for (
auto &col : columns) {
124 record.emplace_back(
new double(
std::stod(col)));
128 record.emplace_back(
new Long64_t(std::stoll(col)));
133 record.emplace_back(
b);
134 std::istringstream is(col);
135 is >> std::boolalpha >> *
b;
139 record.emplace_back(
new std::string(col));
149 for (
size_t i = 0; i < size; ++i) {
150 fHeaders.push_back(
"Col" + std::to_string(i));
156 const auto colType =
GetType(colName);
158 if ((colType ==
'd' &&
typeid(
double) != ti) || (colType ==
'l' &&
typeid(
Long64_t) != ti) ||
159 (colType ==
's' &&
typeid(std::string) != ti) || (colType ==
'b' &&
typeid(
bool) != ti)) {
160 std::string err =
"The type selected for column \"";
162 err +=
"\" does not correspond to column type, which is ";
164 throw std::runtime_error(err);
168 const auto index = std::distance(colNames.begin(), std::find(colNames.begin(), colNames.end(), colName));
169 std::vector<void *> ret(
fNSlots);
172 if (ti ==
typeid(
double)) {
174 }
else if (ti ==
typeid(
Long64_t)) {
176 }
else if (ti ==
typeid(std::string)) {
189 for (
auto &col : columns) {
217 std::vector<std::string> columns;
219 for (
size_t i = 0; i <
line.size(); ++i) {
228 std::stringstream val;
231 for (; i <
line.size(); ++i) {
234 }
else if (
line[i] ==
'"') {
236 if (
line[i + 1] !=
'"') {
246 columns.emplace_back(val.str());
258 : fReadHeaders(readHeaders),
259 fStream(
std::string(fileName)),
260 fDelimiter(delimiter),
261 fLinesChunkSize(linesChunkSize)
270 std::string msg =
"Error reading headers of CSV file ";
272 throw std::runtime_error(msg);
296 for (
size_t i = 0; i < record.size(); ++i) {
301 delete static_cast<double *
>(p);
309 delete static_cast<bool *
>(p);
313 delete static_cast<std::string *
>(p);
356 std::vector<std::pair<ULong64_t, ULong64_t>> entryRanges;
357 const auto nRecords =
fRecords.size();
361 const auto chunkSize = nRecords /
fNSlots;
369 entryRanges.emplace_back(start, end);
372 entryRanges.back().second += remainder;
383 std::string msg =
"The dataset does not have column ";
385 throw std::runtime_error(msg);
405 const auto recordPos = entry - offset;
408 auto dataPtr =
fRecords[recordPos][colIndex];
434 R__ASSERT(0U ==
fNSlots &&
"Setting the number of slots even if the number of slots is different from zero.");
438 const auto nColumns =
fHeaders.size();
456 ROOT::RDataFrame tdf(std::make_unique<RCsvDS>(fileName, readHeaders, delimiter, linesChunkSize));
static RooMathCoreReg dummy
unsigned long long ULong64_t
typedef void((*Func_t)())
RCsvDS(std::string_view fileName, bool readHeaders=true, char delimiter=',', Long64_t linesChunkSize=-1LL)
Constructor to create a CSV RDataSource for RDataFrame.
std::map< std::string, ColType_t > fColTypes
static TRegexp falseRegex
void FillRecord(const std::string &, Record_t &)
ColType_t GetType(std::string_view colName) const
std::vector< std::vector< double > > fDoubleEvtValues
void InferType(const std::string &, unsigned int)
size_t ParseValue(const std::string &, std::vector< std::string > &, size_t)
void GenerateHeaders(size_t)
std::vector< std::vector< void * > > fColAddresses
std::string GetLabel()
Return a string representation of the datasource type.
const Long64_t fLinesChunkSize
std::vector< std::string > fHeaders
static TRegexp doubleRegex2
ULong64_t fEntryRangesRequested
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
ULong64_t fProcessedLines
std::vector< void * > GetColumnReadersImpl(std::string_view, const std::type_info &)
type-erased vector of pointers to pointers to column values - one per slot
void InferColTypes(std::vector< std::string > &)
std::vector< std::vector< Long64_t > > fLong64EvtValues
static const std::map< ColType_t, std::string > fgColTypeMap
std::vector< Record_t > fRecords
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
bool SetEntry(unsigned int slot, ULong64_t entry)
Advance the "cursors" returned by GetColumnReaders to the selected entry for a particular slot.
bool HasColumn(std::string_view colName) const
Checks if the dataset has a certain column.
static TRegexp doubleRegex1
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
std::string GetTypeName(std::string_view colName) const
Type of a column as a string, e.g.
std::vector< std::string > ParseColumns(const std::string &)
void FillHeaders(const std::string &)
void Finalise()
Convenience method called after concluding an event-loop.
std::vector< std::vector< std::string > > fStringEvtValues
std::vector< std::deque< bool > > fBoolEvtValues
std::list< ColType_t > fColTypesList
std::vector< void * > Record_t
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
A pseudo container class which is a generator of indices.
Regular expression class.
Ssiz_t Index(const TString &str, Ssiz_t *len, Ssiz_t start=0) const
Find the first occurrence of the regexp in string and return the position, or -1 if there is no match...
RDataFrame MakeCsvDataFrame(std::string_view fileName, bool readHeaders=true, char delimiter=',', Long64_t linesChunkSize=-1LL)
Factory method to create a CSV RDataFrame.
Namespace for new ROOT classes and functions.
double stod(std::string_view str, size_t *pos)
basic_string_view< char > string_view