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