00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <ctype.h>
00025
00026 #include "Riostream.h"
00027 #include "TFile.h"
00028 #include "TDirectoryFile.h"
00029 #include "TTree.h"
00030 #include "TLeafI.h"
00031 #include "TH1.h"
00032 #include "TH2.h"
00033 #include "TProfile.h"
00034 #include "TGraph.h"
00035 #include "TMath.h"
00036
00037
00038
00039
00040
00041 #ifndef WIN32
00042 #define PAWC_SIZE 4000000
00043 # define bigbuf bigbuf_
00044 # define pawc pawc_
00045 # define quest quest_
00046 # define hcbits hcbits_
00047 # define hcbook hcbook_
00048 # define rzcl rzcl_
00049
00050
00051
00052
00053
00054 extern "C" char bigbuf[PAWC_SIZE];
00055 extern "C" int pawc[PAWC_SIZE];
00056 extern "C" int quest[100];
00057 extern "C" int hcbits[37];
00058 extern "C" int hcbook[51];
00059 extern "C" int rzcl[11];
00060 #else
00061
00062 #define PAWC_SIZE 4000000
00063 # define bigbuf BIGBUF
00064 # define pawc PAWC
00065 # define quest QUEST
00066 # define hcbits HCBITS
00067 # define hcbook HCBOOK
00068 # define rzcl RZCL
00069 extern "C" int bigbuf[PAWC_SIZE];
00070 extern "C" int pawc[PAWC_SIZE];
00071 extern "C" int quest[100];
00072 extern "C" int hcbits[37];
00073 extern "C" int hcbook[51];
00074 extern "C" int rzcl[11];
00075 #endif
00076
00077 int *iq, *lq;
00078 float *q;
00079 char idname[128];
00080 int nentries;
00081 char chtitl[128];
00082 int ncx,ncy,nwt,idb;
00083 int lcont, lcid, lcdir;
00084 float xmin,xmax,ymin,ymax;
00085 const Int_t kMIN1 = 7;
00086 const Int_t kMAX1 = 8;
00087
00088 #if defined __linux
00089
00090 int xargv=0;
00091 int xargc=0;
00092 void MAIN__() {}
00093 #endif
00094
00095
00096
00097 #ifndef WIN32
00098 # define hlimit hlimit_
00099 # define hropen hropen_
00100 # define hrin hrin_
00101 # define hnoent hnoent_
00102 # define hgive hgive_
00103 # define hgiven hgiven_
00104 # define hprntu hprntu_
00105 # define hgnpar hgnpar_
00106 # define hgnf hgnf_
00107 # define hgnt hgnt_
00108 # define rzink rzink_
00109 # define hdcofl hdcofl_
00110 # define hmaxim hmaxim_
00111 # define hminim hminim_
00112 # define hdelet hdelet_
00113 # define hntvar2 hntvar2_
00114 # define hbname hbname_
00115 # define hbnamc hbnamc_
00116 # define hbnam hbnam_
00117 # define hi hi_
00118 # define hie hie_
00119 # define hif hif_
00120 # define hij hij_
00121 # define hix hix_
00122 # define hijxy hijxy_
00123 # define hije hije_
00124 # define hcdir hcdir_
00125 # define zitoh zitoh_
00126 # define uhtoc uhtoc_
00127
00128 # define type_of_call
00129 # define DEFCHAR const char*
00130 # define PASSCHAR(string) string
00131 #else
00132 # define hlimit HLIMIT
00133 # define hropen HROPEN
00134 # define hrin HRIN
00135 # define hnoent HNOENT
00136 # define hgive HGIVE
00137 # define hgiven HGIVEN
00138 # define hprntu HPRNTU
00139 # define hgnpar HGNPAR
00140 # define hgnf HGNF
00141 # define hgnt HGNT
00142 # define rzink RZINK
00143 # define hdcofl HDCOFL
00144 # define hmaxim HMAXIM
00145 # define hminim HMINIM
00146 # define hdelet HDELET
00147 # define hntvar2 HNTVAR2
00148 # define hbname HBNAME
00149 # define hbnamc HBNAMC
00150 # define hbnam HBNAM
00151 # define hi HI
00152 # define hie HIE
00153 # define hif HIF
00154 # define hij HIJ
00155 # define hix HIX
00156 # define hijxy HIJXY
00157 # define hije HIJE
00158 # define hcdir HCDIR
00159 # define zitoh ZITOH
00160 # define uhtoc UHTOC
00161 # define type_of_call _stdcall
00162 # define DEFCHAR const char*, const int
00163 # define PASSCHAR(string) string, strlen(string)
00164 #endif
00165
00166 extern "C" void type_of_call hlimit(const int&);
00167 #ifndef WIN32
00168 extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
00169 const int&,const int&,const int,const int,const int);
00170 #else
00171 extern "C" void type_of_call hropen(const int&,DEFCHAR,DEFCHAR,DEFCHAR,
00172 const int&,const int&);
00173 #endif
00174
00175 extern "C" void type_of_call hrin(const int&,const int&,const int&);
00176 extern "C" void type_of_call hnoent(const int&,const int&);
00177 #ifndef WIN32
00178 extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
00179 const int&,const float&,const float&,const int&,const int&,const int);
00180 #else
00181 extern "C" void type_of_call hgive(const int&,DEFCHAR,const int&,const float&,const float&,
00182 const int&,const float&,const float&,const int&,const int&);
00183 #endif
00184
00185 #ifndef WIN32
00186 extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
00187 const float&,const float&,const int,const int);
00188 #else
00189 extern "C" void type_of_call hgiven(const int&,DEFCHAR,const int&,DEFCHAR,
00190 const float&,const float&);
00191 #endif
00192
00193 #ifndef WIN32
00194 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);
00195 #else
00196 extern "C" void type_of_call hntvar2(const int&,const int&,DEFCHAR,DEFCHAR,DEFCHAR,int&,int&,int&,int&,int&);
00197 #endif
00198
00199 #ifndef WIN32
00200 extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&,const int, const int);
00201 #else
00202 extern "C" void type_of_call hbnam(const int&,DEFCHAR,const int&,DEFCHAR,const int&);
00203 #endif
00204
00205 extern "C" void type_of_call hprntu(const int&);
00206 extern "C" void type_of_call hgnpar(const int&,const char *,const int);
00207 extern "C" void type_of_call hgnf(const int&,const int&,const float&,const int&);
00208 extern "C" void type_of_call hgnt(const int&,const int&,const int&);
00209 extern "C" void type_of_call rzink(const int&,const int&,const char *,const int);
00210 extern "C" void type_of_call hdcofl();
00211 extern "C" void type_of_call hmaxim(const int&,const float&);
00212 extern "C" void type_of_call hminim(const int&,const float&);
00213 extern "C" void type_of_call hdelet(const int&);
00214 extern "C" void type_of_call hix(const int&,const int&,const float&);
00215 extern "C" void type_of_call hijxy(const int&,const int&,const int&,const float&,const float&);
00216
00217 #ifndef R__B64BUG
00218 extern "C" float type_of_call hi(const int&,const int&);
00219 extern "C" float type_of_call hie(const int&,const int&);
00220 extern "C" float type_of_call hif(const int&,const int&);
00221 extern "C" float type_of_call hij(const int&,const int&,const int&);
00222 extern "C" float type_of_call hije(const int&,const int&,const int&);
00223 #else
00224 extern "C" double type_of_call hi(const int&,const int&);
00225 extern "C" double type_of_call hie(const int&,const int&);
00226 extern "C" double type_of_call hif(const int&,const int&);
00227 extern "C" double type_of_call hij(const int&,const int&,const int&);
00228 extern "C" double type_of_call hije(const int&,const int&,const int&);
00229 #endif
00230
00231 #ifndef WIN32
00232 extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR ,const int,const int);
00233 #else
00234 extern "C" void type_of_call hcdir(DEFCHAR,DEFCHAR);
00235 #endif
00236
00237 extern "C" void type_of_call zitoh(const int&,const int&,const int&);
00238 #ifndef WIN32
00239 extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&,const int);
00240 #else
00241 extern "C" void type_of_call uhtoc(const int&,const int&,DEFCHAR,int&);
00242 #endif
00243
00244 extern void convert_directory(const char*);
00245 extern void convert_1d(Int_t id);
00246 extern void convert_2d(Int_t id);
00247 extern void convert_profile(Int_t id);
00248 extern void convert_cwn(Int_t id);
00249 extern void convert_rwn(Int_t id);
00250
00251 Int_t golower = 1;
00252 Int_t bufsize = 64000;
00253 Int_t optcwn = 1;
00254 int main(int argc, char **argv)
00255 {
00256
00257 if (argc < 2) {
00258 printf("******Error in invoking h2root\n");
00259 printf("===> h2root file.hbook file.root [compress] [tolower] [lrecl] [bufsize] [optcwn] \n");
00260 printf(" if file.root is not given it will be = file.root\n");
00261 printf(" compress = 1 by default (use 0 for no compression)\n");
00262 printf(" tolower = 1 by default (use 0 to keep case of column names)\n");
00263 printf(" lrecl =0 by default (must be specified if >8092)\n");
00264 printf(" bufsize = 8000 by default (branch buffer size)\n");
00265 printf(" for cwn ntuple only: optcwn = 1 (default) 1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) \n");
00266 return 1;
00267 }
00268 lq = &pawc[9];
00269 iq = &pawc[17];
00270 void *qq = iq;
00271 q = (float*)qq;
00272 char *file_in=argv[1];
00273 char *file_out;
00274 Int_t compress = 1;
00275 int ier=0, record_size=0;
00276 if (argc > 7) {
00277 optcwn = atoi(argv[7]);
00278 }
00279 if (argc > 6) {
00280 bufsize = atoi(argv[6]);
00281 }
00282 if (argc > 5) {
00283 record_size = atoi(argv[5]);
00284 }
00285 if (argc > 4) {
00286 golower = atoi(argv[4]);
00287 }
00288 if (argc > 3) {
00289 compress = atoi(argv[3]);
00290 }
00291 if (argc > 2) {
00292 file_out=argv[2];
00293 } else {
00294 Int_t nchf = strlen(file_in)+strlen(".root")+1;
00295 file_out= new char[nchf];
00296 strlcpy(file_out,file_in,nchf);
00297 char *dot = strrchr(file_out,'.');
00298 if (dot) strcpy(dot+1,"root");
00299 else strlcat(file_out,".root",nchf);
00300 }
00301
00302 #if defined(_HIUX_SOURCE) && !defined(__GNUC__)
00303 hf_fint((char *)NULL);
00304 #endif
00305
00306
00307 int pawc_size = PAWC_SIZE;
00308 hlimit(pawc_size);
00309
00310 int lun = 10;
00311 #ifndef WIN32
00312 hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("p"),record_size,ier,7,strlen(file_in),1);
00313 #else
00314 hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("p"),record_size,ier);
00315 #endif
00316
00317 if (ier) printf (" Error on hropen was %d \n", ier);
00318 if (quest[0]) {
00319 printf("Error cannot open input file: %s\n",file_in);
00320 return 1;
00321 }
00322
00323 char root_file_title[2000];
00324 snprintf(root_file_title,2000,"HBOOK file: %s converted to ROOT",file_in);
00325 TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,compress);
00326
00327 if (!hfile) {
00328 printf("Error: can't open output file: %s \n",file_out);
00329 return 1;
00330 }
00331
00332
00333 convert_directory("//example");
00334
00335 hfile->Write();
00336 hfile->ls();
00337 hfile->Close();
00338 delete hfile;
00339 return(0);
00340 }
00341
00342
00343 void convert_directory(const char *dir)
00344 {
00345
00346 printf(" Converting directory %s\n",dir);
00347 Int_t id;
00348
00349
00350
00351 for (Int_t key=1;key<1000000;key++) {
00352 int z0 = 0;
00353 rzink(key,z0,"S",1);
00354 if (quest[0]) break;
00355 if (quest[13] & 8) {
00356 continue;
00357
00358
00359
00360
00361
00362
00363
00364
00365 }
00366 id = quest[20];
00367
00368
00369
00370 int i999 = 999;
00371 hrin(id,i999,0);
00372 if (quest[0]) {
00373 printf("Error cannot read ID = %d\n",id);
00374
00375 }
00376 hdcofl();
00377 lcid = hcbook[10];
00378 lcont = lq[lcid-1];
00379 if (hcbits[3]) {
00380 if (iq[lcid-2] == 2) convert_rwn(id);
00381 else convert_cwn(id);
00382 hdelet(id);
00383 continue;
00384 }
00385 if (hcbits[0] && hcbits[7]) {
00386 convert_profile(id);
00387 hdelet(id);
00388 continue;
00389 }
00390 if (hcbits[0]) {
00391 convert_1d(id);
00392 hdelet(id);
00393 continue;
00394 }
00395 if (hcbits[1] || hcbits[2]) {
00396 convert_2d(id);
00397 hdelet(id);
00398 }
00399 }
00400
00401
00402 const Int_t kKLS = 26;
00403 const Int_t kKNSD = 23;
00404 lcdir = rzcl[2];
00405 Int_t ls = iq[lcdir+kKLS];
00406 Int_t ndir = iq[lcdir+kKNSD];
00407 Int_t nch=16;
00408 Int_t ihdir[4];
00409 Int_t ncw = 4;
00410 TDirectory *cursav = gDirectory;
00411 Int_t i;
00412 char chdir[17];
00413 char hbookdir[17];
00414 for (Int_t k=0;k<ndir;k++) {
00415 lcdir = rzcl[2];
00416 zitoh(iq[lcdir+ls+7*k],ihdir[0],ncw);
00417 for (i=0;i<17;i++) chdir[i] = 0;
00418 #ifndef WIN32
00419 uhtoc(ihdir[0],ncw,chdir,nch ,16);
00420 #else
00421 uhtoc(ihdir[0],ncw,chdir,16,nch);
00422 #endif
00423
00424 if (strchr(chdir,'/')) {
00425 printf("Sorry cannot convert directory name %s because it contains a slash\n",chdir);
00426 continue;
00427 }
00428 strlcpy(hbookdir,chdir,17);
00429 for (i=16;i>0;i--) {
00430 if (chdir[i] == 0) continue;
00431 if (chdir[i] != ' ') break;
00432 chdir[i] = 0;
00433 }
00434 #ifndef WIN32
00435 hcdir(PASSCHAR(hbookdir),PASSCHAR(" "),16,1);
00436 #else
00437 hcdir(PASSCHAR(hbookdir),PASSCHAR(" "));
00438 #endif
00439 TDirectoryFile *newdir = new TDirectoryFile(chdir,chdir);
00440 newdir->cd();
00441 convert_directory(chdir);
00442 #ifndef WIN32
00443 hcdir(PASSCHAR("\\"),PASSCHAR(" "),1,1);
00444 #else
00445 hcdir(PASSCHAR("\\"),PASSCHAR(" "));
00446 #endif
00447 newdir->Write();
00448 cursav->cd();
00449 }
00450 }
00451
00452
00453 void convert_1d(Int_t id)
00454 {
00455
00456 if (id > 0) snprintf(idname,128,"h%d",id);
00457 else snprintf(idname,128,"h_%d",-id);
00458 hnoent(id,nentries);
00459 #ifndef WIN32
00460 hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
00461 #else
00462 hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
00463 #endif
00464 chtitl[4*nwt] = 0;
00465 TH1F *h1;
00466 Int_t i;
00467 if (hcbits[5]) {
00468 Int_t lbins = lq[lcid-2];
00469 Double_t *xbins = new Double_t[ncx+1];
00470 for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1];
00471 h1 = new TH1F(idname,chtitl,ncx,xbins);
00472 delete [] xbins;
00473 } else {
00474 h1 = new TH1F(idname,chtitl,ncx,xmin,xmax);
00475 }
00476 if (hcbits[8]) h1->Sumw2();
00477 TGraph *gr = 0;
00478 if (hcbits[11]) {
00479 gr = new TGraph(ncx);
00480 h1->GetListOfFunctions()->Add(gr);
00481 }
00482
00483 Float_t x,yx;
00484 for (i=0;i<=ncx+1;i++) {
00485 x = h1->GetBinCenter(i);
00486 yx = hi(id,i);
00487 h1->Fill(x,yx);
00488 if (hcbits[8]) h1->SetBinError(i,hie(id,i));
00489 if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i));
00490 }
00491 Float_t yymin, yymax;
00492 if (hcbits[19]) {
00493 yymax = q[lcid+kMAX1];
00494 h1->SetMaximum(yymax);
00495 }
00496 if (hcbits[20]) {
00497 yymin = q[lcid+kMIN1];
00498 h1->SetMinimum(yymin);
00499 }
00500 h1->SetEntries(nentries);
00501 h1->Write();
00502 delete h1;
00503 }
00504
00505
00506 void convert_2d(Int_t id)
00507 {
00508
00509 if (id > 0) snprintf(idname,128,"h%d",id);
00510 else snprintf(idname,128,"h_%d",-id);
00511 hnoent(id,nentries);
00512 #ifndef WIN32
00513 hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
00514 #else
00515 hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
00516 #endif
00517 chtitl[4*nwt] = 0;
00518 TH2F *h2 = new TH2F(idname,chtitl,ncx,xmin,xmax,ncy,ymin,ymax);
00519 Float_t offsetx = 0.5*(xmax-xmin)/ncx;
00520 Float_t offsety = 0.5*(ymax-ymin)/ncy;
00521 Int_t lw = lq[lcont];
00522 if (lw) h2->Sumw2();
00523
00524 Float_t x,y;
00525 for (Int_t j=0;j<=ncy+1;j++) {
00526 for (Int_t i=0;i<=ncx+1;i++) {
00527 hijxy(id,i,j,x,y);
00528 h2->Fill(x+offsetx,y+offsety,hij(id,i,j));
00529 if (lw) {
00530 Double_t err2 = hije(id,i,j);
00531 h2->SetCellError(i,j,err2);
00532 }
00533 }
00534 }
00535 h2->SetEntries(nentries);
00536 h2->Write();
00537 delete h2;
00538 }
00539
00540
00541 void convert_profile(Int_t id)
00542 {
00543
00544
00545
00546
00547
00548
00549
00550
00551 if (id > 0) snprintf(idname,128,"h%d",id);
00552 else snprintf(idname,128,"h_%d",-id);
00553 hnoent(id,nentries);
00554 Int_t lw = lq[lcont];
00555 Int_t ln = lq[lw];
00556 #ifndef WIN32
00557 hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80);
00558 #else
00559 hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb);
00560 #endif
00561 chtitl[4*nwt] = 0;
00562 const char *option= " ";
00563 if (iq[lw] == 1) option = "S";
00564 if (iq[lw] == 2) option = "I";
00565 TProfile *p = new TProfile(idname,chtitl,ncx,xmin,xmax,ymin,ymax,option);
00566
00567 const Int_t kCON1 = 9;
00568 Int_t i;
00569 for (i=1;i<=ncx;i++) {
00570 Int_t n = Int_t(q[ln+i]);
00571 p->SetBinEntries(i,n);
00572 Float_t content = q[lcont+kCON1+i];
00573 Float_t error = TMath::Sqrt(q[lw+i]);
00574 p->SetBinContent(i,content);
00575 p->SetBinError(i,error);
00576 }
00577 p->SetEntries(nentries);
00578 p->Write();
00579 delete p;
00580 }
00581
00582
00583 void convert_rwn(Int_t id)
00584 {
00585
00586 const int kNchar=9;
00587 int nvar;
00588 int ier=0;
00589 int i,j;
00590 char *chtag_out;
00591 float *x;
00592 float rmin[1000], rmax[1000];
00593
00594 if (id > 0) snprintf(idname,128,"h%d",id);
00595 else snprintf(idname,128,"h_%d",-id);
00596 hnoent(id,nentries);
00597 printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries);
00598 nvar=0;
00599 #ifndef WIN32
00600 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
00601 #else
00602 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
00603 #endif
00604
00605 chtag_out = new char[nvar*kNchar+1];
00606 x = new float[nvar];
00607
00608 chtag_out[nvar*kNchar]=0;
00609 for (i=0;i<80;i++)chtitl[i]=0;
00610 #ifndef WIN32
00611 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar);
00612 #else
00613 hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]);
00614 #endif
00615 hgnpar(id,"?",1);
00616 char *name = chtag_out;
00617 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
00618 TTree *tree = new TTree(idname,chtitl);
00619 Int_t first,last;
00620 for(i=0; i<nvar;i++) {
00621 name[kNchar-1] = 0;
00622 first = last = 0;
00623
00624 for (j=kNchar-2;j>0;j--) {
00625 if(golower) name[j] = tolower(name[j]);
00626 if (name[j] == ' ' && last == 0) name[j] = 0;
00627 else last = j;
00628 }
00629 if (golower == 2) name[0] = tolower(name[0]);
00630
00631
00632 for (j=0;j<kNchar;j++) {
00633 if (name[j] != ' ') break;
00634 first = j+1;
00635 }
00636 tree->Branch(&name[first],&x[i],&name[first],bufsize);
00637 name += kNchar;
00638 }
00639 for(i=1;i<=nentries;i++) {
00640 hgnf(id,i,x[0],ier);
00641 tree->Fill();
00642 }
00643 tree->Write();
00644 delete tree;
00645 delete [] x;
00646 }
00647
00648
00649 void convert_cwn(Int_t id)
00650 {
00651
00652 const int kNchar=9;
00653 int nvar;
00654 int ier=0;
00655 int i,j;
00656 int nsub,itype,isize,ielem;
00657 char *chtag_out;
00658 float *x;
00659 float rmin[1000], rmax[1000];
00660
00661 if (id > 0) snprintf(idname,128,"h%d",id);
00662 else snprintf(idname,128,"h_%d",-id);
00663 hnoent(id,nentries);
00664 printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries);
00665 nvar=0;
00666 #ifndef WIN32
00667 hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0);
00668 #else
00669 hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]);
00670 #endif
00671
00672
00673 chtag_out = new char[nvar*kNchar+1];
00674 Int_t *charflag = new Int_t[nvar];
00675 Int_t *lenchar = new Int_t[nvar];
00676 Int_t *boolflag = new Int_t[nvar];
00677 Int_t *lenbool = new Int_t[nvar];
00678 UChar_t *boolarr = new UChar_t[10000];
00679 x = new float[nvar];
00680
00681 chtag_out[nvar*kNchar]=0;
00682 for (i=0;i<80;i++)chtitl[i]=0;
00683 #ifndef WIN32
00684 hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar);
00685 #else
00686 hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]);
00687 #endif
00688 Long_t add= (Long_t)&bigbuf[0];
00689 #ifndef WIN32
00690 hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0,1,6);
00691 #else
00692 hbnam(id,PASSCHAR(" "),add,PASSCHAR("$CLEAR"),0);
00693 #endif
00694
00695 Int_t bufpos = 0;
00696 Int_t isachar = 0;
00697 Int_t isabool = 0;
00698 char fullname[1024];
00699 char name[512];
00700 char block[512];
00701 char oldblock[512];
00702 Int_t nbits = 0;
00703 strlcpy(oldblock,"OLDBLOCK",512);
00704 Int_t oldischar = -1;
00705 for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; }
00706 TTree *tree = new TTree(idname,chtitl);
00707 for(i=0; i<nvar;i++) {
00708 memset(name,' ',sizeof(name));
00709 name[sizeof(name)-1] = 0;
00710 memset(block,' ',sizeof(block));
00711 block[sizeof(block)-1] = 0;
00712 memset(fullname,' ',sizeof(fullname));
00713 fullname[sizeof(fullname)-1]=0;
00714 #ifndef WIN32
00715 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,512,1024,512);
00716 #else
00717 hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
00718 #endif
00719
00720 for (j=510;j>0;j--) {
00721 if(golower) name[j] = tolower(name[j]);
00722 if (name[j] == ' ') name[j] = 0;
00723 }
00724 if (golower == 2) name[0] = tolower(name[0]);
00725
00726 for (j=1022;j>0;j--) {
00727 if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]);
00728
00729 if (golower == 2) fullname[j] = tolower(fullname[j]);
00730 if (fullname[j] == ' ') fullname[j] = 0;
00731 }
00732
00733 if (golower == 2) fullname[0] = tolower(fullname[0]);
00734 for (j=510;j>0;j--) {
00735 if (block[j] == ' ') block[j] = 0;
00736 else break;
00737 }
00738 if (itype == 1) {
00739 if( isize == 4 ) strlcat(fullname,"/F",1024);
00740 else if( isize == 8) strlcat(fullname,"/D",1024);
00741 }
00742
00743
00744
00745 Int_t nBytesUsed = 4;
00746
00747 if( itype == 2 ) {
00748 if( optcwn == 1 ) {
00749 if( nbits > 16 ) {
00750 strlcat(fullname,"/I",1024);
00751 } else {
00752 if( nbits > 8 ) {
00753 strlcat(fullname,"/S",1024);
00754 nBytesUsed = 2;
00755 } else {
00756 strlcat(fullname,"/B",1024);
00757 nBytesUsed = 1;
00758 }
00759 }
00760 } else {
00761 strlcat(fullname,"/I",1024);
00762 }
00763 }
00764
00765
00766 if ( itype == 3 ) {
00767 if( optcwn == 1 ) {
00768 if( nbits > 16) {
00769 strlcat(fullname,"/i",1024);
00770 } else {
00771 if( nbits > 8 ) {
00772 strlcat(fullname,"/s",1024);
00773 nBytesUsed = 2;
00774 } else {
00775 strlcat(fullname,"/b",1024);
00776 nBytesUsed = 1;
00777 }
00778 }
00779 } else {
00780 strlcat(fullname,"/i",1024);
00781 }
00782 }
00783
00784
00785
00786
00787
00788 if (itype == 4) strlcat(fullname,"/b",1024);
00789 if (itype == 5) strlcat(fullname,"/C",1024);
00790 printf("Creating branch:%s, block:%s, fullname:%s, nsub=%d, itype=%d, isize=%d, ielem=%d\n",name,block,fullname,nsub,itype,isize,ielem);
00791 Int_t ischar;
00792 if (itype == 5) ischar = 1;
00793 else ischar = 0;
00794 if (ischar != oldischar || strcmp(oldblock,block) != 0) {
00795 strlcpy(oldblock,block,512);
00796 oldischar = ischar;
00797 Int_t lblock = strlen(block);
00798 add= (Long_t)&bigbuf[bufpos];
00799 #ifndef WIN32
00800 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4);
00801 #else
00802 hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar);
00803 #endif
00804
00805 }
00806 TBranch *branch = tree->Branch(name,(void*)&bigbuf[bufpos],fullname,bufsize);
00807 boolflag[i] = -10;
00808 charflag[i] = 0;
00809 if (itype == 4) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;}
00810 bufpos += isize*ielem;
00811 if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;}
00812 TObjArray *ll= branch->GetListOfLeaves();
00813 TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0);
00814 if (!leaf) continue;
00815 TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount();
00816 if (leafcount) {
00817 if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem);
00818 }
00819 }
00820 Int_t cf,l;
00821 for(i=1;i<=nentries;i++) {
00822 hgnt(id,i,ier);
00823 if (isabool) {
00824 for (j=0;j<nvar;j++) {
00825 cf = boolflag[j];
00826 if (cf >-1) {
00827 for (l=0;l<lenbool[j];l++) {
00828 #ifdef R__BYTESWAP
00829 boolarr[l] = (UChar_t)bigbuf[cf+4*l];
00830 #else
00831 boolarr[l] = (UChar_t)bigbuf[cf+4*l+3];
00832 #endif
00833 }
00834 memcpy(&bigbuf[cf],boolarr,lenbool[j]);
00835 }
00836 }
00837 }
00838 if (isachar) {
00839 for (j=0;j<nvar;j++) {
00840 cf = charflag[j];
00841 if (cf) {
00842 bigbuf[cf] = '\0';
00843 if (bigbuf[cf-1] != ' ') continue;
00844 bigbuf[cf-1] = '\0';
00845 if (bigbuf[cf-2] != ' ') continue;
00846 bigbuf[cf-2] = '\0';
00847 }
00848 }
00849 }
00850
00851
00852 if( optcwn == 1 ) {
00853 bufpos = 0;
00854 for(int k=0; k<nvar;k++) {
00855 #ifndef WIN32
00856 hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32);
00857 #else
00858 hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem);
00859 #endif
00860
00861 Int_t nBytesUsed = 4;
00862
00863 if ( itype == 2 || itype == 3) {
00864 if( nbits > 16) {
00865
00866 } else {
00867 if( nbits > 8 ) nBytesUsed = 2;
00868 else nBytesUsed = 1;
00869 }
00870 }
00871
00872 if(nBytesUsed == 1) {
00873 for(Int_t index = 0; index < ielem; index++) {
00874
00875 bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize];
00876 }
00877 } else {
00878 if(nBytesUsed == 2) {
00879 for(Int_t index = 0; index < ielem; index++) {
00880
00881 bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize];
00882 bigbuf[bufpos + index*nBytesUsed+1 ] = bigbuf[bufpos + index * isize+1];
00883 }
00884 }
00885 }
00886 bufpos += isize*ielem;
00887
00888 }
00889 }
00890
00891 tree->Fill();
00892 }
00893 tree->Print();
00894 tree->Write();
00895 delete tree;
00896 delete [] x;
00897 delete [] charflag;
00898 delete [] lenchar;
00899 delete [] boolflag;
00900 delete [] lenbool;
00901 delete [] boolarr;
00902 delete [] chtag_out;
00903 }