gen_module.cc File Reference

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include "Util/UtilString.h"

Go to the source code of this file.

Classes

class  ConfigParam
class  ModuleOptions

Typedefs

typedef std::vector< ConfigParamModuleConfig

Functions

static bool yn_querry (const char *t, bool deflt)
static std::string str_querry (const char *t, const char *deflt)
static void setupNames (ModuleOptions &m)
static void setupMethods (ModuleOptions &m)
static void setupServices (ModuleOptions &m)
static void parseCfg (std::string str, ConfigParam &p)
static void setupConfig (ModuleOptions &m, ModuleConfig &cfg)
static void write_h (const ModuleOptions &m, ModuleConfig &cfg)
static void write_method (const char *type_s, const char *meth, const char *return_s, const ModuleOptions &m, std::ofstream &ofs)
static void write_constructor (const ModuleOptions &m, const ModuleConfig &cfg, std::ofstream &ofs)
static void write_default_config_method (const ModuleOptions &m, const ModuleConfig &cfg, std::ofstream &ofs)
static void write_config_method (const ModuleOptions &m, const ModuleConfig &cfg, std::ofstream &ofs)
static void write_config_methods (const ModuleOptions &m, const ModuleConfig &cfg, std::ofstream &ofs)
static void write_cxx (const ModuleOptions &m, const ModuleConfig &cfg)
static void getSetup (ModuleOptions &m, ModuleConfig &cfg)
static void doWrite (ModuleOptions &m, ModuleConfig &cfg)
int main (void)

Variables

static const char * gsDocComment
static const char * gsSlashDivider
static const char * gsEqualsDivider
static const char * gsDotDivider

Typedef Documentation

typedef std::vector<ConfigParam> ModuleConfig

Definition at line 27 of file gen_module.cc.


Function Documentation

static void doWrite ( ModuleOptions m,
ModuleConfig cfg 
) [static]

Definition at line 662 of file gen_module.cc.

References write_cxx(), and write_h().

Referenced by main().

00662                                                          {
00663   write_h(m,cfg);
00664   write_cxx(m,cfg);
00665 }

static void getSetup ( ModuleOptions m,
ModuleConfig cfg 
) [static]

Definition at line 653 of file gen_module.cc.

References setupConfig(), setupMethods(), setupNames(), and setupServices().

Referenced by main().

00653                                                           {
00654   setupNames(m);
00655   setupMethods(m);
00656   setupServices(m);
00657   setupConfig(m,cfg);
00658 }

int main ( void   ) 

Definition at line 669 of file gen_module.cc.

References doWrite(), getSetup(), and Munits::m.

00669                {
00670   ModuleOptions m;
00671   ModuleConfig  cfg;
00672   
00673   getSetup(m,cfg);
00674   doWrite(m,cfg);
00675 }

static void parseCfg ( std::string  str,
ConfigParam p 
) [static]

Definition at line 165 of file gen_module.cc.

References ConfigParam::fName, ConfigParam::fType, ConfigParam::fValue, UtilString::IsBool(), UtilString::IsFloat(), and UtilString::IsInt().

Referenced by setupConfig().

00166 {
00167 //======================================================================
00168 // Extract information about parameter name, type, and value from a
00169 // string like "name=10.0"
00170 //======================================================================
00171   std::string name;
00172   std::string value;
00173   const char* s = str.c_str();
00174   const char* c;
00175   
00176   name  = "";
00177   value = "";
00178   bool passedEqual = false;
00179   for (c=s; *c!='\0'; ++c) {
00180     switch (*c) {
00181     case '=': passedEqual = true; break;
00182     case ' ': continue;           break;
00183     default:
00184       if (passedEqual) value += *c;
00185       else name += *c;
00186     }
00187   }
00188   p.fName  = name;
00189   p.fValue = value;
00190 
00191   // Assign type to value. Test for float must preceed int
00192   s = p.fValue.c_str();
00193   p.fType = "string";
00194   if (UtilString::IsBool(s))  { p.fType = "bool";  }
00195   if (UtilString::IsFloat(s)) { p.fType = "float"; }
00196   if (UtilString::IsInt(s))   { p.fType = "int";   }
00197 }

