Snapshot in python

In C++ the third argument in Snapshot have such brackets “{}”. But in Python it associated with dictionaries. How i can substitute {} to Python code?

mim = ROOT.RDataFrame(“FADCData 882”, “/home/erg/po_1_event/Oct__13070311.root”)

lum = mim.Redefine(“Channel0”, “Channel0 - 562”).Snapshot(“FData882”, “/home/erg/po_1_event/Oct_13070311.root”, [“trench0”])

TypeError: Template method resolution failed:
none of the 3 overloaded methods succeeded.
could not convert argument 3
Unknown column: trench0

_ROOT Version: 6.26/10
_Platform: pycharm community
Compiler: Not Provided


You did it correct by substituting {} with [] list.

The error says that “Unknown column: trench0”. Did you mean Channel0 here?
Otherwise ensure that the column exists in the tree or there are no typos…

cheers

“trench0” is a branch, which i created before in the tree “FData882” in file “/home/erg/po_1_event/Oct_13070311.root”

myFile = ROOT.TFile.Open(‘/home/erg/po_1_event/Oct_13070311.root’, “RECREATE”)
mytree = ROOT.TTree(“FData882”, “FData882”)
rock0 = array.array(‘i’, [0])
mytree.Branch(“trench0”, rock0, “trench0/I”)

Or Snapshot itself create the new file with new tree and branch?

In the code above the tree name has a space bar inside it, is that a typo or is it expected?
FADCData 882

And yes, Snapshot creates a completely new file and copies all the branches indicated in the 3rd argument list. I am not sure if the default behaviour is to rewrite the file. So be careful to rename it to something different than initial file name.

Yes, this tree name has a space bar.

Thank you so much for advices.

I delete that file and rewrite the line

lum = mim.Redefine(“Channel0”, “Channel0-562”).Snapshot(“FADCData 882”, “/home/erg/po_1_event/Oct_13070311.root”, [“Channel0”])

none of the 3 overloaded methods succeeded
could not convert argument 3
Unknown column: size

Is it possible for you to share the file and a small reproducer?

All this is on the working computer. In 9 days I will be able to reply.

Oct__13070311.root (147.5 KB)

Ok, interesting. It seems that Redifine produces some strange error with arrays?

import ROOT
df = ROOT.RDataFrame("FADCData 882", "Oct__13070311.root")
# commenting redifine works , output 1
df = df.Redefine("Channel0", "Channel0 - 562")
print( df.Count().GetValue() )

Error:

Error in <TTreeReaderArrayBase::GetBranchContentDataType()>: The branch Channel0 was created using a leaf list and cannot be represented as a C++ type. Please access one of its siblings using a TTreeReaderArray:
Error in <TTreeReaderArrayBase::GetBranchContentDataType()>:    Channel0.ch0
Error in <TTreeReaderArrayBase::CreateContentProxy()>: Cannot determine the type contained in the collection of branch Channel0. That's weird - please report!
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    print( df.Count().GetValue())
cppyy.gbl.std.runtime_error: const ULong64_t& ROOT::RDF::RResultPtr<ULong64_t>::GetValue() =>
    runtime_error: An error was encountered while processing the data. TTreeReader status code is: 6

It even has “That’s weird - please report!” in the error…

Maybe @eguiraud can help :slight_smile: ?

Hi,

sorry for the (very) late reply and thank you very much @FoxWise for taking a look.
I will be off for a while, I hope @vpadulan or @Axel can try to reproduce and debug in the meanwhile.

Cheers,
Enrico

The greatest suspect in my opinion is neither Snapshot nor Redefine, but

Error in <TTreeReaderArrayBase::GetBranchContentDataType()>: The branch Channel0 was created using a leaf list and cannot be represented as a C++ type. Please access one of its siblings using a TTreeReaderArray

as this makes the practical usage of this column invalid in almost all the operations of the API, I will try to look further into this.

It’s maybe a long shot, but would it be possible to know how the “Channel0” column was created and filled in the first place?

Vincenzo

As far as I understand, this column was created as a C++ type. The set of 10230 points.

In the “Oct__13070311.root” file, the “FADCData 882” and “FADCData 939” trees have:

...
*Br    0 :SizeOfChannels : size/S                                            *
...
*Br    1 :Channel0  : ch0[size]/s                                            *
...

This will not work in ROOT.
The leaf which is used as the variable length of an array must be an “Int_t” (you need “SizeOfChannels : size/I”).

Thanks a lot.
@pcanal Can we change /S to /I? Or can we copy data with changes?

Can we change /S to /I?

What do you mean? A priori you type to change the variable type to “int” and the ’ /S to /I’ at write time.

Or can we copy data with changes?

Yes? It should be just to set the input/original/read tree as before and the output tree with the new layout and the same addresses for the size (where you have to have 2 variable one short for input, one int for output).

Probably this wasn’t clear enough. I meant to ask you if you had access to the code that writes the data to disk, and if you could share that with us.
Judging by the last few comments, this has now become sort of necessary to fix your problem.

I’ve made a request.

Also, some RDataFrame experts should confirm that it can deal with “16-bit unsigned integer” (UShort_t) variable length arrays (e.g., the “Channel0 : ch0[size]/s”). Otherwise, one would need to change them, too.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.