# Segmentation fault using new method "AddVariablesArray"

**URL:** <https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436>\
**Category:** TMVA\
**Created:** [September 14, 2020, 1:42pm UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436 "2020-09-14T13:42:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheZardoz](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@TheZardoz](https://root-forum.cern.ch/u/TheZardoz)\
**Post date:** [September 14, 2020, 1:42pm UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/1 "2020-09-14T13:42:54Z")

</div>

Hi,  
I tried to use the RNN from TMVA using the example : [https://root.cern/doc/master/TMVA\_\_RNN\_\_Classification\_8C.html](https://root.cern/doc/master/TMVA __RNN__ Classification_8C.html)

This example use the new function “AddVariablesArray”

For my case i used a tree with 500 samples of 50\*3500 entries (the creator of the example used different number but the idea is the same).

However the program break into segmentation fault after loading the Signal event as follow :

> fo in \<TMVA\_RNN\_Classification\>: Booking Keras GRU model  
> Factory : Booking method: PyKeras\_GRU  
> :  
> : Using TensorFlow backend - setting special configuration options  
> : Using Tensorflow version 2  
> : Applying GPU option: gpu\_options.allow\_growth=True  
> : Load model from file: model\_GRU.h5  
> Factory : Booking method: BDTG  
> :  
> : the option NegWeightTreatment=InverseBoostNegWeights does not exist for BoostType=Grad  
> : → change to new default NegWeightTreatment=Pray  
> : Building event vectors for type 2 Signal  
> : Dataset[dataset] : create input formulas for tree RNN\_TWFS  
> : Using variable RNN\_N\_WF\_0[0] from array expression RNN\_N\_WF\_0 of size 50  
> : Using variable RNN\_N\_WF\_1[0] from array expression RNN\_N\_WF\_1 of size 50  
> : Using variable RNN\_N\_WF\_2[0] from array expression RNN\_N\_WF\_2 of size 50  
> : Using variable RNN\_N\_WF\_3[0] from array expression RNN\_N\_WF\_3 of size 50  
> : Using variable RNN\_N\_WF\_4[0] from array expression RNN\_N\_WF\_4 of size 50  
> : Using variable RNN\_N\_WF\_5[0] from array expression RNN\_N\_WF\_5 of size 50  
> : Using variable RNN\_N\_WF\_6[0] from array expression RNN\_N\_WF\_6 of size 50  
> : Using variable RNN\_N\_WF\_7[0] from array expression RNN\_N\_WF\_7 of size 50  
> : Using variable RNN\_N\_WF\_8[0] from array expression RNN\_N\_WF\_8 of size 50  
> : Using variable RNN\_N\_WF\_9[0] from array expression RNN\_N\_WF\_9 of size 50  
> : Using variable RNN\_N\_WF\_10[0] from array expression RNN\_N\_WF\_10 of size 50  
> : Using variable RNN\_N\_WF\_11[0] from array expression RNN\_N\_WF\_11 of size 50  
> : Using variable RNN\_N\_WF\_12[0] from array expression RNN\_N\_WF\_12 of size 50  
> : Using variable RNN\_N\_WF\_13[0] from array expression RNN\_N\_WF\_13 of size 50  
> : Using variable RNN\_N\_WF\_14[0] from array expression RNN\_N\_WF\_14 of size 50  
> : Using variable RNN\_N\_WF\_15[0] from array expression RNN\_N\_WF\_15 of size 50  
> : Using variable RNN\_N\_WF\_16[0] from array expression RNN\_N\_WF\_16 of size 50  
> : Using variable RNN\_N\_WF\_17[0] from array expression RNN\_N\_WF\_17 of size 50  
> : Using variable RNN\_N\_WF\_18[0] from array expression RNN\_N\_WF\_18 of size 50  
> : Using variable RNN\_N\_WF\_19[0] from array expression RNN\_N\_WF\_19 of size 50  
> : Using variable RNN\_N\_WF\_20[0] from array expression RNN\_N\_WF\_20 of size 50  
> : Using variable RNN\_N\_WF\_21[0] from array expression RNN\_N\_WF\_21 of size 50  
> : Using variable RNN\_N\_WF\_22[0] from array expression RNN\_N\_WF\_22 of size 50  
> : Using variable RNN\_N\_WF\_23[0] from array expression RNN\_N\_WF\_23 of size 50  
> : Using variable RNN\_N\_WF\_24[0] from array expression RNN\_N\_WF\_24 of size 50  
> : Using variable RNN\_N\_WF\_25[0] from array expression RNN\_N\_WF\_25 of size 50  
> : Using variable RNN\_N\_WF\_26[0] from array expression RNN\_N\_WF\_26 of size 50  
> : Using variable RNN\_N\_WF\_27[0] from array expression RNN\_N\_WF\_27 of size 50  
> : Using variable RNN\_N\_WF\_28[0] from array expression RNN\_N\_WF\_28 of size 50  
> : Using variable RNN\_N\_WF\_29[0] from array expression RNN\_N\_WF\_29 of size 50  
> : Using variable RNN\_N\_WF\_30[0] from array expression RNN\_N\_WF\_30 of size 50  
> : Using variable RNN\_N\_WF\_31[0] from array expression RNN\_N\_WF\_31 of size 50  
> : Using variable RNN\_N\_WF\_32[0] from array expression RNN\_N\_WF\_32 of size 50  
> : Using variable RNN\_N\_WF\_33[0] from array expression RNN\_N\_WF\_33 of size 50  
> : Using variable RNN\_N\_WF\_34[0] from array expression RNN\_N\_WF\_34 of size 50  
> : Using variable RNN\_N\_WF\_35[0] from array expression RNN\_N\_WF\_35 of size 50  
> : Using variable RNN\_N\_WF\_36[0] from array expression RNN\_N\_WF\_36 of size 50  
> : Using variable RNN\_N\_WF\_37[0] from array expression RNN\_N\_WF\_37 of size 50  
> : Using variable RNN\_N\_WF\_38[0] from array expression RNN\_N\_WF\_38 of size 50  
> : Using variable RNN\_N\_WF\_39[0] from array expression RNN\_N\_WF\_39 of size 50  
> : Using variable RNN\_N\_WF\_40[0] from array expression RNN\_N\_WF\_40 of size 50  
> : Using variable RNN\_N\_WF\_41[0] from array expression RNN\_N\_WF\_41 of size 50  
> : Using variable RNN\_N\_WF\_42[0] from array expression RNN\_N\_WF\_42 of size 50  
> : Using variable RNN\_N\_WF\_43[0] from array expression RNN\_N\_WF\_43 of size 50  
> : Using variable RNN\_N\_WF\_44[0] from array expression RNN\_N\_WF\_44 of size 50  
> : Using variable RNN\_N\_WF\_45[0] from array expression RNN\_N\_WF\_45 of size 50  
> : Using variable RNN\_N\_WF\_46[0] from array expression RNN\_N\_WF\_46 of size 50  
> : Using variable RNN\_N\_WF\_47[0] from array expression RNN\_N\_WF\_47 of size 50  
> : Using variable RNN\_N\_WF\_48[0] from array expression RNN\_N\_WF\_48 of size 50  
> : Using variable RNN\_N\_WF\_49[0] from array expression RNN\_N\_WF\_49 of size 50  
> : Using variable RNN\_N\_WF\_50[0] from array expression RNN\_N\_WF\_50 of size 50  
> : Using variable RNN\_N\_WF\_51[0] from array expression RNN\_N\_WF\_51 of size 50  
> : Using variable RNN\_N\_WF\_52[0] from array expression RNN\_N\_WF\_52 of size 50  
> : Using variable RNN\_N\_WF\_53[0] from array expression RNN\_N\_WF\_53 of size 50  
> : Using variable RNN\_N\_WF\_54[0] from array expression RNN\_N\_WF\_54 of size 50  
> : Using variable RNN\_N\_WF\_55[0] from array expression RNN\_N\_WF\_55 of size 50  
> : Using variable RNN\_N\_WF\_56[0] from array expression RNN\_N\_WF\_56 of size 50  
> : Using variable RNN\_N\_WF\_57[0] from array expression RNN\_N\_WF\_57 of size 50  
> : Using variable RNN\_N\_WF\_58[0] from array expression RNN\_N\_WF\_58 of size 50  
> : Using variable RNN\_N\_WF\_59[0] from array expression RNN\_N\_WF\_59 of size 50  
> : Using variable RNN\_N\_WF\_60[0] from array expression RNN\_N\_WF\_60 of size 50  
> : Using variable RNN\_N\_WF\_61[0] from array expression RNN\_N\_WF\_61 of size 50  
> : Using variable RNN\_N\_WF\_62[0] from array expression RNN\_N\_WF\_62 of size 50  
> : Using variable RNN\_N\_WF\_63[0] from array expression RNN\_N\_WF\_63 of size 50  
> : Using variable RNN\_N\_WF\_64[0] from array expression RNN\_N\_WF\_64 of size 50  
> : Using variable RNN\_N\_WF\_65[0] from array expression RNN\_N\_WF\_65 of size 50  
> : Using variable RNN\_N\_WF\_66[0] from array expression RNN\_N\_WF\_66 of size 50  
> : Using variable RNN\_N\_WF\_67[0] from array expression RNN\_N\_WF\_67 of size 50  
> : Using variable RNN\_N\_WF\_68[0] from array expression RNN\_N\_WF\_68 of size 50  
> : Using variable RNN\_N\_WF\_69[0] from array expression RNN\_N\_WF\_69 of size 50  
> : Using variable RNN\_N\_WF\_70[0] from array expression RNN\_N\_WF\_70 of size 50  
> : Using variable RNN\_N\_WF\_71[0] from array expression RNN\_N\_WF\_71 of size 50  
> : Using variable RNN\_N\_WF\_72[0] from array expression RNN\_N\_WF\_72 of size 50  
> : Using variable RNN\_N\_WF\_73[0] from array expression RNN\_N\_WF\_73 of size 50  
> : Using variable RNN\_N\_WF\_74[0] from array expression RNN\_N\_WF\_74 of size 50  
> : Using variable RNN\_N\_WF\_75[0] from array expression RNN\_N\_WF\_75 of size 50  
> : Using variable RNN\_N\_WF\_76[0] from array expression RNN\_N\_WF\_76 of size 50  
> ect …

> …  
> : Using variable RNN\_N\_WF\_492[0] from array expression RNN\_N\_WF\_492 of size 50  
> : Using variable RNN\_N\_WF\_493[0] from array expression RNN\_N\_WF\_493 of size 50  
> : Using variable RNN\_N\_WF\_494[0] from array expression RNN\_N\_WF\_494 of size 50  
> : Using variable RNN\_N\_WF\_495[0] from array expression RNN\_N\_WF\_495 of size 50  
> : Using variable RNN\_N\_WF\_496[0] from array expression RNN\_N\_WF\_496 of size 50  
> : Using variable RNN\_N\_WF\_497[0] from array expression RNN\_N\_WF\_497 of size 50  
> : Using variable RNN\_N\_WF\_498[0] from array expression RNN\_N\_WF\_498 of size 50  
> : Using variable RNN\_N\_WF\_499[0] from array expression RNN\_N\_WF\_499 of size 50
> 
> \*\*\* Break \*\*\* segmentation violation  
> [/usr/lib/system/libsystem\_platform.dylib] \_sigtramp (no debug info)  
> [/usr/lib/dyld] dyld::gLinkContext (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTreePlayer.so] double TFormLeafInfoCollection::GetValueImpl(TLeaf\*, int) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA::DataSetFactory::BuildEventVector(TMVA::DataSetInfo&, TMVA::DataInputHandler&, std::\_\_1::map\<TMVA::Types::ETreeType, std::\_\_1::vector\<std::\_\_1::vector\<TMVA::Event\*, std::\_\_1::allocatorTMVA::Event\* \>, std::\_\_1::allocator\<std::\_\_1::vector\<TMVA::Event\*, std::\_\_1::allocatorTMVA::Event\* \> \> \>, std::\_\_1::lessTMVA::Types::ETreeType, std::\_\_1::allocator\<std::\_\_1::pair\<TMVA::Types::ETreeType const, std::\_\_1::vector\<std::\_\_1::vector\<TMVA::Event\*, std::\_\_1::allocatorTMVA::Event\* \>, std::\_\_1::allocator\<std::\_\_1::vector\<TMVA::Event\*, std::\_\_1::allocatorTMVA::Event\* \> \> \> \> \> \>&, std::\_\_1::vector\<TMVA::DataSetFactory::EventStats, std::\_\_1::allocatorTMVA::DataSetFactory::EventStats \>&) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA::DataSetFactory::BuildInitialDataSet(TMVA::DataSetInfo&, TMVA::DataInputHandler&) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA::DataSetFactory::CreateDataSet(TMVA::DataSetInfo&, TMVA::DataInputHandler&) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA::DataSetManager::CreateDataSet(TString const&) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA::DataSetInfo::GetDataSet() const (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA::MethodBDT::ProcessOptions() (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA:🏭:BookMethod(TMVA::DataLoader\*, TString, TString, TString) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libTMVA.so] TMVA:🏭:BookMethod(TMVA::DataLoader\*, TMVA::Types::EMVA, TString, TString) (no debug info)  
> [] (no debug info)  
> [] (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value\*) const (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const\*, cling::Value\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::\_\_1::basic\_string\<char, std::\_\_1::char\_traits, std::\_\_1::allocator \> const&, cling::CompilationOptions, cling::Value\*, cling::Transaction\*\*, unsigned long) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value\*, bool) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor\*, char const\*, cling::Interpreter::CompilationResult&, cling::Value\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] TCling::ProcessLine(char const\*, TInterpreter::EErrorCode\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCling.so] TCling::ProcessLineSynch(char const\*, TInterpreter::EErrorCode\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libCore.so] TApplication::ExecuteFile(char const\*, int\*, bool) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libRint.so] TRint::ProcessLineNr(char const\*, char const\*, int\*) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/lib/root/libRint.so] TRint::Run(bool) (no debug info)  
> [/usr/local/Cellar/root/6.22.00\_1/bin/root.exe] main (no debug info)  
> [/usr/lib/system/libdyld.dylib] start (no debug info)  
> [] (no debug info)

