H2root and Convert2root not functioning with my simple .hbook file

My root version is 6.30/04. My CERNLIB version is 2023. Both are installed using homebrew. My MacOS is Sonoma 14.2.1.

I have a very simple .hbook file created by piece of example code from the HBOOK manual.

	PROGRAM TEST
	PARAMETER (NWPAWC = 15000)
	COMMON/PAWC/PAW(NWPAWC)
	CHARACTER*8 CHTAGS(5)
	DIMENSION EVENT(5)
	EQUIVALENCE (EVENT(1),X),(EVENT(2),Y),(EVENT(3),Z)
	EQUIVALENCE (EVENT(4),ENERGY),(EVENT(5),ELOSS)
	DATA CHTAGS/'X','Y','Z','Energy','Eloss'/
C
    CALL HLIMIT(NWPAWC)
	CALL HROPEN(1,'EXAMPLE','EXAMPLE.hbook','N',1024,ISTAT)
	IF(ISTAT.NE.0)GO TO 99

	CALL HBOOKN(10,'A Row-Wise-Ntuple',5,'//EXAMPLE',5000,CHTAGS)
	CALL HBOOK1(100,'Energy distribution',100,0.,100.,0.)
C
	DO 10 I=1,10000
	CALL RANNOR(X,Y)
	Z=SQRT(X*X+Y*Y)
	ENERGY=50. + 10.*X
	ELOSS=10.*ABS(Y)
	CALL HFN(10,EVENT)
	CALL HFILL(100,ENERGY,0.,1.)
 10	 CONTINUE
*
	CALL HROUT(0,ICYCLE,' ')
	CALL HREND('EXAMPLE')
*
 99	 CONTINUE
      END

This is compiled and linked with this line:
gfortran test.f -o test -L/opt/homebrew/lib/cernlib/2023/lib -lpacklib -lkernlib

When I run it, it produces the file example.hbook. I would like to convert it using h2root.
But this doesn’t work.

pate@SFP-MacBook-Pro-Work CERNLIB % h2root example.hbook 
 RZIODO. Error at record =    2 LUN =    10 IOSTAT =  5001
 >>>>>> CALL RZEND(CHDIR)
 Cannot open fileHROPEN           0
 Error on hropen was 101 
Error cannot open input file: example.hbook

It also doesn’t work to try to use the THbookFile class to Convert2root.

pate@SFP-MacBook-Pro-Work CERNLIB % root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.30/04                        https://root.cern |
  | (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosxarm64 on Jan 31 2024, 08:17:06                   |
  | From heads/master@tags/v6-30-04                                  |
  | With Apple clang version 15.0.0 (clang-1500.1.0.2.5)             |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] THbookFile f("example.hbook");
root [1] f.Convert2root();
 RZIODO. Error at record =    2 LUN =    10 IOSTAT =  5001
 >>>>>> CALL RZEND(CHDIR)
 Cannot open fileHROPEN           0
 Error on hropen was 101 
Error cannot open input file: example.hbook
Error in <TFile::TFile>: file /Users/pate/Library/CloudStorage/Dropbox/CERNLIB/example.root does not exist

So I think some sort of bug has crept in if h2root and Convert2root both do not work on this simple case. Or it could be I am doing something wrong. Any advice is appreciated.

Dear Stephen,

I propose to include in the loop @couet , who has a long experience also with PAW and CERNLIB.

Best,
Danilo

@sfpate
Thanks for your input. Can you send the hbook file you generated ?

Dear Olivier

Thank you for your attention. I have attached the hbook file to this email.

Steve Pate

Whoops. I forgot to zip it.
example.hbook.zip (184.1 KB)

I get something similar on my Mac:

% h2root example.hbook
 Converting directory //example
 >>>>>> CALL HRZKEY(IDN)
 Converting RWN with ID= 10, nentries = 10000

 *** Break *** bus error
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/Users/couet/git/couet-root-bin/bin/h2root] hgiven_ (no debug info)
[/Users/couet/git/couet-root-bin/bin/h2root] convert_rwn(int) (no debug info)
[/Users/couet/git/couet-root-bin/bin/h2root] convert_directory(char const*) (no debug info)
[/Users/couet/git/couet-root-bin/bin/h2root] main (no debug info)
[/usr/lib/dyld] start (no debug info)

I must admit I have no idea why this problem occurs. By the way, why are you creating an hbook file and not directly a root file? are there some technical reasons imposing you such a working environment? cernlib/hbook are not maintained for years…

The hbook file I am interested in is coming from a fortran-based theory code. When I was not able to use h2root on the output, I went to this simple example to try to isolate the problem. When this simple example failed, I thought I must be doing something wrong.

I have experience linking fortran code and C++ code and the ROOT libraries, and if necessary I can build an interface layer allowing the fortran code to create a ROOT Tree and Histos directly and make a proper .root file. This will take a day of hair-pulling, but I have a healthy scalp and I will survive.

If such an interface layer already exists, I would be happy to use it of course.

Yes that might be a more reliable solution in the long term.

One of my students has access to some gvpm (linux) machines at Fermilab where Root 5 is installed, for backward compatibility with older analysis software. He wrote this little script:

#include <THbookFile.h>

void convertToRoot() {
    gSystem->Load("libHbook");
    THbookFile f("example.hbook");
    if (!f.IsOpen()) {
        std::cerr << "Error: Failed to open HBOOK file." << std::endl;
        return;
    }

    f.cd("//lun10");
    f.Convert2root(); 
}

It works on Root 5.

[mhossain@spinquestgpvm01 PawToROOT]$ root -b convertToRoot.C
  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.34/28     24 March 2015   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************

ROOT 5.34/28 (v5-34-28@v5-34-28, Mar 24 2015, 10:54:51 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] 
Processing convertToRoot.C...
fCurdir=//lun10
 Converting directory //example
 >>>>>> CALL HRZKEY(IDN)
 Converting RWN with ID= 10, nentries = 10000
 >>>>>> CALL HRZKEY(IDN)
TFile**		example.root	HBOOK file: example.hbook converted to ROOT
 TFile*		example.root	HBOOK file: example.hbook converted to ROOT
  KEY: TTree	h10;1	A
  KEY: TH1F	h100;1	Energy distribution 

But not on Root 6, on my Mac.

pate@SFP-MacBook-Pro-Home CERNLIB % root
  ------------------------------------------------------------------
 | Welcome to ROOT 6.30/02                        https://root.cern |
 | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
 | Built for macosxarm64 on Nov 27 2023, 18:27:38                   |
 | From heads/master@tags/v6-30-02                                  |
 | With Apple clang version 15.0.0 (clang-1500.0.40.1)              |
 | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
  ------------------------------------------------------------------

root [0] .L convertToRoot.C  
root [1] convertToRoot()
fCurdir=//lun10
RZIODO. Error at record =    2 LUN =    10 IOSTAT =  5001
>>>>>>CALL RZEND(CHDIR)
Cannot open fileHROPEN           0
Error on hropen was 101  Error cannot open input file: example.hbook
Error in <TFile::TFile>: file /Users/pate/Library/CloudStorage/Dropbox/CERNLIB/example.root does not exist
root [2]

So something happened between 5.34 and 6.30 that broke something related to the THbookFile class. :frowning:

The code of file hbbok.f (where these messages come from) has not been changed since 15 years. I guess that code is showing its age. As I said, it is not safe to rely on such translation (hbook to root) on the long term. The only safe way is to generate directly root files. Note that h2root was created at the beginning of root to ease the transition between cernlib and root.

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