Hi, I’m new to JSROOT and javascript in general and I have what is likely an easy question:
I’m trying to write a function that will turn a branch into a javascript array.
function branchToArray(filename, branchName) {
let branchArray = [];
//use JSROOT to get arrays
JSROOT.OpenFile(filename, function(file) {
file.ReadObject('mytree;1', function(tree) {
//create selector object, add branches
let selector = new JSROOT.TSelector();
selector.AddBranch(branchName, 'myBranch');
let nPoints = 0;
//start the analysis
selector.Begin = function(){};
//run the loop
selector.Process = function(){
branchArray.push(this.tgtobj.myBranch);
nPoints ++;
}
//kill the loop
selector.Terminate = function(){};
tree.Process(selector);
});
});
return branchArray;
}
This returns an empty array at first, and then proceeds to fill it due to asynchronous behaviors I don’t fully understand, thus messing with my code. How would I make it so that my function fills the array before outputting it?