Skip to content

Commit e441a3d

Browse files
committed
Support fixed-size arrays in TTree::Draw
1 parent 35fca0c commit e441a3d

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

scripts/JSRootIOEvolution.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@
3535
Z_DEFLATED : 8,
3636
Z_HDRSIZE : 9,
3737
Mode : "array", // could be string or array, enable usage of ArrayBuffer in http requests
38-
NativeArray : true // when true, native arrays like Int32Array or Float64Array are used
38+
NativeArray : true, // when true, native arrays like Int32Array or Float64Array are used
39+
IsInteger : function(typ) { return ((typ>=this.kChar) && (typ<=this.kCounter)) ||
40+
((typ>=this.kLegacyChar) && (typ<=this.kBool)); },
41+
IsNumeric : function(typ) { return (typ>0) && (typ<=this.kBool) && (typ!==this.kCharStar); }
42+
3943
};
4044

45+
46+
4147
// map of user-streamer function like func(buf,obj)
4248
JSROOT.fUserStreamers = {};
4349

@@ -236,6 +242,7 @@
236242
for (var i = 0; i < n; ++i)
237243
array[i] = this.ntoi4();
238244
break;
245+
case JSROOT.IO.kBits:
239246
case JSROOT.IO.kUInt:
240247
array = JSROOT.IO.NativeArray ? new Uint32Array(n) : new Array(n);
241248
for (var i = 0; i < n; ++i)
@@ -691,6 +698,7 @@
691698
for (; i < n; ++i, o+=4)
692699
array[i] = view.getInt32(o);
693700
break;
701+
case JSROOT.IO.kBits:
694702
case JSROOT.IO.kUInt:
695703
array = new Uint32Array(n);
696704
for (; i < n; ++i, o+=4)
@@ -1863,6 +1871,7 @@
18631871
case JSROOT.IO.kOffsetL+JSROOT.IO.kDouble:
18641872
case JSROOT.IO.kOffsetL+JSROOT.IO.kShort:
18651873
case JSROOT.IO.kOffsetL+JSROOT.IO.kUShort:
1874+
case JSROOT.IO.kOffsetL+JSROOT.IO.kBits:
18661875
case JSROOT.IO.kOffsetL+JSROOT.IO.kUInt:
18671876
case JSROOT.IO.kOffsetL+JSROOT.IO.kULong:
18681877
case JSROOT.IO.kOffsetL+JSROOT.IO.kULong64:
@@ -1914,6 +1923,7 @@
19141923
case JSROOT.IO.kOffsetP+JSROOT.IO.kChar:
19151924
case JSROOT.IO.kOffsetP+JSROOT.IO.kShort:
19161925
case JSROOT.IO.kOffsetP+JSROOT.IO.kUShort:
1926+
case JSROOT.IO.kOffsetP+JSROOT.IO.kBits:
19171927
case JSROOT.IO.kOffsetP+JSROOT.IO.kUInt:
19181928
case JSROOT.IO.kOffsetP+JSROOT.IO.kULong:
19191929
case JSROOT.IO.kOffsetP+JSROOT.IO.kULong64:
@@ -2008,6 +2018,7 @@
20082018
member.func = function(buf,obj) { obj[this.name] = buf.ntou1(); }; break;
20092019
case JSROOT.IO.kUShort:
20102020
member.func = function(buf,obj) { obj[this.name] = buf.ntou2(); }; break;
2021+
case JSROOT.IO.kBits:
20112022
case JSROOT.IO.kUInt:
20122023
member.func = function(buf,obj) { obj[this.name] = buf.ntou4(); }; break;
20132024
case JSROOT.IO.kULong64:

scripts/JSRootPainter.js

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8166,7 +8166,7 @@
81668166
buf.CheckBytecount(ver, 'branch_vector_read');
81678167
}
81688168
} else {
8169-
arrays.push(baskets[n].raw.ReadFastArray(baskets[n].fNevBuf, item._datakind));
8169+
arrays.push(baskets[n].raw.ReadFastArray(baskets[n].fNevBuf * item._arrsize, item._datakind));
81708170
}
81718171

81728172
// console.log('array', arr.length);
@@ -8181,12 +8181,25 @@
81818181
if ((n===0) || (lmax > xmax)) xmax = lmax;
81828182
}
81838183

8184-
if (xmin>=xmax)
8185-
xmax = (xmin<1e6) ? (xmin+1) : (xmin*1.01);
8184+
var nbins = 200;
81868185

8187-
histo = JSROOT.CreateTH1(100);
8186+
if (xmin>=xmax) {
8187+
xmax = xmin;
8188+
if (Math.abs(xmin<100)) { xmin-=1; xmax+=1; } else
8189+
if (xmin>0) { xmin*=0.9; xmax*=1.1; } else
8190+
{ xmin*=1.1; xmax*=0.9; }
8191+
} else
8192+
if (JSROOT.IO.IsInteger(item._datakind) && (xmax-xmin >=1) && (xmax-xmin<5000)) {
8193+
xmin = Math.floor(xmin) - 1;
8194+
xmax = Math.floor(xmax) + ((xmax === Math.round(xmax)) ? 1 : 2);
8195+
nbins = xmax - xmin + 1;
8196+
} else {
8197+
xmax += (xmax-xmin)/nbins;
8198+
}
8199+
8200+
histo = JSROOT.CreateTH1(nbins);
81888201
histo.fXaxis.fXmin = xmin;
8189-
histo.fXaxis.fXmax = xmin + (xmax-xmin)*1.001;
8202+
histo.fXaxis.fXmax = xmax;
81908203
histo.fName = "draw_" + item._name;
81918204
histo.fTitle = "drawing '" + item._name + "' from " + item._parent._name;
81928205
histo.fCustomStat = 111110;
@@ -8207,6 +8220,7 @@
82078220
ReadNextBaskets(0);
82088221
}
82098222