static void setupConfig ( ModuleOptions m,
ModuleConfig cfg 
) [static]

Definition at line 201 of file gen_module.cc.

References ModuleOptions::fNeedConfig, parseCfg(), str_querry(), and yn_querry().

Referenced by getSetup().

00202 {
00203 //======================================================================
00204 // Querry user for information about their module's configuration
00205 //======================================================================
00206   m.fNeedConfig = 
00207     yn_querry("Do you want to set up the module's configuration parameters? ",
00208               true);
00209   if (m.fNeedConfig == false) {
00210     return;
00211   }
00212   
00213   std::cout << "  Enter parameter list following these examples:"<<std::endl;
00214   std::cout << "    bool parameter:   > DoTest    = true"<<std::endl;
00215   std::cout << "    int parameter:    > NhitMax   = 20"<<std::endl;
00216   std::cout << "    real parameter:   > ChiSqrCut = 10.0"<<std::endl;
00217   std::cout << "    string parameter: > UseStream = DaqSnarl"<<std::endl;
00218   std::cout << "  Enter 'q' to end\n";
00219   
00220   bool more = true;
00221   std::string s;
00222   while (more) {
00223     s = str_querry("[name = default_value] ",0);
00224     if (s == "q" || s == "Q" || s=="" || s==" ") { 
00225       more = false; 
00226     }
00227     else {
00228       ConfigParam p;
00229       parseCfg(s,p);
00230       cfg.push_back(p);
00231     }
00232   }
00233 }

static void setupMethods ( ModuleOptions m  )  [static]

Definition at line 128 of file gen_module.cc.

References ModuleOptions::fNeedAna, ModuleOptions::fNeedBeginFile, ModuleOptions::fNeedBeginJob, ModuleOptions::fNeedBeginRun, ModuleOptions::fNeedEndFile, ModuleOptions::fNeedEndJob, ModuleOptions::fNeedEndRun, ModuleOptions::fNeedGet, ModuleOptions::fNeedHandleCommand, ModuleOptions::fNeedHelp, ModuleOptions::fNeedPut, ModuleOptions::fNeedReco, ModuleOptions::fNeedReport, ModuleOptions::fNeedReset, and yn_querry().

Referenced by getSetup().

00129 {
00130 //======================================================================
00131 // Ask users what methods they want in their job module
00132 //======================================================================
00133   std::cout << "Which methods do you need? (Select [y/n])"<<std::endl;
00134   m.fNeedAna           = yn_querry("  Ana()           ? ", true);
00135   m.fNeedReco          = yn_querry("  Reco()          ? ", true);
00136   m.fNeedBeginJob      = yn_querry("  BeginJob()      ? ", true);
00137   m.fNeedEndJob        = yn_querry("  EndJob()        ? ", false);
00138   m.fNeedBeginFile     = yn_querry("  BeginFile()     ? ", false);
00139   m.fNeedEndFile       = yn_querry("  EndFile()       ? ", false);
00140   m.fNeedBeginRun      = yn_querry("  BeginRun()      ? ", false);
00141   m.fNeedEndRun        = yn_querry("  EndRun()        ? ", false);
00142   m.fNeedGet           = yn_querry("  Get()           ? ", false);
00143   m.fNeedPut           = yn_querry("  Put()           ? ", false);
00144   m.fNeedHelp          = yn_querry("  Help()          ? ", false);
00145   m.fNeedReport        = yn_querry("  Report()        ? ", false);
00146   m.fNeedReset         = yn_querry("  Reset()         ? ", false);
00147   m.fNeedHandleCommand = yn_querry("  HandleCommand() ? ", false);
00148 }

static void setupNames ( ModuleOptions m  )  [static]

Definition at line 114 of file gen_module.cc.

References ModuleOptions::fClassName, ModuleOptions::fDescription, ModuleOptions::fEmailAddr, ModuleOptions::fModuleName, ModuleOptions::fPackageName, and str_querry().

Referenced by getSetup().

