58 #define PAWC_SIZE 4000000
65 # define hcbits hcbits_
66 # define hcbook hcbook_
68 extern "C" int pawc[PAWC_SIZE];
69 extern "C" int quest[100];
70 extern "C" int hcbits[37];
71 extern "C" int hcbook[51];
72 extern "C" int rzcl[11];
76 # define hcbits HCBITS
77 # define hcbook HCBOOK
79 extern "C" int pawc[PAWC_SIZE];
80 extern "C" int quest[100];
81 extern "C" int hcbits[37];
82 extern "C" int hcbook[51];
83 extern "C" int rzcl[11];
92 int lcont, lcid, lcdir, ltab;
93 float xmin,xmax,ymin,ymax;
95 const Int_t kMIN1 = 7;
96 const Int_t kMAX1 = 8;
98 static Int_t gLastEntry = -1;
103 # define hlimit hlimit_
104 # define hldir hldir_
105 # define hropen hropen_
106 # define hrend hrend_
108 # define hnoent hnoent_
109 # define hgive hgive_
110 # define hgiven hgiven_
111 # define hgnpar hgnpar_
114 # define hgntf hgntf_
115 # define hgnt1 hgnt1_
116 # define rzink rzink_
117 # define hdcofl hdcofl_
118 # define hmaxim hmaxim_
119 # define hminim hminim_
120 # define hdelet hdelet_
121 # define hntvar2 hntvar2_
122 # define hntvar3 hntvar3_
123 # define hbname hbname_
124 # define hbnamc hbnamc_
125 # define hbnam hbnam_
131 # define hijxy hijxy_
133 # define hcdir hcdir_
135 # define type_of_call
136 # define DEFCHAR const char*
137 # define PASSCHAR(string) string
139 # define hlimit HLIMIT
141 # define hropen HROPEN
144 # define hnoent HNOENT
146 # define hgiven HGIVEN
147 # define hgnpar HGNPAR
153 # define hdcofl HDCOFL
154 # define hmaxim HMAXIM
155 # define hminim HMINIM
156 # define hdelet HDELET
157 # define hntvar2 HNTVAR2
158 # define hntvar3 HNTVAR3
159 # define hbname HBNAME
160 # define hbnamc HBNAMC
170 # define type_of_call _stdcall
171 # define DEFCHAR const char*, const int
172 # define PASSCHAR(string) string, strlen(string)
175 extern "C" void type_of_call hlimit(
const int&);
177 extern "C" void type_of_call hropen(
const int&,DEFCHAR,DEFCHAR,DEFCHAR,
178 const int&,
const int&,
const int,
const int,
const int);
179 extern "C" void type_of_call hrend(DEFCHAR,
const int);
181 extern "C" void type_of_call hropen(
const int&,DEFCHAR,DEFCHAR,DEFCHAR,
182 const int&,
const int&);
183 extern "C" void type_of_call hrend(DEFCHAR);
186 extern "C" void type_of_call hrin(
const int&,
const int&,
const int&);
187 extern "C" void type_of_call hnoent(
const int&,
const int&);
189 extern "C" void type_of_call hgive(
const int&,DEFCHAR,
const int&,
const float&,
const float&,
190 const int&,
const float&,
const float&,
const int&,
const int&,
const int);
192 extern "C" void type_of_call hgive(
const int&,DEFCHAR,
const int&,
const float&,
const float&,
193 const int&,
const float&,
const float&,
const int&,
const int&);
198 extern "C" void type_of_call hgiven(
const int&,DEFCHAR,
const int&,DEFCHAR,
199 const float&,
const float&,
const int,
const int);
200 extern "C" void type_of_call hgnt1(
const int&,DEFCHAR,DEFCHAR,
const int&,
const int&,
const int&,
const int&,
const int,
const int);
202 extern "C" void type_of_call hgiven(
const int&,DEFCHAR,
const int&,DEFCHAR,
203 const float&,
const float&);
204 extern "C" void type_of_call hgnt1(
const int&,DEFCHAR,DEFCHAR,
const int&,
const int&,
const int&,
const int&);
208 extern "C" void type_of_call hntvar2(
const int&,
const int&,DEFCHAR,DEFCHAR,DEFCHAR,
int&,
int&,
int&,
int&,
int&,
const int,
const int,
const int);
209 extern "C" void type_of_call hntvar3(
const int&,
const int&,DEFCHAR,
const int);
211 extern "C" void type_of_call hntvar2(
const int&,
const int&,DEFCHAR,DEFCHAR,DEFCHAR,
int&,
int&,
int&,
int&,
int&);
212 extern "C" void type_of_call hntvar3(
const int&,
const int&,DEFCHAR);
216 extern "C" void type_of_call hbnam(
const int&,DEFCHAR,
const int&,DEFCHAR,
const int&,
const int,
const int);
218 extern "C" void type_of_call hbnam(
const int&,DEFCHAR,
const int&,DEFCHAR,
const int&);
221 extern "C" void type_of_call hgnpar(
const int&,
const char *,
const int);
222 extern "C" void type_of_call hgnf(
const int&,
const int&,
const float&,
const int&);
223 extern "C" void type_of_call hgnt(
const int&,
const int&,
const int&);
224 extern "C" void type_of_call hgntf(
const int&,
const int&,
const int&);
225 extern "C" void type_of_call rzink(
const int&,
const int&,
const char *,
const int);
226 extern "C" void type_of_call hdcofl();
227 extern "C" void type_of_call hmaxim(
const int&,
const float&);
228 extern "C" void type_of_call hminim(
const int&,
const float&);
229 extern "C" void type_of_call hdelet(
const int&);
230 extern "C" float type_of_call hi(
const int&,
const int&);
231 extern "C" float type_of_call hie(
const int&,
const int&);
232 extern "C" float type_of_call hif(
const int&,
const int&);
233 extern "C" float type_of_call hij(
const int&,
const int&,
const int&);
234 extern "C" void type_of_call hix(
const int&,
const int&,
const float&);
235 extern "C" void type_of_call hijxy(
const int&,
const int&,
const int&,
const float&,
const float&);
236 extern "C" float type_of_call hije(
const int&,
const int&,
const int&);
238 extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR ,
const int,
const int);
239 extern "C" void type_of_call hldir(DEFCHAR,DEFCHAR ,
const int,
const int);
241 extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
242 extern "C" void type_of_call hldir(DEFCHAR,DEFCHAR);
245 Bool_t THbookFile::fgPawInit = kFALSE;
246 Int_t *THbookFile::fgLuns = 0;
248 ClassImp(THbookFile);
253 THbookFile::THbookFile() : TNamed(),fLun(0),fLrecl(0)
262 THbookFile::THbookFile(
const char *fname, Int_t lrecl)
273 int pawc_size = PAWC_SIZE;
275 fgLuns =
new Int_t[10];
276 for (i=0;i<10;i++) fgLuns[i] = 0;
282 if (fgLuns[i] == 0) {
289 Error(
"THbookFile",
"Too many HbookFiles\n");
293 snprintf(topdir,19,
"lun%d",fLun);
297 hropen(fLun,PASSCHAR(topdir),PASSCHAR(fname),PASSCHAR(
"p"),lrecl,ier,strlen(topdir),strlen(fname),1);
299 hropen(fLun,PASSCHAR(topdir),PASSCHAR(fname),PASSCHAR(
"p"),lrecl,ier);
303 snprintf(topdir,19,
"//lun%d",fLun);
306 if (ier) printf (
" Error on hropen was %d \n", ier);
308 printf(
"Error cannot open input file: %s\n",fname);
310 if (ier || quest[0]) {
319 gROOT->GetListOfBrowsables()->Add(
this,fname);
323 for (Int_t key=1;key<1000000;key++) {
327 if (quest[13] & 8)
continue;
328 Int_t
id = quest[20];
329 THbookKey *akey =
new THbookKey(
id,
this);
337 THbookFile::~THbookFile()
348 void THbookFile::Browse(TBrowser *b)
351 b->Add(fList,
"memory");
352 b->Add(fKeys,
"IDs on disk");
360 Bool_t THbookFile::cd(
const char *dirname)
362 Int_t nch = strlen(dirname);
365 hcdir(PASSCHAR(fCurDir.Data()),PASSCHAR(
" "),fCurDir.Length(),1);
367 hcdir(PASSCHAR(fCurDir.Data()),PASSCHAR(
" "));
374 for (i=0;i<512;i++) cdir[i] =
' ';
377 hcdir(PASSCHAR(dirname),PASSCHAR(
" "),nch,1);
378 hcdir(PASSCHAR(cdir),PASSCHAR(
"R"),511,1);
380 hcdir(PASSCHAR(dirname),PASSCHAR(
" "));
381 hcdir(PASSCHAR(cdir),PASSCHAR(
"R"));
383 for (i=510;i>=0;i--) {
384 if (cdir[i] !=
' ')
break;
388 printf(
"fCurdir=%s\n",fCurDir.Data());
396 void THbookFile::Close(Option_t *)
398 if(!IsOpen())
return;
401 gROOT->GetListOfBrowsables()->Remove(
this);
407 if (fgLuns) fgLuns[fLun-10] = 0;
410 hrend(PASSCHAR(GetTitle()),strlen(GetTitle()));
412 hrend(PASSCHAR(GetTitle()));
419 void THbookFile::DeleteID(Int_t
id)
427 TObject *THbookFile::FindObject(
const char *name)
const
429 return fList->FindObject(name);
435 TObject *THbookFile::FindObject(
const TObject *obj)
const
437 return fList->FindObject(obj);
443 TObject *THbookFile::Get(Int_t idd)
446 for (Int_t key=1;key<1000000;key++) {
450 if (quest[13] & 8)
continue;
452 if (
id == idd)
break;
454 if (
id == 0)
return 0;
456 printf(
"Error cannot find ID = %d\n",idd);
464 for (Int_t i=1;i<=iq[lcdir+kNRH];i++) {
465 if (iq[ltab+i] ==
id) {
466 printf(
"WARNING, previous ID=%d is replaced\n",
id);
473 printf(
"Error cannot read ID = %d\n",
id);
481 if (iq[lcid-2] == 2) obj = ConvertRWN(
id);
482 else obj = ConvertCWN(
id);
486 ((THbookTree *)obj)->SetTitle(GetName());
490 if (hcbits[0] && hcbits[7]) {
491 obj = ConvertProfile(
id);
493 if (obj) fList->Add(obj);
499 if (obj) fList->Add(obj);
502 if (hcbits[1] || hcbits[2]) {
505 if (obj) fList->Add(obj);
515 Int_t THbookFile::GetEntry(Int_t entry, Int_t
id, Int_t atype, Float_t *x)
519 hgnf(
id,entry+1,x[0],ier);
521 hgnt(
id,entry+1,ier);
529 Int_t THbookFile::GetEntryBranch(Int_t entry, Int_t
id)
531 if (entry == gLastEntry)
return 0;
535 hgntf(
id,entry+1,ier);
552 void THbookFile::InitLeaves(Int_t
id, Int_t var, TTreeFormula *formula)
554 if (!formula)
return;
555 Int_t ncodes = formula->GetNcodes();
556 for (Int_t i=1;i<=ncodes;i++) {
557 TLeaf *leaf = formula->GetLeaf(i-1);
561 if (leaf->GetLeafCount()) leaf = leaf->GetLeafCount();
564 if (var == 1 && i == ncodes) last = 1;
566 hntvar3(
id,last,PASSCHAR(leaf->GetName()),strlen(leaf->GetName()));
568 hntvar3(
id,last,PASSCHAR(leaf->GetName()));
576 Bool_t THbookFile::IsOpen()
const
578 return fLun == 0 ? kFALSE : kTRUE;
585 void THbookFile::SetBranchAddress(Int_t
id,
const char *bname,
void *add)
587 Int_t *iadd = (Int_t*)add;
590 hbnam(
id,PASSCHAR(bname),aadd,PASSCHAR(
"$SET"),0,strlen(bname),4);
592 hbnam(
id,PASSCHAR(bname),aadd,PASSCHAR(
"$SET"),0);
605 TFile *THbookFile::Convert2root(
const char *rootname, Int_t ,
608 TString opt = option;
611 Int_t nch = strlen(rootname);
614 rfile =
new char[nch+1];
615 strlcpy(rfile,rootname,nch+1);
617 nch = strlen(GetName());
618 rfile =
new char[nch+1];
619 strlcpy(rfile,GetName(),nch+1);
620 char *dot = strrchr(rfile,
'.');
621 if (dot) strcpy(dot+1,
"root");
622 else strlcat(rfile,
".root",nch+1);
626 char *cmd =
new char[nch+1];
627 snprintf(cmd,nch,
"h2root %s %s",GetName(),rfile);
628 if (opt.Contains(
"c")) strlcat (cmd,
" 0",nch+1);
629 if (opt.Contains(
"l")) strlcat (cmd,
" 0",nch+1);
634 if (opt.Contains(
"no")) {
delete [] rfile;
return 0;}
635 TFile *f =
new TFile(rfile);
637 if (f->IsZombie()) {
delete f; f = 0;}
645 TObject *THbookFile::ConvertCWN(Int_t
id)
650 int nsub,itype,isize,ielem;
652 float rmin[1000], rmax[1000];
654 if (
id > 0) snprintf(idname,127,
"h%d",
id);
655 else snprintf(idname,127,
"h_%d",-
id);
660 hgiven(
id,chtitl,nvar,PASSCHAR(
""),rmin[0],rmax[0],80,0);
662 hgiven(
id,chtitl,80,nvar,PASSCHAR(
""),rmin[0],rmax[0]);
664 chtag_out =
new char[nvar*nchar+1];
665 Int_t *charflag =
new Int_t[nvar];
666 Int_t *lenchar =
new Int_t[nvar];
667 Int_t *boolflag =
new Int_t[nvar];
668 Int_t *lenbool =
new Int_t[nvar];
669 UChar_t *boolarr =
new UChar_t[10000];
671 chtag_out[nvar*nchar]=0;
672 for (i=0;i<80;i++)chtitl[i]=0;
674 hgiven(
id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
676 hgiven(
id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
686 strlcpy(oldblock,
"OLDBLOCK",32);
687 Int_t oldischar = -1;
688 for (i=80;i>0;i--) {
if (chtitl[i] ==
' ') chtitl[i] = 0; }
689 THbookTree *tree =
new THbookTree(idname,
id);
690 tree->SetHbookFile(
this);
693 char *bigbuf = tree->MakeX(500000);
696 hbnam(
id,PASSCHAR(
" "),bigbuf[0],PASSCHAR(
"$CLEAR"),0,1,6);
698 hbnam(
id,PASSCHAR(
" "),bigbuf[0],PASSCHAR(
"$CLEAR"),0);
701 UInt_t varNumber = 0;
704 for(i=0; i<nvar;i++) {
705 memset(name,
' ',
sizeof(name));
706 name[
sizeof(name)-1] = 0;
707 memset(block,
' ',
sizeof(block));
708 block[
sizeof(block)-1] = 0;
709 memset(fullname,
' ',
sizeof(fullname));
710 fullname[
sizeof(fullname)-1]=0;
712 hntvar2(
id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
714 hntvar2(
id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
716 TString hbookName = name;
719 if(golower) name[j] = tolower(name[j]);
720 if (name[j] ==
' ') name[j] = 0;
722 if (golower == 2) name[0] = tolower(name[0]);
725 if(golower && fullname[j-1] !=
'[') fullname[j] = tolower(fullname[j]);
727 if (golower == 2) fullname[j] = tolower(fullname[j]);
728 if (fullname[j] ==
' ') fullname[j] = 0;
731 if (golower == 2) fullname[0] = tolower(fullname[0]);
733 if (block[j] ==
' ') block[j] = 0;
736 if (itype == 1 && isize == 4) strlcat(fullname,
"/F",64);
737 if (itype == 1 && isize == 8) strlcat(fullname,
"/D",64);
738 if (itype == 2) strlcat(fullname,
"/I",64);
739 if (itype == 3) strlcat(fullname,
"/i",64);
741 if (itype == 4) strlcat(fullname,
"/b",64);
742 if (itype == 5) strlcat(fullname,
"/C",64);
745 if (itype == 5) ischar = 1;
748 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
750 strlcpy(oldblock,block,32);
752 Long_t add= (Long_t)&bigbuf[bufpos];
753 Int_t lblock = strlen(block);
755 hbnam(
id,PASSCHAR(block),add,PASSCHAR(
"$SET"),ischar,lblock,4);
757 hbnam(
id,PASSCHAR(block),add,PASSCHAR(
"$SET"),ischar);
762 Int_t bufsize = 8000;
763 THbookBranch *branch =
new THbookBranch(tree,name,(
void*)&bigbuf[bufpos],fullname,bufsize);
764 tree->GetListOfBranches()->Add(branch);
765 branch->SetBlockName(block);
766 branch->SetUniqueID(varNumber);
773 if (itype == 4) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;}
774 bufpos += isize*ielem;
775 if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;}
776 TObjArray *ll= branch->GetListOfLeaves();
777 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
779 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
781 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
784 tree->SetEntries(nentries);
798 TObject *THbookFile::ConvertRWN(Int_t
id)
804 float rmin[1000], rmax[1000];
806 if (
id > 0) snprintf(idname,127,
"h%d",
id);
807 else snprintf(idname,127,
"h_%d",-
id);
812 hgiven(
id,chtitl,nvar,PASSCHAR(
""),rmin[0],rmax[0],80,0);
814 hgiven(
id,chtitl,80,nvar,PASSCHAR(
""),rmin[0],rmax[0]);
817 chtag_out =
new char[nvar*nchar+1];
820 chtag_out[nvar*nchar]=0;
821 for (i=0;i<80;i++)chtitl[i]=0;
823 hgiven(
id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,nchar);
825 hgiven(
id,chtitl,80,nvar,chtag_out,nchar,rmin[0],rmax[0]);
828 char *name = chtag_out;
829 for (i=80;i>0;i--) {
if (chtitl[i] ==
' ') chtitl[i] = 0; }
830 THbookTree *tree =
new THbookTree(idname,
id);
831 tree->SetHbookFile(
this);
833 Float_t *x = (Float_t*)tree->MakeX(nvar*4);
836 for(i=0; i<nvar;i++) {
839 TString hbookName = name;
841 for (j=nchar-2;j>0;j--) {
842 if(golower) name[j] = tolower(name[j]);
843 if (name[j] ==
' ' && last == 0) name[j] = 0;
846 if (golower == 2) name[0] = tolower(name[0]);
849 for (j=0;j<nchar;j++) {
850 if (name[j] !=
' ')
break;
853 Int_t bufsize = 8000;
855 THbookBranch *branch =
new THbookBranch(tree,&name[first],&x[4*i],&name[first],bufsize);
856 branch->SetAddress(&x[i]);
857 branch->SetBlockName(hbookName.Data());
858 tree->GetListOfBranches()->Add(branch);
861 tree->SetEntries(nentries);
878 TObject *THbookFile::ConvertProfile(Int_t
id)
880 if (
id > 0) snprintf(idname,127,
"h%d",
id);
881 else snprintf(idname,127,
"h_%d",-
id);
883 Int_t lw = lq[lcont];
886 hgive(
id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
888 hgive(
id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
890 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
892 const char *option=
" ";
893 if (iq[lw] == 1) option =
"S";
894 if (iq[lw] == 2) option =
"I";
895 TProfile *p =
new TProfile(idname,chtitl,ncx,xmin,xmax,ymin,ymax,option);
897 const Int_t kCON1 = 9;
900 Float_t y = 0.5*(ymin+ymax);
901 for (i=1;i<=ncx;i++) {
902 Int_t n = Int_t(q[ln+i]);
904 for (Int_t j=0;j<n;j++) {
905 p->Fill(x+offsetx,y);
907 Float_t content = q[lcont+kCON1+i];
908 Float_t error = TMath::Sqrt(q[lw+i]);
909 p->SetBinContent(i,content);
910 p->SetBinError(i,error);
912 p->SetEntries(nentries);
919 TObject *THbookFile::Convert1D(Int_t
id)
921 if (
id > 0) snprintf(idname,127,
"h%d",
id);
922 else snprintf(idname,127,
"h_%d",-
id);
925 hgive(
id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
927 hgive(
id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
933 Int_t lbins = lq[lcid-2];
934 Double_t *xbins =
new Double_t[ncx+1];
935 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
936 h1 =
new TH1F(idname,chtitl,ncx,xbins);
939 h1 =
new TH1F(idname,chtitl,ncx,xmin,xmax);
941 if (hcbits[8]) h1->Sumw2();
944 gr =
new TGraph(ncx);
945 h1->GetListOfFunctions()->Add(gr);
949 for (i=0;i<=ncx+1;i++) {
950 x = h1->GetBinCenter(i);
951 h1->Fill(x,hi(
id,i));
952 if (hcbits[8]) h1->SetBinError(i,hie(
id,i));
953 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(
id,i));
955 Float_t yymin, yymax;
957 yymax = q[lcid+kMAX1];
958 h1->SetMaximum(yymax);
961 yymin = q[lcid+kMIN1];
962 h1->SetMinimum(yymin);
964 h1->SetEntries(nentries);
971 TObject *THbookFile::Convert2D(Int_t
id)
973 if (
id > 0) snprintf(idname,127,
"h%d",
id);
974 else snprintf(idname,127,
"h_%d",-
id);
977 hgive(
id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
979 hgive(
id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
982 TH2F *h2 =
new TH2F(idname,chtitl,ncx,xmin,xmax,ncy,ymin,ymax);
983 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
984 Float_t offsety = 0.5*(ymax-ymin)/ncy;
985 Int_t lw = lq[lcont];
988 Float_t x = 0.0, y = 0.0;
989 for (Int_t j=0;j<=ncy+1;j++) {
990 for (Int_t i=0;i<=ncx+1;i++) {
992 h2->Fill(x+offsetx,y+offsety,hij(
id,i,j));
994 Double_t err2 = hije(
id,i,j);
995 h2->SetBinError(i,j,err2);
999 h2->SetEntries(nentries);
1006 void THbookFile::ls(
const char *path)
const
1008 Int_t nch = strlen(path);
1011 hldir(PASSCHAR(fCurDir.Data()),PASSCHAR(
"T"),fCurDir.Length(),1);
1013 hldir(PASSCHAR(fCurDir.Data()),PASSCHAR(
"T"));
1019 hldir(PASSCHAR(path),PASSCHAR(
"T"),strlen(path),1);
1021 hldir(PASSCHAR(path),PASSCHAR(
"T"));