Add a TWebFile to a TChain

Hi, ROOT experts,

I am working with many root files online (files in http), and I am wondering if I can use TWebFile to open each of them and then add them to a TChain? Somebody asked the same question long time ago but there’s still no clear answer to this question:

I want to do something like this:

# These files contain trees with the same tree name
f1 = TWebFile("http://....../file1.root")
f2 = TWebFile("http://....../file2.root")
f3 = TWebFile("http://....../file3.root")

chain = ROOT.TChain("combined")

waveforms = ROOT.mattak.Waveforms()
chain.SetBranchAddress("waveforms", ROOT.AddressOf(waveforms))

nTotalEvents = chain.GetEntries()
for i_event in range(nTotalEvents):

Is it possible to do it this way or something like this, or is there a better way?

Thank you!

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


chain = ROOT.TChain("combined")

would create TWebFile to access the file.

What are you trying to accomplish by creating them explicitly?

Hi, @pcanal,

Thanks for your reply. But doing it in this way

I got an error when I was trying to get the tree out of the file:

Error in <DavixOpen>: can not open file "https://....../combined.root" with davix: Result HTTP 401 : Authentication Error  after 3 attempts (14)

Somebody told me that if I wanted to fix this issue for just using a TFile I could do:

ROOT.gPluginMgr.AddHandler("TFile", "^http[s]?:", "TWebFile", "Net", "TWebFile(const char*,Option_t*)")
f = TFile.Open("http://....../combined.root")
t = f.Get("combined")
t.SetBranchAddress("waveforms", ROOT.AddressOf(waveforms))

This works for me to deal with just one TFile at a time, but I really want to use TChain to deal with several files, could you please tell me if there’s a way to do it if I were to use TChain in this case?

Thank you!


ROOT.gPluginMgr.AddHandler("TFile", "^http?:", "TWebFile", "Net", "TWebFile(const char*,Option_t*)")

This works for me to deal with just one TFile at a time, but I really want to use TChain

If it works with TFile::Open, it should work for TChain.

It works for me using a TFile, but it doesn’t work when I use a TChain, I still got the same error.

I can not reproduce the original problem. Can you pm me the url of one of the files?

I am sorry I am not allowed to share the link because there’s a password in there and that belongs to the research group. I will try to find the solution, if not I will just use TFile to work with each file individually, and then use hadd command to combine the output files…

Thank you so much for all your replies!

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