00115 {
00116 //======================================================================
00117 // Querry user for names of things in the module
00118 //======================================================================
00119   m.fClassName  =str_querry("Class name",0);
00120   m.fPackageName=str_querry("Package name",0);
00121   m.fModuleName =str_querry("Human readable name of the module",0);
00122   m.fDescription=str_querry("Short description of what the module does",0);
00123   m.fEmailAddr  =str_querry("Your e-mail address",0);
00124 }

static void setupServices ( ModuleOptions m  )  [static]

Definition at line 152 of file gen_module.cc.

References ModuleOptions::fNeedMsg, ModuleOptions::fPackagePrefix, str_querry(), and yn_querry().

Referenced by getSetup().

00153 {
00154 //======================================================================
00155 // Querry user about what services their module will use
00156 //======================================================================
00157   m.fNeedMsg = yn_querry("Do you plan to use the MessageService? ",true);
00158   if (m.fNeedMsg) {
00159     m.fPackagePrefix = str_querry("  What's the package prefix? ",0);
00160   }
00161 }

static std::string str_querry ( const char *  t,
const char *  deflt 
) [static]

Definition at line 96 of file gen_module.cc.

Referenced by setupConfig(), setupNames(), and setupServices().

00097 {
00098 //======================================================================
00099 // Prompt user for string response. Print text t. Return deflt is user
00100 // provides no input.
00101 //======================================================================
00102   if (deflt==0 || std::string(deflt)=="") std::cout << t << " : ";
00103   else                                    std::cout << t << "[" << deflt << "] :";
00104   std::cout << std::flush;
00105 
00106   std::string s;
00107   getline(std::cin, s);
00108 
00109   return s;
00110 }

static void write_config_method ( const ModuleOptions m,
const ModuleConfig cfg,
std::ofstream &  ofs 
) [static]

Definition at line 474 of file gen_module.cc.

References ModuleOptions::fClassName, gsDotDivider, and gsEqualsDivider.

Referenced by write_config_methods().

00477 {
00478 //======================================================================
00479 // Write some template code for the Config() method
00480 //======================================================================
00481   ofs << gsDotDivider << std::endl;
00482   ofs << std::endl;
00483   ofs << "void " << m.fClassName << "::Config(const Registry& r)"
00484       << std::endl;
00485   ofs << "{" << std::endl;
00486   ofs << "  " << gsEqualsDivider << std::endl;
00487   ofs << "  /// Configure the module given the Registry r" << std::endl;
00488   ofs << "  " << gsEqualsDivider << std::endl;
00489   
00490   ModuleConfig::const_iterator itr(cfg.begin());
00491   ModuleConfig::const_iterator itrEnd(cfg.end());
00492   for (; itr!=itrEnd; ++itr) {
00493     ofs << "  f" << itr->fName << " = ";
00494     if (itr->fType == "bool")   ofs << "r.GetInt";
00495     if (itr->fType == "int")    ofs << "r.GetInt";
00496     if (itr->fType == "float")  ofs << "r.GetDouble";
00497     if (itr->fType == "string") ofs << "r.GetCharString";
00498     ofs << "(\"" << itr->fName << "\");" << std::endl;
00499   }
00500   ofs << "}" << std::endl;
00501   ofs << std::endl;
00502 
00503   return;
00504 
00505   /*
00506   bool need_tmpb = false;
00507   bool need_tmpi = false;
00508   bool need_tmpd = false;
00509   bool need_tmps = false;
00510 
00511   ModuleConfig::const_iterator itr(cfg.begin());
00512   ModuleConfig::const_iterator itrEnd(cfg.end());
00513   for (; itr!=itrEnd; ++itr) {
00514     if (itr->fType == "bool")   need_tmpb = true;
00515     if (itr->fType == "int")    need_tmpi = true;
00516     if (itr->fType == "float")  need_tmpd = true;
00517     if (itr->fType == "string") need_tmps = true;
00518   }
00519 
00520   ofs << gsDotDivider << std::endl;
00521   ofs << std::endl;
00522   ofs << "void " << m.fClassName << "::Config(const Registry& r)"
00523       << std::endl;
00524   ofs << "{" << std::endl;
00525   ofs << gsEqualsDivider << std::endl;
00526   ofs << "// Configure the module given the Registry r" << std::endl;
00527   ofs << gsEqualsDivider << std::endl;
00528 
00529   // On most systems, the bool's get implicitly converted to int's
00530   if (need_tmpb) ofs << "  int    tmpb;" << std::endl;
00531   if (need_tmpi) ofs << "  int    tmpi;" << std::endl;
00532   if (need_tmpd) ofs << "  double tmpd;" << std::endl;
00533   if (need_tmps) ofs << "  const char* tmps;" << std::endl;
00534   ofs << std::endl;
00535   
00536   for (itr=cfg.begin(); itr!=itrEnd; ++itr) {
00537     ofs << "  if (r.Get(\"" << itr->fName << "\",";
00538     if (itr->fType == "bool")   { ofs << "tmpb"; }
00539     if (itr->fType == "int")    { ofs << "tmpi"; }
00540     if (itr->fType == "float")  { ofs << "tmpd"; }
00541     if (itr->fType == "string") { ofs << "tmps"; }
00542     ofs << ")) { fData = ";
00543     if (itr->fType == "bool")   { ofs << "tmpb"; }
00544     if (itr->fType == "int")    { ofs << "tmpi"; }
00545     if (itr->fType == "float")  { ofs << "tmpd"; }
00546     if (itr->fType == "string") { ofs << "tmps"; }
00547     ofs << "; }" << std::endl;
00548   }
00549   ofs << "}" << std::endl;
00550   ofs << std::endl;
00551   */
00552 }

