RootEnv.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file RootEnv.cxx
3 /// \brief Configure the ROOT environment
4 ///
5 /// \version $Id: RootEnv.cxx,v 1.7 2011-10-31 14:41:40 greenc Exp $
6 /// \author messier@indiana.edu
7 ////////////////////////////////////////////////////////////////////////
8 #include "nutools/EventDisplayBase/RootEnv.h"
9 
10 #include <iostream>
11 #include <string>
12 #include <cstdlib>
13 
14 #include "TROOT.h"
15 #include "TCanvas.h"
16 #include "TStyle.h"
17 #include "TApplication.h"
18 #include "TRootApplication.h"
19 #include "TGClient.h"
20 #include "TRint.h"
21 #include "TSystem.h"
22 #include "TSysEvtHandler.h"
23 #include "TInterpreter.h"
24 
25 #include "cetlib_except/exception.h"
26 
27 namespace evdb{
28 
29  RootEnv::RootEnv(int /*argc*/, char** /*argv*/)
30  {
31  //======================================================================
32  // Setup the root environment for a program started with command line
33  // options argc and argv
34  //======================================================================
35  TApplication* app = ROOT::GetROOT()->GetApplication();
36 
37  // ROOT::GetROOT() should initialize gROOT.
38  if(!gROOT)
39  throw cet::exception("RootEnv") << "No ROOT global pointer";
40 
41  if (app == 0) {
42  int largc = 0;
43  char** largv = 0;
44  TRint* rapp = new TRint("TAPP",&largc, largv, 0, 0, kTRUE);
45 
46  // std::string p = gSystem->BaseName(argv[0]); p+= " [%d] ";
47  rapp->SetPrompt("evd [%d] ");
48  }
49  else {
50  gROOT->SetBatch(kFALSE);
51  if (gClient==0) {
52  app->InitializeGraphics();
53  }
54  }
55 
56  this->SetStyle();
57  this->SignalConfig();
58  this->InterpreterConfig();
59  this->LoadIncludes();
60  this->LoadClasses();
61  }
62 
63  //......................................................................
64 
66  {
67  // ROOT takes care of the following delete so don't do it twice
68  // if (fTheApp) { delete fTheApp; fTheApp = 0; }
69  }
70 
71  //......................................................................
72 
73  int RootEnv::Run()
74  {
75  //======================================================================
76  // Turn control of the application over to ROOT's event loop
77  //======================================================================
78  TApplication* app = ROOT::GetROOT()->GetApplication();
79  if (app) {
80  app->Run(kFALSE); // kTRUE == "Return from run" request...
81  return 1;
82  }
83  return 0;
84  }
85 
86  //......................................................................
87 
89  {
90  //======================================================================
91  // Configure the root interpreter
92  //======================================================================
93  if (gInterpreter) { // gInterpreter from TInterpreter.h
94  gInterpreter->SaveContext();
95  gInterpreter->SaveGlobalsContext();
96  }
97  }
98 
99  //......................................................................
100 
102  {
103  //======================================================================
104  // Configure root's signale handlers
105  //======================================================================
106  return;
107  if (gSystem) { // gSystem from TSystem.h
108  // Reset ROOT's signal handling to the defaults...
109  gSystem->ResetSignal(kSigBus, kTRUE);
110  gSystem->ResetSignal(kSigSegmentationViolation,kTRUE);
111  gSystem->ResetSignal(kSigSystem, kTRUE);
112  gSystem->ResetSignal(kSigPipe, kTRUE);
113  gSystem->ResetSignal(kSigIllegalInstruction, kTRUE);
114  gSystem->ResetSignal(kSigQuit, kTRUE);
115  gSystem->ResetSignal(kSigInterrupt, kTRUE);
116  gSystem->ResetSignal(kSigWindowChanged, kTRUE);
117  gSystem->ResetSignal(kSigAlarm, kTRUE);
118  gSystem->ResetSignal(kSigChild, kTRUE);
119  gSystem->ResetSignal(kSigUrgent, kTRUE);
120  gSystem->ResetSignal(kSigFloatingException, kTRUE);
121  gSystem->ResetSignal(kSigTermination, kTRUE);
122  gSystem->ResetSignal(kSigUser1, kTRUE);
123  gSystem->ResetSignal(kSigUser2, kTRUE);
124  }
125  }
126 
127  //......................................................................
128 
130  {
131  //======================================================================
132  // Load include files to make the root session more covenient
133  //======================================================================
134  TApplication* app = gROOT->GetApplication();
135  if (app) {
136  // Load a set of useful C++ includes.
137  // app->ProcessLine("#include <iostream>"); // Root gets this one itself
138  app->ProcessLine("#include <iomanip>");
139  app->ProcessLine("#include <string>");
140 
141  // Load experiment include files
142  // Have to be careful here, not every experiment uses
143  // SRT, so don't try to load the SRT macro paths
144  // if SRT variables aren't defined.
145  std::string mp = gROOT->GetMacroPath();
146  std::string ip;
147  const char* p;
148  bool srtPrivate = false;
149  bool srtPublic = false;
150  p = gSystem->Getenv("SRT_PRIVATE_CONTEXT");
151  if (p) {
152  srtPrivate = true;
153  mp += ":";
154  mp += p;
155  mp += ":";
156  mp += p;
157  mp += "/macros";
158  ip += " -I";
159  ip += p;
160 
161  std::string dip = ".include ";
162  dip += gSystem->Getenv("SRT_PRIVATE_CONTEXT");
163  gROOT->ProcessLine(dip.c_str());
164  }
165  p = gSystem->Getenv("SRT_PUBLIC_CONTEXT");
166  if (p) {
167  srtPublic = true;
168  mp += ":";
169  mp += p;
170  mp += "/macros";
171  ip += " -I";
172  ip += p;
173 
174  std::string dip = ".include ";
175  dip += gSystem->Getenv("SRT_PUBLIC_CONTEXT");
176  gROOT->ProcessLine(dip.c_str());
177  }
178 
179  if(srtPublic || srtPrivate){
180  gROOT->SetMacroPath(mp.c_str());
181  gSystem->SetIncludePath(ip.c_str());
182  }
183  }
184  }
185 
186  //......................................................................
187 
189  {
190  //======================================================================
191  // Load classes to make the root session more covenient
192  //======================================================================
193  if (gROOT) {
194  gROOT->LoadClass("TGeometry", "Graf3d");
195  gROOT->LoadClass("TTree", "Tree");
196  gROOT->LoadClass("TMatrix", "Matrix");
197  gROOT->LoadClass("TMinuit", "Minuit");
198  gROOT->LoadClass("TPostScript", "Postscript");
199  gROOT->LoadClass("TCanvas", "Gpad");
200  gROOT->LoadClass("THtml", "Html");
201  }
202  }
203 
204  //......................................................................
205 
207  {
208  gROOT->SetStyle("Plain");
209 
210  // Set Line Widths
211  gStyle->SetFrameLineWidth(1);
212  gStyle->SetFuncWidth(1);
213  gStyle->SetHistLineWidth(1);
214 
215  gStyle->SetFuncColor(2);
216  gStyle->SetGridColor(18);
217  gStyle->SetGridStyle(1);
218  // SetGridWidth expects a short, the default value is 1, just use that
219  gStyle->SetGridWidth();
220 
221  // Set margins -- I like to shift the plot a little up and to the
222  // right to make more room for axis labels
223  gStyle->SetPadTopMargin(0.08);
224  gStyle->SetPadBottomMargin(0.36);
225  gStyle->SetPadRightMargin(0.03);
226  gStyle->SetPadLeftMargin(0.10);
227 
228  // Set fonts
229  gStyle->SetTextFont(132);
230  gStyle->SetLabelFont(132,"XYZ");
231  gStyle->SetStatFont(132);
232  gStyle->SetTitleFont(132,"XYZ");
233 
234  gStyle->SetStatFontSize(0.07);
235  gStyle->SetTitleFontSize(0.07);
236  gStyle->SetLabelSize(0.07,"XYZ");
237  gStyle->SetTitleSize(0.07,"XYZ");
238  gStyle->SetTextSize(0.07);
239 
240  gStyle->SetStatW(0.19);
241  gStyle->SetStatX(0.90);
242  gStyle->SetStatY(0.90);
243  gStyle->SetOptTitle(0);
244  gStyle->SetOptStat(0);
245 
246  // Set tick marks and turn off grids
247  gStyle->SetNdivisions(510,"XYZ");
248  gStyle->SetPadTickX(1);
249  gStyle->SetPadTickY(1);
250 
251  // Set paper size for life in the US
252  gStyle->SetPaperSize(TStyle::kUSLetter);
253  gStyle->SetPalette(1);
254 
255  // Force this style on all histograms
256  gROOT->ForceStyle();
257  }
258 
259 }// namespace
260 ////////////////////////////////////////////////////////////////////////
std::string string
Definition: nybbler.cc:12
void LoadIncludes()
Definition: RootEnv.cxx:129
Manage all things related to colors for the event display.
void SetStyle()
Definition: RootEnv.cxx:206
p
Definition: test.py:223
void SignalConfig()
Definition: RootEnv.cxx:101
void InterpreterConfig()
Definition: RootEnv.cxx:88
void LoadClasses()
Definition: RootEnv.cxx:188
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
RootEnv(int argc, char **argv)
Definition: RootEnv.cxx:29