How to read array with fixed size stored in branch from TTree in JSROOT?

I am trying to read fiexd size array from branches in TTree in jsroot. At first, I built a tree with C++ and coded like

// in cpp
tree.Branch("px", &px, "px[3]/D");

So this branch is a fixed size array branch. And I am familiar to read this branch with C++, but I failed to read it with jsroot. I followed the demo in Reading object from the ROOT file, and coded like

// in main.js script
class MySelector extends TSelector {
	constructor() {
		super();
		this.addBranch('px');
	}
	...
}

This works well with bracnhes that store single number. But it failed with array. To run the above js code, I build a simple local server on win10 with command python -m http.server, serving a webpage writring with html. In the webpage, I use

# in html
<script type="module" src="main.js"></script>

to run the code I memtioned above. I check the webpage with firefox browser. I tried to get more information about the variable px using codes

console.log(this.tgtobj.px, typeof(this.tgtobj.px));

The log shows that px is of number type, and I can only get px[0]. However, I hope to read it as Array type in js to get the information of px[1] and px[2].

ROOT Version: jsroot 7.5.2
Platform: win10
Compiler: firefox?

------------ update 1 -------------------
I upload the root file (example.root), html (index.cpp) and javascript code (main.cpp). Since the limited of extensions, please change the name of the files by yorurself (index.cpp → index. html, main.cpp → main.js).


example.root (5.6 KB)
index.cpp (248 Bytes)
main.cpp (698 Bytes)

#include <TFile.h>
#include <TTree.h>

int main() {
  TFile opf("example.root", "recreate");
  TTree opt("tree", "example tree");
  // output data
  double px[3];
  double p;
  // setup output branches
  opt.Branch("px", px, "px[3]/D");
  opt.Branch("p", &p, "p/D");
    
  // fill data
  for (int i = 0; i < 10; ++i) {
    px[0] = i;
    px[1] = i+1;
    px[1] = i+2;
    p = px[0] + px[1] + px[2];
    opt.Fill();
  }
  // save tree
  opt.Write();
  // close files
  opf.Close();
  return 0;
}

To be clear, I paste the C++ code that building this example root file.

Hi and welcome one the forum,

Can you upload here ROOT file with such TTree object?

I upload the example root file and some code to read it.

Thank you for providing reproducer!

JSROOT was never tested with such data and therefore was not working :frowning:

I apply the fix to all active branches of JSROOT. Now it should work - here is link with dump of that branch.

Your example has small typo - last element of the array is not initialized and therefore has strange values.

You can use now master or 7.5 branch.
I will provide bug-fix release later this week.

Thank you. Now my program works well with master.