static void write_config_methods ( const ModuleOptions m,
const ModuleConfig cfg,
std::ofstream &  ofs 
) [static]

Definition at line 556 of file gen_module.cc.

References write_config_method(), and write_default_config_method().

Referenced by write_cxx().

00559 {
00560 //======================================================================
00561 // Write the methods which handle the module configuration
00562 //======================================================================
00563   write_default_config_method(m,cfg,ofs);
00564   write_config_method(m,cfg,ofs);
00565 }

static void write_constructor ( const ModuleOptions m,
const ModuleConfig cfg,
std::ofstream &  ofs 
) [static]

Definition at line 385 of file gen_module.cc.

References ModuleOptions::fClassName, ModuleOptions::fNeedConfig, gsDocComment, gsDotDivider, and gsEqualsDivider.

Referenced by write_cxx().

00388 {
00389   ofs << gsDotDivider << std::endl;
00390   ofs << std::endl;
00391   ofs << m.fClassName << "::" << m.fClassName << "()";
00392   if(m.fNeedConfig) {
00393     ofs << " : ";
00394     ModuleConfig::const_iterator itr(cfg.begin());
00395     ModuleConfig::const_iterator itrEnd(cfg.end());
00396     for (itr=cfg.begin(); itr!=itrEnd; ++itr) {
00397       ofs << std::endl;
00398       ofs << "  f" << itr->fName << "(";
00399       if (itr->fType == "bool")   { ofs << "false"; }
00400       if (itr->fType == "int")    { ofs << "0"; }
00401       if (itr->fType == "float")  { ofs << "0.0"; }
00402       if (itr->fType == "string") { ofs << "\"\""; }
00403       ofs << ")";
00404       if(itr+1 != itrEnd) ofs << ",";
00405     }
00406   }
00407   ofs << std::endl;
00408   ofs << "{" << std::endl;
00409   ofs << "  " << gsEqualsDivider << std::endl;
00410   ofs << "  " << gsDocComment << std::endl;
00411   ofs << "  " << gsEqualsDivider << std::endl;
00412   ofs << "}" << std::endl;
00413    
00414  
00415 }

static void write_cxx ( const ModuleOptions m,
const ModuleConfig cfg 
) [static]

Definition at line 570 of file gen_module.cc.

References ModuleOptions::fClassName, ModuleOptions::fDescription, ModuleOptions::fEmailAddr, ModuleOptions::fModuleName, ModuleOptions::fNeedAna, ModuleOptions::fNeedBeginFile, ModuleOptions::fNeedBeginJob, ModuleOptions::fNeedBeginRun, ModuleOptions::fNeedConfig, ModuleOptions::fNeedEndFile, ModuleOptions::fNeedEndJob, ModuleOptions::fNeedEndRun, ModuleOptions::fNeedGet, ModuleOptions::fNeedHandleCommand, ModuleOptions::fNeedHelp, ModuleOptions::fNeedMsg, ModuleOptions::fNeedPut, ModuleOptions::fNeedReco, ModuleOptions::fNeedReport, ModuleOptions::fNeedReset, gsDocComment, gsSlashDivider, write_config_methods(), write_constructor(), and write_method().

