# TMVA::DataLoader::AddEvent() Segmentation Violation

**URL:** <https://root-forum.cern.ch/t/tmva-addevent-segmentation-violation/31764>\
**Category:** TMVA\
**Created:** [November 26, 2018, 9:48am UTC](https://root-forum.cern.ch/t/tmva-addevent-segmentation-violation/31764 "2018-11-26T09:48:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mckea](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/54ee81/32.png) [@mckea](https://root-forum.cern.ch/u/mckea)\
**Post date:** [November 26, 2018, 9:48am UTC](https://root-forum.cern.ch/t/tmva-addevent-segmentation-violation/31764/1 "2018-11-26T09:48:41Z")

</div>

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:

```cpp
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:

```auto
===========================================================
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!!

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [November 26, 2018, 2:09pm UTC](https://root-forum.cern.ch/t/tmva-addevent-segmentation-violation/31764/2 "2018-11-26T14:09:03Z")

</div>

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 🙂

```auto
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](https://sft.its.cern.ch/jira/browse/ROOT-9833).

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![mckea](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/54ee81/32.png) [@mckea](https://root-forum.cern.ch/u/mckea)\
**Post date:** [November 26, 2018, 7:14pm UTC](https://root-forum.cern.ch/t/tmva-addevent-segmentation-violation/31764/3 "2018-11-26T19:14:52Z")

</div>

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.
