Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
THbookFile.cxx
Go to the documentation of this file.
1// @(#)root/hbook:$Id$
2// Author: Rene Brun 18/02/2002
3
4/*************************************************************************
5 * Copyright (C) 1995-2002, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class THbookFile
13 \ingroup Hist
14 This class is an interface to the Hbook objects in Hbook files.
15 Any Hbook object (1-D, 2-D, Profile, RWN or CWN can be read
16
17 NB: a THbookFile can only be used in READ mode
18 Use the utility in $ROOTSYS/bin/h2root to convert Hbook to Root
19
20 Example of use:
21
22 gSystem->Load("libHbook");
23 THbookFile f("myfile.hbook");
24 f.ls();
25 TH1F *h1 = (TH1F*)f.Get(1); //import histogram ID=1 in h1
26 h1->Fit("gaus");
27 THbookTree *T = (THbookTree*)f.Get(111); //import ntuple header
28 T->Print(); //show the Hbook ntuple variables
29 T->Draw("x","y<0"); // as in normal TTree::Draw
30
31 THbookFile can be browsed via TBrowser.
32*/
33
34#include "TROOT.h"
35#include "THbookFile.h"
36#include "TH2.h"
37#include "THbookTree.h"
38#include "THbookBranch.h"
39#include "THbookKey.h"
40#include "TGraph.h"
41#include "TProfile.h"
42#include "TTreeFormula.h"
43#include "TLeafI.h"
44#include "TBrowser.h"
45#include "TSystem.h"
46#include "TMath.h"
47#include "strlcpy.h"
48
49#include <cstdint>
50#include <cstdio>
51#include <cstdlib>
52#include <cstring>
53#include <cctype>
54
55// NOTE: THe following comments and declarations are a duplicate
56// of those in main/src/h2root.cxx
57
58// Note that with gcc3.4 or above the size of PAWC_SIZE must be the same
59// as in the Fortran definition in hbook.f and zebra
60// Also, the arrays must be declared extern like on Windows
61#define PAWC_SIZE 4000000
62
63// Define the names of the Fortran common blocks for the different OSs
64
65#ifndef WIN32
66# define pawc pawc_
67# define quest quest_
68# define hcbits hcbits_
69# define hcbook hcbook_
70# define rzcl rzcl_
71extern "C" int pawc[PAWC_SIZE];
72extern "C" int quest[100];
73extern "C" int hcbits[37];
74extern "C" int hcbook[51];
75extern "C" int rzcl[11];
76#else
77# define pawc PAWC
78# define quest QUEST
79# define hcbits HCBITS
80# define hcbook HCBOOK
81# define rzcl RZCL
82extern "C" int pawc[PAWC_SIZE];
83extern "C" int quest[100];
84extern "C" int hcbits[37];
85extern "C" int hcbook[51];
86extern "C" int rzcl[11];
87#endif
88
89int *iq, *lq;
90float *q;
91char idname[128];
93char chtitl[128];
97const Int_t kNRH = 6;
98const Int_t kMIN1 = 7;
99const Int_t kMAX1 = 8;
100
101static Int_t gLastEntry = -1;
102
103// Define the names of the Fortran subroutine and functions for the different OSs
104
105#ifndef WIN32
106# define hlimit hlimit_
107# define hldir hldir_
108# define hropen hropen_
109# define hrend hrend_
110# define hrin hrin_
111# define hnoent hnoent_
112# define hgive hgive_
113# define hgiven hgiven_
114# define hgnpar hgnpar_
115# define hgnf hgnf_
116# define hgnt hgnt_
117# define hgntf hgntf_
118# define hgnt1 hgnt1_
119# define rzink rzink_
120# define hdcofl hdcofl_
121# define hmaxim hmaxim_
122# define hminim hminim_
123# define hdelet hdelet_
124# define hntvar2 hntvar2_
125# define hntvar3 hntvar3_
126# define hbname hbname_
127# define hbnamc hbnamc_
128# define hbnam hbnam_
129# define hi hi_
130# define hie hie_
131# define hif hif_
132# define hij hij_
133# define hix hix_
134# define hijxy hijxy_
135# define hije hije_
136# define hcdir hcdir_
137
138# define type_of_call
139# define DEFCHAR const char*
140# define PASSCHAR(string) string
141
142// As recommended in
143// https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
144using fortran_charlen_t = size_t;
145
146#else
147# define hlimit HLIMIT
148# define hldir HLDIR
149# define hropen HROPEN
150# define hrend HREND
151# define hrin HRIN
152# define hnoent HNOENT
153# define hgive HGIVE
154# define hgiven HGIVEN
155# define hgnpar HGNPAR
156# define hgnf HGNF
157# define hgnt HGNT
158# define hgntf HGNTF
159# define hgnt1 HGNT1
160# define rzink RZINK
161# define hdcofl HDCOFL
162# define hmaxim HMAXIM
163# define hminim HMINIM
164# define hdelet HDELET
165# define hntvar2 HNTVAR2
166# define hntvar3 HNTVAR3
167# define hbname HBNAME
168# define hbnamc HBNAMC
169# define hbnam HBNAM
170# define hi HI
171# define hie HIE
172# define hif HIF
173# define hij HIJ
174# define hix HIX
175# define hijxy HIJXY
176# define hije HIJE
177# define hcdir HCDIR
178# define type_of_call _stdcall
179# define DEFCHAR const char*, const int
180# define PASSCHAR(string) string, strlen(string)
181#endif
182
183extern "C" void type_of_call hlimit(const int&);
184#ifndef WIN32
185extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
188#else
189extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
190 const int&,const int&);
191extern "C" void type_of_call hrend(DEFCHAR);
192#endif
193
194extern "C" void type_of_call hrin(const int&,const int&,const int&);
195extern "C" void type_of_call hnoent(const int&,const int&);
196#ifndef WIN32
197extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
198 const int&,const float&,const float&,const int&,const int&,fortran_charlen_t);
199#else
200extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
201 const int&,const float&,const float&,const int&,const int&);
202#endif
203
204 //SUBROUTINE HGNT1(IDD,BLKNA1,VAR,IOFFST,NVAR,IDNEVT,IERROR)
205#ifndef WIN32
206extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
207 const float&,const float&,fortran_charlen_t,fortran_charlen_t);
208extern "C" void type_of_call hgnt1(const int&,DEFCHAR,DEFCHAR,const int&,const int&,const int&,const int&,fortran_charlen_t,fortran_charlen_t);
209#else
210extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
211 const float&,const float&);
212extern "C" void type_of_call hgnt1(const int&,DEFCHAR,DEFCHAR,const int&,const int&,const int&,const int&);
213#endif
214
215#ifndef WIN32
216extern "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);
217extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR, fortran_charlen_t);
218#else
219extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&);
220extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR);
221#endif
222
223#ifndef WIN32
224extern "C" void type_of_call hbnam(const int&,DEFCHAR,const std::int64_t&,DEFCHAR,const int&,fortran_charlen_t, fortran_charlen_t);
225#else
226extern "C" void type_of_call hbnam(const int&,DEFCHAR,const std::int64_t&,DEFCHAR,const int&);
227#endif
228
229extern "C" void type_of_call hgnpar(const int&,const char *,const int);
230extern "C" void type_of_call hgnf(const int&,const int&,const float&,const int&);
231extern "C" void type_of_call hgnt(const int&,const int&,const int&);
232extern "C" void type_of_call hgntf(const int&,const int&,const int&);
233extern "C" void type_of_call rzink(const int&,const int&,const char *,const int);
234extern "C" void type_of_call hdcofl();
235extern "C" void type_of_call hmaxim(const int&,const float&);
236extern "C" void type_of_call hminim(const int&,const float&);
237extern "C" void type_of_call hdelet(const int&);
238extern "C" float type_of_call hi(const int&,const int&);
239extern "C" float type_of_call hie(const int&,const int&);
240extern "C" float type_of_call hif(const int&,const int&);
241extern "C" float type_of_call hij(const int&,const int&,const int&);
242extern "C" void type_of_call hix(const int&,const int&,const float&);
243extern "C" void type_of_call hijxy(const int&,const int&,const int&,const float&,const float&);
244extern "C" float type_of_call hije(const int&,const int&,const int&);
245#ifndef WIN32
248#else
249extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
250extern "C" void type_of_call hldir(DEFCHAR,DEFCHAR);
251#endif
252
254Int_t *THbookFile::fgLuns = nullptr;
255
256
257////////////////////////////////////////////////////////////////////////////////
258///the constructor
259
260THbookFile::THbookFile() : fLun(0),fLrecl(0)
261{
262 fList = new TList();
263 fKeys = new TList();
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// Constructor for an HBook file object
268
269THbookFile::THbookFile(const char *fname, Int_t lrecl)
270 :TNamed(fname,"")
271{
272 // Initialize the Hbook/Zebra store
273 Int_t i;
274 if (!fgPawInit) {
276 lq = &pawc[9];
277 iq = &pawc[17];
278 void *qq = iq;
279 q = (float*)qq;
280 int pawc_size = PAWC_SIZE;
281 hlimit(pawc_size);
282 fgLuns = new Int_t[10];
283 for (i=0;i<10;i++) fgLuns[i] = 0;
284 }
285
286 //find a free logical unit (max 10)
287 fLun = 0;
288 for (i=0;i<10;i++) {
289 if (fgLuns[i] == 0) {
290 fLun = 10+i;
291 fgLuns[i] = 1;
292 break;
293 }
294 }
295 if (fLun == 0) {
296 Error("THbookFile","Too many HbookFiles\n");
297 return;
298 }
299 char topdir[20];
300 snprintf(topdir,19,"lun%d",fLun);
301
302 Int_t ier = 0;
303#ifndef WIN32
304 hropen(fLun,PASSCHAR(topdir),PASSCHAR(fname),PASSCHAR("p"),lrecl,ier,strlen(topdir),strlen(fname),1);
305#else
306 hropen(fLun,PASSCHAR(topdir),PASSCHAR(fname),PASSCHAR("p"),lrecl,ier);
307#endif
308 fLrecl = lrecl;
309 SetTitle(topdir);
310 snprintf(topdir,19,"//lun%d",fLun);
311 fCurDir = topdir;
312
313 if (ier) printf (" Error on hropen was %d \n", ier);
314 if (quest[0]) {
315 printf("Error cannot open input file: %s\n",fname);
316 }
317 if (ier || quest[0]) {
318 fgLuns[fLun-10]=0;
319 fLun = 0;
320 fList = nullptr;
321 fKeys = nullptr;
322 MakeZombie();
323 return;
324 }
325
326 gROOT->GetListOfBrowsables()->Add(this,fname);
327
328 fList = new TList();
329 fKeys = new TList();
330 for (Int_t key=1;key<1000000;key++) {
331 int z0 = 0;
332 rzink(key,z0,"S",1);
333 if (quest[0]) break;
334 if (quest[13] & 8) continue;
335 Int_t id = quest[20];
336 THbookKey *akey = new THbookKey(id,this);
337 fKeys->Add(akey);
338 }
339}
340
341////////////////////////////////////////////////////////////////////////////////
342///destructor
343
345{
346 if (!fList) return;
347 Close();
348 delete fList;
349 delete fKeys;
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// to be implemented
354
356{
357 if( b ) {
358 b->Add(fList, "memory");
359 b->Add(fKeys, "IDs on disk");
360 }
361 cd();
362}
363
364////////////////////////////////////////////////////////////////////////////////
365/// change directory to dirname
366
367Bool_t THbookFile::cd(const char *dirname)
368{
369 Int_t nch = strlen(dirname);
370 if (nch == 0) {
371#ifndef WIN32
373#else
375#endif
376 return kTRUE;
377 }
378
379 char cdir[512];
380 Int_t i;
381 for (i=0;i<512;i++) cdir[i] = ' ';
382 cdir[511] = 0;
383#ifndef WIN32
384 hcdir(PASSCHAR(dirname),PASSCHAR(" "),nch,1);
385 hcdir(PASSCHAR(cdir),PASSCHAR("R"),511,1);
386#else
387 hcdir(PASSCHAR(dirname),PASSCHAR(" "));
388 hcdir(PASSCHAR(cdir),PASSCHAR("R"));
389#endif
390 for (i=510;i>=0;i--) {
391 if (cdir[i] != ' ') break;
392 cdir[i] = 0;
393 }
394 fCurDir = cdir;
395 printf("fCurdir=%s\n",fCurDir.Data());
396
397 return kTRUE;
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Close the Hbook file
402
404{
405 if(!IsOpen()) return;
406 if (!fList) return;
407
408 gROOT->GetListOfBrowsables()->Remove(this);
409
410 cd();
411
412 fList->Delete();
413 fKeys->Delete();
414 if (fgLuns) fgLuns[fLun-10] = 0;
415 hdelet(0);
416#ifndef WIN32
417 hrend(PASSCHAR(GetTitle()),strlen(GetTitle()));
418#else
420#endif
421}
422
423////////////////////////////////////////////////////////////////////////////////
424///remove id from file and memory
425
427{
428 hdelet(id);
429}
430
431////////////////////////////////////////////////////////////////////////////////
432/// return object with name in fList in memory
433
435{
436 return fList->FindObject(name);
437}
438
439////////////////////////////////////////////////////////////////////////////////
440/// return object with pointer obj in fList in memory
441
443{
444 return fList->FindObject(obj);
445}
446
447////////////////////////////////////////////////////////////////////////////////
448/// import Hbook object with identifier idd in memory
449
451{
452 Int_t id = 0;
453 for (Int_t key=1;key<1000000;key++) {
454 int z0 = 0;
455 rzink(key,z0,"S",1);
456 if (quest[0]) break;
457 if (quest[13] & 8) continue;
458 id = quest[20];
459 if (id == idd) break;
460 }
461 if (id == 0) return nullptr;
462 if (id != idd) {
463 printf("Error cannot find ID = %d\n",idd);
464 return nullptr;
465 }
466
467 int i999 = 999;
468 // must delete any previous object with the same ID !!
469 lcdir = hcbook[6];
470 ltab = hcbook[9];
471 for (Int_t i=1;i<=iq[lcdir+kNRH];i++) {
472 if (iq[ltab+i] == id) {
473 printf("WARNING, previous ID=%d is replaced\n",id);
474 hdelet(id);
475 break;
476 }
477 }
478 hrin(id,i999,0);
479 if (quest[0]) {
480 printf("Error cannot read ID = %d\n",id);
481 return nullptr;
482 }
483 hdcofl();
484 lcid = hcbook[10];
485 lcont = lq[lcid-1];
486 TObject *obj = nullptr;
487 if (hcbits[3]) {
488 if (iq[lcid-2] == 2) obj = ConvertRWN(id);
489 else obj = ConvertCWN(id);
490 //hdelet(id); //cannot be deleted here since used in GetEntry
491 if (obj) {
492 fList->Add(obj);
493 ((THbookTree *)obj)->SetTitle(GetName());
494 }
495 return obj;
496 }
497 if (hcbits[0] && hcbits[7]) {
498 obj = ConvertProfile(id);
499 hdelet(id);
500 if (obj) fList->Add(obj);
501 return obj;
502 }
503 if (hcbits[0]) {
504 obj = Convert1D(id);
505 hdelet(id);
506 if (obj) fList->Add(obj);
507 return obj;
508 }
509 if (hcbits[1] || hcbits[2]) {
510 obj = Convert2D(id);
511 hdelet(id);
512 if (obj) fList->Add(obj);
513 return obj;
514 }
515 return obj;
516}
517
518
519////////////////////////////////////////////////////////////////////////////////
520/// Read in memory all columns of entry number of ntuple id from the Hbook file
521
523{
524 Int_t ier = 0;
525 if (atype == 0) {
526 hgnf(id,entry+1,x[0],ier);
527 } else {
528 hgnt(id,entry+1,ier);
529 }
530 return 0;
531}
532
533////////////////////////////////////////////////////////////////////////////////
534/// Read in memory only the branch bname
535
537{
538 if (entry == gLastEntry) return 0;
539 gLastEntry = entry;
540 Int_t ier = 0;
541 //uses the fast read method using the Hbook tables computed in InitLeaves
542 hgntf(id,entry+1,ier);
543 //old alternative slow method
544//#ifndef WIN32
545// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier,strlen(blockname),strlen(branchname));
546//#else
547// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier);
548//#endif
549 return 0;
550}
551
552
553////////////////////////////////////////////////////////////////////////////////
554/// This function is called from the first entry in TTreePlayer::InitLoop
555/// It analyzes the list of variables involved in the current query
556/// and pre-process the internal Hbook tables to speed-up the search
557/// at the next entries.
558
560{
561 if (!formula) return;
562 Int_t ncodes = formula->GetNcodes();
563 for (Int_t i=1;i<=ncodes;i++) {
564 TLeaf *leaf = formula->GetLeaf(i-1);
565 if (!leaf) continue;
566 if (var == 5) {
567 //leafcount may be null in case of a fix size array
568 if (leaf->GetLeafCount()) leaf = leaf->GetLeafCount();
569 }
570 Int_t last = 0;
571 if (var == 1 && i == ncodes) last = 1;
572#ifndef WIN32
573 hntvar3(id,last,PASSCHAR(leaf->GetName()),strlen(leaf->GetName()));
574#else
575 hntvar3(id,last,PASSCHAR(leaf->GetName()));
576#endif
577 }
578}
579
580////////////////////////////////////////////////////////////////////////////////
581/// Returns kTRUE in case file is open and kFALSE if file is not open.
582
584{
585 return fLun == 0 ? kFALSE : kTRUE;
586}
587
588
589////////////////////////////////////////////////////////////////////////////////
590///Set branch address
591
592void THbookFile::SetBranchAddress(Int_t id, const char *bname, void *add)
593{
594 std::int64_t aadd = reinterpret_cast<std::int64_t>(add);
595#ifndef WIN32
596 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0,strlen(bname),4);
597#else
598 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0);
599#endif
600}
601
602////////////////////////////////////////////////////////////////////////////////
603/// Convert this Hbook file to a Root file with name rootname.
604/// if rootname="', rootname = hbook file name with .root instead of .hbook
605/// By default, the Root file is connected and returned
606/// option:
607/// - "NO" do not connect the Root file
608/// - "C" do not compress file (default is to compress)
609/// - "L" do not convert names to lower case (default is to convert)
610
611TFile *THbookFile::Convert2root(const char *rootname, Int_t /*lrecl*/,
613{
614 TString opt = option;
615 opt.ToLower();
616
617 Int_t nch = strlen(rootname);
618 char *rfile=nullptr;
619 if (nch) {
620 rfile = new char[nch+1];
621 strlcpy(rfile,rootname,nch+1);
622 } else {
623 nch = strlen(GetName());
624 rfile = new char[nch+1];
625 strlcpy(rfile,GetName(),nch+1);
626 char *dot = strrchr(rfile,'.');
627 if (dot) strcpy(dot+1,"root");
628 else strlcat(rfile,".root",nch+1);
629 }
630
631 nch = 2*nch+50;
632 char *cmd = new char[nch+1];
633 snprintf(cmd,nch,"h2root %s %s",GetName(),rfile);
634 if (opt.Contains("c")) strlcat (cmd," 0",nch+1);
635 if (opt.Contains("l")) strlcat (cmd," 0",nch+1);
636
637 gSystem->Exec(cmd);
638
639 delete [] cmd;
640 if (opt.Contains("no")) {delete [] rfile; return nullptr;}
641 TFile *f = new TFile(rfile);
642 delete [] rfile;
643 if (f->IsZombie()) {delete f; f = nullptr;}
644 return f;
645}
646
647
648////////////////////////////////////////////////////////////////////////////////
649/// Convert the Column-Wise-Ntuple id to a Root Tree
650
652{
653 const int nchar=9;
654 int nvar;
655 int i,j;
656 int nsub,itype,isize,ielem;
657 char *chtag_out;
658 float rmin[1000], rmax[1000];
659
660 if (id > 0) snprintf(idname,127,"h%d",id);
661 else snprintf(idname,127,"h_%d",-id);
662 hnoent(id,nentries);
663 //printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
664 nvar=0;
665#ifndef WIN32
666 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
667#else
668 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
669#endif
670 chtag_out = new char[nvar*nchar+1];
671 Int_t *charflag = new Int_t[nvar];
672 Int_t *lenchar = new Int_t[nvar];
673 Int_t *boolflag = new Int_t[nvar];
674 Int_t *lenbool = new Int_t[nvar];
675 UChar_t *boolarr = new UChar_t[10000];
676
677 chtag_out[nvar*nchar]=0;
678 for (i=0;i<80;i++)chtitl[i]=0;
679#ifndef WIN32
680 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
681#else
682 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
683#endif
684
685 Int_t bufpos = 0;
686 //Int_t isachar = 0;
687 //Int_t isabool = 0;
688 char fullname[64];
689 char name[32];
690 char block[32];
691 char oldblock[32];
692 strlcpy(oldblock,"OLDBLOCK",32);
693 Int_t oldischar = -1;
694 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
695 THbookTree *tree = new THbookTree(idname,id);
696 tree->SetHbookFile(this);
697 tree->SetType(1);
698
699 char *bigbuf = tree->MakeX(500000);
700
701 std::int64_t add = reinterpret_cast<std::int64_t>(&bigbuf[0]);
702#ifndef WIN32
703 hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0,1,6);
704#else
705 hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0);
706#endif
707
708 UInt_t varNumber = 0;
709 Int_t golower = 1;
710 Int_t nbits = 0;
711 for(i=0; i<nvar;i++) {
712 memset(name,' ',sizeof(name));
713 name[sizeof(name)-1] = 0;
714 memset(block,' ',sizeof(block));
715 block[sizeof(block)-1] = 0;
716 memset(fullname,' ',sizeof(fullname));
717 fullname[sizeof(fullname)-1]=0;
718#ifndef WIN32
719 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
720#else
721 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
722#endif
723 TString hbookName = name;
724
725 for (j=30;j>0;j--) {
726 if(golower) name[j] = tolower(name[j]);
727 if (name[j] == ' ') name[j] = 0;
728 }
729 if (golower == 2) name[0] = tolower(name[0]);
730
731 for (j=62;j>0;j--) {
732 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
733 // convert also character after [, if golower == 2
734 if (golower == 2) fullname[j] = tolower(fullname[j]);
735 if (fullname[j] == ' ') fullname[j] = 0;
736 }
737 // convert also first character, if golower == 2
738 if (golower == 2) fullname[0] = tolower(fullname[0]);
739 for (j=30;j>0;j--) {
740 if (block[j] == ' ') block[j] = 0;
741 else break;
742 }
743 if (itype == 1 && isize == 4) strlcat(fullname,"/F",64);
744 if (itype == 1 && isize == 8) strlcat(fullname,"/D",64);
745 if (itype == 2) strlcat(fullname,"/I",64);
746 if (itype == 3) strlcat(fullname,"/i",64);
747// if (itype == 4) strlcat(fullname,"/i",64);
748 if (itype == 4) strlcat(fullname,"/b",64);
749 if (itype == 5) strlcat(fullname,"/C",64);
750//printf("Creating branch:%s, block:%s, fullname:%s, nsub=%d, itype=%d, isize=%d, ielem=%d, bufpos=%d\n",name,block,fullname,nsub,itype,isize,ielem,bufpos);
751 Int_t ischar;
752 if (itype == 5) ischar = 1;
753 else ischar = 0;
754
755 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
756 varNumber = 0;
757 strlcpy(oldblock,block,32);
758 oldischar = ischar;
759 add = reinterpret_cast<std::int64_t>(&bigbuf[bufpos]);
760 Int_t lblock = strlen(block);
761#ifndef WIN32
762 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
763#else
764 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
765#endif
766
767 }
768
769 Int_t bufsize = 8000;
770 THbookBranch *branch = new THbookBranch(tree,name,(void*)&bigbuf[bufpos],fullname,bufsize);
771 tree->GetListOfBranches()->Add(branch);
772 branch->SetBlockName(block);
773 branch->SetUniqueID(varNumber);
774 varNumber++;
775
776 //NB: the information about isachar should be saved in the branch
777 // to be done
778 boolflag[i] = -10;
779 charflag[i] = 0;
780 if (itype == 4) {
781 //isabool++;
782 boolflag[i] = bufpos;
783 lenbool[i] = ielem;
784 }
785 bufpos += isize*ielem;
786 if (ischar) {
787 //isachar++;
788 charflag[i] = bufpos - 1;
789 lenchar[i] = isize * ielem;
790 }
791 TObjArray *ll= branch->GetListOfLeaves();
792 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
793 if (!leaf) continue;
794 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
795 if (leafcount) {
796 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
797 }
798 }
799 tree->SetEntries(nentries);
800 delete [] charflag;
801 delete [] lenchar;
802 delete [] boolflag;
803 delete [] lenbool;
804 delete [] boolarr;
805 delete [] chtag_out;
806
807 return tree;
808}
809
810////////////////////////////////////////////////////////////////////////////////
811/// Convert the Row-Wise-Ntuple id to a Root Tree
812
814{
815 const int nchar=9;
816 int nvar;
817 int i,j;
818 char *chtag_out;
819 float rmin[1000], rmax[1000];
820
821 if (id > 0) snprintf(idname,127,"h%d",id);
822 else snprintf(idname,127,"h_%d",-id);
823 hnoent(id,nentries);
824 //printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
825 nvar=0;
826#ifndef WIN32
827 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
828#else
829 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
830#endif
831
832 chtag_out = new char[nvar*nchar+1];
833
834 Int_t golower = 1;
835 chtag_out[nvar*nchar]=0;
836 for (i=0;i<80;i++)chtitl[i]=0;
837#ifndef WIN32
838 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
839#else
840 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
841#endif
842 hgnpar(id,"?",1);
843 char *name = chtag_out;
844 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
845 THbookTree *tree = new THbookTree(idname,id);
846 tree->SetHbookFile(this);
847 tree->SetType(0);
848 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
849
850 Int_t first,last;
851 for(i=0; i<nvar;i++) {
852 name[nchar-1] = 0;
853 first = last = 0;
854 TString hbookName = name;
855 // suppress trailing blanks
856 for (j=nchar-2;j>0;j--) {
857 if(golower) name[j] = tolower(name[j]);
858 if (name[j] == ' ' && last == 0) name[j] = 0;
859 else last = j;
860 }
861 if (golower == 2) name[0] = tolower(name[0]);
862
863 // suppress heading blanks
864 for (j=0;j<nchar;j++) {
865 if (name[j] != ' ') break;
866 first = j+1;
867 }
868 Int_t bufsize = 8000;
869 //tree->Branch(&name[first],&x[i],&name[first],bufsize);
870 THbookBranch *branch = new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
871 branch->SetAddress(&x[i]);
872 branch->SetBlockName(hbookName.Data());
873 tree->GetListOfBranches()->Add(branch);
874 name += nchar;
875 }
876 tree->SetEntries(nentries);
877 delete [] chtag_out;
878
879 return tree;
880}
881
882////////////////////////////////////////////////////////////////////////////////
883/// Convert an Hbook profile histogram into a Root TProfile
884///
885/// the following structure is used in Hbook
886/// lcid points to the profile in array iq
887/// lcont = lq(lcid-1)
888/// lw = lq(lcont)
889/// ln = lq(lw)
890/// if option S jbyt(iq(lw),1,2) = 1
891/// if option I jbyt(iq(lw),1,2) = 2
892
894{
895 if (id > 0) snprintf(idname,127,"h%d",id);
896 else snprintf(idname,127,"h_%d",-id);
897 hnoent(id,nentries);
898 Int_t lw = lq[lcont];
899 Int_t ln = lq[lw];
900#ifndef WIN32
902#else
904#endif
905 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
906 chtitl[4*nwt] = 0;
907 const char *option= " ";
908 if (iq[lw] == 1) option = "S";
909 if (iq[lw] == 2) option = "I";
911
912 const Int_t kCON1 = 9;
913 Int_t i;
914 Float_t x = 0.0;
915 Float_t y = 0.5*(ymin+ymax);
916 for (i=1;i<=ncx;i++) {
917 Int_t n = Int_t(q[ln+i]);
918 hix(id,i,x);
919 for (Int_t j=0;j<n;j++) {
920 p->Fill(x+offsetx,y);
921 }
922 Float_t content = q[lcont+kCON1+i];
923 Float_t error = TMath::Sqrt(q[lw+i]);
924 p->SetBinContent(i,content);
925 p->SetBinError(i,error);
926 }
927 p->SetEntries(nentries);
928 return p;
929}
930
931////////////////////////////////////////////////////////////////////////////////
932/// Convert an Hbook 1-d histogram into a Root TH1F
933
935{
936 if (id > 0) snprintf(idname,127,"h%d",id);
937 else snprintf(idname,127,"h_%d",-id);
938 hnoent(id,nentries);
939#ifndef WIN32
941#else
943#endif
944 chtitl[4*nwt] = 0;
945 TH1F *h1;
946 Int_t i;
947 if (hcbits[5]) {
948 Int_t lbins = lq[lcid-2];
949 Double_t *xbins = new Double_t[ncx+1];
950 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
951 h1 = new TH1F(idname,chtitl,ncx,xbins);
952 delete [] xbins;
953 } else {
955 }
956 if (hcbits[8]) h1->Sumw2();
957 TGraph *gr = nullptr;
958 if (hcbits[11]) {
959 gr = new TGraph(ncx);
961 }
962
963 Float_t x;
964 for (i=0;i<=ncx+1;i++) {
965 x = h1->GetBinCenter(i);
966 h1->Fill(x,hi(id,i));
967 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
968 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
969 }
970 Float_t yymin, yymax;
971 if (hcbits[19]) {
972 yymax = q[lcid+kMAX1];
973 h1->SetMaximum(yymax);
974 }
975 if (hcbits[20]) {
976 yymin = q[lcid+kMIN1];
977 h1->SetMinimum(yymin);
978 }
980 return h1;
981}
982
983////////////////////////////////////////////////////////////////////////////////
984/// Convert an Hbook 2-d histogram into a Root TH2F
985
987{
988 if (id > 0) snprintf(idname,127,"h%d",id);
989 else snprintf(idname,127,"h_%d",-id);
990 hnoent(id,nentries);
991#ifndef WIN32
993#else
995#endif
996 chtitl[4*nwt] = 0;
998 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
999 Float_t offsety = 0.5*(ymax-ymin)/ncy;
1000 Int_t lw = lq[lcont];
1001 if (lw) h2->Sumw2();
1002
1003 Float_t x = 0.0, y = 0.0;
1004 for (Int_t j=0;j<=ncy+1;j++) {
1005 for (Int_t i=0;i<=ncx+1;i++) {
1006 hijxy(id,i,j,x,y);
1007 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
1008 if (lw) {
1009 Double_t err2 = hije(id,i,j);
1010 h2->SetBinError(i,j,err2);
1011 }
1012 }
1013 }
1014 h2->SetEntries(nentries);
1015 return h2;
1016}
1017
1018////////////////////////////////////////////////////////////////////////////////
1019/// List contents of Hbook directory
1020
1021void THbookFile::ls(const char *path) const
1022{
1023 Int_t nch = strlen(path);
1024 if (nch == 0) {
1025#ifndef WIN32
1027#else
1029#endif
1030 return;
1031 }
1032
1033#ifndef WIN32
1034 hldir(PASSCHAR(path),PASSCHAR("T"),strlen(path),1);
1035#else
1036 hldir(PASSCHAR(path),PASSCHAR("T"));
1037#endif
1038}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
Definition RtypesCore.h:53
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
const char Option_t
Option string (const char)
Definition RtypesCore.h:81
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t nchar
char name[80]
Definition TGX11.cxx:142
float xmin
#define quest
#define hi
#define hgnt1
#define hrin
char idname[128]
#define hrend
int lcid
int nentries
float * q
#define hix
int lcdir
#define hgnpar
#define hntvar2
#define hdcofl
const Int_t kMIN1
int ncx
char chtitl[128]
float ymin
#define rzink
#define hntvar3
#define hlimit
const Int_t kMAX1
int nwt
static Int_t gLastEntry
#define hgive
int * iq
#define hropen
#define hbnam
size_t fortran_charlen_t
#define hije
#define hie
#define hgiven
#define hcbits
int idb
int ncy
float xmax
#define hgnf
#define hcbook
#define PAWC_SIZE
#define type_of_call
int lcont
#define hmaxim
#define hldir
#define hgntf
int * lq
#define hminim
#define hdelet
#define hgnt
float ymax
#define hif
#define DEFCHAR
int ltab
#define hij
#define hnoent
#define hcdir
#define PASSCHAR(string)
#define rzcl
const Int_t kNRH
#define pawc
#define hijxy
#define gROOT
Definition TROOT.h:417
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
TObjArray * GetListOfLeaves()
Definition TBranch.h:256
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2386
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9371
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:652
virtual void SetBinError(Int_t bin, Double_t error)
Set the bin Error Note that this resets the bin eror option to be of Normal Type and for the non-empt...
Definition TH1.cxx:9436
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3489
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:653
TList * GetListOfFunctions() const
Definition TH1.h:488
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9253
virtual void SetEntries(Double_t n)
Definition TH1.h:639
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:368
HBOOK Branch.
void SetAddress(void *addobj) override
Set address of this branch See important remark in the header of THbookTree.
void SetBlockName(const char *name)
void InitLeaves(Int_t id, Int_t var, TTreeFormula *formula)
This function is called from the first entry in TTreePlayer::InitLoop It analyzes the list of variabl...
Int_t fLun
Definition THbookFile.h:32
TObject * Get(Int_t id)
import Hbook object with identifier idd in memory
static Bool_t fgPawInit
Definition THbookFile.h:38
Int_t fLrecl
Definition THbookFile.h:33
void DeleteID(Int_t id)
remove id from file and memory
Int_t GetEntryBranch(Int_t entry, Int_t id)
Read in memory only the branch bname.
virtual void Close(Option_t *option="")
Close the Hbook file.
TString fCurDir
Definition THbookFile.h:36
TList * fList
Definition THbookFile.h:34
void ls(const char *path="") const override
List contents of Hbook directory.
virtual void SetBranchAddress(Int_t id, const char *bname, void *add)
Set branch address.
virtual Bool_t cd(const char *dirname="")
change directory to dirname
~THbookFile() override
destructor
THbookFile()
the constructor
static Int_t * fgLuns
Definition THbookFile.h:39
TList * fKeys
Definition THbookFile.h:35
TObject * FindObject(const char *name) const override
return object with name in fList in memory
virtual TObject * Convert1D(Int_t id)
Convert an Hbook 1-d histogram into a Root TH1F.
virtual TObject * ConvertProfile(Int_t id)
Convert an Hbook profile histogram into a Root TProfile.
virtual TFile * Convert2root(const char *rootname="", Int_t lrecl=0, Option_t *option="")
Convert this Hbook file to a Root file with name rootname.
virtual Bool_t IsOpen() const
Returns kTRUE in case file is open and kFALSE if file is not open.
virtual TObject * Convert2D(Int_t id)
Convert an Hbook 2-d histogram into a Root TH2F.
virtual TObject * ConvertCWN(Int_t id)
Convert the Column-Wise-Ntuple id to a Root Tree.
void Browse(TBrowser *b) override
to be implemented
Int_t GetEntry(Int_t entry, Int_t id, Int_t atype, Float_t *x)
Read in memory all columns of entry number of ntuple id from the Hbook file.
virtual TObject * ConvertRWN(Int_t id)
Convert the Row-Wise-Ntuple id to a Root Tree.
HBOOK Key.
Definition THbookKey.h:26
A wrapper class supporting Hbook ntuples (CWN and RWN).
Definition THbookTree.h:30
virtual void SetType(Int_t atype)
Definition THbookTree.h:53
char * MakeX(Int_t nvars)
Definition THbookTree.h:49
Long64_t SetEntries(Long64_t n=-1) override
Set the number of entries in the tree header and its branches.
virtual void SetHbookFile(THbookFile *file)
Definition THbookTree.h:52
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
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
An array of TObjects.
Definition TObjArray.h:31
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:90
void Add(TObject *obj) override
Definition TObjArray.h:68
Mother of all ROOT objects.
Definition TObject.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1096
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:897
void MakeZombie()
Definition TObject.h:55
Profile Histogram.
Definition TProfile.h:32
Basic string class.
Definition TString.h:137
Ssiz_t Length() const
Definition TString.h:426
void ToLower()
Change string to lower-case.
Definition TString.cxx:1190
const char * Data() const
Definition TString.h:385
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:642
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:656
Used to pass a selection expression to the Tree drawing routine.
virtual TLeaf * GetLeaf(Int_t n) const
Return leaf corresponding to serial number n.
virtual Int_t GetNcodes() const
virtual TObjArray * GetListOfBranches()
Definition TTree.h:589
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
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:675