Referenced by doWrite().

00571 {
00572 //======================================================================
00573 // Write the implementation file for the module
00574 //======================================================================
00575   std::string filename = m.fClassName;
00576   filename += ".cxx";
00577   std::ofstream ofs(filename.c_str());
00578 
00579   ofs << gsSlashDivider << std::endl;
00580   ofs << "/// $Id: gen_module.cc,v 1.5 2010/08/12 16:13:52 rhatcher Exp $" << std::endl;
00581   ofs << "///" << std::endl;
00582   ofs << gsDocComment << std::endl;
00583   ofs << "///" << std::endl;
00584   ofs << "/// " << m.fEmailAddr << std::endl;
00585   ofs << gsSlashDivider << std::endl;
00586   
00587   // Includes...
00588   ofs << 
00589     "#include \""<<m.fClassName<<".h\""<<std::endl;
00590   if (m.fNeedMsg) {
00591     ofs << "#include \"MessageService/MsgService.h\"" << std::endl;
00592   }
00593   ofs << "#include \"MinosObjectMap/MomNavigator.h\"" << std::endl;
00594   ofs << "#include \"JobControl/JobCModuleRegistry.h\" // For JOBMODULE macro"
00595       << std::endl;
00596   ofs << std::endl;
00597 
00598   // Global static data
00599   ofs << "JOBMODULE(" << m.fClassName << ", \"" << m.fModuleName << "\",\n"
00600       << "          \"" << m.fDescription << "\");" << std::endl;
00601   if (m.fNeedMsg) {
00602     ofs << "CVSID(\"$Id: gen_module.cc,v 1.5 2010/08/12 16:13:52 rhatcher Exp $\");" << std::endl;
00603   }
00604 
00605   // Constructor
00606   write_constructor(m,cfg,ofs);
00607   //std::string s = m.fClassName; s+= "()";
00608   //write_method("", s.c_str(), "", m, ofs);
00609 
00610   // Destructor
00611   std::string s = "~"; s += m.fClassName; s+= "()";
00612   write_method("", s.c_str(), "", m, ofs);
00613 
00614   // Status change handlers
00615   if (m.fNeedBeginJob)  write_method("void", "BeginJob()",  "", m, ofs);
00616   if (m.fNeedEndJob)    write_method("void", "EndJob()",    "", m, ofs);
00617   if (m.fNeedBeginFile) write_method("void", "BeginFile()", "", m, ofs);
00618   if (m.fNeedEndFile)   write_method("void", "EndFile()",   "", m, ofs);
00619   if (m.fNeedBeginRun)  write_method("void", "BeginRun()",  "", m, ofs);
00620   if (m.fNeedEndRun)    write_method("void", "EndRun()",    "", m, ofs);
00621 
00622   if (m.fNeedAna) 
00623     write_method("JobCResult",
00624                  "Ana(const MomNavigator* mom)", 
00625                  "JobCResult::kPassed; // kNoDecision, kFailed, etc.",
00626                  m, ofs);
00627   if (m.fNeedReco)
00628     write_method("JobCResult",
00629                  "Reco(MomNavigator* mom)", 
00630                  "JobCResult::kPassed; // kNoDecision, kFailed, etc.",
00631                  m, ofs);
00632   if (m.fNeedGet)
00633     write_method("JobCResult",
00634                  "Get(MomNavigator* mom)",
00635                  "JobCResult::kPassed; // kNoDecision, kFailed, etc.",
00636                  m, ofs);
00637   if (m.fNeedPut)
00638     write_method("JobCResult",
00639                  "Put(const MomNavigator* mom)",
00640                  "JobCResult::kPassed; // kNoDecision, kFailed, etc.",
00641                  m, ofs);
00642   if (m.fNeedConfig)        write_config_methods(m,cfg,ofs);
00643   if (m.fNeedHelp)          write_method("void","Help()",  "",m,ofs);
00644   if (m.fNeedReport)        write_method("void","Report()","",m,ofs);
00645   if (m.fNeedReset)         write_method("void","Reset()", "",m,ofs);
00646   if (m.fNeedHandleCommand) 
00647     write_method("void","HandleCommand(JobCommand* c)", "",m,ofs);
00648   ofs << gsSlashDivider << std::endl;
00649 }

