BOSS 8.0.0
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 <fstream.h>
10#include <string>
11
12std::string getLine( ifstream& in ) {
13 char buffer[200];
14 if ( in.getline( buffer, 200 ) )
15 {
16 std::string s = buffer;
17 return s;
18 }
19 else return "eof";
20}
21
22void parseTemplate( std::string dir, std::string filename, std::string dname ) {
23 std::string outname = dname;
24 std::string outfile = dir + outname + ".temp";
25 ofstream out( outfile.c_str() );
26 ifstream in( ( dir + filename ).c_str() );
27
28 unsigned int i = 0;
29 std::string buffer;
30 while ( ( buffer = getLine( in ) ) != "eof" )
31 {
32 while ( ( i = buffer.find( "@NAME" ) ) != std::string::npos )
33 {
34 if ( i > 0 ) buffer.replace( i, 5, outname );
35 }
36 out << buffer << std::endl;
37 }
38}
39
41 rm = v;
42
43 make = new G4UIcommand( "/Project/make", this );
44 make->SetGuidance( "Builds the specified project" );
45 G4UIparameter* parameter;
46 G4bool omitable;
47 parameter = new G4UIparameter( "Project", 's', omitable = false );
48 make->SetParameter( parameter );
49
50 create = new G4UIcommand( "/Project/create", this );
51 create->SetGuidance( "Creates an empty project" );
52 parameter = new G4UIparameter( "Project", 's', omitable = false );
53 create->SetParameter( parameter );
54
55 del = new G4UIcommand( "/Project/delete", this );
56 del->SetGuidance( "Deletes a project" );
57 parameter = new G4UIparameter( "Project", 's', omitable = false );
58 del->SetParameter( parameter );
59
60 geo = new G4UIcommand( "/Project/add/DetectorFacility", this );
61 geo->SetGuidance( "Generates sample code for a detector facility in a project" );
62 parameter = new G4UIparameter( "Project", 's', omitable = false );
63 geo->SetParameter( parameter );
64
65 G4UIparameter* parameter2;
66 parameter2 = new G4UIparameter( "DetectorFacilityName", 's', omitable = false );
67 geo->SetParameter( parameter2 );
68
69 act = new G4UIcommand( "/Project/add/UserAction", this );
70 act->SetGuidance( "Generates sample code for an user action in a project" );
71 parameter = new G4UIparameter( "Project", 's', omitable = false );
72 act->SetParameter( parameter );
73
74 G4UIparameter* parameter3;
75 parameter3 = new G4UIparameter( "UserAction Name", 's', omitable = false );
76 act->SetParameter( parameter3 );
77}
78
80 // delete make;
81 // delete create;
82 // delete del;
83 // delete geo;
84 // delete act;
85}
86
87void ProjectMessenger::SetNewValue( G4UIcommand* command, G4String newValues ) {
88 if ( command == make ) { Goofy::Shell( "cd " + newValues + "; gmake" ); }
89 else if ( command == create )
90 {
91 Goofy::Shell( "mkdir " + newValues );
92 Goofy::Shell( "mkdir " + newValues + "/src" );
93 Goofy::Shell( "mkdir " + newValues + "/include" );
94 Goofy::Shell( "touch " + newValues + "/src/dummy.cc" );
95 std::cout << "Looking for " << std::flush;
96 if ( Goofy::Shell( "find $FADS_CURRENT/config -name GNUmakefile_template" ) == 0 )
97 {
98 std::cout << " Found! " << std::endl;
99 Goofy::Shell( "cp $FADS_CURRENT/config/GNUmakefile_template " + newValues +
100 "/GNUmakefile" );
101 }
102 Goofy::Shell( "chmod -R 755 " + newValues );
103 }
104 else if ( command == del )
105 {
106 if ( Goofy::Shell( "find . -name " + newValues ) ) Goofy::Shell( "rm -rf " + newValues );
107 }
108 else if ( command == geo )
109 {
110 G4String detName, project;
111 const char* s = newValues;
112 std::istrstream is( (char*)s );
113 is >> project >> detName;
114
115 if ( Goofy::Shell( "find . -name " + project ) == 0 )
116 {
117 std::string where = "$FADS_CURRENT/config/";
118 std::string incl = project + "/include/";
119 std::string src = project + "/src/";
120 Goofy::Shell( "cp " + where + "DetectorFacilityTemplate.hh " + incl );
121 parseTemplate( incl, "DetectorFacilityTemplate.hh", detName );
122 Goofy::Shell( "mv " + incl + detName + ".temp " + incl + +detName + "Facility.hh" );
123 Goofy::Shell( "rm -f " + incl + "DetectorFacilityTemplate.hh" );
124 Goofy::Shell( "cp " + where + "DetectorFacilityTemplate.cc " + src );
125 parseTemplate( src, "DetectorFacilityTemplate.cc", detName );
126 Goofy::Shell( "mv " + src + detName + ".temp " + src + +detName + "Facility.cc" );
127 Goofy::Shell( "rm -f " + src + "DetectorFacilityTemplate.cc" );
128 }
129 }
130 else if ( command == act )
131 {
132 G4String actName, project;
133 const char* s = newValues;
134 std::istrstream is( (char*)s );
135 is >> project >> actName;
136
137 if ( Goofy::Shell( "find . -name " + project ) == 0 )
138 {
139 std::string where = "$FADS_CURRENT/config/";
140 std::string incl = project + "/include/";
141 std::string src = project + "/src/";
142 Goofy::Shell( "cp " + where + "UserActionTemplate.hh " + incl );
143 parseTemplate( incl, "UserActionTemplate.hh", actName );
144 Goofy::Shell( "mv " + incl + actName + ".temp " + incl + +actName + "Action.hh" );
145 Goofy::Shell( "rm -f " + incl + "UserActionTemplate.hh" );
146 Goofy::Shell( "cp " + where + "UserActionTemplate.cc " + src );
147 parseTemplate( src, "UserActionTemplate.cc", actName );
148 Goofy::Shell( "mv " + src + actName + ".temp " + src + +actName + "Action.cc" );
149 Goofy::Shell( "rm -f " + src + "UserActionTemplate.cc" );
150 }
151 }
152}
153
154G4String ProjectMessenger::GetCurrentValue( G4UIcommand* command ) {
155 G4String s = "Undefined";
156 return s;
157}
XmlRpcServer s
**********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:58
void SetNewValue(G4UIcommand *command, G4String newValues)
G4String GetCurrentValue(G4UIcommand *command)