**Break** segmentation violation

Hi everyone,
I stuck while compiling the code it shows an error(attachment) of “Break segmentation violation”.
Please suggest to me how should I resolve this error?

I See the error is in TUnixSystem.cxx. I also see you are trying to compile a quite old version (6.14). Can you tell us on which machine you are trying this installation ?

Hi @priyankaboora ,
does this happen when compiling ROOT or compiling/running your own code based on ROOT?

In case it’s the former, note that you don’t have to compile ROOT from source, there are several ways in which you can install ROOT much more quickly, see Installing ROOT - ROOT .

Cheers,
Enrico

Hi,
This is happening when I am running my own code based on ROOT. For this what should I do?

Actually, ROOT is installed. I am facing this error when running the code.

The most likely explanation is that a bug in your code is causing the crash. In particular there seems to be a bad “branchname” parameter being passed to TTree::FindBranch.

Standard C++ debugging techniques apply: you can compile your code with the -g compilation flag to get debug symbols, so the stacktrace will tell you exactly at what line in main the crash happens. And then you can run your code through a debugger, e.g. gdb, to inspect exactly what’s going on.

I also suggest to use the -Wall -Wextra -Wpedantic compile options to turn on many useful compiler warnings, that sometimes warn about potential bugs.

Cheers,
Enrico

But the same code works finely on my laptop but shows this above error in work station.

