20 #include "TApplication.h" 23 #include "TVirtualX.h" 51 struct RootGraphicsEnablerClass {
54 RootGraphicsEnablerClass() { EnableRootGraphics(); }
57 RootGraphicsEnablerClass(std::ostream& out) { EnableRootGraphics(&out); }
61 static void EnableRootGraphics(std::ostream* out =
nullptr);
67 RootGraphicsEnablerClass RootGraphicsEnabler{
68 #if not defined(NDEBUG) // output only if debug is not suppressed 74 void RootGraphicsEnablerClass::EnableRootGraphics
78 if (out) (*out) <<
"RootGraphicsEnablerClass hacking its way forth." << std::endl;
84 if (out) (*out) <<
" ==> get the current TApplication (and make sure gROOT is valid)" << std::endl;
85 TApplication* app = ROOT::GetROOT()->GetApplication();
89 throw std::runtime_error(
"RootGraphicsEnabler: no ROOT global pointer");
92 if (out) (*out) <<
" ==> create a TApplication" << std::endl;
94 char** argv =
nullptr;
95 new TApplication(
"TApplicationFromRootGraphicsEnabler", &argc, argv);
98 if (out) (*out) <<
" ==> set batch mode off (now it is " << (gROOT->IsBatch()?
"on":
"already off") << std::endl;
99 gROOT->SetBatch(kFALSE);
102 if (out) (*out) <<
" ==> creating a TGClient" << std::endl;
104 if (out) (*out) <<
" ==> loading graphics library (X11)" << std::endl;
105 int res = gSystem->Load(
"libGX11.so");
109 case 1: (*out) <<
" (it was already)" << std::endl;
break;
110 case -1: (*out) <<
" ERROR: not found!" << std::endl;
break;
111 case -2: (*out) <<
" ERROR: version mismatch!" << std::endl;
break;
112 default: (*out) <<
" ERROR: undocumented (code=" << res <<
")" << std::endl;
break;
116 if (out) (*out) <<
" ==> creating TVirtualX" << std::endl;
117 gVirtualX =
new TGX11(
"X11",
"X11 session");
119 std::string
const DISPLAY = getenv(
"DISPLAY");
121 if (out) (*out) <<
" ==> creating the TGClient (DISPLAY='" << DISPLAY <<
"')" << std::endl;
122 new TGClient(DISPLAY.c_str());
125 if (out) (*out) <<
"RootGraphicsEnablerClass hacking compleled." << std::endl;