Hadd files on castor

I’d like to merge hundreds of root files sitting in a castor directory. They contain histograms and ntuples.

My naive guess didn’t work,

Is there another simple way? Or do I need to copy the files to a tmp directory and hadd those? I know that “hadd out.root *” works for merging files in the current directory.

Dear mbanderson,

This is because “/castor/…” is not a standard mount point, so the wildcarding is not working.
You have to create a text file with the list of files the you want to merge, with the full path that you would use to access them in ROOT, e.g. something like this

rfio:/castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/MPA_March312010_MinBias_Spring10_START3X_V25B_V2_job_1.root
rfio:/castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/MPA_March312010_MinBias_Spring10_START3X_V25B_V2_job_100.root
rfio:/castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/MPA_March312010_MinBias_Spring10_START3X_V25B_V2_job_1002.roo
t
rfio:/castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/MPA_March312010_MinBias_Spring10_START3X_V25B_V2_job_1003.roo
t
rfio:/castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/MPA_March312010_MinBias_Spring10_START3X_V25B_V2_job_1004.roo
t

(You can get the list with, for example, ‘nsls /castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/ > list.txt’ and then editing list.txt) .
Once you have the list, you can do:

hadd example.root @list.txt

Alternatively, you can tailor your own merger using the class TFileMerger.

G. Ganis

Great! An automatic way to create the list of text files in the format needed would be:

Then

Works great!

Thanks!

After further use, I think it’s safer to copy all the files to a local dir and hadd from there.

I use a script:

#!/bin/bash tempdir="$1" for afile in `nsls $tempdir`; do rfcp $tempdir/$afile . done

Which I call with nohup so it runs even if I disconnect:

$ nohup ~/bin/castor_cp_dir /castor/cern.ch/user/g/gaultney/SergueiTrees/New_MinBiasMC/ >& log.txt &
then when it’s done hadd the files in my local dir: