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