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

JobCPathHandler.cxx

Go to the documentation of this file.
00001 
00002 // $Id: JobCPathHandler.cxx,v 1.4 2009/02/28 21:46:13 gmieg Exp $
00003 //
00004 // Interface between JobCommand's and JobCPath classes
00005 //
00006 // messier@huhepl.harvard.edu
00008 #include <cstring> // strcmp()
00009 
00010 #include "JobControl/JobCPathHandler.h"
00011 #include "MessageService/MsgService.h"
00012 #include "JobControl/JobCommand.h"
00013 #include "JobControl/JobCPath.h"
00014 #include "JobControl/JobCNode.h"
00015 
00016 CVSID("$Id: JobCPathHandler.cxx,v 1.4 2009/02/28 21:46:13 gmieg Exp $");
00017 
00018 //......................................................................
00019 
00020 static void sorry(const char* method) 
00021 {
00022   MSG("JobC",Msg::kWarning) << 
00023     "Sorry, method " << method << " not implemented." << endl;
00024 }
00025 
00026 //......................................................................
00027 
00028 JobCPathHandler::JobCPathHandler() : fPath(0) { }
00029 
00030 //......................................................................
00031 
00032 JobCPathHandler::JobCPathHandler(JobCPath* p) : fPath(p) { }
00033 
00034 //......................................................................
00035 
00036 JobCPathHandler::~JobCPathHandler() { }
00037 
00038 //......................................................................
00039 
00040 void JobCPathHandler::HandleCommand(JobCommand *cmd) 
00041 {
00042 //======================================================================
00043 // Purpose: Switch yard for commands that act on paths as a whole
00044 // 
00045 // Inputs: path - the job path to act on
00046 //         cmd  - the job command to use to decide how to act on the 
00047 //                path
00048 //======================================================================
00049   const char *c = cmd->PopCmd();
00050   if (c) {
00051     if (strcmp(c,"Run")==0)    {this->PathRunCommand   (fPath, cmd); return;}
00052     if (strcmp(c,"Filter")==0) {this->PathFilterCommand(fPath, cmd); return;}
00053     if (strcmp(c,"Report")==0) {this->PathReportCommand(fPath, cmd); return;}
00054     if (strcmp(c,"Reset")==0)  {this->PathResetCommand (fPath, cmd); return;}
00055     MSG("JobC", Msg::kWarning) << 
00056       "Unknown command '" << c << "'." <<
00057       " Try one of the following:\n" <<
00058       " Run,Filter,Report,Reset\n";
00059   }
00060 }
00061 
00062 //......................................................................
00063 
00064 void JobCPathHandler::PathRunCommand(JobCPath *p, JobCommand *cmd) 
00065 {
00066 //======================================================================
00067 // Purpose: handle a /<path>/Run [Nin,Npass,Nfail] [n] command
00068 //
00069 // Inputs: p   - the path <path>
00070 //         cmd - the job command
00071 //======================================================================
00072   // Figure out how many options we've been given
00073   const char* c[2];
00074   int nopt = 0;
00075   while (cmd->HaveOpt() && nopt<2) {
00076     c[nopt] = cmd->PopOpt();
00077     ++nopt;
00078   }
00079 
00080   // No options - run until there are no records left to process
00081   if (nopt == 0) {
00082     p->Run();
00083     return;
00084   }
00085 
00086   // One option -- assume this is some number of events to process
00087   if (nopt == 1) {
00088     int n = atoi(c[0]);
00089     p->RunNin(n);   
00090     return;
00091   }
00092 
00093   // Two options -- [Nin,Npass,Nfail] [# records]
00094   if (nopt == 2) {
00095     int n = atoi(c[1]);
00096     if (strcmp(c[0],"Nin")==0)   { p->RunNin(n);   return; }
00097     if (strcmp(c[0],"Npass")==0) { p->RunNpass(n); return; }
00098     if (strcmp(c[0],"Nfail")==0) { p->RunNfail(n); return; }
00099   }
00100   
00101   // Errors fall through
00102   const char* nm = p->GetName();
00103   MSG("JobC", Msg::kWarning) << 
00104     "usage: \n" 
00105     " " << nm << "/Run Nin   [n] - run until n records have been input\n" <<
00106     " " << nm << "/Run Npass [n] - run until n records pass\n"
00107     " " << nm << "/Run Nfail [n] - run until n records fail\n"
00108     " " << nm << "/Run [n]       - same as /Run Nin [n]\n";
00109 }
00110 
00111 //......................................................................
00112 
00113 void JobCPathHandler::PathFilterCommand(JobCPath* p, JobCommand* cmd) 
00114 { 
00115 //======================================================================
00116 // Purpose: Process filter command
00117 //======================================================================
00118   while (cmd->HaveOpt()) {
00119     const char* node  = cmd->PopOpt();
00120     const char* onOff = cmd->PopOpt();
00121     if (node == 0 || onOff == 0) {
00122       MSG("JobC",Msg::kWarning) <<
00123         "Usage: Filter <module>::<method> [on,reverse,off] ...\n" <<
00124         "       Filter all [on,off]\n";
00125       return;
00126     }
00127     
00128     string onOffs(onOff);
00129     string nodes(node);
00130     if (nodes == "ALL" || nodes == "all") {
00131       if (onOffs == "on" || onOffs == "ON") {
00132         p->SetAllFilters(true);
00133         return;
00134       }
00135       else if (onOffs == "reverse" || onOffs == "REVERSE") {
00136         p->ReverseAllFilters();
00137         return;
00138       }
00139     }
00140     
00141     // Get the module method pair that describe the node
00142     string mod;
00143     string method;
00144     JobCommand::SplitLine(node,':',mod,method);
00145     JobCNode* nodep = p->FindNode(mod.c_str(), method.c_str());
00146     if (nodep == 0) {
00147       MSG("JobC",Msg::kWarning) <<
00148         "Can't find node " << mod << "::" << method << ". Skipped.\n";
00149     }
00150     else {
00151       if (onOffs == "on" || onOffs == "ON") {
00152         nodep->FilterOn();
00153       }
00154       else if (onOffs == "reverse" || onOffs == "REVERSE") {
00155         nodep->ReverseFilter();
00156       }
00157       else {
00158         nodep->FilterOff();
00159       }
00160     }
00161   }
00162 }
00163 
00164 //......................................................................
00165 
00166 void JobCPathHandler::PathReportCommand(JobCPath* p, JobCommand* /*cmd*/) 
00167 { 
00168 //======================================================================
00169 // Purpose: Print the status of a given path
00170 //======================================================================
00171   MSG("JobC",Msg::kInfo) << (*p) << endl;
00172 }
00173 
00174 //......................................................................
00175 
00176 void JobCPathHandler::PathResetCommand(JobCPath* /*p*/, 
00177                                        JobCommand* /*cmd*/)  
00178 { 
00179   sorry("PathResetCommand"); 
00180 }
00181 

Generated on Mon Feb 15 11:06:49 2010 for loon by  doxygen 1.3.9.1