Inverse of TChain::Add?

In PyROOT I’m building TChains and using wildcards to add all files in a given folder. Now, I’d like to remove a few specific files from said TChains. Is there a method similar to TChain::Add that could do that? Or should I first find the files I need in the folder, then chain them in a loop?

Thanks!

Hi,

You could find the files in that directory using gSystem->OpenDirectory() / ->GetDirEntry() / FreeDirectory(). Or you remove the entries you don’t need from the chain->GetListOfFiles(), which is a collection of TChainElements.

Cheers, Axel

Hi,

I’d like to go with the second option, but I can’t find anything in the TChain reference page that would allow me to remove an element from a TChain. I see there is an ls method; would looking up a particular substring in mychain.ls() then finding its index and pop()'ing that index work? Is there a simpler, more efficient method?

Thanks!

Hi,

This is what I meant:

root [0] TChain ch("ntuple");
root [1] ch.Add("tutorials/hsimple*.root")
root [2] ch.ls()
OBJ: TChain	ntuple	 : 0 at: 0x7fe2250cf040
 tutorials/hsimple.roottree:ntuple entries=<not calculated>
 tutorials/hsimple_1.roottree:ntuple entries=<not calculated>
root [3] TChainElement* chainElm = dynamic_cast<TChainElement*>(ch.GetListOfFiles()->At(1))
(TChainElement *) 0x25cfbd0
root [4] ch.GetListOfFiles()->Remove(chainElm)
(TObject *) 0x25cfbd0
root [5] ch.ls()
OBJ: TChain	ntuple	 : 0 at: 0x7fe2250cf040
 tutorials/hsimple.roottree:ntuple entries=<not calculated>

Does that work for you?

Axel.

Hi @Axel,

Thanks, that’s very nice!