234 |
extern void convert_profile(Int_t id); |
extern void convert_profile(Int_t id); |
235 |
extern void convert_cwn(Int_t id); |
extern void convert_cwn(Int_t id); |
236 |
extern void convert_rwn(Int_t id); |
extern void convert_rwn(Int_t id); |
237 |
extern void convert_psam(const char*); |
extern void convert_psam(const char*, TTree *, pEvent *); |
238 |
|
|
239 |
Int_t golower = 1; |
Int_t golower = 1; |
240 |
Int_t bufsize = 64000; |
Int_t bufsize = 64000; |
241 |
Int_t optcwn = 1; |
Int_t optcwn = 1; |
242 |
|
|
243 |
|
|
|
// struct gdata{ |
|
|
// int irun; |
|
|
// int iev; |
|
|
// int ipa; |
|
|
// float x0; |
|
|
// float y0; |
|
|
// float z0; |
|
|
// float theta; |
|
|
// float phi; |
|
|
// float p0; |
|
|
// }; |
|
|
|
|
|
// union gcdata{ |
|
|
// gdata data; |
|
|
// char c[36]; |
|
|
// }; |
|
|
|
|
|
|
|
|
// struct general{ |
|
|
|
|
|
// gcdata dat; |
|
|
|
|
|
|
|
|
// void SetIt(char * buf){ |
|
|
// for(int i=0;i<36;++i) dat.c[i]=*(buf+i); |
|
|
// // irun=*(int *)buf++; |
|
|
// // iev =(int) *buf++; |
|
|
// // ipa =(int) *buf++; |
|
|
// // x0 =(float) *buf++; |
|
|
// // y0 =(float) *buf++; |
|
|
// // z0 =(float) *buf++; |
|
|
// // theta =(float) *buf++; |
|
|
// // phi =(float) *buf++; |
|
|
// // p0 =(float) *buf++; |
|
|
|
|
|
// } |
|
|
|
|
|
// void Print(){ |
|
|
// std::cout << dat.data.irun << ", " << |
|
|
// dat.data.iev << ", " << |
|
|
// dat.data.ipa << ", " << |
|
|
// dat.data.x0 << ", " << |
|
|
// dat.data.y0 << ", " << |
|
|
// dat.data.z0 << ", " << |
|
|
// dat.data.theta << ", " << |
|
|
// dat.data.phi << ", " << |
|
|
// dat.data.p0 << std::endl; |
|
|
|
|
|
// } |
|
|
// }; |
|
|
|
|
|
|
|
|
// struct cascwn { |
|
|
// int nthcas; |
|
|
// int iparcas[50]; |
|
|
// int icas[50]; |
|
|
// float x0[50]; |
|
|
// float y0[50]; |
|
|
// float z0[50]; |
|
|
// float x1[50]; |
|
|
// float y1[50]; |
|
|
// float z1[50]; |
|
|
// float erel[50]; |
|
|
// float time[50]; |
|
|
// float path[50]; |
|
|
// float p0[50]; |
|
|
|
|
|
// }; |
|
|
|
|
|
// struct structcas{ |
|
|
|
|
|
// cascwn *cas; //= new cascwn; |
|
|
|
|
|
// void SetIt(char * buf){ |
|
|
// cas = (cascwn *) buf; |
|
|
// } |
|
|
|
|
|
// void Print(){ |
|
|
// std::cout << cas->nthcas << ", " << |
|
|
// // iparcas[0] << ", " << |
|
|
// // x0[0] << ", " << |
|
|
// // y0[0] << ", " << |
|
|
// // z0[0] << ", " << |
|
|
// // erel[0] << ", " << |
|
|
// // p0[0] << |
|
|
// std::endl; |
|
|
|
|
|
// } |
|
|
|
|
|
// gpcasdat GetCas(int &i){ |
|
|
// gpcasdat temp; |
|
|
// temp.pathcas=(double *)&cas->path[i]; |
|
|
// temp.icas=&cas->icas[i]; |
|
|
// temp.dat = new gpdat(); |
|
|
// temp.dat->ipart=&cas->iparcas[i]; |
|
|
// temp.dat->xyzin = new coord(); |
|
|
// temp.dat->xyzout = new coord(); |
|
|
// temp.dat->xyzin->x=(double )cas->x0[i]; |
|
|
// temp.dat->xyzin->y=(double )cas->y0[i]; |
|
|
// temp.dat->xyzin->z=(double )cas->z0[i]; |
|
|
// temp.dat->xyzout->x=(double )cas->x1[i]; |
|
|
// temp.dat->xyzout->y=(double )cas->y1[i]; |
|
|
// temp.dat->xyzout->z=(double )cas->z1[i]; |
|
|
// temp.dat->erel=(double *)&cas->erel[i]; |
|
|
// temp.dat->time=(double *)&cas->time[i]; |
|
|
// temp.dat->p=(double *)&cas->p0[i]; |
|
|
// return temp; |
|
|
// } |
|
|
// }; |
|
|
|
|
244 |
|
|
245 |
int main(int argc, char **argv) |
int main(int argc, char **argv) |
246 |
{ |
{ |
310 |
} |
} |
311 |
|
|
312 |
char root_file_title[2000]; |
char root_file_title[2000]; |
313 |
sprintf(root_file_title,"HBOOK file: %s converted to ROOT",file_in); |
sprintf(root_file_title,"HBOOK file: %s converted to ROOT",file_in); |
314 |
TFile* hfile= TFile::Open(file_out,"RECREATE",root_file_title,compress); |
TFile* hfile=new TFile(file_out,"RECREATE",root_file_title,compress); |
315 |
|
|
316 |
|
// Create global GPAMELA event |
317 |
|
|
318 |
|
pEvent *myevent=new pEvent(); |
319 |
|
// Create ROOT tree and assign a Branch to the event |
320 |
|
TTree* gptree=new TTree("gptree","GPAMELA tree"); |
321 |
|
gptree->Branch("pEvent_br","pEvent",&myevent,16000,0); |
322 |
|
|
323 |
if (!hfile) { |
if (!hfile) { |
324 |
printf("Error: can't open output file: %s \n",file_out); |
printf("Error: can't open output file: %s \n",file_out); |
325 |
return 1; |
return 1; |
326 |
} |
} |
327 |
|
|
328 |
|
|
329 |
convert_psam("//example"); |
convert_psam("//example",gptree,myevent); |
330 |
// convert_directory("//example"); |
// convert_directory("//example"); |
331 |
|
|
332 |
hfile->Write(); |
hfile->Write(); |
336 |
return(0); |
return(0); |
337 |
} |
} |
338 |
|
|
339 |
void convert_psam(const char *dir){ |
void convert_psam(const char *dir, TTree *gptree, pEvent* myevent){ |
340 |
int nsub,itype,isize,ielem,ierr; |
int nsub,itype,isize,ielem,ierr; |
341 |
const int kNchar=9; |
const int kNchar=9; |
342 |
printf(" Converting directory %s\n",dir); |
printf(" Converting directory %s\n",dir); |
362 |
char *t=bigbuf; |
char *t=bigbuf; |
363 |
|
|
364 |
|
|
|
// gpevent myevent; |
|
|
pEvent myevent; |
|
365 |
|
|
366 |
std::istringstream *test; |
std::istringstream *test; |
367 |
|
|
405 |
std::cout << p->name << ": "<< p->nbyte << '\n'; |
std::cout << p->name << ": "<< p->nbyte << '\n'; |
406 |
if(p->name!="GENERAL" && p->name!="CALI" |
if(p->name!="GENERAL" && p->name!="CALI" |
407 |
&& p->name!="TRD" && p->name!= "SPE") |
&& p->name!="TRD" && p->name!= "SPE") |
408 |
myevent.AddDetector(p->name); |
myevent->AddDetector(p->name); |
409 |
} |
} |
410 |
myevent.Print(); |
myevent->Print(); |
|
// general mygen; |
|
|
// structcas mycas; |
|
|
// t=(char *) &mygen; |
|
|
// hbnam(id,PASSCHAR(" "),(int) *t,PASSCHAR("$CLEAR"),0,1,6); |
|
|
// t=(char *) &mycas; |
|
|
// hbnam(id,PASSCHAR(" "),(int) *t,PASSCHAR("$CLEAR"),0,1,6); |
|
|
// Long_t add= (Long_t)&bigbuf[0]; |
|
|
|
|
|
// Generate the buffer and pass it to the hbook routine |
|
411 |
t=m.CreatePbuf(); |
t=m.CreatePbuf(); |
412 |
hbnam(id,PASSCHAR(" "),(int) *t,PASSCHAR("$CLEAR"),0,1,6); |
hbnam(id,PASSCHAR(" "),(int) *t,PASSCHAR("$CLEAR"),0,1,6); |
413 |
|
|
425 |
strlen( p->name.c_str() ),4); |
strlen( p->name.c_str() ),4); |
426 |
} |
} |
427 |
} |
} |
|
// Long_t add= (Long_t)&mygen; |
|
|
// Int_t lblock = strlen("GENERAL"); |
|
|
|
|
|
// hbnam(id,PASSCHAR("GENERAL"),add,PASSCHAR("$SET"),ischar,lblock,4); |
|
|
// add= (Long_t)&mycas; |
|
|
// lblock = strlen("CAS"); |
|
|
// hbnam(id,PASSCHAR("CAS"),add,PASSCHAR("$SET"),ischar,lblock,4); |
|
|
|
|
|
// hgntb(id,PASSCHAR("GENERAL"),0,ierr); |
|
|
// hbnam(id,PASSCHAR("GENERAL"),(Long_t) m.BuffAddress(), |
|
|
// PASSCHAR("$SET"),ischar,lblock,4); |
|
|
// lblock = strlen("CAS"); |
|
|
// hbnam(id,PASSCHAR("CAS"),(Long_t) m.BuffAddress(), |
|
|
// PASSCHAR("$SET"),ischar,lblock,4); |
|
|
|
|
|
// hbnam(id,PASSCHAR("GENERAL"),(Long_t) m.BlockAddress("GENERAL"), |
|
|
// PASSCHAR("$SET"),ischar,lblock,4); |
|
|
// lblock = strlen("CAS"); |
|
|
// hbnam(id,PASSCHAR("CAS"),(Long_t) m.BlockAddress("CAS"), |
|
|
// PASSCHAR("$SET"),ischar,lblock,4); |
|
|
|
|
|
// gpcasdat ttt; |
|
|
// gpcas *tc; |
|
428 |
char * junk; |
char * junk; |
429 |
for(int i=0;i<nentries;++i){ |
for(int i=0;i<nentries;++i){ |
430 |
hgnt(id,i+1,ierr); |
hgnt(id,i+1,ierr); |
431 |
junk=m.BuffAddress(); |
junk=m.BuffAddress(); |
432 |
junk=m.BuffReorder(); |
junk=m.BuffReorder(); |
|
// t=(char *) &mygen; |
|
|
// for(int i=0; i<36; ++i) *t++=*junk++; |
|
433 |
std::cout << junk << std::dec << |
std::cout << junk << std::dec << |
434 |
", " << ierr << std::endl; |
", " << ierr << std::endl; |
435 |
for(pBlockMap::const_iterator p=(m.GetBlockMap())->begin(); |
for(pBlockMap::const_iterator p=(m.GetBlockMap())->begin(); |
444 |
int nb= (m.BlockVar(p->name.c_str())-1)*4; |
int nb= (m.BlockVar(p->name.c_str())-1)*4; |
445 |
std::cout << " nhit : "<< nhit << endl; |
std::cout << " nhit : "<< nhit << endl; |
446 |
for (int i=0; i<nhit;++i) { |
for (int i=0; i<nhit;++i) { |
447 |
myevent.AddHit(p->name.c_str(),cc); |
myevent->AddHit(p->name.c_str(),cc); |
448 |
cc+=nb; |
cc+=nb; |
449 |
} |
} |
|
// hbnam(id,PASSCHAR(p->name.c_str()), |
|
|
// (Long_t) m.BlockAddress(p->name.c_str()), |
|
|
// PASSCHAR("$SET"),ischar, |
|
|
// strlen( p->name.c_str() ),4); |
|
450 |
} |
} |
451 |
|
gptree->Fill(); |
452 |
} |
} |
|
// mygen.SetIt(m.BlockAddress("GENERAL")); |
|
|
// mycas.SetIt(m.BlockAddress("CAS")); |
|
|
// mygen.Print(); |
|
|
// mycas.Print(); |
|
|
|
|
|
// if(mycas.nthcas) { |
|
|
// for(int j=0;j<mycas.nthcas;++j) { |
|
|
// ttt=mycas.GetCas(j); |
|
|
// myevent.AddCasHit(&ttt); |
|
|
// // tc=new gpcas(&ttt); |
|
|
// // tc->Print(); |
|
|
// // delete tc; |
|
|
// } |
|
|
// } |
|
|
} |
|
|
myevent.Print(); |
|
|
} |
|
|
//____________________________________________________________________________ |
|
|
void convert_directory(const char *dir) |
|
|
{ |
|
|
|
|
|
printf(" Converting directory %s\n",dir); |
|
|
Int_t id; |
|
|
// Int_t nastycase=0; |
|
|
// Int_t nastyprint=0; |
|
|
// Int_t idold = 0; |
|
|
for (Int_t key=1;key<1000000;key++) { |
|
|
int z0 = 0; |
|
|
rzink(key,z0,"S",1); |
|
|
if (quest[0]) break; |
|
|
if (quest[13] & 8) { |
|
|
continue; |
|
|
// if (!nastyprint) { |
|
|
// printf("Found nasty Hbook case!! You had an Hbook error message\n"); |
|
|
// printf(" when creating the file (too many records)\n"); |
|
|
// printf(" Hbook file should have been created with a bigger LRECL\n"); |
|
|
// printf(" ROOT will try to recover\n"); |
|
|
// nastyprint = 1; |
|
|
// } |
|
|
// nastycase = 1; |
|
|
} |
|
|
id = quest[20]; |
|
|
// if (id == idold && nastycase) continue; |
|
|
// nastycase = 0; |
|
|
// idold = id; |
|
|
int i999 = 999; |
|
|
hrin(id,i999,0); |
|
|
if (quest[0]) { |
|
|
printf("Error cannot read ID = %d\n",id); |
|
|
break; |
|
|
} |
|
|
hdcofl(); |
|
|
lcid = hcbook[10]; |
|
|
lcont = lq[lcid-1]; |
|
|
if (hcbits[3]) { |
|
|
if (iq[lcid-2] == 2) convert_rwn(id); |
|
|
else convert_cwn(id); |
|
|
hdelet(id); |
|
|
continue; |
|
|
} |
|
|
if (hcbits[0] && hcbits[7]) { |
|
|
convert_profile(id); |
|
|
hdelet(id); |
|
|
continue; |
|
|
} |
|
|
if (hcbits[0]) { |
|
|
convert_1d(id); |
|
|
hdelet(id); |
|
|
continue; |
|
|
} |
|
|
if (hcbits[1] || hcbits[2]) { |
|
|
convert_2d(id); |
|
|
hdelet(id); |
|
|
} |
|
|
} |
|
|
|
|
|
// converting subdirectories of this directory |
|
|
const Int_t kKLS = 26; |
|
|
const Int_t kKNSD = 23; |
|
|
lcdir = rzcl[2]; |
|
|
Int_t ls = iq[lcdir+kKLS]; |
|
|
Int_t ndir = iq[lcdir+kKNSD]; |
|
|
Int_t nch=16; |
|
|
Int_t ihdir[4]; |
|
|
Int_t ncw = 4; |
|
|
TDirectory *cursav = gDirectory; |
|
|
Int_t i; |
|
|
char chdir[17]; |
|
|
char hbookdir[17]; |
|
|
for (Int_t k=0;k<ndir;k++) { |
|
|
lcdir = rzcl[2]; |
|
|
zitoh(iq[lcdir+ls+7*k],ihdir[0],ncw); |
|
|
for (i=0;i<17;i++) chdir[i] = 0; |
|
|
#ifndef WIN32 |
|
|
uhtoc(ihdir[0],ncw,chdir,nch ,16); |
|
|
#else |
|
|
uhtoc(ihdir[0],ncw,chdir,16,nch); |
|
|
#endif |
|
|
strcpy(hbookdir,chdir); |
|
|
for (i=16;i>0;i--) { |
|
|
if (chdir[i] == 0) continue; |
|
|
if (chdir[i] != ' ') break; |
|
|
chdir[i] = 0; |
|
|
} |
|
|
#ifndef WIN32 |
|
|
hcdir(PASSCHAR(hbookdir),PASSCHAR(" "),16,1); |
|
|
#else |
|
|
hcdir(PASSCHAR(hbookdir),PASSCHAR(" ")); |
|
|
#endif |
|
|
TDirectory *newdir = new TDirectory(chdir,chdir); |
|
|
newdir->cd(); |
|
|
convert_directory(chdir); |
|
|
#ifndef WIN32 |
|
|
hcdir(PASSCHAR("\\"),PASSCHAR(" "),1,1); |
|
|
#else |
|
|
hcdir(PASSCHAR("\\"),PASSCHAR(" ")); |
|
|
#endif |
|
|
newdir->Write(); |
|
|
cursav->cd(); |
|
|
} |
|
|
} |
|
|
|
|
|
//____________________________________________________________________________ |
|
|
void convert_1d(Int_t id) |
|
|
{ |
|
|
if (id > 0) sprintf(idname,"h%d",id); |
|
|
else sprintf(idname,"h_%d",-id); |
|
|
hnoent(id,nentries); |
|
|
#ifndef WIN32 |
|
|
hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80); |
|
|
#else |
|
|
hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb); |
|
|
#endif |
|
|
chtitl[4*nwt] = 0; |
|
|
TH1F *h1; |
|
|
Int_t i; |
|
|
if (hcbits[5]) { |
|
|
Int_t lbins = lq[lcid-2]; |
|
|
Double_t *xbins = new Double_t[ncx+1]; |
|
|
for (i=0;i<=ncx;i++) xbins[i] = q[lbins+i+1]; |
|
|
h1 = new TH1F(idname,chtitl,ncx,xbins); |
|
|
delete [] xbins; |
|
|
} else { |
|
|
h1 = new TH1F(idname,chtitl,ncx,xmin,xmax); |
|
|
} |
|
|
if (hcbits[8]) h1->Sumw2(); |
|
|
TGraph *gr = 0; |
|
|
if (hcbits[11]) { |
|
|
gr = new TGraph(ncx); |
|
|
h1->GetListOfFunctions()->Add(gr); |
|
|
} |
|
|
|
|
|
Float_t x; |
|
|
for (i=0;i<=ncx+1;i++) { |
|
|
x = h1->GetBinCenter(i); |
|
|
h1->Fill(x,hi(id,i)); |
|
|
if (hcbits[8]) h1->SetBinError(i,hie(id,i)); |
|
|
if (gr && i>0 && i<=ncx) gr->SetPoint(i,x,hif(id,i)); |
|
|
} |
|
|
Float_t ymin, ymax; |
|
|
if (hcbits[19]) { |
|
|
ymax = q[lcid+kMAX1]; |
|
|
h1->SetMaximum(ymax); |
|
|
} |
|
|
if (hcbits[20]) { |
|
|
ymin = q[lcid+kMIN1]; |
|
|
h1->SetMinimum(ymin); |
|
|
} |
|
|
h1->SetEntries(nentries); |
|
|
h1->Write(); |
|
|
delete h1; |
|
|
} |
|
|
|
|
|
//____________________________________________________________________________ |
|
|
void convert_2d(Int_t id) |
|
|
{ |
|
|
if (id > 0) sprintf(idname,"h%d",id); |
|
|
else sprintf(idname,"h_%d",-id); |
|
|
hnoent(id,nentries); |
|
|
#ifndef WIN32 |
|
|
hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80); |
|
|
#else |
|
|
hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb); |
|
|
#endif |
|
|
chtitl[4*nwt] = 0; |
|
|
TH2F *h2 = new TH2F(idname,chtitl,ncx,xmin,xmax,ncy,ymin,ymax); |
|
|
Float_t offsetx = 0.5*(xmax-xmin)/ncx; |
|
|
Float_t offsety = 0.5*(ymax-ymin)/ncy; |
|
|
Int_t lw = lq[lcont]; |
|
|
if (lw) h2->Sumw2(); |
|
|
|
|
|
Float_t x,y; |
|
|
for (Int_t j=0;j<=ncy+1;j++) { |
|
|
for (Int_t i=0;i<=ncx+1;i++) { |
|
|
hijxy(id,i,j,x,y); |
|
|
h2->Fill(x+offsetx,y+offsety,hij(id,i,j)); |
|
|
if (lw) { |
|
|
Double_t err2 = hije(id,i,j); |
|
|
h2->SetCellError(i,j,err2); |
|
|
} |
|
|
} |
|
|
} |
|
|
h2->SetEntries(nentries); |
|
|
h2->Write(); |
|
|
delete h2; |
|
|
} |
|
|
|
|
|
//____________________________________________________________________________ |
|
|
void convert_profile(Int_t id) |
|
|
{ |
|
|
// the following structure is used in Hbook |
|
|
// lcid points to the profile in array iq |
|
|
// lcont = lq(lcid-1) |
|
|
// lw = lq(lcont) |
|
|
// ln = lq(lw) |
|
|
// if option S jbyt(iq(lw),1,2) = 1 |
|
|
// if option I jbyt(iq(lw),1,2) = 2 |
|
|
|
|
|
if (id > 0) sprintf(idname,"h%d",id); |
|
|
else sprintf(idname,"h_%d",-id); |
|
|
hnoent(id,nentries); |
|
|
Int_t lw = lq[lcont]; |
|
|
Int_t ln = lq[lw]; |
|
|
#ifndef WIN32 |
|
|
hgive(id,chtitl,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb,80); |
|
|
#else |
|
|
hgive(id,chtitl,80,ncx,xmin,xmax,ncy,ymin,ymax,nwt,idb); |
|
|
#endif |
|
|
Float_t offsetx = 0.5*(xmax-xmin)/ncx; |
|
|
chtitl[4*nwt] = 0; |
|
|
const char *option= " "; |
|
|
if (iq[lw] == 1) option = "S"; |
|
|
if (iq[lw] == 2) option = "I"; |
|
|
TProfile *p = new TProfile(idname,chtitl,ncx,xmin,xmax,ymin,ymax,option); |
|
|
|
|
|
const Int_t kCON1 = 9; |
|
|
Int_t i; |
|
|
Float_t x; |
|
|
Float_t y = 0.5*(ymin+ymax); |
|
|
for (i=1;i<=ncx;i++) { |
|
|
Int_t n = Int_t(q[ln+i]); |
|
|
hix(id,i,x); |
|
|
for (Int_t j=0;j<n;j++) { |
|
|
p->Fill(x+offsetx,y); |
|
|
} |
|
|
//p->SetBinEntries(i,n); //this one should be much faster (to be tested) |
|
|
Float_t content = q[lcont+kCON1+i]; |
|
|
Float_t error = TMath::Sqrt(q[lw+i]); |
|
|
p->SetBinContent(i,content); |
|
|
p->SetBinError(i,error); |
|
|
} |
|
|
p->SetEntries(nentries); |
|
|
p->Write(); |
|
|
delete p; |
|
|
} |
|
|
|
|
|
//____________________________________________________________________________ |
|
|
void convert_rwn(Int_t id) |
|
|
{ |
|
|
const int kNchar=9; |
|
|
int nvar; |
|
|
int ier=0; |
|
|
int i,j; |
|
|
char *chtag_out; |
|
|
float *x; |
|
|
float rmin[1000], rmax[1000]; |
|
|
|
|
|
if (id > 0) sprintf(idname,"h%d",id); |
|
|
else sprintf(idname,"h_%d",-id); |
|
|
hnoent(id,nentries); |
|
|
printf(" Converting RWN with ID= %d, nentries = %d\n",id,nentries); |
|
|
nvar=0; |
|
|
#ifndef WIN32 |
|
|
hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0); |
|
|
#else |
|
|
hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]); |
|
|
#endif |
|
|
|
|
|
chtag_out = new char[nvar*kNchar+1]; |
|
|
x = new float[nvar]; |
|
|
|
|
|
chtag_out[nvar*kNchar]=0; |
|
|
for (i=0;i<80;i++)chtitl[i]=0; |
|
|
#ifndef WIN32 |
|
|
hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar); |
|
|
#else |
|
|
hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]); |
|
|
#endif |
|
|
hgnpar(id,"?",1); |
|
|
char *name = chtag_out; |
|
|
for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; } |
|
|
TTree *tree = new TTree(idname,chtitl); |
|
|
Int_t first,last; |
|
|
for(i=0; i<nvar;i++) { |
|
|
name[kNchar-1] = 0; |
|
|
first = last = 0; |
|
|
// suppress traling blanks |
|
|
for (j=kNchar-2;j>0;j--) { |
|
|
if(golower) name[j] = tolower(name[j]); |
|
|
if (name[j] == ' ' && last == 0) name[j] = 0; |
|
|
else last = j; |
|
|
} |
|
|
if (golower == 2) name[0] = tolower(name[0]); |
|
|
|
|
|
// suppress heading blanks |
|
|
for (j=0;j<kNchar;j++) { |
|
|
if (name[j] != ' ') break; |
|
|
first = j+1; |
|
|
} |
|
|
tree->Branch(&name[first],&x[i],&name[first],bufsize); |
|
|
name += kNchar; |
|
453 |
} |
} |
454 |
for(i=1;i<=nentries;i++) { |
myevent->Print(); |
|
hgnf(id,i,x[0],ier); |
|
|
tree->Fill(); |
|
|
} |
|
|
tree->Write(); |
|
|
delete tree; |
|
|
delete [] x; |
|
455 |
} |
} |
|
|
|
456 |
//____________________________________________________________________________ |
//____________________________________________________________________________ |
|
void convert_cwn(Int_t id) |
|
|
{ |
|
|
const int kNchar=9; |
|
|
int nvar; |
|
|
int ier=0; |
|
|
int i,j; |
|
|
int nsub,itype,isize,ielem; |
|
|
char *chtag_out; |
|
|
float *x; |
|
|
float rmin[1000], rmax[1000]; |
|
|
|
|
|
if (id > 0) sprintf(idname,"h%d",id); |
|
|
else sprintf(idname,"h_%d",-id); |
|
|
hnoent(id,nentries); |
|
|
printf(" Converting CWN with ID= %d, nentries = %d\n",id,nentries); |
|
|
nvar=0; |
|
|
#ifndef WIN32 |
|
|
hgiven(id,chtitl,nvar,PASSCHAR(""),rmin[0],rmax[0],80,0); |
|
|
#else |
|
|
hgiven(id,chtitl,80,nvar,PASSCHAR(""),rmin[0],rmax[0]); |
|
|
#endif |
|
|
|
|
|
|
|
|
chtag_out = new char[nvar*kNchar+1]; |
|
|
Int_t *charflag = new Int_t[nvar]; |
|
|
Int_t *lenchar = new Int_t[nvar]; |
|
|
Int_t *boolflag = new Int_t[nvar]; |
|
|
Int_t *lenbool = new Int_t[nvar]; |
|
|
UChar_t *boolarr = new UChar_t[10000]; |
|
|
x = new float[nvar]; |
|
|
char *bigbuf = new char[2500000]; |
|
|
|
|
|
chtag_out[nvar*kNchar]=0; |
|
|
for (i=0;i<80;i++)chtitl[i]=0; |
|
|
#ifndef WIN32 |
|
|
hgiven(id,chtitl,nvar,chtag_out,rmin[0],rmax[0],80,kNchar); |
|
|
#else |
|
|
hgiven(id,chtitl,80,nvar,chtag_out,kNchar,rmin[0],rmax[0]); |
|
|
#endif |
|
|
#ifndef WIN32 |
|
|
hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0,1,6); |
|
|
#else |
|
|
hbnam(id,PASSCHAR(" "),bigbuf[0],PASSCHAR("$CLEAR"),0); |
|
|
#endif |
|
|
|
|
|
Int_t bufpos = 0; |
|
|
Int_t isachar = 0; |
|
|
Int_t isabool = 0; |
|
|
char fullname[1024]; |
|
|
char name[512]; |
|
|
char block[512]; |
|
|
char oldblock[512]; |
|
|
Int_t nbits = 0; |
|
|
strcpy(oldblock,"OLDBLOCK"); |
|
|
Int_t oldischar = -1; |
|
|
for (i=80;i>0;i--) {if (chtitl[i] == ' ') chtitl[i] = 0; } |
|
|
TTree *tree = new TTree(idname,chtitl); |
|
|
for(i=0; i<nvar;i++) { |
|
|
memset(name,' ',sizeof(name)); |
|
|
name[sizeof(name)-1] = 0; |
|
|
memset(block,' ',sizeof(block)); |
|
|
block[sizeof(block)-1] = 0; |
|
|
memset(fullname,' ',sizeof(fullname)); |
|
|
fullname[sizeof(fullname)-1]=0; |
|
|
#ifndef WIN32 |
|
|
hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,512,1024,512); |
|
|
#else |
|
|
hntvar2(id,i+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem); |
|
|
#endif |
|
|
|
|
|
for (j=510;j>0;j--) { |
|
|
if(golower) name[j] = tolower(name[j]); |
|
|
if (name[j] == ' ') name[j] = 0; |
|
|
} |
|
|
if (golower == 2) name[0] = tolower(name[0]); |
|
|
|
|
|
for (j=1022;j>0;j--) { |
|
|
if(golower && fullname[j-1] != '[') fullname[j] = tolower(fullname[j]); |
|
|
// convert also character after [, if golower == 2 |
|
|
if (golower == 2) fullname[j] = tolower(fullname[j]); |
|
|
if (fullname[j] == ' ') fullname[j] = 0; |
|
|
} |
|
|
// convert also first character, if golower == 2 |
|
|
if (golower == 2) fullname[0] = tolower(fullname[0]); |
|
|
for (j=510;j>0;j--) { |
|
|
if (block[j] == ' ') block[j] = 0; |
|
|
else break; |
|
|
} |
|
|
if (itype == 1) { |
|
|
if( isize == 4 ) strcat(fullname,"/F"); |
|
|
else if( isize == 8) strcat(fullname,"/D"); |
|
|
} |
|
|
|
|
|
|
|
|
// add support for 1-byte (Char_t) and 2-byte (Short_t) integers |
|
|
Int_t nBytesUsed = 4; // default for integers |
|
|
|
|
|
if( itype == 2 ) |
|
|
{ |
|
|
if( optcwn == 1 ) |
|
|
{ |
|
|
if( nbits > 16 ) |
|
|
{ |
|
|
strcat(fullname,"/I"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
if( nbits > 8 ) |
|
|
{ |
|
|
strcat(fullname,"/S"); |
|
|
nBytesUsed = 2; |
|
|
} |
|
|
else |
|
|
{ |
|
|
strcat(fullname,"/B"); |
|
|
nBytesUsed = 1; |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
strcat(fullname,"/I"); |
|
|
} |
|
|
} |
|
|
|
|
|
// add support for 1-byte (UChar_t) and 2-byte (UShort_t) integers |
|
|
if ( itype == 3 ) |
|
|
{ |
|
|
if( optcwn == 1 ) |
|
|
{ |
|
|
if( nbits > 16) |
|
|
{ |
|
|
strcat(fullname,"/i"); |
|
|
} |
|
|
else |
|
|
{ |
|
|
if( nbits > 8 ) |
|
|
{ |
|
|
strcat(fullname,"/s"); |
|
|
nBytesUsed = 2; |
|
|
} |
|
|
else |
|
|
{ |
|
|
strcat(fullname,"/b"); |
|
|
nBytesUsed = 1; |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
strcat(fullname,"/i"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (itype == 4) strcat(fullname,"/i"); |
|
|
if (itype == 4) strcat(fullname,"/b"); |
|
|
if (itype == 5) strcat(fullname,"/C"); |
|
|
printf("Creating branch:%s, block:%s, fullname:%s, nsub=%d, itype=%d, isize=%d, ielem=%d\n",name,block,fullname,nsub,itype,isize,ielem); |
|
|
Int_t ischar; |
|
|
if (itype == 5) ischar = 1; |
|
|
else ischar = 0; |
|
|
if (ischar != oldischar || strcmp(oldblock,block) != 0) { |
|
|
strcpy(oldblock,block); |
|
|
oldischar = ischar; |
|
|
Int_t lblock = strlen(block); |
|
|
Long_t add= (Long_t)&bigbuf[bufpos]; |
|
|
#ifndef WIN32 |
|
|
hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar,lblock,4); |
|
|
#else |
|
|
hbnam(id,PASSCHAR(block),add,PASSCHAR("$SET"),ischar); |
|
|
#endif |
|
|
|
|
|
} |
|
|
TBranch *branch = tree->Branch(name,(void*)&bigbuf[bufpos],fullname,bufsize); |
|
|
boolflag[i] = -10; |
|
|
charflag[i] = 0; |
|
|
if (itype == 4) {isabool++; boolflag[i] = bufpos; lenbool[i] = ielem;} |
|
|
bufpos += isize*ielem; |
|
|
if (ischar) {isachar++; charflag[i] = bufpos-1; lenchar[i] = isize*ielem;} |
|
|
TObjArray *ll= branch->GetListOfLeaves(); |
|
|
TLeaf *leaf = (TLeaf*)ll->UncheckedAt(0); |
|
|
if (!leaf) continue; |
|
|
TLeafI *leafcount = (TLeafI*)leaf->GetLeafCount(); |
|
|
if (leafcount) { |
|
|
if (leafcount->GetMaximum() <= 0) leafcount->SetMaximum(ielem); |
|
|
} |
|
|
} |
|
|
Int_t cf,l; |
|
|
for(i=1;i<=nentries;i++) { |
|
|
hgnt(id,i,ier); |
|
|
if (isabool) { // if column is boolean |
|
|
for (j=0;j<nvar;j++) { |
|
|
cf = boolflag[j]; |
|
|
if (cf >-1) { |
|
|
for (l=0;l<lenbool[j];l++) { |
|
|
#ifdef R__BYTESWAP |
|
|
boolarr[l] = (UChar_t)bigbuf[cf+4*l]; |
|
|
#else |
|
|
boolarr[l] = (UChar_t)bigbuf[cf+4*l+3]; |
|
|
#endif |
|
|
} |
|
|
memcpy(&bigbuf[cf],boolarr,lenbool[j]); |
|
|
} |
|
|
} |
|
|
} |
|
|
if (isachar) { // if column is character, set terminator |
|
|
for (j=0;j<nvar;j++) { |
|
|
cf = charflag[j]; |
|
|
if (cf) { |
|
|
bigbuf[cf] = '\0'; |
|
|
if (bigbuf[cf-1] != ' ') continue; |
|
|
bigbuf[cf-1] = '\0'; |
|
|
if (bigbuf[cf-2] != ' ') continue; |
|
|
bigbuf[cf-2] = '\0'; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// if optimizing cwn ntuple then look up bufpos and adjust integers to be shorts or chars |
|
|
if( optcwn == 1 ) |
|
|
{ |
|
|
bufpos = 0; |
|
|
for(int k=0; k<nvar;k++) |
|
|
{ |
|
|
#ifndef WIN32 |
|
|
hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem,32,64,32); |
|
|
#else |
|
|
hntvar2(id,k+1,PASSCHAR(name),PASSCHAR(fullname),PASSCHAR(block),nsub,itype,isize,nbits,ielem); |
|
|
#endif |
|
|
|
|
|
Int_t nBytesUsed = 4; // default for integers |
|
|
|
|
|
if ( itype == 2 || itype == 3) |
|
|
{ |
|
|
if( nbits > 16) |
|
|
{ |
|
|
// do nothing for integers of 4 byte |
|
|
} |
|
|
else |
|
|
{ |
|
|
if( nbits > 8 ) |
|
|
{ |
|
|
nBytesUsed = 2; |
|
|
} |
|
|
else |
|
|
{ |
|
|
nBytesUsed = 1; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if(nBytesUsed == 1) |
|
|
{ |
|
|
|
|
|
for(Int_t index = 0; index < ielem; index++) |
|
|
{ |
|
|
// shift all chars with data to be one after another |
|
|
bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize]; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
if(nBytesUsed == 2) |
|
|
{ |
|
|
|
|
|
for(Int_t index = 0; index < ielem; index++) |
|
|
{ |
|
|
// shift all shorts ( 2 chars) with data to be one after another |
|
|
bigbuf[bufpos + index*nBytesUsed ] = bigbuf[bufpos + index * isize]; |
|
|
bigbuf[bufpos + index*nBytesUsed+1 ] = bigbuf[bufpos + index * isize+1]; |
|
|
} |
|
|
} |
|
|
} |
|
|
bufpos += isize*ielem; |
|
|
} |
|
|
} |
|
|
|
|
|
tree->Fill(); |
|
|
} |
|
|
tree->Print(); |
|
|
tree->Write(); |
|
|
delete tree; |
|
|
delete [] x; |
|
|
delete [] bigbuf; |
|
|
delete [] charflag; |
|
|
delete [] lenchar; |
|
|
delete [] boolflag; |
|
|
delete [] lenbool; |
|
|
delete [] boolarr; |
|
|
delete [] chtag_out; |
|
|
} |
|