How to Read a ROOT File via the Web?
By adding one ROOT specific module to your Apache web server you can distribute ROOT files to any ROOT user. No need anymore for ftp'ing files containing (out of date) histograms or other objects. Your latest up-to-date results are always accessable to all your colleagues.
How to access ROOT files via a web server. Simple, just create a TWebFile object instead of a TFile object with a standard URL as file name. For example:
root [0] TWebFile f("http://root.cern.ch/~rdm/hsimple.root")
root [1] f.ls()
TWebFile** http://root.cern.ch/~rdm/hsimple.root
TWebFile* http://root.cern.ch/~rdm/hsimple.root
KEY: TH1F hpx;1 This is the px distribution
KEY: TH2F hpxpy;1 py vs px
KEY: TProfile hprof;1 Profile of pz versus px
KEY: TNtuple ntuple;1 Demo ntuple
root [2] hpx.Draw()
Since TWebFile inherits from TFile all TFile operations work as expected. However, due to the nature of a web server a TWebFile is a readonly file. A TWebFile is ideally suited to read relatively small objects (like histograms or other data analysis results). Although possible, you don't want to analyse large TTree's via a TWebFile.
Here follows a step-by-step recipe for making your Apache 1.1 or 1.2 web server ROOT aware:
- Go to your Apache source directory and add the file mod_root.c
- Add to the end of the Configuration file the line:
Module root_module mod_root.o - Run the Configure script
- Type make
- Copy the new httpd to its expected place
- Go to the conf directory and add at the end of the srm.conf file the line:
AddHandler root-action root - Restart the httpd server
If you have Apache 1.3 you can also add modules without recompiling the server source. Do the following to compile and add the file mod_root133.c:
- gcc -c -I/usr/include/apache/ -DSHARED_MODULE -DEAPI mod_root133.c
- ld -shared -o mod_root.so mod_root133.o
- cp mod_root.so /usr/lib/apache/
- Configure Apache
- Goto /etc/httpd/conf/
- Add to the end of http.conf the line:
"LoadModule root_module /usr/lib/apache/mod_root.so"
This points Apache to the shared object if mod_root is being used as loadable module. - Add to the srm.conf the line:
"AddHandler root-action root"
- Restart the httpd daemon
If you have Apache 2.0 you can also add modules without recompiling the server source. Do the following to compile and add the file mod_root2.c:
- apxs -c mod_root2.c
- su
- apxs -i -c mod_root2.c
- Get the config file root2.conf and copy it into /etc/httpd/conf.d/
- Restart Apache using apachectl restart