JobCPathModule Class Reference

#include <JobCPathModule.h>

Inheritance diagram for JobCPathModule:
JobCModule

List of all members.

Public Member Functions

 JobCPathModule ()
 JobCPathModule (MomNavigator *mom, JobCInputModule *input)
virtual ~JobCPathModule ()
JobCPathCreate (const char *path, const char *nodes="")
void Delete (const char *path)
void Add (const char *path, const char *nodes, int n=-1)
void Remove ()
void Attach (const char *pathA, const char *pathB)
void Detach (const char *pathA, const char *pathB)
void Help ()
void Report ()
void Reset ()
JobCPathoperator() (const char *path)
const JobCPathRegistryGetPathRegistry () const
void HandleCommand (JobCommand *cmd)
void SetPathRegistry (JobCPathRegistry *pr)
void SetMom (MomNavigator *mom)
void SetInput (JobCInputModule *inp)
JobCPathModuleoperator= (const JobCPathModule &)

Private Attributes

MomNavigatorfMom
JobCInputModulefInput
JobCPathRegistryfPathRegistry
JobCPathfDummyPath

Detailed Description

Definition at line 40 of file JobCPathModule.h.


Constructor & Destructor Documentation

JobCPathModule::JobCPathModule (  ) 

Definition at line 33 of file JobCPathModule.cxx.

00033                                : 
00034   fMom(0), 
00035   fInput(0),
00036   fPathRegistry(0), 
00037   fDummyPath(0) 
00038 { }

JobCPathModule::JobCPathModule ( MomNavigator mom,
JobCInputModule input 
)

Definition at line 42 of file JobCPathModule.cxx.

00043                                                        : 
00044   fMom(mom),
00045   fInput(input),
00046   fPathRegistry(0), 
00047   fDummyPath(0) 
00048 { }

JobCPathModule::~JobCPathModule (  )  [virtual]

Definition at line 60 of file JobCPathModule.cxx.

References fDummyPath.

00061 {
00062 //======================================================================
00063 //Purpose: Delete the Path modules -- delete the paths owned by the
00064 //         module
00065 //======================================================================
00066   if (fDummyPath) { delete fDummyPath; fDummyPath = 0; }
00067 }


Member Function Documentation

void JobCPathModule::Add ( const char *  path,
const char *  nodes,
int  n = -1 
)

Definition at line 71 of file JobCPathModule.cxx.

References JobCPath::AddAt(), fPathRegistry, Msg::kDebug, Msg::kWarning, JobCPathRegistry::LookUpPath(), MSG, JobCPath::PushBack(), JobCommand::SplitLine(), and UtilString::StringTok().

Referenced by HandleCommand(), main(), and SetupInput().

00072 {
00073 //======================================================================
00074 // Purpose: Add a module::method pair to a path. The expected order of
00075 // options is: <path_name> <module>::<method> <module>::<method> ...
00076 //
00077 // Inputs: cmd - the job command
00078 //======================================================================
00079   JobCPath* p = fPathRegistry->LookUpPath(pathName);
00080   if (p) {
00081     int inode = 0;
00082     vector<string> nodelist;
00083     JobCommand::StringTok(nodelist, nodes, " ");
00084     vector<string>::iterator itr(nodelist.begin());
00085     vector<string>::iterator itrEnd(nodelist.end());
00086     for (; itr!=itrEnd; ++itr) {
00087       std::string module;
00088       std::string method;
00089       JobCommand::SplitLine((*itr).c_str(), ':', module, method);
00090       if (n>=0) {
00091         p->AddAt(module.c_str(),method.c_str(),n+inode);        
00092       }
00093       else {
00094         p->PushBack(module.c_str(), method.c_str());
00095       }
00096       ++inode;
00097     }
00098     MSG("JobC", Msg::kDebug) << "\n" << (*p) << endl;
00099   }
00100   else {
00101     MSG("JobC",Msg::kWarning) << "Can not find path '" << pathName << "'\n";
00102     return;
00103   }
00104 }

void JobCPathModule::Attach ( const char *  pathA,
const char *  pathB 
)

Definition at line 275 of file JobCPathModule.cxx.

References JobCPath::Attach(), fPathRegistry, JobCModule::GetName(), Msg::kError, JobCPathRegistry::LookUpPath(), and MSG.

Referenced by attach_blinded_output(), attach_mrcc_path(), attach_output(), attach_output_mc(), attach_output_mc_srsafitter(), attach_output_srsafitter(), HandleCommand(), and main().