8223+
/*
82108224
JSROOT.Painter.CreateBranchLeaves = function(s_i, hitem) {
82118225
// not yet used, in the feauture one can streamer objects from branch and access its fields
82128226
@@ -8263,21 +8277,23 @@
82638277
82648278
return cnt;
82658279
}
8280+
*/
82668281

82678282
JSROOT.Painter.CreateBranchItem = function(node, branch) {
82688283
if (!node || !branch) return false;
82698284

82708285
var nb_branches = branch.fBranches ? branch.fBranches.arr.length : 0,
82718286
nb_leaves = branch.fLeaves ? branch.fLeaves.arr.length : 0,
82728287
leaf = (nb_leaves>0) ? branch.fLeaves.arr[0] : null,
8273-
datakind = 0, isvector = false,
8288+
datakind = 0, arrsize = 1,
8289+
isvector = false,
82748290
fprnt = node._parent;
82758291

82768292
// check that we have file
82778293
while (fprnt && !fprnt._file) fprnt = fprnt._parent;
82788294

8279-
// display branch with only leaf as leaf
8280-
if ((nb_leaves === 1) && (leaf.fName === branch.fName) && fprnt) {
8295+
// display branch with the only leaf
8296+
if ((nb_leaves === 1) && fprnt && ((leaf.fName === branch.fName) || (branch.fName.indexOf(leaf.fName)===0)) ) {
82818297
switch (leaf._typename) {
82828298
case 'TLeafF' : datakind = JSROOT.IO.kFloat; break;
82838299
case 'TLeafD' : datakind = JSROOT.IO.kDouble; break;
@@ -8295,9 +8311,14 @@
82958311
case "vector<bool>": isvector = true; datakind = JSROOT.IO.kBool; break;
82968312
}
82978313
} else
8298-
if ((leaf.fType > 0) && (leaf.fType < 19) &&
8299-
(leaf.fType!==JSROOT.IO.kCharStar) && (leaf.fType!==JSROOT.IO.kBits))
8300-
datakind = leaf.fType;
8314+
if (JSROOT.IO.IsNumeric(leaf.fType)) {
8315+
datakind = leaf.fType;
8316+
} else
8317+
if (JSROOT.IO.IsNumeric(leaf.fType-JSROOT.IO.kOffsetL)) {
8318+
datakind = leaf.fType - JSROOT.IO.kOffsetL;
8319+
arrsize = leaf.fLen; // fixed-size array
8320+
}
8321+
83018322
break;
83028323
}
83038324
}
@@ -8311,7 +8332,7 @@
83118332
_name : ClearName(branch.fName),
83128333
_kind : "ROOT." + branch._typename,
83138334
_title : branch.fTitle
8314-
// _obj: branch // only for debug purposes
8335+
// _obj: branch // only for debug purposes
83158336
};
83168337

83178338
if (!node._childs) node._childs = [];
@@ -8326,6 +8347,7 @@
83268347
subitem._can_draw = true;
83278348
subitem._branch = branch;
83288349
subitem._datakind = datakind;
8350+
subitem._arrsize = arrsize;
83298351
subitem._isvector = isvector;
83308352
subitem._get = JSROOT.Painter.TreeDrawGet;
83318353

@@ -8335,7 +8357,7 @@
83358357
if (branch._typename==='TBranchElement')
83368358
subitem._title += " " + branch.fClassName + ";" + branch.fClassVersion;
83378359

8338-
//subitem._obj = branch;
8360+
subitem._obj = branch;
83398361

83408362
if (nb_branches > 0) {
83418363
subitem._more = true;
@@ -10517,8 +10539,8 @@
1051710539
JSROOT.addDrawFunc({ name: "TTask", icon: "img_task", expand: JSROOT.Painter.TaskHierarchy, for_derived: true });
1051810540
JSROOT.addDrawFunc({ name: "TTree", icon: "img_tree", noinspect:true, expand: JSROOT.Painter.TreeHierarchy });
1051910541
JSROOT.addDrawFunc({ name: "TNtuple", icon: "img_tree", noinspect:true, expand: JSROOT.Painter.TreeHierarchy });
10520-
JSROOT.addDrawFunc({ name: /^TBranch/, icon: "img_branch", noinspect:true });
10521-
JSROOT.addDrawFunc({ name: /^TLeaf/, icon: "img_leaf", noinspect:true });
10542+
JSROOT.addDrawFunc({ name: /^TBranch/, icon: "img_branch", noinspect:false });
10543+
JSROOT.addDrawFunc({ name: /^TLeaf/, icon: "img_leaf", noinspect:false });
1052210544
JSROOT.addDrawFunc({ name: "TList", icon: "img_list", noinspect:true, expand: JSROOT.Painter.ListHierarchy });
1052310545
JSROOT.addDrawFunc({ name: "TObjArray", icon: "img_list", noinspect:true, expand: JSROOT.Painter.ListHierarchy });
1052410546
JSROOT.addDrawFunc({ name: "TClonesArray", icon: "img_list", noinspect:true, expand: JSROOT.Painter.ListHierarchy });

0 commit comments

Comments
 (0)