How to skip/fix LZMA Error?

Dear all,

We processed input information and saved output root files. We can also see that the total number of entries is identical in the input and output root files, that should be the case if our code is processed successfully.

For some of the output files, when we try to read them for several events inside the root file shows the following messages:

R__unzipLZMA: error 9 in lzma_code
Error in <TBasket::ReadBasketBuffers>: fNbytes = 2362, fKeylen = 89, fObjlen = 17140, noutot = 0, nout=0, nin=2273, nbuf=17140

I can read the entries even for these events. Also, I can skim and save to root file using pyROOT.[1].

Problem: We are trying to read it using uproot, there we get an issue while saving to the .parquet file [2], it shows an error given below [3].

Question:

  1. Is there any workaround using which we can avoid this error while working with uproot?
  2. What is the cause of this issue in our output ROOT files? I mean why it is there in the file that I created?

[1]

inFile = "root://eos.cms.rcac.purdue.edu:1094//store/user/rasharma/customNanoAOD_Others/UL2018/TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/04005D2F-8BFF-8B43-BA27-4D78C5CBE179_NanoAOD.root"
file = ROOT.TFile.Open(inFile)
tree = file.Get("Events")
output_file = TFile.Open("out.root", "RECREATE")
skimmed_tree = tree.CloneTree()
skimmed_tree = tree.CopyTree("nMuon >= 2 && Muon_pt[0] > 20 && Muon_pt[1] > 20")
output_file.WriteObject(skimmed_tree, "physics")
output_file.Close()

[2]

import ROOT
import pandas as pd

inFile = "root://eos.cms.rcac.purdue.edu:1094//store/user/rasharma/customNanoAOD_Others/UL2018/TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/04005D2F-8BFF-8B43-BA27-4D78C5CBE179_NanoAOD.root"
file = ROOT.TFile.Open(inFile)

tree = file.Get("Events")
print(tree.GetEntries())
nMuons = []
muon_pt = []
muon_eta = []
muon_phi = []
nentres = tree.GetEntries()
nentres = 20505
for i in range(nentres):
    if i < 20500: continue
    print(f"=====> Processing entry {i} <=====")
    tree.GetEntry(i)
    nMuons.append(tree.nMuon)
    muon_pt.append(tree.Muon_pt)
    muon_eta.append(tree.Muon_eta)

df = pd.DataFrame({
    "nMuons": nMuons,
    "Muon_pt": muon_pt,
    "Muon_eta": muon_eta,
})

print(df.head())

df.to_parquet("test.parquet")

[3]

   nMuons                                   Muon_pt                                    Muon_eta