00276 {
00277 //======================================================================
00278 // Purpose: Handle the "Attach" command which links one path to another
00279 //======================================================================
00280   if (n1==0 || n2==0) {
00281     MSG("JobC",Msg::kError) << 
00282       "Attach requires two path names as arguments.\n" <<
00283       "Example: '" << 
00284       this->GetName() << "/Attach path1 path2' will attach path2 to path1\n";
00285     return;
00286   }
00287   JobCPath *p1 = fPathRegistry->LookUpPath(n1);
00288   if (p1==0) {
00289     MSG("JobC",Msg::kError) << "Path '" << n1 << "' not found.\n";
00290     return;
00291   }
00292   JobCPath *p2 = fPathRegistry->LookUpPath(n2);
00293   if (p2==0) {
00294     MSG("JobC",Msg::kError) << "Path '" << n2 << "' not found.\n";
00295     return;
00296   }
00297   // Stick p2 onto p1
00298   p1->Attach(p2);
00299 }

JobCPath & JobCPathModule::Create ( const char *  path,
const char *  nodes = "" 
)

Definition at line 108 of file JobCPathModule.cxx.

References fInput, fMom, fPathRegistry, Msg::kDebug, Msg::kWarning, len, JobCPathRegistry::MakePath(), MSG, JobCPath::PushBack(), JobCommand::SplitLine(), and UtilString::StringTok().

Referenced by atmo_create_path_datafilter(), atmo_create_path_mc(), attach_blinded_output(), attach_mrcc_path(), attach_mrcc_path_far(), attach_mrcc_path_near(), attach_output(), attach_output_mc(), attach_output_mc_srfitter(), attach_output_mc_srsafitter(), attach_output_srfitter(), attach_output_srsafitter(), cosmic_create_path(), far_all_create_path(), far_all_mc_create_path(), far_cosmic_mc_create_path(), far_create_path(), far_mc_create_path(), far_spill_create_path(), HandleCommand(), job_setup(), main(), mc_reco_cosmic_create_path(), mc_reco_create_path(), mc_reco_far_create_path(), merge_create_path(), near_cosmic_create_path(), near_cosmic_mc_create_path(), near_create_path(), near_mc_create_path(), reroot_create_path(), run(), and spill_create_path().

00110 {
00111 //======================================================================
00112 // Purpose: Given a command line create a job path
00113 //
00114 // Inputs: cmd - The job command
00115 //======================================================================
00116   JobCPath *path;
00117 
00118   // Create the path and add it to the list ** Remember this module
00119   // owns the paths and has the responsibility to delete them! **
00120   path = fPathRegistry->MakePath(pathName,fMom,fInput);
00121   if (path == 0) {
00122     MSG("JobC",Msg::kWarning) << 
00123       "Failed to make path '" << pathName << "'. May already exist!\n";
00124     static JobCPath dummy;
00125     return dummy;
00126   }
00127     
00128   // Loop over remaining options and add nodes to the path
00129   vector<string> nodes;
00130   JobCommand::StringTok(nodes, nodeList, " ");
00131   vector<string>::iterator itr(nodes.begin());
00132   vector<string>::iterator itrEnd(nodes.end());
00133   for (; itr!=itrEnd; ++itr) {
00134     int len = strlen((*itr).c_str())+1;
00135     if (len>4) { // Need at least 4 char's to create a node name: 'a:b\0'
00136       // Valid node name
00137       std::string module;
00138       std::string method;
00139       JobCommand::SplitLine((*itr).c_str(), ':', module, method);
00140       path->PushBack(module.c_str(), method.c_str());
00141     }
00142     else {
00143       // Invalid node name
00144       MSG("JobC",Msg::kWarning) << 
00145         "'" << (*itr) << "' is not a valid module::method pair.\n";
00146       MSG("JobC",Msg::kWarning) << 
00147         "Attempt to create unnamed module::method pair ignored.\n";
00148     }
00149   }
00150 #ifdef SITE_HAS_SIGC
00151   this->SigNewPath(path);
00152 #endif
00153   MSG("JobC", Msg::kDebug) << "\n" << (*path) << endl; 
00154   return *path;
00155 }

void JobCPathModule::Delete ( const char *  path  ) 

Definition at line 159 of file JobCPathModule.cxx.

References JobCPathRegistry::DeletePath(), and fPathRegistry.

Referenced by HandleCommand().

