/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Simulation/G4Svc/G4Svc-00-01-52/other_src/ProjectMessenger.cpp

Go to the documentation of this file.
00001 #include "G4Svc/ProjectMessenger.h"
00002 #include "G4Svc/Goofy.h"
00003 
00004 #include "G4UIcommand.hh"
00005 #include "G4UImanager.hh"
00006 
00007 #include "FadsPackageLoader/PackageLoader.h"
00008 
00009 #include <string>
00010 #include <fstream.h>
00011 
00012 std::string getLine(ifstream& in)
00013 {
00014         char buffer[200];
00015         if (in.getline(buffer,200))
00016         {
00017                 std::string s=buffer;
00018                 return s;
00019         }
00020         else return "eof";
00021 }
00022 
00023 void parseTemplate(std::string dir,std::string filename, std::string dname)
00024 {
00025         std::string outname=dname;
00026         std::string outfile=dir+outname+".temp";
00027         ofstream out(outfile.c_str());
00028         ifstream in((dir+filename).c_str());
00029 
00030         unsigned int i=0;
00031         std::string buffer;
00032         while ((buffer=getLine(in))!="eof")
00033         {
00034                 while ((i=buffer.find("@NAME"))!=std::string::npos)
00035                 {
00036                         if (i>0) buffer.replace(i,5,outname);
00037                 }
00038                 out<<buffer<<std::endl;
00039         }
00040 } 
00041 
00042 ProjectMessenger::ProjectMessenger(Goofy *v)
00043 {
00044         rm=v;
00045 
00046         make=new G4UIcommand("/Project/make",this);
00047         make->SetGuidance("Builds the specified project");
00048         G4UIparameter* parameter;
00049         G4bool omitable;
00050         parameter = new G4UIparameter ("Project", 's', omitable = false);
00051         make->SetParameter(parameter);
00052         
00053         create=new G4UIcommand("/Project/create",this);
00054         create->SetGuidance("Creates an empty project");
00055         parameter = new G4UIparameter ("Project", 's', omitable = false);
00056         create->SetParameter(parameter);
00057         
00058         del=new G4UIcommand("/Project/delete",this);
00059         del->SetGuidance("Deletes a project");
00060         parameter = new G4UIparameter ("Project", 's', omitable = false);
00061         del->SetParameter(parameter);
00062         
00063         geo=new G4UIcommand("/Project/add/DetectorFacility",this);
00064         geo->SetGuidance("Generates sample code for a detector facility in a project");
00065         parameter = new G4UIparameter ("Project", 's', omitable = false);
00066         geo->SetParameter(parameter);
00067         
00068         G4UIparameter* parameter2;
00069         parameter2 = new G4UIparameter ("DetectorFacilityName", 's', omitable = false);
00070         geo->SetParameter(parameter2);
00071 
00072         act=new G4UIcommand("/Project/add/UserAction",this);
00073         act->SetGuidance("Generates sample code for an user action in a project");
00074         parameter = new G4UIparameter ("Project", 's', omitable = false);
00075         act->SetParameter(parameter);
00076         
00077         G4UIparameter* parameter3;
00078         parameter3 = new G4UIparameter ("UserAction Name", 's', omitable = false);
00079         act->SetParameter(parameter3);
00080 }
00081 
00082 ProjectMessenger::~ProjectMessenger()
00083 {
00084         // delete make;
00085         // delete create;
00086         // delete del;
00087         // delete geo;
00088         // delete act;
00089 }
00090 
00091 void ProjectMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
00092 {
00093         if (command==make)
00094         {
00095                 Goofy::Shell("cd "+newValues+"; gmake");
00096         }
00097         else if (command==create)
00098         {
00099                 Goofy::Shell("mkdir "+newValues);
00100                 Goofy::Shell("mkdir "+newValues+"/src");
00101                 Goofy::Shell("mkdir "+newValues+"/include");
00102                 Goofy::Shell("touch "+newValues+"/src/dummy.cc");
00103                 std::cout<<"Looking for "<<std::flush;
00104                 if (Goofy::Shell("find $FADS_CURRENT/config -name GNUmakefile_template")==0)
00105                 {
00106                         std::cout<<" Found! "<<std::endl;
00107                         Goofy::Shell("cp $FADS_CURRENT/config/GNUmakefile_template "
00108                                                 +newValues+"/GNUmakefile");
00109                 }
00110                 Goofy::Shell("chmod -R 755 "+newValues);
00111         }
00112         else if (command==del)
00113         {
00114                 if (Goofy::Shell("find . -name "+newValues))
00115                         Goofy::Shell("rm -rf "+newValues); 
00116         }
00117         else if (command==geo)
00118         {
00119                 G4String detName,project;
00120                 const char* s = newValues;
00121                 std::istrstream is ((char*)s);
00122                 is>>project>>detName;
00123                 
00124                 if (Goofy::Shell("find . -name "+project)==0)
00125                 {
00126                         std::string where="$FADS_CURRENT/config/";
00127                         std::string incl=project+"/include/";
00128                         std::string src=project+"/src/";
00129                         Goofy::Shell("cp "+where+"DetectorFacilityTemplate.hh "
00130                                         +incl);
00131                         parseTemplate(incl,"DetectorFacilityTemplate.hh",detName);
00132                         Goofy::Shell("mv "+incl+detName+".temp "+incl+
00133                                                 +detName+"Facility.hh");
00134                         Goofy::Shell("rm -f "+incl+"DetectorFacilityTemplate.hh");
00135                         Goofy::Shell("cp "+where+"DetectorFacilityTemplate.cc "
00136                                                 +src);
00137                         parseTemplate(src,"DetectorFacilityTemplate.cc",detName);
00138                         Goofy::Shell("mv "+src+detName+".temp "+src+
00139                                                 +detName+"Facility.cc");
00140                         Goofy::Shell("rm -f "+src+"DetectorFacilityTemplate.cc");
00141                 }
00142         }
00143         else if (command==act)
00144         {
00145                 G4String actName,project;
00146                 const char* s = newValues;
00147                 std::istrstream is ((char*)s);
00148                 is>>project>>actName;
00149                 
00150                 if (Goofy::Shell("find . -name "+project)==0)
00151                 {
00152                         std::string where="$FADS_CURRENT/config/";
00153                         std::string incl=project+"/include/";
00154                         std::string src=project+"/src/";
00155                         Goofy::Shell("cp "+where+"UserActionTemplate.hh "
00156                                         +incl);
00157                         parseTemplate(incl,"UserActionTemplate.hh",actName);
00158                         Goofy::Shell("mv "+incl+actName+".temp "+incl+
00159                                                 +actName+"Action.hh");
00160                         Goofy::Shell("rm -f "+incl+"UserActionTemplate.hh");
00161                         Goofy::Shell("cp "+where+"UserActionTemplate.cc "
00162                                                 +src);
00163                         parseTemplate(src,"UserActionTemplate.cc",actName);
00164                         Goofy::Shell("mv "+src+actName+".temp "+src+
00165                                                 +actName+"Action.cc");
00166                         Goofy::Shell("rm -f "+src+"UserActionTemplate.cc");
00167                 }
00168         }
00169 }
00170 
00171 G4String ProjectMessenger::GetCurrentValue(G4UIcommand * command)
00172 {
00173         G4String s="Undefined";
00174         return s;
00175 }

Generated on Tue Nov 29 23:14:33 2016 for BOSS_7.0.2 by  doxygen 1.4.7