static void write_default_config_method ( const ModuleOptions m,
const ModuleConfig cfg,
std::ofstream &  ofs 
) [static]

Definition at line 418 of file gen_module.cc.

References UtilString::atob(), ModuleOptions::fClassName, gsDotDivider, and gsEqualsDivider.

Referenced by write_config_methods().

00421 {
00422 //======================================================================
00423 // Write the method which supplies the default configuration
00424 //======================================================================
00425   ofs << gsDotDivider << std::endl;
00426   ofs << std::endl;
00427   ofs << "const Registry& " << m.fClassName << "::DefaultConfig() const"
00428       << std::endl;
00429   ofs << "{" << std::endl;
00430   ofs << "  " << gsEqualsDivider << std::endl;
00431   ofs << "  /// Supply the default configuration for the module" << std::endl;
00432   ofs << "  " << gsEqualsDivider << std::endl;
00433   ofs << "  static Registry r; // Default configuration for module" 
00434       << std::endl;
00435   ofs << std::endl;
00436   ofs << "  // Set name of config" << std::endl;
00437   ofs << "  std::string name = this->GetName();" << std::endl;
00438   ofs << "  name += \".config.default\";" << std::endl;
00439   ofs << "  r.SetName(name.c_str());" << std::endl;
00440   ofs << std::endl;
00441   ofs << "  // Set values in configuration" << std::endl;
00442   ofs << "  r.UnLockValues();" << std::endl;
00443   ModuleConfig::const_iterator itr(cfg.begin());
00444   ModuleConfig::const_iterator itrEnd(cfg.end());
00445   unsigned int w = 0;
00446   for (; itr!=itrEnd; ++itr) {
00447     if (itr->fName.size() > w) w = itr->fName.size();
00448   }
00449   for (itr = cfg.begin(); itr!=itrEnd; ++itr) {
00450     ofs << "  r.Set(\"" << itr->fName << "\",";
00451     for (unsigned int i=itr->fName.size(); i<w; ++i) ofs << " ";
00452     if (itr->fType == "string") {
00453       ofs << "\"" << itr->fValue << "\");" << std::endl;
00454     }
00455     else if (itr->fType == "bool") {
00456       if (UtilString::atob(itr->fValue.c_str()))
00457         ofs << " true);"  << std::endl;
00458       else
00459         ofs << " false);" << std::endl;
00460     }
00461     else {
00462       ofs << " " << itr->fValue << ");" << std::endl;
00463     }
00464   }
00465   ofs << "  r.LockValues();" << std::endl;
00466   ofs << std::endl;
00467   ofs << "  return r;" << std::endl;
00468   ofs << "}" << std::endl;
00469   ofs << std::endl;
00470 }

static void write_h ( const ModuleOptions m,
ModuleConfig cfg 
) [static]

Definition at line 251 of file gen_module.cc.

References ModuleOptions::fClassName, ModuleOptions::fEmailAddr, ModuleOptions::fNeedAna, ModuleOptions::fNeedBeginFile, ModuleOptions::fNeedBeginJob, ModuleOptions::fNeedBeginRun, ModuleOptions::fNeedConfig, ModuleOptions::fNeedEndFile, ModuleOptions::fNeedEndJob, ModuleOptions::fNeedEndRun, ModuleOptions::fNeedGet, ModuleOptions::fNeedHandleCommand, ModuleOptions::fNeedHelp, ModuleOptions::fNeedPut, ModuleOptions::fNeedReco, ModuleOptions::fNeedReport, ModuleOptions::fNeedReset, gsDocComment, gsSlashDivider, and UtilString::ToUpper().

Referenced by doWrite().

