Open ROOT file with absolute path specified by input file processed by TEnv

Dear ROOTers,

I’m trying to create a standalone programme that uses a TEnv environment to control its behaviour. Part of this is reading the absolute path of a ROOT file. I read in a string from the input file, which specifies where the file is. I then try and open the file based on this path, but the programme seems to want to open this path in the current directory, so it fails. Below is a MWE for you to examine and offer advice!

FILE: mwe.C

#include <iostream>
#include <TEnv.h>
#include <TString.h>
#include <TFile.h>

void mwe(){
	TEnv *config = new TEnv( "input_file.dat" );

	TString s = config->GetValue( "ROOTFile", "" );
	std::cout << s << std::endl;

	TFile *f = new TFile( s.Data() );
	if ( f->IsZombie() ){
		std::cout << "FILE DID NOT OPEN" << std::endl;


FILE: input_file.dat

ROOTFile: "/Users/username/root-file-directory/my_root_file.root"

Both of these files are in /Users/username/root-script-directory/ When I run it, I get the following:

username@laptop root-script-directory % root -l -x -q mwe.C++
Processing mwe.C++...
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/username/root-script-directory/mwe/./
Error in <TFile::TFile>: file /Users/username/root-script-directory/"/Users/username/root-file-directory/my_root_file.root" does not exist

As you can see, it tries to open the specified absolute path following the relative path. Any ideas how to fix this?

ROOT Version: 6.26/10
Platform: macOS Ventura 13.01

Remove the quotes:

ROOTFile: /Users/username/root-file-directory/my_root_file.root

Thank you @ferhue! I can’t believe I didn’t figure that out, but the issue is now resolved :slight_smile:

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