BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
ProjectMessenger.cpp
Go to the documentation of this file.
1#include "G4Svc/ProjectMessenger.h"
2#include "G4Svc/Goofy.h"
3
4#include "G4UIcommand.hh"
5#include "G4UImanager.hh"
6
7#include "FadsPackageLoader/PackageLoader.h"
8
9#include <string>
10#include <fstream.h>
11
12std::string getLine(ifstream& in)
13{
14 char buffer[200];
15 if (in.getline(buffer,200))
16 {
17 std::string s=buffer;
18 return s;
19 }
20 else return "eof";
21}
22
23void parseTemplate(std::string dir,std::string filename, std::string dname)
24{
25 std::string outname=dname;
26 std::string outfile=dir+outname+".temp";
27 ofstream out(outfile.c_str());
28 ifstream in((dir+filename).c_str());
29
30 unsigned int i=0;
31 std::string buffer;
32 while ((buffer=getLine(in))!="eof")
33 {
34 while ((i=buffer.find("@NAME"))!=std::string::npos)
35 {
36 if (i>0) buffer.replace(i,5,outname);
37 }
38 out<<buffer<<std::endl;
39 }
40}
41
43{
44 rm=v;
45
46 make=new G4UIcommand("/Project/make",this);
47 make->SetGuidance("Builds the specified project");
48 G4UIparameter* parameter;
49 G4bool omitable;
50 parameter = new G4UIparameter ("Project", 's', omitable = false);
51 make->SetParameter(parameter);
52
53 create=new G4UIcommand("/Project/create",this);
54 create->SetGuidance("Creates an empty project");
55 parameter = new G4UIparameter ("Project", 's', omitable = false);
56 create->SetParameter(parameter);
57
58 del=new G4UIcommand("/Project/delete",this);
59 del->SetGuidance("Deletes a project");
60 parameter = new G4UIparameter ("Project", 's', omitable = false);
61 del->SetParameter(parameter);
62
63 geo=new G4UIcommand("/Project/add/DetectorFacility",this);
64 geo->SetGuidance("Generates sample code for a detector facility in a project");
65 parameter = new G4UIparameter ("Project", 's', omitable = false);
66 geo->SetParameter(parameter);
67
68 G4UIparameter* parameter2;
69 parameter2 = new G4UIparameter ("DetectorFacilityName", 's', omitable = false);
70 geo->SetParameter(parameter2);
71
72 act=new G4UIcommand("/Project/add/UserAction",this);
73 act->SetGuidance("Generates sample code for an user action in a project");
74 parameter = new G4UIparameter ("Project", 's', omitable = false);
75 act->SetParameter(parameter);
76
77 G4UIparameter* parameter3;
78 parameter3 = new G4UIparameter ("UserAction Name", 's', omitable = false);
79 act->SetParameter(parameter3);
80}
81
83{
84 // delete make;
85 // delete create;
86 // delete del;
87 // delete geo;
88 // delete act;
89}
90
91void ProjectMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
92{
93 if (command==make)
94 {
95 Goofy::Shell("cd "+newValues+"; gmake");
96 }
97 else if (command==create)
98 {
99 Goofy::Shell("mkdir "+newValues);
100 Goofy::Shell("mkdir "+newValues+"/src");
101 Goofy::Shell("mkdir "+newValues+"/include");
102 Goofy::Shell("touch "+newValues+"/src/dummy.cc");
103 std::cout<<"Looking for "<<std::flush;
104 if (Goofy::Shell("find $FADS_CURRENT/config -name GNUmakefile_template")==0)
105 {
106 std::cout<<" Found! "<<std::endl;
107 Goofy::Shell("cp $FADS_CURRENT/config/GNUmakefile_template "
108 +newValues+"/GNUmakefile");
109 }
110 Goofy::Shell("chmod -R 755 "+newValues);
111 }
112 else if (command==del)
113 {
114 if (Goofy::Shell("find . -name "+newValues))
115 Goofy::Shell("rm -rf "+newValues);
116 }
117 else if (command==geo)
118 {
119 G4String detName,project;
120 const char* s = newValues;
121 std::istrstream is ((char*)s);
122 is>>project>>detName;
123
124 if (Goofy::Shell("find . -name "+project)==0)
125 {
126 std::string where="$FADS_CURRENT/config/";
127 std::string incl=project+"/include/";
128 std::string src=project+"/src/";
129 Goofy::Shell("cp "+where+"DetectorFacilityTemplate.hh "
130 +incl);
131 parseTemplate(incl,"DetectorFacilityTemplate.hh",detName);
132 Goofy::Shell("mv "+incl+detName+".temp "+incl+
133 +detName+"Facility.hh");
134 Goofy::Shell("rm -f "+incl+"DetectorFacilityTemplate.hh");
135 Goofy::Shell("cp "+where+"DetectorFacilityTemplate.cc "
136 +src);
137 parseTemplate(src,"DetectorFacilityTemplate.cc",detName);
138 Goofy::Shell("mv "+src+detName+".temp "+src+
139 +detName+"Facility.cc");
140 Goofy::Shell("rm -f "+src+"DetectorFacilityTemplate.cc");
141 }
142 }
143 else if (command==act)
144 {
145 G4String actName,project;
146 const char* s = newValues;
147 std::istrstream is ((char*)s);
148 is>>project>>actName;
149
150 if (Goofy::Shell("find . -name "+project)==0)
151 {
152 std::string where="$FADS_CURRENT/config/";
153 std::string incl=project+"/include/";
154 std::string src=project+"/src/";
155 Goofy::Shell("cp "+where+"UserActionTemplate.hh "
156 +incl);
157 parseTemplate(incl,"UserActionTemplate.hh",actName);
158 Goofy::Shell("mv "+incl+actName+".temp "+incl+
159 +actName+"Action.hh");
160 Goofy::Shell("rm -f "+incl+"UserActionTemplate.hh");
161 Goofy::Shell("cp "+where+"UserActionTemplate.cc "
162 +src);
163 parseTemplate(src,"UserActionTemplate.cc",actName);
164 Goofy::Shell("mv "+src+actName+".temp "+src+
165 +actName+"Action.cc");
166 Goofy::Shell("rm -f "+src+"UserActionTemplate.cc");
167 }
168 }
169}
170
171G4String ProjectMessenger::GetCurrentValue(G4UIcommand * command)
172{
173 G4String s="Undefined";
174 return s;
175}
XmlRpcServer s
Definition: HelloServer.cpp:11
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition: KarLud.h:35
std::string getLine(ifstream &in)
void parseTemplate(std::string dir, std::string filename, std::string dname)
Definition: Goofy.h:13
static int Shell(std::string s)
Definition: Goofy.cpp:62
void SetNewValue(G4UIcommand *command, G4String newValues)
ProjectMessenger(Goofy *v)
G4String GetCurrentValue(G4UIcommand *command)
double precision pisqo6 parameter(pi=3.14159265358979d0, pisq=pi *pi, pisqo6=pisq/6d0) double precision zip