00252 {
00253 //======================================================================
00254 // Write header file for job module
00255 //======================================================================
00256   std::string filename = m.fClassName;
00257   filename += ".h";
00258   std::ofstream ofs(filename.c_str());
00259 
00260   std::string inc_tag = UtilString::ToUpper(m.fClassName);
00261   inc_tag += "_H";
00262 
00263   //
00264 
00265   ofs << gsSlashDivider << std::endl;
00266   ofs << "/// $Id: gen_module.cc,v 1.5 2010/08/12 16:13:52 rhatcher Exp $" << std::endl;
00267   ofs << "///" << std::endl;
00268   ofs << gsDocComment << std::endl;
00269   ofs << "///" << std::endl;
00270   ofs << "/// " << m.fEmailAddr << std::endl;
00271   ofs << gsSlashDivider << std::endl;
00272   ofs << "#ifndef " << inc_tag << std::endl;
00273   ofs << "#define " << inc_tag << std::endl;
00274   ofs << "#include \"JobControl/JobCModule.h\"" << std::endl;
00275   ofs << std::endl;
00276   ofs << "class "<<m.fClassName<<" : public JobCModule"<<std::endl;
00277   ofs << "{" << std::endl;
00278   ofs << "public:" << std::endl;
00279   ofs << "  " << m.fClassName << "();" << std::endl;
00280   ofs << "  ~" << m.fClassName << "();" << std::endl;
00281   ofs << std::endl;
00282   ofs << "public:" << std::endl;
00283   if (m.fNeedBeginJob  || m.fNeedEndJob ||
00284       m.fNeedBeginFile || m.fNeedEndFile ||
00285       m.fNeedBeginRun  || m.fNeedEndRun) {
00286     ofs << "  // Handle job status changes" << std::endl;
00287     if (m.fNeedBeginJob)  ofs << "  void BeginJob();"  << std::endl;
00288     if (m.fNeedEndJob)    ofs << "  void EndJob();"    << std::endl;
00289     if (m.fNeedBeginFile) ofs << "  void BeginFile();" << std::endl;
00290     if (m.fNeedEndFile)   ofs << "  void EndFile();"   << std::endl;
00291     if (m.fNeedBeginRun)  ofs << "  void BeginRun();"  << std::endl;
00292     if (m.fNeedEndRun)    ofs << "  void EndRun();"    << std::endl;
00293     ofs << std::endl;
00294   }
00295   if (m.fNeedAna || m.fNeedReco) {
00296     ofs << "  // Analysis and Reconstruction methods" << std::endl;
00297     if (m.fNeedAna)  
00298       ofs << "  JobCResult Ana(const MomNavigator* mom);" << std::endl;
00299     if (m.fNeedReco) 
00300       ofs << "  JobCResult Reco(MomNavigator* mom);" << std::endl;
00301     ofs << std::endl;
00302   }
00303   if (m.fNeedGet || m.fNeedPut) {
00304     ofs << "  // I/O methods" << std::endl;
00305     if (m.fNeedGet)  
00306       ofs << "  JobCResult Get(MomNavigator* mom);" << std::endl;
00307     if (m.fNeedPut)  
00308       ofs << "  JobCResult Put(const MomNavigator* mom);" << std::endl;
00309     ofs << std::endl;
00310   }
00311   if (m.fNeedConfig) {
00312     ofs << "  // Module configuration" << std::endl;
00313     ofs << "  const Registry& DefaultConfig() const;" << std::endl;
00314     ofs << "  void            Config(const Registry& r);" << std::endl;
00315     ofs << std::endl;
00316   }
00317   if (m.fNeedHelp  || m.fNeedReport || 
00318       m.fNeedReset || m.fNeedHandleCommand) {
00319     ofs << "  // User interface methods" << std::endl;
00320     if (m.fNeedHelp) 
00321       ofs << "  void Help();" << std::endl;
00322     if (m.fNeedReport) 
00323       ofs << "  void Report();" << std::endl;
00324     if (m.fNeedReset)
00325       ofs << "  void Reset();" << std::endl;
00326     if (m.fNeedHandleCommand)
00327       ofs << "  void HandleCommand(JobCommand* c);" << std::endl;
00328     ofs << std::endl;
00329   }
00330   ofs << std::endl;
00331   ofs << "private:" << std::endl;
00332   ofs << "  // Module configuration" << std::endl;
00333   if(m.fNeedConfig) {
00334     ModuleConfig::const_iterator itr(cfg.begin());
00335     ModuleConfig::const_iterator itrEnd(cfg.end());
00336     for (itr=cfg.begin(); itr!=itrEnd; ++itr) {
00337       if (itr->fType == "bool")   { ofs << "  Bool_t      "; }
00338       if (itr->fType == "int")    { ofs << "  Int_t       "; }
00339       if (itr->fType == "float")  { ofs << "  Double_t    "; }
00340       if (itr->fType == "string") { ofs << "  std::string "; }
00341       ofs << "f" << itr->fName << ";" << std::endl;    
00342     }
00343   }
00344   ofs << std::endl;
00345   ofs << "  // Module member data" << std::endl;
00346   ofs << std::endl;
00347   ofs << "};" << std::endl;
00348   ofs << "#endif // " << inc_tag << std::endl;
00349   ofs << gsSlashDivider << std::endl;
00350 }

