Unknown Type Error


Please read tips for efficient and successful posting and posting code

_ROOT Version_Not Provided
Platform: Ubuntu via WSL
Compiler: Not Provided


When I run the following code:

TFile *file = TFile::Open("https://atlas-opendata.web.cern.ch/atlas-opendata/samples/2020/1largeRjet1lep/MC/mc_361106.Zee.1largeRjet1lep.root");
TTree *baum = (TTree*) file->Get("mini");

UInt_t lepton_n = -1;
baum->SetBranchAddress("lep_n", &lepton_n);
TCanvas *canv = new TCanvas("CAnvas", "canvas", 800, 600);
TH1F *hist = new TH1F("variable","Example plot: Number of leptons; Number of leptons ; Events ",5,-0.5,4.5);
int nentries, nbytes, i;
nentries = (Int_t)baum->GetEntries();

for (i=0; i<nentries;i++){
    nbytes = baum->GetEntry(i);
    hist->Fill(lepton_n);
}


hist->SetFillColor(kRed);
hist->Draw();
canv->Draw();

I get this error:

/home/advait/main.C:5:1: error: unknown type name 'baum'                                                                baum->SetBranchAddress("lep_n", &lepton_n);                                                                             ^                                                                                                                       /home/advait/main.C:5:5: error: cannot use arrow operator on a type                                                     baum->SetBranchAddress("lep_n", &lepton_n);                                                                                 ^                                                                                                                   /home/advait/main.C:9:1: error: C++ requires a type specifier for all declarations                                      nentries = (Int_t)baum->GetEntries();                                                                                   ^                                                                                                                       /home/advait/main.C:11:1: error: expected unqualified-id                                                                for (i=0; i<nentries;i++){                                                                                              ^                                                                                                                       /home/advait/main.C:17:1: error: unknown type name 'hist'                                                               hist->SetFillColor(kRed);                                                                                               ^                                                                                                                       /home/advait/main.C:17:5: error: cannot use arrow operator on a type                                                    hist->SetFillColor(kRed);                                                                                                   ^                                                                                                                   /home/advait/main.C:18:1: error: unknown type name 'hist'                                                               hist->Draw();                                                                                                           ^                                                                                                                       /home/advait/main.C:18:5: error: cannot use arrow operator on a type                                                    hist->Draw();                                                                                                               ^                                                                                                                   /home/advait/main.C:19:1: error: unknown type name 'canv'                                                               canv->Draw();                                                                                                           ^                                                                                                                       /home/advait/main.C:19:5: error: cannot use arrow operator on a type                                                    canv->Draw();    

Which is strange. I get this error even for the simplest of things. Whats up here?

Maybe a missing;
#include "TTree.h"

1 Like

I tried that. I also forgot to wrap the whole code in a function with the files name. After doing both of these things, I still get this:

Error in <TWebFile::GetHead>: https://atlas-opendata.web.cern.ch:443/atlas-opendata/samples/2020/1largeRjet1lep/MC/mc_361106.Zee.1largeRjet1lep.root?: Service Unavailable (503)                                                                
Error in <TWebFile::GetFromWeb10>: https://atlas-opendata.web.cern.ch:443/atlas-opendata/samples/2020/1largeRjet1lep/MC/mc_361106.Zee.1largeRjet1lep.root?: Service Unavailable (503)                                                            
Generating stack trace...                                                                                               0x00007f8b44c5f08f in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44bd3965 in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44bd668d in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44cc9c19 in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44cd8945 in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44cda1f8 in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44cc2fd0 in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44ad4aec in <unknown> from /home/advait/Documents/buildroot/lib/libCling.so                                   0x00007f8b44aec5ee in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x116e from /home/advait/Documents/buildroot/lib/libCling.so                                                                                                0x00007f8b44aec98a in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0xea from /home/advait/Documents/buildroot/lib/libCling.so                                                                                             0x00007f8b494a92ea in TApplication::ExecuteFile(char const*, int*, bool) at TApplication.cxx:? from /home/advait/Documents/buildroot/lib/libCore.so                                                                                             0x00007f8b494aa2af in TApplication::ProcessLine(char const*, bool, int*) + 0xa5f from /home/advait/Documents/buildroot/lib/libCore.so                                                                                                           0x00007f8b498b51b6 in TRint::ProcessLineNr(char const*, char const*, int*) + 0x66 from /home/advait/Documents/buildroot/lib/libRint.so                                                                                                          0x00007f8b498b6abd in TRint::Run(bool) + 0x32d from /home/advait/Documents/buildroot/lib/libRint.so                     0x00007f8b49904180 in main + 0x50 from /home/advait/Documents/buildroot/bin/root.exe                                    0x00007f8b48f070b3 in __libc_start_main + 0xf3 from /lib/x86_64-linux-gnu/libc.so.6                                     0x00007f8b499041ce in _start + 0x2e from /home/advait/Documents/buildroot/bin/root.exe                                 Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.                                                                                                                  Execution of your code was aborted.                                                                                     In file included from input_line_8:1:                                                                                   /home/advait/file.C:5:28: warning: null passed to a callee that requires a non-null argument [-Wnonnull]                    TTree *baum = (TTree*) file->Get("mini"); 

“Service Unavailable (503)” suggests that the www server was “down”.

1 Like

Ah, I see. Let me check if I can solve that.

It works now! Thanks!

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