ROOT::RDF::FromCSV

0x00007FFD08414F08 处(位于 CSV.exe 中)有未经处理的异常: Microsoft C++ 异常: std::bad_alloc,位于内存位置 0x000000BCC075F170 处。
Unhandled exception at 0x00007FFD08414F08 (located in CSV.exe) : Microsoft C++ exception: std::bad_alloc, located at memory location 0x000000BCC075F170.

auto fileNameUrl = "http://root.cern.ch/files/tutorials/df014_CsvDataSource_MuRun2010B.csv";
    auto fileName = "df014_CsvDataSource_MuRun2010B_cpp.csv";
    if (gSystem->AccessPathName(fileName))
        TFile::Cp(fileNameUrl, fileName);
      ROOT::RDataFrame df = ROOT::RDF::FromCSV(fileName);

Dear @songshusen ,

Thank you for reaching out. I tried your code snippet with no failure on my machine:

root [0] auto fileNameUrl = "http://root.cern.ch/files/tutorials/df014_CsvDataSource_MuRun2010B.csv";
root [1] auto fileName = "df014_CsvDataSource_MuRun2010B_cpp.csv";
root [2] if (gSystem->AccessPathName(fileName)) TFile::Cp(fileNameUrl, fileName);
[TFile::Cp] Total 14.46 MB	|====================| 100.00 % [94.0 MB/s]
root [3] ROOT::RDataFrame df = ROOT::RDF::FromCSV(fileName);
root [4] df.Display()->Print()
Info in <Print>: Only showing 10 columns out of 22

+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| Row | E1        | E2        | Event    | M         | Q1 | Q2 | Run    | Type1 | Type2 | ... | 
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 0   | 19.171200 | 5.4398400 | 90830792 | 2.7320500 | 1  | 1  | 146436 | "G"   | "T"   | ... | 
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 1   | 12.943500 | 11.863600 | 90862225 | 3.1025600 | -1 | 1  | 146436 | "G"   | "G"   | ... | 
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 2   | 12.399900 | 8.5553200 | 90644850 | 9.4114900 | 1  | -1 | 146436 | "G"   | "G"   | ... | 
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 3   | 17.813200 | 9.4217400 | 90678594 | 7.7470200 | 1  | 1  | 146436 | "G"   | "G"   | ... | 
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 4   | 7.9566400 | 5.4446700 | 90686690 | 8.6772700 | 1  | -1 | 146436 | "G"   | "T"   | ... | 
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+

Could you be more specific about the error? Aren’t there any other steps to reproduce it?
For instance, I see

Unhandled exception at 0x00007FFD08414F08 (located in CSV.exe)

I am not sure whether this is something wrong with ROOT or with how windows handles CSV. Maybe @bellenot could try out the lines of code I pasted in this post and see if they work on windows?

Cheers,
Vincenzo

Same here:

C:\Users\bellenot\rootdev>root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.29/01                        https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win32 on May 24 2023, 15:16:48                         |
  | From heads/master@v6-29-01-1417-ge6080327f4                      |
  | With MSVC 19.29.30146.0                                          |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] auto fileNameUrl = "http://root.cern.ch/files/tutorials/df014_CsvDataSource_MuRun2010B.csv";
root [1] auto fileName = "df014_CsvDataSource_MuRun2010B_cpp.csv";
root [2] if (gSystem->AccessPathName(fileName)) TFile::Cp(fileNameUrl, fileName);
[TFile::Cp] Total 14.46 MB      |====================| 100.00 % [79.5 MB/s]
root [3] ROOT::RDataFrame df = ROOT::RDF::FromCSV(fileName);
root [4] df.Display()->Print()
Info in <Print>: Only showing 10 columns out of 22

+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| Row | E1        | E2        | Event    | M         | Q1 | Q2 | Run    | Type1 | Type2 | ... |
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 0   | 19.171200 | 5.4398400 | 90830792 | 2.7320500 | 1  | 1  | 146436 | "G"   | "T"   | ... |
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 1   | 12.943500 | 11.863600 | 90862225 | 3.1025600 | -1 | 1  | 146436 | "G"   | "G"   | ... |
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 2   | 12.399900 | 8.5553200 | 90644850 | 9.4114900 | 1  | -1 | 146436 | "G"   | "G"   | ... |
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 3   | 17.813200 | 9.4217400 | 90678594 | 7.7470200 | 1  | 1  | 146436 | "G"   | "G"   | ... |
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
| 4   | 7.9566400 | 5.4446700 | 90686690 | 8.6772700 | 1  | -1 | 146436 | "G"   | "T"   | ... |
+-----+-----------+-----------+----------+-----------+----+----+--------+-------+-------+-----+
root [5]

So @songshusen, can you tell us how you run your code and with which exact version of ROOT?

The version of ROOT I used is v6.28/04.
I run my code on windows with visual studio 2022 and C++17 (and C++20).
@bellenot

Hi @songshusen ,

when you run that code somewhere in there someone throws a std::bad_alloc exception. As we cannot reproduce the issue, I can only suggest that you compile that C++ code as a normal C++ program with debug symbols and run it in a debugger to see where the exception is thrown from.

Cheers,
Enrico

So you compiled your code with Visual Studio? Please make sure you use the same compilation flags than the ones used to compile ROOT, using root-config --cflags, as shown below:

C:\Users\bellenot>root-config --cflags
 -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -IC:\Users\bellenot\build\release\include

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.