00160 { 
00161 //======================================================================
00162 // Delete a path from the registry
00163 //======================================================================
00164   fPathRegistry->DeletePath(path);
00165 }

void JobCPathModule::Detach ( const char *  pathA,
const char *  pathB 
)

Definition at line 303 of file JobCPathModule.cxx.

References Msg::kWarning, MSG, and sorry().

Referenced by HandleCommand().

00304 { 
00305   MSG("JobC",Msg::kWarning) << 
00306     "Detach(" << pathA << "," << pathB <<") \n";
00307   sorry("JobCPathModule::Detach");
00308 }

const JobCPathRegistry* JobCPathModule::GetPathRegistry (  )  const [inline]

Definition at line 60 of file JobCPathModule.h.

References fPathRegistry.

Referenced by Jint::Jint().

00060 { return fPathRegistry; }

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

Implement to handle a JobCommand

Reimplemented from JobCModule.

Definition at line 169 of file JobCPathModule.cxx.

References Add(), Attach(), Create(), Delete(), Detach(), JobCModule::GetName(), JobCommand::HaveOpt(), Msg::kWarning, MSG, JobCommand::PopCmd(), JobCommand::PopOpt(), and Remove().

00170 {
00171 //======================================================================
00172 // Purpose: Switchyard for commands
00173 // 
00174 // Input: cmd - the job command
00175 //======================================================================
00176   string c = cmd->PopCmd();
00177   if (c=="Create") {
00178     string path  = cmd->PopOpt();
00179     string nodes;
00180     while (cmd->HaveOpt()) {
00181       nodes += cmd->PopOpt();
00182       nodes += " ";
00183     }
00184     this->Create(path.c_str(), nodes.c_str());
00185     return;
00186   }
00187   if (c=="Delete") {
00188     const char* path = cmd->PopOpt();
00189     this->Delete(path);
00190     return;
00191   }
00192   if (c=="Add") {
00193     const char* path = cmd->PopOpt();
00194     string nodes;
00195     while (cmd->HaveOpt()) {
00196       nodes += cmd->PopOpt();
00197       nodes += " ";
00198     }
00199     this->Add(path, nodes.c_str());
00200     return;
00201   }
00202   if (c=="Remove") {
00203     this->Remove();
00204     return;
00205   }
00206   if (c=="Attach") {
00207     const char* upStreamPath = cmd->PopOpt();
00208     const char* dnStreamPath = cmd->PopOpt();
00209     this->Attach(upStreamPath, dnStreamPath);
00210     return;
00211   }
00212   if (c=="Detach") {
00213     const char* path1 = cmd->PopOpt();
00214     const char* path2 = cmd->PopOpt();
00215     this->Detach(path1, path2);
00216     return;
00217   }
00218   // Fall through to here if nothing has handled the command
00219   MSG("JobC",Msg::kWarning) << 
00220     "Module " << this->GetName() << 
00221     " does not implement command " << c << "." << endl;
00222 }

void JobCPathModule::Help (  )  [virtual]

Implement to spew some useful help to cout

Reimplemented from JobCModule.

Definition at line 226 of file JobCPathModule.cxx.

References help(), Msg::kInfo, and MSG.

00227 {
00228 //======================================================================
00229 // Purpose: Print help for this job module
00230 //======================================================================
00231   static const char* help =
00232     "Help for 'Path' module:\n"
00233     "\n"
00234     " Path is a module for creating and holding the job paths and\n"
00235     " job modules used by your job. Possible commands are:\n"
00236     "\n"
00237     " /Path/Add <path> <module>::<method>\n"
00238     " /Path/Add <path> <module>::<method> <position>\n"
00239     "\n"
00240     "  Add module's '<module>' '<method>' to the path 'path' at\n"
00241     "  the <position> (1,2,3...). <position> is optional.\n"
00242     "\n"
00243     " /Path/Create <path>\n"
00244     " /Path/Create <path> <mod1>::<meth1> <mod2>::<meth2> ...\n"
00245     "\n"
00246     "  Create a path named 'path' and add nodes specified by the module \n"
00247     "  and method pairs <mod>::<meth> to it.\n"
00248     "\n"
00249     " /Path/Delete <path>\n"
00250     "\n"
00251     "  Delete the path named '<path>'\n"
00252     "\n"
00253     " /Path/Remove <module>\n"
00254     " /Path/Remove <module>::<method>\n"
00255     "\n"
00256     "  Remove the node <module>::<method> from a path\n"
00257     "  If <method> is not specified all nodes using <module> are removed.\n"
00258     "\n"
00259     " /Path/Attach <path1> <path2>\n"
00260     " /Path/Detach <path1> <path2>\n"
00261     "\n"
00262     "  Attach/Detach <path2> to/from <path1>\n";
00263   MSG("JobC", Msg::kInfo) << help << endl;
00264 }

