95 const std::map<RCsvDS::ColType_t, std::string>
101 for (
auto &col : columns) {
108 std::istringstream lineStream(line);
113 for (
auto &col : columns) {
118 record.emplace_back(
new double(std::stod(col)));
122 record.emplace_back(
new Long64_t(std::stoll(col)));
127 record.emplace_back(
b);
128 std::istringstream is(col);
129 is >> std::boolalpha >> *
b;
133 record.emplace_back(
new std::string(col));
143 for (
size_t i = 0; i < size; ++i) {
144 fHeaders.push_back(
"Col" + std::to_string(i));
150 const auto colType =
GetType(colName);
152 if ((colType ==
'd' &&
typeid(
double) != ti) || (colType ==
'l' &&
typeid(
Long64_t) != ti) ||
153 (colType ==
's' &&
typeid(std::string) != ti) || (colType ==
'b' &&
typeid(
bool) != ti)) {
154 std::string err =
"The type selected for column \"";
156 err +=
"\" does not correspond to column type, which is ";
158 throw std::runtime_error(err);
162 const auto index = std::distance(colNames.begin(), std::find(colNames.begin(), colNames.end(), colName));
163 std::vector<void *> ret(
fNSlots);
166 if (ti ==
typeid(
double)) {
168 }
else if (ti ==
typeid(
Long64_t)) {
170 }
else if (ti ==
typeid(std::string)) {
183 for (
auto &col : columns) {
211 std::vector<std::string> columns;
213 for (
size_t i = 0; i < line.size(); ++i) {
222 std::stringstream val;
225 for (; i < line.size(); ++i) {
228 }
else if (line[i] ==
'"') {
230 if (line[i + 1] !=
'"') {
240 columns.emplace_back(val.str());
260 if (std::getline(
fStream, line)) {
263 std::string msg =
"Error reading headers of CSV file ";
265 throw std::runtime_error(msg);
269 if (std::getline(
fStream, line)) {
289 for (
size_t i = 0; i < record.size(); ++i) {
294 delete static_cast<double *
>(p);
302 delete static_cast<bool *
>(p);
306 delete static_cast<std::string *
>(p);
347 std::vector<std::pair<ULong64_t, ULong64_t>> entryRanges;
348 const auto nRecords =
fRecords.size();
352 const auto chunkSize = nRecords /
fNSlots;
360 entryRanges.emplace_back(start, end);
363 entryRanges.back().second += remainder;
373 std::string msg =
"The dataset does not have column ";
375 throw std::runtime_error(msg);
395 const auto recordPos = entry - offset;
398 auto dataPtr =
fRecords[recordPos][colIndex];
424 assert(0U ==
fNSlots &&
"Setting the number of slots even if the number of slots is different from zero.");
428 const auto nColumns =
fHeaders.size();
441 ROOT::RDataFrame tdf(std::make_unique<RCsvDS>(fileName, readHeaders, delimiter, linesChunkSize));
std::vector< std::string > ParseColumns(const std::string &)
std::vector< std::string > fHeaders
size_t ParseValue(const std::string &, std::vector< std::string > &, size_t)
void FillRecord(const std::string &, Record_t &)
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.
static TRegexp doubleRegex1
void SetNSlots(unsigned int nSlots)
Inform RDataSource of the number of processing slots (i.e.
static TRegexp doubleRegex2
std::vector< std::vector< void * > > fColAddresses
Regular expression class.
std::vector< std::vector< double > > fDoubleEvtValues
void InferType(const std::string &, unsigned int)
ULong64_t fEntryRangesRequested
std::map< std::string, ColType_t > fColTypes
static TRegexp falseRegex
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.
std::string GetTypeName(std::string_view colName) const
Type of a column as a string, e.g.
RCsvDS(std::string_view fileName, bool readHeaders=true, char delimiter=',', Long64_t linesChunkSize=-1LL)
Constructor to create a CSV RDataSource for RDataFrame.
std::vector< std::vector< Long64_t > > fLong64EvtValues
void InferColTypes(std::vector< std::string > &)
const Long64_t fLinesChunkSize
std::vector< Record_t > fRecords
std::vector< std::pair< ULong64_t, ULong64_t > > GetEntryRanges()
Return ranges of entries to distribute to tasks.
ULong64_t fProcessedLines
void GenerateHeaders(size_t)
std::vector< std::vector< std::string > > fStringEvtValues
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV's and other data formats.
std::vector< void * > Record_t
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...
A pseudo container class which is a generator of indices.
unsigned long long ULong64_t
static RooMathCoreReg dummy
basic_string_view< char > string_view
const std::vector< std::string > & GetColumnNames() const
Returns a reference to the collection of the dataset's column names.
void FillHeaders(const std::string &)
typedef void((*Func_t)())
static const std::map< ColType_t, std::string > fgColTypeMap
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
std::vector< void * > GetColumnReadersImpl(std::string_view, const std::type_info &)
type-erased vector of pointers to pointers to column values - one per slot
std::vector< std::deque< bool > > fBoolEvtValues
std::list< ColType_t > fColTypesList
ColType_t GetType(std::string_view colName) const