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