C++ Macro in ROOT Does Not Terminate Properly

So, I have a macro like the following:

void Function() {
TFile *openFile = new TFile(“data/open.root”, “READ”);

//retrieve some data from the TTrees in open.root and save them in C++ vectors

//some long analyses, print some results

openFile->Close();

}

I execute this macro by: .x Function.C in an interactive ROOT session on cmd.

However, after running all the analyses and printing (seemingly) correct results, the code does not terminate. I have tried putting testing print statement during the analyses (which consist of several for loops running over the data retrieved), right before, and right after the openFile->Close(); statement, and they all print perfectly. The CPU usage drops after finishing the test printing statements, and the memory usage indicates nothing problematic going on. So, the computer does “reach the end of the code,” yet it wouldn’t terminate and go back to give me a new ROOT line root [1].

Is there any typical cases when this happens? If there is a link that explains why this may typically happen, that would be great too. Does it have to do with specific analyses that I am running (i.e. what I am doing with the data retrieved from the file)? It seems really bizarre that I get all the printing results, even the one exactly the line above the very last } that concludes the function, yet the macro does not terminate.

Any help/guidance will be greatly appreciated.

  1. Try to precompile your macro using ACLiC, in order to find source code problems, e.g. try something like (inspect all reported warnings and errors):
    root [0] .x Function.C++

  2. You can “debug” many problems using “valgrind”. See, for example: Segmentation Fault depending on linux distribution

BTW. Instead of “openFile->Close();”, you should have “delete openFile;”

[quote=“Pepe Le Pew”]1. Try to precompile your macro using ACLiC, in order to find source code problems, e.g. try something like (inspect all reported warnings and errors):
root [0] .x Function.C++

  1. You can “debug” many problems using “valgrind”. See, for example: Segmentation Fault depending on linux distribution

BTW. Instead of “openFile->Close();”, you should have “delete openFile;”[/quote]

  1. I tried .x Function.C++, and all I get are error messages because C++ does not understand types like TFile, TMath, TTree, etc. There is no error otherwise.

  2. I used delete openFile; instead. The program still does not terminate; the print statements right before and after are both printed properly.

For any class that the compiler does not understand, you need an appropriate line in form:
#include “TFile.h”
#include “TTree.h”
#include “TMath.h”

[quote=“Pepe Le Pew”]For any class that the compiler does not understand, you need an appropriate line in form:
#include “TFile.h”
#include “TTree.h”
#include “TMath.h”[/quote]

Yes, but that is not what is causing the issue. I think it is a memory-related issue with the specific C++ code. I will dig more into it.

Thank you anyways!