JobCRootModule Class Reference

#include <JobCRootModule.h>

Inheritance diagram for JobCRootModule:
JobCModule

List of all members.

Public Member Functions

 JobCRootModule ()
 ~JobCRootModule ()
virtual void HandleCommand (JobCommand *cmd)
virtual void Help ()
virtual void Report ()
virtual void Reset ()

Static Public Member Functions

static void InitRoot ()
static void PassPtrToRoot (std::string className, std::string instanceName, const void *ptr, bool isConst=false)

Detailed Description

Definition at line 18 of file JobCRootModule.h.


Constructor & Destructor Documentation

JobCRootModule::JobCRootModule (  ) 

Definition at line 29 of file JobCRootModule.cxx.

References Msg::kVerbose, and MSG.

00030 {
00031    MSG("Root",Msg::kVerbose) << "JobCRootModule::ctor" << endl;
00032 }

JobCRootModule::~JobCRootModule (  ) 

Definition at line 36 of file JobCRootModule.cxx.

References Msg::kVerbose, and MSG.

00037 {
00038    MSG("Root",Msg::kVerbose) << "JobCRootModule::dtor" << endl;
00039 }


Member Function Documentation

void JobCRootModule::HandleCommand ( JobCommand command  )  [virtual]

Implement to handle a JobCommand

Reimplemented from JobCModule.

Definition at line 141 of file JobCRootModule.cxx.

References Form(), gSystem(), Help(), InitRoot(), Msg::kInfo, Msg::kWarning, MSG, JobCommand::PopCmd(), JobCommand::PopIntOpt(), JobCommand::PopOpt(), and JobCommand::PushOpt().

00142 {
00143 
00144    static int ncmd = 0;
00145    ncmd++;
00146 
00147    class BadJobCRootCmd { };
00148 
00149    // make sure TApp is running so that CINT with <iostream.h> is defined
00150    InitRoot();
00151 
00152    try {
00153       TApplication* app = gROOT->GetApplication();
00154       const char* c = cmd->PopCmd();
00155       if (c) {
00156          string sc(c);
00157          if ((sc == "RunMacro")            || 
00158              (sc == "LoadMacro")           || 
00159              (sc == "CompileMacro")        || 
00160              (sc == "ForceCompileMacro")   || 
00161              (sc == "ProcessLine")            ) {
00162             string wholeLine;
00163             // eat up rest of line
00164             while (const char* opt = cmd->PopOpt()) {
00165                wholeLine += " ";  // put back in the spaces
00166                wholeLine += opt;
00167             }
00168             if (sc == "RunMacro")  wholeLine.insert(0,".x ");
00169             if (sc == "LoadMacro" || sc == "CompileMacro") 
00170                wholeLine.insert(0,".L ");
00171             if (sc == "CompileMacro") wholeLine += "+";
00172             if (sc == "ForceCompileMacro") wholeLine += "++";
00173             app->ProcessLine(wholeLine.c_str());
00174          }
00175          else if (sc == "StartBrowser") {
00176             static int nbrowser = 0; 
00177             nbrowser++;
00178             string bstart("TBrowser RootModuleBrowser");
00179             bstart += Form("%d",nbrowser);
00180             app->ProcessLine(bstart.c_str());
00181          }
00182          else if (sc == "LoadLibrary") {
00183             const char* libraryName = cmd->PopOpt();
00184             Int_t status = gSystem->Load(libraryName);
00185             MSG("Root",Msg::kInfo) 
00186                << Form("(Int_t) %d = gSystem->Load(%s)",
00187                        status,libraryName)
00188                << endl;
00189          }
00190          else if (sc == "LoadClass") {
00191             const char* className   = cmd->PopOpt();
00192             const char* libraryName = cmd->PopOpt();
00193             Int_t status = gROOT->LoadClass(className,libraryName);
00194             MSG("Root",Msg::kInfo) 
00195                << Form("(Int_t) %d = gROOT->LoadClass(%s,%s)",
00196                        status,className,libraryName)
00197                << endl;
00198          }
00199          else if (sc == "MacroPath") {
00200             const char* c2 = cmd->PopCmd();
00201             // if no further part of the command: assume user meant "Reset"
00202             if (!c2) c2 = "Reset";
00203             string sc2(c2);
00204             const char* opt = cmd->PopOpt();
00205             if (!opt) opt = "";
00206             if (sc2 == "Add") {
00207                // add first opt to from of macropath
00208                TString tsopt(opt);
00209                tsopt += ":";
00210                tsopt += TROOT::GetMacroPath();
00211                TROOT::SetMacroPath(tsopt);
00212             }
00213             else if (sc2 == "Reset") {
00214                // reset the path
00215                // if user supplied an option then full path is that
00216                // if not then the path is cleared and will be refetched
00217                // from the gEnv "database".
00218                TROOT::SetMacroPath(opt);
00219             }
00220             else if (sc2 == "Show") {
00221                // do nothing we'll always show the value
00222             }
00223             else {
00224                MSG("Root",Msg::kWarning) 
00225                   << "\"" << sc2 << "\": "
00226                   << "Not a valid sub-comand of " << sc << endl;
00227                throw BadJobCRootCmd();
00228             }
00229             MSG("Root",Msg::kInfo)
00230                << "MacroPath is \""
00231                << TROOT::GetMacroPath()
00232                << "\"" << endl;
00233          }
00234          else if (sc == "ObjectStat") {
00235             const char* c2 = cmd->PopCmd();
00236             // if no further part of the command: assume user meant "Print"
00237             if (!c2) c2 = "Print";
00238             string sc2(c2);
00239             if (sc2 == "Print") {
00240                if (gObjectTable) {
00241                   gObjectTable->Print();
00242                } else {
00243                   MSG("Root",Msg::kInfo) 
00244                      << "Sorry no gObjectTable available" << endl;
00245                }
00246             }
00247             else if (sc2 == "Set") {
00248                bool toggle = true;
00249                const char* val = cmd->PopOpt();
00250                if (val) {
00251                   // there was an actual value, use that
00252                   cmd->PushOpt();
00253                   toggle = (bool) cmd->PopIntOpt();
00254                }
00255                TObject::SetObjectStat(toggle);
00256             }
00257             else {
00258                MSG("Root",Msg::kWarning) 
00259                   << "\"" << sc2 << "\": "
00260                   << "Not a valid sub-comand of " << sc<< endl;
00261                throw BadJobCRootCmd();
00262             }
00263          }
00264          else if (sc == "Reset") {
00265             gROOT->Reset(cmd->PopOpt());
00266          }
00267          else if (sc == "SaveContext") {
00268             gROOT->SaveContext();
00269          }
00270          else if (sc == "SetStyle") {
00271             gROOT->SetStyle(cmd->PopOpt());
00272          }
00273          else {
00274             MSG("Root",Msg::kWarning) 
00275                << "\"" << sc << "\":"
00276                << " Not a valid command" << endl;
00277             throw BadJobCRootCmd();
00278          }
00279       }
00280       else {
00281          throw BadJobCRootCmd();
00282       }
00283    }
00284    catch ( BadJobCRootCmd ) {
00285       static bool firsthelp = true;
00286       if (firsthelp) Help();
00287       firsthelp = false;
00288    }
00289 }

