JobCRootEnv Class Reference

#include <JobCRootEnv.h>

List of all members.

Public Member Functions

 JobCRootEnv (int argc, char **argv)
 ~JobCRootEnv ()
bool HaveBatchOpt ()
bool HaveQuitOpt ()
bool HaveInaccessibleFile ()
int RunTheApp ()

Private Member Functions

void InterpreterConfig ()
void SignalConfig ()
void LoadIncludes ()
void LoadClasses ()

Private Attributes

bool fHaveBatchOpt
bool fHaveQuitOpt
bool fHaveMacroFiles
bool fHaveInaccessibleFile

Detailed Description

Definition at line 11 of file JobCRootEnv.h.


Constructor & Destructor Documentation

JobCRootEnv::JobCRootEnv ( int  argc,
char **  argv 
)

Definition at line 45 of file JobCRootEnv.cxx.

References exit(), fHaveBatchOpt, fHaveInaccessibleFile, fHaveMacroFiles, fHaveQuitOpt, fname, GETOPTDONE, gSystem(), InterpreterConfig(), IsArgMacroFile(), Msg::kDebug, Msg::kError, LoadClasses(), LoadIncludes(), MSG, root(), and SignalConfig().

00045                                               : 
00046   fHaveBatchOpt(false),
00047   fHaveQuitOpt(false),
00048   fHaveMacroFiles(false),
00049   fHaveInaccessibleFile(false)
00050 {
00051 //======================================================================
00052 // Purpose: Set up the ROOT environment
00053 //
00054 // Inputs:
00055 //  argc - number of command line arguments
00056 //  argv - array of command line arguments
00057 //======================================================================
00058   // Root only understands a subset of the command line arguments we
00059   // might want to allow. This makes a copy of command line arguments
00060   // ROOT understands.
00061   static int   localArgc = 0;   // Copy of command line args.
00062   static char* localArgv[1024]; // Copy of command line args.
00063   if (argc>0) {
00064     localArgv[localArgc++] = argv[0];
00065   }
00066   else {
00067     localArgv[localArgc++] = const_cast<char*>("moot"); // Dummy program name
00068   }
00069   
00070   // Setup the ROOT globals. gROOT from TROOT.h
00071   if (gROOT==0) {
00072     static TROOT root("TROOT",localArgv[0]);
00073   }
00074   assert(gROOT);
00075 
00076   // Setup the application
00077   TApplication* app = gROOT->GetApplication();
00078   if (app==0) {
00079     int c;
00080 
00081 #ifndef MACOSX
00082   optind = 0; // getopt.h: Reset getopt to start of arguments
00083 #else
00084   optind = 1; // skip 0th argument ("loon") for MACOSX
00085 #endif
00086 
00087 #ifdef IRIX6
00088     getoptreset(); // needed by IRIX to reset getopt
00089 #endif
00090     const char* opts = "bs:nqlt:r:x:hH:d:u:p:o:v:";
00091     while ((c=getopt(argc, argv, opts)) != GETOPTDONE) {
00092       MSG("JobC",Msg::kDebug)
00093         << "Processing job command-line ROOT option argument: "
00094         << c << " '" << (char)c << "'" << endl;
00095       switch (c) {
00096         // const_cast because these are string constants but TRint
00097         // ctor needs a char**
00098       case 'l': localArgv[localArgc++] = const_cast<char*>("-l"); break;
00099       case 'b': localArgv[localArgc++] = const_cast<char*>("-b"); fHaveBatchOpt = true; break;
00100       case 'n': localArgv[localArgc++] = const_cast<char*>("-n"); break;
00101       case 'q': localArgv[localArgc++] = const_cast<char*>("-q"); fHaveQuitOpt  = true; break;
00102       case 'h': localArgv[localArgc++] = const_cast<char*>("-h"); break;
00103       default: break;
00104       }
00105     }
00106 
00107     // Add the directory/macro file stuff to the list
00108     int ndir = 0; // Number of directories specified on command line
00109     for (int i=optind; i<argc; ++i) {
00110       // Check if argv[i] is a directory -- if yes add it to the ROOT
00111       // command line
00112       DIR* d = opendir(argv[i]);
00113       if (d) {
00114         localArgv[localArgc++] = argv[i];
00115         closedir(d);
00116         ++ndir;
00117       }
00118 
00119       // Check if argv[i] is a ROOT macro file
00120       // if yes add it to the ROOT command line
00121       TString fname = IsArgMacroFile(argv[i]);
00122       if (fname != "") {
00123         if (gSystem->AccessPathName(fname.Data())) {
00124           cerr << "Skipping inaccessible file: " << argv[i] << endl;
00125           fHaveInaccessibleFile = true;
00126           continue;
00127         }
00128         fHaveMacroFiles = true;
00129         localArgv[localArgc++] = argv[i];
00130       }
00131     }
00132     // If the user has two directories on the command line they've
00133     // made a mistake. Kindly inform them of that mistake...
00134     if (ndir>1) {
00135       MSG("JobC",Msg::kError) << 
00136         "Ambiguous: More than one directory specified on command line.\n";
00137       exit(1);
00138     }
00139 
00140     // Create the ROOT application. This is a little confusing. The
00141     // "new" goes off and puts the TRint application off into ROOT
00142     // global space (gROOT). I can check that's true with the
00143     // assert(). I'm assuming gROOT has taken control of the delete
00144     // for this class. The assert checks that the first part is
00145     // true. I guess I'd have to look at the root code to see if the
00146     // second assumption is also true.
00147     TRint* rint = new TRint("TAPP",&localArgc,localArgv,0,0,kTRUE);
00148     assert(rint == gROOT->GetApplication());
00149     std::string p = gSystem->BaseName(localArgv[0]); p += " [%d] ";
00150     rint->SetPrompt(p.c_str());    
00151 
00152     // Configure the ROOT session
00153     this->SignalConfig();
00154     this->InterpreterConfig();
00155     this->LoadIncludes();
00156     this->LoadClasses();
00157   }
00158 }

