00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4AnalysisProxy.h"
00015
00016 #include <string>
00017 #include <map>
00018 #include <stdlib.h>
00019
00020 #include "TH1.h"
00021 #include "TFolder.h"
00022 #include "TTree.h"
00023 #include "TLeaf.h"
00024 #include "TTime.h"
00025 #include "TSystem.h"
00026 #include "TRegexp.h"
00027
00028 #include "TGo4Log.h"
00029
00030 #include "TGo4Slot.h"
00031 #include "TGo4ObjectProxy.h"
00032 #include "TGo4ObjectManager.h"
00033
00034 #include "TGo4RemoteCommand.h"
00035 #include "TGo4AnalysisObjectResult.h"
00036 #include "TGo4ObjEnvelope.h"
00037 #include "TGo4ComExecLine.h"
00038
00039 #include "TGo4Display.h"
00040 #include "TGo4TaskManager.h"
00041 #include "TGo4TaskHandler.h"
00042 #include "TGo4ClientTask.h"
00043 #include "TGo4ServerTask.h"
00044 #include "TGo4BufferQueue.h"
00045
00046 #include "TGo4Parameter.h"
00047 #include "TGo4ObjectStatus.h"
00048
00049 #include "TGo4AnalysisStatus.h"
00050 #include "TGo4AnalysisClientStatus.h"
00051 #include "TGo4AnalysisObjectNames.h"
00052 #include "TGo4TreeStructure.h"
00053 #include "TGo4DynamicEntry.h"
00054 #include "TGo4HistogramEntry.h"
00055 #include "TGo4TreeHistogramEntry.h"
00056 #include "TGo4BranchStatus.h"
00057 #include "TGo4ParameterStatus.h"
00058 #include "TGo4MemberStatus.h"
00059
00060 enum { cmdEnvelope, cmdStatus, cmdEvStatus, cmdDefualtEnvelope };
00061
00062
00063 class TGo4AnalysisObjectAccess : public TObject, public TGo4Access {
00064 public:
00065
00066 TGo4AnalysisObjectAccess(TGo4AnalysisProxy* cont,
00067 Int_t proxykind,
00068 const char* name,
00069 const char* classname,
00070 const char* fullpath) :
00071 TObject(),
00072 TGo4Access(),
00073 fxAnalProxy(cont),
00074 fProxyKind(proxykind),
00075 fxObjName(name),
00076 fxObjClassName(classname),
00077 fxFullPath(fullpath),
00078 fxReceiver(0),
00079 fxReceiverPath(),
00080 fxSubmitTime()
00081 {
00082 }
00083
00084 virtual ~TGo4AnalysisObjectAccess() {}
00085
00086 virtual Bool_t IsRemote() const { return kTRUE; }
00087 virtual Bool_t CanGetObject() const { return kFALSE; }
00088 virtual const char* GetObjectName() const { return fxObjName.Data(); }
00089 virtual const char* GetObjectClassName() const { return fxObjClassName.Data(); }
00090
00091 const char* GetPathName() const { return fxFullPath.Data(); }
00092
00093 virtual Int_t AssignObjectTo(TGo4ObjectManager* rcv, const char* path)
00094 {
00095 if ((rcv==0) || (fxAnalProxy==0)) return 0;
00096 fxReceiver = rcv;
00097 fxReceiverPath = path;
00098 if (fxAnalProxy->SubmitProxy(this)) return 2;
00099 return 0;
00100 }
00101
00102 Int_t ProxyKind() const { return fProxyKind; }
00103
00104 void ChangeObjectName(const char* newname) { fxObjName = newname; }
00105
00106 void SetSubmitTime() { fxSubmitTime = gSystem->Now(); }
00107
00108 Bool_t CheckLifeTime(long int millisec)
00109 {
00110 long int res = gSystem->Now() - fxSubmitTime;
00111 return (res<0) || (res > millisec);
00112 }
00113
00114 void ReceiveObject(TObject* obj, const char* objfolder, const char* objname, Bool_t owner)
00115 {
00116 if (fProxyKind == cmdDefualtEnvelope) {
00117 TString path = fxReceiverPath;
00118 if ((objfolder!=0) && (strlen(objfolder)!=0)) {
00119 path += objfolder; path += "/";
00120 }
00121 if ((objname!=0) && (strlen(objname)!=0)) path += objname;
00122 DoObjectAssignement(fxReceiver, path.Data(), obj, owner);
00123
00124 } else {
00125 DoObjectAssignement(fxReceiver, fxReceiverPath.Data(), obj, owner);
00126 }
00127 }
00128
00129 void SetDefaultReceiver(TGo4ObjectManager* rcv, const char* path)
00130 {
00131 fxReceiver = rcv;
00132 fxReceiverPath = path;
00133 }
00134
00135 protected:
00136 TGo4AnalysisProxy* fxAnalProxy;
00137 Int_t fProxyKind;
00138 TString fxObjName;
00139 TString fxObjClassName;
00140 TString fxFullPath;
00141 TGo4ObjectManager* fxReceiver;
00142 TString fxReceiverPath;
00143 TTime fxSubmitTime;
00144 };
00145
00146
00147
00148
00149 class TGo4AnalysisLevelIter : public TGo4LevelIter {
00150 public:
00151 TGo4AnalysisLevelIter() :
00152 TGo4LevelIter(),
00153 fIter(0),
00154 fCurrent(0),
00155 fIsTree(kFALSE)
00156 {
00157 }
00158
00159 TGo4AnalysisLevelIter(TFolder* folder, Bool_t istree = kFALSE) :
00160 TGo4LevelIter(),
00161 fIter(0),
00162 fCurrent(0),
00163 fIsTree(istree)
00164 {
00165 fIter = folder->GetListOfFolders()->MakeIterator();
00166 }
00167
00168 virtual ~TGo4AnalysisLevelIter()
00169 {
00170 delete fIter;
00171 }
00172
00173 virtual Bool_t next()
00174 {
00175 fCurrent = fIter->Next();
00176 return (fCurrent!=0);
00177 }
00178
00179 virtual Bool_t isfolder()
00180 {
00181 return ((dynamic_cast<TFolder*>(fCurrent)!=0) ||
00182 (dynamic_cast<TGo4TreeStructure*>(fCurrent)!=0));
00183 }
00184
00185 virtual Int_t getflag(const char* flagname)
00186 {
00187 if (strcmp(flagname,"IsRemote")==0) return 1;
00188 if (strcmp(flagname,"IsDeleteProtect")==0) {
00189 TGo4ObjectStatus* sts = dynamic_cast<TGo4ObjectStatus*> (fCurrent);
00190 if (sts!=0)
00191 return sts->IsDeleteProtect() ? 1 : 0;
00192 }
00193 if (strcmp(flagname,"IsResetProtect")==0) {
00194 TGo4ObjectStatus* sts = dynamic_cast<TGo4ObjectStatus*> (fCurrent);
00195 if (sts!=0)
00196 return sts->IsResetProtect() ? 1 : 0;
00197 }
00198
00199 return -1;
00200 }
00201
00202 virtual Bool_t isremote()
00203 {
00204 return kTRUE;
00205 }
00206
00207 virtual TGo4LevelIter* subiterator()
00208 {
00209 TGo4TreeStructure* tr = dynamic_cast<TGo4TreeStructure*>(fCurrent);
00210 if (tr!=0) return new TGo4AnalysisLevelIter(tr->GetNamesFolder(), kTRUE);
00211 return new TGo4AnalysisLevelIter((TFolder*)fCurrent, fIsTree);
00212 }
00213
00214 virtual const char* name()
00215 {
00216 return fCurrent->GetName();
00217 }
00218
00219 virtual const char* info()
00220 {
00221 return fCurrent->GetTitle();
00222 }
00223
00224 virtual Int_t sizeinfo()
00225 {
00226 TGo4ObjectStatus* status = dynamic_cast <TGo4ObjectStatus*> (fCurrent);
00227 return (status==0) ? 0 : status->GetObjectSize();
00228 }
00229
00230 virtual Int_t GetKind()
00231 {
00232 Int_t kind = TGo4Access::kndNone;
00233 if (fIsTree)
00234 if (isfolder()) kind = TGo4Access::kndTreeBranch;
00235 else kind = TGo4Access::kndTreeLeaf;
00236 else
00237 if (isfolder())
00238 kind = TGo4Access::kndFolder;
00239 else {
00240 kind = TGo4Access::kndObject;
00241 if ((fCurrent!=0) && fCurrent->InheritsFrom(TGo4ParameterStatus::Class()))
00242 kind = TGo4Access::kndGo4Param;
00243 else
00244 if ((fCurrent!=0) && fCurrent->InheritsFrom(TGo4MemberStatus::Class()))
00245 kind = TGo4Access::kndDataMember;
00246 }
00247
00248 return kind;
00249 }
00250
00251 virtual const char* GetClassName()
00252 {
00253 return EntryClassName(fCurrent);
00254 }
00255
00256 static const char* EntryClassName(TObject* entry)
00257 {
00258 if (entry==0) return 0;
00259
00260 if (entry->InheritsFrom(TGo4TreeStructure::Class()))
00261 return TTree::Class()->GetName();
00262
00263 if(entry->InheritsFrom(TGo4BranchStatus::Class())) {
00264 TGo4BranchStatus* status = dynamic_cast <TGo4BranchStatus*> (entry);
00265 if (status!=0) return status->GetObjectClass();
00266 }
00267
00268 if (entry->InheritsFrom(TGo4ParameterStatus::Class())) {
00269 TGo4ParameterStatus* status = dynamic_cast<TGo4ParameterStatus*> (entry);
00270 if (status!=0) return status->GetObjectClass();
00271 }
00272
00273 if(entry->InheritsFrom(TGo4AnalysisStatus::Class())) {
00274 return TGo4AnalysisStatus::Class()->GetName();
00275 }
00276
00277 if(entry->InheritsFrom(TGo4ObjectStatus::Class())) {
00278 TGo4ObjectStatus* status = dynamic_cast <TGo4ObjectStatus*> (entry);
00279 if (status!=0) return status->GetObjectClass();
00280 }
00281
00282 return entry->ClassName();
00283 }
00284
00285 protected:
00286 TIterator* fIter;
00287 TObject* fCurrent;
00288 Bool_t fIsTree;
00289 };
00290
00291
00292
00293 class TGo4Prefs {
00294 protected:
00295 std::map<std::string, std::string> fPars;
00296 public:
00297 TGo4Prefs(const char* hostname)
00298 {
00299 SetPar("hostname", hostname);
00300 #ifdef WIN32
00301 SetPar("os", "win32");
00302 #else
00303 SetPar("os", "linux");
00304 #endif
00305 }
00306
00307 void AddFile(const char* fname, bool errorout = false)
00308 {
00309 std::ifstream f(fname);
00310 if(!f) {
00311 if (errorout) TGo4Log::Debug("ERROR: Preferences file %s not existing",fname);
00312 return;
00313 }
00314
00315 std::string hostname = GetPar("hostname");
00316
00317 char formatstring[4096];
00318
00319 while (!f.eof()) {
00320
00321 f.getline(formatstring, sizeof(formatstring), '\n' );
00322 if ((f.gcount()==0) || (strlen(formatstring)==0)) continue;
00323
00324 const char* sbuf = formatstring;
00325
00326 while (*sbuf != 0) {
00327 if (*sbuf==' ') { sbuf++; continue; }
00328 if (*sbuf=='#') break;
00329
00330 const char* separ = strchr(sbuf, ':');
00331 if (separ==0) break;
00332
00333 std::string name(sbuf, separ-sbuf);
00334
00335 size_t pos = name.find('=');
00336 if (pos!=name.npos) {
00337 std::string subname(name, 0, pos);
00338 std::string mask(name, pos+1);
00339
00340 if ((subname.length()==0) || (mask.length()==0)) break;
00341
00342 const char* subvalue = GetPar(subname.c_str());
00343
00344 if (subvalue==0) break;
00345
00346
00347
00348 TRegexp re(mask.c_str(), kTRUE);
00349 Int_t len(0);
00350 if (re.Index(subvalue, &len)!=0) break;
00351 if (len != (Int_t) strlen(subvalue)) break;
00352
00353
00354 sbuf = separ+1;
00355 continue;
00356 }
00357
00358 if (!HasPar(name.c_str()))
00359 SetPar(name.c_str(), separ+1);
00360
00361 break;
00362 }
00363 }
00364 }
00365
00367 bool IsOk() const { return fPars.size()>2; }
00368
00369 void SetPar(const char* name, const char* value, bool force = true)
00370 {
00371 std::string dname = Form("%s%s%s", "%", name, "%");
00372 if (force || (fPars.find(dname) == fPars.end()))
00373 fPars[dname] = value;
00374 }
00375
00376 const char* GetPar(const char* name)
00377 {
00378 std::string dname = Form("%s%s%s", "%", name, "%");
00379 if (fPars.find(dname) == fPars.end()) return 0;
00380 return fPars[dname].c_str();
00381 }
00382
00383 bool HasPar(const char* name)
00384 {
00385 return GetPar(name)!=0;
00386 }
00387
00388 void ReplacePars(std::string& str)
00389 {
00390 size_t pos;
00391 bool isany = false;
00392 int cnt = 0;
00393
00394 do {
00395 isany = false;
00396 std::map<std::string,std::string>::iterator iter = fPars.begin();
00397 while (iter != fPars.end()) {
00398 pos = 0;
00399 while ((pos = str.find(iter->first, pos)) != str.npos) {
00400 str.replace(pos, iter->first.length(), iter->second);
00401 isany = true;
00402 }
00403 iter++;
00404 }
00405 if (cnt++>100000) {
00406 std::cerr << "Syntax error in go4.prefs files - endless recursion" << std::endl;
00407 std::cerr << "Program aborted, please fix an error" << std::endl;
00408 exit(-1);
00409 }
00410 } while (isany);
00411 }
00412
00413 void ReplaceEnvPars(std::string& str)
00414 {
00415 size_t pos1, pos2;
00416
00417 while ((pos1 = str.find("${")) != str.npos) {
00418
00419 pos2 = str.find("}");
00420
00421 if ((pos1>pos2) || (pos2==str.npos)) {
00422 TGo4Log::Debug("ERROR: Wrong variable parenthesis %s",str.c_str());
00423 return;
00424 }
00425
00426 std::string var(str, pos1+2, pos2-pos1-2);
00427
00428 str.erase(pos1, pos2-pos1+1);
00429
00430 const char* value = gSystem->Getenv(var.c_str());
00431 if (value!=0) str.insert(pos1, value);
00432 }
00433 }
00434
00436 std::string GetOpt(const char* prefix)
00437 {
00438 const char* opt = GetPar(prefix);
00439 if (opt==0) return std::string("");
00440 std::string res = opt;
00441 ReplacePars(res);
00442 ReplaceEnvPars(res);
00443 return res;
00444 }
00445
00446 };
00447
00448
00449
00450
00451 Int_t TGo4AnalysisProxy::fNumberOfWaitingProxyes = 0;
00452
00453 TGo4AnalysisProxy::TGo4AnalysisProxy(Bool_t isserver) :
00454 TGo4Proxy(),
00455 fIsServer(isserver),
00456 fAnalysisNames(0),
00457 fxParentSlot(0),
00458 fxSubmittedProxy(),
00459 fxDefaultProxy(0),
00460 fbNamesListReceived(kFALSE),
00461 fbAnalysisReady(kFALSE),
00462 fbAnalysisSettingsReady(kFALSE),
00463 fbAnalysisRunning(kFALSE),
00464 fDisconectCounter(-111),
00465 fxDisplay(0),
00466 fInfoStr(),
00467 fActualRole(-1),
00468 fxRefreshTimer(0),
00469 fxConnectionTimer(0)
00470 {
00471 fxDisplay = new TGo4Display(!isserver);
00472
00473 fxDisplay->SetAnalysis(this);
00474
00475 fxDisplay->GetTask()->Initialization();
00476 }
00477
00478 TGo4AnalysisProxy::~TGo4AnalysisProxy()
00479 {
00480
00481
00482 if (fxRefreshTimer!=0) delete fxRefreshTimer;
00483 if (fxConnectionTimer!=0) delete fxConnectionTimer;
00484
00485 fNumberOfWaitingProxyes -= fxSubmittedProxy.GetEntries();
00486 fxSubmittedProxy.Delete();
00487
00488 delete fxDefaultProxy; fxDefaultProxy = 0;
00489
00490 delete fAnalysisNames;
00491
00492 if (fxDisplay!=0) {
00493
00494
00495 if (fDisconectCounter==-111)
00496 fxDisplay->SubmitCommand("MRQuit");
00497
00498 if (fxDisplay!=0) {
00499 fxDisplay->SetAnalysis(0);
00500 TGo4Log::Debug("TGo4Display instance is not deleted correctly when analysis proxy is destroyed");
00501 }
00502 }
00503 }
00504
00505 void TGo4AnalysisProxy::Initialize(TGo4Slot* slot)
00506 {
00507 fxParentSlot = slot;
00508
00509 TGo4Slot* subslot = new TGo4Slot(fxParentSlot, "Settings", "Analysis configuration");
00510 subslot->SetProxy(new TGo4ObjectProxy());
00511
00512 subslot = new TGo4Slot(fxParentSlot, "Ratemeter", "Analysis ratemeter");
00513 subslot->SetProxy(new TGo4ObjectProxy());
00514
00515 subslot = new TGo4Slot(fxParentSlot, "Loginfo", "Analysis logging message");
00516 subslot->SetProxy(new TGo4ObjectProxy());
00517
00518 subslot = new TGo4Slot(fxParentSlot, "UpdateObject", "Result of update object");
00519 subslot->SetProxy(new TGo4ObjectProxy());
00520 }
00521
00522 TGo4Slot* TGo4AnalysisProxy::SettingsSlot()
00523 {
00524 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("Settings");
00525 }
00526
00527 TGo4Slot* TGo4AnalysisProxy::RatemeterSlot()
00528 {
00529 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("Ratemeter");
00530 }
00531
00532 TGo4Slot* TGo4AnalysisProxy::LoginfoSlot()
00533 {
00534 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("Loginfo");
00535 }
00536
00537 TGo4Slot* TGo4AnalysisProxy::UpdateObjectSlot()
00538 {
00539 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("UpdateObject");
00540 }
00541
00542
00543 void TGo4AnalysisProxy::Finalize(TGo4Slot* slot)
00544 {
00545
00546
00547 slot->DeleteChilds();
00548
00549 fxParentSlot = 0;
00550 }
00551
00552 Bool_t TGo4AnalysisProxy::HasSublevels() const
00553 {
00554 return (fAnalysisNames!=0);
00555 }
00556
00557 TGo4LevelIter* TGo4AnalysisProxy::MakeIter()
00558 {
00559 if (fAnalysisNames==0) return 0;
00560
00561 return new TGo4AnalysisLevelIter(fAnalysisNames->GetNamesFolder(), kFALSE);
00562 }
00563
00564 void TGo4AnalysisProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00565 {
00566 }
00567
00568 void TGo4AnalysisProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00569 {
00570 }
00571
00572 Int_t TGo4AnalysisProxy::GetRole()
00573 {
00574 if (fxDisplay==0) return kGo4ComModeRefused;
00575
00576 Int_t res = kGo4ComModeRefused;
00577
00578 if (IsAnalysisServer()) {
00579 if (fActualRole>=0)
00580 res = fActualRole;
00581 } else
00582 if (fxDisplay->GetTask()!=0)
00583 if (fxDisplay->GetTask()->GetTaskHandler()!=0)
00584 res = fxDisplay->GetTask()->GetTaskHandler()->GetRole();
00585 return res;
00586 }
00587
00588 Bool_t TGo4AnalysisProxy::IsViewer()
00589 {
00590 return GetRole()==kGo4ComModeObserver;
00591 }
00592
00593 Bool_t TGo4AnalysisProxy::IsController()
00594 {
00595 return GetRole()==kGo4ComModeController;
00596 }
00597
00598 Bool_t TGo4AnalysisProxy::IsAdministrator()
00599 {
00600 return GetRole()==kGo4ComModeAdministrator;
00601 }
00602
00603 const char* TGo4AnalysisProxy::GetContainedObjectInfo()
00604 {
00605 bool disconn = false;
00606
00607 switch (GetRole()) {
00608 case kGo4ComModeObserver: fInfoStr = "Observer"; break;
00609 case kGo4ComModeController: fInfoStr = "Controller"; break;
00610 case kGo4ComModeAdministrator: fInfoStr = "Administrator"; break;
00611 default: fInfoStr = "Disconnected"; disconn = true; break;
00612 }
00613
00614 if (!disconn && (fAnalysisNames!=0) && (strcmp(fAnalysisNames->GetName(),"Go4NamesList")!=0)) {
00615 fInfoStr += " name:";
00616 fInfoStr += fAnalysisNames->GetName();
00617 }
00618
00619 return fInfoStr.Data();
00620 }
00621
00622 TGo4AnalysisObjectAccess* TGo4AnalysisProxy::FindSubmittedProxy(const char* pathname, const char* objname)
00623 {
00624 for(int n=0;n<=fxSubmittedProxy.GetLast();n++) {
00625 TGo4AnalysisObjectAccess* proxy = (TGo4AnalysisObjectAccess*) fxSubmittedProxy.At(n);
00626 if (proxy==0) continue;
00627 if (strcmp(proxy->GetObjectName(), objname)!=0) continue;
00628 if ((pathname!=0) && (strcmp(proxy->GetPathName(), pathname)!=0)) continue;
00629 return proxy;
00630 }
00631 return 0;
00632 }
00633
00634 void TGo4AnalysisProxy::DeleteSubmittedProxy(TGo4AnalysisObjectAccess* proxytodelete)
00635 {
00636 bool docompress = false;
00637 if (proxytodelete!=0) {
00638 fxSubmittedProxy.Remove(proxytodelete);
00639 delete proxytodelete;
00640 docompress = true;
00641 fNumberOfWaitingProxyes--;
00642 }
00643
00644 for(int n=0;n<=fxSubmittedProxy.GetLast();n++) {
00645 TGo4AnalysisObjectAccess* proxy = (TGo4AnalysisObjectAccess*) fxSubmittedProxy.At(n);
00646 if (proxy==0) continue;
00647 if (proxy->CheckLifeTime(100000)) {
00648 fxSubmittedProxy.Remove(proxy);
00649 docompress = true;
00650 delete proxy;
00651 fNumberOfWaitingProxyes--;
00652 }
00653 }
00654
00655 if (docompress)
00656 fxSubmittedProxy.Compress();
00657 }
00658
00659 void TGo4AnalysisProxy::ReceiveStatus(TGo4Status* status)
00660 {
00661
00662
00663 if (dynamic_cast<TGo4AnalysisStatus*> (status)!=0) {
00664 SetAnalysisReady(kTRUE);
00665 if (SettingsSlot()!=0) {
00666 SettingsSlot()->AssignObject(status, kTRUE);
00667 status =0;
00668 }
00669 CallSlotUpdate();
00670 }
00671
00672 TGo4AnalysisClientStatus* analstatus = dynamic_cast<TGo4AnalysisClientStatus*> (status);
00673 if (analstatus!=0) {
00674 fbAnalysisRunning = analstatus->IsAnalysisRunning();
00675 if (RatemeterSlot()!=0) {
00676 RatemeterSlot()->AssignObject(status, kTRUE);
00677 status=0;
00678 }
00679 }
00680
00681 TGo4AnalysisObjectResult* obres = dynamic_cast<TGo4AnalysisObjectResult*> (status);
00682 if (obres!=0) {
00683
00684
00685
00686
00687 TGo4AnalysisObjectNames* objnames = obres->GetNamesList(kTRUE);
00688 if (objnames!=0)
00689 AssignNewNamesList(objnames);
00690 if (UpdateObjectSlot()!=0) {
00691 TString fullname = obres->GetObjectFullName();
00692
00693 if (fxParentSlot!=0) {
00694 fullname.Prepend("/");
00695 fullname.Prepend(fxParentSlot->GetName());
00696 }
00697
00698 obres->SetObjectFullName(fullname.Data());
00699
00700 UpdateObjectSlot()->AssignObject(obres, kTRUE);
00701 status=0;
00702 }
00703 CallSlotUpdate();
00704 }
00705
00706
00707 if (status!=0) {
00708 TString message = status->GetName();
00709
00710
00711
00712 if(message.Contains("event classes were initialized"))
00713 SetAnalysisSettingsReady(kTRUE);
00714
00715
00716 if (message.Contains("is logged in at") && IsAnalysisServer())
00717 for(int j=0; j<4;++j)
00718 if(message.Contains(TGo4Command::GetModeDescription((Go4CommandMode_t) j ))) {
00719 fActualRole = j;
00720 break;
00721 }
00722
00723
00724 if (message.Contains("is shutting down now!")) {
00725 fActualRole = -1;
00726 TGo4Task* task = fxDisplay==0 ? 0 : fxDisplay->GetTask();
00727 TGo4BufferQueue* qu = task==0 ? 0 : task->GetCommandQueue();
00728 if(qu!=0) qu->Clear();
00729 }
00730
00731
00732 if (LoginfoSlot()!=0) {
00733 LoginfoSlot()->AssignObject(status, kTRUE);
00734 status = 0;
00735 }
00736 }
00737
00738 if (status!=0) delete status;
00739 }
00740
00741 void TGo4AnalysisProxy::ReceiveObject(TNamed* obj)
00742 {
00743
00744
00745 if (obj==0) return;
00746
00747 TGo4ObjEnvelope* envelope = dynamic_cast<TGo4ObjEnvelope*> (obj);
00748 if (envelope!=0) {
00749 TGo4AnalysisObjectAccess* proxy = FindSubmittedProxy(envelope->GetObjFolder(), envelope->GetObjName());
00750 if (proxy==0) proxy = fxDefaultProxy;
00751
00752 if (proxy!=0) {
00753 TObject* envelopeobj = envelope->TakeObject();
00754 if ((envelopeobj!=0) && envelopeobj->InheritsFrom(TH1::Class()))
00755 ((TH1*) envelopeobj)->SetDirectory(0);
00756 proxy->ReceiveObject(envelopeobj, envelope->GetObjFolder(), envelope->GetObjName(), kTRUE);
00757
00758
00759 if (proxy != fxDefaultProxy) DeleteSubmittedProxy(proxy);
00760 }
00761 delete envelope;
00762 return;
00763 }
00764
00765 TGo4AnalysisObjectNames* objnames = dynamic_cast<TGo4AnalysisObjectNames*> (obj);
00766 if (objnames!=0) {
00767 AssignNewNamesList(objnames);
00768 return;
00769 }
00770
00771 TGo4AnalysisObjectAccess* proxy = FindSubmittedProxy(0, obj->GetName());
00772 if (proxy!=0) {
00773 proxy->ReceiveObject(obj, 0, obj->GetName(), kTRUE);
00774 DeleteSubmittedProxy(proxy);
00775 return;
00776 }
00777
00778 delete obj;
00779 }
00780
00781 void TGo4AnalysisProxy::AssignNewNamesList(TGo4AnalysisObjectNames* objnames)
00782 {
00783 delete fAnalysisNames;
00784 fAnalysisNames = objnames;
00785 fbNamesListReceived = kTRUE;
00786
00787 SetAnalysisReady(kTRUE);
00788
00789 if (fxParentSlot!=0)
00790 fxParentSlot->ForwardEvent(fxParentSlot, TGo4Slot::evObjAssigned);
00791 }
00792
00793 void TGo4AnalysisProxy::RefreshNamesList()
00794 {
00795
00796
00797 fxDisplay->SubmitCommand("ANNames");
00798 fbNamesListReceived = kFALSE;
00799 }
00800
00801 void TGo4AnalysisProxy::DelayedRefreshNamesList(Int_t delay_sec)
00802 {
00803 if (fxRefreshTimer==0) fxRefreshTimer = new TTimer(this, 10, kTRUE);
00804
00805 fxRefreshTimer->Start(delay_sec*1000, kTRUE);
00806 }
00807
00808 Bool_t TGo4AnalysisProxy::NamesListReceived()
00809 {
00810 return fbNamesListReceived;
00811 }
00812
00813 TGo4Access* TGo4AnalysisProxy::MakeProxy(const char* name)
00814 {
00815 if ((name==0) || (*name==0) || (fAnalysisNames==0)) return 0;
00816
00817 TObject* entry = fAnalysisNames->GetNamesFolder()->FindObjectAny(name);
00818
00819 const char* classname = TGo4AnalysisLevelIter::EntryClassName(entry);
00820
00821 if (classname==0) return 0;
00822
00823 TString objfolder, objname;
00824 TGo4Slot::ProduceFolderAndName(name, objfolder, objname);
00825
00826
00827
00828
00829 return new TGo4AnalysisObjectAccess(this, cmdEnvelope, objname.Data(), classname, objfolder.Data());
00830 }
00831
00832 void TGo4AnalysisProxy::Update(TGo4Slot* slot, Bool_t strong)
00833 {
00834 if (strong)
00835 RefreshNamesList();
00836 }
00837
00838
00839 Bool_t TGo4AnalysisProxy::SubmitProxy(TGo4AnalysisObjectAccess* proxy)
00840 {
00841 if (proxy==0) return kFALSE;
00842
00843 fxSubmittedProxy.Add(proxy);
00844
00845 fNumberOfWaitingProxyes++;
00846
00847 proxy->SetSubmitTime();
00848
00849 if (proxy->ProxyKind()==cmdEnvelope) {
00850
00851 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANGetEnvelope");
00852 com->SetString(proxy->GetObjectName(), 0);
00853 com->SetString(proxy->GetPathName(), 1);
00854 fxDisplay->SubmitCommand(com);
00855 } else
00856 if (proxy->ProxyKind()==cmdStatus) {
00857
00858
00859 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANObjectStatus");
00860 com->SetString(proxy->GetObjectName(),0);
00861 com->SetString(proxy->GetPathName(),1);
00862 TString rcvname = proxy->GetObjectName();
00863 rcvname.Append("_status");
00864 proxy->ChangeObjectName(rcvname.Data());
00865 fxDisplay->SubmitCommand(com);
00866 } else
00867 if (proxy->ProxyKind()==cmdEvStatus) {
00868
00869
00870
00871 Bool_t astree = strcmp(proxy->GetPathName(),"Tree")==0;
00872
00873 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANGetEvent");
00874 com->SetString(proxy->GetObjectName(),0);
00875 com->SetValue(kFALSE,0);
00876 com->SetValue(kFALSE,1);
00877 com->SetValue(astree,2);
00878 fxDisplay->SubmitCommand(com);
00879 }
00880
00881 return kTRUE;
00882 }
00883
00884 void TGo4AnalysisProxy::RequestObjectStatus(const char* fullname, TGo4Slot* tgtslot)
00885 {
00886 if ((fullname==0) || (tgtslot==0)) return;
00887
00888 TString objfolder, objname;
00889 TGo4Slot::ProduceFolderAndName(fullname, objfolder, objname);
00890
00891 TGo4AnalysisObjectAccess* proxy =
00892 new TGo4AnalysisObjectAccess(this, cmdStatus, objname, "", objfolder);
00893
00894 TString tgtname;
00895 tgtslot->ProduceFullName(tgtname);
00896 proxy->AssignObjectTo(tgtslot->GetOM(), tgtname.Data());
00897 }
00898
00899 void TGo4AnalysisProxy::RequestEventStatus(const char* evname, Bool_t astree, TGo4Slot* tgtslot)
00900 {
00901 if (evname==0) return;
00902
00903 TString folder, name;
00904 TGo4Slot::ProduceFolderAndName(evname, folder, name);
00905
00906 if (tgtslot==0) {
00907
00908
00909
00910
00911 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANGetEvent");
00912 com->SetString(name,0);
00913 com->SetValue(kFALSE,0);
00914 com->SetValue(kTRUE,1);
00915 com->SetValue(astree,2);
00916 fxDisplay->SubmitCommand(com);
00917 } else {
00918 if (astree) folder = "Tree";
00919 else folder = "Event";
00920
00921 TGo4AnalysisObjectAccess* proxy =
00922 new TGo4AnalysisObjectAccess(this, cmdEvStatus, name, "", folder);
00923
00924 TString tgtname = tgtslot->GetFullName();
00925 proxy->AssignObjectTo(tgtslot->GetOM(), tgtname.Data());
00926 }
00927 }
00928
00929
00930 void TGo4AnalysisProxy::RemoteTreeDraw(const char* treename,
00931 const char* varexp,
00932 const char* cutcond,
00933 const char* hname)
00934 {
00935 TString tfoldername, tobjectname;
00936 TGo4Slot::ProduceFolderAndName(treename, tfoldername, tobjectname);
00937
00938 TString hfoldername, hobjectname;
00939 TGo4Slot::ProduceFolderAndName(hname, hfoldername, hobjectname);
00940
00941
00942 TGo4RemoteCommand* remcom = new TGo4RemoteCommand("ANAddTreeHis");
00943 remcom->SetString(hobjectname.Data(),0);
00944 remcom->SetString(tobjectname.Data(),1);
00945 remcom->SetString(varexp,2);
00946 remcom->SetString(cutcond,3);
00947 fxDisplay->SubmitCommand(remcom);
00948 }
00949
00950 void TGo4AnalysisProxy::RemotePrintEvent(const char* evname,
00951 Int_t evnumber,
00952 Int_t subid,
00953 Bool_t ishex,
00954 Bool_t islong)
00955 {
00956 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSetPrintEvent");
00957 com->SetString(evname,0);
00958 com->SetValue(evnumber, 0);
00959 com->SetValue(subid, 1);
00960 com->SetValue(islong, 2);
00961 com->SetValue(ishex, 3);
00962 com->SetValue(!ishex, 4);
00963 fxDisplay->SubmitCommand(com);
00964 }
00965
00966 Bool_t TGo4AnalysisProxy::UpdateAnalysisObject(const char* fullpath, TObject* obj)
00967 {
00968 if (obj==0) return kFALSE;
00969
00970 const char* objname = obj->GetName();
00971 if ((objname==0) || (*objname==0)) return kFALSE;
00972
00974 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANSetObject");
00975 com->SetString(objname,0);
00976 com->SetAggregate(obj);
00977 fxDisplay->SubmitCommand(com);
00978
00979 return kTRUE;
00980 }
00981
00982 void TGo4AnalysisProxy::LoadConfigFile(const char* fname)
00983 {
00984 if((fname==0) || (strlen(fname)==0)) {
00985 fxDisplay->SubmitCommand("ANLoad");
00986 } else {
00987
00988 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANLoad");
00989 com->SetString(fname,0);
00990 fxDisplay->SubmitCommand(com);
00991 }
00992 }
00993
00994 void TGo4AnalysisProxy::SaveConfigFile(const char* fname)
00995 {
00996 if((fname==0) || (strlen(fname)==0)) {
00997 fxDisplay->SubmitCommand("ANSave");
00998 } else {
00999
01000 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSave");
01001 com->SetString(fname,0);
01002 fxDisplay->SubmitCommand(com);
01003 }
01004 }
01005
01006 void TGo4AnalysisProxy::WriteAutoSave(const char* fname,
01007 Int_t complevel,
01008 Bool_t overwrite)
01009 {
01010
01011
01012
01013
01014 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANAutosave");
01015 com->SetString(fname,0);
01016 com->SetValue(complevel,0);
01017 com->SetValue(overwrite,1);
01018 fxDisplay->SubmitCommand(com);
01019 }
01020
01021 void TGo4AnalysisProxy::StartAnalysis()
01022 {
01023 fxDisplay->SubmitCommand("THStart");
01024 fbAnalysisRunning = kTRUE;
01025 }
01026
01027 void TGo4AnalysisProxy::StopAnalysis()
01028 {
01029 fxDisplay->SubmitCommand("THStop");
01030 fbAnalysisRunning = kFALSE;
01031 }
01032
01033 void TGo4AnalysisProxy::ExecuteLine(const char* line)
01034 {
01035 TGo4ComExecLine *com = new TGo4ComExecLine();
01036 com->SetLine(line);
01037 fxDisplay->SubmitCommand(com);
01038 }
01039
01040 void TGo4AnalysisProxy::ClearAnalysisObject(const char* fullpath)
01041 {
01042 TString foldername, objectname;
01043 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
01044 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANClearObject");
01045 com->SetString(objectname.Data(),0);
01046 fxDisplay->SubmitCommand(com);
01047 }
01048
01049 void TGo4AnalysisProxy::ChageObjectProtection(const char* fullpath, const char* flags)
01050 {
01051 TString foldername, objectname;
01052 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
01053 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANSetProtect");
01054 com->SetString(objectname.Data(),0);
01055 com->SetString(flags,2);
01056 fxDisplay->SubmitCommand(com);
01057 }
01058
01059 void TGo4AnalysisProxy::RemoveObjectFromAnalysis(const char* fullpath, TClass* cl)
01060 {
01061 TString foldername, objectname;
01062 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
01063 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANDelete");
01064 com->SetString(objectname.Data(),0);
01065 fxDisplay->SubmitCommand(com);
01066 }
01067
01068 void TGo4AnalysisProxy::RequestAnalysisSettings()
01069 {
01070 fxDisplay->SubmitCommand("ANGetStatus");
01071 }
01072
01073 void TGo4AnalysisProxy::SubmitAnalysisSettings()
01074 {
01075 TGo4AnalysisStatus* status = 0;
01076 if (SettingsSlot()!=0)
01077 status = dynamic_cast<TGo4AnalysisStatus*>(SettingsSlot()->GetAssignedObject());
01078 if (status!=0) {
01079 SetAnalysisSettingsReady(kFALSE);
01080 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANSetStatus");
01081 com->SetAggregate(status);
01082 fxDisplay->SubmitCommand(com);
01083 fxDisplay->SubmitCommand("ANInit");
01084 }
01085 }
01086
01087 void TGo4AnalysisProxy::CloseAnalysisSettings()
01088 {
01089 SetAnalysisSettingsReady(kFALSE);
01090
01091 fxDisplay->SubmitCommand("ANClose");
01092 }
01093
01094
01095 void TGo4AnalysisProxy::PrintDynListEntry(const char* fullpath)
01096 {
01097 TString foldername, objectname;
01098 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
01099 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANPrdyn");
01100 com->SetString(objectname.Data(),0);
01101 fxDisplay->SubmitCommand(com);
01102 }
01103
01104 Int_t TGo4AnalysisProxy::ConnectorPort()
01105 {
01106 if (fxDisplay==0) return 0;
01107
01108 TGo4ServerTask* tsk = dynamic_cast<TGo4ServerTask*>
01109 (fxDisplay->GetTask());
01110 if (tsk==0) return 0;
01111
01112 return tsk->GetTaskManager()->GetNegotiationPort();
01113 }
01114
01115
01116 Bool_t TGo4AnalysisProxy::LaunchAsClient(TString& launchcmd,
01117 TString& killcmd,
01118 Int_t usessh,
01119 Int_t konsole,
01120 const char* name,
01121 const char* remotehost,
01122 const char* remotedir,
01123 const char* remoteexe,
01124 Int_t exe_kind,
01125 const char* exeargs)
01126 {
01127 if (fxDisplay==0) return kFALSE;
01128
01129 TGo4ServerTask* tsk = dynamic_cast<TGo4ServerTask*> (fxDisplay->GetTask());
01130 if (tsk==0) return kFALSE;
01131
01132 Int_t guiport = tsk->GetTaskManager()->GetNegotiationPort();
01133
01134 if (!GetLaunchString(launchcmd, killcmd,
01135 kFALSE, usessh, konsole,
01136 name, remotehost, remotedir, remoteexe,
01137 guiport, exe_kind, exeargs)) return kFALSE;
01138
01139 tsk->StartConnectorThread();
01140
01141 if ((konsole==2) || (konsole==3))
01142 gSystem->Exec(launchcmd.Data());
01143
01144 return kTRUE;
01145 }
01146
01147 Bool_t TGo4AnalysisProxy::LaunchAsServer(TString& launchcmd,
01148 TString& killcmd,
01149 Int_t usessh,
01150 Int_t konsole,
01151 const char* name,
01152 const char* remotehost,
01153 const char* remotedir,
01154 const char* remoteexe,
01155 Int_t exe_kind,
01156 const char* exeargs)
01157 {
01158 if (!GetLaunchString(launchcmd, killcmd,
01159 kTRUE, usessh, konsole,
01160 name, remotehost, remotedir, remoteexe,
01161 0, exe_kind, exeargs)) return kFALSE;
01162
01163 if ((konsole==2) || (konsole==3))
01164 gSystem->Exec(launchcmd.Data());
01165
01166 return kTRUE;
01167 }
01168
01169 Bool_t TGo4AnalysisProxy::GetLaunchString(TString& launchcmd,
01170 TString& killcmd,
01171 Bool_t server,
01172 Int_t shellkind,
01173 Int_t konsole,
01174 const char* name,
01175 const char* remotehost,
01176 const char* remotedir,
01177 const char* remoteexe,
01178 Int_t guiport,
01179 Int_t exe_kind,
01180 const char* exeargs)
01181 {
01182 const char* serverhost = gSystem->HostName();
01183 const char* sdisplay = gSystem->Getenv("DISPLAY");
01184 const char* go4sys = TGo4Log::GO4SYS();
01185 const char* rootsys = gSystem->Getenv("ROOTSYS");
01186 const char* path = gSystem->Getenv("PATH");
01187 const char* ldpath = gSystem->Getenv("LD_LIBRARY_PATH");
01188
01189 if ((name==0) || (strlen(name)==0)) name = "UserAnalysis";
01190 if ((serverhost==0) || (strlen(serverhost)==0)) serverhost = "localhost";
01191
01192 if (gSystem->Getenv("GO4OLDLAUNCH")==0) {
01193 TGo4Prefs prefs(remotehost);
01194
01195 const char* shellname = "exec";
01196 if (shellkind==1) shellname = "rsh"; else
01197 if (shellkind==2) shellname = konsole==1 ? "ssh" : "sshX";
01198 prefs.SetPar("shellkind", shellname, false);
01199 prefs.SetPar("exekind", Form("%d", exe_kind), false);
01200 prefs.SetPar("clientkind", server ? "Go4Server" : "Go4Client", false);
01201
01202 prefs.AddFile("go4.prefs", false);
01203 prefs.AddFile(TGo4Log::subGO4SYS("etc/go4.prefs"), true);
01204 if (!prefs.IsOk()) {
01205 std::cout << "Cannot find prefs file" << std::endl;
01206 return kFALSE;
01207 }
01208
01209 prefs.SetPar("guihost", serverhost, false);
01210 if (!server) prefs.SetPar("guiport", Form("%d", guiport));
01211 prefs.SetPar("guigo4sys", go4sys, false);
01212 prefs.SetPar("analysisname", name, false);
01213 prefs.SetPar("workdir", remotedir, false);
01214 prefs.SetPar(exe_kind==0 ? "exename" : "libname", remoteexe, false);
01215
01216
01217 if ((exe_kind==1) && (exeargs!=0) && (strlen(exeargs)>0))
01218 prefs.SetPar("userargs", Form("%s", exeargs), false);
01219 else
01220 prefs.SetPar("userargs", "", false);
01221
01222
01223 const char* termname = "qtwindow";
01224 if (konsole==2) termname = "xterm"; else
01225 if (konsole==3) termname = "konsole";
01226
01227
01228 if ((shellkind==0) && (konsole==1))
01229 prefs.SetPar("cd_workdir", "");
01230
01231 std::string executable;
01232 bool is_exe = prefs.GetOpt("exekind") != "1";
01233 if (is_exe) {
01234 if (prefs.GetOpt("exename").empty())
01235 executable = prefs.GetOpt("analysis_default_exe");
01236 else
01237 executable = prefs.GetOpt("analysis_exe");
01238 } else {
01239 if (prefs.GetOpt("libname").empty())
01240 executable = prefs.GetOpt("analysis_default_lib");
01241 else
01242 executable = prefs.GetOpt("analysis_lib");
01243 }
01244 prefs.SetPar("analysis", executable.c_str());
01245
01246 if (!is_exe) prefs.SetPar("killexename", "go4analysis", false); else {
01247 #ifdef WIN32
01248 char symbol = '\\';
01249 #else
01250 char symbol = '/';
01251 #endif
01252 const char* runname = strrchr(remoteexe, symbol);
01253 prefs.SetPar("killexename", runname ? runname+1 : remoteexe, false);
01254 }
01255
01256 std::string initcmd = prefs.GetOpt(shellkind==0 ? "execinitcmd" : "shellinitcmd");
01257 prefs.SetPar("initcmd", initcmd.c_str());
01258
01259 std::string progcmd = prefs.GetOpt(server ? "servercmd" : "clientcmd");
01260 prefs.SetPar("progcmd", progcmd.c_str());
01261
01262 std::string hostcmd = prefs.GetOpt(termname);
01263 prefs.SetPar("hostcmd", hostcmd.c_str());
01264
01265 std::string cmd = prefs.GetOpt(shellname);
01266 std::cout << "cmd: " << cmd << std::endl;
01267 launchcmd = cmd.c_str();
01268
01269 std::string dkill = prefs.GetOpt("kill");
01270 prefs.SetPar("hostcmd", dkill.c_str());
01271 cmd = prefs.GetOpt(shellname);
01272 std::cout << "killcmd: " << cmd << std::endl;
01273 killcmd = cmd.c_str();
01274
01275 return kTRUE;
01276
01277 }
01278
01279 if ((go4sys==0) || (strlen(go4sys)==0)) return kFALSE;
01280
01281 TString filename = TGo4Log::subGO4SYS(TGo4ServerTask::Get_fgcLAUNCHPREFSFILE());
01282
01283 std::ifstream launchprefs(filename.Data());
01284 if(!launchprefs) {
01285 TGo4Log::Debug("Master -- ERROR: Preferences file %s not existing, could not launch client ",
01286 filename.Data());
01287 return kFALSE;
01288 }
01289
01290 char formatstring[1000];
01291
01292 if ((konsole<1) || (konsole>3)) konsole = 1;
01293 Int_t num = konsole;
01294 if (server) num+=3;
01295
01296 for(int n=0;n<num;n++)
01297 launchprefs.getline(formatstring, 1000, '\n' );
01298
01299 const char* sh_com = "";
01300 const char* sh_host = remotehost;
01301 TString serverdisplay = "";
01302
01303 switch (shellkind) {
01304 case 1:
01305 sh_com = "rsh -n";
01306 serverdisplay = "-display ";
01307 serverdisplay += sdisplay;
01308 break;
01309 case 2:
01310 sh_com = (konsole == 0) ? "ssh -x " : "ssh -X ";
01311 break;
01312 default:
01313 sh_com = "";
01314 sh_host = "";
01315 break;
01316 }
01317
01318 killcmd = "killall ";
01319 killcmd += remoteexe;
01320
01321 if((shellkind>0) && (strcmp(remotehost, gSystem->HostName())!=0) && (strcmp(remotehost,"localhost")!=0)) {
01322 TString precmd = sh_com;
01323 precmd += " ";
01324 precmd += remotehost;
01325 precmd += " ";
01326 killcmd.Prepend(precmd);
01327 }
01328
01329 launchcmd = "";
01330
01331 switch(konsole) {
01332 case 2: {
01333 launchcmd.Form(formatstring,
01334 sh_com, sh_host, serverdisplay.Data(), name, remotehost, go4sys, go4sys, rootsys,
01335 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
01336 break;
01337 }
01338
01339 case 3: {
01340 launchcmd.Form(formatstring,
01341 sh_com, sh_host, name, go4sys, go4sys, rootsys,
01342 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
01343 break;
01344 }
01345
01346 default: {
01347
01348 launchcmd.Form(formatstring,
01349 sh_com, sh_host, go4sys, go4sys, rootsys,
01350 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
01351 break;
01352 }
01353 }
01354
01355 return kTRUE;
01356 }
01357
01358 Bool_t TGo4AnalysisProxy::ConnectToServer(const char* remotehost,
01359 Int_t remoteport,
01360 Int_t ascontroller,
01361 const char* accesspass)
01362 {
01363
01364 TGo4ClientTask* client =
01365 dynamic_cast<TGo4ClientTask*> (fxDisplay->GetTask());
01366 if(client!=0) {
01367 Go4CommandMode_t mode = kGo4ComModeObserver;
01368 switch (ascontroller) {
01369 case 0: mode = kGo4ComModeObserver; break;
01370 case 1: mode = kGo4ComModeController; break;
01371 case 2: mode = kGo4ComModeAdministrator; break;
01372 }
01373 if (accesspass==0)
01374 switch (mode) {
01375 case kGo4ComModeObserver: accesspass = "go4view"; break;
01376 case kGo4ComModeController: accesspass = "go4ctrl"; break;
01377 case kGo4ComModeAdministrator: accesspass = "go4super"; break;
01378 default: accesspass = ""; break;
01379 }
01380
01381
01382
01383 client->ConnectServer(remotehost, remoteport, mode, accesspass);
01384 RefreshNamesList();
01385 }
01386
01387 return (client!=0);
01388 }
01389
01390 Bool_t TGo4AnalysisProxy::WaitForConnection(Int_t seconds)
01391 {
01392 Int_t period = seconds*1000;
01393 while (period>0) {
01394 if (IsConnected()) return kTRUE;
01395 gSystem->Sleep(100);
01396 gSystem->ProcessEvents();
01397 period-=100;
01398 }
01399 return IsConnected();
01400 }
01401
01402
01403 void TGo4AnalysisProxy::DisconnectAnalysis(Int_t waittime, Bool_t servershutdown)
01404 {
01405 if (fDisconectCounter>0) return;
01406
01407 if (fxDisplay!=0) {
01408 if (servershutdown)
01409 fxDisplay->SubmitCommand("SVQuit");
01410 else
01411 fxDisplay->SubmitCommand("MRQuit");
01412 }
01413
01414 fDisconectCounter = waittime*10;
01415
01416 fActualRole = -1;
01417
01418 CallSlotUpdate();
01419
01420 if (fxConnectionTimer==0)
01421 fxConnectionTimer = new TTimer(this, 10, kTRUE);
01422
01423 fxConnectionTimer->Start(100, kTRUE);
01424 }
01425
01426 Bool_t TGo4AnalysisProxy::IsConnected()
01427 {
01428 if (fxDisplay==0) return kFALSE;
01429
01430 if (!fxDisplay->IsConnected()) return kFALSE;
01431
01432 return !IsAnalysisServer() || (fActualRole>=0);
01433 }
01434
01435 void TGo4AnalysisProxy::DisplayDeleted(TGo4Display* displ)
01436 {
01437 if (fxDisplay==displ) fxDisplay=0;
01438 }
01439
01440 void TGo4AnalysisProxy::DisplayDisconnected(TGo4Display* displ)
01441 {
01442 if ((fxDisplay==displ) && (displ!=0))
01443 DisconnectAnalysis(5, false);
01444
01445 }
01446
01447
01448 void TGo4AnalysisProxy::CallSlotUpdate()
01449 {
01450
01451
01452 if (fxParentSlot!=0)
01453 fxParentSlot->ForwardEvent(fxParentSlot, TGo4Slot::evObjUpdated);
01454 }
01455
01456 Bool_t TGo4AnalysisProxy::HandleTimer(TTimer* timer)
01457 {
01458 if (timer == fxRefreshTimer) {
01459 RefreshNamesList();
01460 } else
01461 if (timer == fxConnectionTimer) {
01462
01463 if (fxDisplay != 0) {
01464
01465 if (fDisconectCounter > 0) {
01466 fDisconectCounter--;
01467 fxConnectionTimer->Start(100, kTRUE);
01468
01469 } else {
01470
01471
01472 std::cout<< " TGo4AnalysisProxy::HandleTimer still sees not that display is gone. Cleanup myself!"<< std::endl;
01473 fxConnectionTimer->TurnOff();
01474 fxConnectionTimer = 0;
01475 if (fxParentSlot != 0) {
01476
01477
01478
01479
01480
01481 fxParentSlot->Delete();
01482
01483
01484 } else {
01485 delete this;
01486 }
01487 }
01488 }
01489 }
01490 return kFALSE;
01491 }
01492
01493 void TGo4AnalysisProxy::SetDefaultReceiver(TGo4ObjectManager* rcv, const char* path)
01494 {
01495 if (rcv==0) {
01496 delete fxDefaultProxy; fxDefaultProxy = 0;
01497 } else {
01498 if (fxDefaultProxy==0) fxDefaultProxy = new TGo4AnalysisObjectAccess(this, cmdDefualtEnvelope, "", "", "");
01499 fxDefaultProxy->SetDefaultReceiver(rcv, path);
01500 }
01501 }