31 std::map<std::string, std::string>
fPars;
35 SetPar(
"hostname", hostname);
45 void AddFile(
const char* fname,
bool errorout =
false)
47 std::ifstream f(fname);
49 if (errorout)
TGo4Log::Debug(
"ERROR: Preferences file %s not existing",fname);
53 std::string hostname =
GetPar(
"hostname");
55 char formatstring[4096];
59 f.getline(formatstring,
sizeof(formatstring),
'\n' );
60 if ((f.gcount()==0) || (strlen(formatstring)==0))
continue;
62 const char* sbuf = formatstring;
65 if (*sbuf==
' ') { sbuf++;
continue; }
66 if (*sbuf==
'#')
break;
68 const char* separ = strchr(sbuf,
':');
71 std::string name(sbuf, separ-sbuf);
73 size_t pos = name.find(
'=');
75 std::string subname(name, 0, pos);
76 std::string mask(name, pos+1);
78 if ((subname.length()==0) || (mask.length()==0))
break;
80 const char* subvalue =
GetPar(subname.c_str());
82 if (subvalue==0)
break;
86 TRegexp re(mask.c_str(), kTRUE);
88 if (re.Index(subvalue, &len)!=0)
break;
89 if (len != (Int_t) strlen(subvalue))
break;
97 SetPar(name.c_str(), separ+1);
105 bool IsOk()
const {
return fPars.size()>2; }
107 void SetPar(
const char* name,
const char* value,
bool force =
true)
109 std::string dname = Form(
"%s%s%s",
"%", name,
"%");
110 if (force || (fPars.find(dname) == fPars.end()))
111 fPars[dname] = value;
116 std::string dname = Form(
"%s%s%s",
"%", name,
"%");
117 if (fPars.find(dname) == fPars.end())
return 0;
118 return fPars[dname].c_str();
134 std::map<std::string,std::string>::iterator iter = fPars.begin();
135 while (iter != fPars.end()) {
137 while ((pos = str.find(iter->first, pos)) != str.npos) {
138 str.replace(pos, iter->first.length(), iter->second);
144 std::cerr <<
"Syntax error in go4.prefs files - endless recursion" << std::endl;
145 std::cerr <<
"Program aborted, please fix an error" << std::endl;
155 while ((pos1 = str.find(
"${")) != str.npos) {
157 pos2 = str.find(
"}");
159 if ((pos1>pos2) || (pos2==str.npos)) {
160 TGo4Log::Debug(
"ERROR: Wrong variable parenthesis %s",str.c_str());
164 std::string var(str, pos1+2, pos2-pos1-2);
166 str.erase(pos1, pos2-pos1+1);
168 const char* value = gSystem->Getenv(var.c_str());
169 if (value!=0) str.insert(pos1, value);
176 const char* opt =
GetPar(prefix);
177 if (opt==0)
return std::string(
"");
178 std::string res = opt;
192 const char* remotehost,
193 const char* remotedir,
194 const char* remoteexe,
199 const char* serverhost = gSystem->HostName();
200 const char* sdisplay = gSystem->Getenv(
"DISPLAY");
202 const char* rootsys = gSystem->Getenv(
"ROOTSYS");
203 const char* path = gSystem->Getenv(
"PATH");
204 const char* ldpath = gSystem->Getenv(
"LD_LIBRARY_PATH");
206 if ((name==0) || (strlen(name)==0)) name =
"UserAnalysis";
207 if ((serverhost==0) || (strlen(serverhost)==0)) serverhost =
"localhost";
209 if (gSystem->Getenv(
"GO4OLDLAUNCH")==0) {
212 const char* shellname =
"exec";
213 if (shellkind==1) shellname =
"rsh";
else
214 if (shellkind==2) shellname = konsole==1 ?
"ssh" :
"sshX";
215 prefs.
SetPar(
"shellkind", shellname,
false);
216 prefs.
SetPar(
"exekind", Form(
"%d", exe_kind),
false);
217 prefs.
SetPar(
"clientkind", serverkind>0 ?
"Go4Server" :
"Go4Client",
false);
219 prefs.
AddFile(
"go4.prefs",
false);
222 std::cout <<
"Cannot find prefs file" << std::endl;
226 prefs.
SetPar(
"guihost", serverhost,
false);
228 prefs.
SetPar(
"guiport", Form(
"%d", guiport));
229 prefs.
SetPar(
"guigo4sys", go4sys,
false);
230 prefs.
SetPar(
"analysisname", name,
false);
231 prefs.
SetPar(
"workdir", remotedir,
false);
232 prefs.
SetPar(exe_kind==0 ?
"exename" :
"libname", remoteexe,
false);
235 if ((exe_kind==1) && (exeargs!=0) && (strlen(exeargs)>0))
236 prefs.
SetPar(
"userargs", Form(
"%s", exeargs),
false);
238 prefs.
SetPar(
"userargs",
"",
false);
241 const char* termname =
"qtwindow";
242 if (konsole==2) termname =
"xterm";
else
243 if (konsole==3) termname =
"konsole";
246 if ((shellkind==0) && (konsole==1))
247 prefs.
SetPar(
"cd_workdir",
"");
249 std::string executable;
250 bool is_exe = prefs.
GetOpt(
"exekind") !=
"1";
252 if (prefs.
GetOpt(
"exename").empty())
253 executable = prefs.
GetOpt(
"analysis_default_exe");
255 executable = prefs.
GetOpt(
"analysis_exe");
257 if (prefs.
GetOpt(
"libname").empty())
258 executable = prefs.
GetOpt(
"analysis_default_lib");
260 executable = prefs.
GetOpt(
"analysis_lib");
262 prefs.
SetPar(
"analysis", executable.c_str());
264 if (!is_exe) prefs.
SetPar(
"killexename",
"go4analysis",
false);
else {
270 const char* runname = strrchr(remoteexe, symbol);
271 prefs.
SetPar(
"killexename", runname ? runname+1 : remoteexe,
false);
274 std::string initcmd = prefs.
GetOpt(shellkind==0 ?
"execinitcmd" :
"shellinitcmd");
275 prefs.
SetPar(
"initcmd", initcmd.c_str());
277 std::string progcmd = prefs.
GetOpt((serverkind>0) ? ((serverkind==2) ?
"httpcmd" :
"servercmd") :
"clientcmd");
278 prefs.
SetPar(
"progcmd", progcmd.c_str());
280 std::string hostcmd = prefs.
GetOpt(termname);
281 prefs.
SetPar(
"hostcmd", hostcmd.c_str());
283 std::string cmd = prefs.
GetOpt(shellname);
284 std::cout <<
"cmd: " << cmd << std::endl;
285 launchcmd = cmd.c_str();
287 std::string dkill = prefs.
GetOpt(
"kill");
288 prefs.
SetPar(
"hostcmd", dkill.c_str());
289 cmd = prefs.
GetOpt(shellname);
290 std::cout <<
"killcmd: " << cmd << std::endl;
291 killcmd = cmd.c_str();
296 if ((go4sys==0) || (strlen(go4sys)==0))
return kFALSE;
300 std::ifstream launchprefs(filename.Data());
302 TGo4Log::Debug(
"Master -- ERROR: Preferences file %s not existing, could not launch client ",
307 char formatstring[1000];
309 if ((konsole<1) || (konsole>3)) konsole = 1;
311 if (serverkind>0) num+=3;
313 for(
int n=0;n<num;n++)
314 launchprefs.getline(formatstring, 1000,
'\n' );
316 const char* sh_com =
"";
317 const char* sh_host = remotehost;
318 TString serverdisplay =
"";
323 serverdisplay =
"-display ";
324 serverdisplay += sdisplay;
327 sh_com = (konsole == 0) ?
"ssh -x " :
"ssh -X ";
335 killcmd =
"killall ";
336 killcmd += remoteexe;
338 if((shellkind>0) && (strcmp(remotehost, gSystem->HostName())!=0) && (strcmp(remotehost,
"localhost")!=0)) {
339 TString precmd = sh_com;
341 precmd += remotehost;
343 killcmd.Prepend(precmd);
350 launchcmd.Form(formatstring,
351 sh_com, sh_host, serverdisplay.Data(), name, remotehost, go4sys, go4sys, rootsys,
352 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
357 launchcmd.Form(formatstring,
358 sh_com, sh_host, name, go4sys, go4sys, rootsys,
359 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
365 launchcmd.Form(formatstring,
366 sh_com, sh_host, go4sys, go4sys, rootsys,
367 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
380 fbAnalysisReady(kFALSE),
381 fbAnalysisSettingsReady(kFALSE),
382 fAnalysisLaunched(0),
virtual Bool_t IsViewer()
virtual Bool_t IsConnected()
virtual Bool_t IsAdministrator()
std::string GetOpt(const char *prefix)
virtual ~TGo4ServerProxy()
TGo4Slot * RatemeterSlot()
static const char * Get_fgcLAUNCHPREFSFILE()
TGo4Slot * DebugOutputSlot()
TGo4Slot * FindChild(const char *name)
virtual const char * GetContainedObjectInfo()
TGo4Slot * SettingsSlot()
virtual Bool_t IsController()
void ReplacePars(std::string &str)
static Bool_t GetLaunchString(TString &launchcmd, TString &killcmd, Int_t serverkind, Int_t shellkind, Int_t konsole, const char *name, const char *remotehost, const char *remotedir, const char *remoteexe, Int_t guiport, Int_t exe_kind=0, const char *exeargs=0)
void AddFile(const char *fname, bool errorout=false)
void ReplaceEnvPars(std::string &str)
static TString subGO4SYS(const char *subdir)
bool HasPar(const char *name)
TGo4Prefs(const char *hostname)
static const char * GO4SYS()
const char * GetPar(const char *name)
static void Debug(const char *text,...)
void SetPar(const char *name, const char *value, bool force=true)
std::map< std::string, std::string > fPars