TFile Open from Gitlab

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

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

But It didn’t find the file.

How can I do it?

Imanol


Please read tips for efficient and successful posting and posting code

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


Try:
root -l -q -b -e 'TFile *f = TFile::Open("http://root.cern.ch/files/atlas.root"); f->ls();'
root -l -q -b -e 'TFile *f = TFile::Open("https://root.cern.ch/files/atlas.root"); f->ls();'

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

Imanol

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("https://github.com/root-project/root/blob/master/tutorials/gallery.root?raw=true"); 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.:
"https://my.git.lab/api/v4/projects/MyRepositoryID/repository/files/MyFile.root/raw?private_token=MyReadApiOrReadRepositoryToken"

@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 https://gitlab.cern.ch/ path /filename

Do I understand it right that when you:
wget https://gitlab.cern.ch/path/filename.root
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:

gitlab.cern.ch → HepMC/HepMC3 → python/test/inputIO4.root

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

wget "https://gitlab.cern.ch/api/v4/projects/hepmc%2FHepMC3/repository/files/python%2Ftest%2FinputIO4.root/raw" -O inputIO4.root

wget "https://gitlab.cern.ch/api/v4/projects/6751/repository/files/python%2Ftest%2FinputIO4.root/raw" -O inputIO4.root

Unfortunately, ROOT fails:

root -l -q -b -e 'TFile *f = TFile::Open("https://gitlab.cern.ch/api/v4/projects/hepmc%2FHepMC3/repository/files/python%2Ftest%2FinputIO4.root/raw");'

root -l -q -b -e 'TFile *f = TFile::Open("https://gitlab.cern.ch/api/v4/projects/6751/repository/files/python%2Ftest%2FinputIO4.root/raw");'

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("https://gitlab.cern.ch/api/v4/projects/hepmc%2FHepMC3/repository/files/python%2Ftest%2FinputIO4.root/raw?private_token=AReadRepositoryOrReadApiToken");'

root -l -q -b -e 'TFile *f = TFile::Open("https://gitlab.cern.ch/api/v4/projects/6751/repository/files/python%2Ftest%2FinputIO4.root/raw?private_token=AReadRepositoryOrReadApiToken");'

In all cases, I get the following:

Error in <TDavixFile::Init>: file https://gitlab.cern.ch/api/v4/projects/.../repository/files/python%2Ftest%2FinputIO4.root/raw 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("https://gitlab.cern.ch/hepmc/HepMC3/-/raw/master/python/test/inputIO4.root?inline=false");' 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.