0       2  [39.771934509277344, 14.352097511291504]  [-0.8841629028320312, -0.5072555541992188]
1       1                      [39.771934509277344]                       [-0.8841629028320312]
2       2  [39.771934509277344, 14.352097511291504]  [-0.8841629028320312, -0.5072555541992188]
3       1                      [39.771934509277344]                       [-0.8841629028320312]
4       1                      [39.771934509277344]                       [-0.8841629028320312]
Traceback (most recent call last):
  File "/depot/cms/private/users/shar1172/copperheadV2/scripts/test_LZMAError_UseUproot.py", line 47, in <module>
    df.to_parquet("test.parquet")
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pandas/util/_decorators.py", line 333, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pandas/core/frame.py", line 3113, in to_parquet
    return to_parquet(
           ^^^^^^^^^^^
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pandas/io/parquet.py", line 480, in to_parquet
    impl.write(
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pandas/io/parquet.py", line 190, in write
    table = self.api.Table.from_pandas(df, **from_pandas_kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyarrow/table.pxi", line 4623, in pyarrow.lib.Table.from_pandas
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pyarrow/pandas_compat.py", line 616, in dataframe_to_arrays
    arrays = [convert_column(c, f)
              ^^^^^^^^^^^^^^^^^^^^
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pyarrow/pandas_compat.py", line 603, in convert_column
    raise e
  File "/depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/pyarrow/pandas_compat.py", line 597, in convert_column
    result = pa.array(col, type=type_, from_pandas=True, safe=safe)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyarrow/array.pxi", line 358, in pyarrow.lib.array
  File "pyarrow/array.pxi", line 85, in pyarrow.lib._ndarray_to_array
  File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: ('Could not convert <cppyy.LowLevelView object at 0x7f357c110cb0> with type cppyy.LowLevelView: did not recognize Python value type when inferring an Arrow data type', 'Conversion failed for column Muon_pt with type object')

ROOT Version: 6.26/11
Platform: LXPLUS (CERN)
Container: el8_amd64_gcc11
CMSSW: CMSSW_13_0_14


To confirm, do you see any error message when using ROOT/pyROOT or just with uproot?

yes, I saw the message (same as shown in the original post). I am pasting it again here:

R__unzipLZMA: error 9 in lzma_code
Error in <TBasket::ReadBasketBuffers>: fNbytes = 17956, fKeylen = 79, fObjlen = 45452, noutot = 0, nout=0, nin=17877, nbuf=45452
Error in <TBranch::GetBasket>: File: root://eos.cms.rcac.purdue.edu//store/user/rasharma/customNanoAOD_Others/UL2018/TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/04005D2F-8BFF-8B43-BA27-4D78C5CBE179_NanoAOD.root at byte:60014167, branch:SV_dlenSig, entry:20502, badread=1, nerrors=1, basketnumber=7

Also, I tried to skim the tree and write another tree using pyROOT and it worked.

Just that I am unable to save it to the parquet file.

Also, I am wondering why I get the error while saving to the parquet format, especially with the code patch that I added in my original post. As I read the input tree save to arrays then add them to the pandas dataframe. Now they should be just arrays so saving them to parquet should not be the issue. No?

Furthermore, one additional input. I also tried to read using RDF using code [1] and it also threw the error [2], not being able to read the input file. This issue is with particular events. So, if I read up to entries 1575 (below code[1]), I don’t see any error. As soon as I try to read entry 1576 it shows me the error.

I hope you can access the root file. If not, let me know I can share them using gDrive.

Thank you for your help.

[1]

import ROOT

inFile = "root://eos.cms.rcac.purdue.edu:1094//store/user/rasharma/customNanoAOD_Others/UL2018/TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/04005D2F-8BFF-8B43-BA27-4D78C5CBE179_NanoAOD.root"
df = ROOT.RDataFrame("Events", inFile)

df = df.Filter('nMuon == 2')\
       .Filter('Muon_charge[0] != Muon_charge[1]')\
       .Define('Dimuon_mass', 'InvariantMass(Muon_pt, Muon_eta, Muon_phi, Muon_mass)')\
       .Filter('Dimuon_mass > 70')\
       .Range(1576)

print('\nApproximate mass of the Z boson: {:.2f} GeV\n'.format(
    df.Mean('Dimuon_mass').GetValue()))

df.Describe().Print(shortFormat=True)
print("\n\n")

[2]

(/depot/cms/kernels/coffea_latest) [shar1172@purdue-af-182 scripts]$ python test_LZMAError_RDF.py 
TClass::Init:0: RuntimeWarning: no dictionary for class edm::Hash<1> is available
TClass::Init:0: RuntimeWarning: no dictionary for class edm::ProcessHistory is available
TClass::Init:0: RuntimeWarning: no dictionary for class edm::ProcessConfiguration is available
TClass::Init:0: RuntimeWarning: no dictionary for class edm::ParameterSetBlob is available
TClass::Init:0: RuntimeWarning: no dictionary for class pair<edm::Hash<1>,edm::ParameterSetBlob> is available
R__unzipLZMA: error 9 in lzma_code
Error in <TBasket::ReadBasketBuffers>: fNbytes = 14082, fKeylen = 77, fObjlen = 30236, noutot = 0, nout=0, nin=14005, nbuf=30236
Error in <TBranch::GetBasket>: File: root://eos.cms.rcac.purdue.edu//store/user/rasharma/customNanoAOD_Others/UL2018/TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/04005D2F-8BFF-8B43-BA27-4D78C5CBE179_NanoAOD.root at byte:88103710, branch:Muon_eta, entry:34174, badread=1, nerrors=1, basketnumber=20
 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f05778577da in <unknown function>
 0x00007f0577857690 in <unknown function>
 0x00007f0578c09034 in <unknown> from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f057785e054 in <unknown function>
 0x00007f057785df23 in <unknown function>
 0x00007f056d0bff76 in <unknown function>
 0x00007f05779acf60 in <unknown function>
 0x00007f0578c7e15a in ROOT::Detail::RDF::RLoopManager::RunAndCheckFilters(unsigned int, long long) + 0xba from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f0578c8fc95 in ROOT::Detail::RDF::RLoopManager::RunTreeReader() + 0x125 from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f0578c907b6 in ROOT::Detail::RDF::RLoopManager::Run(bool) + 0x976 from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f05779bc165 in <unknown function>
 0x00007f05779bc018 in <unknown function>
 0x00007f0599dbdbd0 in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/lib-dynload/../../libcppyy_backend.so
 0x00007f0599dbefd0 in Cppyy::CallR(long, void*, unsigned long, void*) + 0x30 from /depot/cms/kernels/coffea_latest/lib/python3.12/lib-dynload/../../libcppyy_backend.so
 0x00007f0579a53e33 in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a33d0a in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a34076 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) + 0x56 from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a341b6 in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) + 0x116 from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a3ca38 in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x000056275e6da55e in PyObject_Vectorcall + 0x2e from python
 0x000056275e5d37e4 in <unknown> from python
 0x000056275e77c341 in PyEval_EvalCode + 0xa1 from python
 0x000056275e7a09ba in <unknown> from python
 0x000056275e79b9c5 in <unknown> from python
 0x000056275e7b42d0 in <unknown> from python
 0x000056275e7b394e in _PyRun_SimpleFileObject + 0x1ce from python
 0x000056275e7b3614 in _PyRun_AnyFileObject + 0x44 from python
 0x000056275e7ac89e in Py_RunMain + 0x2fe from python
 0x000056275e766477 in Py_BytesMain + 0x37 from python
 0x00007f059a6e47e5 in __libc_start_main + 0xe5 from /lib64/libc.so.6
 0x000056275e766321 in <unknown> from python
 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f05778577da in <unknown function>
 0x00007f0577857690 in <unknown function>
 0x00007f0578c09034 in <unknown> from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f057785e054 in <unknown function>
 0x00007f057785df23 in <unknown function>
 0x00007f056d0bff76 in <unknown function>
 0x00007f05779acf60 in <unknown function>
 0x00007f0578c7e15a in ROOT::Detail::RDF::RLoopManager::RunAndCheckFilters(unsigned int, long long) + 0xba from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f0578c8fc95 in ROOT::Detail::RDF::RLoopManager::RunTreeReader() + 0x125 from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f0578c907b6 in ROOT::Detail::RDF::RLoopManager::Run(bool) + 0x976 from /depot/cms/kernels/coffea_latest/lib/libROOTDataFrame.so.6.32.02
 0x00007f05779bc165 in <unknown function>
 0x00007f05779bc018 in <unknown function>
 0x00007f0599dbdbd0 in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/lib-dynload/../../libcppyy_backend.so
 0x00007f0599dbefd0 in Cppyy::CallR(long, void*, unsigned long, void*) + 0x30 from /depot/cms/kernels/coffea_latest/lib/python3.12/lib-dynload/../../libcppyy_backend.so
 0x00007f0579a53e33 in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a33d0a in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a34076 in CPyCppyy::CPPMethod::Execute(void*, long, CPyCppyy::CallContext*) + 0x56 from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a341b6 in CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object* const*, unsigned long, _object*, CPyCppyy::CallContext*) + 0x116 from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x00007f0579a3ca38 in <unknown> from /depot/cms/kernels/coffea_latest/lib/python3.12/site-packages/libcppyy.so
 0x000056275e6da55e in PyObject_Vectorcall + 0x2e from python
 0x000056275e5d37e4 in <unknown> from python
 0x000056275e77c341 in PyEval_EvalCode + 0xa1 from python
 0x000056275e7a09ba in <unknown> from python
 0x000056275e79b9c5 in <unknown> from python
 0x000056275e7b42d0 in <unknown> from python
 0x000056275e7b394e in _PyRun_SimpleFileObject + 0x1ce from python
 0x000056275e7b3614 in _PyRun_AnyFileObject + 0x44 from python
 0x000056275e7ac89e in Py_RunMain + 0x2fe from python
 0x000056275e766477 in Py_BytesMain + 0x37 from python
 0x00007f059a6e47e5 in __libc_start_main + 0xe5 from /lib64/libc.so.6
 0x000056275e766321 in <unknown> from python

If you see message like:

R__unzipLZMA: error 9 in lzma_code
Error in <TBasket::ReadBasketBuffers>: fNbytes = 17956, fKeylen = 79, fObjlen = 45452, noutot = 0, nout=0, nin=17877, nbuf=45452
Error in <TBranch::GetBasket>: File: root://eos.cms.rcac.purdue.edu//store/user/rasharma/customNanoAOD_Others/UL2018/TTTo2L2Nu_TuneCP5_13TeV-powheg-pythia8/04005D2F-8BFF-8B43-BA27-4D78C5CBE179_NanoAOD.root at byte:60014167, branch:SV_dlenSig, entry:20502, badread=1, nerrors=1, basketnumber=7

in ROOT, it indicates that there is something wrong with the file. As you noticed the problem seems to be limited to a single basket (or so) and thus would affect a single range of entries (starting at entry 20502) for a single branch (named SV_dlenSig). Not ready that branch (or that range) would solve the problem.

When this message, the data corresponding to that branch and entry range is “lost” and even if a copy appear to succeed the information recorded for that branch and entry range will nonsensical (but all the other data for al the other branches will be fine).

To figure out what the problem with the file is required to be able to reproduce it, i.e. rerun the writing program:

  • If it is possible and the problem goes away, the issue is a hardware induced corruption
  • If it is possible and the problem is still there, the issue is an issue with the writing program that needs to be fixed.
  • If it is not possible to rewrite the file then we are left with assuming it is a hardware induced corruption
    example of hardware induced corruption:
  • random bit flip in memory
  • random bit flip in the disk
  • unaccessible block/part of the disk
  • etc.

Dear @pcanal ,

Thank you very much for your detailed response.

I can recover (at least some of them) them. So, it should be the hardware-induced corruption as per your explanation.

I guess that this problem is induced due to reading from a remote storage area (EOS) when it has an interrupted connection over the network. Do you think it could be the issue?

I have one further question. When I loop over the events then it only prints the LZMA error for several events. So, do you think that I can catch this issue and skip only the affected entries instead of skipping the full root file? I tried to use the try-and-catch block but looks like it’s not working.

this problem is induced due to reading from a remote storage area (EOS) when it has an interrupted connection over the network. Do you think it could be the issue?

Indeed, that could be a very good reason. You may want to report the issue to the EOS support group.

tried to use the try-and-catch block but looks like it’s not working.

Unfortunately the code infrastructure in TTree predates the practical availability of exception and does not throw exception in case of failure. To get better error handling you may want to switch to using RNTuple as soon as it v6.36.00 is releases (in a few weeks).

1 Like

Dear @pcanal ,

Thank you very much for your help and detailed information.

To tag the files, I just write a simple C macro to read any branch from the tree. Then, it prints the message with the word “lzma.” I run it using a Python script to run over all files, and based on log messages (having the word “lzma”) recorded by the Python subprocess, I tag the files as corrupt.

Later when RNTuple is available, I would be happy to try. Thanks.