Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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


Constructor & Destructor Documentation

JobCRootEnv::JobCRootEnv int  argc,
char **  argv
 

Definition at line 44 of file JobCRootEnv.cxx.

References fHaveBatchOpt, fHaveInaccessibleFile, fHaveMacroFiles, fHaveQuitOpt, gSystem(), InterpreterConfig(), IsArgMacroFile(), LoadClasses(), LoadIncludes(), MSG, root(), and SignalConfig().

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

JobCRootEnv::~JobCRootEnv  ) 
 

Definition at line 273 of file JobCRootEnv.cxx.

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


Member Function Documentation

bool JobCRootEnv::HaveBatchOpt  )  [inline]
 

Definition at line 18 of file JobCRootEnv.h.

00018 { return fHaveBatchOpt; }

bool JobCRootEnv::HaveInaccessibleFile  )  [inline]
 

Definition at line 20 of file JobCRootEnv.h.

Referenced by JobCEnv::HaveInaccessibleFile().

00020 { return fHaveInaccessibleFile; }

bool JobCRootEnv::HaveQuitOpt  )  [inline]
 

Definition at line 19 of file JobCRootEnv.h.

00019 { return fHaveQuitOpt;  }

void JobCRootEnv::InterpreterConfig  )  [private]
 

Definition at line 161 of file JobCRootEnv.cxx.

Referenced by JobCRootEnv().

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

void JobCRootEnv::LoadClasses  )  [private]
 

Definition at line 255 of file JobCRootEnv.cxx.

Referenced by JobCRootEnv().

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

void JobCRootEnv::LoadIncludes  )  [private]
 

Definition at line 203 of file JobCRootEnv.cxx.

References gSystem().

Referenced by JobCRootEnv().

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

int JobCRootEnv::RunTheApp  ) 
 

Definition at line 282 of file JobCRootEnv.cxx.

Referenced by JobCEnv::RunRootApp().

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

void JobCRootEnv::SignalConfig  )  [private]
 

Definition at line 174 of file JobCRootEnv.cxx.

References gSystem().

Referenced by JobCRootEnv().

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


Member Data Documentation

bool JobCRootEnv::fHaveBatchOpt [private]
 

Definition at line 31 of file JobCRootEnv.h.

Referenced by JobCRootEnv().

bool JobCRootEnv::fHaveInaccessibleFile [private]
 

Definition at line 34 of file JobCRootEnv.h.

Referenced by JobCRootEnv().

bool JobCRootEnv::fHaveMacroFiles [private]
 

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 JobCRootEnv().


The documentation for this class was generated from the following files:
Generated on Mon Feb 15 11:09:21 2010 for loon by  doxygen 1.3.9.1