Is the new method “AddVariablesArray” not confortable with vector of vector ?

Here the script i used (it’s the same from the example but modified a little)[TMVA\_RNN\_Classification.C](https://root-forum.cern.ch/uploads/short-url/yi2Eghirr0oAu6EI2LE6drZUtaM.C) (13.8 KB)

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [September 15, 2020, 7:12am UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/2 "2020-09-15T07:12:58Z")

</div>

@moneta Can you help?

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 15, 2020, 2:11pm UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/3 "2020-09-15T14:11:38Z")

</div>

Hi,  
What is the type of the branch in the Tree : `RNN_N_WF_...` . It should be a collection, e.g. an std::vector or similar. Can you post a small snapshot of your data, just a copy with few events, so I can reproduce your error

Thank you

Lorenzo

---

<div class="post-metadata">

**Author:** ![TheZardoz](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@TheZardoz](https://root-forum.cern.ch/u/TheZardoz)\
**Post date:** [September 16, 2020, 10:56am UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/4 "2020-09-16T10:56:20Z")

</div>

Hi,  
The type of the branch is an std::vector . Here a small snapshot of my data

[test\_small\_OUT\_RNN\_OUT\_Alphas\_Dataset\_BiPo.root](https://root-forum.cern.ch/uploads/short-url/tdh6diVI6pwNslxG7K4agKcYOk5.root) (1.6 MB) [test\_small\_OUT\_RNN\_OUT\_Neutron\_AmBe\_Complete\_Source\_Stack.root](https://root-forum.cern.ch/uploads/short-url/zNxtvEvQHC2CXyvWiLM2FDW2f7H.root) (1.7 MB)

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 16, 2020, 1:03pm UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/5 "2020-09-16T13:03:30Z")

</div>

Hi,

It looks to me that in the Tree the std::vector have different sizes Are the vector size sometimes zero for some events ? That could explain the crash observed.  
I would try to re-create a Tree where for each entry each vector has a size=50. If it is not the case I would add a vector padding with zero values

Lorenzo

---

<div class="post-metadata">

**Author:** ![TheZardoz](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@TheZardoz](https://root-forum.cern.ch/u/TheZardoz)\
**Post date:** [September 16, 2020, 3:13pm UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/6 "2020-09-16T15:13:45Z")

</div>

Hi,

Normally all vector have the same size (50) except for the last one but we didn’t take into account this one in the RNN script.

Zardoz

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 17, 2020, 8:56am UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/7 "2020-09-17T08:56:46Z")

</div>

Hi,  
I can reproduce the crash in the data I have. The problem (in the data you have posted) is that the TTree’s have 500 entries but only for the first 50 entries the arrays have size=50.  
You can check this by doing:

```auto
tree->Draw(Draw("Length$(RNN_N_WF_0)","Entry$>=50")

```

You can strip the tree and keep only the good entries, unfortunately you cannot use the tree’s as they are in TMVA, but you can fix this before using TMVA with `TTree::CloneTree``:

```auto
auto file = TFile::Open("test_small_OUT_RNN_OUT_Alphas_Dataset_BiPo.root");
auto * t = (TTree*) file->Get("RNN_Results/RNN_TWFS");
TFile fileOut("test_new_Alphas.root","NEW");
auto tnew = t->CloneTree(50); // copy the first 50 entry of the tree
tnew->Write(); 
fileOut.Close(); 

```

after doing this your macro works fine with these data

Lorenzo

---

<div class="post-metadata">

**Author:** ![TheZardoz](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@TheZardoz](https://root-forum.cern.ch/u/TheZardoz)\
**Post date:** [September 17, 2020, 11:16am UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/8 "2020-09-17T11:16:45Z")

</div>

Hi,

Indeed, it’s working after these modifications. Thank you very much !

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [September 17, 2020, 12:33pm UTC](https://root-forum.cern.ch/t/segmentation-fault-using-new-method-addvariablesarray/41436/9 "2020-09-17T12:33:38Z")

</div>

Good!  
I have added anyway a check in TMVA for this case by printing an error message.  
See [https://github.com/root-project/root/pull/6372](https://github.com/root-project/root/pull/6372)

Lorenzo
