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
251
252////////////////////////////////////////////////////////////////////////////////
253///the constructor
254
255THbookFile::THbookFile() : TNamed(),fLun(0),fLrecl(0)
256{
257 fList = new TList();
258 fKeys = new TList();
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Constructor for an HBook file object
263
264THbookFile::THbookFile(const char *fname, Int_t lrecl)
265 :TNamed(fname,"")
266{
267 // Initialize the Hbook/Zebra store
268 Int_t i;
269 if (!fgPawInit) {
271 lq = &pawc[9];
272 iq = &pawc[17];
273 void *qq = iq;
274 q = (float*)qq;
275 int pawc_size = PAWC_SIZE;
276 hlimit(pawc_size);
277 fgLuns = new Int_t[10];
278 for (i=0;i<10;i++) fgLuns[i] = 0;
279 }
280
281 //find a free logical unit (max 10)
282 fLun = 0;
283 for (i=0;i<10;i++) {
284 if (fgLuns[i] == 0) {
285 fLun = 10+i;
286 fgLuns[i] = 1;
287 break;
288 }
289 }
290 if (fLun == 0) {
291 Error("THbookFile","Too many HbookFiles\n");
292 return;
293 }
294 char topdir[20];
295 snprintf(topdir,19,"lun%d",fLun);
296
297 Int_t ier = 0;
298#ifndef WIN32
299 hropen(fLun,PASSCHAR(topdir),PASSCHAR(fname),PASSCHAR("p"),lrecl,ier,strlen(topdir),strlen(fname),1);
300#else
301 hropen(fLun,PASSCHAR(topdir),PASSCHAR(fname),PASSCHAR("p"),lrecl,ier);
302#endif
303 fLrecl = lrecl;
304 SetTitle(topdir);
305 snprintf(topdir,19,"//lun%d",fLun);
306 fCurDir = topdir;
307
308 if (ier) printf (" Error on hropen was %d \n", ier);
309 if (quest[0]) {
310 printf("Error cannot open input file: %s\n",fname);
311 }
312 if (ier || quest[0]) {
313 fgLuns[fLun-10]=0;
314 fLun = 0;
315 fList = nullptr;
316 fKeys = nullptr;
317 MakeZombie();
318 return;
319 }
320
321 gROOT->GetListOfBrowsables()->Add(this,fname);
322
323 fList = new TList();
324 fKeys = new TList();
325 for (Int_t key=1;key<1000000;key++) {
326 int z0 = 0;
327 rzink(key,z0,"S",1);
328 if (quest[0]) break;
329 if (quest[13] & 8) continue;
330 Int_t id = quest[20];
331 THbookKey *akey = new THbookKey(id,this);
332 fKeys->Add(akey);
333 }
334}
335
336////////////////////////////////////////////////////////////////////////////////
337///destructor
338
340{
341 if (!fList) return;
342 Close();
343 delete fList;
344 delete fKeys;
345}
346
347////////////////////////////////////////////////////////////////////////////////
348/// to be implemented
349
351{
352 if( b ) {
353 b->Add(fList, "memory");
354 b->Add(fKeys, "IDs on disk");
355 }
356 cd();
357}
358
359////////////////////////////////////////////////////////////////////////////////
360/// change directory to dirname
361
362Bool_t THbookFile::cd(const char *dirname)
363{
364 Int_t nch = strlen(dirname);
365 if (nch == 0) {
366#ifndef WIN32
368#else
370#endif
371 return kTRUE;
372 }
373
374 char cdir[512];
375 Int_t i;
376 for (i=0;i<512;i++) cdir[i] = ' ';
377 cdir[511] = 0;
378#ifndef WIN32
379 hcdir(PASSCHAR(dirname),PASSCHAR(" "),nch,1);
380 hcdir(PASSCHAR(cdir),PASSCHAR("R"),511,1);
381#else
382 hcdir(PASSCHAR(dirname),PASSCHAR(" "));
383 hcdir(PASSCHAR(cdir),PASSCHAR("R"));
384#endif
385 for (i=510;i>=0;i--) {
386 if (cdir[i] != ' ') break;
387 cdir[i] = 0;
388 }
389 fCurDir = cdir;
390 printf("fCurdir=%s\n",fCurDir.Data());
391
392 return kTRUE;
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Close the Hbook file
397
399{
400 if(!IsOpen()) return;
401 if (!fList) return;
402
403 gROOT->GetListOfBrowsables()->Remove(this);
404
405 cd();
406
407 fList->Delete();
408 fKeys->Delete();
409 if (fgLuns) fgLuns[fLun-10] = 0;
410 hdelet(0);
411#ifndef WIN32
412 hrend(PASSCHAR(GetTitle()),strlen(GetTitle()));
413#else
415#endif
416}
417
418////////////////////////////////////////////////////////////////////////////////
419///remove id from file and memory
420
422{
423 hdelet(id);
424}
425
426////////////////////////////////////////////////////////////////////////////////
427/// return object with name in fList in memory
428
430{
431 return fList->FindObject(name);
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// return object with pointer obj in fList in memory
436
438{
439 return fList->FindObject(obj);
440}
441
442////////////////////////////////////////////////////////////////////////////////
443/// import Hbook object with identifier idd in memory
444
446{
447 Int_t id = 0;
448 for (Int_t key=1;key<1000000;key++) {
449 int z0 = 0;
450 rzink(key,z0,"S",1);
451 if (quest[0]) break;
452 if (quest[13] & 8) continue;
453 id = quest[20];
454 if (id == idd) break;
455 }
456 if (id == 0) return nullptr;
457 if (id != idd) {
458 printf("Error cannot find ID = %d\n",idd);
459 return nullptr;
460 }
461
462 int i999 = 999;
463 // must delete any previous object with the same ID !!
464 lcdir = hcbook[6];
465 ltab = hcbook[9];
466 for (Int_t i=1;i<=iq[lcdir+kNRH];i++) {
467 if (iq[ltab+i] == id) {
468 printf("WARNING, previous ID=%d is replaced\n",id);
469 hdelet(id);
470 break;
471 }
472 }
473 hrin(id,i999,0);
474 if (quest[0]) {
475 printf("Error cannot read ID = %d\n",id);
476 return nullptr;
477 }
478 hdcofl();
479 lcid = hcbook[10];
480 lcont = lq[lcid-1];
481 TObject *obj = nullptr;
482 if (hcbits[3]) {
483 if (iq[lcid-2] == 2) obj = ConvertRWN(id);
484 else obj = ConvertCWN(id);
485 //hdelet(id); //cannot be deleted here since used in GetEntry
486 if (obj) {
487 fList->Add(obj);
488 ((THbookTree *)obj)->SetTitle(GetName());
489 }
490 return obj;
491 }
492 if (hcbits[0] && hcbits[7]) {
493 obj = ConvertProfile(id);
494 hdelet(id);
495 if (obj) fList->Add(obj);
496 return obj;
497 }
498 if (hcbits[0]) {
499 obj = Convert1D(id);
500 hdelet(id);
501 if (obj) fList->Add(obj);
502 return obj;
503 }
504 if (hcbits[1] || hcbits[2]) {
505 obj = Convert2D(id);
506 hdelet(id);
507 if (obj) fList->Add(obj);
508 return obj;
509 }
510 return obj;
511}
512
513
514////////////////////////////////////////////////////////////////////////////////
515/// Read in memory all columns of entry number of ntuple id from the Hbook file
516
518{
519 Int_t ier = 0;
520 if (atype == 0) {
521 hgnf(id,entry+1,x[0],ier);
522 } else {
523 hgnt(id,entry+1,ier);
524 }
525 return 0;
526}
527
528////////////////////////////////////////////////////////////////////////////////
529/// Read in memory only the branch bname
530
532{
533 if (entry == gLastEntry) return 0;
534 gLastEntry = entry;
535 Int_t ier = 0;
536 //uses the fast read method using the Hbook tables computed in InitLeaves
537 hgntf(id,entry+1,ier);
538 //old alternative slow method
539//#ifndef WIN32
540// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier,strlen(blockname),strlen(branchname));
541//#else
542// hgnt1(id,PASSCHAR(blockname),PASSCHAR(branchname),0,-1,entry+1,ier);
543//#endif
544 return 0;
545}
546
547
548////////////////////////////////////////////////////////////////////////////////
549/// This function is called from the first entry in TTreePlayer::InitLoop
550/// It analyzes the list of variables involved in the current query
551/// and pre-process the internal Hbook tables to speed-up the search
552/// at the next entries.
553
555{
556 if (!formula) return;
557 Int_t ncodes = formula->GetNcodes();
558 for (Int_t i=1;i<=ncodes;i++) {
559 TLeaf *leaf = formula->GetLeaf(i-1);
560 if (!leaf) continue;
561 if (var == 5) {
562 //leafcount may be null in case of a fix size array
563 if (leaf->GetLeafCount()) leaf = leaf->GetLeafCount();
564 }
565 Int_t last = 0;
566 if (var == 1 && i == ncodes) last = 1;
567#ifndef WIN32
568 hntvar3(id,last,PASSCHAR(leaf->GetName()),strlen(leaf->GetName()));
569#else
570 hntvar3(id,last,PASSCHAR(leaf->GetName()));
571#endif
572 }
573}
574
575////////////////////////////////////////////////////////////////////////////////
576/// Returns kTRUE in case file is open and kFALSE if file is not open.
577
579{
580 return fLun == 0 ? kFALSE : kTRUE;
581}
582
583
584////////////////////////////////////////////////////////////////////////////////
585///Set branch address
586
587void THbookFile::SetBranchAddress(Int_t id, const char *bname, void *add)
588{
589 Int_t *iadd = (Int_t*)add;
590 Int_t &aadd = *iadd;
591#ifndef WIN32
592 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0,strlen(bname),4);
593#else
594 hbnam(id,PASSCHAR(bname),aadd,PASSCHAR("$SET"),0);
595#endif
596}
597
598////////////////////////////////////////////////////////////////////////////////
599/// Convert this Hbook file to a Root file with name rootname.
600/// if rootname="', rootname = hbook file name with .root instead of .hbook
601/// By default, the Root file is connected and returned
602/// option:
603/// - "NO" do not connect the Root file
604/// - "C" do not compress file (default is to compress)
605/// - "L" do not convert names to lower case (default is to convert)
606
607TFile *THbookFile::Convert2root(const char *rootname, Int_t /*lrecl*/,
609{
610 TString opt = option;
611 opt.ToLower();
612
613 Int_t nch = strlen(rootname);
614 char *rfile=nullptr;
615 if (nch) {
616 rfile = new char[nch+1];
617 strlcpy(rfile,rootname,nch+1);
618 } else {
619 nch = strlen(GetName());
620 rfile = new char[nch+1];
621 strlcpy(rfile,GetName(),nch+1);
622 char *dot = strrchr(rfile,'.');
623 if (dot) strcpy(dot+1,"root");
624 else strlcat(rfile,".root",nch+1);
625 }
626
627 nch = 2*nch+50;
628 char *cmd = new char[nch+1];
629 snprintf(cmd,nch,"h2root %s %s",GetName(),rfile);
630 if (opt.Contains("c")) strlcat (cmd," 0",nch+1);
631 if (opt.Contains("l")) strlcat (cmd," 0",nch+1);
632
633 gSystem->Exec(cmd);
634
635 delete [] cmd;
636 if (opt.Contains("no")) {delete [] rfile; return nullptr;}
637 TFile *f = new TFile(rfile);
638 delete [] rfile;
639 if (f->IsZombie()) {delete f; f = nullptr;}
640 return f;
641}
642
643
644////////////////////////////////////////////////////////////////////////////////
645/// Convert the Column-Wise-Ntuple id to a Root Tree
646
648{
649 const int nchar=9;
650 int nvar;
651 int i,j;
652 int nsub,itype,isize,ielem;
653 char *chtag_out;
654 float rmin[1000], rmax[1000];
655
656 if (id > 0) snprintf(idname,127,"h%d",id);
657 else snprintf(idname,127,"h_%d",-id);
658 hnoent(id,nentries);
659 //printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
660 nvar=0;
661#ifndef WIN32
662 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
663#else
664 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
665#endif
666 chtag_out = new char[nvar*nchar+1];
667 Int_t *charflag = new Int_t[nvar];
668 Int_t *lenchar = new Int_t[nvar];
669 Int_t *boolflag = new Int_t[nvar];
670 Int_t *lenbool = new Int_t[nvar];
671 UChar_t *boolarr = new UChar_t[10000];
672
673 chtag_out[nvar*nchar]=0;
674 for (i=0;i<80;i++)chtitl[i]=0;
675#ifndef WIN32
676 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
677#else
678 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
679#endif
680
681 Int_t bufpos = 0;
682 //Int_t isachar = 0;
683 //Int_t isabool = 0;
684 char fullname[64];
685 char name[32];
686 char block[32];
687 char oldblock[32];
688 strlcpy(oldblock,"OLDBLOCK",32);
689 Int_t oldischar = -1;
690 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
691 THbookTree *tree = new THbookTree(idname,id);
692 tree->SetHbookFile(this);
693 tree->SetType(1);
694
695 char *bigbuf = tree->MakeX(500000);
696
697#ifndef WIN32
698 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6);
699#else
700 hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0);
701#endif
702
703 UInt_t varNumber = 0;
704 Int_t golower = 1;
705 Int_t nbits = 0;
706 for(i=0; i<nvar;i++) {
707 memset(name,' ',sizeof(name));
708 name[sizeof(name)-1] = 0;
709 memset(block,' ',sizeof(block));
710 block[sizeof(block)-1] = 0;
711 memset(fullname,' ',sizeof(fullname));
712 fullname[sizeof(fullname)-1]=0;
713#ifndef WIN32
714 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
715#else
716 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
717#endif
718 TString hbookName = name;
719
720 for (j=30;j>0;j--) {
721 if(golower) name[j] = tolower(name[j]);
722 if (name[j] == ' ') name[j] = 0;
723 }
724 if (golower == 2) name[0] = tolower(name[0]);
725
726 for (j=62;j>0;j--) {
727 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
728 // convert also character after [, if golower == 2
729 if (golower == 2) fullname[j] = tolower(fullname[j]);
730 if (fullname[j] == ' ') fullname[j] = 0;
731 }
732 // convert also first character, if golower == 2
733 if (golower == 2) fullname[0] = tolower(fullname[0]);
734 for (j=30;j>0;j--) {
735 if (block[j] == ' ') block[j] = 0;
736 else break;
737 }
738 if (itype == 1 && isize == 4) strlcat(fullname,"/F",64);
739 if (itype == 1 && isize == 8) strlcat(fullname,"/D",64);
740 if (itype == 2) strlcat(fullname,"/I",64);
741 if (itype == 3) strlcat(fullname,"/i",64);
742// if (itype == 4) strlcat(fullname,"/i",64);
743 if (itype == 4) strlcat(fullname,"/b",64);
744 if (itype == 5) strlcat(fullname,"/C",64);
745//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 Int_t ischar;
747 if (itype == 5) ischar = 1;
748 else ischar = 0;
749
750 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
751 varNumber = 0;
752 strlcpy(oldblock,block,32);
753 oldischar = ischar;
754 Long_t add= (Long_t)&bigbuf[bufpos];
755 Int_t lblock = strlen(block);
756#ifndef WIN32
757 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
758#else
759 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
760#endif
761
762 }
763
764 Int_t bufsize = 8000;
765 THbookBranch *branch = new THbookBranch(tree,name,(void*)&bigbuf[bufpos],fullname,bufsize);
766 tree->GetListOfBranches()->Add(branch);
767 branch->SetBlockName(block);
768 branch->SetUniqueID(varNumber);
769 varNumber++;
770
771 //NB: the information about isachar should be saved in the branch
772 // to be done
773 boolflag[i] = -10;
774 charflag[i] = 0;
775 if (itype == 4) {
776 //isabool++;
777 boolflag[i] = bufpos;
778 lenbool[i] = ielem;
779 }
780 bufpos += isize*ielem;
781 if (ischar) {
782 //isachar++;
783 charflag[i] = bufpos - 1;
784 lenchar[i] = isize * ielem;
785 }
786 TObjArray *ll= branch->GetListOfLeaves();
787 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
788 if (!leaf) continue;
789 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
790 if (leafcount) {
791 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
792 }
793 }
794 tree->SetEntries(nentries);
795 delete [] charflag;
796 delete [] lenchar;
797 delete [] boolflag;
798 delete [] lenbool;
799 delete [] boolarr;
800 delete [] chtag_out;
801
802 return tree;
803}
804
805////////////////////////////////////////////////////////////////////////////////
806/// Convert the Row-Wise-Ntuple id to a Root Tree
807
809{
810 const int nchar=9;
811 int nvar;
812 int i,j;
813 char *chtag_out;
814 float rmin[1000], rmax[1000];
815
816 if (id > 0) snprintf(idname,127,"h%d",id);
817 else snprintf(idname,127,"h_%d",-id);
818 hnoent(id,nentries);
819 //printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
820 nvar=0;
821#ifndef WIN32
822 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
823#else
824 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
825#endif
826
827 chtag_out = new char[nvar*nchar+1];
828
829 Int_t golower = 1;
830 chtag_out[nvar*nchar]=0;
831 for (i=0;i<80;i++)chtitl[i]=0;
832#ifndef WIN32
833 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
834#else
835 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
836#endif
837 hgnpar(id,"?",1);
838 char *name = chtag_out;
839 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
840 THbookTree *tree = new THbookTree(idname,id);
841 tree->SetHbookFile(this);
842 tree->SetType(0);
843 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
844
845 Int_t first,last;
846 for(i=0; i<nvar;i++) {
847 name[nchar-1] = 0;
848 first = last = 0;
849 TString hbookName = name;
850 // suppress trailing blanks
851 for (j=nchar-2;j>0;j--) {
852 if(golower) name[j] = tolower(name[j]);
853 if (name[j] == ' ' && last == 0) name[j] = 0;
854 else last = j;
855 }
856 if (golower == 2) name[0] = tolower(name[0]);
857
858 // suppress heading blanks
859 for (j=0;j<nchar;j++) {
860 if (name[j] != ' ') break;
861 first = j+1;
862 }
863 Int_t bufsize = 8000;
864 //tree->Branch(&name[first],&x[i],&name[first],bufsize);
865 THbookBranch *branch = new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
866 branch->SetAddress(&x[i]);
867 branch->SetBlockName(hbookName.Data());
868 tree->GetListOfBranches()->Add(branch);
869 name += nchar;
870 }
871 tree->SetEntries(nentries);
872 delete [] chtag_out;
873
874 return tree;
875}
876
877////////////////////////////////////////////////////////////////////////////////
878/// Convert an Hbook profile histogram into a Root TProfile
879///
880/// the following structure is used in Hbook
881/// lcid points to the profile in array iq
882/// lcont = lq(lcid-1)
883/// lw = lq(lcont)
884/// ln = lq(lw)
885/// if option S jbyt(iq(lw),1,2) = 1
886/// if option I jbyt(iq(lw),1,2) = 2
887
889{
890 if (id > 0) snprintf(idname,127,"h%d",id);
891 else snprintf(idname,127,"h_%d",-id);
892 hnoent(id,nentries);
893 Int_t lw = lq[lcont];
894 Int_t ln = lq[lw];
895#ifndef WIN32
897#else
899#endif
900 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
901 chtitl[4*nwt] = 0;
902 const char *option= " ";
903 if (iq[lw] == 1) option = "S";
904 if (iq[lw] == 2) option = "I";
906
907 const Int_t kCON1 = 9;
908 Int_t i;
909 Float_t x = 0.0;
910 Float_t y = 0.5*(ymin+ymax);
911 for (i=1;i<=ncx;i++) {
912 Int_t n = Int_t(q[ln+i]);
913 hix(id,i,x);
914 for (Int_t j=0;j<n;j++) {
915 p->Fill(x+offsetx,y);
916 }
917 Float_t content = q[lcont+kCON1+i];
918 Float_t error = TMath::Sqrt(q[lw+i]);
919 p->SetBinContent(i,content);
920 p->SetBinError(i,error);
921 }
922 p->SetEntries(nentries);
923 return p;
924}
925
926////////////////////////////////////////////////////////////////////////////////
927/// Convert an Hbook 1-d histogram into a Root TH1F
928
930{
931 if (id > 0) snprintf(idname,127,"h%d",id);
932 else snprintf(idname,127,"h_%d",-id);
933 hnoent(id,nentries);
934#ifndef WIN32
936#else
938#endif
939 chtitl[4*nwt] = 0;
940 TH1F *h1;
941 Int_t i;
942 if (hcbits[5]) {
943 Int_t lbins = lq[lcid-2];
944 Double_t *xbins = new Double_t[ncx+1];
945 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
946 h1 = new TH1F(idname,chtitl,ncx,xbins);
947 delete [] xbins;
948 } else {
950 }
951 if (hcbits[8]) h1->Sumw2();
952 TGraph *gr = nullptr;
953 if (hcbits[11]) {
954 gr = new TGraph(ncx);
956 }
957
958 Float_t x;
959 for (i=0;i<=ncx+1;i++) {
960 x = h1->GetBinCenter(i);
961 h1->Fill(x,hi(id,i));
962 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
963 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
964 }
965 Float_t yymin, yymax;
966 if (hcbits[19]) {
967 yymax = q[lcid+kMAX1];
968 h1->SetMaximum(yymax);
969 }
970 if (hcbits[20]) {
971 yymin = q[lcid+kMIN1];
972 h1->SetMinimum(yymin);
973 }
975 return h1;
976}
977
978////////////////////////////////////////////////////////////////////////////////
979/// Convert an Hbook 2-d histogram into a Root TH2F
980
982{
983 if (id > 0) snprintf(idname,127,"h%d",id);
984 else snprintf(idname,127,"h_%d",-id);
985 hnoent(id,nentries);
986#ifndef WIN32
988#else
990#endif
991 chtitl[4*nwt] = 0;
993 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
994 Float_t offsety = 0.5*(ymax-ymin)/ncy;
995 Int_t lw = lq[lcont];
996 if (lw) h2->Sumw2();
997
998 Float_t x = 0.0, y = 0.0;
999 for (Int_t j=0;j<=ncy+1;j++) {
1000 for (Int_t i=0;i<=ncx+1;i++) {
1001 hijxy(id,i,j,x,y);
1002 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
1003 if (lw) {
1004 Double_t err2 = hije(id,i,j);
1005 h2->SetBinError(i,j,err2);
1006 }
1007 }
1008 }
1009 h2->SetEntries(nentries);
1010 return h2;
1011}
1012
1013////////////////////////////////////////////////////////////////////////////////
1014/// List contents of Hbook directory
1015
1016void THbookFile::ls(const char *path) const
1017{
1018 Int_t nch = strlen(path);
1019 if (nch == 0) {
1020#ifndef WIN32
1022#else
1024#endif
1025 return;
1026 }
1027
1028#ifndef WIN32
1029 hldir(PASSCHAR(path),PASSCHAR("T"),strlen(path),1);
1030#else
1031 hldir(PASSCHAR(path),PASSCHAR("T"));
1032#endif
1033}
#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
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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:407
R__EXTERN TSystem * gSystem
Definition TSystem.h:560
#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 ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
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:2315
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:9058
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:400
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:9123
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3345
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:401
TList * GetListOfFunctions() const
Definition TH1.h:242
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8937
virtual void SetEntries(Double_t n)
Definition TH1.h:387
2-D histogram with a float per channel (see TH1 documentation)}
Definition TH2.h:258
Int_t Fill(Double_t) override
Invalid Fill method.
Definition TH2.cxx:347
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
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:578
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:470
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
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
An array of TObjects.
Definition TObjArray.h:31
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
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:987
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:791
void MakeZombie()
Definition TObject.h:53
Profile Histogram.
Definition TProfile.h:32
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:421
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
const char * Data() const
Definition TString.h:380
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:640
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
Definition first.py:1
Definition tree.py:1