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
260
261////////////////////////////////////////////////////////////////////////////////
262///the constructor
263
264THbookFile::THbookFile() : fLun(0),fLrecl(0)
265{
266 fList = new TList();
267 fKeys = new TList();
268}
269
270////////////////////////////////////////////////////////////////////////////////
271/// Constructor for an HBook file object
272
274 :TNamed(fname,"")
275{
276 // Initialize the Hbook/Zebra store
277 Int_t i;
278 if (!fgPawInit) {
280 lq = &pawc[9];
281 iq = &pawc[17];
282 void *qq = iq;
283 q = (float*)qq;
284 int pawc_size = PAWC_SIZE;
286 fgLuns = new Int_t[10];
287 for (i=0;i<10;i++) fgLuns[i] = 0;
288 }
289
290 //find a free logical unit (max 10)
291 fLun = 0;
292 for (i=0;i<10;i++) {
293 if (fgLuns[i] == 0) {
294 fLun = 10+i;
295 fgLuns[i] = 1;
296 break;
297 }
298 }
299 if (fLun == 0) {
300 Error("THbookFile","Too many HbookFiles\n");
301 return;
302 }
303 char topdir[20];
304 snprintf(topdir,19,"lun%d",fLun);
305
306 Int_t ier = 0;
307#ifndef WIN32
309#else
311#endif
312 fLrecl = lrecl;
314 snprintf(topdir,19,"//lun%d",fLun);
315 fCurDir = topdir;
316
317 if (ier) printf (" Error on hropen was %d \n", ier);
318 if (quest[0]) {
319 printf("Error cannot open input file: %s\n",fname);
320 }
321 if (ier || quest[0]) {
322 fgLuns[fLun-10]=0;
323 fLun = 0;
324 fList = nullptr;
325 fKeys = nullptr;
326 MakeZombie();
327 return;
328 }
329
330 gROOT->GetListOfBrowsables()->Add(this,fname);
331
332 fList = new TList();
333 fKeys = new TList();
334 for (Int_t key=1;key<1000000;key++) {
335 int z0 = 0;
336 rzink(key,z0,"S",1);
337 if (quest[0]) break;
338 if (quest[13] & 8) continue;
339 Int_t id = quest[20];
340 THbookKey *akey = new THbookKey(id,this);
341 fKeys->Add(akey);
342 }
343}
344
345////////////////////////////////////////////////////////////////////////////////
346///destructor
347
349{
350 if (!fList) return;
351 Close();
352 delete fList;
353 delete fKeys;
354}
355
356////////////////////////////////////////////////////////////////////////////////
357/// to be implemented
358
360{
361 if( b ) {
362 b->Add(fList, "memory");
363 b->Add(fKeys, "IDs on disk");
364 }
365 cd();
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// change directory to dirname
370
372{
374 if (nch == 0) {
375#ifndef WIN32
377#else
379#endif
380 return kTRUE;
381 }
382
383 char cdir[512];
384 Int_t i;
385 for (i=0;i<512;i++) cdir[i] = ' ';
386 cdir[511] = 0;
387#ifndef WIN32
389 hcdir(PASSCHAR(cdir),PASSCHAR("R"),511,1);
390#else
393#endif
394 for (i=510;i>=0;i--) {
395 if (cdir[i] != ' ') break;
396 cdir[i] = 0;
397 }
398 fCurDir = cdir;
399 printf("fCurdir=%s\n",fCurDir.Data());
400
401 return kTRUE;
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Close the Hbook file
406
408{
409 if(!IsOpen()) return;
410 if (!fList) return;
411
412 gROOT->GetListOfBrowsables()->Remove(this);
413
414 cd();
415
416 fList->Delete();
417 fKeys->Delete();
418 if (fgLuns) fgLuns[fLun-10] = 0;
419 hdelet(0);
420#ifndef WIN32
422#else
424#endif
425}
426
427////////////////////////////////////////////////////////////////////////////////
428///remove id from file and memory
429
431{
432 hdelet(id);
433}
434
435////////////////////////////////////////////////////////////////////////////////
436/// return object with name in fList in memory
437
439{
440 return fList->FindObject(name);
441}
442
443////////////////////////////////////////////////////////////////////////////////
444/// return object with pointer obj in fList in memory
445
447{
448 return fList->FindObject(obj);
449}
450
451////////////////////////////////////////////////////////////////////////////////
452/// import Hbook object with identifier idd in memory
453
455{
456 Int_t id = 0;
457 for (Int_t key=1;key<1000000;key++) {
458 int z0 = 0;
459 rzink(key,z0,"S",1);
460 if (quest[0]) break;
461 if (quest[13] & 8) continue;
462 id = quest[20];
463 if (id == idd) break;
464 }
465 if (id == 0) return nullptr;
466 if (id != idd) {
467 printf("Error cannot find ID = %d\n",idd);
468 return nullptr;
469 }
470
471 int i999 = 999;
472 // must delete any previous object with the same ID !!
473 lcdir = hcbook[6];
474 ltab = hcbook[9];
475 for (Int_t i=1;i<=iq[lcdir+kNRH];i++) {
476 if (iq[ltab+i] == id) {
477 printf("WARNING, previous ID=%d is replaced\n",id);
478 hdelet(id);
479 break;
480 }
481 }
482 hrin(id,i999,0);
483 if (quest[0]) {
484 printf("Error cannot read ID = %d\n",id);
485 return nullptr;
486 }
487 hdcofl();
488 lcid = hcbook[10];
489 lcont = lq[lcid-1];
490 TObject *obj = nullptr;
491 if (hcbits[3]) {
492 if (iq[lcid-2] == 2) obj = ConvertRWN(id);
493 else obj = ConvertCWN(id);
494 //hdelet(id); //cannot be deleted here since used in GetEntry
495 if (obj) {
496 fList->Add(obj);
497 ((THbookTree *)obj)->SetTitle(GetName());
498 }
499 return obj;
500 }
501 if (hcbits[0] && hcbits[7]) {
502 obj = ConvertProfile(id);
503 hdelet(id);
504 if (obj) fList->Add(obj);
505 return obj;
506 }
507 if (hcbits[0]) {
508 obj = Convert1D(id);
509 hdelet(id);
510 if (obj) fList->Add(obj);
511 return obj;
512 }
513 if (hcbits[1] || hcbits[2]) {
514 obj = Convert2D(id);
515 hdelet(id);
516 if (obj) fList->Add(obj);
517 return obj;
518 }
519 return obj;
520}
521
522
523////////////////////////////////////////////////////////////////////////////////
524/// Read in memory all columns of entry number of ntuple id from the Hbook file
525
527{
528 Int_t ier = 0;
529 if (atype == 0) {
530 hgnf(id,entry+1,x[0],ier);
531 } else {
532 hgnt(id,entry+1,ier);
533 }
534 return 0;
535}
536
537////////////////////////////////////////////////////////////////////////////////
538/// Read in memory only the branch bname
539
541{
542 if (entry == gLastEntry) return 0;
544 Int_t ier = 0;
545 //uses the fast read method using the Hbook tables computed in InitLeaves
546 hgntf(id,entry+1,ier);
547 //old alternative slow method
548//#ifndef WIN32
549// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier,strlen(blockname),strlen(branchname));
550//#else
551// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier);
552//#endif
553 return 0;
554}
555
556
557////////////////////////////////////////////////////////////////////////////////
558/// This function is called from the first entry in TTreePlayer::InitLoop
559/// It analyzes the list of variables involved in the current query
560/// and pre-process the internal Hbook tables to speed-up the search
561/// at the next entries.
562
564{
565 if (!formula) return;
566 Int_t ncodes = formula->GetNcodes();
567 for (Int_t i=1;i<=ncodes;i++) {
568 TLeaf *leaf = formula->GetLeaf(i-1);
569 if (!leaf) continue;
570 if (var == 5) {
571 //leafcount may be null in case of a fix size array
572 if (leaf->GetLeafCount()) leaf = leaf->GetLeafCount();
573 }
574 Int_t last = 0;
575 if (var == 1 && i == ncodes) last = 1;
576#ifndef WIN32
577 hntvar3(id,last,PASSCHAR(leaf->GetName()),strlen(leaf->GetName()));
578#else
579 hntvar3(id,last,PASSCHAR(leaf->GetName()));
580#endif
581 }
582}
583
584////////////////////////////////////////////////////////////////////////////////
585/// Returns kTRUE in case file is open and kFALSE if file is not open.
586
588{
589 return fLun == 0 ? kFALSE : kTRUE;
590}
591
592
593////////////////////////////////////////////////////////////////////////////////
594///Set branch address
595
596void THbookFile::SetBranchAddress(Int_t id, const char *bname, void *add)
597{
598 Int_t *iadd = (Int_t*)add;
599 Int_t &aadd = *iadd;
600#ifndef WIN32
601 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0,strlen(bname),4);
602#else
603 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0);
604#endif
605}
606
607////////////////////////////////////////////////////////////////////////////////
608/// Convert this Hbook file to a Root file with name rootname.
609/// if rootname="', rootname = hbook file name with .root instead of .hbook
610/// By default, the Root file is connected and returned
611/// option:
612/// - "NO" do not connect the Root file
613/// - "C" do not compress file (default is to compress)
614/// - "L" do not convert names to lower case (default is to convert)
615
618{
619 TString opt = option;
620 opt.ToLower();
621
623 char *rfile=nullptr;
624 if (nch) {
625 rfile = new char[nch+1];
627 } else {
628 nch = strlen(GetName());
629 rfile = new char[nch+1];
631 char *dot = strrchr(rfile,'.');
632 if (dot) strcpy(dot+1,"root");
633 else strlcat(rfile,".root",nch+1);
634 }
635
636 nch = 2*nch+50;
637 char *cmd = new char[nch+1];
638 snprintf(cmd,nch,"h2root %s %s",GetName(),rfile);
639 if (opt.Contains("c")) strlcat (cmd," 0",nch+1);
640 if (opt.Contains("l")) strlcat (cmd," 0",nch+1);
641
642 gSystem->Exec(cmd);
643
644 delete [] cmd;
645 if (opt.Contains("no")) {delete [] rfile; return nullptr;}
646 TFile *f = new TFile(rfile);
647 delete [] rfile;
648 if (f->IsZombie()) {delete f; f = nullptr;}
649 return f;
650}
651
652
653////////////////////////////////////////////////////////////////////////////////
654/// Convert the Column-Wise-Ntuple id to a Root Tree
655
657{
658 const int nchar=9;
659 int nvar;
660 int i,j;
661 int nsub,itype,isize,ielem;
662 char *chtag_out;
663 float rmin[1000], rmax[1000];
664
665 if (id > 0) snprintf(idname,127,"h%d",id);
666 else snprintf(idname,127,"h_%d",-id);
667 hnoent(id,nentries);
668 //printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
669 nvar=0;
670#ifndef WIN32
671 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
672#else
673 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
674#endif
675 chtag_out = new char[nvar*nchar+1];
676 Int_t *charflag = new Int_t[nvar];
677 Int_t *lenchar = new Int_t[nvar];
678 Int_t *boolflag = new Int_t[nvar];
679 Int_t *lenbool = new Int_t[nvar];
680 UChar_t *boolarr = new UChar_t[10000];
681
682 chtag_out[nvar*nchar]=0;
683 for (i=0;i<80;i++)chtitl[i]=0;
684#ifndef WIN32
685 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
686#else
687 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
688#endif
689
690 Int_t bufpos = 0;
691 //Int_t isachar = 0;
692 //Int_t isabool = 0;
693 char fullname[64];
694 char name[32];
695 char block[32];
696 char oldblock[32];
697 strlcpy(oldblock,"OLDBLOCK",32);
698 Int_t oldischar = -1;
699 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
700 THbookTree *tree = new THbookTree(idname,id);
701 tree->SetHbookFile(this);
702 tree->SetType(1);
703
704 char *bigbuf = tree->MakeX(500000);
705
706#ifndef WIN32
707 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6);
708#else
709 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0);
710#endif
711
712 UInt_t varNumber = 0;
713 Int_t golower = 1;
714 Int_t nbits = 0;
715 for(i=0; i<nvar;i++) {
716 memset(name,' ',sizeof(name));
717 name[sizeof(name)-1] = 0;
718 memset(block,' ',sizeof(block));
719 block[sizeof(block)-1] = 0;
720 memset(fullname,' ',sizeof(fullname));
721 fullname[sizeof(fullname)-1]=0;
722#ifndef WIN32
723 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
724#else
726#endif
728
729 for (j=30;j>0;j--) {
730 if(golower) name[j] = tolower(name[j]);
731 if (name[j] == ' ') name[j] = 0;
732 }
733 if (golower == 2) name[0] = tolower(name[0]);
734
735 for (j=62;j>0;j--) {
736 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
737 // convert also character after [, if golower == 2
738 if (golower == 2) fullname[j] = tolower(fullname[j]);
739 if (fullname[j] == ' ') fullname[j] = 0;
740 }
741 // convert also first character, if golower == 2
742 if (golower == 2) fullname[0] = tolower(fullname[0]);
743 for (j=30;j>0;j--) {
744 if (block[j] == ' ') block[j] = 0;
745 else break;
746 }
747 if (itype == 1 && isize == 4) strlcat(fullname,"/F",64);
748 if (itype == 1 && isize == 8) strlcat(fullname,"/D",64);
749 if (itype == 2) strlcat(fullname,"/I",64);
750 if (itype == 3) strlcat(fullname,"/i",64);
751// if (itype == 4) strlcat(fullname,"/i",64);
752 if (itype == 4) strlcat(fullname,"/b",64);
753 if (itype == 5) strlcat(fullname,"/C",64);
754//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);
756 if (itype == 5) ischar = 1;
757 else ischar = 0;
758
759 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
760 varNumber = 0;
763 Long_t add= (Long_t)&bigbuf[bufpos];
765#ifndef WIN32
766 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
767#else
768 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
769#endif
770
771 }
772
773 Int_t bufsize = 8000;
774 THbookBranch *branch = new THbookBranch(tree,name,(void*)&bigbuf[bufpos],fullname,bufsize);
775 tree->GetListOfBranches()->Add(branch);
776 branch->SetBlockName(block);
777 branch->SetUniqueID(varNumber);
778 varNumber++;
779
780 //NB: the information about isachar should be saved in the branch
781 // to be done
782 boolflag[i] = -10;
783 charflag[i] = 0;
784 if (itype == 4) {
785 //isabool++;
786 boolflag[i] = bufpos;
787 lenbool[i] = ielem;
788 }
789 bufpos += isize*ielem;
790 if (ischar) {
791 //isachar++;
792 charflag[i] = bufpos - 1;
793 lenchar[i] = isize * ielem;
794 }
795 TObjArray *ll= branch->GetListOfLeaves();
796 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
797 if (!leaf) continue;
798 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
799 if (leafcount) {
800 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
801 }
802 }
803 tree->SetEntries(nentries);
804 delete [] charflag;
805 delete [] lenchar;
806 delete [] boolflag;
807 delete [] lenbool;
808 delete [] boolarr;
809 delete [] chtag_out;
810
811 return tree;
812}
813
814////////////////////////////////////////////////////////////////////////////////
815/// Convert the Row-Wise-Ntuple id to a Root Tree
816
818{
819 const int nchar=9;
820 int nvar;
821 int i,j;
822 char *chtag_out;
823 float rmin[1000], rmax[1000];
824
825 if (id > 0) snprintf(idname,127,"h%d",id);
826 else snprintf(idname,127,"h_%d",-id);
827 hnoent(id,nentries);
828 //printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
829 nvar=0;
830#ifndef WIN32
831 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
832#else
833 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
834#endif
835
836 chtag_out = new char[nvar*nchar+1];
837
838 Int_t golower = 1;
839 chtag_out[nvar*nchar]=0;
840 for (i=0;i<80;i++)chtitl[i]=0;
841#ifndef WIN32
842 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
843#else
844 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
845#endif
846 hgnpar(id,"?",1);
847 char *name = chtag_out;
848 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
849 THbookTree *tree = new THbookTree(idname,id);
850 tree->SetHbookFile(this);
851 tree->SetType(0);
852 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
853
854 Int_t first,last;
855 for(i=0; i<nvar;i++) {
856 name[nchar-1] = 0;
857 first = last = 0;
859 // suppress trailing blanks
860 for (j=nchar-2;j>0;j--) {
861 if(golower) name[j] = tolower(name[j]);
862 if (name[j] == ' ' && last == 0) name[j] = 0;
863 else last = j;
864 }
865 if (golower == 2) name[0] = tolower(name[0]);
866
867 // suppress heading blanks
868 for (j=0;j<nchar;j++) {
869 if (name[j] != ' ') break;
870 first = j+1;
871 }
872 Int_t bufsize = 8000;
873 //tree->Branch(&name[first],&x[i],&name[first],bufsize);
874 THbookBranch *branch = new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
875 branch->SetAddress(&x[i]);
876 branch->SetBlockName(hbookName.Data());
877 tree->GetListOfBranches()->Add(branch);
878 name += nchar;
879 }
880 tree->SetEntries(nentries);
881 delete [] chtag_out;
882
883 return tree;
884}
885
886////////////////////////////////////////////////////////////////////////////////
887/// Convert an Hbook profile histogram into a Root TProfile
888///
889/// the following structure is used in Hbook
890/// lcid points to the profile in array iq
891/// lcont = lq(lcid-1)
892/// lw = lq(lcont)
893/// ln = lq(lw)
894/// if option S jbyt(iq(lw),1,2) = 1
895/// if option I jbyt(iq(lw),1,2) = 2
896
898{
899 if (id > 0) snprintf(idname,127,"h%d",id);
900 else snprintf(idname,127,"h_%d",-id);
901 hnoent(id,nentries);
902 Int_t lw = lq[lcont];
903 Int_t ln = lq[lw];
904#ifndef WIN32
906#else
908#endif
909 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
910 chtitl[4*nwt] = 0;
911 const char *option= " ";
912 if (iq[lw] == 1) option = "S";
913 if (iq[lw] == 2) option = "I";
915
916 const Int_t kCON1 = 9;
917 Int_t i;
918 Float_t x = 0.0;
919 Float_t y = 0.5*(ymin+ymax);
920 for (i=1;i<=ncx;i++) {
921 Int_t n = Int_t(q[ln+i]);
922 hix(id,i,x);
923 for (Int_t j=0;j<n;j++) {
924 p->Fill(x+offsetx,y);
925 }
927 Float_t error = TMath::Sqrt(q[lw+i]);
928 p->SetBinContent(i,content);
929 p->SetBinError(i,error);
930 }
931 p->SetEntries(nentries);
932 return p;
933}
934
935////////////////////////////////////////////////////////////////////////////////
936/// Convert an Hbook 1-d histogram into a Root TH1F
937
939{
940 if (id > 0) snprintf(idname,127,"h%d",id);
941 else snprintf(idname,127,"h_%d",-id);
942 hnoent(id,nentries);
943#ifndef WIN32
945#else
947#endif
948 chtitl[4*nwt] = 0;
949 TH1F *h1;
950 Int_t i;
951 if (hcbits[5]) {
952 Int_t lbins = lq[lcid-2];
953 Double_t *xbins = new Double_t[ncx+1];
954 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
955 h1 = new TH1F(idname,chtitl,ncx,xbins);
956 delete [] xbins;
957 } else {
959 }
960 if (hcbits[8]) h1->Sumw2();
961 TGraph *gr = nullptr;
962 if (hcbits[11]) {
963 gr = new TGraph(ncx);
965 }
966
967 Float_t x;
968 for (i=0;i<=ncx+1;i++) {
969 x = h1->GetBinCenter(i);
970 h1->Fill(x,hi(id,i));
971 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
972 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
973 }
975 if (hcbits[19]) {
976 yymax = q[lcid+kMAX1];
978 }
979 if (hcbits[20]) {
980 yymin = q[lcid+kMIN1];
982 }
984 return h1;
985}
986
987////////////////////////////////////////////////////////////////////////////////
988/// Convert an Hbook 2-d histogram into a Root TH2F
989
991{
992 if (id > 0) snprintf(idname,127,"h%d",id);
993 else snprintf(idname,127,"h_%d",-id);
994 hnoent(id,nentries);
995#ifndef WIN32
997#else
999#endif
1000 chtitl[4*nwt] = 0;
1002 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
1003 Float_t offsety = 0.5*(ymax-ymin)/ncy;
1004 Int_t lw = lq[lcont];
1005 if (lw) h2->Sumw2();
1006
1007 Float_t x = 0.0, y = 0.0;
1008 for (Int_t j=0;j<=ncy+1;j++) {
1009 for (Int_t i=0;i<=ncx+1;i++) {
1010 hijxy(id,i,j,x,y);
1011 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
1012 if (lw) {
1013 Double_t err2 = hije(id,i,j);
1014 h2->SetBinError(i,j,err2);
1015 }
1016 }
1017 }
1018 h2->SetEntries(nentries);
1019 return h2;
1020}
1021
1022////////////////////////////////////////////////////////////////////////////////
1023/// List contents of Hbook directory
1024
1025void THbookFile::ls(const char *path) const
1026{
1027 Int_t nch = strlen(path);
1028 if (nch == 0) {
1029#ifndef WIN32
1031#else
1033#endif
1034 return;
1035 }
1036
1037#ifndef WIN32
1038 hldir(PASSCHAR(path),PASSCHAR("T"),strlen(path),1);
1039#else
1040 hldir(PASSCHAR(path),PASSCHAR("T"));
1041#endif
1042}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
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:414
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define snprintf
Definition civetweb.c:1540
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:2291
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:877
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9138
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:651
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:9203
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3320
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:652
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:9020
virtual void SetEntries(Double_t n)
Definition TH1.h:638
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
HBOOK Branch.
This class is an interface to the Hbook objects in Hbook files.
Definition THbookFile.h:29
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:576
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:468
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:174
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:84
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:1071
void MakeZombie()
Definition TObject.h:53
Profile Histogram.
Definition TProfile.h:32
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
const char * Data() const
Definition TString.h:376
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:653
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:666