ROOT logo
ROOT » CORE » BASE » TMacro

class TMacro: public TNamed


TMacro

Class supporting a collection of lines with C++ code.
A TMacro can be executed, saved to a ROOT file, edited, etc.

A macro can be built line by line by calling the AddLine function.
 or it can be created directly from a file via the special constructor
when the first argument is a file name.

A macro can be executed via the Exec function.
Arguments can be specified when calling Exec.

A macro can be drawn in a pad. When the pad is updated, the macro is
automatically executed.

The code in the macro can be saved via the SaveSource function.
If the macro is in the list of primitives of a pad/canvas, the macro
will be saved in the script generated by TCanvas::SaveSource.

A macro can be written to a ROOT file via TObject::Write.

Examples:
TMacro m("Peaks.C");  //macro m with name "Peaks" is created
from file  Peaks.C
m.Exec();             //macro executed with default arguments
m.Exec("4");          //macro executed with argument
m.SaveSource("newPeaks.C");
TFile f("mymacros.root","recreate");
m.Write();   //macro saved to file with name "Peaks"


Function Members (Methods)

public:
TMacro()
TMacro(const TMacro&)
TMacro(const char* name, const char* title = "")
virtual~TMacro()
voidTObject::AbstractMethod(const char* method) const
virtual TObjString*AddLine(const char* text)
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidBrowse(TBrowser* b)
virtual TMD5*Checksum()
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTNamed::Clear(Option_t* option = "")
virtual TObject*TNamed::Clone(const char* newname = "") const
virtual Int_tTNamed::Compare(const TObject* obj) const
virtual voidTNamed::Copy(TObject& named) const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual Long_tExec(const char* params = 0, Int_t* error = 0)MENU
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual voidTNamed::FillBuffer(char*& buffer)
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
virtual TObjString*GetLineWith(const char* text) const
TList*GetListOfLines() const
virtual const char*TNamed::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual const char*TNamed::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTNamed::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTNamed::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTNamed::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
static voidTObject::operator delete(void* ptr)
static voidTObject::operator delete(void* ptr, void* vp)
static voidTObject::operator delete[](void* ptr)
static voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
TMacro&operator=(const TMacro&)
virtual voidPaint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidPrint(Option_t* option = "") constMENU
virtual Int_tTObject::Read(const char* name)
virtual Int_tReadFile(const char* filename)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidSavePrimitive(ostream& out, Option_t* option = "")
virtual voidSaveSource(const char* filename)MENU
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
virtual voidTNamed::SetName(const char* name)MENU
virtual voidTNamed::SetNameTitle(const char* name, const char* title)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidSetParams(const char* params = 0)MENU
virtual voidTNamed::SetTitle(const char* title = "")MENU
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp)
virtual Int_tTNamed::Sizeof() const
virtual voidStreamer(TBuffer& b)
voidStreamerNVirtual(TBuffer& b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()

Data Members

protected:
TList*fLinescollection of lines
TStringTNamed::fNameobject identifier
TStringfParamsdefault string of macro parameters
TStringTNamed::fTitleobject title

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TMacro()
 Create an empty macro, use AddLine() or ReadFile() to fill this macro.
TMacro(const char* name, const char* title = "")
 Create a macro with a name and a title.
 If name contains a '.' it is assumed to be the name of a file, and
 * the macro is automatically filled by reading all the lines in the file,
 * if the title is empty, it will be set to the name of the file,
 * the name will be set to the filename without path or extension.
TMacro(const TMacro& )
 Copy constructor.
~TMacro()
 Delete this macro.
TMacro& operator=(const TMacro& )
 Copy constructor.
TObjString * AddLine(const char* text)
 Add line with text in the list of lines of this macro.
void Browse(TBrowser* b)
 When clicking in the browser, the following action is performed
 on this macro, depending the content of the variable TMacro.Browse.
 TMacro.Browse can be set in the system.rootrc or .rootrc file like
     TMacro.Browse   :  Action
 or set via gEnv->SetValue, eg
     gEnv->SetValue("TMacro.Browse","Print");
 By default TMacro.Browse=""
 -if TMacro.Browse ="" the macro is executed
 -if TMacro.Browse ="Print" the macro is printed in stdout
 -if TMacro.Browse is of the form "mymacro.C"
     the macro void mymacro.C(TMacro *m) is called where m=this macro
     An example of macro.C saving the macro into a file and viewing it
     with emacs is shown below:
        void mymacro(TMacro *m) {
           m->SaveSource("xx.log");
           gSystem->Exec("emacs xx.log&");
        }
TMD5 * Checksum()
 Returns checksum of the current content. The returned TMD5 object must
 be deleted by the user. Returns 0 in case of error.
Long_t Exec(const char* params = 0, Int_t* error = 0)
 Execute this macro with params, if params is 0, default parameters
 (set via SetParams) are used.
 error is set to an TInterpreter::EErrorCode by TApplication::ProcessLine().
 Returns the result of the macro (return value or value of the last
 expression), cast to a Long_t.
TObjString * GetLineWith(const char* text) const
 Search the first line containing text.
void Paint(Option_t* option = "")
 Execute this macro (called by TPad::Paint).
void Print(Option_t* option = "") const
 Print contents of this macro.
Int_t ReadFile(const char* filename)
 Read lines in filename in this macro.
void SaveSource(const char* filename)
 Save macro source in filename.
void SavePrimitive(ostream& out, Option_t* option = "")
 Save macro source on stream out.
void SetParams(const char* params = 0)
 Set default parameters to execute this macro.
TList * GetListOfLines() const
{return fLines;}