JobCRootEnv::~JobCRootEnv (  ) 

Definition at line 274 of file JobCRootEnv.cxx.

00275 {
00276 //======================================================================
00277 // Purpose: Shut down the ROOT session
00278 //======================================================================
00279 }


Member Function Documentation

bool JobCRootEnv::HaveBatchOpt (  )  [inline]

Definition at line 18 of file JobCRootEnv.h.

References fHaveBatchOpt.

00018 { return fHaveBatchOpt; }

bool JobCRootEnv::HaveInaccessibleFile (  )  [inline]

Definition at line 20 of file JobCRootEnv.h.

References fHaveInaccessibleFile.

Referenced by JobCEnv::HaveInaccessibleFile().

00020 { return fHaveInaccessibleFile; }

bool JobCRootEnv::HaveQuitOpt (  )  [inline]

Definition at line 19 of file JobCRootEnv.h.

References fHaveQuitOpt.

00019 { return fHaveQuitOpt;  }

void JobCRootEnv::InterpreterConfig (  )  [private]

Definition at line 162 of file JobCRootEnv.cxx.

Referenced by JobCRootEnv().

00163 {
00164 //======================================================================
00165 // Configure the root interpreter
00166 //======================================================================
00167   if (gInterpreter) { // gInterpreter from TInterpreter.h
00168     gInterpreter->SaveContext();
00169     gInterpreter->SaveGlobalsContext();
00170   }
00171 }

void JobCRootEnv::LoadClasses (  )  [private]

Definition at line 256 of file JobCRootEnv.cxx.

Referenced by JobCRootEnv().

00257 {
00258 //======================================================================
00259 // Load classes to make the root session more covenient
00260 //======================================================================
00261   if (gROOT) {
00262     gROOT->LoadClass("TGeometry",   "Graf3d");
00263     gROOT->LoadClass("TTree",       "Tree");
00264     gROOT->LoadClass("TMatrix",     "Matrix");
00265     gROOT->LoadClass("TMinuit",     "Minuit");
00266     gROOT->LoadClass("TPostScript", "Postscript");
00267     gROOT->LoadClass("TCanvas",     "Gpad");
00268     gROOT->LoadClass("THtml",       "Html");
00269   }
00270 }

void JobCRootEnv::LoadIncludes (  )  [private]

Definition at line 204 of file JobCRootEnv.cxx.

References gSystem().

Referenced by JobCRootEnv().

