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
143using fortran_charlen_t = size_t;
144
145#else
146# define hlimit HLIMIT
147# define hldir HLDIR
148# define hropen HROPEN
149# define hrend HREND
150# define hrin HRIN
151# define hnoent HNOENT
152# define hgive HGIVE
153# define hgiven HGIVEN
154# define hgnpar HGNPAR
155# define hgnf HGNF
156# define hgnt HGNT
157# define hgntf HGNTF
158# define hgnt1 HGNT1
159# define rzink RZINK
160# define hdcofl HDCOFL
161# define hmaxim HMAXIM
162# define hminim HMINIM
163# define hdelet HDELET
164# define hntvar2 HNTVAR2
165# define hntvar3 HNTVAR3
166# define hbname HBNAME
167# define hbnamc HBNAMC
168# define hbnam HBNAM
169# define hi HI
170# define hie HIE
171# define hif HIF
172# define hij HIJ
173# define hix HIX
174# define hijxy HIJXY
175# define hije HIJE
176# define hcdir HCDIR
177# define type_of_call _stdcall
178# define DEFCHAR const char*, const int
179# define PASSCHAR(string) string, strlen(string)
180#endif
181
182extern "C" void type_of_call hlimit(const int&);
183#ifndef WIN32
184extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
187#else
188extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
189 const int&,const int&);
190extern "C" void type_of_call hrend(DEFCHAR);
191#endif
192
193extern "C" void type_of_call hrin(const int&,const int&,const int&);
194extern "C" void type_of_call hnoent(const int&,const int&);
195#ifndef WIN32
196extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
197 const int&,const float&,const float&,const int&,const int&,fortran_charlen_t);
198#else
199extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
200 const int&,const float&,const float&,const int&,const int&);
201#endif
202
203 //SUBROUTINE HGNT1(IDD,BLKNA1,VAR,IOFFST,NVAR,IDNEVT,IERROR)
204#ifndef WIN32
205extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
206 const float&,const float&,fortran_charlen_t,fortran_charlen_t);
207extern "C" void type_of_call hgnt1(const int&,DEFCHAR,DEFCHAR,const int&,const int&,const int&,const int&,fortran_charlen_t,fortran_charlen_t);
208#else
209extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
210 const float&,const float&);
211extern "C" void type_of_call hgnt1(const int&,DEFCHAR,DEFCHAR,const int&,const int&,const int&,const int&);
212#endif
213
214#ifndef WIN32
215extern "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);
216extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR, fortran_charlen_t);
217#else
218extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&);
219extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR);
220#endif
221
222#ifndef WIN32
223extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,fortran_charlen_t, fortran_charlen_t);
224#else
225extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
226#endif
227
228extern "C" void type_of_call hgnpar(const int&,const char *,const int);
229extern "C" void type_of_call hgnf(const int&,const int&,const float&,const int&);
230extern "C" void type_of_call hgnt(const int&,const int&,const int&);
231extern "C" void type_of_call hgntf(const int&,const int&,const int&);
232extern "C" void type_of_call rzink(const int&,const int&,const char *,const int);
233extern "C" void type_of_call hdcofl();
234extern "C" void type_of_call hmaxim(const int&,const float&);
235extern "C" void type_of_call hminim(const int&,const float&);
236extern "C" void type_of_call hdelet(const int&);
237extern "C" float type_of_call hi(const int&,const int&);
238extern "C" float type_of_call hie(const int&,const int&);
239extern "C" float type_of_call hif(const int&,const int&);
240extern "C" float type_of_call hij(const int&,const int&,const int&);
241extern "C" void type_of_call hix(const int&,const int&,const float&);
242extern "C" void type_of_call hijxy(const int&,const int&,const int&,const float&,const float&);
243extern "C" float type_of_call hije(const int&,const int&,const int&);
244#ifndef WIN32
247#else
248extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
249extern "C" void type_of_call hldir(DEFCHAR,DEFCHAR);
250#endif
251
253Int_t *THbookFile::fgLuns = nullptr;
254
255
256////////////////////////////////////////////////////////////////////////////////
257///the constructor
258
259THbookFile::THbookFile() : fLun(0),fLrecl(0)
260{
261 fList = new TList();
262 fKeys = new TList();
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Constructor for an HBook file object
267
269 :TNamed(fname,"")
270{
271 // Initialize the Hbook/Zebra store
272 Int_t i;
273 if (!fgPawInit) {
275 lq = &pawc[9];
276 iq = &pawc[17];
277 void *qq = iq;
278 q = (float*)qq;
279 int pawc_size = PAWC_SIZE;
281 fgLuns = new Int_t[10];
282 for (i=0;i<10;i++) fgLuns[i] = 0;
283 }
284
285 //find a free logical unit (max 10)
286 fLun = 0;
287 for (i=0;i<10;i++) {
288 if (fgLuns[i] == 0) {
289 fLun = 10+i;
290 fgLuns[i] = 1;
291 break;
292 }
293 }
294 if (fLun == 0) {
295 Error("THbookFile","Too many HbookFiles\n");
296 return;
297 }
298 char topdir[20];
299 snprintf(topdir,19,"lun%d",fLun);
300
301 Int_t ier = 0;
302#ifndef WIN32
304#else
306#endif
307 fLrecl = lrecl;
309 snprintf(topdir,19,"//lun%d",fLun);
310 fCurDir = topdir;
311
312 if (ier) printf (" Error on hropen was %d \n", ier);
313 if (quest[0]) {
314 printf("Error cannot open input file: %s\n",fname);
315 }
316 if (ier || quest[0]) {
317 fgLuns[fLun-10]=0;
318 fLun = 0;
319 fList = nullptr;
320 fKeys = nullptr;
321 MakeZombie();
322 return;
323 }
324
325 gROOT->GetListOfBrowsables()->Add(this,fname);
326
327 fList = new TList();
328 fKeys = new TList();
329 for (Int_t key=1;key<1000000;key++) {
330 int z0 = 0;
331 rzink(key,z0,"S",1);
332 if (quest[0]) break;
333 if (quest[13] & 8) continue;
334 Int_t id = quest[20];
335 THbookKey *akey = new THbookKey(id,this);
336 fKeys->Add(akey);
337 }
338}
339
340////////////////////////////////////////////////////////////////////////////////
341///destructor
342
344{
345 if (!fList) return;
346 Close();
347 delete fList;
348 delete fKeys;
349}
350
351////////////////////////////////////////////////////////////////////////////////
352/// to be implemented
353
355{
356 if( b ) {
357 b->Add(fList, "memory");
358 b->Add(fKeys, "IDs on disk");
359 }
360 cd();
361}
362
363////////////////////////////////////////////////////////////////////////////////
364/// change directory to dirname
365
367{
369 if (nch == 0) {
370#ifndef WIN32
372#else
374#endif
375 return kTRUE;
376 }
377
378 char cdir[512];
379 Int_t i;
380 for (i=0;i<512;i++) cdir[i] = ' ';
381 cdir[511] = 0;
382#ifndef WIN32
384 hcdir(PASSCHAR(cdir),PASSCHAR("R"),511,1);
385#else
388#endif
389 for (i=510;i>=0;i--) {
390 if (cdir[i] != ' ') break;
391 cdir[i] = 0;
392 }
393 fCurDir = cdir;
394 printf("fCurdir=%s\n",fCurDir.Data());
395
396 return kTRUE;
397}
398
399////////////////////////////////////////////////////////////////////////////////
400/// Close the Hbook file
401
403{
404 if(!IsOpen()) return;
405 if (!fList) return;
406
407 gROOT->GetListOfBrowsables()->Remove(this);
408
409 cd();
410
411 fList->Delete();
412 fKeys->Delete();
413 if (fgLuns) fgLuns[fLun-10] = 0;
414 hdelet(0);
415#ifndef WIN32
417#else
419#endif
420}
421
422////////////////////////////////////////////////////////////////////////////////
423///remove id from file and memory
424
426{
427 hdelet(id);
428}
429
430////////////////////////////////////////////////////////////////////////////////
431/// return object with name in fList in memory
432
434{
435 return fList->FindObject(name);
436}
437
438////////////////////////////////////////////////////////////////////////////////
439/// return object with pointer obj in fList in memory
440
442{
443 return fList->FindObject(obj);
444}
445
446////////////////////////////////////////////////////////////////////////////////
447/// import Hbook object with identifier idd in memory
448
450{
451 Int_t id = 0;
452 for (Int_t key=1;key<1000000;key++) {
453 int z0 = 0;
454 rzink(key,z0,"S",1);
455 if (quest[0]) break;
456 if (quest[13] & 8) continue;
457 id = quest[20];
458 if (id == idd) break;
459 }
460 if (id == 0) return nullptr;
461 if (id != idd) {
462 printf("Error cannot find ID = %d\n",idd);
463 return nullptr;
464 }
465
466 int i999 = 999;
467 // must delete any previous object with the same ID !!
468 lcdir = hcbook[6];
469 ltab = hcbook[9];
470 for (Int_t i=1;i<=iq[lcdir+kNRH];i++) {
471 if (iq[ltab+i] == id) {
472 printf("WARNING, previous ID=%d is replaced\n",id);
473 hdelet(id);
474 break;
475 }
476 }
477 hrin(id,i999,0);
478 if (quest[0]) {
479 printf("Error cannot read ID = %d\n",id);
480 return nullptr;
481 }
482 hdcofl();
483 lcid = hcbook[10];
484 lcont = lq[lcid-1];
485 TObject *obj = nullptr;
486 if (hcbits[3]) {
487 if (iq[lcid-2] == 2) obj = ConvertRWN(id);
488 else obj = ConvertCWN(id);
489 //hdelet(id); //cannot be deleted here since used in GetEntry
490 if (obj) {
491 fList->Add(obj);
492 ((THbookTree *)obj)->SetTitle(GetName());
493 }
494 return obj;
495 }
496 if (hcbits[0] && hcbits[7]) {
497 obj = ConvertProfile(id);
498 hdelet(id);
499 if (obj) fList->Add(obj);
500 return obj;
501 }
502 if (hcbits[0]) {
503 obj = Convert1D(id);
504 hdelet(id);
505 if (obj) fList->Add(obj);
506 return obj;
507 }
508 if (hcbits[1] || hcbits[2]) {
509 obj = Convert2D(id);
510 hdelet(id);
511 if (obj) fList->Add(obj);
512 return obj;
513 }
514 return obj;
515}
516
517
518////////////////////////////////////////////////////////////////////////////////
519/// Read in memory all columns of entry number of ntuple id from the Hbook file
520
522{
523 Int_t ier = 0;
524 if (atype == 0) {
525 hgnf(id,entry+1,x[0],ier);
526 } else {
527 hgnt(id,entry+1,ier);
528 }
529 return 0;
530}
531
532////////////////////////////////////////////////////////////////////////////////
533/// Read in memory only the branch bname
534
536{
537 if (entry == gLastEntry) return 0;
539 Int_t ier = 0;
540 //uses the fast read method using the Hbook tables computed in InitLeaves
541 hgntf(id,entry+1,ier);
542 //old alternative slow method
543//#ifndef WIN32
544// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier,strlen(blockname),strlen(branchname));
545//#else
546// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier);
547//#endif
548 return 0;
549}
550
551
552////////////////////////////////////////////////////////////////////////////////
553/// This function is called from the first entry in TTreePlayer::InitLoop
554/// It analyzes the list of variables involved in the current query
555/// and pre-process the internal Hbook tables to speed-up the search
556/// at the next entries.
557
559{
560 if (!formula) return;
561 Int_t ncodes = formula->GetNcodes();
562 for (Int_t i=1;i<=ncodes;i++) {
563 TLeaf *leaf = formula->GetLeaf(i-1);
564 if (!leaf) continue;
565 if (var == 5) {
566 //leafcount may be null in case of a fix size array
567 if (leaf->GetLeafCount()) leaf = leaf->GetLeafCount();
568 }
569 Int_t last = 0;
570 if (var == 1 && i == ncodes) last = 1;
571#ifndef WIN32
572 hntvar3(id,last,PASSCHAR(leaf->GetName()),strlen(leaf->GetName()));
573#else
574 hntvar3(id,last,PASSCHAR(leaf->GetName()));
575#endif
576 }
577}
578
579////////////////////////////////////////////////////////////////////////////////
580/// Returns kTRUE in case file is open and kFALSE if file is not open.
581
583{
584 return fLun == 0 ? kFALSE : kTRUE;
585}
586
587
588////////////////////////////////////////////////////////////////////////////////
589///Set branch address
590
591void THbookFile::SetBranchAddress(Int_t id, const char *bname, void *add)
592{
593 Int_t *iadd = (Int_t*)add;
594 Int_t &aadd = *iadd;
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
613{
614 TString opt = option;
615 opt.ToLower();
616
618 char *rfile=nullptr;
619 if (nch) {
620 rfile = new char[nch+1];
622 } else {
623 nch = strlen(GetName());
624 rfile = new char[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#ifndef WIN32
702 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6);
703#else
704 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0);
705#endif
706
707 UInt_t varNumber = 0;
708 Int_t golower = 1;
709 Int_t nbits = 0;
710 for(i=0; i<nvar;i++) {
711 memset(name,' ',sizeof(name));
712 name[sizeof(name)-1] = 0;
713 memset(block,' ',sizeof(block));
714 block[sizeof(block)-1] = 0;
715 memset(fullname,' ',sizeof(fullname));
716 fullname[sizeof(fullname)-1]=0;
717#ifndef WIN32
718 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
719#else
721#endif
723
724 for (j=30;j>0;j--) {
725 if(golower) name[j] = tolower(name[j]);
726 if (name[j] == ' ') name[j] = 0;
727 }
728 if (golower == 2) name[0] = tolower(name[0]);
729
730 for (j=62;j>0;j--) {
731 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
732 // convert also character after [, if golower == 2
733 if (golower == 2) fullname[j] = tolower(fullname[j]);
734 if (fullname[j] == ' ') fullname[j] = 0;
735 }
736 // convert also first character, if golower == 2
737 if (golower == 2) fullname[0] = tolower(fullname[0]);
738 for (j=30;j>0;j--) {
739 if (block[j] == ' ') block[j] = 0;
740 else break;
741 }
742 if (itype == 1 && isize == 4) strlcat(fullname,"/F",64);
743 if (itype == 1 && isize == 8) strlcat(fullname,"/D",64);
744 if (itype == 2) strlcat(fullname,"/I",64);
745 if (itype == 3) strlcat(fullname,"/i",64);
746// if (itype == 4) strlcat(fullname,"/i",64);
747 if (itype == 4) strlcat(fullname,"/b",64);
748 if (itype == 5) strlcat(fullname,"/C",64);
749//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 if (itype == 5) ischar = 1;
752 else ischar = 0;
753
754 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
755 varNumber = 0;
758 Long_t add= (Long_t)&bigbuf[bufpos];
760#ifndef WIN32
761 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
762#else
763 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
764#endif
765
766 }
767
768 Int_t bufsize = 8000;
769 THbookBranch *branch = new THbookBranch(tree,name,(void*)&bigbuf[bufpos],fullname,bufsize);
770 tree->GetListOfBranches()->Add(branch);
771 branch->SetBlockName(block);
772 branch->SetUniqueID(varNumber);
773 varNumber++;
774
775 //NB: the information about isachar should be saved in the branch
776 // to be done
777 boolflag[i] = -10;
778 charflag[i] = 0;
779 if (itype == 4) {
780 //isabool++;
781 boolflag[i] = bufpos;
782 lenbool[i] = ielem;
783 }
784 bufpos += isize*ielem;
785 if (ischar) {
786 //isachar++;
787 charflag[i] = bufpos - 1;
788 lenchar[i] = isize * ielem;
789 }
790 TObjArray *ll= branch->GetListOfLeaves();
791 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
792 if (!leaf) continue;
793 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
794 if (leafcount) {
795 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
796 }
797 }
798 tree->SetEntries(nentries);
799 delete [] charflag;
800 delete [] lenchar;
801 delete [] boolflag;
802 delete [] lenbool;
803 delete [] boolarr;
804 delete [] chtag_out;
805
806 return tree;
807}
808
809////////////////////////////////////////////////////////////////////////////////
810/// Convert the Row-Wise-Ntuple id to a Root Tree
811
813{
814 const int nchar=9;
815 int nvar;
816 int i,j;
817 char *chtag_out;
818 float rmin[1000], rmax[1000];
819
820 if (id > 0) snprintf(idname,127,"h%d",id);
821 else snprintf(idname,127,"h_%d",-id);
822 hnoent(id,nentries);
823 //printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
824 nvar=0;
825#ifndef WIN32
826 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
827#else
828 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
829#endif
830
831 chtag_out = new char[nvar*nchar+1];
832
833 Int_t golower = 1;
834 chtag_out[nvar*nchar]=0;
835 for (i=0;i<80;i++)chtitl[i]=0;
836#ifndef WIN32
837 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
838#else
839 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
840#endif
841 hgnpar(id,"?",1);
842 char *name = chtag_out;
843 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
844 THbookTree *tree = new THbookTree(idname,id);
845 tree->SetHbookFile(this);
846 tree->SetType(0);
847 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
848
849 Int_t first,last;
850 for(i=0; i<nvar;i++) {
851 name[nchar-1] = 0;
852 first = last = 0;
854 // suppress trailing blanks
855 for (j=nchar-2;j>0;j--) {
856 if(golower) name[j] = tolower(name[j]);
857 if (name[j] == ' ' && last == 0) name[j] = 0;
858 else last = j;
859 }
860 if (golower == 2) name[0] = tolower(name[0]);
861
862 // suppress heading blanks
863 for (j=0;j<nchar;j++) {
864 if (name[j] != ' ') break;
865 first = j+1;
866 }
867 Int_t bufsize = 8000;
868 //tree->Branch(&name[first],&x[i],&name[first],bufsize);
869 THbookBranch *branch = new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
870 branch->SetAddress(&x[i]);
871 branch->SetBlockName(hbookName.Data());
872 tree->GetListOfBranches()->Add(branch);
873 name += nchar;
874 }
875 tree->SetEntries(nentries);
876 delete [] chtag_out;
877
878 return tree;
879}
880
881////////////////////////////////////////////////////////////////////////////////
882/// Convert an Hbook profile histogram into a Root TProfile
883///
884/// the following structure is used in Hbook
885/// lcid points to the profile in array iq
886/// lcont = lq(lcid-1)
887/// lw = lq(lcont)
888/// ln = lq(lw)
889/// if option S jbyt(iq(lw),1,2) = 1
890/// if option I jbyt(iq(lw),1,2) = 2
891
893{
894 if (id > 0) snprintf(idname,127,"h%d",id);
895 else snprintf(idname,127,"h_%d",-id);
896 hnoent(id,nentries);
897 Int_t lw = lq[lcont];
898 Int_t ln = lq[lw];
899#ifndef WIN32
901#else
903#endif
904 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
905 chtitl[4*nwt] = 0;
906 const char *option= " ";
907 if (iq[lw] == 1) option = "S";
908 if (iq[lw] == 2) option = "I";
910
911 const Int_t kCON1 = 9;
912 Int_t i;
913 Float_t x = 0.0;
914 Float_t y = 0.5*(ymin+ymax);
915 for (i=1;i<=ncx;i++) {
916 Int_t n = Int_t(q[ln+i]);
917 hix(id,i,x);
918 for (Int_t j=0;j<n;j++) {
919 p->Fill(x+offsetx,y);
920 }
922 Float_t error = TMath::Sqrt(q[lw+i]);
923 p->SetBinContent(i,content);
924 p->SetBinError(i,error);
925 }
926 p->SetEntries(nentries);
927 return p;
928}
929
930////////////////////////////////////////////////////////////////////////////////
931/// Convert an Hbook 1-d histogram into a Root TH1F
932
934{
935 if (id > 0) snprintf(idname,127,"h%d",id);
936 else snprintf(idname,127,"h_%d",-id);
937 hnoent(id,nentries);
938#ifndef WIN32
940#else
942#endif
943 chtitl[4*nwt] = 0;
944 TH1F *h1;
945 Int_t i;
946 if (hcbits[5]) {
947 Int_t lbins = lq[lcid-2];
948 Double_t *xbins = new Double_t[ncx+1];
949 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
950 h1 = new TH1F(idname,chtitl,ncx,xbins);
951 delete [] xbins;
952 } else {
954 }
955 if (hcbits[8]) h1->Sumw2();
956 TGraph *gr = nullptr;
957 if (hcbits[11]) {
958 gr = new TGraph(ncx);
960 }
961
962 Float_t x;
963 for (i=0;i<=ncx+1;i++) {
964 x = h1->GetBinCenter(i);
965 h1->Fill(x,hi(id,i));
966 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
967 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
968 }
970 if (hcbits[19]) {
971 yymax = q[lcid+kMAX1];
973 }
974 if (hcbits[20]) {
975 yymin = q[lcid+kMIN1];
977 }
979 return h1;
980}
981
982////////////////////////////////////////////////////////////////////////////////
983/// Convert an Hbook 2-d histogram into a Root TH2F
984
986{
987 if (id > 0) snprintf(idname,127,"h%d",id);
988 else snprintf(idname,127,"h_%d",-id);
989 hnoent(id,nentries);
990#ifndef WIN32
992#else
994#endif
995 chtitl[4*nwt] = 0;
997 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
998 Float_t offsety = 0.5*(ymax-ymin)/ncy;
999 Int_t lw = lq[lcont];
1000 if (lw) h2->Sumw2();
1001
1002 Float_t x = 0.0, y = 0.0;
1003 for (Int_t j=0;j<=ncy+1;j++) {
1004 for (Int_t i=0;i<=ncx+1;i++) {
1005 hijxy(id,i,j,x,y);
1006 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
1007 if (lw) {
1008 Double_t err2 = hije(id,i,j);
1009 h2->SetBinError(i,j,err2);
1010 }
1011 }
1012 }
1013 h2->SetEntries(nentries);
1014 return h2;
1015}
1016
1017////////////////////////////////////////////////////////////////////////////////
1018/// List contents of Hbook directory
1019
1020void THbookFile::ls(const char *path) const
1021{
1022 Int_t nch = strlen(path);
1023 if (nch == 0) {
1024#ifndef WIN32
1026#else
1028#endif
1029 return;
1030 }
1031
1032#ifndef WIN32
1033 hldir(PASSCHAR(path),PASSCHAR("T"),strlen(path),1);
1034#else
1035 hldir(PASSCHAR(path),PASSCHAR("T"));
1036#endif
1037}
#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
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:414
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#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: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:2387
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:9254
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:9319
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3372
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:9136
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:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1089
void MakeZombie()
Definition TObject.h:55
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