Some categories of C++ bugs can have that behavior (typically because you are in undefined behavior territory so different compilers (or the same compiler with different flags) might generate code that behaves very differently. This is the case e.g. if you use an object after it has been deleted.

Anyway, the simplest way to know is compiling the code with debug symbols and running gdb on it.

Cheers,
Enrico

Hi everyone, I’m having a similar issue with *** Break *** segmentation violation. I’m trying to compile a relatively simple macro I wrote. I will share my code below. The code works fine for 10k entries, but when I try to increase to 100k entries, I see this segmentation violation. I have tried running with gdb to catch errors and I have shared that output below. It doesn’t seem to be a memory issue because I still have space on this machine, and running the top command shows that there is available memory. Does anyone have any ideas for what could be going on? Any suggestions or advice is very appreciated.

Thank you,
Anna H

Event 8107 already in event vector 

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f9b8745f60c in waitpid () from /lib64/libc.so.6
#1  0x00007f9b873dcf62 in do_system () from /lib64/libc.so.6
#2  0x00007f9b88570ab3 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x1b79570) at /scratch/workspace/canvas-products-all/vedge-/SLF7/e20-prof/build/root/v6_22_08d/source/root-6.22.08/core/unix/src/TUnixSystem.cxx:2117
#3  TUnixSystem::StackTrace (this=0x1b79570) at /scratch/workspace/canvas-products-all/vedge-/SLF7/e20-prof/build/root/v6_22_08d/source/root-6.22.08/core/unix/src/TUnixSystem.cxx:2408
#4  0x00007f9b8856db85 in TUnixSystem::DispatchSignals (this=0x1b79570, sig=kSigSegmentationViolation) at /scratch/workspace/canvas-products-all/vedge-/SLF7/e20-prof/build/root/v6_22_08d/source/root-6.22.08/core/unix/src/TUnixSystem.cxx:3646
#5  <signal handler called>
#6  0x00007f9b88b6323b in ?? ()
#7  0x00007ffd496830c0 in ?? ()
#8  0x00007ffd496830b8 in ?? ()
#9  0x00007ffd49683068 in ?? ()
#10 0x00007f9b88b63360 in ?? ()
#11 0x00007ffd496830b8 in ?? ()
#12 0x00000000015e8f3c in ?? ()
#13 0x00007ffd496830d0 in ?? ()
#14 0x00007f9b88b63c9a in ?? ()
#15 0x00007ffd496830c8 in ?? ()
#16 0x00007f9b88b631d4 in ?? ()
#17 0x00007ffd496830b8 in ?? ()
#18 0x00007ffd496830c0 in ?? ()
#19 0x00007ffd496830c8 in ?? ()
#20 0x00000000015e8f3c in ?? ()
#21 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.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f9b88b6323b in ?? ()
#7  0x00007ffd496830c0 in ?? ()
#8  0x00007ffd496830b8 in ?? ()
#9  0x00007ffd49683068 in ?? ()
#10 0x00007f9b88b63360 in ?? ()
#11 0x00007ffd496830b8 in ?? ()
#12 0x00000000015e8f3c in ?? ()
#13 0x00007ffd496830d0 in ?? ()
#14 0x00007f9b88b63c9a in ?? ()
#15 0x00007ffd496830c8 in ?? ()
#16 0x00007f9b88b631d4 in ?? ()
#17 0x00007ffd496830b8 in ?? ()
#18 0x00007ffd496830c0 in ?? ()
#19 0x00007ffd496830c8 in ?? ()
#20 0x00000000015e8f3c in ?? ()
#21 0x0000000000000000 in ?? ()
===========================================================

Here is my code:

#include <iostream>
#include <map>
#include "TFile.h"
#include "TH1D.h"
#include <stdio.h>

#include "string"

using namespace std;

void T1_timing(){

  TFile *f1 = new TFile("path/to/my/file/run7449_decoded_ana_172files.root");
  TTree *daqtr = (TTree*)f1->Get("CRTDataAnalysis/DAQTree");
  // Declaration of leaf types                                                                           
  Int_t           event;
  Int_t           nChan;
  ULong64_t       t0;
  ULong64_t       t1;
  Int_t           adc;
  Int_t           entry;
  Int_t           mac5;
  Int_t           region;
  Int_t           subSys;
  UChar_t         gate_type;
  //string          *gate_name=0;                                                                        
  ULong64_t       trigger_timestamp;
  ULong64_t       gate_start_timestamp;
  ULong64_t       trigger_gate_diff;
  ULong64_t       gate_crt_diff;

  // List of branches                                                                                    
  TBranch        *b_event;   //!                                                                         
  TBranch        *b_nChan;   //!                                                                         
  TBranch        *b_t0;   //!                                                                            
  TBranch        *b_t1;   //!                                                                            
  TBranch        *b_adc;   //!                                                                           
  TBranch        *b_entry;   //!                                                                         
  TBranch        *b_mac5;   //!                                                                          
  TBranch        *b_region;   //!                                                                        
  TBranch        *b_subSys;   //!                                                                        
  TBranch        *b_gate_type;   //!                                                                     
  //TBranch        *b_gate_name;   //!                                                                   
  TBranch        *b_trigger_timestamp;   //!                                                             
  TBranch        *b_gate_start_timestamp;   //!                                                          
  TBranch        *b_trigger_gate_diff;   //!                                                             
  TBranch        *b_gate_crt_diff;   //!    

  //set branch addresses and branch pointers                                                             
  daqtr->SetBranchAddress("event", &event, &b_event);
  daqtr->SetBranchAddress("nChan", &nChan, &b_nChan);
  daqtr->SetBranchAddress("t0", &t0, &b_t0);
  daqtr->SetBranchAddress("t1", &t1, &b_t1);
  daqtr->SetBranchAddress("adc", &adc, &b_adc);
  daqtr->SetBranchAddress("entry", &entry, &b_entry);
  daqtr->SetBranchAddress("mac5", &mac5, &b_mac5);
  daqtr->SetBranchAddress("region", &region, &b_region);
  daqtr->SetBranchAddress("subSys", &subSys, &b_subSys);
  daqtr->SetBranchAddress("gate_type", &gate_type, &b_gate_type);
  //daqtr->SetBranchAddress("gate_name", &gate_name, &b_gate_name);                                      
  daqtr->SetBranchAddress("trigger_timestamp", &trigger_timestamp, &b_trigger_timestamp);
  daqtr->SetBranchAddress("gate_start_timestamp", &gate_start_timestamp, &b_gate_start_timestamp);
  daqtr->SetBranchAddress("trigger_gate_diff", &trigger_gate_diff, &b_trigger_gate_diff);
  daqtr->SetBranchAddress("gate_crt_diff", &gate_crt_diff, &b_gate_crt_diff);


  //histos 

  //initialize variables
  ULong64_t temp_maxT1 = 0;
  ULong64_t temp_minT1 = 100000000;
  //make a vector to store each individual mac5's, so we dont overwrite
  vector<int> mac5_vect;
  // make an array to store each FEBs max T1
  ULong64_t maxT1array [93] = {};
  ULong64_t minT1array [93] = {};
  //make a vector to store event #'s
  vector<int> event_vect;
  //get entries                                                                                  
  Long64_t nentries = (Long64_t)daqtr->GetEntries();
  cout << "Reading from CRT DAQTree with " << nentries << " entries...\n";
  for (Int_t i=0; i<100000; i++){     
    daqtr->GetEntry(i);
    if (adc==0) continue;
    //if(mac5!=61)continue; // try to see what 61's max is 
    //mac5_vect.push_back(mac5);
    //check if new event
    if(count(event_vect.begin(), event_vect.end(), event)){
      cout << "Event " << event << " already in event vector \n"; 
    }
    else{
      cout << "New Event! " << event << "\n";
      }
    event_vect.push_back(event);
    if (std::count(mac5_vect.begin(), mac5_vect.end(), mac5)) {
      //std::cout << "Element found, adding to vector " << mac5<<"\n";                            
    }
    else { //clear vectors if a new mac5                                                         
      //break;
      //std::cout << "New mac5!!  " << mac5 <<"\n";                                           
      //start over, reset variables to store max/min
      temp_maxT1 = 0;
      temp_minT1 = 100000000;
    }
    mac5_vect.push_back(mac5);
    Int_t temp_mac = mac5;
    ULong64_t temp_t1 = t1; 
    //cout << "Event:" << event << ", i: " << i << ", mac5: " <<  mac5 << ", t1: " << t1 << "\n";
    
    if (temp_t1 > temp_maxT1){
      //cout << "Max! temp_t1 " << temp_t1 << " is > temp_maxT1 " << temp_maxT1 << "\n";
      temp_maxT1 = temp_t1;
    }
    if (temp_t1 < temp_minT1){
      //cout << "Min! temp_t1 " << temp_t1 << " is < temp_minT1 " << temp_minT1 << "\n";
      temp_minT1 = temp_t1;
    }
    maxT1array[mac5] = temp_maxT1;
    minT1array[mac5] = temp_minT1;
  }
  //cout << "temp_maxT1: " << temp_maxT1 << "\n";
  //cout << "temp_minT1: " << temp_minT1 << "\n";
  
  for(Int_t i=1; i<93; i++){
    if (maxT1array[i] == 0 ) continue;
    if (minT1array[i] == 100000000) continue;
    cout << "Max T1 for feb " << i << ": " << maxT1array[i] << "\n";
  }

}

Given these:

a first check is to make sure that mac5 is indeed always >=0 and < 93.

Thank you so much for your reply. I checked and the mac5 is indeed always greater than 0 and less than 93. I added cout statements to print if the mac5<0 or if mac5>93, and these statements were never printed.

And mac5=93?

yes, I have mac5=93 by reading values from the TTree.

I tried commenting out my whole code and uncommenting things line by line to try to find where this Segmentation violation occurs. it seems to shows up after i add this line:

if (temp_t1 > temp_maxT1){
      //cout << "Max! temp_t1 " << temp_t1 << " is > temp_maxT1 " << temp_maxT1 << "\n";           
      temp_maxT1 = temp_t1;
    }
if (temp_t1 < temp_minT1){
      //cout << "Min! temp_t1 " << temp_t1 << " is < temp_minT1 " << temp_minT1 << "\n";           
      temp_minT1 = temp_t1;

and it seems the Seg violation interrupts at entry 39330 out of 100000. However, if i just try to read all 100000 entries, and not do anything with finding the min/max, it will loop through all entries just fine. So I can at least access those entries and they are not empty.

If you have “mac5=93” then you need “...T1array [94]” (at least).

This seemed to fix it. Thanks so much!