Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
h2root.cxx
Go to the documentation of this file.
1// @(#)root/main:$Id$
2// Author: Rene Brun 20/09/96
3/////////////////////////////////////////////////////////////////////////
4// Program to convert an HBOOK file into a ROOT file
5// Author: Rene Brun
6//
7// This program is invoked via:
8// h2root hbook_file_name root_file_name compress tolower
9// if the second parameter root_file_name is missing the name will be
10// automatically generated from the hbook file name. Example:
11// h2root test.hbook
12// is identical to
13// h2root test.hbook test.root
14// if compress is missing (or = 1)the ROOT file will be compressed
15// if compress = 0 the ROOT file will not be compressed.
16// if tolower is missing (or = 1) ntuple column names are converted to lower case
17// but the first character is converted to upper case.
18// if tolower = 2 same as tolower=1 except that the first character is also
19// converted to lower case
20/////////////////////////////////////////////////////////////////////////
21
22#include <cstdlib>
23#include <cstring>
24#include <cctype>
25#include <iostream>
26
27#include "TFile.h"
28#include "TDirectoryFile.h"
29#include "TTree.h"
30#include "TBranch.h"
31#include "TLeafI.h"
32#include "TH1.h"
33#include "TH2.h"
34#include "TProfile.h"
35#include "TGraph.h"
36#include "TMath.h"
37#include "strlcpy.h"
38#include "snprintf.h"
39
40// Define the names of the Fortran common blocks for the different OSs
41// Note that with gcc3.4 or above the size of PAWC_SIZE must be the same
42// as in the Fortran definition in hbook.f and zebra
43// Also, the arrays must be declared extern like on Windows
44#ifndef WIN32
45#define PAWC_SIZE 4000000
46# define bigbuf bigbuf_
47# define pawc pawc_
48# define quest quest_
49# define hcbits hcbits_
50# define hcbook hcbook_
51# define rzcl rzcl_
52//int pawc[PAWC_SIZE];
53//int quest[100];
54//int hcbits[37];
55//int hcbook[51];
56//int rzcl[11];
57extern "C" char bigbuf[PAWC_SIZE];
58extern "C" int pawc[PAWC_SIZE];
59extern "C" int quest[100];
60extern "C" int hcbits[37];
61extern "C" int hcbook[51];
62extern "C" int rzcl[11];
63#else
64// on windows /pawc/ must have the same length as in libPacklib.a !!
65#define PAWC_SIZE 4000000
66# define bigbuf BIGBUF
67# define pawc PAWC
68# define quest QUEST
69# define hcbits HCBITS
70# define hcbook HCBOOK
71# define rzcl RZCL
72extern "C" int bigbuf[PAWC_SIZE];
73extern "C" int pawc[PAWC_SIZE];
74extern "C" int quest[100];
75extern "C" int hcbits[37];
76extern "C" int hcbook[51];
77extern "C" int rzcl[11];
78#endif
79
80int *iq, *lq;
81float *q;
82char idname[128];
84char chtitl[128];
88const Int_t kMIN1 = 7;
89const Int_t kMAX1 = 8;
90
91#if defined __linux
92//On linux Fortran wants this, so we give to it!
93int xargv=0;
94int xargc=0;
95void MAIN__() {}
96#endif
97
98// Define the names of the Fortran subroutine and functions for the different OSs
99
100#ifndef WIN32
101# define hlimit hlimit_
102# define hropen hropen_
103# define hrin hrin_
104# define hnoent hnoent_
105# define hgive hgive_
106# define hgiven hgiven_
107# define hprntu hprntu_
108# define hgnpar hgnpar_
109# define hgnf hgnf_
110# define hgnt hgnt_
111# define rzink rzink_
112# define hdcofl hdcofl_
113# define hmaxim hmaxim_
114# define hminim hminim_
115# define hdelet hdelet_
116# define hntvar2 hntvar2_
117# define hbname hbname_
118# define hbnamc hbnamc_
119# define hbnam hbnam_
120# define hi hi_
121# define hie hie_
122# define hif hif_
123# define hij hij_
124# define hix hix_
125# define hijxy hijxy_
126# define hije hije_
127# define hcdir hcdir_
128# define zitoh zitoh_
129# define uhtoc uhtoc_
130
131# define type_of_call
132# define DEFCHAR const char*
133# define PASSCHAR(string) string
134
135// As recommended in
136// https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
137using fortran_charlen_t = size_t;
138
139#else
140# define hlimit HLIMIT
141# define hropen HROPEN
142# define hrin HRIN
143# define hnoent HNOENT
144# define hgive HGIVE
145# define hgiven HGIVEN
146# define hprntu HPRNTU
147# define hgnpar HGNPAR
148# define hgnf HGNF
149# define hgnt HGNT
150# define rzink RZINK
151# define hdcofl HDCOFL
152# define hmaxim HMAXIM
153# define hminim HMINIM
154# define hdelet HDELET
155# define hntvar2 HNTVAR2
156# define hbname HBNAME
157# define hbnamc HBNAMC
158# define hbnam HBNAM
159# define hi HI
160# define hie HIE
161# define hif HIF
162# define hij HIJ
163# define hix HIX
164# define hijxy HIJXY
165# define hije HIJE
166# define hcdir HCDIR
167# define zitoh ZITOH
168# define uhtoc UHTOC
169# define type_of_call _stdcall
170# define DEFCHAR const char*, const int
171# define PASSCHAR(string) string, strlen(string)
172#endif
173
174extern "C" void type_of_call hlimit(const int&);
175#ifndef WIN32
176extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
178#else
179extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
180 const int&,const int&);
181#endif
182
183extern "C" void type_of_call hrin(const int&,const int&,const int&);
184extern "C" void type_of_call hnoent(const int&,const int&);
185#ifndef WIN32
186extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
187 const int&,const float&,const float&,const int&,const int&,fortran_charlen_t);
188#else
189extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
190 const int&,const float&,const float&,const int&,const int&);
191#endif
192
193#ifndef WIN32
194extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
195 const float&,const float&,fortran_charlen_t,fortran_charlen_t);
196#else
197extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
198 const float&,const float&);
199#endif
200
201#ifndef WIN32
202extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&,fortran_charlen_t,fortran_charlen_t,fortran_charlen_t);
203#else
204extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&);
205#endif
206
207#ifndef WIN32
208extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,fortran_charlen_t,fortran_charlen_t);
209#else
210extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
211#endif
212
213extern "C" void type_of_call hprntu(const int&);
214#ifndef WIN32
215extern "C" void type_of_call hgnpar(const int&,DEFCHAR,fortran_charlen_t);
216#else
217extern "C" void type_of_call hgnpar(const int&,DEFCHAR);
218#endif
219extern "C" void type_of_call hgnf(const int&,const int&,const float&,const int&);
220extern "C" void type_of_call hgnt(const int&,const int&,const int&);
221#ifndef WIN32
222extern "C" void type_of_call rzink(const int&,const int&,DEFCHAR,fortran_charlen_t);
223#else
224extern "C" void type_of_call rzink(const int&,const int&,DEFCHAR);
225#endif
226extern "C" void type_of_call hdcofl();
227extern "C" void type_of_call hmaxim(const int&,const float&);
228extern "C" void type_of_call hminim(const int&,const float&);
229extern "C" void type_of_call hdelet(const int&);
230extern "C" void type_of_call hix(const int&,const int&,const float&);
231extern "C" void type_of_call hijxy(const int&,const int&,const int&,const float&,const float&);
232
233#ifndef R__B64BUG
234extern "C" float type_of_call hi(const int&,const int&);
235extern "C" float type_of_call hie(const int&,const int&);
236extern "C" float type_of_call hif(const int&,const int&);
237extern "C" float type_of_call hij(const int&,const int&,const int&);
238extern "C" float type_of_call hije(const int&,const int&,const int&);
239#else
240extern "C" double type_of_call hi(const int&,const int&);
241extern "C" double type_of_call hie(const int&,const int&);
242extern "C" double type_of_call hif(const int&,const int&);
243extern "C" double type_of_call hij(const int&,const int&,const int&);
244extern "C" double type_of_call hije(const int&,const int&,const int&);
245#endif
246
247#ifndef WIN32
249#else
250extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
251#endif
252
253extern "C" void type_of_call zitoh(const int&,const int&,const int&);
254#ifndef WIN32
255extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&,fortran_charlen_t);
256#else
257extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&);
258#endif
259
260extern void convert_directory(const char*);
261extern void convert_1d(Int_t id);
262extern void convert_2d(Int_t id);
263extern void convert_profile(Int_t id);
264extern void convert_cwn(Int_t id);
265extern void convert_rwn(Int_t id);
266
270int main(int argc, char **argv)
271{
272 //Program to convert an HBOOK file into a ROOT file
273 if (argc < 2) {
274 printf("******Error in invoking h2root\n");
275 printf("===> h2root file.hbook file.root [compress] [tolower] [lrecl] [bufsize] [optcwn] \n");
276 printf(" if file.root is not given it will be = file.root\n");
277 printf(" compress = 1 by default (use 0 for no compression)\n");
278 printf(" tolower = 1 by default (use 0 to keep case of column names)\n");
279 printf(" lrecl =0 by default (must be specified if >8092)\n");
280 printf(" bufsize = 8000 by default (branch buffer size)\n");
281 printf(" for cwn ntuple only: optcwn = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n");
282 return 1;
283 }
284 lq = &pawc[9];
285 iq = &pawc[17];
286 void *qq = iq;
287 q = (float*)qq;
288 char *file_in=argv[1];
289 char *file_out;
290 Int_t compress = 1;
291 int ier=0, record_size=0;
292 if (argc > 7) {
293 optcwn = atoi(argv[7]);
294 }
295 if (argc > 6) {
296 bufsize = atoi(argv[6]);
297 }
298 if (argc > 5) {
299 record_size = atoi(argv[5]);
300 }
301 if (argc > 4) {
302 golower = atoi(argv[4]);
303 }
304 if (argc > 3) {
305 compress = atoi(argv[3]);
306 }
307 if (argc > 2) {
308 file_out=argv[2];
309 } else {
310 Int_t nchf = strlen(file_in)+std::char_traits<char>::length(".root")+1;
311 file_out= new char[nchf];
312 strlcpy(file_out,file_in,nchf);
313 char *dot = strrchr(file_out,'.');
314 if (dot) strcpy(dot+1,"root");
315 else strlcat(file_out,".root",nchf);
316 }
317
318#if defined(_HIUX_SOURCE) && !defined(__GNUC__)
319 hf_fint((char *)NULL);
320#endif
321
322
323 int pawc_size = PAWC_SIZE;
324 hlimit(pawc_size);
325
326 int lun = 10;
327#ifndef WIN32
328 // Reminder: Argument passing convention is that string lengths go as hidden arguments
329 // at the end of the argument list.
330 constexpr auto chdir = "example";
331 constexpr auto opt = "px";
332 hropen(lun, chdir, file_in, opt, record_size, ier, strlen(chdir), strlen(file_in), strlen(opt));
333#else
334 hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("px"),record_size,ier);
335#endif
336
337 if (ier) printf (" Error on hropen was %d \n", ier);
338 if (quest[0]) {
339 printf("Error cannot open input file: %s\n",file_in);
340 return 1;
341 }
342
343 char root_file_title[2000];
344 snprintf(root_file_title,2000,"HBOOK file: %s converted to ROOT",file_in);
345 TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,compress);
346
347 if (!hfile) {
348 printf("Error: can't open output file: %s \n",file_out);
349 if (argc <= 2)
350 delete[] file_out;
351 return 1;
352 }
353
354
355 convert_directory("//example");
356
357 hfile->Write();
358 hfile->ls();
359 hfile->Close();
360 delete hfile;
361 if (argc <= 2)
362 delete[] file_out;
363 return 0;
364}
365
366////////////////////////////////////////////////////////////////////////////////
367///convert a directory
368
369void convert_directory(const char *dir)
370{
371 printf(" Converting directory %s\n",dir);
372 Int_t id;
373// Int_t nastycase=0;
374// Int_t nastyprint=0;
375// Int_t idold = 0;
376 for (Int_t key=1;key<1000000;key++) {
377 int z0 = 0;
378 rzink(key,z0,"S",1);
379 if (quest[0]) break;
380 if (quest[13] & 8) {
381 continue;
382// if (!nastyprint) {
383// printf("Found nasty Hbook case!! You had an Hbook error message\n");
384// printf(" when creating the file (too many records)\n");
385// printf(" Hbook file should have been created with a bigger LRECL\n");
386// printf(" ROOT will try to recover\n");
387// nastyprint = 1;
388// }
389// nastycase = 1;
390 }
391 id = quest[20];
392// if (id == idold && nastycase) continue;
393// nastycase = 0;
394// idold = id;
395 int i999 = 999;
396 hrin(id,i999,0);
397 if (quest[0]) {
398 printf("Error cannot read ID = %d\n",id);
399 //break;
400 }
401 hdcofl();
402 lcid = hcbook[10];
403 lcont = lq[lcid-1];
404 if (hcbits[3]) {
405 if (iq[lcid-2] == 2) convert_rwn(id);
406 else convert_cwn(id);
407 hdelet(id);
408 continue;
409 }
410 if (hcbits[0] && hcbits[7]) {
411 convert_profile(id);
412 hdelet(id);
413 continue;
414 }
415 if (hcbits[0]) {
416 convert_1d(id);
417 hdelet(id);
418 continue;
419 }
420 if (hcbits[1] || hcbits[2]) {
421 convert_2d(id);
422 hdelet(id);
423 }
424 }
425
426// converting subdirectories of this directory
427 const Int_t kKLS = 26;
428 const Int_t kKNSD = 23;
429 lcdir = rzcl[2];
430 Int_t ls = iq[lcdir+kKLS];
431 Int_t ndir = iq[lcdir+kKNSD];
432 Int_t nch=16;
433 Int_t ihdir[4];
434 Int_t ncw = 4;
435 TDirectory *cursav = gDirectory;
436 Int_t i;
437 char chdir[17];
438 char hbookdir[17];
439 for (Int_t k=0;k<ndir;k++) {
440 lcdir = rzcl[2];
441 zitoh(iq[lcdir+ls+7*k],ihdir[0],ncw);
442 for (i=0;i<17;i++) chdir[i] = 0;
443#ifndef WIN32
444 uhtoc(ihdir[0],ncw,chdir,nch ,16);
445#else
446 uhtoc(ihdir[0],ncw,chdir,16,nch);
447#endif
448 //do not process directory names containing a slash
449 if (strchr(chdir,'/')) {
450 printf("Sorry cannot convert directory name %s because it contains a slash\n",chdir);
451 continue;
452 }
453 strlcpy(hbookdir,chdir,17);
454 for (i=16;i>0;i--) {
455 if (chdir[i] == 0) continue;
456 if (chdir[i] != ' ') break;
457 chdir[i] = 0;
458 }
459#ifndef WIN32
460 hcdir(PASSCHAR(hbookdir),PASSCHAR(" "),16,1);
461#else
462 hcdir(PASSCHAR(hbookdir),PASSCHAR(" "));
463#endif
464 TDirectoryFile *newdir = new TDirectoryFile(chdir,chdir);
465 newdir->cd();
466 convert_directory(chdir);
467#ifndef WIN32
468 hcdir(PASSCHAR("\\"),PASSCHAR(" "),1,1);
469#else
470 hcdir(PASSCHAR("\\"),PASSCHAR(" "));
471#endif
472 newdir->Write();
473 cursav->cd();
474 }
475}
476
477////////////////////////////////////////////////////////////////////////////////
478///convert 1d histogram
479
481{
482 if (id > 0) snprintf(idname,128,"h%d",id);
483 else snprintf(idname,128,"h_%d",-id);
484 hnoent(id,nentries);
485#ifndef WIN32
487#else
489#endif
490 chtitl[4*nwt] = 0;
491 TH1F *h1;
492 Int_t i;
493 if (hcbits[5]) {
494 Int_t lbins = lq[lcid-2];
495 Double_t *xbins = new Double_t[ncx+1];
496 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
497 h1 = new TH1F(idname,chtitl,ncx,xbins);
498 delete [] xbins;
499 } else {
501 }
502 if (hcbits[8]) h1->Sumw2();
503 TGraph *gr = 0;
504 if (hcbits[11]) {
505 gr = new TGraph(ncx);
506 h1->GetListOfFunctions()->Add(gr);
507 }
508
509 Float_t x,yx;
510 for (i=0;i<=ncx+1;i++) {
511 x = h1->GetBinCenter(i);
512 yx = hi(id,i);
513 h1->Fill(x,yx);
514 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
515 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
516 }
517 Float_t yymin, yymax;
518 if (hcbits[19]) {
519 yymax = q[lcid+kMAX1];
520 h1->SetMaximum(yymax);
521 }
522 if (hcbits[20]) {
523 yymin = q[lcid+kMIN1];
524 h1->SetMinimum(yymin);
525 }
526 h1->SetEntries(nentries);
527 h1->Write();
528 delete h1;
529}
530
531////////////////////////////////////////////////////////////////////////////////
532///convert 2d histogram
533
535{
536 if (id > 0) snprintf(idname,128,"h%d",id);
537 else snprintf(idname,128,"h_%d",-id);
538 hnoent(id,nentries);
539#ifndef WIN32
541#else
543#endif
544 chtitl[4*nwt] = 0;
546 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
547 Float_t offsety = 0.5*(ymax-ymin)/ncy;
548 Int_t lw = lq[lcont];
549 if (lw) h2->Sumw2();
550
551 Float_t x = 0.0, y = 0.0;
552 for (Int_t j=0;j<=ncy+1;j++) {
553 for (Int_t i=0;i<=ncx+1;i++) {
554 hijxy(id,i,j,x,y);
555 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
556 if (lw) {
557 Double_t err2 = hije(id,i,j);
558 h2->SetBinError(i,j,err2);
559 }
560 }
561 }
562 h2->SetEntries(nentries);
563 h2->Write();
564 delete h2;
565}
566
567////////////////////////////////////////////////////////////////////////////////
568/// the following structure is used in Hbook
569/// lcid points to the profile in array iq
570/// lcont = lq(lcid-1)
571/// lw = lq(lcont)
572/// ln = lq(lw)
573/// if option S jbyt(iq(lw),1,2) = 1
574/// if option I jbyt(iq(lw),1,2) = 2
575
577{
578 if (id > 0) snprintf(idname,128,"h%d",id);
579 else snprintf(idname,128,"h_%d",-id);
580 hnoent(id,nentries);
581 Int_t lw = lq[lcont];
582 Int_t ln = lq[lw];
583#ifndef WIN32
585#else
587#endif
588 chtitl[4*nwt] = 0;
589 const char *option= " ";
590 if (iq[lw] == 1) option = "S";
591 if (iq[lw] == 2) option = "I";
593
594 const Int_t kCON1 = 9;
595 Int_t i;
596 for (i=1;i<=ncx;i++) {
597 Int_t n = Int_t(q[ln+i]);
598 p->SetBinEntries(i,n);
599 Float_t content = q[lcont+kCON1+i];
600 Float_t error = TMath::Sqrt(q[lw+i]);
601 p->SetBinContent(i,content);
602 p->SetBinError(i,error);
603 }
604 p->SetEntries(nentries);
605 p->Write();
606 delete p;
607}
608
609////////////////////////////////////////////////////////////////////////////////
610///convert row wise ntuple
611
613{
614 const int kNchar=9;
615 int nvar;
616 int ier=0;
617 int i,j;
618 char *chtag_out;
619 float *x;
620 float rmin[1000], rmax[1000];
621
622 if (id > 0) snprintf(idname,128,"h%d",id);
623 else snprintf(idname,128,"h_%d",-id);
624 hnoent(id,nentries);
625 printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
626 nvar=0;
627#ifndef WIN32
628 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
629#else
630 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
631#endif
632
633 chtag_out = new char[nvar*kNchar+1];
634 x = new float[nvar];
635
636 chtag_out[nvar*kNchar]=0;
637 for (i=0;i<80;i++)chtitl[i]=0;
638#ifndef WIN32
639 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar);
640#else
641 hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]);
642#endif
643 hgnpar(id,"?",1);
644 char *name = chtag_out;
645 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
646 TTree *tree = new TTree(idname,chtitl);
647 Int_t first,last;
648 for(i=0; i<nvar;i++) {
649 name[kNchar-1] = 0;
650 first = last = 0;
651 // suppress trailing blanks
652 for (j=kNchar-2;j>0;j--) {
653 if(golower) name[j] = tolower(name[j]);
654 if (name[j] == ' ' && last == 0) name[j] = 0;
655 else last = j;
656 }
657 if (golower == 2) name[0] = tolower(name[0]);
658
659 // suppress heading blanks
660 for (j=0;j<kNchar;j++) {
661 if (name[j] != ' ') break;
662 first = j+1;
663 }
664 tree->Branch(&name[first],&x[i],&name[first],bufsize);
665 name += kNchar;
666 }
667 for(i=1;i<=nentries;i++) {
668 hgnf(id,i,x[0],ier);
669 tree->Fill();
670 }
671 tree->Write();
672 delete tree;
673 delete [] x;
674 delete [] chtag_out;
675}
676
677////////////////////////////////////////////////////////////////////////////////
678///convert column wise ntuple
679
681{
682 const int kNchar=9;
683 int nvar;
684 int ier=0;
685 int i,j;
686 int nsub,itype,isize,ielem;
687 char *chtag_out;
688 float *x;
689 float rmin[1000], rmax[1000];
690
691 if (id > 0) snprintf(idname,128,"h%d",id);
692 else snprintf(idname,128,"h_%d",-id);
693 hnoent(id,nentries);
694 printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
695 nvar=0;
696#ifndef WIN32
697 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
698#else
699 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
700#endif
701
702
703 chtag_out = new char[nvar*kNchar+1];
704 Int_t *charflag = new Int_t[nvar];
705 Int_t *lenchar = new Int_t[nvar];
706 Int_t *boolflag = new Int_t[nvar];
707 Int_t *lenbool = new Int_t[nvar];
708 UChar_t *boolarr = new UChar_t[10000];
709 x = new float[nvar];
710
711 chtag_out[nvar*kNchar]=0;
712 for (i=0;i<80;i++)chtitl[i]=0;
713#ifndef WIN32
714 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar);
715#else
716 hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]);
717#endif
718 Long_t add= (Long_t)&bigbuf[0];
719#ifndef WIN32
720 hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0,1,6);
721#else
722 hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0);
723#endif
724
725 Int_t bufpos = 0;
726 Int_t isachar = 0;
727 Int_t isabool = 0;
728 char fullname[1024];
729 char name[512];
730 char block[512];
731 char oldblock[512];
732 Int_t nbits = 0;
733 strlcpy(oldblock,"OLDBLOCK",512);
734 Int_t oldischar = -1;
735 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
736 TTree *tree = new TTree(idname,chtitl);
737 for(i=0; i<nvar;i++) {
738 memset(name,' ',sizeof(name));
739 name[sizeof(name)-1] = 0;
740 memset(block,' ',sizeof(block));
741 block[sizeof(block)-1] = 0;
742 memset(fullname,' ',sizeof(fullname));
743 fullname[sizeof(fullname)-1]=0;
744#ifndef WIN32
745 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,512,1024,512);
746#else
747 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
748#endif
749
750 for (j=510;j>0;j--) {
751 if(golower) name[j] = tolower(name[j]);
752 if (name[j] == ' ') name[j] = 0;
753 }
754 if (golower == 2) name[0] = tolower(name[0]);
755
756 for (j=1022;j>0;j--) {
757 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
758 // convert also character after [, if golower == 2
759 if (golower == 2) fullname[j] = tolower(fullname[j]);
760 if (fullname[j] == ' ') fullname[j] = 0;
761 }
762 // convert also first character, if golower == 2
763 if (golower == 2) fullname[0] = tolower(fullname[0]);
764 for (j=510;j>0;j--) {
765 if (block[j] == ' ') block[j] = 0;
766 else break;
767 }
768 if (itype == 1) {
769 if( isize == 4 ) strlcat(fullname,"/F",1024);
770 else if( isize == 8) strlcat(fullname,"/D",1024);
771 }
772
773
774 // add support for 1-byte (Char_t) and 2-byte (Short_t) integers
775 // Int_t nBytesUsed = 4; // default for integers
776
777 if( itype == 2 ) {
778 if( optcwn == 1 ) {
779 if( nbits > 16 ) {
780 strlcat(fullname,"/I",1024);
781 } else {
782 if( nbits > 8 ) {
783 strlcat(fullname,"/S",1024);
784 //nBytesUsed = 2;
785 } else {
786 strlcat(fullname,"/B",1024);
787 //nBytesUsed = 1;
788 }
789 }
790 } else {
791 strlcat(fullname,"/I",1024);
792 }
793 }
794
795 // add support for 1-byte (UChar_t) and 2-byte (UShort_t) integers
796 if ( itype == 3 ) {
797 if( optcwn == 1 ) {
798 if( nbits > 16) {
799 strlcat(fullname,"/i",1024);
800 } else {
801 if( nbits > 8 ) {
802 strlcat(fullname,"/s",1024);
803 //nBytesUsed = 2;
804 } else {
805 strlcat(fullname,"/b",1024);
806 //nBytesUsed = 1;
807 }
808 }
809 } else {
810 strlcat(fullname,"/i",1024);
811 }
812 }
813
814
815
816
817// if (itype == 4) strlcat(fullname,"/i",1024);
818 if (itype == 4) strlcat(fullname,"/b",1024);
819 if (itype == 5) strlcat(fullname,"/C",1024);
820 printf("Creating branch:%s, block:%s, fullname:%s, nsub=%d, itype=%d, isize=%d, ielem=%d\n",name,block,fullname,nsub,itype,isize,ielem);
821 Int_t ischar;
822 if (itype == 5) ischar = 1;
823 else ischar = 0;
824 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
825 strlcpy(oldblock,block,512);
826 oldischar = ischar;
827 Int_t lblock = strlen(block);
828 add= (Long_t)&bigbuf[bufpos];
829#ifndef WIN32
830 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
831#else
832 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
833#endif
834
835 }
836 TBranch *branch = tree->Branch(name,(void*)&bigbuf[bufpos],fullname,bufsize);
837 boolflag[i] = -10;
838 charflag[i] = 0;
839 if (itype == 4) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;}
840 bufpos += isize*ielem;
841 if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;}
842 TObjArray *ll= branch->GetListOfLeaves();
843 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
844 if (!leaf) continue;
845 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
846 if (leafcount) {
847 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
848 }
849 }
850 Int_t cf,l;
851 for(i=1;i<=nentries;i++) {
852 hgnt(id,i,ier);
853 if (isabool) { // if column is boolean
854 for (j=0;j<nvar;j++) {
855 cf = boolflag[j];
856 if (cf >-1) {
857 for (l=0;l<lenbool[j];l++) {
858#ifdef R__BYTESWAP
859 boolarr[l] = (UChar_t)bigbuf[cf+4*l];
860#else
861 boolarr[l] = (UChar_t)bigbuf[cf+4*l+3];
862#endif
863 }
864 memcpy(&bigbuf[cf],boolarr,lenbool[j]);
865 }
866 }
867 }
868 if (isachar) { // if column is character, set terminator
869 for (j=0;j<nvar;j++) {
870 cf = charflag[j];
871 if (cf) {
872 bigbuf[cf] = '\0';
873 if (bigbuf[cf-1] != ' ') continue;
874 bigbuf[cf-1] = '\0';
875 if (bigbuf[cf-2] != ' ') continue;
876 bigbuf[cf-2] = '\0';
877 }
878 }
879 }
880
881 // if optimizing cwn ntuple then look up bufpos and adjust integers to be shorts or chars
882 if( optcwn == 1 ) {
883 bufpos = 0;
884 for(int k=0; k<nvar;k++) {
885#ifndef WIN32
886 hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
887#else
888 hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
889#endif
890
891 Int_t nBytesUsed = 4; // default for integers
892
893 if ( itype == 2 || itype == 3) {
894 if( nbits > 16) {
895 // do nothing for integers of 4 byte
896 } else {
897 if( nbits > 8 ) nBytesUsed = 2;
898 else nBytesUsed = 1;
899 }
900 }
901
902 if(nBytesUsed == 1) {
903 for(Int_t index = 0; index < ielem; index++) {
904 // shift all chars with data to be one after another
905 bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize];
906 }
907 } else {
908 if(nBytesUsed == 2) {
909 for(Int_t index = 0; index < ielem; index++) {
910 // shift all shorts ( 2 chars) with data to be one after another
911 bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize];
912 bigbuf[bufpos + index*nBytesUsed+1 ] = bigbuf[bufpos + index * isize+1];
913 }
914 }
915 }
916 bufpos += isize*ielem;
917
918 }
919 }
920
921 tree->Fill();
922 }
923 tree->Print();
924 tree->Write();
925 delete tree;
926 delete [] x;
927 delete [] charflag;
928 delete [] lenchar;
929 delete [] boolflag;
930 delete [] lenbool;
931 delete [] boolarr;
932 delete [] chtag_out;
933}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
Definition RtypesCore.h:52
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
#define gDirectory
Definition TDirectory.h:385
XFontStruct * id
Definition TGX11.cxx:147
char name[80]
Definition TGX11.cxx:148
float xmin
#define quest
char idname[128]
int lcid
int nentries
float * q
int lcdir
const Int_t kMIN1
int ncx
char chtitl[128]
float ymin
const Int_t kMAX1
int nwt
int * iq
size_t fortran_charlen_t
#define hcbits
int idb
int ncy
float xmax
#define hcbook
#define PAWC_SIZE
#define type_of_call
int lcont
int * lq
float ymax
#define DEFCHAR
#define rzcl
#define pawc
#define NULL
Definition ZInflate.c:15
#define snprintf
Definition civetweb.c:1579
A TTree is a list of TBranches.
Definition TBranch.h:93
TObjArray * GetListOfLeaves()
Definition TBranch.h:256
A ROOT file is structured in Directories (like a file system).
Bool_t cd() override
Change current directory to "this" directory.
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write all objects in memory to disk.
Describe directory structure in memory.
Definition TDirectory.h:45
virtual Bool_t cd()
Change current directory to "this" directory.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
void ls(Option_t *option="") const override
List file contents.
Definition TFile.cxx:1470
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) override
Write memory objects to this file.
Definition TFile.cxx:2489
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3788
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:982
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
A TLeaf for an Integer data type.
Definition TLeafI.h:27
Int_t GetMaximum() const override
Definition TLeafI.h:44
virtual void SetMaximum(Int_t max)
Definition TLeafI.h:56
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
Definition TLeaf.h:124
An array of TObjects.
Definition TObjArray.h:31
Profile Histogram.
Definition TProfile.h:32
A TTree represents a columnar dataset.
Definition TTree.h:89
int main()
TH2F * h2
#define hi
Definition h2root.cxx:120
#define hrin
Definition h2root.cxx:103
void convert_rwn(Int_t id)
convert row wise ntuple
Definition h2root.cxx:612
Int_t golower
Definition h2root.cxx:267
void convert_directory(const char *)
convert a directory
Definition h2root.cxx:369
#define hix
Definition h2root.cxx:124
#define hgnpar
Definition h2root.cxx:108
#define hntvar2
Definition h2root.cxx:116
#define hdcofl
Definition h2root.cxx:112
#define rzink
Definition h2root.cxx:111
void convert_2d(Int_t id)
convert 2d histogram
Definition h2root.cxx:534
#define hlimit
Definition h2root.cxx:101
void convert_profile(Int_t id)
the following structure is used in Hbook lcid points to the profile in array iq lcont = lq(lcid-1) lw...
Definition h2root.cxx:576
#define hgive
Definition h2root.cxx:105
#define hropen
Definition h2root.cxx:102
#define hbnam
Definition h2root.cxx:119
#define hije
Definition h2root.cxx:126
#define zitoh
Definition h2root.cxx:128
#define hie
Definition h2root.cxx:121
#define hgiven
Definition h2root.cxx:106
#define hgnf
Definition h2root.cxx:109
Int_t bufsize
Definition h2root.cxx:268
#define hmaxim
Definition h2root.cxx:113
#define hminim
Definition h2root.cxx:114
void convert_1d(Int_t id)
convert 1d histogram
Definition h2root.cxx:480
#define hdelet
Definition h2root.cxx:115
#define bigbuf
Definition h2root.cxx:46
#define hgnt
Definition h2root.cxx:110
#define uhtoc
Definition h2root.cxx:129
#define hif
Definition h2root.cxx:122
#define hprntu
Definition h2root.cxx:107
#define hij
Definition h2root.cxx:123
void convert_cwn(Int_t id)
convert column wise ntuple
Definition h2root.cxx:680
#define hnoent
Definition h2root.cxx:104
#define hcdir
Definition h2root.cxx:127
#define PASSCHAR(string)
Definition h2root.cxx:133
#define hijxy
Definition h2root.cxx:125
Int_t optcwn
Definition h2root.cxx:269
mfile ls()
printf("Client 0: bytes recv = %d, bytes sent = %d\n", s0->GetBytesRecv(), s0->GetBytesSent())
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
TH1F * h1
Definition legend1.C:5
bool first
Definition line3Dfit.C:46
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:673
void dir(char *path=0)
Definition rootalias.C:42
TLine l
Definition textangle.C:4
TTree * tree