Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This works for me using indexing in python.</p> <pre><code> &gt;&gt;&gt;from ROOT import * &gt;&gt;&gt;vec1 = std.vector('double')() &gt;&gt;&gt;vec2 = std.vector('double')() &gt;&gt;&gt;vec_vec = std.vector(std.vector('double'))() &gt;&gt;&gt;for i in range(3): &gt;&gt;&gt; vec1.push_back(i) &gt;&gt;&gt;for i in range(5): &gt;&gt;&gt; vec2.push_back(i) &gt;&gt;&gt;vec_vec.push_back(vec1) &gt;&gt;&gt;vec_vec.push_back(vec2) &gt;&gt;&gt;len(vec_vec) 2 &gt;&gt;&gt;len(vec_vec[0]) 3 &gt;&gt;&gt;len(vec_vec[1]) 5 &gt;&gt;&gt;vec_vec[1][2] 2.0 </code></pre> <p>In your example the error says:</p> <pre><code> TypeError: 'vector&lt;vector&lt;float&gt; &gt;' object is unindexable </code></pre> <p>After calling the constructor std.vector(type)() you have different types that indicate that an allocator for memory space is working.</p> <pre><code> &gt;&gt;&gt;type(vec1) &lt;class 'ROOT.vector&lt;double,allocator&lt;double&gt; &gt;'&gt; &gt;&gt;&gt;type(vec_vec) &lt;class 'ROOT.vector&lt;vector&lt;double,allocator&lt;double&gt; &gt;,allocator&lt;vector&lt;double,allocator&lt;double&gt; &gt; &gt; &gt;'&gt; </code></pre> <p>To import such vectors from a TTree use setBranchAddress like in this example:</p> <pre><code> &gt;&gt;&gt;tree = file.Get('tree') &gt;&gt;&gt;tree.SetBranchAddress("nested",vec_vec) &gt;&gt;&gt;N = tree.GetEntries() &gt;&gt;&gt;for i in range(N): &gt;&gt;&gt; vec_vec.clear() &gt;&gt;&gt; tree.GetEntry(i) &gt;&gt;&gt; print vec_vec[0][0] </code></pre> <p>Also note that this may be significantly faster after using</p> <pre><code> &gt;&gt;&gt;tree.setBranchStatus('*',0) &gt;&gt;&gt;tree.setBranchStatus('nested',1) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload