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#else
141# define hlimit HLIMIT
142# define hldir HLDIR
143# define hropen HROPEN
144# define hrend HREND
145# define hrin HRIN
146# define hnoent HNOENT
147# define hgive HGIVE
148# define hgiven HGIVEN
149# define hgnpar HGNPAR
150# define hgnf HGNF
151# define hgnt HGNT
152# define hgntf HGNTF
153# define hgnt1 HGNT1
154# define rzink RZINK
155# define hdcofl HDCOFL
156# define hmaxim HMAXIM
157# define hminim HMINIM
158# define hdelet HDELET
159# define hntvar2 HNTVAR2
160# define hntvar3 HNTVAR3
161# define hbname HBNAME
162# define hbnamc HBNAMC
163# define hbnam HBNAM
164# define hi HI
165# define hie HIE
166# define hif HIF
167# define hij HIJ
168# define hix HIX
169# define hijxy HIJXY
170# define hije HIJE
171# define hcdir HCDIR
172# define type_of_call _stdcall
173# define DEFCHAR const char*, const int
174# define PASSCHAR(string) string, strlen(string)
175#endif
176
177extern "C" void type_of_call hlimit(const int&);
178#ifndef WIN32
179extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
180 const int&,const int&,const int,const int,const int);
181extern "C" void type_of_call hrend(DEFCHAR,const int);
182#else
183extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
184 const int&,const int&);
185extern "C" void type_of_call hrend(DEFCHAR);
186#endif
187
188extern "C" void type_of_call hrin(const int&,const int&,const int&);
189extern "C" void type_of_call hnoent(const int&,const int&);
190#ifndef WIN32
191extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
192 const int&,const float&,const float&,const int&,const int&,const int);
193#else
194extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
195 const int&,const float&,const float&,const int&,const int&);
196#endif
197
198 //SUBROUTINE HGNT1(IDD,BLKNA1,VAR,IOFFST,NVAR,IDNEVT,IERROR)
199#ifndef WIN32
200extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
201 const float&,const float&,const int,const int);
202extern "C" void type_of_call hgnt1(const int&,DEFCHAR,DEFCHAR,const int&,const int&,const int&,const int&,const int,const int);
203#else
204extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
205 const float&,const float&);
206extern "C" void type_of_call hgnt1(const int&,DEFCHAR,DEFCHAR,const int&,const int&,const int&,const int&);
207#endif
208
209#ifndef WIN32
210extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&,const int,const int, const int);
211extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR, const int);
212#else
213extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&);
214extern "C" void type_of_call hntvar3(const int&,const int&,DEFCHAR);
215#endif
216
217#ifndef WIN32
218extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,const int, const int);
219#else
220extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
221#endif
222
223extern "C" void type_of_call hgnpar(const int&,const char *,const int);
224extern "C" void type_of_call hgnf(const int&,const int&,const float&,const int&);
225extern "C" void type_of_call hgnt(const int&,const int&,const int&);
226extern "C" void type_of_call hgntf(const int&,const int&,const int&);
227extern "C" void type_of_call rzink(const int&,const int&,const char *,const int);
228extern "C" void type_of_call hdcofl();
229extern "C" void type_of_call hmaxim(const int&,const float&);
230extern "C" void type_of_call hminim(const int&,const float&);
231extern "C" void type_of_call hdelet(const int&);
232extern "C" float type_of_call hi(const int&,const int&);
233extern "C" float type_of_call hie(const int&,const int&);
234extern "C" float type_of_call hif(const int&,const int&);
235extern "C" float type_of_call hij(const int&,const int&,const int&);
236extern "C" void type_of_call hix(const int&,const int&,const float&);
237extern "C" void type_of_call hijxy(const int&,const int&,const int&,const float&,const float&);
238extern "C" float type_of_call hije(const int&,const int&,const int&);
239#ifndef WIN32
240extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR ,const int,const int);
241extern "C" void type_of_call hldir(DEFCHAR,DEFCHAR ,const int,const int);
242#else
243extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
244extern "C" void type_of_call hldir(DEFCHAR,DEFCHAR);
245#endif
246
248Int_t *THbookFile::fgLuns = nullptr;
249
250
251////////////////////////////////////////////////////////////////////////////////
252///the constructor
253
254THbookFile::THbookFile() : fLun(0),fLrecl(0)
255{
256 fList = new TList();
257 fKeys = new TList();
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Constructor for an HBook file object
262
264 :TNamed(fname,"")
265{
266 // Initialize the Hbook/Zebra store
267 Int_t i;
268 if (!fgPawInit) {
270 lq = &pawc[9];
271 iq = &pawc[17];
272 void *qq = iq;
273 q = (float*)qq;
274 int pawc_size = PAWC_SIZE;
276 fgLuns = new Int_t[10];
277 for (i=0;i<10;i++) fgLuns[i] = 0;
278 }
279
280 //find a free logical unit (max 10)
281 fLun = 0;
282 for (i=0;i<10;i++) {
283 if (fgLuns[i] == 0) {
284 fLun = 10+i;
285 fgLuns[i] = 1;
286 break;
287 }
288 }
289 if (fLun == 0) {
290 Error("THbookFile","Too many HbookFiles\n");
291 return;
292 }
293 char topdir[20];
294 snprintf(topdir,19,"lun%d",fLun);
295
296 Int_t ier = 0;
297#ifndef WIN32
299#else
301#endif
302 fLrecl = lrecl;
304 snprintf(topdir,19,"//lun%d",fLun);
305 fCurDir = topdir;
306
307 if (ier) printf (" Error on hropen was %d \n", ier);
308 if (quest[0]) {
309 printf("Error cannot open input file: %s\n",fname);
310 }
311 if (ier || quest[0]) {
312 fgLuns[fLun-10]=0;
313 fLun = 0;
314 fList = nullptr;
315 fKeys = nullptr;
316 MakeZombie();
317 return;
318 }
319
320 gROOT->GetListOfBrowsables()->Add(this,fname);
321
322 fList = new TList();
323 fKeys = new TList();
324 for (Int_t key=1;key<1000000;key++) {
325 int z0 = 0;
326 rzink(key,z0,"S",1);
327 if (quest[0]) break;
328 if (quest[13] & 8) continue;
329 Int_t id = quest[20];
330 THbookKey *akey = new THbookKey(id,this);
331 fKeys->Add(akey);
332 }
333}
334
335////////////////////////////////////////////////////////////////////////////////
336///destructor
337
339{
340 if (!fList) return;
341 Close();
342 delete fList;
343 delete fKeys;
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// to be implemented
348
350{
351 if( b ) {
352 b->Add(fList, "memory");
353 b->Add(fKeys, "IDs on disk");
354 }
355 cd();
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// change directory to dirname
360
362{
364 if (nch == 0) {
365#ifndef WIN32
367#else
369#endif
370 return kTRUE;
371 }
372
373 char cdir[512];
374 Int_t i;
375 for (i=0;i<512;i++) cdir[i] = ' ';
376 cdir[511] = 0;
377#ifndef WIN32
379 hcdir(PASSCHAR(cdir),PASSCHAR("R"),511,1);
380#else
383#endif
384 for (i=510;i>=0;i--) {
385 if (cdir[i] != ' ') break;
386 cdir[i] = 0;
387 }
388 fCurDir = cdir;
389 printf("fCurdir=%s\n",fCurDir.Data());
390
391 return kTRUE;
392}
393
394////////////////////////////////////////////////////////////////////////////////
395/// Close the Hbook file
396
398{
399 if(!IsOpen()) return;
400 if (!fList) return;
401
402 gROOT->GetListOfBrowsables()->Remove(this);
403
404 cd();
405
406 fList->Delete();
407 fKeys->Delete();
408 if (fgLuns) fgLuns[fLun-10] = 0;
409 hdelet(0);
410#ifndef WIN32
412#else
414#endif
415}
416
417////////////////////////////////////////////////////////////////////////////////
418///remove id from file and memory
419
421{
422 hdelet(id);
423}
424
425////////////////////////////////////////////////////////////////////////////////
426/// return object with name in fList in memory
427
429{
430 return fList->FindObject(name);
431}
432
433////////////////////////////////////////////////////////////////////////////////
434/// return object with pointer obj in fList in memory
435
437{
438 return fList->FindObject(obj);
439}
440
441////////////////////////////////////////////////////////////////////////////////
442/// import Hbook object with identifier idd in memory
443
445{
446 Int_t id = 0;
447 for (Int_t key=1;key<1000000;key++) {
448 int z0 = 0;
449 rzink(key,z0,"S",1);
450 if (quest[0]) break;
451 if (quest[13] & 8) continue;
452 id = quest[20];
453 if (id == idd) break;
454 }
455 if (id == 0) return nullptr;
456 if (id != idd) {
457 printf("Error cannot find ID = %d\n",idd);
458 return nullptr;
459 }
460
461 int i999 = 999;
462 // must delete any previous object with the same ID !!
463 lcdir = hcbook[6];
464 ltab = hcbook[9];
465 for (Int_t i=1;i<=iq[lcdir+kNRH];i++) {
466 if (iq[ltab+i] == id) {
467 printf("WARNING, previous ID=%d is replaced\n",id);
468 hdelet(id);
469 break;
470 }
471 }
472 hrin(id,i999,0);
473 if (quest[0]) {
474 printf("Error cannot read ID = %d\n",id);
475 return nullptr;
476 }
477 hdcofl();
478 lcid = hcbook[10];
479 lcont = lq[lcid-1];
480 TObject *obj = nullptr;
481 if (hcbits[3]) {
482 if (iq[lcid-2] == 2) obj = ConvertRWN(id);
483 else obj = ConvertCWN(id);
484 //hdelet(id); //cannot be deleted here since used in GetEntry
485 if (obj) {
486 fList->Add(obj);
487 ((THbookTree *)obj)->SetTitle(GetName());
488 }
489 return obj;
490 }
491 if (hcbits[0] && hcbits[7]) {
492 obj = ConvertProfile(id);
493 hdelet(id);
494 if (obj) fList->Add(obj);
495 return obj;
496 }
497 if (hcbits[0]) {
498 obj = Convert1D(id);
499 hdelet(id);
500 if (obj) fList->Add(obj);
501 return obj;
502 }
503 if (hcbits[1] || hcbits[2]) {
504 obj = Convert2D(id);
505 hdelet(id);
506 if (obj) fList->Add(obj);
507 return obj;
508 }
509 return obj;
510}
511
512
513////////////////////////////////////////////////////////////////////////////////
514/// Read in memory all columns of entry number of ntuple id from the Hbook file
515
517{
518 Int_t ier = 0;
519 if (atype == 0) {
520 hgnf(id,entry+1,x[0],ier);
521 } else {
522 hgnt(id,entry+1,ier);
523 }
524 return 0;
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Read in memory only the branch bname
529
531{
532 if (entry == gLastEntry) return 0;
534 Int_t ier = 0;
535 //uses the fast read method using the Hbook tables computed in InitLeaves
536 hgntf(id,entry+1,ier);
537 //old alternative slow method
538//#ifndef WIN32
539// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier,strlen(blockname),strlen(branchname));
540//#else
541// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier);
542//#endif
543 return 0;
544}
545
546
547////////////////////////////////////////////////////////////////////////////////
548/// This function is called from the first entry in TTreePlayer::InitLoop
549/// It analyzes the list of variables involved in the current query
550/// and pre-process the internal Hbook tables to speed-up the search
551/// at the next entries.
552
554{
555 if (!formula) return;
556 Int_t ncodes = formula->GetNcodes();
557 for (Int_t i=1;i<=ncodes;i++) {
558 TLeaf *leaf = formula->GetLeaf(i-1);
559 if (!leaf) continue;
560 if (var == 5) {
561 //leafcount may be null in case of a fix size array
562 if (leaf->GetLeafCount()) leaf = leaf->GetLeafCount();
563 }
564 Int_t last = 0;
565 if (var == 1 && i == ncodes) last = 1;
566#ifndef WIN32
567 hntvar3(id,last,PASSCHAR(leaf->GetName()),strlen(leaf->GetName()));
568#else
569 hntvar3(id,last,PASSCHAR(leaf->GetName()));
570#endif
571 }
572}
573
574////////////////////////////////////////////////////////////////////////////////
575/// Returns kTRUE in case file is open and kFALSE if file is not open.
576
578{
579 return fLun == 0 ? kFALSE : kTRUE;
580}
581
582
583////////////////////////////////////////////////////////////////////////////////
584///Set branch address
585
586void THbookFile::SetBranchAddress(Int_t id, const char *bname, void *add)
587{
588 Int_t *iadd = (Int_t*)add;
589 Int_t &aadd = *iadd;
590#ifndef WIN32
591 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0,strlen(bname),4);
592#else
593 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0);
594#endif
595}
596
597////////////////////////////////////////////////////////////////////////////////
598/// Convert this Hbook file to a Root file with name rootname.
599/// if rootname="', rootname = hbook file name with .root instead of .hbook
600/// By default, the Root file is connected and returned
601/// option:
602/// - "NO" do not connect the Root file
603/// - "C" do not compress file (default is to compress)
604/// - "L" do not convert names to lower case (default is to convert)
605
608{
609 TString opt = option;
610 opt.ToLower();
611
613 char *rfile=nullptr;
614 if (nch) {
615 rfile = new char[nch+1];
617 } else {
618 nch = strlen(GetName());
619 rfile = new char[nch+1];
621 char *dot = strrchr(rfile,'.');
622 if (dot) strcpy(dot+1,"root");
623 else strlcat(rfile,".root",nch+1);
624 }
625
626 nch = 2*nch+50;
627 char *cmd = new char[nch+1];
628 snprintf(cmd,nch,"h2root %s %s",GetName(),rfile);
629 if (opt.Contains("c")) strlcat (cmd," 0",nch+1);
630 if (opt.Contains("l")) strlcat (cmd," 0",nch+1);
631
632 gSystem->Exec(cmd);
633
634 delete [] cmd;
635 if (opt.Contains("no")) {delete [] rfile; return nullptr;}
636 TFile *f = new TFile(rfile);
637 delete [] rfile;
638 if (f->IsZombie()) {delete f; f = nullptr;}
639 return f;
640}
641
642
643////////////////////////////////////////////////////////////////////////////////
644/// Convert the Column-Wise-Ntuple id to a Root Tree
645
647{
648 const int nchar=9;
649 int nvar;
650 int i,j;
651 int nsub,itype,isize,ielem;
652 char *chtag_out;
653 float rmin[1000], rmax[1000];
654
655 if (id > 0) snprintf(idname,127,"h%d",id);
656 else snprintf(idname,127,"h_%d",-id);
657 hnoent(id,nentries);
658 //printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
659 nvar=0;
660#ifndef WIN32
661 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
662#else
663 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
664#endif
665 chtag_out = new char[nvar*nchar+1];
666 Int_t *charflag = new Int_t[nvar];
667 Int_t *lenchar = new Int_t[nvar];
668 Int_t *boolflag = new Int_t[nvar];
669 Int_t *lenbool = new Int_t[nvar];
670 UChar_t *boolarr = new UChar_t[10000];
671
672 chtag_out[nvar*nchar]=0;
673 for (i=0;i<80;i++)chtitl[i]=0;
674#ifndef WIN32
675 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
676#else
677 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
678#endif
679
680 Int_t bufpos = 0;
681 //Int_t isachar = 0;
682 //Int_t isabool = 0;
683 char fullname[64];
684 char name[32];
685 char block[32];
686 char oldblock[32];
687 strlcpy(oldblock,"OLDBLOCK",32);
688 Int_t oldischar = -1;
689 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
690 THbookTree *tree = new THbookTree(idname,id);
691 tree->SetHbookFile(this);
692 tree->SetType(1);
693
694 char *bigbuf = tree->MakeX(500000);
695
696#ifndef WIN32
697 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6);
698#else
699 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0);
700#endif
701
702 UInt_t varNumber = 0;
703 Int_t golower = 1;
704 Int_t nbits = 0;
705 for(i=0; i<nvar;i++) {
706 memset(name,' ',sizeof(name));
707 name[sizeof(name)-1] = 0;
708 memset(block,' ',sizeof(block));
709 block[sizeof(block)-1] = 0;
710 memset(fullname,' ',sizeof(fullname));
711 fullname[sizeof(fullname)-1]=0;
712#ifndef WIN32
713 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
714#else
716#endif
718
719 for (j=30;j>0;j--) {
720 if(golower) name[j] = tolower(name[j]);
721 if (name[j] == ' ') name[j] = 0;
722 }
723 if (golower == 2) name[0] = tolower(name[0]);
724
725 for (j=62;j>0;j--) {
726 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
727 // convert also character after [, if golower == 2
728 if (golower == 2) fullname[j] = tolower(fullname[j]);
729 if (fullname[j] == ' ') fullname[j] = 0;
730 }
731 // convert also first character, if golower == 2
732 if (golower == 2) fullname[0] = tolower(fullname[0]);
733 for (j=30;j>0;j--) {
734 if (block[j] == ' ') block[j] = 0;
735 else break;
736 }
737 if (itype == 1 && isize == 4) strlcat(fullname,"/F",64);
738 if (itype == 1 && isize == 8) strlcat(fullname,"/D",64);
739 if (itype == 2) strlcat(fullname,"/I",64);
740 if (itype == 3) strlcat(fullname,"/i",64);
741// if (itype == 4) strlcat(fullname,"/i",64);
742 if (itype == 4) strlcat(fullname,"/b",64);
743 if (itype == 5) strlcat(fullname,"/C",64);
744//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);
746 if (itype == 5) ischar = 1;
747 else ischar = 0;
748
749 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
750 varNumber = 0;
753 Long_t add= (Long_t)&bigbuf[bufpos];
755#ifndef WIN32
756 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
757#else
758 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
759#endif
760
761 }
762
763 Int_t bufsize = 8000;
764 THbookBranch *branch = new THbookBranch(tree,name,(void*)&bigbuf[bufpos],fullname,bufsize);
765 tree->GetListOfBranches()->Add(branch);
766 branch->SetBlockName(block);
767 branch->SetUniqueID(varNumber);
768 varNumber++;
769
770 //NB: the information about isachar should be saved in the branch
771 // to be done
772 boolflag[i] = -10;
773 charflag[i] = 0;
774 if (itype == 4) {
775 //isabool++;
776 boolflag[i] = bufpos;
777 lenbool[i] = ielem;
778 }
779 bufpos += isize*ielem;
780 if (ischar) {
781 //isachar++;
782 charflag[i] = bufpos - 1;
783 lenchar[i] = isize * ielem;
784 }
785 TObjArray *ll= branch->GetListOfLeaves();
786 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
787 if (!leaf) continue;
788 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
789 if (leafcount) {
790 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
791 }
792 }
793 tree->SetEntries(nentries);
794 delete [] charflag;
795 delete [] lenchar;
796 delete [] boolflag;
797 delete [] lenbool;
798 delete [] boolarr;
799 delete [] chtag_out;
800
801 return tree;
802}
803
804////////////////////////////////////////////////////////////////////////////////
805/// Convert the Row-Wise-Ntuple id to a Root Tree
806
808{
809 const int nchar=9;
810 int nvar;
811 int i,j;
812 char *chtag_out;
813 float rmin[1000], rmax[1000];
814
815 if (id > 0) snprintf(idname,127,"h%d",id);
816 else snprintf(idname,127,"h_%d",-id);
817 hnoent(id,nentries);
818 //printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
819 nvar=0;
820#ifndef WIN32
821 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
822#else
823 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
824#endif
825
826 chtag_out = new char[nvar*nchar+1];
827
828 Int_t golower = 1;
829 chtag_out[nvar*nchar]=0;
830 for (i=0;i<80;i++)chtitl[i]=0;
831#ifndef WIN32
832 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
833#else
834 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
835#endif
836 hgnpar(id,"?",1);
837 char *name = chtag_out;
838 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
839 THbookTree *tree = new THbookTree(idname,id);
840 tree->SetHbookFile(this);
841 tree->SetType(0);
842 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
843
844 Int_t first,last;
845 for(i=0; i<nvar;i++) {
846 name[nchar-1] = 0;
847 first = last = 0;
849 // suppress trailing blanks
850 for (j=nchar-2;j>0;j--) {
851 if(golower) name[j] = tolower(name[j]);
852 if (name[j] == ' ' && last == 0) name[j] = 0;
853 else last = j;
854 }
855 if (golower == 2) name[0] = tolower(name[0]);
856
857 // suppress heading blanks
858 for (j=0;j<nchar;j++) {
859 if (name[j] != ' ') break;
860 first = j+1;
861 }
862 Int_t bufsize = 8000;
863 //tree->Branch(&name[first],&x[i],&name[first],bufsize);
864 THbookBranch *branch = new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
865 branch->SetAddress(&x[i]);
866 branch->SetBlockName(hbookName.Data());
867 tree->GetListOfBranches()->Add(branch);
868 name += nchar;
869 }
870 tree->SetEntries(nentries);
871 delete [] chtag_out;
872
873 return tree;
874}
875
876////////////////////////////////////////////////////////////////////////////////
877/// Convert an Hbook profile histogram into a Root TProfile
878///
879/// the following structure is used in Hbook
880/// lcid points to the profile in array iq
881/// lcont = lq(lcid-1)
882/// lw = lq(lcont)
883/// ln = lq(lw)
884/// if option S jbyt(iq(lw),1,2) = 1
885/// if option I jbyt(iq(lw),1,2) = 2
886
888{
889 if (id > 0) snprintf(idname,127,"h%d",id);
890 else snprintf(idname,127,"h_%d",-id);
891 hnoent(id,nentries);
892 Int_t lw = lq[lcont];
893 Int_t ln = lq[lw];
894#ifndef WIN32
896#else
898#endif
899 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
900 chtitl[4*nwt] = 0;
901 const char *option= " ";
902 if (iq[lw] == 1) option = "S";
903 if (iq[lw] == 2) option = "I";
905
906 const Int_t kCON1 = 9;
907 Int_t i;
908 Float_t x = 0.0;
909 Float_t y = 0.5*(ymin+ymax);
910 for (i=1;i<=ncx;i++) {
911 Int_t n = Int_t(q[ln+i]);
912 hix(id,i,x);
913 for (Int_t j=0;j<n;j++) {
914 p->Fill(x+offsetx,y);
915 }
917 Float_t error = TMath::Sqrt(q[lw+i]);
918 p->SetBinContent(i,content);
919 p->SetBinError(i,error);
920 }
921 p->SetEntries(nentries);
922 return p;
923}
924
925////////////////////////////////////////////////////////////////////////////////
926/// Convert an Hbook 1-d histogram into a Root TH1F
927
929{
930 if (id > 0) snprintf(idname,127,"h%d",id);
931 else snprintf(idname,127,"h_%d",-id);
932 hnoent(id,nentries);
933#ifndef WIN32
935#else
937#endif
938 chtitl[4*nwt] = 0;
939 TH1F *h1;
940 Int_t i;
941 if (hcbits[5]) {
942 Int_t lbins = lq[lcid-2];
943 Double_t *xbins = new Double_t[ncx+1];
944 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
945 h1 = new TH1F(idname,chtitl,ncx,xbins);
946 delete [] xbins;
947 } else {
949 }
950 if (hcbits[8]) h1->Sumw2();
951 TGraph *gr = nullptr;
952 if (hcbits[11]) {
953 gr = new TGraph(ncx);
955 }
956
957 Float_t x;
958 for (i=0;i<=ncx+1;i++) {
959 x = h1->GetBinCenter(i);
960 h1->Fill(x,hi(id,i));
961 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
962 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
963 }
965 if (hcbits[19]) {
966 yymax = q[lcid+kMAX1];
968 }
969 if (hcbits[20]) {
970 yymin = q[lcid+kMIN1];
972 }
974 return h1;
975}
976
977////////////////////////////////////////////////////////////////////////////////
978/// Convert an Hbook 2-d histogram into a Root TH2F
979
981{
982 if (id > 0) snprintf(idname,127,"h%d",id);
983 else snprintf(idname,127,"h_%d",-id);
984 hnoent(id,nentries);
985#ifndef WIN32
987#else
989#endif
990 chtitl[4*nwt] = 0;
992 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
993 Float_t offsety = 0.5*(ymax-ymin)/ncy;
994 Int_t lw = lq[lcont];
995 if (lw) h2->Sumw2();
996
997 Float_t x = 0.0, y = 0.0;
998 for (Int_t j=0;j<=ncy+1;j++) {
999 for (Int_t i=0;i<=ncx+1;i++) {
1000 hijxy(id,i,j,x,y);
1001 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
1002 if (lw) {
1003 Double_t err2 = hije(id,i,j);
1004 h2->SetBinError(i,j,err2);
1005 }
1006 }
1007 }
1008 h2->SetEntries(nentries);
1009 return h2;
1010}
1011
1012////////////////////////////////////////////////////////////////////////////////
1013/// List contents of Hbook directory
1014
1015void THbookFile::ls(const char *path) const
1016{
1017 Int_t nch = strlen(path);
1018 if (nch == 0) {
1019#ifndef WIN32
1021#else
1023#endif
1024 return;
1025 }
1026
1027#ifndef WIN32
1028 hldir(PASSCHAR(path),PASSCHAR("T"),strlen(path),1);
1029#else
1030 hldir(PASSCHAR(path),PASSCHAR("T"));
1031#endif
1032}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t nchar
char name[80]
Definition TGX11.cxx:110
float xmin
#define quest
#define hi
#define hgnt1
#define hrin
char idname[128]
#define hrend
int lcid
int nentries
float * q
#define hix
int lcdir
#define hgnpar
#define hntvar2
#define hdcofl
const Int_t kMIN1
int ncx
char chtitl[128]
float ymin
#define rzink
#define hntvar3
#define hlimit
const Int_t kMAX1
int nwt
static Int_t gLastEntry
#define hgive
int * iq
#define hropen
#define hbnam
#define hije
#define hie
#define hgiven
#define hcbits
int idb
int ncy
float xmax
#define hgnf
#define hcbook
#define PAWC_SIZE
#define type_of_call
int lcont
#define hmaxim
#define hldir
#define hgntf
int * lq
#define hminim
#define hdelet
#define hgnt
float ymax
#define hif
#define DEFCHAR
int ltab
#define hij
#define hnoent
#define hcdir
#define PASSCHAR(string)
#define rzcl
const Int_t kNRH
#define pawc
#define hijxy
#define gROOT
Definition TROOT.h:411
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define snprintf
Definition civetweb.c:1579
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2290
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:879
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9166
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:653
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:9231
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:654
TList * GetListOfFunctions() const
Definition TH1.h:489
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:9048
virtual void SetEntries(Double_t n)
Definition TH1.h:640
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
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:575
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:467
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
void MakeZombie()
Definition TObject.h:53
Profile Histogram.
Definition TProfile.h:32
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
const char * Data() const
Definition TString.h:384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
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