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