TMVA::DataLoader::AddEvent() Segmentation Violation

Hi!

I’m running in some trouble trying to add training and test events by hand into a DataLoader object, following the instructions in the TMVAClassification.C example.

Hereby I present a small snippet of code which reproduce the problem:

void test()
{
  TMVA::Tools::Instance();
  TFile* fout = new TFile("~/tmp/outClass.root", "RECREATE");
  TMVA::Factory* factory = new TMVA::Factory("MNISTClassOut", fout, "V:Silent:Color:DrawProgressBar:AnalysisType=auto");
  TMVA::DataLoader* dataloader = new TMVA::DataLoader();
  
  std::vector<double> data(2);
  data.at(0) = 1;
  data.at(1) = 2;
  
  dataloader->AddEvent("class1", TMVA::Types::kTraining, data, 1.0);
  
  return;
}

Running it with “root test.cc” gives me the following trace:

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007ff97c7de37b in waitpid () from /lib64/libc.so.6
#1  0x00007ff97c754a4f in ?? () from /lib64/libc.so.6
#2  0x00007ff97d43f71a in TUnixSystem::StackTrace() () from /usr/lib64/root/6.14/lib/libCore.so.6.14
#3  0x00007ff97d442204 in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib64/root/6.14/lib/libCore.so.6.14
#4  <signal handler called>
#5  0x00007ff96ef486d1 in TMVA::DataLoader::AddEvent(TString const&, TMVA::Types::ETreeType, std::vector<double, std::allocator<double> > const&, double) () from /usr/lib64/root/6.14/lib64/libTMVA.so.6.14.04
#6  0x00007ff97db80354 in ?? ()
#7  0x0000000000000000 in ?? ()
===========================================================

However, it does work if I follow the standard procedure of creating the different classes by adding TTrees and using AddVariable().

My ROOT version is 6.14/04 built with GCC-7.3.0 in a Gentoo system.

Thank you in advance!!

Hi,

Thanks for the report.

You need to declare the variables you are going to use (TMVA uses named variables), adding the two following lines before the call to DataLoader::AddEvent should do the trick :slight_smile:

dataloader->AddVariable("x", 'F');
dataloader->AddVariable("y", 'F');

Admittedly, TMVA should be able to provide this information (that it lacks variable definitions) and not crash. A bug report has been created for this. Should you be interested you can follow the resolution in this ticket.

Cheers,
Kim

Hi!

Thank you very much for the quick answer! It’s working now. I misunderstood the code examples and thought that the AddVariable step was not necessary in my approach.

Best regards.