void JobCRootModule::Help (  )  [virtual]

Implement to spew some useful help to cout

Reimplemented from JobCModule.

Definition at line 293 of file JobCRootModule.cxx.

References JobCModule::GetName(), Msg::kInfo, and MSG.

Referenced by HandleCommand().

00294 {
00295    //
00296    // Print help for this module
00297    //
00298 
00299    const char *name = this->GetName();
00300 
00301    MSG("JobC", Msg::kInfo)
00302       << "Help for '" << name << "': " 
00303       << name 
00304       << " is a JobCModule interfacing to ROOT from JobControl" << endl
00305       << "Commands implemented:" 
00306       << endl << endl
00307 //--------------
00308       << "  /" << name << "/RunMacro   <macro.C>    // root [] .x <macro.C>"
00309       << endl
00310       << "  /" << name << "/LoadMacro  <macro.C>    // root [] .L <macro.C>"
00311       << endl
00312       << "  /" << name << "/CompileMacro  <macro.C> // root [] .L <macro.C>+"
00313       << endl
00314       << "  /" << name << "/ForceCompileMacro  <macro.C> // root [] .L <macro.C>++"
00315       << endl
00316       << "     Run or Load a macro file, like .x or .L at ROOT prompt"
00317       << endl << endl
00318 //--------------
00319       << "  /" << name << "/ProcessLine <arbitrary text>"
00320       << endl
00321       << "     Process line just like at ROOT prompt"
00322       << endl << endl
00323 //--------------
00324       << "  /" << name << "/StartBrowser"
00325       << endl
00326       << "     Start a TBrowser"
00327       << endl << endl
00328 //--------------
00329       << "  /" << name << "/LoadLibrary <libraryName> "
00330       << endl
00331       << "     Make a dynamic library available (via gSystem)"
00332       << endl << endl
00333 //--------------
00334       << "  /" << name << "/LoadClass <className> <libraryName> "
00335       << endl
00336       << "     Make a class available out of a dynamic library (via gROOT)"
00337       << endl << endl
00338 //--------------
00339       << "  /" << name << "/MacroPath/Add <location(s)>"
00340       << endl
00341       << "  /" << name << "/MacroPath/Reset [<full list>]"
00342       << endl
00343       << "  /" << name << "/MacroPath/Show"
00344       << endl
00345       << "     Manipulate the locations where ROOT looks for macros;"
00346       << endl
00347       << "     path is a colon separated list:"
00348       << endl
00349       << "        Add to the front of the list"
00350       << endl
00351       << "        Reset to fixed value (default: initial ROOT defined value)"
00352       << endl
00353       << "        Show the current setting"
00354       << endl << endl
00355 //--------------
00356       << "  /" << name << "/ObjectStat/Set [1|0]"
00357       << endl
00358       << "  /" << name << "/ObjectStat/Print"
00359       << endl
00360       << "     TObject statistics collection (via gObjectTable):"
00361       << endl
00362       << "        Turn [on|off] the statistics collection (default: on)"
00363       << endl
00364       << "        Print the gObjectTable"
00365       << endl << endl
00366 //--------------
00367       << "  /" << name << "/Reset "
00368       << endl
00369       << "     Reset ROOT"
00370       << endl << endl
00371 //--------------
00372       << "  /" << name << "/SaveContext"
00373       << endl
00374       << "     Have the interpreter save the current context"
00375       << endl << endl
00376 //--------------
00377       << "  /" << name << "/SetStyle <styleName>"
00378       << endl
00379       << "     Set the ROOT Style"
00380       << endl << endl
00381 //--------------
00382       << endl;
00383 }

