Can't plot more than 1 canvas on MacOS

Seems all of a sudden I can’t plot more than one canvas when they are constructed at the start of the script. Old scripts don’t work either. System is MacOS 10.14.6, Xcode 10.0, root 6.18.04 (and installed 6.22.06 - same result).

Here is the code:

void plot_clusters_on_midstream_plates()
  int events;
  std::vector<int> *clusters_on_midstream_plates;
  TCanvas *c1 = new TCanvas("c1", "c1", 5, 26, 1200, 815);
  TCanvas *c2 = new TCanvas("c2", "c2", 5, 26, 1200, 815);

  TH1F* h101 = new TH1F("plate_4", "plate_4", 20, 0, 20);
  // ...

  TH1F* h201 = new TH1F("cl_pl", "cl_pl", 10, 0, 10);
  TFile* in_file = new TFile("../output.root", "READ");
  //TTree* in_tree = new TTree();
  //in_tree = (TTree*) in_file->Get("ssd_tracks");
  TTree* in_tree = (TTree*) in_file->Get("ssd_tracks");
  in_tree->SetBranchAddress("clusters_on_midstream_plates", &clusters_on_midstream_plates);

  events = in_tree->GetEntries();
  cout << in_tree->GetEntries() << endl;
  for (int i = 0; i < events; i++)
    if (clusters_on_midstream_plates->size() == 5)
      // ...
      h201->AddBinContent(4, clusters_on_midstream_plates->at(0));
      // ...
      cout << "Wrong number of plates in event..." << endl;
  // ...

The error is (in 6.22.06):

*** Break *** segmentation violation

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[<unknown binary>] (no debug info)

[/Applications/root_v6.22.06/lib/] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)

[/Applications/root_v6.22.06/lib/] TBranchElement::ReadLeavesMember(TBuffer&) (no debug info)

[/Applications/root_v6.22.06/lib/] TBranch::GetEntry(long long, int) (no debug info)

[/Applications/root_v6.22.06/lib/] TBranchElement::GetEntry(long long, int) (no debug info)

[/Applications/root_v6.22.06/lib/] TTree::GetEntry(long long, int) (no debug info)

[<unknown binary>] (no debug info)

[<unknown binary>] (no debug info)

[/Applications/root_v6.22.06/lib/] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)

[/Applications/root_v6.22.06/lib/] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)

[/Applications/root_v6.22.06/lib/] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)

[/Applications/root_v6.22.06/lib/] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)

[/Applications/root_v6.22.06/lib/] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)

[/Applications/root_v6.22.06/lib/] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)

[/Applications/root_v6.22.06/lib/] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)

[/Applications/root_v6.22.06/lib/] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)

[/Applications/root_v6.22.06/lib/] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)

[/Applications/root_v6.22.06/lib/] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)

[/Applications/root_v6.22.06/lib/] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)

[/Applications/root_v6.22.06/lib/] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)

[/Applications/root_v6.22.06/lib/] TRint::HandleTermInput() (no debug info)

[/Applications/root_v6.22.06/lib/] TUnixSystem::CheckDescriptors() (no debug info)

[/Applications/root_v6.22.06/lib/] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)

[/Applications/root_v6.22.06/lib/] TSystem::InnerLoop() (no debug info)

[/Applications/root_v6.22.06/lib/] TSystem::Run() (no debug info)

[/Applications/root_v6.22.06/lib/] TApplication::Run(bool) (no debug info)

[/Applications/root_v6.22.06/lib/] TRint::Run(bool) (no debug info)

[/Applications/root_v6.22.06/bin/root.exe] main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

When I move the construction of c2 right before c2->cd() it works. Either canvas works separately if I comment the other one.

Can you post a macro we can run ?
Looking at the code snippet you sent it seems ok.

Here they are.

plot_clusters_on_midstream_plates.C (2.1 KB) output.root (40.0 KB)

Sorry that was the one that works. This doesn’t:

plot_clusters_on_midstream_plates.C (2.1 KB)

Can you share the output of in_tree->GetBranch("clusters_on_midstream_plates")->Print()? Sorry - you’ve attached the file, perfect! Looking…

Here’s the solution:
std::vector<int> *clusters_on_midstream_plates = nullptr;

If the pointer is non-null, ROOT has to assume that it points to something previously set (e.g. by a previous event), and it will delete the object pointed to. If the pointer is just uninitialized then that will crash.

See the doc of TTree::SetNranchAddress which forwards to the doc of TBranchElement::SetAddress where we try to explain the pointer null / pointee null rules.

I understand now.

Thank you!

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