Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
makeimage.C
Go to the documentation of this file.
1/// Generates the ImageName output of the macro MacroName
2
3#include <TPad.h>
4#include <TIterator.h>
5#include <TImage.h>
6#include <TCanvas.h>
7#include <TStyle.h>
8#include <TROOT.h>
9#include <TString.h>
10#include <TSystem.h>
11
12#include <cstdio>
13
15{
16 TObject *o;
17 TIter next(P->GetListOfPrimitives());
18 while ((o = (TObject *)next())) {
19 if (o->InheritsFrom(TPad::Class())) {
20 FindImageInPad((TPad *)o);
21 } else if (o->InheritsFrom(TImage::Class())) {
22 gStyle->SetImageScaling(1.);
23 break;
24 } else {
25 continue;
26 }
27 }
28}
29
31{
32 TObject *o;
33 TIter next(C->GetListOfPrimitives());
34 while ((o = (TObject *)next())) {
35 if (o->InheritsFrom(TPad::Class())) {
36 FindImageInPad((TPad *)o);
37 } else if (o->InheritsFrom(TImage::Class())) {
38 gStyle->SetImageScaling(1.);
39 break;
40 } else {
41 continue;
42 }
43 }
44}
45
46void makeimage(const char *MacroName, const char *ImageName, const char *OutDir, bool cp, bool py)
47{
48 // Execute the macro as a C++ one or a Python one.
49 if (!py) gROOT->ProcessLine(TString::Format(".x %s",MacroName));
50 else gROOT->ProcessLine(TString::Format("TPython::ExecScript(\"%s\");",MacroName));
51
52 // If needed, copy the macro in the documentation directory.
53 if (cp) {
54 TString MN = MacroName;
55 Int_t i = MN.Index("(");
56 Int_t l = MN.Length();
57 if (i>0) MN.Remove(i, l);
58 gSystem->Exec(TString::Format("cp %s %s/macros", MN.Data(), OutDir));
59 }
60
61 // Iterate over all the pads generated by the macro and produce the corresponding pictures.
62 TIter iCanvas(gROOT->GetListOfCanvases());
63 TCanvas* canvas = 0;
64 int ImageNum = 0;
65
66 FILE *s = fopen("ImagesSizes.dat", "w");
67
68 int cw;
69 while ((canvas = (TCanvas*) iCanvas())) {
70 ImageNum++;
71 gStyle->SetImageScaling(3.);
73 canvas->SaveAs(TString::Format("%s/html/pict%d_%s",OutDir,ImageNum,ImageName));
74 cw = canvas->GetWindowWidth();
75 fprintf(s,"%d\n",cw);
76 }
77
78 fclose(s);
79
80 FILE *f = fopen("NumberOfImages.dat", "w");
81 fprintf(f,"%d\n",ImageNum);
82 fclose(f);
83}
#define f(i)
Definition RSha256.hxx:104
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
#define gROOT
Definition TROOT.h:417
externTStyle * gStyle
Definition TStyle.h:442
externTSystem * gSystem
Definition TSystem.h:582
TCanvas * canvas
Definition webwindow.cxx:22
The Canvas class.
Definition TCanvas.h:23
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:42
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
The most important graphics class in the ROOT system.
Definition TPad.h:28
static TClass * Class()
TList * GetListOfPrimitives() const override
Definition TPad.h:247
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
const char * Data() const
Definition TString.h:384
TString & Remove(Ssiz_t pos)
Definition TString.h:694
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2385
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
Float_t py
Definition hprod.C:37
void FindImageInCanvas(TCanvas *C)
Definition makeimage.C:30
void FindImageInPad(TPad *P)
Generates the ImageName output of the macro MacroName.
Definition makeimage.C:14
TSpectrum2 * s
Definition peaks2.C:33
TLine l
Definition textangle.C:4