Hi,
I am using c++14, so I can do as you suggest. However, I get a segmentation violation when I do:
using namespace ROOT::Experimental;
auto BuildSensorBandDateDF(TDataFrame& d, const std::vector<std::string>& features) {
using cbutils::string::split;
using TokenType = std::vector<std::string>;
return d.DefineSlotEntry("tokens",
[&features](unsigned int slot, ULong64_t entry) {
return split(features[entry], "_");
})
.Define("sensor", [](TokenType &t) { return t[0].c_str(); }, {"tokens"})
.Define("band", [](TokenType &t) { return t[1].c_str(); }, {"tokens"})
.Define("date", [](TokenType &t) { return atoi(t[2].c_str()); }, {"tokens"});
}
int main()
{
auto fileName = "../data/input_samples.csv";
auto tdf = ROOT::Experimental::TDF::MakeCsvDataFrame(fileName);
//How many "events" (i.e. samples) have code 211?
auto filteredEvents =
tdf.Filter("code == 211").Count();
auto columnNames = tdf.GetColumnNames();
// build a DF from the features available in the input file
TDataFrame empty_d(columnNames.size());
auto colDF = BuildSensorBandDateDF(empty_d, columnNames);
// How many features correspond to ndvi?
auto isNDVI = [](const char* band) { return std::strcmp(band,"ndvi")==0; };
// Limit to landsat8
auto isLandsat8 = [](const char* sensor){return std::strcmp(sensor,"landsat8")==0; };
auto ndviLandsat8Features = colDF.Filter(isNDVI,{"band"}).Filter(isLandsat8,{"sensor"});
std::cout << *(ndviLandsat8Features.Count()) << '\n';
return 0;
}
Executing this code, works sometimes, but sometimes I get:
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f1178db1fba in __GI___waitpid (pid=17923, stat_loc=stat_loc
entry=0x7ffcf6c15f20, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1 0x00007f1178d3907b in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2 0x00007f117d2ddec2 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x55bd43a26570) at /home/garjola/src/root/core/unix/src/TUnixSystem.cxx:2118
#3 TUnixSystem::StackTrace (this=0x55bd43a26570) at /home/garjola/src/root/core/unix/src/TUnixSystem.cxx:2412
#4 0x00007f117d2e034c in TUnixSystem::DispatchSignals (this=0x55bd43a26570, sig=kSigSegmentationViolation) at /home/garjola/src/root/core/unix/src/TUnixSystem.cxx:3643
#5 <signal handler called>
#6 __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
#7 0x000055bd428e4827 in <lambda(char const*)>::operator()(const char *) const (__closure=0x55bd489e768c, band=0x7265745f6c6c6163 <error: Cannot access memory at address 0x7265745f6c6c6163>) at /home/garjola/Dev/RootLearning/sql/csv-dataframe.cxx:42
#8 0x000055bd428ee5a3 in ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager>::CheckFilterHelper<0>(unsigned int, Long64_t, ROOT::Internal::TDF::StaticSeq<0>) (this=0x55bd489e75f0, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:647
#9 0x000055bd428eddb8 in ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager>::CheckFilters(unsigned int, Long64_t) (this=0x55bd489e75f0, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:635
#10 0x000055bd428ed926 in ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager> >::CheckFilters(unsigned int, Long64_t) (this=0x55bd475fe7c0, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:630
#11 0x000055bd428ed6e5 in ROOT::Internal::TDF::TAction<ROOT::Internal::TDF::CountHelper, ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager> >, ROOT::TypeTraits::TypeList<> >::Run(unsigned int, Long64_t) (this=0x55bd48cac270, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:402
#12 0x00007f117b10cfba in ROOT::Detail::TDF::TLoopManager::RunAndCheckFilters (this=this
entry=0x55bd48ce4330, slot=slot
entry=0, entry=entry
entry=2) at /home/garjola/src/root/tree/treeplayer/src/TDFNodes.cxx:282
#13 0x00007f117b10d1db in ROOT::Detail::TDF::TLoopManager::RunEmptySource (this=0x55bd48ce4330) at /home/garjola/src/root/tree/treeplayer/src/TDFNodes.cxx:182
#14 0x00007f117b110025 in ROOT::Detail::TDF::TLoopManager::Run (this=0x55bd48ce4330) at /home/garjola/src/root/tree/treeplayer/src/TDFNodes.cxx:379
#15 0x000055bd428f42bd in ROOT::Experimental::TDF::TResultProxy<unsigned long long>::TriggerRun (this=0x7ffcf6c18bb0) at /home/garjola/src/root-build/include/ROOT/TResultProxy.hxx:283
#16 0x000055bd428f279e in ROOT::Experimental::TDF::TResultProxy<unsigned long long>::Get (this=0x7ffcf6c18bb0) at /home/garjola/src/root-build/include/ROOT/TResultProxy.hxx:123
#17 0x000055bd428f0d62 in ROOT::Experimental::TDF::TResultProxy<unsigned long long>::operator* (this=0x7ffcf6c18bb0) at /home/garjola/src/root-build/include/ROOT/TResultProxy.hxx:150
#18 0x000055bd428e4c5d in main () at /home/garjola/Dev/RootLearning/sql/csv-dataframe.cxx:46
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
#7 0x000055bd428e4827 in <lambda(char const*)>::operator()(const char *) const (__closure=0x55bd489e768c, band=0x7265745f6c6c6163 <error: Cannot access memory at address 0x7265745f6c6c6163>) at /home/garjola/Dev/RootLearning/sql/csv-dataframe.cxx:42
#8 0x000055bd428ee5a3 in ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager>::CheckFilterHelper<0>(unsigned int, Long64_t, ROOT::Internal::TDF::StaticSeq<0>) (this=0x55bd489e75f0, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:647
#9 0x000055bd428eddb8 in ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager>::CheckFilters(unsigned int, Long64_t) (this=0x55bd489e75f0, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:635
#10 0x000055bd428ed926 in ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager> >::CheckFilters(unsigned int, Long64_t) (this=0x55bd475fe7c0, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:630
#11 0x000055bd428ed6e5 in ROOT::Internal::TDF::TAction<ROOT::Internal::TDF::CountHelper, ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TFilter<main()::<lambda(char const*)>, ROOT::Detail::TDF::TLoopManager> >, ROOT::TypeTraits::TypeList<> >::Run(unsigned int, Long64_t) (this=0x55bd48cac270, slot=0, entry=2) at /home/garjola/src/root-build/include/ROOT/TDFNodes.hxx:402
#12 0x00007f117b10cfba in ROOT::Detail::TDF::TLoopManager::RunAndCheckFilters (this=this
entry=0x55bd48ce4330, slot=slot
entry=0, entry=entry
entry=2) at /home/garjola/src/root/tree/treeplayer/src/TDFNodes.cxx:282
#13 0x00007f117b10d1db in ROOT::Detail::TDF::TLoopManager::RunEmptySource (this=0x55bd48ce4330) at /home/garjola/src/root/tree/treeplayer/src/TDFNodes.cxx:182
#14 0x00007f117b110025 in ROOT::Detail::TDF::TLoopManager::Run (this=0x55bd48ce4330) at /home/garjola/src/root/tree/treeplayer/src/TDFNodes.cxx:379
#15 0x000055bd428f42bd in ROOT::Experimental::TDF::TResultProxy<unsigned long long>::TriggerRun (this=0x7ffcf6c18bb0) at /home/garjola/src/root-build/include/ROOT/TResultProxy.hxx:283
#16 0x000055bd428f279e in ROOT::Experimental::TDF::TResultProxy<unsigned long long>::Get (this=0x7ffcf6c18bb0) at /home/garjola/src/root-build/include/ROOT/TResultProxy.hxx:123
#17 0x000055bd428f0d62 in ROOT::Experimental::TDF::TResultProxy<unsigned long long>::operator* (this=0x7ffcf6c18bb0) at /home/garjola/src/root-build/include/ROOT/TResultProxy.hxx:150
#18 0x000055bd428e4c5d in main () at /home/garjola/Dev/RootLearning/sql/csv-dataframe.cxx:46
===========================================================
The test file is here input_samples.csv.gz (111.0 KB)
Any idea on what is wrong?
Thanks.
Garjola