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
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 = 0;
316 fKeys = 0;
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 0;
457 if (id != idd) {
458 printf("Error cannot find ID = %d\n",idd);
459 return 0;
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 0;
477 }
478 hdcofl();
479 lcid = hcbook[10];
480 lcont = lq[lcid-1];
481 TObject *obj = 0;
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*/,
608 Option_t *option)
609{
610 TString opt = option;
611 opt.ToLower();
612
613 Int_t nch = strlen(rootname);
614 char *rfile=0;
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 0;}
637 TFile *f = new TFile(rfile);
638 delete [] rfile;
639 if (f->IsZombie()) {delete f; f = 0;}
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) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;}
776 bufpos += isize*ielem;
777 if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;}
778 TObjArray *ll= branch->GetListOfLeaves();
779 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
780 if (!leaf) continue;
781 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
782 if (leafcount) {
783 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
784 }
785 }
786 tree->SetEntries(nentries);
787 delete [] charflag;
788 delete [] lenchar;
789 delete [] boolflag;
790 delete [] lenbool;
791 delete [] boolarr;
792 delete [] chtag_out;
793
794 return tree;
795}
796
797////////////////////////////////////////////////////////////////////////////////
798/// Convert the Row-Wise-Ntuple id to a Root Tree
799
801{
802 const int nchar=9;
803 int nvar;
804 int i,j;
805 char *chtag_out;
806 float rmin[1000], rmax[1000];
807
808 if (id > 0) snprintf(idname,127,"h%d",id);
809 else snprintf(idname,127,"h_%d",-id);
810 hnoent(id,nentries);
811 //printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
812 nvar=0;
813#ifndef WIN32
814 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
815#else
816 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
817#endif
818
819 chtag_out = new char[nvar*nchar+1];
820
821 Int_t golower = 1;
822 chtag_out[nvar*nchar]=0;
823 for (i=0;i<80;i++)chtitl[i]=0;
824#ifndef WIN32
825 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
826#else
827 hgiven(id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
828#endif
829 hgnpar(id,"?",1);
830 char *name = chtag_out;
831 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
832 THbookTree *tree = new THbookTree(idname,id);
833 tree->SetHbookFile(this);
834 tree->SetType(0);
835 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
836
837 Int_t first,last;
838 for(i=0; i<nvar;i++) {
839 name[nchar-1] = 0;
840 first = last = 0;
841 TString hbookName = name;
842 // suppress trailing blanks
843 for (j=nchar-2;j>0;j--) {
844 if(golower) name[j] = tolower(name[j]);
845 if (name[j] == ' ' && last == 0) name[j] = 0;
846 else last = j;
847 }
848 if (golower == 2) name[0] = tolower(name[0]);
849
850 // suppress heading blanks
851 for (j=0;j<nchar;j++) {
852 if (name[j] != ' ') break;
853 first = j+1;
854 }
855 Int_t bufsize = 8000;
856 //tree->Branch(&name[first],&x[i],&name[first],bufsize);
857 THbookBranch *branch = new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
858 branch->SetAddress(&x[i]);
859 branch->SetBlockName(hbookName.Data());
860 tree->GetListOfBranches()->Add(branch);
861 name += nchar;
862 }
863 tree->SetEntries(nentries);
864 delete [] chtag_out;
865
866 return tree;
867}
868
869////////////////////////////////////////////////////////////////////////////////
870/// Convert an Hbook profile histogram into a Root TProfile
871///
872/// the following structure is used in Hbook
873/// lcid points to the profile in array iq
874/// lcont = lq(lcid-1)
875/// lw = lq(lcont)
876/// ln = lq(lw)
877/// if option S jbyt(iq(lw),1,2) = 1
878/// if option I jbyt(iq(lw),1,2) = 2
879
881{
882 if (id > 0) snprintf(idname,127,"h%d",id);
883 else snprintf(idname,127,"h_%d",-id);
884 hnoent(id,nentries);
885 Int_t lw = lq[lcont];
886 Int_t ln = lq[lw];
887#ifndef WIN32
889#else
891#endif
892 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
893 chtitl[4*nwt] = 0;
894 const char *option= " ";
895 if (iq[lw] == 1) option = "S";
896 if (iq[lw] == 2) option = "I";
898
899 const Int_t kCON1 = 9;
900 Int_t i;
901 Float_t x = 0.0;
902 Float_t y = 0.5*(ymin+ymax);
903 for (i=1;i<=ncx;i++) {
904 Int_t n = Int_t(q[ln+i]);
905 hix(id,i,x);
906 for (Int_t j=0;j<n;j++) {
907 p->Fill(x+offsetx,y);
908 }
909 Float_t content = q[lcont+kCON1+i];
910 Float_t error = TMath::Sqrt(q[lw+i]);
911 p->SetBinContent(i,content);
912 p->SetBinError(i,error);
913 }
915 return p;
916}
917
918////////////////////////////////////////////////////////////////////////////////
919/// Convert an Hbook 1-d histogram into a Root TH1F
920
922{
923 if (id > 0) snprintf(idname,127,"h%d",id);
924 else snprintf(idname,127,"h_%d",-id);
925 hnoent(id,nentries);
926#ifndef WIN32
928#else
930#endif
931 chtitl[4*nwt] = 0;
932 TH1F *h1;
933 Int_t i;
934 if (hcbits[5]) {
935 Int_t lbins = lq[lcid-2];
936 Double_t *xbins = new Double_t[ncx+1];
937 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
938 h1 = new TH1F(idname,chtitl,ncx,xbins);
939 delete [] xbins;
940 } else {
942 }
943 if (hcbits[8]) h1->Sumw2();
944 TGraph *gr = 0;
945 if (hcbits[11]) {
946 gr = new TGraph(ncx);
948 }
949
950 Float_t x;
951 for (i=0;i<=ncx+1;i++) {
952 x = h1->GetBinCenter(i);
953 h1->Fill(x,hi(id,i));
954 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
955 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
956 }
957 Float_t yymin, yymax;
958 if (hcbits[19]) {
959 yymax = q[lcid+kMAX1];
960 h1->SetMaximum(yymax);
961 }
962 if (hcbits[20]) {
963 yymin = q[lcid+kMIN1];
964 h1->SetMinimum(yymin);
965 }
967 return h1;
968}
969
970////////////////////////////////////////////////////////////////////////////////
971/// Convert an Hbook 2-d histogram into a Root TH2F
972
974{
975 if (id > 0) snprintf(idname,127,"h%d",id);
976 else snprintf(idname,127,"h_%d",-id);
977 hnoent(id,nentries);
978#ifndef WIN32
980#else
982#endif
983 chtitl[4*nwt] = 0;
985 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
986 Float_t offsety = 0.5*(ymax-ymin)/ncy;
987 Int_t lw = lq[lcont];
988 if (lw) h2->Sumw2();
989
990 Float_t x = 0.0, y = 0.0;
991 for (Int_t j=0;j<=ncy+1;j++) {
992 for (Int_t i=0;i<=ncx+1;i++) {
993 hijxy(id,i,j,x,y);
994 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
995 if (lw) {
996 Double_t err2 = hije(id,i,j);
997 h2->SetBinError(i,j,err2);
998 }
999 }
1000 }
1001 h2->SetEntries(nentries);
1002 return h2;
1003}
1004
1005////////////////////////////////////////////////////////////////////////////////
1006/// List contents of Hbook directory
1007
1008void THbookFile::ls(const char *path) const
1009{
1010 Int_t nch = strlen(path);
1011 if (nch == 0) {
1012#ifndef WIN32
1014#else
1016#endif
1017 return;
1018 }
1019
1020#ifndef WIN32
1021 hldir(PASSCHAR(path),PASSCHAR("T"),strlen(path),1);
1022#else
1023 hldir(PASSCHAR(path),PASSCHAR("T"));
1024#endif
1025}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
const Bool_t kFALSE
Definition RtypesCore.h:92
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
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
const Int_t kMIN1
#define hdcofl
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:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
#define snprintf
Definition civetweb.c:1540
TObjArray * GetListOfLeaves()
Definition TBranch.h:243
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:54
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:2284
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
Definition TH1.cxx:8981
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:398
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:9046
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3350
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:399
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:9062
TList * GetListOfFunctions() const
Definition TH1.h:243
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8860
virtual void SetEntries(Double_t n)
Definition TH1.h:385
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.
void SetBlockName(const char *name)
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...
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
virtual TObject * FindObject(const char *name) const
return object with name in fList in memory
TList * fList
Definition THbookFile.h:34
virtual ~THbookFile()
destructor
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()
the constructor
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.
virtual void Browse(TBrowser *b)
to be implemented
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.
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
virtual Int_t GetMaximum() const
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: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:578
virtual void Delete(Option_t *option="")
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
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:893
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition TObject.cxx:707
void MakeZombie()
Definition TObject.h:49
Profile Histogram.
Definition TProfile.h:32
Int_t Fill(const Double_t *v)
Definition TProfile.h:55
Basic string class.
Definition TString.h:136
Ssiz_t Length() const
Definition TString.h:410
void ToLower()
Change string to lower-case.
Definition TString.cxx:1145
const char * Data() const
Definition TString.h:369
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
virtual Int_t Exec(const char *shellcmd)
Execute a command.
Definition TSystem.cxx:654
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)
Definition TMath.h:691
Definition first.py:1
Definition tree.py:1