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

JobCNode.cxx

Go to the documentation of this file.
00001 
00002 // $Id: JobCNode.cxx,v 1.33 2002/05/14 23:29:03 rhatcher Exp $
00003 //
00004 // A module::method pair
00005 //
00006 // messier@huhepl.harvard.edu
00008 #include "JobControl/JobCNode.h"
00009 #include <cstring> // strcmp()
00010 #include <iomanip>
00011 extern "C" {
00012 #include <unistd.h>    // sysconf
00013 #include <sys/times.h> // times()
00014 }
00015 #include "MessageService/MsgService.h"
00016 #include "MessageService/MsgFormat.h"
00017 #include "JobControl/JobCResult.h"
00018 #include "JobControl/JobCModule.h"
00019 #include "JobControl/JobCMethod.h"
00020 
00021 CVSID("$Id: JobCNode.cxx,v 1.33 2002/05/14 23:29:03 rhatcher Exp $");
00022 
00023 ClassImp(JobCNode)
00024 
00025 //......................................................................
00026 
00027 ostream& operator<<(ostream& os, const JobCNode& n)
00028 {
00029   // Convert time to seconds 
00030   static double ticksPerSecond = sysconf(_SC_CLK_TCK); // units used by times()
00031   double ut = (float)n.fUserTime/ticksPerSecond;
00032   double st = (float)n.fSystemTime/ticksPerSecond;
00033   
00034   MsgFormat ifmt1("%-6d");
00035   MsgFormat ifmt2("%6d");
00036   MsgFormat dfmt("%8.2f");
00037 
00038   string modmeth = n.fModule->GetName();
00039   modmeth += "::";
00040   modmeth += n.fMethod->GetName();
00041   
00042   if (n.fFilterActive) {
00043     if (n.fFilterReverse) {
00044       os << "!";
00045     }
00046     else {
00047       os << "+";
00048     }
00049   }
00050   else {
00051     os << " ";
00052   }
00053   os.setf(ios::left); // Set format to left justified
00054   os.fill(' ');
00055   os << setw(25);
00056   os << modmeth.c_str();
00057   
00058   os << " n=" 
00059      << ifmt1(n.fNin) 
00060      << "("
00061      << ifmt2(n.fNpass) 
00062      << "/" 
00063      << ifmt2(n.fNfail) 
00064      << ")"
00065      << " t=(" 
00066      << dfmt(ut) 
00067      << "/" 
00068      << dfmt(st) 
00069      << ")";
00070   return os;
00071 }
00072 
00073 //......................................................................
00074 
00075 void JobCNode::Init() 
00076 {
00077 //======================================================================
00078 // Purpose: Initialize this node
00079 //======================================================================
00080   fModule = 0;
00081   fMethod = 0;
00082   fFilterActive  = true;
00083   fFilterReverse = false;
00084   fNin   = 0;
00085   fNpass = 0;
00086   fNfail = 0;
00087   fUserTime   = 0l;
00088   fSystemTime = 0l;
00089 }
00090 
00091 //......................................................................
00092 
00093 JobCNode::JobCNode() 
00094 {
00095 //======================================================================
00096 // Purpose: Create an empty node
00097 //======================================================================
00098   this->Init();
00099 }
00100 
00101 //......................................................................
00102 
00103 JobCNode::JobCNode(JobCModule* module, const JobCMethod* method)
00104 {
00105 //======================================================================
00106 // Purpose: Create a node give a module and a method pair
00107 //
00108 // Inputs: module - the module to use
00109 //         method - the module's method to use
00110 //======================================================================
00111   this->Init();
00112 
00113   // Set the module and method for this node
00114   fModule = module;
00115   fMethod = method;
00116   
00117   // Make sure the module implementes this method
00118   if (fMethod->Exists(fModule) == false) {
00119     MSG("JobC", Msg::kWarning) 
00120       << "Module does not implement this method\n";
00121     fModule = 0;
00122     fMethod = 0;
00123     return;
00124   }
00125 }
00126 
00127 //......................................................................
00128 
00129 JobCNode::~JobCNode() {}
00130 
00131 //......................................................................
00132 
00133 JobCResult JobCNode::Execute(MomNavigator *mom)
00134 {
00135 //======================================================================
00136 // Purpose: Give this node a look at a data records
00137 //
00138 // Inputs: mom - the MINOS Object Map that holds the data to process
00139 //
00140 // Returns: Pass/Fail/No Decision depending on how the data record
00141 //          is evaluted by the module::method
00142 //======================================================================
00143   clock_t dummyt;    // Unused return variable
00144   struct tms t1;     // Times before execution of node
00145   struct tms t2;     // Times after execution of node
00146   JobCResult result; // Result of node
00147 
00148   // Evaluate the data record -- keep track of the time it takes...
00149   dummyt = times(&t1);
00150   result = fMethod->Execute(fModule, mom);
00151   dummyt = times(&t2);
00152 
00153   fUserTime   += (t2.tms_utime-t1.tms_utime);
00154   fSystemTime += (t2.tms_stime-t1.tms_stime);
00155 
00156   // If we've reached the end of input, return before accumulating
00157   // statistics
00158   if (result.EndOfInputStream()) return result;
00159 
00160   // Count records seen
00161   ++fNin;
00162 
00163   // Count records passed and failed at each node
00164   if (result.Failed()) {
00165     ++fNfail;
00166   } 
00167   else {
00168     // "No-decisions" and "Passed" count as pass
00169     ++fNpass;
00170   }
00171   
00172   // Determine return type
00173   if (fFilterActive) {
00174     if (fFilterReverse) {
00175       // Reverse the meaning of pass/fail
00176       if      (result.Passed()) result.SetFailed(); 
00177       else if (result.Failed()) result.SetPassed();
00178     }
00179   }
00180   else {
00181     // The filter is not active -- clear any pass/fail decisions
00182     result.ClearPassFail();
00183   }
00184 
00185   return result;
00186 }
00187 
00188 //......................................................................
00189 
00190 bool JobCNode::MatchModuleMethod(const char* mod, const char* meth) 
00191 {
00192 //======================================================================
00193 // Purpose: Check if this node matches a module::method pair
00194 //
00195 // Inputs: mod  - name of the module
00196 //         meth - name of the method
00197 //
00198 // Returns: true/false depending on if this node is a perfect match
00199 //======================================================================
00200   if (strcmp(mod ,fModule->GetName())==0 && 
00201       strcmp(meth,fMethod->GetName())==0) {
00202     return true;
00203   }
00204   return false;
00205 }
00206 
00207 //......................................................................
00208 
00209 JobCModule* JobCNode::GetModule() const { return fModule; }
00210 
00211 //......................................................................
00212 
00213 JobCMethod JobCNode::GetMethod() const
00214 {
00215 //======================================================================
00216 // Purpose: Return the method this node uses
00217 //======================================================================
00218   return (*fMethod);
00219 }
00220 
00221 //......................................................................
00222 
00223 void JobCNode::SetModule(JobCModule *module)
00224 {
00225 //======================================================================
00226 // Purpose: Set the module this node should use
00227 //
00228 // Inputs: module - pointer to the job module to use at this node
00229 //======================================================================
00230   fModule = module;
00231   if (fModule == 0) {
00232     MSG("JobC", Msg::kError) 
00233       << "Attempt to set NULL module.\n";
00234   }
00235 }
00236 
00237 //......................................................................
00238 
00239 void JobCNode::SetMethod(JobCMethod *method)
00240 {
00241 //======================================================================
00242 // Purpose: Set the method this node should call
00243 //
00244 // Inputs: method - pointer to the method to use at this node
00245 //======================================================================
00246   fMethod = method;
00247   if (fMethod == 0) {
00248     MSG("JobC", Msg::kError) 
00249       << "Attempt to set NULL method.\n";
00250   }
00251 }
00252 
00253 //......................................................................
00254 
00255 void JobCNode::FilterOn()  
00256 {
00257 //======================================================================
00258 // Purpose: Activate filtering on this node
00259 //======================================================================
00260   fFilterActive = true;
00261 #ifdef SITE_HAS_SIGC
00262   this->SigUpdate(this,JobCNode::kFilter);
00263 #endif
00264 }
00265 
00266 //......................................................................
00267 
00268 void JobCNode::FilterOff() 
00269 {
00270 //======================================================================
00271 // Purpose: Deactivate filtering on this node
00272 //======================================================================
00273   fFilterActive = false;
00274 #ifdef SITE_HAS_SIGC
00275   this->SigUpdate(this,JobCNode::kFilter);
00276 #endif
00277 }
00278 
00279 //......................................................................
00280 
00281 void JobCNode::ReverseFilter() 
00282 {
00283 //======================================================================
00284 // Purpose: Reverse the meaning of pass/fail for this node
00285 //======================================================================
00286   fFilterActive  = true;
00287   fFilterReverse = !fFilterReverse;
00288 #ifdef SITE_HAS_SIGC
00289   this->SigUpdate(this,JobCNode::kFilter);
00290 #endif
00291 }
00292 

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