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.empty() || mask.empty())
break;
80 const char *subvalue =
GetPar(subname.c_str());
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 = TString::Format(
"%s%s%s",
"%", name,
"%").Data();
110 if (force || (fPars.find(dname) == fPars.end()))
111 fPars[dname] = value;
116 std::string dname = TString::Format(
"%s%s%s",
"%", name,
"%").Data();
117 if (fPars.find(dname) == fPars.end())
return nullptr;
118 return fPars[dname].c_str();
123 return GetPar(name) !=
nullptr;
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) str.insert(pos1, value);
176 const char *opt =
GetPar(prefix);
177 if (!opt)
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 || (strlen(name) == 0)) name =
"UserAnalysis";
207 if (!serverhost || (strlen(serverhost) == 0)) serverhost =
"localhost";
209 if (!gSystem->Getenv(
"GO4OLDLAUNCH")) {
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", TString::Format(
"%d", exe_kind).Data(),
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", TString::Format(
"%d", guiport).Data());
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);
234 if ((exe_kind == 1) && exeargs && (strlen(exeargs) > 0))
235 prefs.
SetPar(
"userargs", exeargs,
false);
237 prefs.
SetPar(
"userargs",
"",
false);
239 const char *termname =
"qtwindow";
240 if (konsole == 2) termname =
"xterm";
else 241 if (konsole == 3) termname =
"konsole";
244 if ((shellkind == 0) && (konsole == 1))
245 prefs.
SetPar(
"cd_workdir",
"");
247 std::string executable;
248 bool is_exe = prefs.
GetOpt(
"exekind") !=
"1";
250 if (prefs.
GetOpt(
"exename").empty())
251 executable = prefs.
GetOpt(
"analysis_default_exe");
253 executable = prefs.
GetOpt(
"analysis_exe");
255 if (prefs.
GetOpt(
"libname").empty())
256 executable = prefs.
GetOpt(
"analysis_default_lib");
258 executable = prefs.
GetOpt(
"analysis_lib");
260 prefs.
SetPar(
"analysis", executable.c_str());
262 if (!is_exe) prefs.
SetPar(
"killexename",
"go4analysis",
false);
else {
268 const char *runname = strrchr(remoteexe, symbol);
269 prefs.
SetPar(
"killexename", runname ? runname+1 : remoteexe,
false);
272 std::string initcmd = prefs.
GetOpt(shellkind == 0 ?
"execinitcmd" :
"shellinitcmd");
273 prefs.
SetPar(
"initcmd", initcmd.c_str());
275 std::string progcmd = prefs.
GetOpt((serverkind>0) ? ((serverkind==2) ?
"httpcmd" :
"servercmd") :
"clientcmd");
276 prefs.
SetPar(
"progcmd", progcmd.c_str());
278 std::string hostcmd = prefs.
GetOpt(termname);
279 prefs.
SetPar(
"hostcmd", hostcmd.c_str());
281 std::string cmd = prefs.
GetOpt(shellname);
282 std::cout <<
"cmd: " << cmd << std::endl;
283 launchcmd = cmd.c_str();
285 std::string dkill = prefs.
GetOpt(
"kill");
286 prefs.
SetPar(
"hostcmd", dkill.c_str());
287 cmd = prefs.
GetOpt(shellname);
288 std::cout <<
"killcmd: " << cmd << std::endl;
289 killcmd = cmd.c_str();
294 if (!go4sys || (strlen(go4sys) == 0))
return kFALSE;
298 std::ifstream launchprefs(filename.Data());
300 TGo4Log::Debug(
"Master -- ERROR: Preferences file %s not existing, could not launch client ",
305 char formatstring[1000];
307 if ((konsole<1) || (konsole>3)) konsole = 1;
309 if (serverkind>0) num+=3;
311 for (
int n = 0; n < num; n++)
312 launchprefs.getline(formatstring, 1000,
'\n');
314 const char *sh_com =
"";
315 const char *sh_host = remotehost;
316 TString serverdisplay =
"";
321 serverdisplay =
"-display ";
322 serverdisplay += sdisplay;
325 sh_com = (konsole == 0) ?
"ssh -x " :
"ssh -X ";
333 killcmd =
"killall ";
334 killcmd += remoteexe;
336 if((shellkind > 0) && (strcmp(remotehost, gSystem->HostName()) != 0) && (strcmp(remotehost,
"localhost") != 0)) {
337 TString precmd = sh_com;
339 precmd += remotehost;
341 killcmd.Prepend(precmd);
348 launchcmd.Form(formatstring,
349 sh_com, sh_host, serverdisplay.Data(), name, remotehost, go4sys, go4sys, rootsys,
350 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
355 launchcmd.Form(formatstring,
356 sh_com, sh_host, name, go4sys, go4sys, rootsys,
357 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
363 launchcmd.Form(formatstring,
364 sh_com, sh_host, go4sys, go4sys, rootsys,
365 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
377 fxParentSlot(nullptr),
378 fbAnalysisReady(kFALSE),
379 fbAnalysisSettingsReady(kFALSE),
380 fAnalysisLaunched(0),
std::string GetOpt(const char *prefix)
TGo4Slot * FindChild(const char *name) const
virtual ~TGo4ServerProxy()
virtual Bool_t IsViewer() const
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=nullptr)
virtual Bool_t IsAdministrator() const
virtual Bool_t IsController() const
TGo4Slot * RatemeterSlot()
static void Debug(const char *text,...) GO4_PRINTF_ARGS
static const char * Get_fgcLAUNCHPREFSFILE()
TGo4Slot * DebugOutputSlot()
TGo4Slot * SettingsSlot()
virtual Bool_t IsConnected() const
void ReplacePars(std::string &str)
void AddFile(const char *fname, bool errorout=false)
const char * GetContainedObjectInfo() override
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)
void SetPar(const char *name, const char *value, bool force=true)
std::map< std::string, std::string > fPars