#include "RConfig.h"
#include "RConfigure.h"
#include "RConfigOptions.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 "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 "TInterpreter.h"
#include "TGuiFactory.h"
#include "TMessageHandler.h"
#include "TFolder.h"
#include "TQObject.h"
#include "TProcessUUID.h"
#include "TPluginManager.h"
#include "TMap.h"
#include "TObjString.h"
#include "TVirtualMutex.h"
#ifdef R__HAS_CLING
# include "TCling.h"
#else
# include "TCint.h"
#endif
#include <string>
namespace std {} using namespace std;
#if defined(R__UNIX)
#include "TUnixSystem.h"
#elif defined(R__WIN32)
#include "TWinNTSystem.h"
#endif
extern "C" void R__SetZipMode(int);
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");
if (gROOT->GetListOfClosedObjects())
gROOT->GetListOfClosedObjects()->Delete("slow");
}
}
Int_t TROOT::fgDirLevel = 0;
Bool_t TROOT::fgRootInit = kFALSE;
Bool_t TROOT::fgMemCheck = kFALSE;
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();
Int_t gDebug;
ClassImp(TROOT)
TROOT::TROOT() : TDirectory(),
fLineIsProcessing(0), fVersion(0), fVersionInt(0), fVersionCode(0),
fVersionDate(0), fVersionTime(0), fBuiltDate(0), fBuiltTime(0), fSvnRevision(0),
fTimer(0), fApplication(0), fInterpreter(0), fBatch(kTRUE), fEditHistograms(kTRUE),
fFromPopUp(kTRUE),fMustClean(kTRUE),fReadingObject(kFALSE),fForceStyle(kFALSE),
fInterrupt(kFALSE),fEscape(kFALSE),fExecutingMacro(kFALSE),fEditorMode(0),
fPrimitive(0),fSelectPad(0),fClasses(0),fTypes(0),fGlobals(0),fGlobalFunctions(0),
fClosedObjects(0),fFiles(0),fMappedFiles(0),fSockets(0),fCanvases(0),fStyles(0),fFunctions(0),
fTasks(0),fColors(0),fGeometries(0),fBrowsers(0),fSpecials(0),fCleanups(0),
fMessageHandlers(0),fStreamerInfo(0),fClassGenerators(0),fSecContexts(0),
fProofs(0),fClipboard(0),fDataSets(0),fUUIDs(0),fRootFolder(0),fBrowsables(0),
fPluginManager(0)
{
}
TROOT::TROOT(const char *name, const char *title, VoidFuncPtr_t *initfunc)
: TDirectory(), fLineIsProcessing(0), fVersion(0), fVersionInt(0), fVersionCode(0),
fVersionDate(0), fVersionTime(0), fBuiltDate(0), fBuiltTime(0), fSvnRevision(0),
fTimer(0), fApplication(0), fInterpreter(0), fBatch(kTRUE), fEditHistograms(kTRUE),
fFromPopUp(kTRUE),fMustClean(kTRUE),fReadingObject(kFALSE),fForceStyle(kFALSE),
fInterrupt(kFALSE),fEscape(kFALSE),fExecutingMacro(kFALSE),fEditorMode(0),
fPrimitive(0),fSelectPad(0),fClasses(0),fTypes(0),fGlobals(0),fGlobalFunctions(0),
fClosedObjects(0),fFiles(0),fMappedFiles(0),fSockets(0),fCanvases(0),fStyles(0),fFunctions(0),
fTasks(0),fColors(0),fGeometries(0),fBrowsers(0),fSpecials(0),fCleanups(0),
fMessageHandlers(0),fStreamerInfo(0),fClassGenerators(0),fSecContexts(0),
fProofs(0),fClipboard(0),fDataSets(0),fUUIDs(0),fRootFolder(0),fBrowsables(0),
fPluginManager(0)
{
if (fgRootInit) {
return;
}
R__LOCKGUARD2(gROOTMutex);
gROOT = this;
gDirectory = 0;
SetName(name);
SetTitle(title);
TDirectory::Build();
fMappedFiles = 0;
gPluginMgr = fPluginManager = new TPluginManager;
InitSystem();
#ifndef ROOTPREFIX
if (!gSystem->Getenv("ROOTSYS")) {
fprintf(stderr, "Fatal in <TROOT::TROOT>: ROOTSYS not set. Set it before trying to run.\n");
exit(1);
}
#endif
fVersionInt = 0;
fClasses = 0;
fInterpreter = new TCint("C/C++", "CINT C/C++ Interpreter");
fConfigOptions = R__CONFIGUREOPTIONS;
fConfigFeatures = R__CONFIGUREFEATURES;
fVersion = ROOT_RELEASE;
fVersionCode = ROOT_VERSION_CODE;
fVersionInt = IVERSQ();
fVersionDate = IDATQQ(ROOT_RELEASE_DATE);
fVersionTime = ITIMQQ(ROOT_RELEASE_TIME);
fBuiltDate = IDATQQ(__DATE__);
fBuiltTime = ITIMQQ(__TIME__);
ReadSvnInfo();
fClasses = new THashTable(800,3);
fStreamerInfo = new TObjArray(100);
fClassGenerators = new TList;
fPluginManager->LoadHandlersFromEnv(gEnv);
#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) {
TEnv plugins(".plugins-ios");
fPluginManager->LoadHandlersFromEnv(&plugins);
}
#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;
delete fList;
fList = new THashList(1000,3);
fClosedObjects = new TList; fClosedObjects->SetName("ClosedFiles");
fFiles = new TList; fFiles->SetName("Files");
fMappedFiles = new TList; fMappedFiles->SetName("MappedFiles");
fSockets = new TList; fSockets->SetName("Sockets");
fCanvases = new TList; fCanvases->SetName("Canvases");
fStyles = new TList; fStyles->SetName("Styles");
fFunctions = new TList; fFunctions->SetName("Functions");
fTasks = new TList; fTasks->SetName("Tasks");
fGeometries = new TList; fGeometries->SetName("Geometries");
fBrowsers = new TList; fBrowsers->SetName("Browsers");
fSpecials = new TList; fSpecials->SetName("Specials");
fBrowsables = new TList; fBrowsables->SetName("Browsables");
fCleanups = new THashList; fCleanups->SetName("Cleanups");
fMessageHandlers = new TList; fMessageHandlers->SetName("MessageHandlers");
fSecContexts = new TList; fSecContexts->SetName("SecContexts");
fProofs = new TList; fProofs->SetName("Proofs");
fClipboard = new TList; fClipboard->SetName("Clipboard");
fDataSets = new TList; fDataSets->SetName("DataSets");
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);
fCleanups->Add(fClosedObjects); fClosedObjects->SetBit(kMustCleanup);
fCleanups->Add(fInterpreter); fInterpreter->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;
fCutClassName = "TCutG";
new TMessageHandler((TClass*)0);
gStyle = 0;
TStyle::BuildStyles();
SetStyle(gEnv->GetValue("Canvas.Style", "Modern"));
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;
TClass::ReadRules();
}
TROOT::~TROOT()
{
if (gROOT == this) {
SetBit(TObject::kInvalidObject);
gGlobalMutex = 0;
if (!fVersionInt) return;
#ifdef R__COMPLETE_MEM_TERMINATION
SafeDelete(fBrowsables);
SafeDelete(fRootFolder);
fSpecials->Delete(); SafeDelete(fSpecials);
#endif
fClosedObjects->Delete("slow");
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;
SafeDelete(fClosedObjects);
fFunctions->Delete(); SafeDelete(fFunctions);
fColors->Delete(); SafeDelete(fColors);
fStyles->Delete(); SafeDelete(fStyles);
fGeometries->Delete(); SafeDelete(fGeometries);
fBrowsers->Delete(); SafeDelete(fBrowsers);
#ifdef R__COMPLETE_MEM_TERMINATION
if (gGuiFactory != gBatchGuiFactory) SafeDelete(gGuiFactory);
SafeDelete(gBatchGuiFactory);
if (gGXBatch != gVirtualX) SafeDelete(gGXBatch);
SafeDelete(gVirtualX);
#endif
TQObject::BlockAllSignals(kTRUE);
fMessageHandlers->Delete(); SafeDelete(fMessageHandlers);
#ifdef R__COMPLETE_MEM_TERMINATION
SafeDelete(fCanvases);
SafeDelete(fTasks);
SafeDelete(fProofs);
SafeDelete(fDataSets);
SafeDelete(fClipboard);
fCleanups->Clear();
delete fPluginManager; gPluginMgr = fPluginManager = 0;
delete gClassTable; gClassTable = 0;
delete gEnv; gEnv = 0;
if (fTypes) fTypes->Delete();
SafeDelete(fTypes);
if (fGlobals) fGlobals->Delete();
SafeDelete(fGlobals);
if (fGlobalFunctions) fGlobalFunctions->Delete();
SafeDelete(fGlobalFunctions);
fClasses->Delete(); SafeDelete(fClasses);
#endif
gSystem->CleanCompiledMacros();
delete gSystem;
SafeDelete(fInterpreter);
#ifdef R__COMPLETE_MEM_TERMINATION
SafeDelete(fCleanups);
#endif
TStorage::PrintStatistics();
gROOT = 0;
fgRootInit = kFALSE;
}
}
void TROOT::AddClass(TClass *cl)
{
TClass::AddClass(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;
}
namespace {
static void R__ListSlowClose(TList *files)
{
static TObject harmless;
TObjLink *cursor = files->FirstLink();
while (cursor) {
TDirectory *dir = static_cast<TDirectory*>( cursor->GetObject() );
if (dir) {
cursor->SetObject(&harmless);
dir->Close();
cursor->SetObject(dir);
}
cursor = cursor->Next();
};
files->Clear();
}
}
void TROOT::CloseFiles()
{
if (fFiles && fFiles->First()) {
R__ListSlowClose(static_cast<TList*>(fFiles));
}
if (fSockets && fSockets->First()) {
if (0==fCleanups->FindObject(fSockets) ) {
fCleanups->Add(fSockets);
fSockets->SetBit(kMustCleanup);
}
CallFunc_t *socketCloser = gInterpreter->CallFunc_Factory();
Long_t offset = 0;
TClass *socketClass = TClass::GetClass("TSocket");
gInterpreter->CallFunc_SetFuncProto(socketCloser, socketClass->GetClassInfo(), "Close", "", &offset);
if (gInterpreter->CallFunc_IsValid(socketCloser)) {
static TObject harmless;
TObjLink *cursor = static_cast<TList*>(fSockets)->FirstLink();
TList notclosed;
while (cursor) {
TObject *socket = cursor->GetObject();
cursor->SetObject(&harmless);
if (socket->IsA()->InheritsFrom(socketClass)) {
gInterpreter->CallFunc_Exec(socketCloser, ((char*)socket)+offset);
socket->SetBit(kMustCleanup);
fClosedObjects->AddLast(socket);
} else {
Long_t other_offset;
CallFunc_t *otherCloser = gInterpreter->CallFunc_Factory();
gInterpreter->CallFunc_SetFuncProto(otherCloser, socket->IsA()->GetClassInfo(), "Close", "", &other_offset);
if (gInterpreter->CallFunc_IsValid(otherCloser)) {
gInterpreter->CallFunc_Exec(otherCloser, ((char*)socket)+other_offset);
socket->SetBit(kMustCleanup);
fClosedObjects->AddLast(socket);
} else {
notclosed.AddLast(socket);
}
gInterpreter->CallFunc_Delete(otherCloser);
cursor->SetObject(socket);
}
cursor = cursor->Next();
}
fSockets->Clear();
cursor = notclosed.FirstLink();
while (cursor) {
static_cast<TList*>(fSockets)->AddLast(cursor->GetObject());
cursor = cursor->Next();
}
}
gInterpreter->CallFunc_Delete(socketCloser);
}
if (fMappedFiles && fMappedFiles->First()) {
R__ListSlowClose(static_cast<TList*>(fMappedFiles));
}
}
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;
return gDirectory->FindObjectAnyFile(name);
}
TObject *TROOT::FindObjectAnyFile(const char *name) const
{
TDirectory *d;
TIter next(GetListOfFiles());
while ((d = (TDirectory*)next())) {
TObject *obj = d->TDirectory::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 "??";
}
static TClass *R__FindSTLClass(const char *name, Bool_t load, Bool_t silent, const char *outername)
{
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(), silent);
}
if (cl==0) {
TDataType *objType = gROOT->GetType(name, load);
if (objType) {
const char *typedfName = objType->GetTypeName();
if (typedfName) {
string defaultTypedefName(TClassEdit::ShortType(typedfName, TClassEdit::kDropStlDefault));
if (strcmp(typedfName, name) && defaultTypedefName == name) {
cl = (TClass*)gROOT->GetListOfClasses()->FindObject(typedfName);
if (load && !cl) cl = gROOT->LoadClass(typedfName, silent);
}
}
}
}
if (cl==0) {
const char *altname = gInterpreter->GetInterpreterTypeName(name);
if (altname && strcmp(altname,name)!=0 && strcmp(altname,outername)!=0) {
cl = TClass::GetClass(altname,load,silent);
}
}
if (cl==0) {
string long64name = TClassEdit::GetLong64_Name( name );
if ( long64name != name && long64name != outername ) return R__FindSTLClass( long64name.c_str(), load, silent, outername);
}
if (cl == 0) {
TString resolvedName = TClassEdit::ResolveTypedef(name,kFALSE).c_str();
if (resolvedName != name && resolvedName != outername) cl = TClass::GetClass(resolvedName,load,silent);
}
if (cl == 0 && (strncmp(name,"std::",5)==0)) {
if (strlen(name+5)) cl = TClass::GetClass(name+5,load,silent);
}
if (load && cl==0) {
cl = new TClass(defaultname.c_str(), TClass::GetClass("TVirtualStreamerInfo")->GetClassVersion(), 0, 0, -1, -1, silent );
cl->SetBit(TClass::kIsEmulation);
}
return cl;
}
TClass *TROOT::FindSTLClass(const char *name, Bool_t load, Bool_t silent) const
{
return R__FindSTLClass(name,load,silent,name);
}
TClass *TROOT::GetClass(const char *name, Bool_t load, Bool_t silent) const
{
return TClass::GetClass(name,load,silent);
}
TClass *TROOT::GetClass(const type_info& typeinfo, Bool_t load, Bool_t silent) const
{
return TClass::GetClass(typeinfo,load,silent);
}
TColor *TROOT::GetColor(Int_t color) const
{
TColor::InitializeColors();
TObjArray *lcolors = (TObjArray*) GetListOfColors();
if (!lcolors) return 0;
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;
}
TCanvas *TROOT::MakeDefCanvas() const
{
return (TCanvas*)gROOT->ProcessLine("TCanvas::MakeDefCanvas();");
}
TDataType *TROOT::GetType(const char *name, Bool_t load) const
{
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
{
if (name == 0 || name[0] == 0) {
return 0;
}
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);
}
static TClass* R__GetClassIfKnown(const char* className) {
const char* libsToLoad = gInterpreter->GetClassSharedLibs(className);
TClass* cla = 0;
if (libsToLoad) {
return TClass::GetClass(className);
} else if (gROOT->GetListOfClasses()
&& (cla = (TClass*)gROOT->GetListOfClasses()->FindObject(className))) {
} else if (gClassTable->FindObject(className)) {
return TClass::GetClass(className);
}
return cla;
}
Int_t TROOT::IgnoreInclude(const char *fname, const char * )
{
if (fname == 0) return 0;
TString stem(fname);
Int_t where = stem.Last('.');
if (where != kNPOS) {
if (stem.EndsWith(".so") || stem.EndsWith(".sl") ||
stem.EndsWith(".dl") || stem.EndsWith(".a") ||
stem.EndsWith(".dll", TString::kIgnoreCase))
return 0;
stem.Remove(where);
}
TString className = gSystem->BaseName(stem);
TClass* cla = R__GetClassIfKnown(className);
if (!cla) {
className = stem;
className.ReplaceAll("/", "::");
className.ReplaceAll("\\", "::");
if (className.Contains(":::")) {
return 0;
}
cla = R__GetClassIfKnown(className);
}
if (!cla) {
return 0;
}
if (cla->GetDeclFileLine() <= 0) return 0;
TString decfile = gSystem->BaseName(cla->GetDeclFileName());
if (decfile != gSystem->BaseName(fname)) {
return 0;
}
return 1;
}
void TROOT::InitSystem()
{
if (gSystem == 0) {
#if defined(R__UNIX)
gSystem = new TUnixSystem;
#elif defined(R__WIN32)
gSystem = new TWinNTSystem;
#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);
if (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 *requestedname, Bool_t silent) const
{
TString classname(requestedname);
VoidFuncPtr_t dict = TClassTable::GetDict(classname);
TString resolved;
if (!dict) {
resolved = TClassEdit::ResolveTypedef(classname,kTRUE);
if (resolved != classname) {
dict = TClassTable::GetDict(resolved.Data());
} else {
resolved.Clear();
}
}
if (!dict) {
if (gInterpreter->AutoLoad(classname)) {
dict = TClassTable::GetDict(classname);
if (!dict) {
if (resolved.Length()) {
dict = TClassTable::GetDict(resolved.Data());
}
}
}
}
if (dict) {
(dict)();
TClass *ncl = TClass::GetClass(classname, kFALSE, silent);
if (ncl) ncl->PostLoadCheck();
return ncl;
}
TIter next(fClassGenerators);
TClassGenerator *gen;
while ((gen = (TClassGenerator*) next())) {
TClass *cl = gen->GetClass(classname, kTRUE, silent);
if (cl) {
cl->PostLoadCheck();
return cl;
}
}
return 0;
}
Int_t TROOT::LoadClass(const char * , const char *libname,
Bool_t check)
{
Int_t err = -1;
char *path;
TString lib = libname;
if (!lib.BeginsWith("lib"))
lib = "lib" + lib;
if ((path = gSystem->DynamicPathName(lib, kTRUE))) {
if (check)
err = 0;
else {
err = gSystem->Load(path, 0, kTRUE);
}
delete [] path;
} else {
if (check) {
FileStat_t stat;
if (!gSystem->GetPathInfo(libname, stat)) {
if (R_ISREG(stat.fMode) &&
!gSystem->AccessPathName(libname, kReadPermission))
err = 0;
else
err = -1;
} 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) ignored in %s", 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, Bool_t padUpdate)
{
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 (padUpdate && 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);
}
}
Long_t TROOT::ProcessLine(const char *line, Int_t *error)
{
TString sline = line;
sline = sline.Strip(TString::kBoth);
if (!fApplication)
TApplication::CreateApplication();
return fApplication->ProcessLine(sline, kFALSE, error);
}
Long_t TROOT::ProcessLineSync(const char *line, Int_t *error)
{
TString sline = line;
sline = sline.Strip(TString::kBoth);
if (!fApplication)
TApplication::CreateApplication();
return fApplication->ProcessLine(sline, kTRUE, error);
}
Long_t TROOT::ProcessLineFast(const char *line, Int_t *error)
{
TString sline = line;
sline = sline.Strip(TString::kBoth);
if (!fApplication)
TApplication::CreateApplication();
Long_t result = 0;
if (fInterpreter) {
TInterpreter::EErrorCode *code = (TInterpreter::EErrorCode*)error;
result = gInterpreter->Calc(sline, code);
}
return result;
}
void TROOT::ReadSvnInfo()
{
fSvnRevision = 0;
#ifdef ROOT_SVN_REVISION
fSvnRevision = ROOT_SVN_REVISION;
#endif
#ifdef ROOT_SVN_BRANCH
fSvnBranch = ROOT_SVN_BRANCH;
#endif
TString svninfo = "svninfo.txt";
char *filename = 0;
#ifdef ROOTETCDIR
filename = gSystem->ConcatFileName(ROOTETCDIR, svninfo);
#else
TString etc = gRootDir;
#ifdef WIN32
etc += "\\etc";
#else
etc += "/etc";
#endif
#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
etc = gRootDir;
#endif
filename = gSystem->ConcatFileName(etc, svninfo);
#endif
FILE *fp = fopen(filename, "r");
if (fp) {
TString s;
s.Gets(fp);
fSvnBranch = s;
s.Gets(fp);
Int_t r = s.Atoi();
if (r > 0)
fSvnRevision = r;
s.Gets(fp);
fSvnDate = s;
fclose(fp);
}
delete [] filename;
}
const char *TROOT::GetSvnDate()
{
if (fSvnDate == "") {
Int_t iday,imonth,iyear, ihour, imin;
static const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "De" };
Int_t idate = gROOT->GetBuiltDate();
Int_t itime = gROOT->GetBuiltTime();
iday = idate%100;
imonth = (idate/100)%100;
iyear = idate/10000;
ihour = itime/100;
imin = itime%100;
fSvnDate.Form("%s %02d %4d, %02d:%02d:00", months[imonth-1], iday, iyear, ihour, imin);
}
return fSvnDate;
}
void TROOT::RefreshBrowsers()
{
TIter next(GetListOfBrowsers());
TBrowser *b;
while ((b = (TBrowser*) next()))
b->SetRefreshFlag(kTRUE);
}
void TROOT::RemoveClass(TClass *oldcl)
{
TClass::RemoveClass(oldcl);
}
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 = TClass::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)
{
TString style_name = stylename;
TStyle *style = GetStyle(style_name);
if (style) style->cd();
else Error("SetStyle","Unknown style:%s",style_name.Data());
}
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__WIN32)
#ifdef ROOTMACRODIR
macroPath = ".:" ROOTMACRODIR;
#else
macroPath = TString(".:") + gRootDir + "/macros";
#endif
#else
#ifdef ROOTMACRODIR
macroPath = ".;" ROOTMACRODIR;
#else
macroPath = TString(".;") + gRootDir + "/macros";
#endif
#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;
}
Int_t TROOT::ConvertVersionCode2Int(Int_t code)
{
return 10000*(code>>16) + 100*((code&65280)>>8) + (code&255);
}
Int_t TROOT::ConvertVersionInt2Code(Int_t v)
{
int a = v/10000;
int b = (v - a*10000)/100;
int c = v - a*10000 - b*100;
return (a << 16) + (b << 8) + c;
}
Int_t TROOT::RootVersionCode()
{
return ROOT_VERSION_CODE;
}