22 #include "Riostream.h"
32 std::map<std::string, std::string>
fPars;
36 SetPar(
"hostname", hostname);
44 void AddFile(
const char* fname,
bool errorout =
false)
46 std::ifstream f(fname);
48 if (errorout)
TGo4Log::Debug(
"ERROR: Preferences file %s not existing",fname);
52 std::string hostname =
GetPar(
"hostname");
54 char formatstring[4096];
58 f.getline(formatstring,
sizeof(formatstring),
'\n' );
59 if ((f.gcount()==0) || (strlen(formatstring)==0))
continue;
61 const char* sbuf = formatstring;
64 if (*sbuf==
' ') { sbuf++;
continue; }
65 if (*sbuf==
'#')
break;
67 const char* separ = strchr(sbuf,
':');
70 std::string name(sbuf, separ-sbuf);
72 size_t pos = name.find(
'=');
74 std::string subname(name, 0, pos);
75 std::string mask(name, pos+1);
77 if ((subname.length()==0) || (mask.length()==0))
break;
79 const char* subvalue =
GetPar(subname.c_str());
81 if (subvalue==0)
break;
85 TRegexp re(mask.c_str(), kTRUE);
87 if (re.Index(subvalue, &len)!=0)
break;
88 if (len != (Int_t) strlen(subvalue))
break;
96 SetPar(name.c_str(), separ+1);
104 bool IsOk()
const {
return fPars.size()>2; }
106 void SetPar(
const char* name,
const char* value,
bool force =
true)
108 std::string dname = Form(
"%s%s%s",
"%", name,
"%");
109 if (force || (fPars.find(dname) == fPars.end()))
110 fPars[dname] = value;
115 std::string dname = Form(
"%s%s%s",
"%", name,
"%");
116 if (fPars.find(dname) == fPars.end())
return 0;
117 return fPars[dname].c_str();
133 std::map<std::string,std::string>::iterator iter = fPars.begin();
134 while (iter != fPars.end()) {
136 while ((pos = str.find(iter->first, pos)) != str.npos) {
137 str.replace(pos, iter->first.length(), iter->second);
143 std::cerr <<
"Syntax error in go4.prefs files - endless recursion" << std::endl;
144 std::cerr <<
"Program aborted, please fix an error" << std::endl;
154 while ((pos1 = str.find(
"${")) != str.npos) {
156 pos2 = str.find(
"}");
158 if ((pos1>pos2) || (pos2==str.npos)) {
159 TGo4Log::Debug(
"ERROR: Wrong variable parenthesis %s",str.c_str());
163 std::string var(str, pos1+2, pos2-pos1-2);
165 str.erase(pos1, pos2-pos1+1);
167 const char* value = gSystem->Getenv(var.c_str());
168 if (value!=0) str.insert(pos1, value);
175 const char* opt =
GetPar(prefix);
176 if (opt==0)
return std::string(
"");
177 std::string res = opt;
191 const char* remotehost,
192 const char* remotedir,
193 const char* remoteexe,
198 const char* serverhost = gSystem->HostName();
199 const char* sdisplay = gSystem->Getenv(
"DISPLAY");
201 const char* rootsys = gSystem->Getenv(
"ROOTSYS");
202 const char* path = gSystem->Getenv(
"PATH");
203 const char* ldpath = gSystem->Getenv(
"LD_LIBRARY_PATH");
205 if ((name==0) || (strlen(name)==0)) name =
"UserAnalysis";
206 if ((serverhost==0) || (strlen(serverhost)==0)) serverhost =
"localhost";
208 if (gSystem->Getenv(
"GO4OLDLAUNCH")==0) {
211 const char* shellname =
"exec";
212 if (shellkind==1) shellname =
"rsh";
else
213 if (shellkind==2) shellname = konsole==1 ?
"ssh" :
"sshX";
214 prefs.
SetPar(
"shellkind", shellname,
false);
215 prefs.
SetPar(
"exekind", Form(
"%d", exe_kind),
false);
216 prefs.
SetPar(
"clientkind", serverkind>0 ?
"Go4Server" :
"Go4Client",
false);
218 prefs.
AddFile(
"go4.prefs",
false);
221 std::cout <<
"Cannot find prefs file" << std::endl;
225 prefs.
SetPar(
"guihost", serverhost,
false);
227 prefs.
SetPar(
"guiport", Form(
"%d", guiport));
228 prefs.
SetPar(
"guigo4sys", go4sys,
false);
229 prefs.
SetPar(
"analysisname", name,
false);
230 prefs.
SetPar(
"workdir", remotedir,
false);
231 prefs.
SetPar(exe_kind==0 ?
"exename" :
"libname", remoteexe,
false);
234 if ((exe_kind==1) && (exeargs!=0) && (strlen(exeargs)>0))
235 prefs.
SetPar(
"userargs", Form(
"%s", exeargs),
false);
237 prefs.
SetPar(
"userargs",
"",
false);
240 const char* termname =
"qtwindow";
241 if (konsole==2) termname =
"xterm";
else
242 if (konsole==3) termname =
"konsole";
245 if ((shellkind==0) && (konsole==1))
246 prefs.
SetPar(
"cd_workdir",
"");
248 std::string executable;
249 bool is_exe = prefs.
GetOpt(
"exekind") !=
"1";
251 if (prefs.
GetOpt(
"exename").empty())
252 executable = prefs.
GetOpt(
"analysis_default_exe");
254 executable = prefs.
GetOpt(
"analysis_exe");
256 if (prefs.
GetOpt(
"libname").empty())
257 executable = prefs.
GetOpt(
"analysis_default_lib");
259 executable = prefs.
GetOpt(
"analysis_lib");
261 prefs.
SetPar(
"analysis", executable.c_str());
263 if (!is_exe) prefs.
SetPar(
"killexename",
"go4analysis",
false);
else {
269 const char* runname = strrchr(remoteexe, symbol);
270 prefs.
SetPar(
"killexename", runname ? runname+1 : remoteexe,
false);
273 std::string initcmd = prefs.
GetOpt(shellkind==0 ?
"execinitcmd" :
"shellinitcmd");
274 prefs.
SetPar(
"initcmd", initcmd.c_str());
276 std::string progcmd = prefs.
GetOpt((serverkind>0) ? ((serverkind==2) ?
"httpcmd" :
"servercmd") :
"clientcmd");
277 prefs.
SetPar(
"progcmd", progcmd.c_str());
279 std::string hostcmd = prefs.
GetOpt(termname);
280 prefs.
SetPar(
"hostcmd", hostcmd.c_str());
282 std::string cmd = prefs.
GetOpt(shellname);
283 std::cout <<
"cmd: " << cmd << std::endl;
284 launchcmd = cmd.c_str();
286 std::string dkill = prefs.
GetOpt(
"kill");
287 prefs.
SetPar(
"hostcmd", dkill.c_str());
288 cmd = prefs.
GetOpt(shellname);
289 std::cout <<
"killcmd: " << cmd << std::endl;
290 killcmd = cmd.c_str();
295 if ((go4sys==0) || (strlen(go4sys)==0))
return kFALSE;
299 std::ifstream launchprefs(filename.Data());
301 TGo4Log::Debug(
"Master -- ERROR: Preferences file %s not existing, could not launch client ",
306 char formatstring[1000];
308 if ((konsole<1) || (konsole>3)) konsole = 1;
310 if (serverkind>0) num+=3;
312 for(
int n=0;n<num;n++)
313 launchprefs.getline(formatstring, 1000,
'\n' );
315 const char* sh_com =
"";
316 const char* sh_host = remotehost;
317 TString serverdisplay =
"";
322 serverdisplay =
"-display ";
323 serverdisplay += sdisplay;
326 sh_com = (konsole == 0) ?
"ssh -x " :
"ssh -X ";
334 killcmd =
"killall ";
335 killcmd += remoteexe;
337 if((shellkind>0) && (strcmp(remotehost, gSystem->HostName())!=0) && (strcmp(remotehost,
"localhost")!=0)) {
338 TString precmd = sh_com;
340 precmd += remotehost;
342 killcmd.Prepend(precmd);
349 launchcmd.Form(formatstring,
350 sh_com, sh_host, serverdisplay.Data(), name, remotehost, go4sys, go4sys, rootsys,
351 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
356 launchcmd.Form(formatstring,
357 sh_com, sh_host, name, go4sys, go4sys, rootsys,
358 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
364 launchcmd.Form(formatstring,
365 sh_com, sh_host, go4sys, go4sys, rootsys,
366 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
379 fbAnalysisReady(kFALSE),
380 fbAnalysisSettingsReady(kFALSE),
381 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