00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4AnalysisProxy.h"
00017
00018 #include "Riostream.h"
00019 #include "TH1.h"
00020 #include "TFolder.h"
00021 #include "TTree.h"
00022 #include "TLeaf.h"
00023 #include "TTime.h"
00024 #include "TSystem.h"
00025
00026 #include "TGo4Log.h"
00027
00028 #include "TGo4Slot.h"
00029 #include "TGo4ObjectProxy.h"
00030 #include "TGo4ObjectManager.h"
00031
00032 #include "TGo4RemoteCommand.h"
00033 #include "TGo4AnalysisObjectResult.h"
00034 #include "TGo4ObjEnvelope.h"
00035 #include "TGo4ComExecLine.h"
00036
00037 #include "TGo4Display.h"
00038 #include "TGo4TaskManager.h"
00039 #include "TGo4TaskHandler.h"
00040 #include "TGo4ClientTask.h"
00041 #include "TGo4ServerTask.h"
00042 #include "TGo4BufferQueue.h"
00043
00044 #include "TGo4Parameter.h"
00045 #include "TGo4ObjectStatus.h"
00046
00047 #include "TGo4AnalysisStatus.h"
00048 #include "TGo4AnalysisClientStatus.h"
00049 #include "TGo4AnalysisObjectNames.h"
00050 #include "TGo4TreeStructure.h"
00051 #include "TGo4DynamicEntry.h"
00052 #include "TGo4HistogramEntry.h"
00053 #include "TGo4TreeHistogramEntry.h"
00054 #include "TGo4BranchStatus.h"
00055 #include "TGo4ParameterStatus.h"
00056 #include "TGo4MemberStatus.h"
00057
00058 enum { cmdEnvelope, cmdStatus, cmdEvStatus };
00059
00060
00061 class TGo4AnalysisObjectAccess : public TObject, public TGo4Access {
00062 public:
00063
00064 TGo4AnalysisObjectAccess(TGo4AnalysisProxy* cont,
00065 Int_t proxykind,
00066 const char* name,
00067 const char* classname,
00068 const char* fullpath) :
00069 TObject(),
00070 TGo4Access(),
00071 fxAnalProxy(cont),
00072 fProxyKind(proxykind),
00073 fxObjName(name),
00074 fxObjClassName(classname),
00075 fxFullPath(fullpath),
00076 fxReceiver(0),
00077 fPermanentProxy(kFALSE)
00078 {
00079 }
00080
00081 virtual ~TGo4AnalysisObjectAccess() {}
00082
00083 virtual Bool_t IsRemote() const { return kTRUE; }
00084 virtual Bool_t CanGetObject() const { return kFALSE; }
00085 virtual const char* GetObjectName() const { return fxObjName.Data(); }
00086 virtual const char* GetObjectClassName() const { return fxObjClassName.Data(); }
00087
00088 const char* GetPathName() const { return fxFullPath.Data(); }
00089
00090 virtual Int_t AssignObjectTo(TGo4ObjectReceiver* rcv, const char* path)
00091 {
00092 if ((rcv==0) || (fxAnalProxy==0)) return 0;
00093 fxReceiver = rcv;
00094 fxReceiverPath = path;
00095 if (fxAnalProxy->SubmitProxy(this)) return 2;
00096 return 0;
00097 }
00098
00099 Int_t ProxyKind() const { return fProxyKind; }
00100
00101 void ChangeObjectName(const char* newname) { fxObjName = newname; }
00102
00103 void SetSubmitTime() { fxSubmitTime = gSystem->Now(); }
00104
00105 Bool_t CheckLifeTime(long int millisec)
00106 {
00107 long int res = gSystem->Now() - fxSubmitTime;
00108 return (res<0) || (res > millisec);
00109 }
00110
00111 void ReceiveObject(TObject* obj, Bool_t owner)
00112 {
00113 DoObjectAssignement(fxReceiver, fxReceiverPath.Data(), obj, owner);
00114 }
00115
00116 protected:
00117 TGo4AnalysisProxy* fxAnalProxy;
00118 Int_t fProxyKind;
00119 TString fxObjName;
00120 TString fxObjClassName;
00121 TString fxFullPath;
00122 TGo4ObjectReceiver* fxReceiver;
00123 TString fxReceiverPath;
00124 TTime fxSubmitTime;
00125 Bool_t fPermanentProxy;
00126 };
00127
00128
00129
00130
00131 class TGo4AnalysisLevelIter : public TGo4LevelIter {
00132 public:
00133 TGo4AnalysisLevelIter() :
00134 TGo4LevelIter(),
00135 fIter(0),
00136 fCurrent(0),
00137 fIsTree(kFALSE)
00138 {
00139 }
00140
00141 TGo4AnalysisLevelIter(TFolder* folder, Bool_t istree = kFALSE) :
00142 TGo4LevelIter(),
00143 fIter(0),
00144 fCurrent(0),
00145 fIsTree(istree)
00146 {
00147 fIter = folder->GetListOfFolders()->MakeIterator();
00148 }
00149
00150 virtual ~TGo4AnalysisLevelIter()
00151 {
00152 delete fIter;
00153 }
00154
00155 virtual Bool_t next()
00156 {
00157 fCurrent = fIter->Next();
00158 return (fCurrent!=0);
00159 }
00160
00161 virtual Bool_t isfolder()
00162 {
00163 return ((dynamic_cast<TFolder*>(fCurrent)!=0) ||
00164 (dynamic_cast<TGo4TreeStructure*>(fCurrent)!=0));
00165 }
00166
00167 virtual Int_t getflag(const char* flagname)
00168 {
00169 if (strcmp(flagname,"IsRemote")==0) return 1;
00170 if (strcmp(flagname,"IsDeleteProtect")==0) {
00171 TGo4ObjectStatus* sts = dynamic_cast<TGo4ObjectStatus*> (fCurrent);
00172 if (sts!=0){
00173 if (sts->IsDeleteProtect()) return 1;
00174 else return 0;
00175 }
00176 }
00177 if (strcmp(flagname,"IsResetProtect")==0) {
00178 TGo4ObjectStatus* sts = dynamic_cast<TGo4ObjectStatus*> (fCurrent);
00179 if (sts!=0){
00180 if (sts->IsResetProtect()) return 1;
00181 else return 0;
00182 }
00183 }
00184
00185 return -1;
00186 }
00187
00188 virtual Bool_t isremote()
00189 {
00190 return kTRUE;
00191 }
00192
00193 virtual TGo4LevelIter* subiterator()
00194 {
00195 TGo4TreeStructure* tr = dynamic_cast<TGo4TreeStructure*>(fCurrent);
00196 if (tr!=0) return new TGo4AnalysisLevelIter(tr->GetNamesFolder(), kTRUE);
00197 return new TGo4AnalysisLevelIter((TFolder*)fCurrent, fIsTree);
00198 }
00199
00200 virtual const char* name()
00201 {
00202 return fCurrent->GetName();
00203 }
00204
00205 virtual const char* info()
00206 {
00207 return fCurrent->GetTitle();
00208 }
00209
00210 virtual Int_t sizeinfo()
00211 {
00212 TGo4ObjectStatus* status = dynamic_cast <TGo4ObjectStatus*> (fCurrent);
00213 return (status==0) ? 0 : status->GetObjectSize();
00214 }
00215
00216 virtual Int_t GetKind()
00217 {
00218 Int_t kind = TGo4Access::kndNone;
00219 if (fIsTree)
00220 if (isfolder()) kind = TGo4Access::kndTreeBranch;
00221 else kind = TGo4Access::kndTreeLeaf;
00222 else
00223 if (isfolder())
00224 kind = TGo4Access::kndFolder;
00225 else {
00226 kind = TGo4Access::kndObject;
00227 if ((fCurrent!=0) && fCurrent->InheritsFrom(TGo4ParameterStatus::Class()))
00228 kind = TGo4Access::kndGo4Param;
00229 else
00230 if ((fCurrent!=0) && fCurrent->InheritsFrom(TGo4MemberStatus::Class()))
00231 kind = TGo4Access::kndDataMember;
00232 }
00233
00234 return kind;
00235 }
00236
00237 virtual const char* GetClassName()
00238 {
00239 return EntryClassName(fCurrent);
00240 }
00241
00242 static const char* EntryClassName(TObject* entry)
00243 {
00244 if (entry==0) return 0;
00245
00246 if (entry->InheritsFrom(TGo4TreeStructure::Class()))
00247 return TTree::Class()->GetName();
00248
00249 if(entry->InheritsFrom(TGo4BranchStatus::Class())) {
00250 TGo4BranchStatus* status = dynamic_cast <TGo4BranchStatus*> (entry);
00251 if (status!=0) return status->GetObjectClass();
00252 }
00253
00254 if (entry->InheritsFrom(TGo4ParameterStatus::Class())) {
00255 TGo4ParameterStatus* status = dynamic_cast<TGo4ParameterStatus*> (entry);
00256 if (status!=0) return status->GetObjectClass();
00257 }
00258
00259 if(entry->InheritsFrom(TGo4AnalysisStatus::Class())) {
00260 return TGo4AnalysisStatus::Class()->GetName();
00261 }
00262
00263 if(entry->InheritsFrom(TGo4ObjectStatus::Class())) {
00264 TGo4ObjectStatus* status = dynamic_cast <TGo4ObjectStatus*> (entry);
00265 if (status!=0) return status->GetObjectClass();
00266 }
00267
00268 return entry->ClassName();
00269 }
00270
00271 protected:
00272 TIterator* fIter;
00273 TObject* fCurrent;
00274 Bool_t fIsTree;
00275 };
00276
00277
00278
00279 Int_t TGo4AnalysisProxy::fNumberOfWaitingProxyes = 0;
00280
00281 TGo4AnalysisProxy::TGo4AnalysisProxy(Bool_t isserver) :
00282 TGo4Proxy(),
00283 fIsServer(isserver),
00284 fAnalysisNames(0),
00285 fxParentSlot(0),
00286 fxSubmittedProxy(),
00287 fbNamesListReceived(kFALSE),
00288 fbAnalysisReady(kFALSE),
00289 fbAnalysisSettingsReady(kFALSE),
00290 fbAnalysisRunning(kFALSE),
00291 fDisconectCounter(-111),
00292 fxDisplay(0),
00293 fInfoStr(),
00294 fActualRole(-1),
00295 fxRefreshTimer(0),
00296 fxConnectionTimer(0)
00297 {
00298 fxDisplay = new TGo4Display(!isserver);
00299
00300 fxDisplay->SetAnalysis(this);
00301
00302 fxDisplay->GetTask()->Initialization();
00303 }
00304
00305 TGo4AnalysisProxy::~TGo4AnalysisProxy()
00306 {
00307
00308
00309 if (fxRefreshTimer!=0) delete fxRefreshTimer;
00310 if (fxConnectionTimer!=0) delete fxConnectionTimer;
00311
00312 fNumberOfWaitingProxyes -= fxSubmittedProxy.GetEntries();
00313 fxSubmittedProxy.Delete();
00314
00315 delete fAnalysisNames;
00316
00317 if (fxDisplay!=0) {
00318
00319
00320 if (fDisconectCounter==-111)
00321 fxDisplay->SubmitCommand("MRQuit");
00322
00323 if (fxDisplay!=0) {
00324 fxDisplay->SetAnalysis(0);
00325 TGo4Log::Debug("TGo4Display instance is not deleted correctly when analysis proxy is destroyed");
00326 }
00327 }
00328 }
00329
00330 void TGo4AnalysisProxy::Initialize(TGo4Slot* slot)
00331 {
00332 fxParentSlot = slot;
00333
00334 TGo4Slot* subslot = new TGo4Slot(fxParentSlot, "Settings","Analsys configuration");
00335 subslot->SetProxy(new TGo4ObjectProxy());
00336
00337 subslot = new TGo4Slot(fxParentSlot, "Ratemeter", "Analsys ratemeter");
00338 subslot->SetProxy(new TGo4ObjectProxy());
00339
00340 subslot = new TGo4Slot(fxParentSlot, "Loginfo", "Analsys logging message");
00341 subslot->SetProxy(new TGo4ObjectProxy());
00342
00343 subslot = new TGo4Slot(fxParentSlot, "UpdateObject", "Result of update object");
00344 subslot->SetProxy(new TGo4ObjectProxy());
00345 }
00346
00347 TGo4Slot* TGo4AnalysisProxy::SettingsSlot()
00348 {
00349 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("Settings");
00350 }
00351
00352 TGo4Slot* TGo4AnalysisProxy::RatemeterSlot()
00353 {
00354 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("Ratemeter");
00355 }
00356
00357 TGo4Slot* TGo4AnalysisProxy::LoginfoSlot()
00358 {
00359 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("Loginfo");
00360 }
00361
00362 TGo4Slot* TGo4AnalysisProxy::UpdateObjectSlot()
00363 {
00364 return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("UpdateObject");
00365 }
00366
00367
00368 void TGo4AnalysisProxy::Finalize(TGo4Slot* slot)
00369 {
00370
00371
00372 slot->DeleteChilds();
00373
00374 fxParentSlot = 0;
00375 }
00376
00377 Bool_t TGo4AnalysisProxy::HasSublevels() const
00378 {
00379 return (fAnalysisNames!=0);
00380 }
00381
00382 TGo4LevelIter* TGo4AnalysisProxy::MakeIter()
00383 {
00384 if (fAnalysisNames==0) return 0;
00385
00386 return new TGo4AnalysisLevelIter(fAnalysisNames->GetNamesFolder(), kFALSE);
00387 }
00388
00389 void TGo4AnalysisProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00390 {
00391 }
00392
00393 void TGo4AnalysisProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00394 {
00395 }
00396
00397 Int_t TGo4AnalysisProxy::GetRole()
00398 {
00399 if (fxDisplay==0) return kGo4ComModeRefused;
00400
00401 Int_t res = kGo4ComModeRefused;
00402
00403 if (IsAnalysisServer()) {
00404 if (fActualRole>=0)
00405 res = fActualRole;
00406 } else
00407 if (fxDisplay->GetTask()!=0)
00408 if (fxDisplay->GetTask()->GetTaskHandler()!=0)
00409 res = fxDisplay->GetTask()->GetTaskHandler()->GetRole();
00410 return res;
00411 }
00412
00413 Bool_t TGo4AnalysisProxy::IsViewer()
00414 {
00415 return GetRole()==kGo4ComModeObserver;
00416 }
00417
00418 Bool_t TGo4AnalysisProxy::IsController()
00419 {
00420 return GetRole()==kGo4ComModeController;
00421 }
00422
00423 Bool_t TGo4AnalysisProxy::IsAdministrator()
00424 {
00425 return GetRole()==kGo4ComModeAdministrator;
00426 }
00427
00428 const char* TGo4AnalysisProxy::GetContainedObjectInfo()
00429 {
00430 switch (GetRole()) {
00431 case kGo4ComModeObserver: fInfoStr = "Observer"; break;
00432 case kGo4ComModeController: fInfoStr = "Controller"; break;
00433 case kGo4ComModeAdministrator: fInfoStr = "Administrator"; break;
00434 default: fInfoStr = "Disconnected"; break;
00435 }
00436
00437 return fInfoStr.Data();
00438 }
00439
00440 TGo4AnalysisObjectAccess* TGo4AnalysisProxy::FindSubmittedProxy(const char* pathname, const char* objname)
00441 {
00442 for(int n=0;n<=fxSubmittedProxy.GetLast();n++) {
00443 TGo4AnalysisObjectAccess* proxy = (TGo4AnalysisObjectAccess*) fxSubmittedProxy.At(n);
00444 if (proxy==0) continue;
00445 if (strcmp(proxy->GetObjectName(), objname)!=0) continue;
00446 if ((pathname!=0) && (strcmp(proxy->GetPathName(), pathname)!=0)) continue;
00447 return proxy;
00448 }
00449 return 0;
00450 }
00451
00452 void TGo4AnalysisProxy::DeleteSubmittedProxy(TGo4AnalysisObjectAccess* proxytodelete)
00453 {
00454 bool docompress = false;
00455 if (proxytodelete!=0) {
00456 fxSubmittedProxy.Remove(proxytodelete);
00457 delete proxytodelete;
00458 docompress = true;
00459 fNumberOfWaitingProxyes--;
00460 }
00461
00462 for(int n=0;n<=fxSubmittedProxy.GetLast();n++) {
00463 TGo4AnalysisObjectAccess* proxy = (TGo4AnalysisObjectAccess*) fxSubmittedProxy.At(n);
00464 if (proxy==0) continue;
00465 if (proxy->CheckLifeTime(100000)) {
00466 fxSubmittedProxy.Remove(proxy);
00467 docompress = true;
00468 delete proxy;
00469 fNumberOfWaitingProxyes--;
00470 }
00471 }
00472
00473 if (docompress)
00474 fxSubmittedProxy.Compress();
00475 }
00476
00477 void TGo4AnalysisProxy::ReceiveStatus(TGo4Status* status)
00478 {
00479 if (dynamic_cast<TGo4AnalysisStatus*> (status)!=0) {
00480 SetAnalysisReady(kTRUE);
00481 if (SettingsSlot()!=0) {
00482 SettingsSlot()->AssignObject(status, kTRUE);
00483 status =0;
00484 }
00485 CallSlotUpdate();
00486 }
00487
00488 TGo4AnalysisClientStatus* analstatus = dynamic_cast<TGo4AnalysisClientStatus*> (status);
00489 if (analstatus!=0) {
00490 fbAnalysisRunning = analstatus->IsAnalysisRunning();
00491 if (RatemeterSlot()!=0) {
00492 RatemeterSlot()->AssignObject(status, kTRUE);
00493 status=0;
00494 }
00495 }
00496
00497 TGo4AnalysisObjectResult* obres=dynamic_cast<TGo4AnalysisObjectResult*> (status);
00498 if (obres!=0) {
00499
00500
00501
00502
00503 TGo4AnalysisObjectNames* objnames = obres->GetNamesList(kTRUE);
00504 if (objnames!=0)
00505 AssignNewNamesList(objnames);
00506 if (UpdateObjectSlot()!=0) {
00507 TString fullname = obres->GetObjectFullName();
00508
00509 if (fxParentSlot!=0) {
00510 fullname.Prepend("/");
00511 fullname.Prepend(fxParentSlot->GetName());
00512 }
00513
00514 obres->SetObjectFullName(fullname.Data());
00515
00516 UpdateObjectSlot()->AssignObject(obres, kTRUE);
00517 status=0;
00518 }
00519 CallSlotUpdate();
00520 }
00521
00522
00523 if (status!=0) {
00524 TString message = status->GetName();
00525
00526
00527
00528 if(message.Contains("event classes were initialized"))
00529 SetAnalysisSettingsReady(kTRUE);
00530
00531
00532 if (message.Contains("is logged in at") && IsAnalysisServer())
00533 for(int j=0; j<4;++j)
00534 if(message.Contains(TGo4Command::GetModeDescription((Go4CommandMode_t) j ))) {
00535 fActualRole = j;
00536 break;
00537 }
00538
00539
00540 if (message.Contains("is shutting down now!")) {
00541 fActualRole = -1;
00542 TGo4Task* task = fxDisplay==0 ? 0 : fxDisplay->GetTask();
00543 TGo4BufferQueue* qu = task==0 ? 0 : task->GetCommandQueue();
00544 if(qu!=0) qu->Clear();
00545 }
00546
00547
00548 if (LoginfoSlot()!=0) {
00549 LoginfoSlot()->AssignObject(status, kTRUE);
00550 status = 0;
00551 }
00552 }
00553
00554 if (status!=0) delete status;
00555 }
00556
00557 void TGo4AnalysisProxy::ReceiveObject(TNamed* obj)
00558
00559 {
00560 if (obj==0) return;
00561
00562
00563
00564
00565 TGo4ObjEnvelope* envelope = dynamic_cast<TGo4ObjEnvelope*> (obj);
00566 if (envelope!=0) {
00567 TGo4AnalysisObjectAccess* proxy = FindSubmittedProxy(envelope->GetObjFolder(), envelope->GetObjName());
00568 if (proxy!=0) {
00569 TObject* envelopeobj = envelope->TakeObject();
00570 if ((envelopeobj!=0) && envelopeobj->InheritsFrom(TH1::Class()))
00571 ((TH1*) envelopeobj)->SetDirectory(0);
00572 proxy->ReceiveObject(envelopeobj, kTRUE);
00573 DeleteSubmittedProxy(proxy);
00574 }
00575 delete envelope;
00576 return;
00577 }
00578
00579 TGo4AnalysisObjectNames* objnames = dynamic_cast<TGo4AnalysisObjectNames*> (obj);
00580 if (objnames!=0) {
00581 AssignNewNamesList(objnames);
00582 return;
00583 }
00584
00585 TGo4AnalysisObjectAccess* proxy = FindSubmittedProxy(0, obj->GetName());
00586 if (proxy!=0) {
00587 proxy->ReceiveObject(obj, kTRUE);
00588 DeleteSubmittedProxy(proxy);
00589 return;
00590 }
00591
00592
00593
00594 delete obj;
00595 }
00596
00597 void TGo4AnalysisProxy::AssignNewNamesList(TGo4AnalysisObjectNames* objnames)
00598 {
00599 delete fAnalysisNames;
00600 fAnalysisNames = objnames;
00601 fbNamesListReceived = kTRUE;
00602
00603 SetAnalysisReady(kTRUE);
00604
00605 if (fxParentSlot!=0)
00606 fxParentSlot->ForwardEvent(fxParentSlot, TGo4Slot::evObjAssigned);
00607 }
00608
00609 void TGo4AnalysisProxy::RefreshNamesList()
00610 {
00611
00612
00613 fxDisplay->SubmitCommand("ANNames");
00614 fbNamesListReceived = kFALSE;
00615 }
00616
00617 void TGo4AnalysisProxy::DelayedRefreshNamesList(Int_t delay_sec)
00618 {
00619 if (fxRefreshTimer==0) fxRefreshTimer = new TTimer(this, 10, kTRUE);
00620
00621 fxRefreshTimer->Start(delay_sec*1000, kTRUE);
00622 }
00623
00624 Bool_t TGo4AnalysisProxy::NamesListReceived()
00625 {
00626 return fbNamesListReceived;
00627 }
00628
00629 TGo4Access* TGo4AnalysisProxy::MakeProxy(const char* name)
00630 {
00631 if ((name==0) || (*name==0) || (fAnalysisNames==0)) return 0;
00632
00633 TObject* entry = fAnalysisNames->GetNamesFolder()->FindObjectAny(name);
00634
00635 const char* classname = TGo4AnalysisLevelIter::EntryClassName(entry);
00636
00637 if (classname==0) return 0;
00638
00639 TString objfolder, objname;
00640 TGo4Slot::ProduceFolderAndName(name, objfolder, objname);
00641
00642
00643
00644
00645 return new TGo4AnalysisObjectAccess(this, cmdEnvelope, objname.Data(), classname, objfolder.Data());
00646 }
00647
00648 void TGo4AnalysisProxy::Update(TGo4Slot* slot, Bool_t strong)
00649 {
00650 if (strong)
00651 RefreshNamesList();
00652 }
00653
00654
00655 Bool_t TGo4AnalysisProxy::SubmitProxy(TGo4AnalysisObjectAccess* proxy)
00656 {
00657 if (proxy==0) return kFALSE;
00658
00659 fxSubmittedProxy.Add(proxy);
00660
00661 fNumberOfWaitingProxyes++;
00662
00663 proxy->SetSubmitTime();
00664
00665 if (proxy->ProxyKind()==cmdEnvelope) {
00666
00667
00668 TGo4RemoteCommand* com = new TGo4RemoteCommand("ANGetEnvelope");
00669 com->SetString(proxy->GetObjectName(),0);
00670 com->SetString(proxy->GetPathName(),1);
00671 fxDisplay->SubmitCommand(com);
00672 } else
00673 if (proxy->ProxyKind()==cmdStatus) {
00674
00675
00676
00677 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANObjectStatus");
00678 com->SetString(proxy->GetObjectName(),0);
00679 com->SetString(proxy->GetPathName(),1);
00680 TString rcvname = proxy->GetObjectName();
00681 rcvname.Append("_status");
00682 proxy->ChangeObjectName(rcvname.Data());
00683 fxDisplay->SubmitCommand(com);
00684 } else
00685 if (proxy->ProxyKind()==cmdEvStatus) {
00686
00687
00688
00689 Bool_t astree = strcmp(proxy->GetPathName(),"Tree")==0;
00690
00691 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANGetEvent");
00692 com->SetString(proxy->GetObjectName(),0);
00693 com->SetValue(kFALSE,0);
00694 com->SetValue(kFALSE,1);
00695 com->SetValue(astree,2);
00696 fxDisplay->SubmitCommand(com);
00697 }
00698
00699 return kTRUE;
00700 }
00701
00702 void TGo4AnalysisProxy::RequestObjectStatus(const char* fullname, TGo4Slot* tgtslot)
00703 {
00704 if ((fullname==0) || (tgtslot==0)) return;
00705
00706 TString objfolder, objname;
00707 TGo4Slot::ProduceFolderAndName(fullname, objfolder, objname);
00708
00709 TGo4AnalysisObjectAccess* proxy =
00710 new TGo4AnalysisObjectAccess(this, cmdStatus, objname, "", objfolder);
00711
00712 TString tgtname;
00713 tgtslot->ProduceFullName(tgtname);
00714 proxy->AssignObjectTo(tgtslot->GetOM(), tgtname.Data());
00715 }
00716
00717 void TGo4AnalysisProxy::RequestEventStatus(const char* evname, Bool_t astree, TGo4Slot* tgtslot)
00718 {
00719 if (evname==0) return;
00720
00721 TString folder, name;
00722 TGo4Slot::ProduceFolderAndName(evname, folder, name);
00723
00724 if (tgtslot==0) {
00725
00726
00727
00728
00729 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANGetEvent");
00730 com->SetString(name,0);
00731 com->SetValue(kFALSE,0);
00732 com->SetValue(kTRUE,1);
00733 com->SetValue(astree,2);
00734 fxDisplay->SubmitCommand(com);
00735 } else {
00736 if (astree) folder="Tree";
00737 else folder="Event";
00738 TGo4AnalysisObjectAccess* proxy =
00739 new TGo4AnalysisObjectAccess(this, cmdEvStatus, name, "", folder);
00740
00741 TString tgtname = tgtslot->GetFullName();
00742 proxy->AssignObjectTo(tgtslot->GetOM(), tgtname.Data());
00743 }
00744 }
00745
00746
00747 void TGo4AnalysisProxy::RemoteTreeDraw(const char* treename,
00748 const char* varexp,
00749 const char* cutcond,
00750 const char* hname)
00751 {
00752 TString tfoldername, tobjectname;
00753 TGo4Slot::ProduceFolderAndName(treename, tfoldername, tobjectname);
00754
00755 TString hfoldername, hobjectname;
00756 TGo4Slot::ProduceFolderAndName(hname, hfoldername, hobjectname);
00757
00758
00759 TGo4RemoteCommand* remcom= new TGo4RemoteCommand("ANAddTreeHis");
00760 remcom->SetString(hobjectname.Data(),0);
00761 remcom->SetString(tobjectname.Data(),1);
00762 remcom->SetString(varexp,2);
00763 remcom->SetString(cutcond,3);
00764 fxDisplay->SubmitCommand(remcom);
00765 }
00766
00767 void TGo4AnalysisProxy::RemotePrintEvent(const char* evname,
00768 Int_t evnumber,
00769 Int_t subid,
00770 Bool_t ishex,
00771 Bool_t islong)
00772 {
00773 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSetPrintEvent");
00774 com->SetString(evname,0);
00775 com->SetValue(evnumber, 0);
00776 com->SetValue(subid, 1);
00777 com->SetValue(islong, 2);
00778 com->SetValue(ishex, 3);
00779 com->SetValue(!ishex, 4);
00780 fxDisplay->SubmitCommand(com);
00781 }
00782
00783 Bool_t TGo4AnalysisProxy::UpdateAnalysisObject(const char* fullpath, TObject* obj)
00784 {
00785 if (obj==0) return kFALSE;
00786
00787 const char* objname = obj->GetName();
00788 if ((objname==0) || (*objname==0)) return kFALSE;
00789
00791 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSetObject");
00792 com->SetString(objname,0);
00793 com->SetAggregate(obj);
00794 fxDisplay->SubmitCommand(com);
00795
00796 return kTRUE;
00797 }
00798
00799 void TGo4AnalysisProxy::LoadConfigFile(const char* fname)
00800 {
00801 if((fname==0) || (strlen(fname)==0))
00802 fxDisplay->SubmitCommand("ANLoad");
00803 else {
00804
00805 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANLoad");
00806 com->SetString(fname,0);
00807 fxDisplay->SubmitCommand(com);
00808 }
00809 }
00810
00811 void TGo4AnalysisProxy::SaveConfigFile(const char* fname)
00812 {
00813 if((fname==0) || (strlen(fname)==0))
00814 fxDisplay->SubmitCommand("ANSave");
00815 else {
00816
00817 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSave");
00818 com->SetString(fname,0);
00819 fxDisplay->SubmitCommand(com);
00820 }
00821 }
00822
00823 void TGo4AnalysisProxy::WriteAutoSave(const char* fname,
00824 Int_t complevel,
00825 Bool_t overwrite)
00826 {
00827
00828
00829
00830
00831 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANAutosave");
00832 com->SetString(fname,0);
00833 com->SetValue(complevel,0);
00834 com->SetValue(overwrite,1);
00835 fxDisplay->SubmitCommand(com);
00836 }
00837
00838 void TGo4AnalysisProxy::StartAnalysis()
00839 {
00840 fxDisplay->SubmitCommand("THStart");
00841 fbAnalysisRunning = kTRUE;
00842 }
00843
00844 void TGo4AnalysisProxy::StopAnalysis()
00845 {
00846 fxDisplay->SubmitCommand("THStop");
00847 fbAnalysisRunning = kFALSE;
00848 }
00849
00850 void TGo4AnalysisProxy::ExecuteLine(const char* line)
00851 {
00852 TGo4ComExecLine *com = new TGo4ComExecLine();
00853 com->SetLine(line);
00854 fxDisplay->SubmitCommand(com);
00855 }
00856
00857 void TGo4AnalysisProxy::ClearAnalysisObject(const char* fullpath)
00858 {
00859 TString foldername, objectname;
00860 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
00861
00862 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANClearObject");
00863 com->SetString(objectname.Data(),0);
00864 fxDisplay->SubmitCommand(com);
00865 }
00866
00867 void TGo4AnalysisProxy::ChageObjectProtection(const char* fullpath, const char* flags)
00868 {
00869 TString foldername, objectname;
00870 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
00871
00872 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSetProtect");
00873 com->SetString(objectname.Data(),0);
00874 com->SetString(flags,2);
00875 fxDisplay->SubmitCommand(com);
00876 }
00877
00878 void TGo4AnalysisProxy::RemoveObjectFromAnalysis(const char* fullpath, TClass* cl)
00879 {
00880 TString foldername, objectname;
00881 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
00882 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANDelete");
00883 com->SetString(objectname.Data(),0);
00884 fxDisplay->SubmitCommand(com);
00885 }
00886
00887 void TGo4AnalysisProxy::RequestAnalysisSettings()
00888 {
00889
00890
00891 fxDisplay->SubmitCommand("ANGetStatus");
00892 }
00893
00894 void TGo4AnalysisProxy::SubmitAnalysisSettings()
00895 {
00896 TGo4AnalysisStatus* status = 0;
00897 if (SettingsSlot()!=0)
00898 status = dynamic_cast<TGo4AnalysisStatus*>(SettingsSlot()->GetAssignedObject());
00899 if (status!=0) {
00900 SetAnalysisSettingsReady(kFALSE);
00901
00902 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSetStatus");
00903 com->SetAggregate(status);
00904 fxDisplay->SubmitCommand(com);
00905 fxDisplay->SubmitCommand("ANInit");
00906 }
00907 }
00908
00909 void TGo4AnalysisProxy::PrintDynListEntry(const char* fullpath)
00910 {
00911 TString foldername, objectname;
00912 TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
00913 TGo4RemoteCommand* com= new TGo4RemoteCommand("ANPrdyn");
00914 com->SetString(objectname.Data(),0);
00915 fxDisplay->SubmitCommand(com);
00916 }
00917
00918 Int_t TGo4AnalysisProxy::ConnectorPort()
00919 {
00920 if (fxDisplay==0) return 0;
00921
00922 TGo4ServerTask* tsk = dynamic_cast<TGo4ServerTask*>
00923 (fxDisplay->GetTask());
00924 if (tsk==0) return 0;
00925
00926 return tsk->GetTaskManager()->GetNegotiationPort();
00927 }
00928
00929
00930 Bool_t TGo4AnalysisProxy::LaunchAsClient(TString& launchcmd,
00931 TString& killcmd,
00932 Bool_t usessh,
00933 Int_t konsole,
00934 const char* name,
00935 const char* remotehost,
00936 const char* remotedir,
00937 const char* remoteexe)
00938 {
00939 if (fxDisplay==0) return kFALSE;
00940
00941 TGo4ServerTask* tsk = dynamic_cast<TGo4ServerTask*>
00942 (fxDisplay->GetTask());
00943 if (tsk==0) return kFALSE;
00944
00945 Int_t guiport = tsk->GetTaskManager()->GetNegotiationPort();
00946
00947 if (!GetLaunchString(launchcmd, killcmd,
00948 kFALSE, usessh, konsole,
00949 name, remotehost, remotedir, remoteexe,
00950 guiport)) return kFALSE;
00951
00952 tsk->StartConnectorThread();
00953
00954 if ((konsole==2) || (konsole==3))
00955 gSystem->Exec(launchcmd.Data());
00956
00957 return kTRUE;
00958 }
00959
00960 Bool_t TGo4AnalysisProxy::LaunchAsServer(TString& launchcmd,
00961 TString& killcmd,
00962 Bool_t usessh,
00963 Int_t konsole,
00964 const char* name,
00965 const char* remotehost,
00966 const char* remotedir,
00967 const char* remoteexe)
00968 {
00969 if (!GetLaunchString(launchcmd, killcmd,
00970 kTRUE, usessh, konsole,
00971 name, remotehost, remotedir, remoteexe,
00972 0)) return kFALSE;
00973
00974 if ((konsole==2) || (konsole==3))
00975 gSystem->Exec(launchcmd.Data());
00976
00977 return kTRUE;
00978 }
00979
00980 Bool_t TGo4AnalysisProxy::GetLaunchString(TString& launchcmd,
00981 TString& killcmd,
00982 Bool_t server,
00983 Bool_t usessh,
00984 Int_t konsole,
00985 const char* name,
00986 const char* remotehost,
00987 const char* remotedir,
00988 const char* remoteexe,
00989 Int_t guiport)
00990 {
00991 const char* serverhost = gSystem->HostName();
00992 const char* sdisplay = gSystem->Getenv("DISPLAY");
00993 const char* go4sys = gSystem->Getenv("GO4SYS");
00994 const char* rootsys = gSystem->Getenv("ROOTSYS");
00995 const char* path = gSystem->Getenv("PATH");
00996 const char* ldpath = gSystem->Getenv("LD_LIBRARY_PATH");
00997
00998 if ((go4sys==0) || (strlen(go4sys)==0)) return kFALSE;
00999
01000 TString filename = go4sys;
01001 filename+="/";
01002 filename += TGo4ServerTask::Get_fgcLAUNCHPREFSFILE();
01003
01004 ifstream launchprefs(filename);
01005 if(!launchprefs) {
01006 TGo4Log::Debug("Master -- ERROR: Preferences file %s not existing, could not launch client ",
01007 filename.Data());
01008 return kFALSE;
01009 }
01010
01011 char formatstring[1000];
01012
01013 if ((konsole<1) || (konsole>3)) konsole = 1;
01014 Int_t num = konsole;
01015 if (server) num+=3;
01016
01017 for(int n=0;n<num;n++)
01018 launchprefs.getline(formatstring, 1000, '\n' );
01019
01020 const char* shcom = usessh ? "ssh -X " : "rsh -n";
01021 TString serverdisplay = "";
01022 if (!usessh) {
01023 serverdisplay = "-display ";
01024 serverdisplay += sdisplay;
01025 }
01026
01027 killcmd = "killall ";
01028 killcmd += remoteexe;
01029
01030 if((strcmp(remotehost, gSystem->HostName())!=0) && (strcmp(remotehost,"localhost")!=0)) {
01031 TString precmd = shcom;
01032 precmd += " ";
01033 precmd += remotehost;
01034 precmd += " ";
01035 killcmd.Prepend(precmd);
01036 }
01037
01038 launchcmd = "";
01039
01040
01041
01042
01043
01044 switch(konsole) {
01045 case 2: {
01046 launchcmd.Form(formatstring,
01047 shcom, remotehost, serverdisplay.Data(), name, remotehost, go4sys, go4sys, rootsys,
01048 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
01049 break;
01050 }
01051
01052 case 3: {
01053 launchcmd.Form(formatstring,
01054 shcom, remotehost, name, go4sys, go4sys, rootsys,
01055 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
01056 break;
01057 }
01058
01059 default: {
01060
01061 launchcmd.Form(formatstring,
01062 shcom, remotehost, go4sys, go4sys, rootsys,
01063 path, ldpath, remotedir, remoteexe, name, serverhost, guiport, remotehost);
01064 break;
01065 }
01066 }
01067
01068 return kTRUE;
01069 }
01070
01071 Bool_t TGo4AnalysisProxy::ConnectToServer(const char* remotehost,
01072 Int_t remoteport,
01073 Int_t ascontroller,
01074 const char* accesspass)
01075 {
01076
01077 TGo4ClientTask* client =
01078 dynamic_cast<TGo4ClientTask*> (fxDisplay->GetTask());
01079 if(client!=0) {
01080 Go4CommandMode_t mode = kGo4ComModeObserver;
01081 switch (ascontroller) {
01082 case 0: mode = kGo4ComModeObserver; break;
01083 case 1: mode = kGo4ComModeController; break;
01084 case 2: mode = kGo4ComModeAdministrator; break;
01085 }
01086 if (accesspass==0)
01087 switch (mode) {
01088 case kGo4ComModeObserver: accesspass = "go4view"; break;
01089 case kGo4ComModeController: accesspass = "go4ctrl"; break;
01090 case kGo4ComModeAdministrator: accesspass = "go4super"; break;
01091 default: accesspass = ""; break;
01092 }
01093
01094
01095
01096 client->ConnectServer(remotehost, remoteport, mode, accesspass);
01097 RefreshNamesList();
01098 }
01099
01100 return (client!=0);
01101 }
01102
01103 Bool_t TGo4AnalysisProxy::WaitForConnection(Int_t seconds)
01104 {
01105 Int_t period = seconds*1000;
01106 while (period>0) {
01107 if (IsConnected()) return kTRUE;
01108 gSystem->Sleep(100);
01109 gSystem->ProcessEvents();
01110 period-=100;
01111 }
01112 return IsConnected();
01113 }
01114
01115
01116 void TGo4AnalysisProxy::DisconnectAnalysis(Int_t waittime, Bool_t servershutdown)
01117 {
01118 if (fDisconectCounter>0) return;
01119
01120 if (fxDisplay!=0) {
01121 if (servershutdown)
01122 fxDisplay->SubmitCommand("SVQuit");
01123 else
01124 fxDisplay->SubmitCommand("MRQuit");
01125 }
01126
01127 fDisconectCounter = waittime*10;
01128
01129 fActualRole = -1;
01130
01131 CallSlotUpdate();
01132
01133 if (fxConnectionTimer==0)
01134 fxConnectionTimer = new TTimer(this, 10, kTRUE);
01135
01136 fxConnectionTimer->Start(100, kTRUE);
01137 }
01138
01139 Bool_t TGo4AnalysisProxy::IsConnected()
01140 {
01141 if (fxDisplay==0) return kFALSE;
01142
01143 if (!fxDisplay->IsConnected()) return kFALSE;
01144
01145 return !IsAnalysisServer() || (fActualRole>=0);
01146 }
01147
01148 void TGo4AnalysisProxy::DisplayDeleted(TGo4Display* displ)
01149 {
01150 if (fxDisplay==displ) fxDisplay=0;
01151 }
01152
01153 void TGo4AnalysisProxy::DisplayDisconnected(TGo4Display* displ)
01154 {
01155 if ((fxDisplay==displ) && (displ!=0))
01156 DisconnectAnalysis(5, false);
01157
01158 }
01159
01160
01161 void TGo4AnalysisProxy::CallSlotUpdate()
01162 {
01163
01164
01165 if (fxParentSlot!=0)
01166 fxParentSlot->ForwardEvent(fxParentSlot, TGo4Slot::evObjUpdated);
01167 }
01168
01169 Bool_t TGo4AnalysisProxy::HandleTimer(TTimer* timer)
01170 {
01171 if (timer==fxRefreshTimer) {
01172 RefreshNamesList();
01173 } else
01174
01175 if (timer==fxConnectionTimer) {
01176 if ((fxDisplay!=0) && (fDisconectCounter>0)) {
01177 fDisconectCounter--;
01178 fxConnectionTimer->Start(100, kTRUE);
01179 } else
01180 if (fxParentSlot!=0) {
01181
01182
01183 fxParentSlot->Delete();
01184
01185
01186 }
01187 else delete this;
01188 }
01189
01190 return kFALSE;
01191 }
01192
01193