# H2root and Convert2root not functioning with my simple .hbook file

**URL:** <https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286>\
**Category:** ROOT\
**Tags:** bug\
**Created:** [February 25, 2024, 1:45pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286 "2024-02-25T13:45:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfpate](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@sfpate](https://root-forum.cern.ch/u/sfpate)\
**Post date:** [February 25, 2024, 1:45pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/1 "2024-02-25T13:45:18Z")

</div>

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.

```auto
	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.

```auto
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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [February 26, 2024, 6:13am UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/2 "2024-02-26T06:13:46Z")

</div>

Dear Stephen,

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

Best,  
Danilo

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 26, 2024, 12:03pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/3 "2024-02-26T12:03:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sfpate](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@sfpate](https://root-forum.cern.ch/u/sfpate)\
**Post date:** [February 26, 2024, 2:16pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/4 "2024-02-26T14:16:06Z")

</div>

Dear Olivier

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

Steve Pate

---

<div class="post-metadata">

**Author:** ![sfpate](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@sfpate](https://root-forum.cern.ch/u/sfpate)\
**Post date:** [February 26, 2024, 2:27pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/5 "2024-02-26T14:27:09Z")

</div>

Whoops. I forgot to zip it.  
[example.hbook.zip](https://root-forum.cern.ch/uploads/short-url/eMHhpbNObtB3p01VDfXea71KeHy.zip) (184.1 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 26, 2024, 4:23pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/6 "2024-02-26T16:23:50Z")

</div>

I get something similar on my Mac:

```auto
% 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)

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 26, 2024, 4:30pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/7 "2024-02-26T16:30:09Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![sfpate](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@sfpate](https://root-forum.cern.ch/u/sfpate)\
**Post date:** [February 26, 2024, 4:38pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/8 "2024-02-26T16:38:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 27, 2024, 6:44am UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/9 "2024-02-27T06:44:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sfpate](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@sfpate](https://root-forum.cern.ch/u/sfpate)\
**Post date:** [February 27, 2024, 1:15pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/10 "2024-02-27T13:15:00Z")

</div>

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:

```auto
#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.

```auto
[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.

```auto
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. ☹

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 27, 2024, 4:20pm UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/11 "2024-02-27T16:20:19Z")

</div>

The code of file `hbbok.f` (where these messages come from) has not been changed [since 15 years](https://github.com/root-project/root/commits/master/misc/minicern/src/hbook.f). 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.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 27, 2025, 6:22am UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/13 "2025-06-27T06:22:50Z")

</div>

Opened on June 27, 2025, 6:22am UTC



---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 27, 2025, 6:23am UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/14 "2025-06-27T06:23:57Z")

</div>

h2root with the attached zip example seems to run fine on Linux machines. @ferhue was able to generate example.root

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [June 27, 2025, 7:57am UTC](https://root-forum.cern.ch/t/h2root-and-convert2root-not-functioning-with-my-simple-hbook-file/58286/15 "2025-06-27T07:57:27Z")

</div>

[example.root](https://root-forum.cern.ch/uploads/short-url/h66WxUh4tSFwMlY4RjQuXLy7HeP.root) (185.2 KB)