void JobCRootModule::InitRoot (  )  [static]

Definition at line 57 of file JobCRootModule.cxx.

References Msg::kDebug, Msg::kFatal, Msg::kVerbose, and MSG.

Referenced by HandleCommand(), and JobCRootCommandModule::Init().

00058 {
00059    // Perform any necessary initialization
00060    // including putting TApplication into TRint-like mode
00061    MSG("Root",Msg::kVerbose) << "JobCRootModule::InitRoot" << endl;
00062 
00063    static bool first = true;
00064    if (!first) return;
00065 
00066    first = false;
00067    // Make sure there is a TApp running
00068    // if we plan on using CINT facilities
00069    TApplication* app = gROOT->GetApplication();
00070    if (app) {
00071       TRint* trint = dynamic_cast<TRint*>(app);
00072       if (!trint) {
00073          MSG("Root",Msg::kDebug) 
00074             << "JobCRootModule::InitRoot not a TRint" << endl;
00075          // initialize Root's CINT to be more like it would be
00076          // if this were a TRint, while still not running
00077          // the user's 
00078          app->ProcessLine("#include <iostream.h>");
00079          
00080          // TRint would do the following:
00081 #ifdef TRINTLIKE
00082          // The following libs are also useful to have,
00083          // make sure they are loaded...
00084          gROOT->LoadClass("TGeometry",   "Graf3d");
00085          gROOT->LoadClass("TTree",       "Tree");
00086          gROOT->LoadClass("TMatrix",     "Matrix");
00087          gROOT->LoadClass("TMinuit",     "Minuit");
00088          gROOT->LoadClass("TPostScript", "Postscript");
00089          gROOT->LoadClass("TCanvas",     "Gpad");
00090          gROOT->LoadClass("THtml",       "Html");
00091 #endif
00092       } else {
00093          MSG("Root",Msg::kDebug)
00094             << "JobCRootModule::InitRoot was a TRint" << endl;
00095       }
00096       app->ProcessLine("#include <iomanip.h>");
00097       app->ProcessLine("#include <string>");
00098       gInterpreter->SaveContext();
00099       gInterpreter->SaveGlobalsContext();
00100    } else {
00101       MSG("Root",Msg::kFatal)
00102          << "JobCRootModule::InitRoot no TApplication" << endl;
00103    }
00104 
00105 }

static void JobCRootModule::PassPtrToRoot ( std::string  className,
std::string  instanceName,
const void *  ptr,
bool  isConst = false 
) [static]
void JobCRootModule::Report (  )  [virtual]

Implement to spew end of running report

Reimplemented from JobCModule.

Definition at line 43 of file JobCRootModule.cxx.

References Msg::kWarning, and MSG.

00044 {
00045    MSG("Root",Msg::kWarning) << "JobCRootModule::Report" << endl;
00046 }

void JobCRootModule::Reset (  )  [virtual]

Implement to reset oneself

Reimplemented from JobCModule.

Definition at line 50 of file JobCRootModule.cxx.

References Msg::kWarning, and MSG.

00051 {
00052    MSG("Root",Msg::kWarning) << "JobCRootModule::Reset" << endl;
00053 }


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1