#include "RConfig.h"
#include "RConfigure.h"
#include <string>
#include <map>
#include <stdlib.h>
#ifdef WIN32
#include <io.h>
#endif
#include "Riostream.h"
#include "Gtypes.h"
#include "TROOT.h"
#include "TClass.h"
#include "TClassEdit.h"
#include "TClassGenerator.h"
#include "TDataType.h"
#include "TFile.h"
#include "TMapFile.h"
#include "TDatime.h"
#include "TStyle.h"
#include "TObjectTable.h"
#include "TClassTable.h"
#include "TSystem.h"
#include "THashList.h"
#include "TObjArray.h"
#include "TEnv.h"
#include "TError.h"
#include "TColor.h"
#include "TGlobal.h"
#include "TFunction.h"
#include "TVirtualPad.h"
#include "TBrowser.h"
#include "TSystemDirectory.h"
#include "TApplication.h"
#include "TCint.h"
#include "TGuiFactory.h"
#include "TRandom3.h"
#include "TMessageHandler.h"
#include "TFolder.h"
#include "TQObject.h"
#include "TProcessUUID.h"
#include "TPluginManager.h"
#include "TMap.h"
#include "TObjString.h"
#include "TAuthenticate.h"
#include "TVirtualMutex.h"
#include <string>
namespace std {} using namespace std;
#if defined(R__UNIX)
#include "TUnixSystem.h"
#elif defined(R__WIN32)
#include "TWinNTSystem.h"
#elif defined(R__VMS)
#include "TVmsSystem.h"
#endif
TVirtualMutex* gROOTMutex = 0;
static Int_t IVERSQ()
{
Int_t maj, min, cycle;
sscanf(ROOT_RELEASE, "%d.%d/%d", &maj, &min, &cycle);
return 10000*maj + 100*min + cycle;
}
static Int_t IDATQQ(const char *date)
{
static const char *months[] = {"Jan","Feb","Mar","Apr","May",
"Jun","Jul","Aug","Sep","Oct",
"Nov","Dec"};
char sm[12];
Int_t yy, mm=0, dd;
sscanf(date, "%s %d %d", sm, &dd, &yy);
for (int i = 0; i < 12; i++)
if (!strncmp(sm, months[i], 3)) {
mm = i+1;
break;
}
return 10000*yy + 100*mm + dd;
}
static Int_t ITIMQQ(const char *time)
{
Int_t hh, mm, ss;
sscanf(time, "%d:%d:%d", &hh, &mm, &ss);
return 100*hh + mm;
}
static void CleanUpROOTAtExit()
{
if (gROOT) {
R__LOCKGUARD(gROOTMutex);
if (gROOT->GetListOfFiles())
gROOT->GetListOfFiles()->Delete("slow");
if (gROOT->GetListOfSockets())
gROOT->GetListOfSockets()->Delete();
if (gROOT->GetListOfMappedFiles())
gROOT->GetListOfMappedFiles()->Delete("slow");
}
}
namespace ROOT {
#define R__USE_STD_MAP
class TMapTypeToTClass {
#if defined R__USE_STD_MAP
public:
#ifdef R__GLOBALSTL
typedef map<string,TClass*> IdMap_t;
#else
typedef std::map<std::string,TClass*> IdMap_t;
#endif
typedef IdMap_t::key_type key_type;
typedef IdMap_t::const_iterator const_iterator;
typedef IdMap_t::size_type size_type;
#ifdef R__WIN32
typedef TClass* mapped_type;
#else
typedef IdMap_t::mapped_type mapped_type;
#endif
private:
IdMap_t fMap;
public:
void Add(const key_type &key, mapped_type &obj) {
fMap[key] = obj;
}
mapped_type Find(const key_type &key) const {
IdMap_t::const_iterator iter = fMap.find(key);
mapped_type cl = 0;
if (iter != fMap.end()) cl = iter->second;
return cl;
}
void Remove(const key_type &key) { fMap.erase(key); }
#else
private:
TMap fMap;
public:
void Add(const char *key, TClass *&obj) {
TObjString *realkey = new TObjString(key);
fMap.Add(realkey, obj);
}
TClass* Find(const char *key) const {
const TPair *a = (const TPair *)fMap.FindObject(key);
if (a) return (TClass*) a->Value();
return 0;
}
void Remove(const char *key) {
TObjString realkey(key);
TObject *actual = fMap.Remove(&realkey);
delete actual;
}
#endif
};
}
Int_t TROOT::fgDirLevel = 0;
Bool_t TROOT::fgRootInit = kFALSE;
Bool_t TROOT::fgMemCheck = kFALSE;
VoidFuncPtr_t TROOT::fgMakeDefCanvas = 0;
namespace ROOT {
TROOT *GetROOT() {
static TROOT root("root", "The ROOT of EVERYTHING");
return &root;
}
TString &GetMacroPath() {
static TString macroPath;
return macroPath;
}
}
TROOT *gROOT = ROOT::GetROOT();
TRandom *gRandom;
Int_t gDebug;
extern "C" void R__SetZipMode(int mode);
ClassImp(TROOT)
TROOT::TROOT() : TDirectory()
{
}
TROOT::TROOT(const char *name, const char *title, VoidFuncPtr_t *initfunc)
: TDirectory()
{
if (fgRootInit) {
return;
}
#ifndef ROOTPREFIX
if (!getenv("ROOTSYS")) {
fprintf(stderr, "Fatal in <TROOT::TROOT>: ROOTSYS not set. Set it before trying to run.\n");
exit(1);
}
#endif
R__LOCKGUARD2(gROOTMutex);
gROOT = this;
gDirectory = 0;
SetName(name);
SetTitle(title);
TDirectory::Build();
fMappedFiles = 0;
fPluginManager = new TPluginManager;
InitSystem();
fVersionInt = 0;
fClasses = 0;
fInterpreter = new TCint("C/C++", "CINT C/C++ Interpreter");
fConfigOptions = R__CONFIGUREOPTIONS;
fVersion = ROOT_RELEASE;
fVersionInt = IVERSQ();
fVersionDate = IDATQQ(ROOT_RELEASE_DATE);
fVersionTime = ITIMQQ(ROOT_RELEASE_TIME);
fBuiltDate = IDATQQ(__DATE__);
fBuiltTime = ITIMQQ(__TIME__);
fClasses = new THashTable(800,3);
fIdMap = new IdMap_t;
fStreamerInfo = new TObjArray(100);
fClassGenerators = new TList;
fPluginManager->LoadHandlersFromEnv(gEnv);
#ifndef ROOTINCDIR
TString include = gSystem->Getenv("ROOTSYS");
include.Append("/include");
fInterpreter->AddIncludePath(include);
#else
fInterpreter->AddIncludePath(ROOTINCDIR);
#endif
TSystemDirectory *workdir = new TSystemDirectory("workdir",gSystem->WorkingDirectory());
fTimer = 0;
fApplication = 0;
fColors = new TObjArray(1000); fColors->SetName("ListOfColors");
fTypes = 0;
fGlobals = 0;
fGlobalFunctions = 0;
fList = new THashList(1000,3);
fFiles = new TList;
fMappedFiles = new TList;
fSockets = new TList;
fCanvases = new TList;
fStyles = new TList;
fFunctions = new TList;
fTasks = new TList;
fGeometries = new TList;
fBrowsers = new TList;
fSpecials = new TList;
fBrowsables = new TList;
fCleanups = new THashList;
fMessageHandlers = new TList;
fSecContexts = new TList;
fProofs = new TList;
fClipboard = new TList;
fDataSets = new TList;
TProcessID::AddProcessID();
fUUIDs = new TProcessUUID();
fRootFolder = new TFolder();
fRootFolder->SetName("root");
fRootFolder->SetTitle("root of all folders");
fRootFolder->AddFolder("Classes", "List of Active Classes",fClasses);
fRootFolder->AddFolder("Colors", "List of Active Colors",fColors);
fRootFolder->AddFolder("MapFiles", "List of MapFiles",fMappedFiles);
fRootFolder->AddFolder("Sockets", "List of Socket Connections",fSockets);
fRootFolder->AddFolder("Canvases", "List of Canvases",fCanvases);
fRootFolder->AddFolder("Styles", "List of Styles",fStyles);
fRootFolder->AddFolder("Functions", "List of Functions",fFunctions);
fRootFolder->AddFolder("Tasks", "List of Tasks",fTasks);
fRootFolder->AddFolder("Geometries","List of Geometries",fGeometries);
fRootFolder->AddFolder("Browsers", "List of Browsers",fBrowsers);
fRootFolder->AddFolder("Specials", "List of Special Objects",fSpecials);
fRootFolder->AddFolder("Handlers", "List of Message Handlers",fMessageHandlers);
fRootFolder->AddFolder("Cleanups", "List of RecursiveRemove Collections",fCleanups);
fRootFolder->AddFolder("StreamerInfo","List of Active StreamerInfo Classes",fStreamerInfo);
fRootFolder->AddFolder("SecContexts","List of Security Contexts",fSecContexts);
fRootFolder->AddFolder("PROOF Sessions", "List of PROOF sessions",fProofs);
fRootFolder->AddFolder("ROOT Memory","List of Objects in the gROOT Directory",fList);
fRootFolder->AddFolder("ROOT Files","List of Connected ROOT Files",fFiles);
fCleanups->Add(fCanvases); fCanvases->SetBit(kMustCleanup);
fCleanups->Add(fBrowsers); fBrowsers->SetBit(kMustCleanup);
fCleanups->Add(fTasks); fTasks->SetBit(kMustCleanup);
fCleanups->Add(fFiles); fFiles->SetBit(kMustCleanup);
fExecutingMacro= kFALSE;
fForceStyle = kFALSE;
fFromPopUp = kFALSE;
fReadingObject = kFALSE;
fInterrupt = kFALSE;
fEscape = kFALSE;
fMustClean = kTRUE;
fPrimitive = 0;
fSelectPad = 0;
fEditorMode = 0;
fDefCanvasName = "c1";
fEditHistograms= kFALSE;
fLineIsProcessing = 1;
gDirectory = this;
gPad = 0;
gRandom = new TRandom3;
fCutClassName = "TCutG";
new TMessageHandler((TClass*)0);
gStyle = 0;
TStyle::BuildStyles();
SetStyle("Default");
gBatchGuiFactory = new TGuiFactory;
gGuiFactory = gBatchGuiFactory;
gGXBatch = new TVirtualX("Batch", "ROOT Interface to batch graphics");
gVirtualX = gGXBatch;
#ifdef R__WIN32
fBatch = kFALSE;
#else
if (gSystem->Getenv("DISPLAY"))
fBatch = kFALSE;
else
fBatch = kTRUE;
#endif
int i = 0;
while (initfunc && initfunc[i]) {
(initfunc[i])();
fBatch = kFALSE;
i++;
}
InitThreads();
TQObject::LoadRQ_OBJECT();
fBrowsables->Add(fRootFolder, "root");
fBrowsables->Add(fProofs, "PROOF Sessions");
fBrowsables->Add(workdir, gSystem->WorkingDirectory());
fBrowsables->Add(fFiles, "ROOT Files");
atexit(CleanUpROOTAtExit);
fgRootInit = kTRUE;
}
TROOT::~TROOT()
{
if (gROOT == this) {
gGlobalMutex = 0;
if (!fVersionInt) return;
fFiles->Delete("slow"); SafeDelete(fFiles);
fSecContexts->Delete("slow"); SafeDelete(fSecContexts);
fSockets->Delete(); SafeDelete(fSockets);
fMappedFiles->Delete("slow");
delete fUUIDs;
TProcessID::Cleanup();
TSeqCollection *tl = fMappedFiles; fMappedFiles = 0; delete tl;
gSystem->CleanCompiledMacros();
delete gSystem;
SafeDelete(fInterpreter);
TStorage::PrintStatistics();
gROOT = 0;
fgRootInit = kFALSE;
}
}
void TROOT::AddClass(TClass *cl)
{
if (!cl) return;
GetListOfClasses()->Add(cl);
if (cl->GetTypeInfo()) {
fIdMap->Add(cl->GetTypeInfo()->name(),cl);
}
}
void TROOT::AddClassGenerator(TClassGenerator *generator)
{
if (!generator) return;
fClassGenerators->Add(generator);
}
void TROOT::Browse(TBrowser *b)
{
TObject *obj;
TIter next(fBrowsables);
while ((obj = (TObject *) next())) {
const char *opt = next.GetOption();
if (opt && strlen(opt))
b->Add(obj, opt);
else
b->Add(obj, obj->GetName());
}
}
Bool_t TROOT::ClassSaved(TClass *cl)
{
if (cl == 0) return kFALSE;
if (cl->TestBit(TClass::kClassSaved)) return kTRUE;
cl->SetBit(TClass::kClassSaved);
return kFALSE;
}
TObject *TROOT::FindObject(const TObject *) const
{
Error("FindObject","Not yet implemented");
return 0;
}
TObject *TROOT::FindObject(const char *name) const
{
if (name && strstr(name,"/")) return FindObjectAny(name);
TObject *temp = 0;
temp = fFiles->FindObject(name); if (temp) return temp;
temp = fMappedFiles->FindObject(name); if (temp) return temp;
temp = fFunctions->FindObject(name); if (temp) return temp;
temp = fGeometries->FindObject(name); if (temp) return temp;
temp = fCanvases->FindObject(name); if (temp) return temp;
temp = fStyles->FindObject(name); if (temp) return temp;
temp = fSpecials->FindObject(name); if (temp) return temp;
TIter next(fGeometries);
TObject *obj;
while ((obj=next())) {
temp = obj->FindObject(name); if (temp) return temp;
}
if (gDirectory) temp = gDirectory->Get(name); if (temp) return temp;
if (gPad) {
TVirtualPad *canvas = gPad->GetVirtCanvas();
if (fCanvases->FindObject(canvas)) {
temp = canvas->FindObject(name);
if (!temp && canvas != gPad) temp = gPad->FindObject(name);
}
}
return temp;
}
TObject *TROOT::FindSpecialObject(const char *name, void *&where)
{
TObject *temp = 0;
where = 0;
if (!temp && !strcmp(name, "gPad")) {
temp = gPad;
if (gPad) {
TVirtualPad *canvas = gPad->GetVirtCanvas();
if (fCanvases->FindObject(canvas))
where = canvas;
}
}
if (!temp && !strcmp(name, "gVirtualX")) {
return gVirtualX;
}
if (!temp && !strcmp(name, "gInterpreter")) {
return gInterpreter;
}
if (!temp) {
temp = fFiles->FindObject(name);
where = fFiles;
}
if (!temp) {
temp = fMappedFiles->FindObject(name);
where = fMappedFiles;
}
if (!temp) {
temp = fFunctions->FindObject(name);
where = fFunctions;
}
if (!temp) {
temp = fCanvases->FindObject(name);
where = fCanvases;
}
if (!temp) {
temp = fStyles->FindObject(name);
where = fStyles;
}
if (!temp) {
temp = fSpecials->FindObject(name);
where = fSpecials;
}
if (!temp) {
TObject *glast = fGeometries->Last();
if (glast) {where = glast; temp = glast->FindObject(name);}
}
if (!temp && gDirectory) {
temp = gDirectory->Get(name);
where = gDirectory;
}
if (!temp && gPad) {
TVirtualPad *canvas = gPad->GetVirtCanvas();
if (fCanvases->FindObject(canvas)) {
temp = canvas->FindObject(name);
where = canvas;
if (!temp && canvas != gPad) {
temp = gPad->FindObject(name);
where = gPad;
}
}
}
if (!temp) return 0;
if (temp->TestBit(kNotDeleted)) return temp;
return 0;
}
TObject *TROOT::FindObjectAny(const char *name) const
{
TObject *obj = fRootFolder->FindObjectAny(name);
if (obj) return obj;
TFile *f;
TIter next(fFiles);
while ((f = (TFile*)next())) {
obj = f->GetList()->FindObject(name);
if (obj) return obj;
}
return 0;
}
const char *TROOT::FindObjectClassName(const char *name) const
{
TObject *obj = FindObject(name);
if (obj) return obj->ClassName();
TGlobal *g = GetGlobal(name);
if (g) return g->GetTypeName();
return 0;
}
const char *TROOT::FindObjectPathName(const TObject *) const
{
Error("FindObjectPathName","Not yet implemented");
return "??";
}
TClass *TROOT::FindSTLClass(const char *name, Bool_t load) const
{
TClass *cl = 0;
string defaultname( TClassEdit::ShortType( name, TClassEdit::kDropStlDefault )) ;
if (defaultname != name) {
cl = (TClass*)gROOT->GetListOfClasses()->FindObject(defaultname.c_str());
if (load && !cl) cl = gROOT->LoadClass(defaultname.c_str());
}
if (cl==0) {
TDataType *objType = gROOT->GetType(name, load);
if (objType) {
const char *typedfName = objType->GetTypeName();
string defaultTypedefName( TClassEdit::ShortType( typedfName, TClassEdit::kDropStlDefault ) );
if (typedfName && strcmp(typedfName, name) && defaultTypedefName==name) {
cl = (TClass*)gROOT->GetListOfClasses()->FindObject(typedfName);
if (load && !cl) cl = gROOT->LoadClass(typedfName);
}
}
}
if (cl==0) {
const char *altname = gInterpreter->GetInterpreterTypeName(name);
if (altname && strcmp(altname,name)!=0) {
cl = gROOT->GetClass(altname,load);
}
}
if (cl==0) {
string long64name = TClassEdit::GetLong64_Name( name );
if ( long64name != name ) return FindSTLClass( long64name.c_str(), load);
}
if (cl == 0) {
TString resolvedName = TClassEdit::ResolveTypedef(name,kFALSE).c_str();
if (resolvedName != name) cl = GetClass(resolvedName,load);
}
if (cl == 0 && (strncmp(name,"std::",5)==0)) {
if (strlen(name+5)) cl = GetClass(name+5,load);
}
if (load && cl==0) {
cl = new TClass(name, GetClass("TStreamerInfo")->GetClassVersion(), 0, 0, -1, -1 );
cl->SetBit(TClass::kIsEmulation);
}
return cl;
}
TClass *TROOT::GetClass(const char *name, Bool_t load) const
{
if (!name || !strlen(name)) return 0;
if (!GetListOfClasses()) return 0;
TString resolvedName;
TClass *cl = (TClass*)GetListOfClasses()->FindObject(name);
if (!cl) {
resolvedName = TClassEdit::ResolveTypedef(name,kTRUE).c_str();
cl = (TClass*)GetListOfClasses()->FindObject(resolvedName);
}
if (cl) {
if (cl->IsLoaded()) return cl;
load = kTRUE;
if (TClassEdit::IsSTLCont(name)) {
const char *altname = gInterpreter->GetInterpreterTypeName(name);
if (altname && strcmp(altname,name)!=0) {
GetListOfClasses()->Remove(cl);
TClass *newcl = GetClass(altname,load);
assert(newcl!=cl);
cl->ReplaceWith(newcl);
delete cl;
return newcl;
}
}
} else {
if (!TClassEdit::IsSTLCont(name)) {
TDataType *objType = GetType(name, load);
if (objType) {
const char *typdfName = objType->GetTypeName();
if (typdfName && strcmp(typdfName, name)) {
cl = GetClass(typdfName, load);
return cl;
}
}
} else {
cl = FindSTLClass(name,kFALSE);
if (cl) {
if (cl->IsLoaded()) return cl;
return gROOT->GetClass(cl->GetName(),kTRUE);
}
}
}
if (!load) return 0;
TClass *loadedcl = 0;
if (cl) loadedcl = LoadClass(cl->GetName());
else loadedcl = LoadClass(name);
if (loadedcl) return loadedcl;
if (cl) return cl;
static const char *full_string_name = "basic_string<char,char_traits<char>,allocator<char> >";
if (strcmp(name,full_string_name)==0
|| ( strncmp(name,"std::",5)==0 && ((strcmp(name+5,"string")==0)||(strcmp(name+5,full_string_name)==0)))) {
return gROOT->GetClass("string");
}
if (TClassEdit::IsSTLCont(name)) {
return FindSTLClass(name,kTRUE);
} else if ( strncmp(name,"std::",5)==0 ) {
return GetClass(name+5,load);
} else if ( strstr(name,"std::") != 0 ) {
TString rname( TClassEdit::ResolveTypedef(name,kTRUE) );
if (rname != name) {
return GetClass( rname, load );
}
}
if (!strcmp(name, "long long")||!strcmp(name,"unsigned long long"))
return 0;
char *modifiable_name = new char[strlen(name)*2];
strcpy(modifiable_name,name);
if (gInterpreter->CheckClassInfo(modifiable_name)) {
const char *altname = gInterpreter->GetInterpreterTypeName(modifiable_name,kTRUE);
if (strcmp(altname,name)!=0) {
delete [] modifiable_name;
return GetClass(altname,load);
}
TClass *ncl = new TClass(name, 1, 0, 0, -1, -1);
if (!ncl->IsZombie()) {
delete [] modifiable_name;
return ncl;
}
delete ncl;
}
delete [] modifiable_name;
return 0;
}
TClass *TROOT::GetClass(const type_info& typeinfo, Bool_t load) const
{
if (!GetListOfClasses()) return 0;
TClass* cl = fIdMap->Find(typeinfo.name());
if (cl) {
if (cl->IsLoaded()) return cl;
load = kTRUE;
} else {
}
if (!load) return 0;
VoidFuncPtr_t dict = TClassTable::GetDict(typeinfo);
if (dict) {
(dict)();
TClass *cl = GetClass(typeinfo);
if (cl) cl->PostLoadCheck();
return cl;
}
if (cl) return cl;
TIter next(fClassGenerators);
TClassGenerator *gen;
while( (gen = (TClassGenerator*) next()) ) {
cl = gen->GetClass(typeinfo,load);
if (cl) {
cl->PostLoadCheck();
return cl;
}
}
return 0;
}
TColor *TROOT::GetColor(Int_t color) const
{
TObjArray *lcolors = (TObjArray*) GetListOfColors();
if (color < 0 || color >= lcolors->GetSize()) return 0;
TColor *col = (TColor*)lcolors->At(color);
if (col && col->GetNumber() == color) return col;
TIter next(lcolors);
while ((col = (TColor *) next()))
if (col->GetNumber() == color) return col;
return 0;
}
VoidFuncPtr_t TROOT::GetMakeDefCanvas() const
{
return fgMakeDefCanvas;
}
TDataType *TROOT::GetType(const char *name, Bool_t load) const
{
const char *tname = name + strspn(name," ");
if (!strncmp(tname,"virtual",7)) {
tname += 7; tname += strspn(tname," ");
}
if (!strncmp(tname,"const",5)) {
tname += 5; tname += strspn(tname," ");
}
size_t nch = strlen(tname);
while (tname[nch-1] == ' ') nch--;
TDataType* type = (TDataType*)gROOT->GetListOfTypes(kFALSE)->FindObject(name);
if (type || !load)
return type;
else
return (TDataType*)gROOT->GetListOfTypes(load)->FindObject(name);
}
TFile *TROOT::GetFile(const char *name) const
{
return (TFile*)GetListOfFiles()->FindObject(name);
}
TStyle *TROOT::GetStyle(const char *name) const
{
return (TStyle*)GetListOfStyles()->FindObject(name);
}
TObject *TROOT::GetFunction(const char *name) const
{
TObject *f1 = fFunctions->FindObject(name);
if (f1) return f1;
gROOT->ProcessLine("TF1::InitStandardFunctions()");
return fFunctions->FindObject(name);
}
TGlobal *TROOT::GetGlobal(const char *name, Bool_t load) const
{
return (TGlobal *)gROOT->GetListOfGlobals(load)->FindObject(name);
}
TGlobal *TROOT::GetGlobal(const TObject *addr, Bool_t load) const
{
TIter next(gROOT->GetListOfGlobals(load));
TGlobal *g;
while ((g = (TGlobal*) next())) {
const char *t = g->GetFullTypeName();
if (!strncmp(t, "class", 5) || !strncmp(t, "struct", 6)) {
int ptr = 0;
if (t[strlen(t)-1] == '*') ptr = 1;
if (ptr) {
if (*(Long_t *)g->GetAddress() == (Long_t)addr) return g;
} else {
if ((Long_t)g->GetAddress() == (Long_t)addr) return g;
}
}
}
return 0;
}
TFunction *TROOT::GetGlobalFunction(const char *function, const char *params,
Bool_t load)
{
if (!params)
return (TFunction *)GetListOfGlobalFunctions(load)->FindObject(function);
else {
if (!fInterpreter)
Fatal("GetGlobalFunction", "fInterpreter not initialized");
TFunction *f;
TIter next(GetListOfGlobalFunctions(load));
TString mangled = gInterpreter->GetMangledName(0, function, params);
while ((f = (TFunction *) next())) {
if (mangled == f->GetMangledName()) return f;
}
return 0;
}
}
TFunction *TROOT::GetGlobalFunctionWithPrototype(const char *function,
const char *proto, Bool_t load)
{
if (!proto)
return (TFunction *)GetListOfGlobalFunctions(load)->FindObject(function);
else {
if (!fInterpreter)
Fatal("GetGlobalFunctionWithPrototype", "fInterpreter not initialized");
TFunction *f;
TIter next(GetListOfGlobalFunctions(load));
TString mangled = gInterpreter->GetMangledNameWithPrototype(0,
function,
proto);
while ((f = (TFunction *) next())) {
if (mangled == f->GetMangledName()) return f;
}
return 0;
}
}
TObject *TROOT::GetGeometry(const char *name) const
{
return GetListOfGeometries()->FindObject(name);
}
TCollection *TROOT::GetListOfGlobals(Bool_t load)
{
if (!fGlobals) {
fGlobals = new THashTable(100, 3);
load = kTRUE;
}
if (!fInterpreter)
Fatal("GetListOfGlobals", "fInterpreter not initialized");
if (load)
gInterpreter->UpdateListOfGlobals();
return fGlobals;
}
TCollection *TROOT::GetListOfGlobalFunctions(Bool_t load)
{
if (!fGlobalFunctions) {
fGlobalFunctions = new THashTable(100, 3);
load = kTRUE;
}
if (!fInterpreter)
Fatal("GetListOfGlobalFunctions", "fInterpreter not initialized");
if (load)
gInterpreter->UpdateListOfGlobalFunctions();
return fGlobalFunctions;
}
TCollection *TROOT::GetListOfTypes(Bool_t load)
{
if (!fTypes) {
fTypes = new THashTable(100, 3);
load = kTRUE;
fTypes->Add(new TDataType("char"));
fTypes->Add(new TDataType("unsigned char"));
fTypes->Add(new TDataType("short"));
fTypes->Add(new TDataType("unsigned short"));
fTypes->Add(new TDataType("int"));
fTypes->Add(new TDataType("unsigned int"));
fTypes->Add(new TDataType("unsigned"));
fTypes->Add(new TDataType("long"));
fTypes->Add(new TDataType("unsigned long"));
fTypes->Add(new TDataType("long long"));
fTypes->Add(new TDataType("unsigned long long"));
fTypes->Add(new TDataType("float"));
fTypes->Add(new TDataType("double"));
fTypes->Add(new TDataType("void"));
fTypes->Add(new TDataType("bool"));
fTypes->Add(new TDataType("char*"));
}
if (!fInterpreter)
Fatal("GetListOfTypes", "fInterpreter not initialized");
if (load)
gInterpreter->UpdateListOfTypes();
return fTypes;
}
void TROOT::Idle(UInt_t idleTimeInSec, const char *command)
{
if (!fApplication)
TApplication::CreateApplication();
if (idleTimeInSec <= 0)
fApplication->RemoveIdleTimer();
else
fApplication->SetIdleTimer(idleTimeInSec, command);
}
Int_t TROOT::IgnoreInclude(const char *fname, const char * )
{
Int_t result = 0;
if ( fname == 0 ) return result;
TString className(fname);
Int_t where = className.Last('.');
if (where != kNPOS) className.Remove( where );
className = gSystem->BaseName(className);
TClass *cla = GetClass(className);
if ( cla ) {
if (cla->GetDeclFileLine() < 0) return 0;
const char *decfile = gSystem->BaseName(cla->GetDeclFileName());
if(!decfile) return 0;
result = strcmp( decfile,fname ) == 0;
}
return result;
}
void TROOT::InitSystem()
{
if (gSystem == 0) {
#if defined(R__UNIX)
gSystem = new TUnixSystem;
#elif defined(R__WIN32)
gSystem = new TWinNTSystem;
#elif defined(R__VMS)
gSystem = new TVmsSystem;
#else
gSystem = new TSystem;
#endif
if (gSystem->Init())
fprintf(stderr, "Fatal in <TROOT::InitSystem>: can't init operating system layer\n");
if (!gSystem->HomeDirectory())
fprintf(stderr, "Fatal in <TROOT::InitSystem>: HOME directory not set\n");
gEnv = new TEnv(".rootrc");
gDebug = gEnv->GetValue("Root.Debug", 0);
Int_t zipmode = gEnv->GetValue("Root.ZipMode",1);
R__SetZipMode(zipmode);
const char *sdeb;
if ((sdeb = gSystem->Getenv("ROOTDEBUG")))
gDebug = atoi(sdeb);
if (gDebug > 0 && isatty(2))
fprintf(stderr, "Info in <TROOT::InitSystem>: running with gDebug = %d\n", gDebug);
if (gEnv->GetValue("Root.MemStat", 0))
TStorage::EnableStatistics();
int msize = gEnv->GetValue("Root.MemStat.size", -1);
int mcnt = gEnv->GetValue("Root.MemStat.cnt", -1);
if (msize != -1 || mcnt != -1)
TStorage::EnableStatistics(msize, mcnt);
fgMemCheck = gEnv->GetValue("Root.MemCheck", 0);
TObject::SetObjectStat(gEnv->GetValue("Root.ObjectStat", 0));
}
}
void TROOT::InitThreads()
{
if (gEnv->GetValue("Root.UseThreads", 0)) {
char *path;
if ((path = gSystem->DynamicPathName("libThread", kTRUE))) {
delete [] path;
LoadClass("TThread", "Thread");
}
}
}
TClass *TROOT::LoadClass(const char *classname) const
{
VoidFuncPtr_t dict = TClassTable::GetDict(classname);
if (!dict) {
if (gInterpreter->AutoLoad(classname)) {
dict = TClassTable::GetDict(classname);
}
}
if (!dict) {
string long64name = TClassEdit::GetLong64_Name(classname);
if (long64name != classname) {
TClass *res = LoadClass(long64name.c_str());
if (res) return res;
}
}
if (!dict) {
string resolved = TClassEdit::ResolveTypedef(classname,kTRUE);
if (resolved != classname) {
dict = TClassTable::GetDict(resolved.c_str());
}
}
if (dict) {
TString clname(classname);
(dict)();
TClass *ncl = GetClass(clname, kFALSE);
if (ncl) ncl->PostLoadCheck();
return ncl;
}
TIter next(fClassGenerators);
TClassGenerator *gen;
while ((gen = (TClassGenerator*) next())) {
TClass *cl = gen->GetClass(classname, kTRUE);
if (cl) {
cl->PostLoadCheck();
return cl;
}
}
return 0;
}
Int_t TROOT::LoadClass(const char *classname, const char *libname,
Bool_t check)
{
if (TClassTable::GetDict(classname)) return 0;
Int_t err = -1;
char *path;
char *lib = 0;
if (strncmp(libname, "lib", 3))
lib = Form("lib%s", libname);
if (lib && (path = gSystem->DynamicPathName(lib, kTRUE))) {
if (check)
err = 0;
else
err = gSystem->Load(path, 0, kTRUE);
delete [] path;
} else if ((path = gSystem->DynamicPathName(libname, kTRUE))) {
if (check)
err = 0;
else
err = gSystem->Load(path, 0, kTRUE);
delete [] path;
} else {
if (check) {
if (!gSystem->AccessPathName(libname, kReadPermission))
err = 0;
else
err = -1;
} else
err = gSystem->Load(libname, 0, kTRUE);
}
if (err == 0 && !check)
GetListOfTypes(kTRUE);
if (err == -1)
;
if (err == 1) {
err = 0;
}
return err;
}
void TROOT::ls(Option_t *option) const
{
TDirectory::ls(option);
}
Int_t TROOT::LoadMacro(const char *filename, int *error, Bool_t check)
{
Int_t err = -1;
Int_t lerr, *terr;
if (error)
terr = error;
else
terr = &lerr;
if (fInterpreter) {
TString aclicMode;
TString arguments;
TString io;
TString fname = gSystem->SplitAclicMode(filename, aclicMode, arguments, io);
if (arguments.Length()) {
Warning("LoadMacro", "argument(s) \"%s\" ignored", arguments.Data(), GetMacroPath());
}
char *mac = gSystem->Which(GetMacroPath(), fname, kReadPermission);
if (!mac) {
if (!check)
Error("LoadMacro", "macro %s not found in path %s", fname.Data(), GetMacroPath());
*terr = TInterpreter::kFatal;
} else {
err = 0;
if (!check) {
fname = mac;
fname += aclicMode;
fname += io;
gInterpreter->LoadMacro(fname.Data(), (TInterpreter::EErrorCode*)terr);
if (*terr)
err = -1;
}
}
delete [] mac;
}
return err;
}
Long_t TROOT::Macro(const char *filename, Int_t *error)
{
Long_t result = 0;
if (fInterpreter) {
TString aclicMode;
TString arguments;
TString io;
TString fname = gSystem->SplitAclicMode(filename, aclicMode, arguments, io);
char *mac = gSystem->Which(GetMacroPath(), fname, kReadPermission);
if (!mac) {
Error("Macro", "macro %s not found in path %s", fname.Data(), GetMacroPath());
if (error)
*error = TInterpreter::kFatal;
} else {
fname = mac;
fname += aclicMode;
fname += arguments;
fname += io;
result = gInterpreter->ExecuteMacro(fname, (TInterpreter::EErrorCode*)error);
}
delete [] mac;
if (gPad) gPad->Update();
}
return result;
}
void TROOT::Message(Int_t id, const TObject *obj)
{
TIter next(fMessageHandlers);
TMessageHandler *mh;
while ((mh = (TMessageHandler*)next())) {
mh->HandleMessage(id,obj);
}
}
void TROOT::ProcessLine(const char *line, Int_t *error)
{
if (!fApplication) {
char *sline = StrDup(line);
TApplication::CreateApplication();
line = Form("%s", sline);
delete [] sline;
}
fApplication->ProcessLine(line, kFALSE, error);
}
void TROOT::ProcessLineSync(const char *line, Int_t *error)
{
if (!fApplication) {
char *sline = StrDup(line);
TApplication::CreateApplication();
line = Form("%s", sline);
delete [] sline;
}
fApplication->ProcessLine(line, kTRUE, error);
}
Long_t TROOT::ProcessLineFast(const char *line, Int_t *error)
{
if (!fApplication) {
char *sline = StrDup(line);
TApplication::CreateApplication();
line = Form("%s", sline);
delete [] sline;
}
Long_t result = 0;
if (fInterpreter) {
TInterpreter::EErrorCode *code = ( TInterpreter::EErrorCode*)error;
result = gInterpreter->Calc(line, code);
}
return result;
}
void TROOT::RefreshBrowsers()
{
TIter next(GetListOfBrowsers());
TBrowser *b;
while ((b = (TBrowser*) next()))
b->SetRefreshFlag(kTRUE);
}
void TROOT::RemoveClass(TClass *oldcl)
{
if (!oldcl) return;
GetListOfClasses()->Remove(oldcl);
if (oldcl->GetTypeInfo()) {
fIdMap->Remove(oldcl->GetTypeInfo()->name());
}
}
void TROOT::Reset(Option_t *option)
{
if (IsExecutingMacro()) return;
if (fInterpreter) {
if (!strncmp(option, "a", 1)) {
fInterpreter->Reset();
fInterpreter->SaveContext();
} else
gInterpreter->ResetGlobals();
if (fGlobals) fGlobals->Delete();
if (fGlobalFunctions) fGlobalFunctions->Delete();
SaveContext();
}
}
void TROOT::SaveContext()
{
if (fInterpreter)
gInterpreter->SaveGlobalsContext();
}
void TROOT::SetCutClassName(const char *name)
{
if (!name) {
Error("SetCutClassName","Invalid class name");
return;
}
TClass *cl = GetClass(name);
if (!cl) {
Error("SetCutClassName","Unknown class:%s",name);
return;
}
if (!cl->InheritsFrom("TCutG")) {
Error("SetCutClassName","Class:%s does not derive from TCutG",name);
return;
}
fCutClassName = name;
}
void TROOT::SetEditorMode(const char *mode)
{
fEditorMode = 0;
if (strlen(mode) == 0) return;
if (!strcmp(mode,"Arc")) {fEditorMode = kArc; return;}
if (!strcmp(mode,"Line")) {fEditorMode = kLine; return;}
if (!strcmp(mode,"Arrow")) {fEditorMode = kArrow; return;}
if (!strcmp(mode,"Button")) {fEditorMode = kButton; return;}
if (!strcmp(mode,"Diamond")) {fEditorMode = kDiamond; return;}
if (!strcmp(mode,"Ellipse")) {fEditorMode = kEllipse; return;}
if (!strcmp(mode,"Pad")) {fEditorMode = kPad; return;}
if (!strcmp(mode,"Pave")) {fEditorMode = kPave; return;}
if (!strcmp(mode,"PaveLabel")){fEditorMode = kPaveLabel; return;}
if (!strcmp(mode,"PaveText")) {fEditorMode = kPaveText; return;}
if (!strcmp(mode,"PavesText")){fEditorMode = kPavesText; return;}
if (!strcmp(mode,"PolyLine")) {fEditorMode = kPolyLine; return;}
if (!strcmp(mode,"CurlyLine")){fEditorMode = kCurlyLine; return;}
if (!strcmp(mode,"CurlyArc")) {fEditorMode = kCurlyArc; return;}
if (!strcmp(mode,"Text")) {fEditorMode = kText; return;}
if (!strcmp(mode,"Marker")) {fEditorMode = kMarker; return;}
if (!strcmp(mode,"CutG")) {fEditorMode = kCutG; return;}
}
void TROOT::SetStyle(const char *stylename)
{
TStyle *style = GetStyle(stylename);
if (style) style->cd();
else Error("SetStyle","Unknown style:%s",stylename);
}
Int_t TROOT::DecreaseDirLevel()
{
return --fgDirLevel;
}
Int_t TROOT::GetDirLevel()
{
return fgDirLevel;
}
const char *TROOT::GetMacroPath()
{
TString ¯oPath = ROOT::GetMacroPath();
if (macroPath.Length() == 0) {
macroPath = gEnv->GetValue("Root.MacroPath", (char*)0);
#if defined(R__WIN32)
macroPath.ReplaceAll(" ", ";");
#else
macroPath.ReplaceAll(" ", ":");
#endif
if (macroPath.Length() == 0)
#if !defined (R__VMS) && !defined(R__WIN32)
#ifdef ROOTMACRODIR
macroPath = ".:" ROOTMACRODIR;
#else
macroPath = TString(".:") + gRootDir + "/macros";
#endif
#elif !defined(__VMS)
#ifdef ROOTMACRODIR
macroPath = ".;" ROOTMACRODIR;
#else
macroPath = TString(".;") + gRootDir + "/macros";
#endif
#else
macroPath = TString(gRootDir) + "MACROS]";
#endif
}
return macroPath;
}
void TROOT::SetMacroPath(const char *newpath)
{
TString ¯oPath = ROOT::GetMacroPath();
if (!newpath || !*newpath)
macroPath = "";
else
macroPath = newpath;
}
Int_t TROOT::IncreaseDirLevel()
{
return ++fgDirLevel;
}
void TROOT::IndentLevel()
{
for (int i = 0; i < fgDirLevel; i++) cout.put(' ');
}
Bool_t TROOT::Initialized()
{
return fgRootInit;
}
Bool_t TROOT::MemCheck()
{
return fgMemCheck;
}
void TROOT::SetDirLevel(Int_t level)
{
fgDirLevel = level;
}
void TROOT::SetMakeDefCanvas(VoidFuncPtr_t makecanvas)
{
fgMakeDefCanvas = makecanvas;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.