//*-- AUTHOR : J. Markert //_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////////////////// // HReport // This class provides a wrapper arround Latex/pdflatex. The tex file will // be created on the fly from a ROOT macro and compiled in background. The // output is a pdf file. This class uses pdflatex with report.sty, so it needs // latex/pdflattex to be installed on the system. For viewing acroread or gv is // used. For converting ROOT graphics ps2pdf and convert has to be available. // HReport creates a directory (name specified in openTex(...)). The tex file // and the converted pictures will be created inside the directory. The pdf // output is coppied to the working dir. A new run of HReport will remove the // existing directory (if "keeppics" option is not specified), so make sure // that the directory name is not equal to a directory you don't want to remove! // The order of the different function calls is important! setOptions("") and // includePackages("") has to be called before openTex(), otherwise they will // have no effect. //-------------------------------------------------------------------------- // HOW TO USE HReport: // HReport* report=new HReport("report","report"); // report->setOptions(""); // Options: // landscape (default portrait) // switch the orientation of the paper // colorlinks (default no colorlinks) // pdf links will be red and printed colored // noTOC (default TOC) // do not make table of contents // noListFigures (default ListFigures) // do not make a list of figures // noListTables (default ListTables) // do not make a list of tables // noListListings (default ListListings) // do not make a list of listings // fontsize=11 or 10 (default fontsize=12) // switch to smaler fonts 10pt and 11pt // oneside (default twoside) // single sided layout // twocolumn (default onecolumn) // two text columns // keeppics (default do not keep pics) // keep the old pictures // draft (default no draft) // place holders instead of pictures // gv (default acroread) // use gv or acroread to view the pdf output // // report->includePackages("name,name2"); :: comma separated list // :: of additional packages (optional) // // report->openTex("tex_dir", :: temp dir in working dir (created) containing pictures,tex.. // "tex_file_name.tex", :: name of the created tex file (and the created pdf output!) // "Title of report", :: Title of the report shown on the title page // "Author"); :: Author shown on the title page // // report->openDocument(); :: open the tex file with specified options // report->closeDocument(); :: closes the tex file // report->makepdf(); :: calls pdflatex in background and copies the pdf output to working dir // report->openpdf(); :: opens the pdf file in acroread // //-------------------------------------------------------------------------- // Between openDocument() and closeDocument() you can add what ever you like // to your report. // Add any text using latex commands : // Rules: "\" has to be replaced by "\\" // "\n" gives a new line in texfile // "\n\n" creates a new paragraph // // report->addText("\\chapter{Report something }\n " // "This report is very important....\n\n " // "line can be splitted in this way if your editor does not " // "support line wrapping."}; // // // report->openAppendix() opens the appendix environment // report->closeAppendix() close the appendix environment // --everything between the calls will go into the appendix // //--------------------------------------------------------------------------- // For simple formated tables a template can be created : // // Float_t values[6]={1.1,2.2, // 3.3,4.4, // 5.5,6.6}; // // Float_t valerr[6]={1.1,2.2, // 3.3,4.4, // 5.5,6.6}; // // report->table(&values[0],&valerr[0], :: pointer to 1dim array value and error of value // 2,3, :: size in x and y of the table (2x3 only) // "x1,x2","y1,y2,y3", :: comma separated list column header (x) and line header (y) // "|c|c|", :: format of the tabel (here centered with line separation) // "%5.1f $\\pm$ %5.2f & %5.1f $\\pm$ %5.2f", :: cells are seprated by &, $\\pm$ indicates usage of errors, // :: formating as printf for floats (tipp: a simple % becomes \\%%) // "caption of table", :: caption below the table // "short caption for list of tables", :: caption used in list of tables // "label_of_table"); :: label for referencing of the table // //--------------------------------------------------------------------------- // Add Root graphics to the report: // Figure with caption on the binding side: // report->figureSideCaption(Tcanvas* canvas, :: canvas pointer which contains the grahic // "caption of figure", :: caption beside the figure // "short caption for list of figures", :: caption used in list of figures // "label_of_figure", :: label for referencing of the figure // 0.7,0.2,0.02, :: size of graphic / caption / space in terms of linewidth // 54,30,1030,750, :: viewport x1,y1,x2,y2 in pixels (display ony a part or the picture) // :: values equal -1 shows full picture // -90, :: rotation (- = clock wise) // "filename"); :: output name of picture ("" will generate the // name from name of canvas). // force); :: picture will be created no matter if keeppics option is used // // Figure with caption below as decribed above (without parameters for caption size and space) // report->figure(canv ,"caption","short cap","label",picsize,x1,y1,x2,y2,rotation,"filename"); // //--------------------------------------------------------------------------- // Include C++ source files / ROOT macros into your code: // This is a wrapper arround listings package of tex. Not all // features are supported but the documentation of the package // will help to get the maximum usage out. // // report->includeSource(TString source, :: path/filename of the source (relative path accpeted) // TString cap, :: caption used above the listing // TString shcap, :: caption used for list of listings // TString label, :: label for referencing the listing // Int_t firstline, :: first line of code listed // Int_t lastline, :: last line of code listed // TString option); :: additional options can be taken into account // //////////////////////////////////////////////////////////////////////////// using namespace std; #include #include #include #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) { // constructor for HReport initVariables(); cout<<"#------------------------------------------------------------------------------"<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<<"#------------------------------------------------------------------------------"<includePackages("name,name2"); // This function has to be called befor openTex(). 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) { // The tex file and the converted pictures will be created inside the directory. // The pdf output is coppied to the working dir. A new run of HReport will // remove the existing directory (if "keeppics" option is not specified), so // make sure that the directory name is not equal to a directory you don't // want to remove! // report->openTex("tex_dir", :: temp dir in working dir (created) containing pictures,tex.. // "tex_file_name.tex", :: name of the created tex file (and the created pdf output!) // "Title of report", :: Title of the report shown on the title page // "Author"); :: Author shown on the title page 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); } //------------------------------------------------------------ // setting up variables of the title page 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); // expand environment variables etc. //------------------------------------------------------------ // check if one or more directory level should be created 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); } //------------------------------------------------------------ //------------------------------------------------------------ // removing old directory if(!keeppics) { // don't remove old pictures if(gSystem->AccessPathName(texdir)) { cout<<"HReport:: dir "<Exec(path.Data()); } cout<<"HReport::Creating tex dir!"<Exec(path.Data()); } else { if(gSystem->AccessPathName(texdir)) { Error("HReport::openTex()","keeppics option used, but texdir does not exist!"); exit(1); } } //------------------------------------------------------------ //------------------------------------------------------------ // removing old tex files 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()); } } //------------------------------------------------------------ //------------------------------------------------------------ // opening output stream to tex file path=texdir + "/" + texfile; fout = new ofstream(path.Data(), ios::out); if (fout){ cout<<"HReport::Tex file opened : "<close(); delete fout; fout=NULL; setopt =kFALSE; includepack =kFALSE; opentex =kFALSE; opendoc =kFALSE; closedoc =kTRUE; } void HReport::addText(TString text) { // Between openDocument() and closeDocument() you can add what ever you like // to your report. // Add any text using latex commands : // Rules: "\" has to be replaced by "\\" // "\n" gives a new line in texfile (only needed if the line // should have an extract break here, otherwise it will // done automatically) // "\n\n" creates a new paragraph // // report->addText("\\chapter{Report something }\n " // "This report is very important....\n\n " // "line can be splitted in this way if your editor does not " // "support line wrapping."}; // // The tex file is formated with a line width of linebreak characters. // (setLineBreak()). Do not use "\" as string break in input, it can cause // strange effects (use the above mentioned method). 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) { // remove all tabs and multible spaces from string // and insert line break in next space if line is longer than // linebreak characters. Does not break in {},[] or $$. // skip_curly= kFALSE will force to break in curly braces. // If alwaysSkipCurly() has been set skip_curly will // be overwritten to kTRUE. if(!fout) { Error("HReport::writeTex()","No valid file pointer!"); printOrder(); exit(1); } if(text.CompareTo("")!=0) { text.ReplaceAll('\t'," \t "); // remove tabs text.ReplaceAll('\t'," "); // remove tabs while(text.Contains(" ")) // remove multible spaces { 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=linebreak && text[i]==' ' && dollar==0 && curly==0 && box==0) { // add line break if line is to Long_t and no braces/math mode is open *fout<<"\n"; linect=1; } else { linect++; *fout<WorkingDirectory(); cout<<"HReport::Creating pdf!"<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() { // opens the pdf file in acroread or gv if(useviewer) { cout<<"HReport::Opening pdf in "<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!"<figureSideCaption(Tcanvas* canvas, :: canvas pointer which contains the grahic // "caption of figure", :: caption beside the figure // "short caption for list of figures", :: caption used in list of figures // "label_of_figure", :: label for referencing of the figure // 0.7, :: size of graphic in terms of linewidth // 54,30,1030,750, :: viewport x1,y1,x2,y2 in pixels (display ony a part or the picture) // :: values equal -1 shows full picture // -90, :: rotation (- = clock wise) // "filename", :: output name of picture ("" will generate the // name from name of canvas). // force); :: picture will be created no matter if keeppics option is used 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) { // create name automatic from canvas name 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) { // if width is defined swidth =Form(",width=%5.2f\\linewidth",width); } else { // take full line width swidth=",width=\\linewidth"; } if(x1<0||y1<0||x2<0||y2<0) { // if viewport is not defined sviewport=""; } else { // if viewport is defined 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) { // Add Root graphics to the report: // The canvas will be saved as .ps and converted to pdf // by ps2pdf. The pdf pic will be stored in tex_dir. // Figure with caption on the binding side: // report->figureSideCaption(Tcanvas* canvas, :: canvas pointer which contains the grahic // "caption of figure", :: caption beside the figure // "short caption for list of figures", :: caption used in list of figures // "label_of_figure", :: label for referencing of the figure // 0.7,0.2,0.02, :: size of graphic / caption / space in terms of linewidth // 54,30,1030,750, :: viewport x1,y1,x2,y2 in pixels (display ony a part or the picture) // :: values equal -1 shows full picture // -90, :: rotation (- = clock wise) // "filename", :: output name of picture ("" will generate the // name from name of canvas). // force); :: picture will be created no matter if keeppics option is used 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) { // create name automatic from canvas name 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 =""; // take full line width swidth=",width=\\linewidth"; if(x1<0||y1<0||x2<0||y2<0) { // if viewport is not defined sviewport=""; } else { // if viewport is defined 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) { // For simple formated tables a template can be created : // // Float_t values[6]={1.1,2.2, // 3.3,4.4, // 5.5,6.6}; // // Float_t valerr[6]={1.1,2.2, // 3.3,4.4, // 5.5,6.6}; // // report->table(&values[0],&valerr[0], :: pointer to 1dim array value and error of value // 2,3, :: size in x and y of the table (2x3 only) // "x1,x2","y1,y2,y3", :: comma separated list column header (x) and line header (y) // "|c|c|", :: format of the tabel (here centered with line separation) // "%5.1f $\\pm$ %5.2f & %5.1f $\\pm$ %5.2f", :: cells are seprated by &, $\\pm$ indicates usage of errors, // :: formating as printf for floats (tipp: a simple % becomes \\%%) // "caption of table", :: caption below the table // "short caption for list of tables", :: caption used in list of tables // "label_of_table"); :: label for referencing of the table // // if valerr=0 no errors will be used. Which value will be printed with errors // is defined by the line format. 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); //----header of table------------- *fout<<"\\hline \n"; *fout<<" & "; for(Int_t x=0;xincludeSource(TString source, :: path/filename of the source (relative path accpeted) // TString cap, :: caption used above the listing // TString shcap, :: caption used for list of listings // TString label, :: label for referencing the listing // Int_t firstline, :: first line of code listed // Int_t lastline, :: last line of code listed // TString option); :: additional options can be taken into account // // source and cap are mandatory, the is optional. Part of the source can be listed with firstline/lastline arguments. // firstline==-1 && lastline!=1 will list from beginning of file to lastline. firstline!=-1 && lastline==-1 will list // from firstline to end of file. Both equal -1 will list the full file (default). 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) { // both values specified lines=", firstline="; lines+=firstline; lines+=", lastline="; lines+=lastline; } else if(firstline!=-1&&lastline==-1) { // only first value specified lines=", firstline="; lines+=firstline; } else if(firstline==-1&&lastline!=-1) { // only value value specified lines=", lastline="; lines+=lastline; } if(option.CompareTo("")!=0) { opt=", " + option; } if(label.CompareTo("")!=0) { opt=", label=" + label; } *fout<<"\\lstinputlisting["<setOption(\"......\"); (optional)"<includePackages(\"......\"); (optional)"<openTex(\"......\");"<openDocument();"<openAppendix(); (optional)"<closeAppendix(); (optional)"<closeDocument();"<makepdf();"<openpdf(); (optional)"<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) { // saves a canvas to png file by storing it as ps and calling // conver to convert it to png. The ps file will be removed. // canvas is the pointer of the canvas which you want to save // path is the path to the directory where you want to store the png // filename is the name of the png which wou create // separate=kTRUE will loop over all pads and save the pictures single // (path/filename_i) separate=kFALSE as the canvas in one png. if(keeppics&&!force) return 0; if(canvas==0) { Error("HReport::saveToPdf()","Zero pointer received for Canvas!"); exit(1); } if(filename.CompareTo("")==0) { // create name automatic from canvas name 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) { // loops over TString options and find substrings separated by separator // and puts them to an array of TStrings. size will hold the size of this // array and the pointer to the array is returned. If tolower is kTRUE options // will be made toLower. if removespace=kTRUE spaces will be remove from the string. 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) // find all token in option string and put them to a list { 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;iGetString(); } array.Delete(); } size=count+1; return sarray; }