JobCPath & JobCPathModule::operator() ( const char *  path  ) 

Definition at line 349 of file JobCPathModule.cxx.

References fDummyPath, fPathRegistry, Msg::kWarning, JobCPathRegistry::LookUpPath(), and MSG.

00350 {
00351 //======================================================================
00352 // Return a path by name
00353 //=======================================================================
00354   JobCPath* p = fPathRegistry->LookUpPath(path);
00355   if (p!=0) return (*p);
00356   
00357   MSG("JobC",Msg::kWarning) << "Failed to find path '" << path << "'.\n";
00358   if (fDummyPath == 0) fDummyPath = new JobCPath;
00359   return (*fDummyPath);
00360 }

JobCPathModule& JobCPathModule::operator= ( const JobCPathModule  )  [inline]

Definition at line 77 of file JobCPathModule.h.

00077 { abort(); return *this; } // no assignment

void JobCPathModule::Remove (  ) 

Definition at line 268 of file JobCPathModule.cxx.

References sorry().

Referenced by HandleCommand().

00269 { 
00270   sorry("JobCPathModule::Remove");
00271 }

void JobCPathModule::Report (  )  [virtual]

Implement to spew end of running report

Reimplemented from JobCModule.

Definition at line 312 of file JobCPathModule.cxx.

References fPathRegistry, JobCPathRegistry::GetPathBegin(), JobCPathRegistry::GetPathEnd(), Msg::kInfo, and MSG.

Referenced by attach_output_mc_srsafitter(), attach_output_srsafitter(), main(), and run().

00313 {
00314 //======================================================================
00315 // Print report for all active paths
00316 //======================================================================
00317   JobCPathRegistry::PathIterator itr(fPathRegistry->GetPathBegin());
00318   JobCPathRegistry::PathIterator itrEnd(fPathRegistry->GetPathEnd());
00319   bool ifirst = true;
00320   if (itr==itrEnd) {
00321     MSG("JobCReport",Msg::kInfo) << 
00322       "...................................." <<
00323       "....................................\n" <<
00324       "<no active paths>\n" <<
00325       "...................................." <<
00326       "....................................\n";
00327     return;
00328   }
00329   for (; itr!=itrEnd; ++itr) {
00330     if (ifirst) {
00331       MSG("JobCReport",Msg::kInfo) << 
00332         "...................................." <<
00333         "....................................\n";
00334       ifirst = false;
00335     }
00336     MSG("JobCReport",Msg::kInfo) << 
00337       (*(*itr)) << // Whoa, pointer to pointer...
00338       "...................................." <<
00339       "....................................\n";
00340   }
00341 }

void JobCPathModule::Reset (  )  [virtual]

Implement to reset oneself

Reimplemented from JobCModule.

Definition at line 345 of file JobCPathModule.cxx.

References fPathRegistry, and JobCPathRegistry::Reset().

00345 { fPathRegistry->Reset(); }

void JobCPathModule::SetInput ( JobCInputModule inp  )  [inline]

Definition at line 65 of file JobCPathModule.h.

References fInput.

Referenced by JobC::Init().

00065 { fInput = inp; }

void JobCPathModule::SetMom ( MomNavigator mom  )  [inline]

Definition at line 64 of file JobCPathModule.h.

References fMom.

Referenced by JobController::BuildSystemPath(), and JobC::Init().

00064 { fMom = mom; }

void JobCPathModule::SetPathRegistry ( JobCPathRegistry pr  ) 

Definition at line 52 of file JobCPathModule.cxx.

References fPathRegistry.

Referenced by JobController::BuildSystemPath(), and JobC::Init().

00053 {
00054   assert(pr);
00055   fPathRegistry = pr; 
00056 }


Member Data Documentation

Definition at line 84 of file JobCPathModule.h.

Referenced by operator()(), and ~JobCPathModule().

Definition at line 82 of file JobCPathModule.h.

Referenced by Create(), and SetInput().

Definition at line 81 of file JobCPathModule.h.

Referenced by Create(), and SetMom().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1