Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

 Using Xrootd from ROOT

Open a File 

Reading or writing files within ROOT requires the class TXNetFile which is found in the library libNetx.so.
This library is loaded automatically if the static method TFlle::Open() is used to open the file.

       Wiki Markuproot \ [2\] TFile \ *f = TFile::Open("root://glast-rdr//wilko/test/basic.root")          // Reading a file

If  TXnetFile is used directly the library has to be loaded first:

  Wiki Markup      root\[2\]  .L        root[2]  .L $ROOTSYS/libNetx.so
Wiki Markup       root\[3\]  TFile \*f = new        root[3]  TFile *f = new TXNetFile("root://glast-rdr//wilko/test/basic.root", ,"RECREATE"))       // Open a file for writing

The above commands were tested using ROOT version 5.12. Test with a previous version (v5.10) showed that opening a file with the
"RECREATE" option fails, with a segmentation violation. The file is opened with zero length but further access to the file fails.
Using "NEW" to open the file works but this means the open will fail if the file already exists.

Using TChain 

TChain will also automatically use TXNetFile if the root files are specified using the "root://<xrootdSrv>/..."  names.
The next example will chain three root files and read them from xrootd:

Wiki Markup&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; root\[1\]&nbsp; TChain \*ch = new        root[1]  TChain *ch = new TChain(<TreeName>)
Wiki Markup&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; root\[2\]&nbsp;        root[2]  ch->Add("root://<xrootdSrv>//test/testtree1.root)
Wiki Markup&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; root\[3\]&nbsp;        root[3]  ch->Add("root://<xrootdSrv>//test/testtree2.root)
Wiki Markup&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; root\[4\]&nbsp;        root[4]  ch->Add("root://<xrootdSrv>//test/testtree3.root)

It is also allowed to use a wildcard (*) after the last '/' in the file name for the Add function of TChain. For example:
       ch->Add("root://<xrootdSrv>//test/test*.root)
would first do a dirlist of the directory /test/ and then add to the chain all files that match test*.root. In order for this to work with xrootd the cluster has to be setup properly. The Add() function will fist stat the directory (in the example above /test) followed by a dirlist (if dir exist). If the client is connected to a xrootd server there should be no problem. However, if the client is connected to a xrootd manager, the manager will redirect the client for the stat command but the client will go back to the manager to issue the dirlist. Therefore the manager has to be setup to return a valid directory listing.