TFile Open from Gitlab

Hi, I wanted to open a ROOT File from GitLab repo. I tried:

TFile* file = TFile::Open(“url/filename”);
TFile* file = TFile::Open(“url/filename”, “WEB”);

But It didn’t find the file.

How can I do it?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

root -l -q -b -e 'TFile *f = TFile::Open(""); f->ls();'
root -l -q -b -e 'TFile *f = TFile::Open(""); f->ls();'

It works, but I don’t understand the difference between this and my code. Maybe the GitLab server is spoiling something?


You may need something like: "http://myusername:mypasswd@my.server/my/file.root"
Make sure that “wget” works, e.g.: wget http://myusername:mypasswd@my.server/my/file.root

Here’s a simple GitHub test (note: the “View raw” link is used):
root -l -q -b -e 'TFile *f = TFile::Open(""); f->ls();'

That GitHub test works, I guess that the difference is the permission, my repository is private. How can I add this?

Make sure you can retrieve your file with the “wget” and/or “curl”. Then ROOT should be able to retrieve it, too.

I can retrieve it with “wget” but ROOT is giving me the error:

Error in : can not open file “path/file” with davix: Result HTTP 404 : File not found after 3 attempts (18)

Have you added the “token”, e.g.:

@Axel We need someone who could have a look at it.

What do you mean? Where should I add this?

How exactly do you get your file with “wget”?

wget path /filename

Do I understand it right that when you:
you really get the raw “filename.root” (which you can then open in ROOT)?

@Axel … ROOT 6.26/10 on a Ubuntu 22.04 / x86_64 / GCC 11.3.0 fails in a simple test: → HepMC/HepMC3 → python/test/inputIO4.root

This is a public repository, so “wget” doesn’t need any tokens:

wget "" -O inputIO4.root

wget "" -O inputIO4.root

Unfortunately, ROOT fails:

root -l -q -b -e 'TFile *f = TFile::Open("");'

root -l -q -b -e 'TFile *f = TFile::Open("");'

Even if I try to use a “Personal Access Token” (a “read_repository” or “read_api” one):

root -l -q -b -e 'TFile *f = TFile::Open("");'

root -l -q -b -e 'TFile *f = TFile::Open("");'

In all cases, I get the following:

Error in <TDavixFile::Init>: file is truncated at 0 bytes: should be 2127856, trying to recover
Warning in <TDavixFile::Init>: no keys recovered, file has been made a Zombie

root -l -q -b -e 'TFile *f = TFile::Open("");' works more or less well :slight_smile:

@Axel Could you please post the relevant link to GitLab documentation?

The one I know is:

GitLab → API Docs → REST API resources → Repository files API → Get raw file from repository

I just went here

Then there’s the “Download” button on the right, I took its URL. Note that GitLab is no full featured web server - this isn’t as fast / efficient as a regular Apache / nginx etc.

@Axel Could you please try “your method” with some “private GitLab repository” (which requires a “private_token” to retrieve files)?

Sorry, I just decided to use another strategy, so this is no longer necessary. Thank you for your help

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