using namespace std;
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include "hreport.h"
#include "htool.h"
#include "TSystem.h"
#include "TPad.h"
#include "TH1.h"
#include "TH2.h"
#include "TObjString.h"
ClassImp(HReport)
HReport::HReport(const Char_t* name,const Char_t* title)
: TNamed(name,title)
{
initVariables();
cout<<"#------------------------------------------------------------------------------"<<endl;
cout<<" HReport checking needed programs:"<<endl;
Bool_t acro =kTRUE;
Bool_t ghost=kTRUE;
if(gSystem->Exec("which pdflatex"))
{
Error("HReport()","pdflatex is not installed on your system!");
exit(1);
}
if(gSystem->Exec("which ps2pdf"))
{
Error("HReport()","ps2pdf is not installed on your system!");
exit(1);
}
if(gSystem->Exec("which convert"))
{
Error("HReport()","convert is not installed on your system!");
exit(1);
}
if(gSystem->Exec("which acroread"))
{
Warning("HReport()","acroread is not installed on your system! \n \
Switch to gv for viewing! ");
viewer="gv";
acro =kFALSE;
}
if(gSystem->Exec("which gv"))
{
Warning("HReport()","gv is not installed on your system! \
Do not gv as option for openpdf()");
ghost =kFALSE;
}
if(!acro&&!ghost)
{
Warning("HReport()","acroread and gv are not installed on your system! \
Do not use openpdf() at all!");
viewer ="none";
useviewer=kFALSE;
}
cout<<"#------------------------------------------------------------------------------"<<endl;
printOrder();
printOptions();
}
HReport::~HReport()
{
if(fout)delete fout;
fout=NULL;
}
void HReport::initVariables()
{
fout=NULL;
texfile ="";
texdir ="";
colorlinks =kFALSE;
makeTOC =kTRUE;
makeListFigures =kTRUE;
makeListTables =kTRUE;
makeListListings=kTRUE;
draft =kFALSE;
font_size =12;
single_double ="twoside";
column ="onecolumn";
orientation ="";
include_packages="";
title ="";
author ="";
date ="";
keeppics =kFALSE;
viewer ="acroread";
useviewer =kTRUE;
setopt =kFALSE;
includepack =kFALSE;
opentex =kFALSE;
opendoc =kFALSE;
closedoc =kFALSE;
linebreak =80;
linect =1;
}
void HReport::printOptions()
{
cout<<"#------------------------------------------------------------------------------"<<endl;
cout<<"# Options:"<<endl;
cout<<"# landscape (default portrait)"<<endl;
cout<<"# switch the orientation of the paper"<<endl;
cout<<"# colorlinks (default no colorlinks)"<<endl;
cout<<"# pdf links will be red and printed colored"<<endl;
cout<<"# noTOC (default TOC)"<<endl;
cout<<"# do not make table of contents"<<endl;
cout<<"# noListFigures (default ListFigures)"<<endl;
cout<<"# do not make a list of figures"<<endl;
cout<<"# noListTables (default ListTables)"<<endl;
cout<<"# do not make a list of tables"<<endl;
cout<<"# noListListings (default ListListings)"<<endl;
cout<<"# do not make a list of listings"<<endl;
cout<<"# fontsize=11 or 10 (default fontsize=12)"<<endl;
cout<<"# switch to smaler fonts 10pt and 11pt"<<endl;
cout<<"# oneside (default twoside)"<<endl;
cout<<"# single sided layout"<<endl;
cout<<"# twocolumn (default onecolumn)"<<endl;
cout<<"# two text columns "<<endl;
cout<<"# keeppics (default do not keep pics)"<<endl;
cout<<"# keep the old pictures"<<endl;
cout<<"# draft (default no draft)"<<endl;
cout<<"# place holders instead of pictures"<<endl;
cout<<"# gv (default acroread)"<<endl;
cout<<"# use gv or acroread to view the pdf output"<<endl;
cout<<"#------------------------------------------------------------------------------"<<endl;
}
void HReport::printSettings()
{
TString orient=orientation;
orient.ReplaceAll(",","");
cout<<"#------------------------------------------------------------------------------"<<endl;
cout<<"# ACTUAL SETTINGS:"<<endl;
cout<<"# orientation : "<<orient.Data()<<endl;
if(colorlinks) cout<<"# colorlinks : kTRUE"<<endl;
else cout<<"# colorlinks : kFALSE"<<endl;
if(makeTOC) cout<<"# noTOC : kTRUE"<<endl;
else cout<<"# noTOC : kFALSE"<<endl;
if(makeListFigures) cout<<"# noListFigures : kFALSE"<<endl;
else cout<<"# noListFigures : kTRUE"<<endl;
if(makeListTables) cout<<"# noListTables : kFALSE"<<endl;
else cout<<"# noListTables : kTRUE"<<endl;
if(makeListListings)cout<<"# noListListings : kFALSE"<<endl;
else cout<<"# noListListings : kTRUE"<<endl;
cout<<"# fontsize : "<<font_size<<endl;
cout<<"# print : "<<single_double.Data()<<endl;
cout<<"# column : "<<column.Data()<<endl;
if(keeppics) cout<<"# keeppics : kTRUE"<<endl;
else cout<<"# keeppics : kFALSE"<<endl;
if(draft) cout<<"# draft : kTRUE"<<endl;
else cout<<"# draft : kFALSE"<<endl;
cout<<"# viewer : "<<viewer.Data()<<endl;
cout<<"# line break : "<<linebreak<<" characters"<<endl;
cout<<"#------------------------------------------------------------------------------"<<endl;
}
void HReport::setOptions(TString option)
{
if(setopt)
{
Error("HReport::setOptions()","Function called more than one time!");
printOrder();
exit(1);
}
if(opendoc)
{
Error("HReport::setOptions()","Function called after opening of tex document!");
printOrder();
exit(1);
}
setopt=kTRUE;
Int_t size=0;
TString* array=parseString(option,size,",",kTRUE,kTRUE);
if(HTool::findString(array,size,"colorlinks")) colorlinks =kTRUE;
if(HTool::findString(array,size,"notoc")) makeTOC =kFALSE;
if(HTool::findString(array,size,"nolistfigures")) makeListFigures =kFALSE;
if(HTool::findString(array,size,"nolisttables")) makeListTables =kFALSE;
if(HTool::findString(array,size,"nolistlistings"))makeListListings=kFALSE;
if(HTool::findString(array,size,"draft")) draft =kTRUE;
if(HTool::findString(array,size,"fontsize=12")) font_size =12;
if(HTool::findString(array,size,"fontsize=11")) font_size =11;
if(HTool::findString(array,size,"fontsize=10")) font_size =10;
if(HTool::findString(array,size,"oneside")) single_double ="oneside";
if(HTool::findString(array,size,"landscape")) orientation =",landscape";
if(HTool::findString(array,size,"twocolumn")) column ="twocolumn";
if(HTool::findString(array,size,"keeppics")) keeppics =kTRUE;
if(HTool::findString(array,size,"gv")) viewer ="gv";
}
void HReport::includePackages(TString packages)
{
if(includepack)
{
Error("HReport:includePackages()","Function called more than one time!");
printOrder();
exit(1);
}
if(opendoc)
{
Error("HReport::includePackages()","Function called after opening of tex document!");
printOrder();
exit(1);
}
includepack =kTRUE;
include_packages=packages;
}
void HReport::openTex(TString tdir,TString tfile, TString titlename, TString authorname)
{
if(opentex)
{
Error("HReport:openTex()","Function called more than one time!");
printOrder();
exit(1);
}
opentex=kTRUE;
if(opendoc)
{
Error("HReport:openTex()","Function called after opening the tex document!");
printOrder();
exit(1);
}
if(tfile.CompareTo("")==0||tdir.CompareTo("")==0)
{
Error("HReport::openTex()","Input for tex file or tex directory not set!");
exit(1);
}
if(tfile.Contains(".tex")==0)
{
Error("HReport::openTex()","Tex file doen not have the correct file type .tex!");
exit(1);
}
title =titlename;
author=authorname;
date =Form("%i/%i/%i %i:%02i",
daytime.GetDay(),
daytime.GetMonth(),
daytime.GetYear(),
daytime.GetHour(),
daytime.GetMinute());
texfile =tfile;
texdir =tdir;
TString path ="";
TString command="";
printSettings();
gSystem->ExpandPathName(texdir);
TString temp =texdir;
TString base =gSystem->BaseName(texdir.Data());
TString parent=temp.Remove(temp.Length()-base.Length());
if(parent.CompareTo("/")!=0
&&parent.CompareTo("")!=0
&&gSystem->AccessPathName(parent.Data()))
{
Error("HReport::openTex()","Recursive mkdir not supported, check your texdir!");
exit(1);
}
if(!keeppics)
{
if(gSystem->AccessPathName(texdir))
{
cout<<"HReport:: dir "<<texdir<<" does not exist!"<<endl;
}
else
{
cout<<"HReport::Removing old tex dir!"<<endl;
path = "rm -r " + texdir;
gSystem->Exec(path.Data());
}
cout<<"HReport::Creating tex dir!"<<endl;
path = "mkdir " + texdir;
gSystem->Exec(path.Data());
}
else
{
if(gSystem->AccessPathName(texdir))
{
Error("HReport::openTex()","keeppics option used, but texdir does not exist!");
exit(1);
}
}
TString filename=texfile;
filename.ReplaceAll(".tex","");
if(!gSystem->AccessPathName(texdir))
{
const Char_t* suffix[8]={".lot",".toc",".aux",".lof",".out",".log",".lol",".tex"};
for(Int_t i=0;i<8;i++)
{
path = texdir + "/" + filename + suffix[i];
command= "rm " + path;
if(!gSystem->AccessPathName(path)) gSystem->Exec(command.Data());
}
}
path=texdir + "/" + texfile;
fout = new ofstream(path.Data(), ios::out);
if (fout){
cout<<"HReport::Tex file opened : "<<path<<" !"<<endl;
}
else
{
Error("HReport::openTex()","Could not open tex file!");
exit(1);
}
}
void HReport::openDocument()
{
if (fout){
cout<<"HReport::Opening document !"<<endl;
}
else
{
Error("HReport::openDocument()","No valid file pointer!");
printOrder();
exit(1);
}
if(opendoc)
{
Error("HReport:openDocument()","Function called more than one time!");
printOrder();
exit(1);
}
opendoc=kTRUE;
TString docclass="";
docclass ="\\documentclass[";
docclass +=font_size;
docclass +="pt," + single_double + ",a4paper" + orientation + "," + column + "]{report}\n";
*fout<<docclass.Data();
*fout<<"\\usepackage{amsmath}\n"
<<"\\usepackage{subfigure}\n"
<<"\\usepackage{placeins}\n"
<<"\\usepackage{caption2}\n"
<<"\\usepackage{floatflt}\n"
<<"\\usepackage{wrapfig}\n"
<<"\\usepackage{ifthen}\n"
<<"\\usepackage{listings}\n"
<<"\\usepackage{times}\n";
if(include_packages.CompareTo("")!=0)
{
Int_t size=0;
TString* array=HTool::parseString(include_packages,size,",",kTRUE);
for(Int_t i=0;i<size;i++)
{
*fout<<"\\usepackage{"<<array[i].Data()<<"}\n";
}
}
if(!draft)*fout <<"\\usepackage[pdftex]{graphicx}\n";
else *fout <<"\\usepackage[pdftex,draft]{graphicx}\n";
if(colorlinks)*fout<<"\\usepackage[pdftex,colorlinks,plainpages=false]{hyperref}\n";
else *fout<<"\\usepackage[pdftex,plainpages=false]{hyperref}\n";
*fout<<"\\pdfcompresslevel=9\n"
<<"\\pdfoutput=1\n";
if(orientation.CompareTo(",landscape")==0)
{
cout<<"HReport::Setting up landscape format"<<endl;
*fout<<"\\setlength{\\textwidth}{246mm}\n"
<<"\\setlength{\\oddsidemargin}{0in}\n"
<<"\\setlength{\\evensidemargin}{0in}\n";
}
else
{
*fout<<"\\setlength{\\textwidth}{159mm}\n"
<<"\\setlength{\\oddsidemargin}{0in}\n"
<<"\\setlength{\\evensidemargin}{0in}\n";
}
*fout<<"\\makeatletter\n"
<<"\\newcommand\\figcaption{\\def\\@captype{figure}\\caption}\n"
<<"\\newcommand\\tabcaption{\\def\\@captype{table}\\caption}\n"
<<"\\makeatother\n"
<<"\\newcommand{\\goodgap}{\n"
<<"\\hspace{\\subfigtopskip}\n"
<<"\\hspace{\\subfigbottomskip}}\n"
<<"\\renewcommand{\\textfraction}{0.0003}\n";
*fout<<"\\setcounter{tocdepth}{4}\n";
*fout<<"\\setcounter{secnumdepth}{4}\n";
*fout<<"\\begin{document}\n";
*fout<<"\\lstset{tabsize=4,showspaces=false,showstringspaces=false,showtabs=false,breaklines=true,";
*fout<<"postbreak=\\space,numbers=left,basicstyle=\\scriptsize\\tt,language=C++}\n";
*fout<<"\\begin{titlepage}\n"
<<"\\begin{center}\n";
*fout<<"{\\bf {\\Huge " <<title.Data() <<"}}\n \\vspace{2cm}\n\n";
*fout<<"{\\bf {\\Large "<<author.Data()<<"}}\n \\vspace{5cm}\n\n";
*fout<<"{\\bf {\\Large "<<date.Data() <<"}}\n\n";
*fout<<"\\end{center}\n"
<<"\\end{titlepage}\n";
*fout<<"\\clearpage\n";
*fout<<"\\pagestyle{headings}\n";
*fout<<"\\DeclareGraphicsExtensions{.jpg,.pdf,.png,.mps}\n"
<<"\\pagenumbering{roman}\n";
if(makeTOC) *fout<<"\\tableofcontents\n"
<<"\\cleardoublepage\n";
if(makeListFigures) *fout<<"\\listoffigures\n";
if(makeListTables) *fout<<"\\listoftables\n";
if(makeListListings)*fout<<"\\lstlistoflistings\n";
*fout<<"\\cleardoublepage\n"
<<"\\pagenumbering{arabic}\n"
<<"\\setlength{\\parskip}{1.0ex plus0.2ex minus0.2ex}\n"
<<"\\clearpage\n";
}
void HReport::closeDocument()
{
if (fout){
cout<<"HReport::Closing document !"<<endl;
}
else
{
Error("HReport::closeDocument()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::closeDocument()","No tex document!");
printOrder();
exit(1);
}
*fout<<"\\clearpage\n"
<<"\\end{document}\n";
fout->close();
delete fout;
fout=NULL;
setopt =kFALSE;
includepack =kFALSE;
opentex =kFALSE;
opendoc =kFALSE;
closedoc =kTRUE;
}
void HReport::addText(TString text)
{
if(!opendoc)
{
Error("HReport::addText()","No tex document!");
printOrder();
exit(1);
}
if (fout)
{
writeTex(text);
}
else
{
Error("HReport::addText()","No valid file pointer!");
printOrder();
exit(1);
}
}
void HReport::writeTex(TString text,Bool_t skip_curly)
{
if(!fout)
{
Error("HReport::writeTex()","No valid file pointer!");
printOrder();
exit(1);
}
if(text.CompareTo("")!=0)
{
text.ReplaceAll('\t'," \t ");
text.ReplaceAll('\t'," ");
while(text.Contains(" "))
{
text.ReplaceAll(" "," ");
}
if(always_skip_curly){skip_curly=kTRUE;}
Int_t curly =0;
Int_t box =0;
Int_t dollar =0;
Int_t size =text.Length();
for(Int_t i=0;i<size;i++)
{
if(skip_curly)
{
if(text[i]=='{')curly++;
if(text[i]=='}')curly--;
}
if(text[i]=='$' && dollar==0)dollar=1;
if(text[i]=='$' && dollar==1)dollar=0;
if(text[i]=='[')box++;
if(text[i]==']')box--;
if(text[i]=='\n') linect=1;
if(linect>=linebreak && text[i]==' ' && dollar==0 && curly==0 && box==0)
{
*fout<<"\n";
linect=1;
}
else
{
linect++;
*fout<<text[i];
}
}
}
}
void HReport::makepdf()
{
TString workingdir=gSystem->WorkingDirectory();
cout<<"HReport::Creating pdf!"<<endl;
TString command ="";
TString filename= texdir + "/" + texfile;
if(!gSystem->AccessPathName(texdir.Data()))
{
if(!gSystem->AccessPathName(filename.Data()))
{
command="cd " + texdir + " && pdflatex -interaction batchmode " + texfile + " 2>&1 > /dev/null" + " && cd -";
gSystem->Exec(command.Data());
gSystem->Exec(command.Data());
gSystem->Exec(command.Data());
TString output=texfile;
output.ReplaceAll(".tex",".pdf");
filename= texdir + "/" + output;
if(!gSystem->AccessPathName(filename.Data()))
{
TString filename2= workingdir + "/" + output;
Int_t success=gSystem->CopyFile(filename.Data(),filename2.Data(),kTRUE);
if(success)
{
Error("HReport::makepdf()","Could not copy pdf file : %s to %s !",filename.Data(),filename2.Data());
exit(1);
}
}
else
{
Error("HReport::makepdf()","Could not access pdf file : %s !",filename.Data());
exit(1);
}
}
else
{
Error("HReport::makepdf()","Could not access tex file : %s !",filename.Data());
exit(1);
}
}
else
{
Error("HReport::makepdf()","Could not access path to texdir: %s !",texdir.Data());
exit(1);
}
}
void HReport::openpdf()
{
if(useviewer)
{
cout<<"HReport::Opening pdf in "<<viewer.Data()<<"!"<<endl;
TString workingdir=gSystem->WorkingDirectory();
TString output =texfile;
output.ReplaceAll(".tex",".pdf");
TString filename = workingdir + "/" + output;
if(!gSystem->AccessPathName(filename.Data()))
{
TString command="";
command=viewer + " " + filename + "&";
gSystem->Exec(command);
}
else
{
Error("HReport::openpdf()","Could not access pdf file : %s !",filename.Data());
exit(1);
}
}
else
{
cout<<"HReport::Cannot Opening pdf in viewer!"<<endl;
}
}
void HReport::figure(TCanvas* canvas,TString cap,TString shcap,TString lab,
Float_t width,Int_t x1,Int_t y1,Int_t x2,Int_t y2,Int_t rotate,
TString filename,Bool_t force,TString format)
{
if(!fout)
{
Error("HReport::figure()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::figure()","No tex document!");
printOrder();
exit(1);
}
if(canvas==0)
{
Error("HReport::figure()","Zero pointer received for Canvas!");
exit(1);
}
if(filename.CompareTo("")==0)
{
filename=canvas->GetName();
filename+="_auto_";
}
if(format.CompareTo("pdf")==0)
{
saveToPdf(canvas,filename,kFALSE,force);
filename=filename + ".pdf";
}
if(format.CompareTo("png")==0)
{
saveToPng(canvas,filename,kFALSE,force);
filename=filename + ".png";
}
TString scaption ="";
TString slabel ="";
TString swidth ="";
TString sviewport="";
TString sgraphic ="";
TString sangle ="";
if(width>0)
{
swidth =Form(",width=%5.2f\\linewidth",width);
}
else
{
swidth=",width=\\linewidth";
}
if(x1<0||y1<0||x2<0||y2<0)
{
sviewport="";
}
else
{
sviewport=Form(",viewport=%i %i %i %i",x1,y1,x2,y2);
}
sangle =Form("angle=%i",rotate);
scaption="\\caption[" + shcap + "]{" + cap + "}\n";
sgraphic="\\includegraphics[" + sangle + sviewport + swidth + ",clip=true]{" + filename + "}\n";
slabel ="\\label{"+ lab +"}\n";
writeTex("\\begin{figure}[\\htb]\n");
writeTex("\\begin{center}\n");
writeTex(sgraphic,kFALSE);
writeTex(scaption,kFALSE);
if(lab.CompareTo("")!=0)writeTex(slabel);
writeTex("\\end{center}\n");
writeTex("\\end{figure}\n");
}
void HReport::figureSideCaption(TCanvas* canvas,TString cap,TString shcap,TString lab,
Float_t widthpic,Float_t widthtxt,Float_t space,Int_t x1,Int_t y1,Int_t x2,Int_t y2,Int_t rotate,
TString filename,Bool_t force,TString format)
{
if(!fout)
{
Error("HReport::figureSideCaption()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::figureSideCaption()","No tex document!");
printOrder();
exit(1);
}
if(canvas==0)
{
Error("HReport::figureSideCaption()","Zero pointer received for Canvas!");
exit(1);
}
if(filename.CompareTo("")==0)
{
filename=canvas->GetName();
filename+="_auto_";
}
if(format.CompareTo("pdf")==0)
{
saveToPdf(canvas,filename,kFALSE,force);
filename=filename + ".pdf";
}
if(format.CompareTo("png")==0)
{
saveToPng(canvas,filename,kFALSE,force);
filename=filename + ".png";
}
TString scaption ="";
TString sviewport="";
TString swidth ="";
TString sgraphic ="";
TString sangle ="";
TString slabel ="";
TString temp ="";
swidth=",width=\\linewidth";
if(x1<0||y1<0||x2<0||y2<0)
{
sviewport="";
}
else
{
sviewport=Form(",viewport=%i %i %i %i",x1,y1,x2,y2);
}
sangle =Form("angle=%i",rotate);
scaption="\\caption[" + shcap + "]{" + cap + "}\n";
sgraphic="\\includegraphics[" + sangle + sviewport + swidth + ",clip=true]{" + filename + "}\n";
slabel ="\\label{"+ lab +"}\n";
writeTex("\\begin{figure}[\\htb]\n");
writeTex("\\centering\n");
temp=" \\ifthenelse{\\isodd{\\pageref{" + lab +"}}}\n";
writeTex(temp);
writeTex(" {%BEGIN ODD-PAGE\n");
temp=Form(" \\begin{minipage}[c]{%5.2f\\linewidth}\n",widthtxt);
writeTex(temp);
writeTex(" \\centering\n");
writeTex(scaption,kFALSE);
if(lab.CompareTo("")!=0)writeTex(slabel);
writeTex(" \\end{minipage}\n");
temp=Form(" \\hspace{%5.2f\\linewidth}\n",space);
writeTex(temp);
temp=Form(" \\begin{minipage}[c]{%5.2f\\linewidth}\n",widthpic);
writeTex(temp);
writeTex(sgraphic,kFALSE);
writeTex(" \\end{minipage}\n");
writeTex(" }% END ODD-PAGE\n");
writeTex(" {% BEGIN EVEN-PAGE\n");
temp=Form(" \\begin{minipage}[c]{%5.2f\\linewidth}\n",widthpic);
writeTex(temp);
writeTex(sgraphic,kFALSE);
writeTex(" \\end{minipage}\n");
temp=Form(" \\hspace{%5.2f\\linewidth}\n",space);
writeTex(temp);
temp=Form(" \\begin{minipage}[c]{%5.2f\\linewidth}\n",widthtxt);
writeTex(temp);
writeTex(" \\centering\n");
writeTex(scaption,kFALSE);
if(lab.CompareTo("")!=0)writeTex(slabel);
writeTex(" \\end{minipage}\n");
writeTex(" }% END EVEN-PAGE\n");
writeTex("\\end{figure}\n");
}
void HReport::table(Float_t* val,Float_t* valerr,Int_t sx,Int_t sy,
TString titlex,TString titley,
TString format,TString line,
TString cap,TString shcap,TString label)
{
if(!fout)
{
Error("HReport::table()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::table()","No tex document!");
printOrder();
exit(1);
}
if(val==0)
{
Error("HReport::table()","Pointer to data is zero!");
exit(1);
}
if(titlex.CompareTo("")==0||titley.CompareTo("")==0||line.CompareTo("")==0)
{
Error("HReport::table()","column or line definitions are empty!");
exit(1);
}
if(sx>10)
{
Warning("HReport::table()","More than 10 x values not supported!");
}
Int_t isx,isy,iline;
TString* arrayx=parseString(titlex,isx ,",",kFALSE,kFALSE);
TString* arrayy=parseString(titley,isy ,",",kFALSE,kFALSE);
TString* arrayf=parseString(line ,iline,"&",kFALSE,kFALSE);
if(isx!=sx || isy!=sy || iline!=sx)
{
Error("HReport::table()","Dimension of array does not match format string / title strings!");
exit(1);
}
openTable(format);
*fout<<"\\hline \n";
*fout<<" & ";
for(Int_t x=0;x<iline;x++)
{
*fout<<arrayx[x].Data();
if(x<sx-1)*fout<<" & ";
}
*fout<<" \\\\ \n";
*fout<<"\\hline \n";
for(Int_t y=0;y<sy;y++)
{
*fout<<arrayy[y].Data()<<" & ";
for(Int_t x=0;x<iline;x++)
{
if(arrayf[x].Contains("\\pm")==0)
{
*fout<<Form(arrayf[x].Data(),val[y*sx+x]);
}
else if(arrayf[x].Contains("\\pm")!=0&&valerr!=0)
{
*fout<<Form(arrayf[x].Data(),val[y*sx+x],valerr[y*sx+x]);
}
else
{
*fout<<Form(arrayf[x].Data(),val[y*sx+x]);
}
if(x<sx-1)*fout<<" & ";
}
*fout<<" \\\\ \n";
*fout<<"\\hline \n";
}
closeTable(cap,shcap,label);
}
void HReport::openTable(TString format)
{
if(!fout)
{
Error("HReport::openTable()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::openTable()","No tex document!");
printOrder();
exit(1);
}
if(format.CompareTo("")==0)
{
Error("HReport::openTable()","Format string is empty!");
exit(1);
}
*fout<<"\\begin{table}[\\htb] \n";
*fout<<"\\centering \n";
*fout<<"\\begin{tabular}{"<<format.Data()<<"} \n";
}
void HReport::closeTable(TString cap,TString shcap,TString label)
{
if(!fout)
{
Error("HReport::closeTable()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::closeTable()","No tex document!");
printOrder();
exit(1);
}
if(cap.CompareTo("")==0)
{
Error("HReport::closeTable()","Format string is empty!");
exit(1);
}
*fout<<"\\end{tabular} \n";
TString scaption ="";
TString slabel ="";
scaption="\\caption[" + shcap + "]{" + cap + "}\n";
slabel ="\\label{"+ label +"}\n";
writeTex(scaption,kFALSE);
writeTex(slabel,kFALSE);
writeTex("\\end{table} \n");
}
void HReport::openAppendix()
{
if(!fout)
{
Error("HReport::openAppendix()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::openAppendix()","No tex document!");
printOrder();
exit(1);
}
*fout<<"\\clearpage \n ";
*fout<<"\\begin{appendix}\n";
}
void HReport::closeAppendix()
{
if(!fout)
{
Error("HReport::closeAppendix()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::closeAppendix()","No tex document!");
printOrder();
exit(1);
}
*fout<<"\\end{appendix}\n\n";
}
void HReport::includeSource(TString source,TString cap,TString shcap,TString label,Int_t firstline,Int_t lastline,TString option)
{
if(!fout)
{
Error("HReport::includeSource()","No valid file pointer!");
printOrder();
exit(1);
}
if(!opendoc)
{
Error("HReport::includeSource()","No tex document!");
printOrder();
exit(1);
}
if(source.CompareTo("")==0||cap.CompareTo("")==0)
{
Error("HReport::includeSource()","source file or caption not specified!");
exit(1);
}
TString caption="";
TString lines ="";
TString opt ="";
TString lab ="";
if(shcap.CompareTo("")!=0)
{
caption="caption={["+ shcap + "] " + cap + "}";
}
else
{
caption="caption={" + cap + "}";
}
if(firstline!=-1&&lastline!=-1)
{
lines=", firstline=";
lines+=firstline;
lines+=", lastline=";
lines+=lastline;
}
else if(firstline!=-1&&lastline==-1)
{
lines=", firstline=";
lines+=firstline;
}
else if(firstline==-1&&lastline!=-1)
{
lines=", lastline=";
lines+=lastline;
}
if(option.CompareTo("")!=0)
{
opt=", " + option;
}
if(label.CompareTo("")!=0)
{
opt=", label=" + label;
}
*fout<<"\\lstinputlisting["<<caption.Data()<<lab.Data()<<lines.Data()<<opt.Data()<<"]{"<<source.Data()<<"}\n";
}
void HReport::printOrder()
{
cout<<"#------------------------------------------------------------------------------"<<endl;
cout<<"# USEAGE of HReport"<<endl;
cout<<"# HReport* report=new HReport(\"report\",\"report\");"<<endl;
cout<<"# report->setOption(\"......\"); (optional)"<<endl;
cout<<"# report->includePackages(\"......\"); (optional)"<<endl;
cout<<"# report->openTex(\"......\");"<<endl;
cout<<"# report->openDocument();"<<endl;
cout<<"#"<<endl;
cout<<"# add your text,figures,tables() etc. (optional)"<<endl;
cout<<"#"<<endl;
cout<<"# report->openAppendix(); (optional)"<<endl;
cout<<"# add something (optional)"<<endl;
cout<<"# report->closeAppendix(); (optional)"<<endl;
cout<<"# report->closeDocument();"<<endl;
cout<<"# report->makepdf();"<<endl;
cout<<"# report->openpdf(); (optional)"<<endl;
cout<<"#------------------------------------------------------------------------------"<<endl;
}
Int_t HReport::saveToPdf(TCanvas* canvas,TString filename,Bool_t separate,Bool_t force)
{
if(keeppics&&!force) return 0;
if(canvas==0)
{
Error("HReport::saveToPdf()","Zero pointer received for Canvas!");
exit(1);
}
if(filename.CompareTo("")==0)
{
filename=canvas->GetName();
filename+="_auto_";
}
TString File =filename;
TString Path =texdir;
Path =Path + "/";
TString command ="";
TString totalin ="";
TString totalout="";
File.ReplaceAll(".ps","");
File.ReplaceAll(".pdf","");
if(!separate)
{
totalin = Path + File + ".ps";
totalout= Path + File + ".pdf";
canvas->SaveAs(totalin.Data());
command= "ps2pdf " + totalin + " " + totalout;
gSystem->Exec(command.Data());
command= "rm " + totalin;
gSystem->Exec(command.Data());
}else{
TString subpad="";
Int_t npads= canvas->GetListOfPrimitives()->GetSize();
for(Int_t i=1;i<=npads;i++)
{
subpad=i;
totalin = Path + File + "_" + subpad + ".ps";
totalout= Path + File + "_" + subpad + ".pdf";
canvas->cd(i);
gPad->SaveAs(totalin.Data());
command= "ps2pdf " + totalin + " " + totalout;
gSystem->Exec(command.Data());
command= "rm " + totalin;
gSystem->Exec(command.Data());
}
}
return 0;
}
Int_t HReport::saveToPng(TCanvas* canvas,TString filename,Bool_t separate,Bool_t force)
{
if(keeppics&&!force) return 0;
if(canvas==0)
{
Error("HReport::saveToPdf()","Zero pointer received for Canvas!");
exit(1);
}
if(filename.CompareTo("")==0)
{
filename=canvas->GetName();
filename+="_auto_";
}
TString File =filename;
TString Path =texdir;
Path =Path + "/";
TString command ="";
TString totalin ="";
TString totalout="";
File.ReplaceAll(".ps","");
File.ReplaceAll(".png","");
if(!separate)
{
totalin = Path + File + ".ps";
totalout= Path + File + ".png";
canvas->SaveAs(totalin.Data());
command= "convert " + totalin + " " + totalout;
gSystem->Exec(command.Data());
command= "rm " + totalin;
gSystem->Exec(command.Data());
}else{
TString subpad="";
Int_t npads= canvas->GetListOfPrimitives()->GetSize();
for(Int_t i=1;i<=npads;i++)
{
subpad=i;
totalin = Path + File + "_" + subpad + ".ps";
totalout= Path + File + "_" + subpad + ".png";
canvas->cd(i);
gPad->SaveAs(totalin.Data());
command= "convert " + totalin + " " + totalout;
gSystem->Exec(command.Data());
command= "rm " + totalin;
gSystem->Exec(command.Data());
}
}
return 0;
}
TString* HReport::parseString(TString options,Int_t& size,TString separator,Bool_t tolower,Bool_t removespace)
{
if(tolower)options.ToLower();
if(removespace)options.ReplaceAll(" ","");
Ssiz_t len=options.Length();
TString* sarray=0;
Int_t count=0;
if(len!=0)
{
TObjArray array;
Char_t* mystring=(Char_t*)options.Data();
Char_t* buffer;
TObjString* stemp;
while(1)
{
if(count==0)
{
buffer=strtok(mystring,separator.Data());
stemp=new TObjString(buffer);
array.Add(stemp);
}
if(!(buffer=strtok(NULL,separator.Data())))break;
stemp=new TObjString(buffer);
array.Add(stemp);
count++;
}
sarray= new TString [count+1];
for(Int_t i=0;i<count+1;i++)
{
sarray[i]= ((TObjString*)(array.At(i)))->GetString();
}
array.Delete();
}
size=count+1;
return sarray;
}
Last change: Sat May 22 13:08:04 2010
Last generated: 2010-05-22 13:08
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.