00205 {
00206 //======================================================================
00207 // Load include files to make the root session more covenient
00208 //======================================================================
00209   TApplication* app = gROOT->GetApplication();
00210   if (app) {
00211     // Load a set of useful C++ includes.
00212     // app->ProcessLine("#include <iostream>"); // Root gets this one itself
00213     app->ProcessLine("#include <iomanip>");
00214     app->ProcessLine("#include <string>");
00215 
00216     // Load minos include files
00217     TString mp = gROOT->GetMacroPath();
00218     TString ip;
00219     const char* p;
00220     p = gSystem->Getenv("SRT_PRIVATE_CONTEXT");
00221     if (p) {
00222       mp += ":";
00223       mp += p;
00224       mp += ":";
00225       mp += p;
00226       mp += "/macros";
00227       ip += " -I";
00228       ip += p;
00229     }
00230     p = gSystem->Getenv("SRT_PUBLIC_CONTEXT");
00231     if (p) {
00232       mp += ":";
00233       mp += p;
00234       mp += "/macros";
00235       ip += " -I";
00236       ip += p;
00237     }
00238     
00239     gROOT->SetMacroPath(mp.Data());
00240     gSystem->SetIncludePath(ip);
00241     
00242     TString dip = ".include ";
00243     dip += gSystem->Getenv("SRT_PRIVATE_CONTEXT");
00244     gROOT->ProcessLine(dip.Data());
00245 
00246     dip = ".include ";
00247     dip += gSystem->Getenv("SRT_PUBLIC_CONTEXT");
00248     gROOT->ProcessLine(dip.Data());
00249     dip += "/RDBC/include";
00250     gROOT->ProcessLine(dip.Data());
00251   }
00252 }

int JobCRootEnv::RunTheApp (  ) 

Definition at line 283 of file JobCRootEnv.cxx.

Referenced by JobCEnv::RunRootApp().

00284 {
00285 //======================================================================
00286 // Purpose: Turn control over to the ROOT application
00287 //======================================================================
00288   TApplication* app = gROOT->GetApplication();
00289   if (app) {
00290     app->Run(kTRUE); // kTRUE == "Return from run" request...
00291     return 1;
00292   }
00293   return 0;
00294 }

void JobCRootEnv::SignalConfig (  )  [private]

Definition at line 175 of file JobCRootEnv.cxx.

References fHaveBatchOpt, and gSystem().

Referenced by JobCRootEnv().

00176 {
00177 //======================================================================
00178 // Configure root's signale handlers
00179 //======================================================================
00180   if (gSystem) { // gSystem from TSystem.h
00181     // Reset ROOT's signal handling to the defaults...
00182     gSystem->ResetSignal(kSigBus,                  kTRUE);
00183     gSystem->ResetSignal(kSigSegmentationViolation,kTRUE);
00184     gSystem->ResetSignal(kSigSystem,               kTRUE);
00185     gSystem->ResetSignal(kSigPipe,                 kTRUE);
00186     gSystem->ResetSignal(kSigIllegalInstruction,   kTRUE);
00187     gSystem->ResetSignal(kSigQuit,                 kTRUE);
00188     if (fHaveBatchOpt)
00189       gSystem->ResetSignal(kSigInterrupt,          kTRUE);
00190     gSystem->ResetSignal(kSigWindowChanged,        kTRUE);
00191     //rwh: 2004-09-07 leave ROOT's version of SigAlarm handling in place
00192     //gSystem->ResetSignal(kSigAlarm,                kTRUE);
00193     gSystem->ResetSignal(kSigChild,                kTRUE);
00194     gSystem->ResetSignal(kSigUrgent,               kTRUE);
00195     gSystem->ResetSignal(kSigFloatingException,    kTRUE);
00196     gSystem->ResetSignal(kSigTermination,          kTRUE);
00197     gSystem->ResetSignal(kSigUser1,                kTRUE);
00198     gSystem->ResetSignal(kSigUser2,                kTRUE);
00199   }
00200 }


Member Data Documentation

Definition at line 31 of file JobCRootEnv.h.

Referenced by HaveBatchOpt(), JobCRootEnv(), and SignalConfig().

Definition at line 34 of file JobCRootEnv.h.

Referenced by HaveInaccessibleFile(), and JobCRootEnv().

Definition at line 33 of file JobCRootEnv.h.

Referenced by JobCRootEnv().

bool JobCRootEnv::fHaveQuitOpt [private]

Definition at line 32 of file JobCRootEnv.h.

Referenced by HaveQuitOpt(), and JobCRootEnv().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1