Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
exec_macro.C File Reference

Detailed Description

This utility macro executes the macro "macro" given as first argument and save a capture in a png file.

This macro is used by stressGUI to execute and compare the output of the GUI tutorials.

#include "TSystem.h"
#include "TString.h"
#include "TGClient.h"
#include "TGWindow.h"
#include "TClass.h"
#include "THashList.h"
#include "TROOT.h"
#include "TInterpreter.h"
#include "TEnv.h"
#include "TVirtualX.h"
#include "TImage.h"
//______________________________________________________________________________
Int_t exec_macro(const char *macro, Bool_t comp = kFALSE, Bool_t save = kTRUE)
{
enum EErrorCodes {
kSuccess,
kScriptDirNotFound,
kCannotRunScript,
kNumErrorCodes
};
if (gROOT->IsBatch() || !(gClient))
return kCannotRunScript;
TString pwd(gSystem->pwd());
if (!gSystem->cd(gSystem->GetDirName(macro)))
return kScriptDirNotFound;
Int_t err = 0;
TString cmd(".x ");
cmd += gSystem->BaseName(macro);
if (comp)
cmd += "+";
gVirtualX->Sync(1);
gROOT->ProcessLine(cmd, &err);
return kCannotRunScript;
gSystem->cd(pwd);
UInt_t nMainFrames = 0;
TClass *clGMainFrame = TClass::GetClass("TGMainFrame");
TGWindow *win = nullptr;
TIter iWin(gClient->GetListOfWindows());
while ((win = (TGWindow *)iWin())) {
const TObject *winGetParent = win->GetParent();
Bool_t winIsMapped = kFALSE;
if (winGetParent == gClient->GetDefaultRoot())
winIsMapped = kTRUE; // win->IsMapped();
if (winIsMapped && win->InheritsFrom(clGMainFrame)) {
win->MapRaised();
if (save) {
TString outfile = gSystem->BaseName(macro);
outfile.ReplaceAll(".C", TString::Format("_%d.png", ++nMainFrames));
win->RaiseWindow();
img->FromWindow(win->GetId());
img->WriteImage(outfile.Data());
delete img;
}
}
}
if (!gEnv->GetValue("X11.Sync", 0))
gVirtualX->Sync(0);
return kSuccess;
}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
externTEnv * gEnv
Definition TEnv.h:170
#define gClient
Definition TGClient.h:157
Double_t err
#define gROOT
Definition TROOT.h:417
externTSystem * gSystem
Definition TSystem.h:582
#define gVirtualX
Definition TVirtualX.h:375
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2994
Handle_t GetId() const
Definition TGObject.h:41
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void MapRaised()
map raised
Definition TGWindow.cxx:174
const TGWindow * GetParent() const
Definition TGWindow.h:83
virtual void RaiseWindow()
raise window
Definition TGWindow.cxx:206
An abstract interface to image processing library.
Definition TImage.h:29
static TImage * Create()
Create an image.
Definition TImage.cxx:34
virtual void FromWindow(Drawable_t, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition TImage.h:245
virtual void WriteImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition TImage.h:115
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
Basic string class.
Definition TString.h:138
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
Author
Bertrand Bellenot

Definition in file exec_macro.C.