00001
00002
00003
00004
00005
00006
00007
00008 #include "EventDisplayBase/RootEnv.h"
00009 #include <iostream>
00010 #include <string>
00011 #include <cassert>
00012 #include "TROOT.h"
00013 #include "TStyle.h"
00014 #include "TApplication.h"
00015 #include "TRootApplication.h"
00016 #include "TGClient.h"
00017 #include "TRint.h"
00018 #include "TSystem.h"
00019 #include "TSysEvtHandler.h"
00020 #include "TInterpreter.h"
00021 using namespace evdb;
00022
00023
00024 static TROOT root("TROOT","TROOT");
00025
00026 RootEnv::RootEnv(int , char** argv)
00027 {
00028
00029
00030
00031
00032 assert(gROOT);
00033
00034 TApplication* app = gROOT->GetApplication();
00035 if (app == 0) {
00036
00037 int largc = 0;
00038 char** largv = 0;
00039 fTheApp = new TRint("TAPP",&largc, largv, 0, 0, kTRUE);
00040
00041
00042 std::string p = gSystem->BaseName(argv[0]); p+= " [%d] ";
00043 fTheApp->SetPrompt(p.c_str());
00044
00045 this->SignalConfig();
00046 this->InterpreterConfig();
00047 this->LoadIncludes();
00048 this->LoadClasses();
00049
00050 gROOT->SetStyle("Plain");
00051 gStyle->SetOptStat(0);
00052 }
00053 }
00054
00055
00056
00057 RootEnv::~RootEnv()
00058 {
00059
00060
00061 }
00062
00063
00064
00065 int RootEnv::Run()
00066 {
00067
00068
00069
00070 TApplication* app = gROOT->GetApplication();
00071 if (app) {
00072 app->Run(kTRUE);
00073 return 1;
00074 }
00075 return 0;
00076 }
00077
00078
00079
00080 void RootEnv::InterpreterConfig()
00081 {
00082
00083
00084
00085 if (gInterpreter) {
00086 gInterpreter->SaveContext();
00087 gInterpreter->SaveGlobalsContext();
00088 }
00089 }
00090
00091
00092
00093 void RootEnv::SignalConfig()
00094 {
00095
00096
00097
00098 if (gSystem) {
00099
00100 gSystem->ResetSignal(kSigBus, kTRUE);
00101 gSystem->ResetSignal(kSigSegmentationViolation,kTRUE);
00102 gSystem->ResetSignal(kSigSystem, kTRUE);
00103 gSystem->ResetSignal(kSigPipe, kTRUE);
00104 gSystem->ResetSignal(kSigIllegalInstruction, kTRUE);
00105 gSystem->ResetSignal(kSigQuit, kTRUE);
00106 gSystem->ResetSignal(kSigInterrupt, kTRUE);
00107 gSystem->ResetSignal(kSigWindowChanged, kTRUE);
00108 gSystem->ResetSignal(kSigAlarm, kTRUE);
00109 gSystem->ResetSignal(kSigChild, kTRUE);
00110 gSystem->ResetSignal(kSigUrgent, kTRUE);
00111 gSystem->ResetSignal(kSigFloatingException, kTRUE);
00112 gSystem->ResetSignal(kSigTermination, kTRUE);
00113 gSystem->ResetSignal(kSigUser1, kTRUE);
00114 gSystem->ResetSignal(kSigUser2, kTRUE);
00115 }
00116 }
00117
00118
00119
00120 void RootEnv::LoadIncludes()
00121 {
00122
00123
00124
00125 TApplication* app = gROOT->GetApplication();
00126 if (app) {
00127
00128
00129 app->ProcessLine("#include <iomanip>");
00130 app->ProcessLine("#include <string>");
00131
00132
00133 std::string mp = gROOT->GetMacroPath();
00134 std::string ip;
00135 const char* p;
00136 p = gSystem->Getenv("SRT_PRIVATE_CONTEXT");
00137 if (p) {
00138 mp += ":";
00139 mp += p;
00140 mp += ":";
00141 mp += p;
00142 mp += "/macros";
00143 ip += " -I";
00144 ip += p;
00145 }
00146 p = gSystem->Getenv("SRT_PUBLIC_CONTEXT");
00147 if (p) {
00148 mp += ":";
00149 mp += p;
00150 mp += "/macros";
00151 ip += " -I";
00152 ip += p;
00153 }
00154
00155 gROOT->SetMacroPath(mp.c_str());
00156 gSystem->SetIncludePath(ip.c_str());
00157
00158 std::string dip = ".include ";
00159 dip += gSystem->Getenv("SRT_PRIVATE_CONTEXT");
00160 gROOT->ProcessLine(dip.c_str());
00161 dip = ".include ";
00162 dip += gSystem->Getenv("SRT_PUBLIC_CONTEXT");
00163 gROOT->ProcessLine(dip.c_str());
00164 }
00165 }
00166
00167
00168
00169 void RootEnv::LoadClasses()
00170 {
00171
00172
00173
00174 if (gROOT) {
00175 gROOT->LoadClass("TGeometry", "Graf3d");
00176 gROOT->LoadClass("TTree", "Tree");
00177 gROOT->LoadClass("TMatrix", "Matrix");
00178 gROOT->LoadClass("TMinuit", "Minuit");
00179 gROOT->LoadClass("TPostScript", "Postscript");
00180 gROOT->LoadClass("TCanvas", "Gpad");
00181 gROOT->LoadClass("THtml", "Html");
00182 }
00183 }
00184