Logo ROOT  
Reference Guide
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 {
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 = 0;
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;
}
Author
Bertrand Bellenot

Definition in file exec_macro.C.

TGWindow
Definition: TGWindow.h:31
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TSystem::cd
Bool_t cd(const char *path)
Definition: TSystem.h:421
TImage::Create
static TImage * Create()
Create an image.
Definition: TImage.cxx:35
gEnv
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
TSystem::BaseName
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:933
TGWindow::RaiseWindow
virtual void RaiseWindow()
raise window
Definition: TGWindow.cxx:189
gVirtualX
#define gVirtualX
Definition: TVirtualX.h:338
TString::Data
const char * Data() const
Definition: TString.h:369
TGWindow::MapRaised
virtual void MapRaised()
map raised
Definition: TGWindow.cxx:157
Int_t
int Int_t
Definition: RtypesCore.h:45
TImage
Definition: TImage.h:29
TClass.h
TEnv::GetValue
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
TVirtualX.h
TString::Format
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:2311
TEnv.h
TString
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TGObject::GetId
Handle_t GetId() const
Definition: TGObject.h:47
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
TString.h
TGWindow.h
TSystem::GetDirName
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1030
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TImage.h
TROOT.h
gClient
#define gClient
Definition: TGClient.h:166
TSystem.h
ROOT::EFromHumanReadableSize::kSuccess
@ kSuccess
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TClass::GetClass
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:2925
TImage::WriteImage
virtual void WriteImage(const char *, EImageFileTypes=TImage::kUnknown)
Definition: TImage.h:115
TGClient.h
THashList.h
gSystem
R__EXTERN TSystem * gSystem
Definition: TSystem.h:559
TGWindow::GetParent
const TGWindow * GetParent() const
Definition: TGWindow.h:84
TInterpreter.h
TClass
Definition: TClass.h:80
TObject
Definition: TObject.h:37
TInterpreter::kNoError
@ kNoError
Definition: TInterpreter.h:76
TIter
Definition: TCollection.h:233
TImage::FromWindow
virtual void FromWindow(Drawable_t, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition: TImage.h:244
TSystem::pwd
const char * pwd()
Definition: TSystem.h:422
gROOT
#define gROOT
Definition: TROOT.h:406