TTreader Error

Hi

I have segmentation violation Error When I use TTreader array from two different ROOT files.

TFile* f = new TFile("SFtest0525_5degree_1K.edm4hep.root");
    f->cd();

    //TTree* t = (TTree*)f->Get("events");
    TTreeReader myReader("events", f);                     // name of tree and file

    TTreeReaderArray<Float_t> energy(myReader, "LumiDirectPCALHits.energy");
    TTreeReaderArray<Float_t> x(myReader, "LumiDirectPCALHits.position.x");
    TTreeReaderArray<Float_t> y(myReader, "LumiDirectPCALHits.position.y");
    
    
     // Rootfile and Tree
    TFile* f1 = new TFile("SFtest0525_5rad_1K.edm4hep.root");
    f1->cd();
    TTreeReader myReader1("events", f1); 
    TTreeReaderArray<Float_t> z(myReader1, "LumiDirectPCALHits.position.z");

yasir@yasir-X270:~/Downloads/Analysis/fiber_CAL$ root crystal_dep.C -l
root [0] 
Processing crystal_dep.C...
Warning in <TClass::Init>: no dictionary for class podio::GenericParameters is available
Warning in <TClass::Init>: no dictionary for class edm4hep::MCParticleData is available
Warning in <TClass::Init>: no dictionary for class edm4hep::Vector3d is available
Warning in <TClass::Init>: no dictionary for class edm4hep::Vector3f is available
Warning in <TClass::Init>: no dictionary for class edm4hep::Vector2i is available
Warning in <TClass::Init>: no dictionary for class podio::ObjectID is available
Warning in <TClass::Init>: no dictionary for class edm4hep::EventHeaderData is available
Warning in <TClass::Init>: no dictionary for class edm4hep::SimTrackerHitData is available
Warning in <TClass::Init>: no dictionary for class edm4hep::SimCalorimeterHitData is available
Warning in <TClass::Init>: no dictionary for class edm4hep::CaloHitContributionData is available
Warning in <TClass::Init>: no dictionary for class podio::CollectionIDTable is available
Warning in <TClass::Init>: no dictionary for class podio::version::Version is available
Warning in <TClass::Init>: no dictionary for class pair<int,podio::GenericParameters> is available
Event: 1

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f61782ea45a in __GI___wait4 (pid=9724, stat_loc=stat_loc
entry=0x7ffcdb8e8fd8, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007f61782ea41b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffcdb8e8fd8, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007f6178250bcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3  0x00007f6178d168a4 in TUnixSystem::StackTrace() () from /home/yasir/Downloads/root/lib/libCore.so.6.26
#4  0x00007f6178d13bb5 in TUnixSystem::DispatchSignals(ESignals) () from /home/yasir/Downloads/root/lib/libCore.so.6.26
#5  <signal handler called>
#6  0x00007f6178835a1f in ?? ()
#7  0x00007ffcdb8ebe48 in ?? ()
#8  0x00007f6178836890 in ?? ()
#9  0x0000000000000000 in ?? ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi @Yasir_Ali ,

Warnings like these one might then result in the segfault you are experiencing. Are you sure you are loading all the libraries needed for your application? Even so, you still need to generate the dictionaries for the classes of the content of your dataset (find more info at I/O of custom classes - ROOT).

Please provide a small, self-contained reproducer, the ROOT version, platform and compiler version you are using.

Cheers,
Vincenzo

@vpadulan The “no dictionary for class” warnings are harmless in this case (i.e., the problem is somewhere else).

@Yasir_Ali Attach your full macro for inspection.

No these warnings are not creating problem Code runs with these warning and if I use one TTreader but when i try to read separate histogram using seperate TTreader

It works When i have

TFile* f = new TFile(“SFtest0525_5degree_1K.edm4hep.root”);
f->cd();

//TTree* t = (TTree*)f->Get("events");
TTreeReader myReader("events", f);                     // name of tree and file

TTreeReaderArray<Float_t> energy(myReader, "LumiDirectPCALHits.energy");
TTreeReaderArray<Float_t> x(myReader, "LumiDirectPCALHits.position.x");
TTreeReaderArray<Float_t> y(myReader, "LumiDirectPCALHits.position.y");
TTreeReaderArray<Float_t> z(myReader, "LumiDirectPCALHits.position.z");

Please see the following Macro:


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <stdlib.h>

#include "TROOT.h"
#include "TTree.h"
#include "TChain.h"
#include "TFile.h"
#include "TString.h"
#include "TSystem.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TColor.h"
#include "Riostream.h"
#include "TDatime.h"
#include "TMath.h"
#include "TStyle.h"
#include "TLorentzVector.h"

#include <TTreeReader.h>
#include <TTreeReaderValue.h>
#include <TTreeReaderArray.h>


stringstream ss;

void crystal_dep()
{
    // *************************************************************************
    // Rootfile and Tree
    TFile* f = new TFile("Qtest0525_5rad_1K.edm4hep.root");
    f->cd();

    //TTree* t = (TTree*)f->Get("events");
    TTreeReader myReader("events", f);                     // name of tree and file

    TTreeReaderArray<Float_t> energy(myReader, "LumiDirectPCALHits.energy");
    TTreeReaderArray<Float_t> x(myReader, "LumiDirectPCALHits.position.x");
    TTreeReaderArray<Float_t> y(myReader, "LumiDirectPCALHits.position.y");
    TTreeReaderArray<Float_t> z(myReader, "LumiDirectPCALHits.position.z");
    
     // Rootfile and Tree
    TFile* f1 = new TFile("SFtest0525_5rad_1K.edm4hep.root");
    f1->cd();
   TTreeReader myReader1("events", f1); 
   TTreeReaderArray<Float_t> z(myReader1, "LumiDirectPCALHits.position.z");
    
    
     const int ngraph = 7; 
 TCanvas * c[ngraph]; 
 for (int i =0; i<ngraph; ++i){
 c[i] = new TCanvas(Form("c%d",i),Form("c%d",i),1200,1000);
 c[i]->SetMargin(0.09, 0.1 ,0.1,0.06);
 }
 
 
    // Rootfile and Tree
    // *************************************************************************
    // *************************************************************************
    // Histograms
    map<string,TH3*> h3;

    float xmin = -50;
    float xmax = 50;
    int nx = 100;
    float ymin = -10;
    float ymax = 40;
    int ny = 50;
    float zmin = 66150;
    float zmax = 66350;
    int nz = 200;

    h3["energy"] = new TH3F("energy", "Total Energy Deposit;x;y;z", nx, xmin, xmax, ny, ymin, ymax, nz, 0, zmax - zmin);

   // TRandom3 *rndm = new TRandom3();
    int nev = 0;
    vector<int> nphoton;
    float xxx = 0;
    float yyy = 0;
    float zzz = 0;
    float emax = 0;
    double binx= 0;
    double biny= 0;
    double binz= 0;
    while (myReader.Next())
    {
        nev++;
        cout << "Event: " << nev << endl;
        nphoton.push_back(0);
        float tot_e = 0;

        for (int i = 0; i < energy.GetSize(); i++)
        {
            nphoton.back()++;
            tot_e += energy[i];
            h3["energy"]->Fill(x[i],y[i],abs(z[i]) - zmin,energy[i]);
            //h3["energy"]->Fill(x[i]+rndm->Gaus(0,1) ,y[i] + rndm->Gaus(0,1) , abs(z[i]) - zmin,energy[i] );
            xxx = max(abs(x[i]), xxx);
            yyy = max(abs(y[i]), yyy);
            zzz = max(abs(z[i]), zzz);
             
   
        }
    }

    cout << "Max-X: " << xxx << endl;
    cout << "Max-Y: " << yyy << endl;
    cout << "Max-Z: " << zzz << endl;
    //cout << "Energy: " << energy << "GeV" <<endl;
    // Fill Histograms
    // *************************************************************************

    // *************************************************************************
    // Draw Histograms
    for (map<string,TH3*>::const_iterator itr = h3.begin(); itr != h3.end(); itr++)
    {
        //gStyle->SetOptStat(0);

        string hname = itr->first;
        TH3* h = (TH3*)itr->second->Clone();
        h->Scale(1.0/float(h->Integral()));

       
        TH2* h2yx = (TH2*)h->Project3D("yx")->Clone();
        TH2* h2zx = (TH2*)h->Project3D("zx")->Clone();
        TH2* h2zy = (TH2*)h->Project3D("zy")->Clone();
        TH1* h1x = (TH2*)h->Project3D("x")->Clone();
        TH1* h1y = (TH2*)h->Project3D("y")->Clone();
        TH1* h1z = (TH2*)h->Project3D("z")->Clone();
        TH1* h1E = (TH2*)h->Project3D("energy")->Clone();
        TH3* h3xyz = (TH3*)h->Project3D("xyz")->Clone();
        
        c[0]->cd();
        h2yx->GetXaxis()->SetTitle("x (mm)");
        h2yx->GetYaxis()->SetTitle("y (mm)");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        h2yx->Draw("colz");
        cout << "Bin Max XY:" << h2yx->GetMaximumBin() <<endl;
        cout << "Energy XY" << h2yx->GetMaximum() <<endl;
        
        //ss.str(""); ss << "test2D_yx_" << hname << ".png";
        //c->SaveAs(TString(ss.str()));
        
        c[1]->cd();
        h2zx->GetXaxis()->SetTitle("x (mm)");
        h2zx->GetYaxis()->SetTitle("z (mm)");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        h2zx->Draw("colz");
      
        c[2]->cd();
        h2zy->GetXaxis()->SetTitle("y (mm)");
        h2zy->GetYaxis()->SetTitle("z (mm)");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        h2zy->Draw("colz");
        
        c[3]->cd();
        h1x->GetXaxis()->SetTitle("x (mm)");
        gPad->SetLogx(0); gPad->SetLogy(1); gPad->SetLogz(0);
        h1x->Draw("colz");
      
        c[4]->cd();
        h1y->GetXaxis()->SetTitle("y (mm)");
        gPad->SetLogx(0); gPad->SetLogy(1); gPad->SetLogz(0);
        h1y->Draw("colz");
       
        c[5]->cd();
        h1z->Draw("colz");
        h1z->GetXaxis()->SetTitle("z (mm)");
        h1z->GetXaxis()->SetRangeUser(0., 200);
        h1z->SetTitle("Energy distribution");
        h1z->GetYaxis()->SetTitle("E (GeV)");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
      
       
         c[6]->cd();
        h3xyz->Draw("LEGO2");
        h3xyz->SetTitle("");
        h3xyz->GetXaxis()->SetTitle("X (mm)");
        h3xyz->GetYaxis()->SetTitle("Y (mm)");
        h3xyz->GetZaxis()->SetTitle("Z (mm)");
        
       
        //h1z->GetXaxis()->SetRangeUser(0., 200);
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        

       // c->Close();

    }
    // Draw Histograms
    // *************************************************************************


}

while (myReader.Next() && myReader1.Next())

BTW. Your code assumes that the length of “z[]” is always the same as that of “energy[]” (and “x[]” and “y[]”).

Sorry even after changing while (myReader.Next() && myReader1.Next()) It crashes after 3 Events

root [0]
Processing crystal_dep.C…
Warning in TClass::Init: no dictionary for class podio::GenericParameters is available
Warning in TClass::Init: no dictionary for class edm4hep::MCParticleData is available
Warning in TClass::Init: no dictionary for class edm4hep::Vector3d is available
Warning in TClass::Init: no dictionary for class edm4hep::Vector3f is available
Warning in TClass::Init: no dictionary for class edm4hep::Vector2i is available
Warning in TClass::Init: no dictionary for class podio::ObjectID is available
Warning in TClass::Init: no dictionary for class edm4hep::EventHeaderData is available
Warning in TClass::Init: no dictionary for class edm4hep::SimTrackerHitData is available
Warning in TClass::Init: no dictionary for class edm4hep::SimCalorimeterHitData is available
Warning in TClass::Init: no dictionary for class edm4hep::CaloHitContributionData is available
Warning in TClass::Init: no dictionary for class podio::CollectionIDTable is available
Warning in TClass::Init: no dictionary for class podio::version::Version is available
Warning in TClass::Init: no dictionary for class pair<int,podio::GenericParameters> is available
Event: 1
Event: 2
Event: 3

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x00007ff2b8cea45a in __GI___wait4 (pid=17848, stat_loc=stat_loc
entry=0x7ffc6292c998, options=options
entry=0, usage=usage
entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007ff2b8cea41b in __GI___waitpid (pid=, stat_loc=stat_loc
entry=0x7ffc6292c998, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007ff2b8c50bcb in do_system (line=) at …/sysdeps/posix/system.c:171
#3 0x00007ff2b97168a4 in TUnixSystem::StackTrace() () from /home/yasir/Downloads/root/lib/libCore.so.6.26
#4 0x00007ff2b9713bb5 in TUnixSystem::DispatchSignals(ESignals) () from /home/yasir/Downloads/root/lib/libCore.so.6.26
#5
#6 0x00007ff2b99cab74 in ?? ()
#7 0x0000000000000150 in ?? ()
#8 0x00007ff2b4cc0920 in ?? () from /home/yasir/Downloads/root/lib/libCling.so
#9 0x00007ffc6292ff40 in ?? ()
#10 0x0000560ff5d95990 in ?? ()
#11 0x00007ffc6292ff40 in ?? ()
#12 0x0001010000000001 in ?? ()
#13 0x0000000000000032 in ?? ()
#14 0x00007ff2b765f2bd in llvm::MCAsmLayout::getFragmentOffset(llvm::MCFragment const*) const () from /home/yasir/Downloads/root/lib/libCling.so
#15 0x00007ff2b762f3a2 in llvm::MCAssembler::computeFragmentSize(llvm::MCAsmLayout const&, llvm::MCFragment const&) const () from /home/yasir/Downloads/root/lib/libCling.so
#16 0x0000000200000003 in ?? ()
#17 0x00000000c7813300 in ?? ()
#18 0x3db851ec3d75c28f in ?? ()
#19 0x000004b0000003e8 in ?? ()
#20 0x00007ffc6292f818 in ?? ()
#21 0x0000000000000006 in ?? ()
#22 0x0000796772656e65 in ?? ()
#23 0x0000000000000000 in ?? ()

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum ROOT Forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at Sign in to GitHub · GitHub Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#6 0x00007ff2b99cab74 in ?? ()
#7 0x0000000000000150 in ?? ()
#8 0x00007ff2b4cc0920 in ?? () from /home/yasir/Downloads/root/lib/libCling.so
#9 0x00007ffc6292ff40 in ?? ()
#10 0x0000560ff5d95990 in ?? ()
#11 0x00007ffc6292ff40 in ?? ()
#12 0x0001010000000001 in ?? ()
#13 0x0000000000000032 in ?? ()
#14 0x00007ff2b765f2bd in llvm::MCAsmLayout::getFragmentOffset(llvm::MCFragment const*) const () from /home/yasir/Downloads/root/lib/libCling.so
#15 0x00007ff2b762f3a2 in llvm::MCAssembler::computeFragmentSize(llvm::MCAsmLayout const&, llvm::MCFragment const&) const () from /home/yasir/Downloads/root/lib/libCling.so
#16 0x0000000200000003 in ?? ()
#17 0x00000000c7813300 in ?? ()
#18 0x3db851ec3d75c28f in ?? ()
#19 0x000004b0000003e8 in ?? ()
#20 0x00007ffc6292f818 in ?? ()
#21 0x0000000000000006 in ?? ()
#22 0x0000796772656e65 in ?? ()
#23 0x0000000000000000 in ?? ()

Root >

Instead of “z[i]”, try “z.At(i)”.

Well, I suspect the “assumption” is not fulfilled:

It means need to change something

h3[“energy”]->Fill(x[i],y[i],abs(z.At[i] - zmin,energy[i]);

Processing crystal_dep.C…
In file included from input_line_8:1:
/home/yasir/Downloads/Analysis/fiber_CAL/crystal_dep.C:104:42: error: no matching function for call to ‘abs’
h3[“energy”]->Fill(x[i],y[i],abs(z.At(i) - zmin,energy[i]);
^~~
/usr/include/c++/11/complex:626:5: note: candidate function template not viable: requires single argument ‘__z’, but 2 arguments were provided
abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
^
/usr/include/c++/11/bits/valarray_after.h:445:33: note: candidate function template not viable: requires single argument ‘__e’, but 2 arguments were provided
_DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
^
/usr/include/c++/11/bits/valarray_after.h:445:33: note: candidate function template not viable: requires single argument ‘__v’, but 2 arguments were provided
/home/yasir/Downloads/root/include/Vc/scalar/…/common/…/sse/vector.h:448:52: note: candidate function not viable: requires single argument ‘x’, but 2 arguments were provided
Vc_ALWAYS_INLINE Vc_PURE Vector<T, VectorAbi::Sse> abs(Vector<T, VectorAbi::Sse> x)
^
/home/yasir/Downloads/root/include/Vc/common/simdarray.h:1806:27: note: candidate function not viable: requires single argument ‘x’, but 2 arguments were provided
Vc_FORWARD_UNARY_OPERATOR(abs);
^
/home/yasir/Downloads/root/include/Vc/common/simdarray.h:1806:27: note: candidate function not viable: requires single argument ‘x’, but 2 arguments were provided
/home/yasir/Downloads/root/include/Vc/scalar/math.h:88:44: note: candidate function not viable: requires single argument ‘x’, but 2 arguments were provided
Vc_ALWAYS_INLINE Vc_PURE Scalar::Vector abs(Scalar::Vector x)
^
/usr/include/stdlib.h:848:12: note: candidate function not viable: requires single argument ‘__x’, but 2 arguments were provided
extern int abs (int __x) __THROW attribute ((const)) __wur;
^
/usr/include/c++/11/bits/std_abs.h:79:3: note: candidate function not viable: requires single argument ‘__x’, but 2 arguments were provided
abs(long double __x)
^
/usr/include/c++/11/bits/std_abs.h:56:3: note: candidate function not viable: requires single argument ‘__i’, but 2 arguments were provided
abs(long __i) { return __builtin_labs(__i); }
^
/usr/include/c++/11/bits/std_abs.h:61:3: note: candidate function not viable: requires single argument ‘__x’, but 2 arguments were provided
abs(long long __x) { return __builtin_llabs (__x); }
^
/usr/include/c++/11/bits/std_abs.h:71:3: note: candidate function not viable: requires single argument ‘__x’, but 2 arguments were provided
abs(double __x)
^
/usr/include/c++/11/bits/std_abs.h:75:3: note: candidate function not viable: requires single argument ‘__x’, but 2 arguments were provided
abs(float __x)
^
/home/yasir/Downloads/root/include/Vc/scalar/math.h:93:48: note: candidate function not viable: requires single argument ‘x’, but 2 arguments were provided
Vc_ALWAYS_INLINE Vc_PURE Scalar::Vector abs(Scalar::Vector x)
^
<<< cling interactive line includer >>>:1:1: error: expected ‘}’
/home/yasir/Downloads/Analysis/fiber_CAL/crystal_dep.C:36:1: note: to match this ‘{’

Regrettably, it seems that no bounds checking is performed by the “At” method so that you can forget it.

You will need to use other methods to make sure that the “z[i]” is valid (for every tree entry).

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