static void write_method ( const char *  type_s,
const char *  meth,
const char *  return_s,
const ModuleOptions m,
std::ofstream &  ofs 
) [static]

Definition at line 354 of file gen_module.cc.

References ModuleOptions::fClassName, gsDocComment, gsDotDivider, and gsEqualsDivider.

Referenced by write_cxx().

00358 {
00359 //======================================================================
00360 // Write a single method for the implementation file:
00361 // type_s : return type
00362 // meth   : method name
00363 // return_s : what to return from method
00364 // m : module definition
00365 // ofs : stream to write to
00366 //======================================================================
00367   ofs << gsDotDivider << std::endl;
00368   ofs << std::endl;
00369   if (type_s!=0 && std::string(type_s)!="")
00370     ofs << type_s << " " << m.fClassName << "::" << meth << std::endl;
00371   else
00372     ofs << m.fClassName << "::" << meth << std::endl;
00373   ofs << "{" << std::endl;
00374   ofs << "  " << gsEqualsDivider << std::endl;
00375   ofs << "  " << gsDocComment << std::endl;
00376   ofs << "  " << gsEqualsDivider << std::endl;
00377   if (return_s!=0 && std::string(return_s) != "")
00378     ofs << "  return " << return_s << std::endl;
00379   ofs << "}" << std::endl;
00380   ofs << std::endl;
00381 }

static bool yn_querry ( const char *  t,
bool  deflt 
) [static]

Definition at line 76 of file gen_module.cc.

Referenced by setupConfig(), setupMethods(), and setupServices().

00077 {
00078 //======================================================================
00079 // Prompt user with a yes/no question. Print text t. deflt is the
00080 // default response if user provides none.
00081 //======================================================================
00082   if (deflt) std::cout << t << "[y] : " << std::flush;
00083   else       std::cout << t << "[n] : " << std::flush;
00084 
00085   std::string s;
00086   getline(std::cin,s);
00087   
00088   if (s=="y" || s=="Y" || s=="yes" || s=="YES") return true;
00089   if (s=="n" || s=="N" || s=="no"  || s=="NO")  return false;
00090 
00091   return deflt;
00092 }


Variable Documentation

const char* gsDocComment [static]
Initial value:
 
"/// (Document me!)"

Definition at line 237 of file gen_module.cc.

Referenced by write_constructor(), write_cxx(), write_h(), and write_method().

const char* gsDotDivider [static]
Initial value:
"//......................................................................"

Definition at line 246 of file gen_module.cc.

Referenced by write_config_method(), write_constructor(), write_default_config_method(), and write_method().

const char* gsEqualsDivider [static]
Initial value:
"///"

Definition at line 243 of file gen_module.cc.

Referenced by write_config_method(), write_constructor(), write_default_config_method(), and write_method().

const char* gsSlashDivider [static]
Initial value:
 
"////////////////////////////////////////////////////////////////////////"

Definition at line 240 of file gen_module.cc.

Referenced by write_cxx(), and write_h().


Generated on 24 Apr 2018 for loon by  doxygen 1.6.1