GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4AnalysisProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4AnalysisProxy.cxx 3505 2022-01-21 17:41:20Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4AnalysisProxy.h"
15 
16 #include "TH1.h"
17 #include "TFolder.h"
18 #include "TTree.h"
19 #include "TTime.h"
20 #include "TSystem.h"
21 
22 #include "TGo4Log.h"
23 
24 #include "TGo4Slot.h"
25 #include "TGo4ObjectProxy.h"
26 
27 #include "TGo4RemoteCommand.h"
29 #include "TGo4ObjEnvelope.h"
30 #include "TGo4ComExecLine.h"
31 
32 #include "TGo4Display.h"
33 #include "TGo4TaskManager.h"
34 #include "TGo4TaskHandler.h"
35 #include "TGo4ClientTask.h"
36 #include "TGo4ServerTask.h"
37 #include "TGo4BufferQueue.h"
38 
39 #include "TGo4Parameter.h"
40 
41 #include "TGo4AnalysisStatus.h"
44 #include "TGo4TreeStructure.h"
45 #include "TGo4BranchStatus.h"
46 #include "TGo4ParameterStatus.h"
47 #include "TGo4MemberStatus.h"
48 
50 
51 
52 class TGo4AnalysisObjectAccess : public TObject, public TGo4Access {
53  public:
54 
56  Int_t proxykind,
57  const char* name,
58  const char* classname,
59  const char* fullpath) :
60  TObject(),
61  TGo4Access(),
62  fxAnalProxy(cont),
63  fProxyKind(proxykind),
64  fxObjName(name),
65  fxObjClassName(classname),
66  fxFullPath(fullpath),
67  fxReceiver(0),
69  fxSubmitTime()
70  {
71  }
72 
74 
75  virtual Bool_t IsRemote() const { return kTRUE; }
76  virtual Bool_t CanGetObject() const { return kFALSE; }
77  virtual const char* GetObjectName() const { return fxObjName.Data(); }
78  virtual const char* GetObjectClassName() const { return fxObjClassName.Data(); }
79 
80  const char* GetPathName() const { return fxFullPath.Data(); }
81 
82  virtual Int_t AssignObjectTo(TGo4ObjectManager* rcv, const char* path)
83  {
84  if ((rcv==0) || (fxAnalProxy==0)) return 0;
85  fxReceiver = rcv;
86  fxReceiverPath = path;
87  if (fxAnalProxy->SubmitProxy(this)) return 2;
88  return 0;
89  }
90 
91  Int_t ProxyKind() const { return fProxyKind; }
92 
93  void ChangeObjectName(const char* newname) { fxObjName = newname; }
94 
95  void SetSubmitTime() { fxSubmitTime = gSystem->Now(); }
96 
97  Bool_t CheckLifeTime(long int millisec)
98  {
99  long int res = gSystem->Now() - fxSubmitTime;
100  return (res<0) || (res > millisec);
101  }
102 
103  void ReceiveObject(TObject* obj, const char* objfolder, const char* objname, Bool_t owner)
104  {
106  TString path = fxReceiverPath;
107  if ((objfolder!=0) && (strlen(objfolder)!=0)) {
108  path += objfolder; path += "/";
109  }
110  if ((objname!=0) && (strlen(objname)!=0)) path += objname;
111  DoObjectAssignement(fxReceiver, path.Data(), obj, owner);
112 
113  } else {
114  DoObjectAssignement(fxReceiver, fxReceiverPath.Data(), obj, owner);
115  }
116  }
117 
118  void SetDefaultReceiver(TGo4ObjectManager* rcv, const char* path)
119  {
120  fxReceiver = rcv;
121  fxReceiverPath = path;
122  }
123 
124  protected:
126  Int_t fProxyKind;
127  TString fxObjName;
128  TString fxObjClassName;
129  TString fxFullPath;
131  TString fxReceiverPath;
132  TTime fxSubmitTime;
133 };
134 
135 
136 // ****************************************************************
137 
139  public:
141  TGo4LevelIter(),
142  fIter(0),
143  fCurrent(0),
144  fIsTree(kFALSE)
145  {
146  }
147 
148  TGo4AnalysisLevelIter(TFolder* folder, Bool_t istree = kFALSE) :
149  TGo4LevelIter(),
150  fIter(0),
151  fCurrent(0),
152  fIsTree(istree)
153  {
154  fIter = folder->GetListOfFolders()->MakeIterator();
155  }
156 
158  {
159  delete fIter;
160  }
161 
162  virtual Bool_t next()
163  {
164  fCurrent = fIter->Next();
165  return (fCurrent!=0);
166  }
167 
168  virtual Bool_t isfolder()
169  {
170  return ((dynamic_cast<TFolder*>(fCurrent)!=0) ||
171  (dynamic_cast<TGo4TreeStructure*>(fCurrent)!=0));
172  }
173 
174  virtual Int_t getflag(const char* flagname)
175  {
176  if (strcmp(flagname,"IsRemote")==0) return 1;
177  if (strcmp(flagname,"IsDeleteProtect")==0) {
178  TGo4ObjectStatus* sts = dynamic_cast<TGo4ObjectStatus*> (fCurrent);
179  if (sts!=0)
180  return sts->IsDeleteProtect() ? 1 : 0;
181  }
182  if (strcmp(flagname,"IsResetProtect")==0) {
183  TGo4ObjectStatus* sts = dynamic_cast<TGo4ObjectStatus*> (fCurrent);
184  if (sts!=0)
185  return sts->IsResetProtect() ? 1 : 0;
186  }
187 
188  return -1;
189  }
190 
191  virtual Bool_t isremote()
192  {
193  return kTRUE;
194  }
195 
197  {
198  TGo4TreeStructure* tr = dynamic_cast<TGo4TreeStructure*>(fCurrent);
199  if (tr!=0) return new TGo4AnalysisLevelIter(tr->GetNamesFolder(), kTRUE);
200  return new TGo4AnalysisLevelIter((TFolder*)fCurrent, fIsTree);
201  }
202 
203  virtual const char* name()
204  {
205  return fCurrent->GetName();
206  }
207 
208  virtual const char* info()
209  {
210  return fCurrent->GetTitle();
211  }
212 
213  virtual Int_t sizeinfo()
214  {
215  TGo4ObjectStatus* status = dynamic_cast <TGo4ObjectStatus*> (fCurrent);
216  return (status==0) ? 0 : status->GetObjectSize();
217  }
218 
219  virtual Int_t GetKind()
220  {
221  Int_t kind = TGo4Access::kndNone;
222  if (fIsTree)
223  if (isfolder()) kind = TGo4Access::kndTreeBranch;
224  else kind = TGo4Access::kndTreeLeaf;
225  else
226  if (isfolder())
227  kind = TGo4Access::kndFolder;
228  else {
229  kind = TGo4Access::kndObject;
230  if ((fCurrent!=0) && fCurrent->InheritsFrom(TGo4ParameterStatus::Class()))
232  else
233  if ((fCurrent!=0) && fCurrent->InheritsFrom(TGo4MemberStatus::Class()))
235  }
236 
237  return kind;
238  }
239 
240  virtual const char* GetClassName()
241  {
242  return EntryClassName(fCurrent);
243  }
244 
245  static const char* EntryClassName(TObject* entry)
246  {
247  if (entry==0) return 0;
248 
249  if (entry->InheritsFrom(TGo4TreeStructure::Class()))
250  return TTree::Class()->GetName();
251 
252  if(entry->InheritsFrom(TGo4BranchStatus::Class())) {
253  TGo4BranchStatus* status = dynamic_cast <TGo4BranchStatus*> (entry);
254  if (status!=0) return status->GetObjectClass();
255  }
256 
257  if (entry->InheritsFrom(TGo4ParameterStatus::Class())) {
258  TGo4ParameterStatus* status = dynamic_cast<TGo4ParameterStatus*> (entry);
259  if (status!=0) return status->GetObjectClass();
260  }
261 
262  if(entry->InheritsFrom(TGo4AnalysisStatus::Class())) {
263  return TGo4AnalysisStatus::Class()->GetName();
264  }
265 
266  if(entry->InheritsFrom(TGo4ObjectStatus::Class())) {
267  TGo4ObjectStatus* status = dynamic_cast <TGo4ObjectStatus*> (entry);
268  if (status!=0) return status->GetObjectClass();
269  }
270 
271  return entry->ClassName();
272  }
273 
274  protected:
275  TIterator* fIter;
276  TObject* fCurrent;
277  Bool_t fIsTree;
278 };
279 
280 // **********************************************************************
281 
283  TGo4ServerProxy(),
284  fIsServer(isserver),
285  fAnalysisNames(0),
286  fxSubmittedProxy(),
287  fxDefaultProxy(0),
288  fbNamesListReceived(kFALSE),
289  fbAnalysisRunning(kFALSE),
290  fDisconectCounter(-111),
291  fxDisplay(0),
292  fActualRole(-1),
293  fxRefreshTimer(0),
294  fxConnectionTimer(0),
295  fNumberOfWaitingProxyes(0)
296 {
297  fxDisplay = new TGo4Display(!isserver);
298 
299  fxDisplay->SetAnalysis(this);
300 
302 }
303 
305 {
306 // Info("~TGo4AnalysisProxy","%x",this);
307 
308  if (fxRefreshTimer!=0) delete fxRefreshTimer;
309  if (fxConnectionTimer!=0) delete fxConnectionTimer;
310 
312  fxSubmittedProxy.Delete();
313 
314  delete fxDefaultProxy; fxDefaultProxy = 0;
315 
316  delete fAnalysisNames;
317 
318  if (fxDisplay!=0) {
319  // if no disconnect attempt was done, send at the end quit command
320  // never delete display directly
321  if (fDisconectCounter==-111)
322  fxDisplay->SubmitCommand("MRQuit");
323 
324  if (fxDisplay!=0) {
326  TGo4Log::Debug("TGo4Display instance is not deleted correctly when analysis proxy is destroyed");
327  }
328  }
329 }
330 
332 {
334 
335  TGo4Slot* subslot = new TGo4Slot(fxParentSlot, "Settings", "Analysis configuration");
336  subslot->SetProxy(new TGo4ObjectProxy());
337 
338  subslot = new TGo4Slot(fxParentSlot, "Ratemeter", "Analysis ratemeter");
339  subslot->SetProxy(new TGo4ObjectProxy());
340 
341  subslot = new TGo4Slot(fxParentSlot, "Loginfo", "Analysis logging message");
342  subslot->SetProxy(new TGo4ObjectProxy());
343 
344  subslot = new TGo4Slot(fxParentSlot, "UpdateObject", "Result of update object");
345  subslot->SetProxy(new TGo4ObjectProxy());
346 }
347 
349 {
350  return fxParentSlot==0 ? 0 : fxParentSlot->FindChild("UpdateObject");
351 }
352 
353 
355 {
356 // Info("Finalize","Parent %x %x", slot, fxParentSlot);
357 
358  slot->DeleteChilds();
359 
360  fxParentSlot = 0;
361 }
362 
364 {
365  return (fAnalysisNames!=0);
366 }
367 
369 {
370  if (fAnalysisNames==0) return 0;
371 
372  return new TGo4AnalysisLevelIter(fAnalysisNames->GetNamesFolder(), kFALSE);
373 }
374 
375 void TGo4AnalysisProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
376 {
377 }
378 
379 void TGo4AnalysisProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
380 {
381 }
382 
384 {
385  if (fxDisplay==0) return kGo4ComModeRefused;
386 
387  Int_t res = kGo4ComModeRefused;
388 
389  if (IsAnalysisServer()) {
390  if (fActualRole>=0)
391  res = fActualRole;
392  } else
393  if (fxDisplay->GetTask()!=0)
394  if (fxDisplay->GetTask()->GetTaskHandler()!=0)
395  res = fxDisplay->GetTask()->GetTaskHandler()->GetRole();
396  return res;
397 }
398 
400 {
401  return GetRole()==kGo4ComModeObserver;
402 }
403 
405 {
406  return GetRole()==kGo4ComModeController;
407 }
408 
410 {
412 }
413 
415 {
416  TGo4ServerProxy::GetContainedObjectInfo(); // evaluate roles
417  fInfoStr +="@";
419  if (IsConnected() && (fAnalysisNames!=0) && (strcmp(fAnalysisNames->GetName(),"Go4NamesList")!=0)) {
420  fInfoStr += " name:";
421  fInfoStr += fAnalysisNames->GetName();
422  }
423  return fInfoStr.Data();
424 }
425 
426 TGo4AnalysisObjectAccess* TGo4AnalysisProxy::FindSubmittedProxy(const char* pathname, const char* objname)
427 {
428  for(int n=0;n<=fxSubmittedProxy.GetLast();n++) {
430  if (proxy==0) continue;
431  if (strcmp(proxy->GetObjectName(), objname)!=0) continue;
432  if ((pathname!=0) && (strcmp(proxy->GetPathName(), pathname)!=0)) continue;
433  return proxy;
434  }
435  return 0;
436 }
437 
439 {
440  bool docompress = false;
441  if (proxytodelete!=0) {
442  fxSubmittedProxy.Remove(proxytodelete);
443  delete proxytodelete;
444  docompress = true;
446  }
447 
448  for(int n=0;n<=fxSubmittedProxy.GetLast();n++) {
450  if (proxy==0) continue;
451  if (proxy->CheckLifeTime(100000)) {
452  fxSubmittedProxy.Remove(proxy);
453  docompress = true;
454  delete proxy;
456  }
457  }
458 
459  if (docompress)
460  fxSubmittedProxy.Compress();
461 }
462 
464 {
465 // std::cout << "Receive status " << status->GetName() << " class: " << status->ClassName() << std::endl;
466 
467  if (dynamic_cast<TGo4AnalysisStatus*> (status)!=0) {
468  SetAnalysisReady(kTRUE);
469  if (SettingsSlot()!=0) {
470  SettingsSlot()->AssignObject(status, kTRUE);
471  status =0;
472  }
473  CallSlotUpdate();
474  }
475 
476  TGo4AnalysisClientStatus* analstatus = dynamic_cast<TGo4AnalysisClientStatus*> (status);
477  if (analstatus!=0) {
478  fbAnalysisRunning = analstatus->IsAnalysisRunning();
480  SetAnalysisSettingsReady(kTRUE); // JAM workaround for go4 server connection: a running analysis must have been configured
481 
482  if (RatemeterSlot()!=0) {
483  RatemeterSlot()->AssignObject(status, kTRUE);
484  status=0;
485  }
486  }
487 
488  TGo4AnalysisObjectResult* obres = dynamic_cast<TGo4AnalysisObjectResult*> (status);
489  if (obres!=0) {
490  // put treatment of result object here
491  // for the moment, we just check what we got:
492 // std::cout <<"GOT result object in status channel: "<<obres->GetName() << std::endl;
493 // obres->PrintStatus();
494  TGo4AnalysisObjectNames* objnames = obres->GetNamesList(kTRUE);
495  if (objnames!=0)
496  AssignNewNamesList(objnames);
497  if (UpdateObjectSlot()!=0) {
498  TString fullname = obres->GetObjectFullName();
499 
500  if (fxParentSlot!=0) {
501  fullname.Prepend("/");
502  fullname.Prepend(fxParentSlot->GetName());
503  }
504 
505  obres->SetObjectFullName(fullname.Data());
506 
507  UpdateObjectSlot()->AssignObject(obres, kTRUE);
508  status=0;
509  }
510  CallSlotUpdate();
511  }
512 
513 
514  if (status!=0) {
515  TString message = status->GetName();
516 
517 // std::cout << "Message = " << message << std::endl;
518 
519  if(message.Contains("event classes were initialized"))
521 
522  // for gui as client at analysis server
523  if (message.Contains("is logged in at") && IsAnalysisServer())
524  for(int j=0; j<4;++j)
525  if(message.Contains(TGo4Command::GetModeDescription((Go4CommandMode_t) j ))) {
526  fActualRole = j;
527  break;
528  }
529 
530  // this happens when analysis disconnects itself
531  if (message.Contains("is shutting down now!")) {
532  fActualRole = -1;
533  TGo4Task* task = fxDisplay==0 ? 0 : fxDisplay->GetTask();
534  TGo4BufferQueue* qu = task==0 ? 0 : task->GetCommandQueue();
535  if(qu!=0) qu->Clear();
536  }
537 
538 
539  if (LoginfoSlot()!=0) {
540  LoginfoSlot()->AssignObject(status, kTRUE);
541  status = 0;
542  }
543  }
544 
545  if (status!=0) delete status;
546 }
547 
549 {
550  // object should be cleaned at the end
551 
552  if (obj==0) return;
553 
554  TGo4ObjEnvelope* envelope = dynamic_cast<TGo4ObjEnvelope*> (obj);
555  if (envelope!=0) {
556  TGo4AnalysisObjectAccess* proxy = FindSubmittedProxy(envelope->GetObjFolder(), envelope->GetObjName());
557  if (proxy==0) proxy = fxDefaultProxy;
558 
559  if (proxy!=0) {
560  TObject* envelopeobj = envelope->TakeObject();
561  if ((envelopeobj!=0) && envelopeobj->InheritsFrom(TH1::Class()))
562  ((TH1*) envelopeobj)->SetDirectory(0);
563  proxy->ReceiveObject(envelopeobj, envelope->GetObjFolder(), envelope->GetObjName(), kTRUE);
564 
565 
566  if (proxy != fxDefaultProxy) DeleteSubmittedProxy(proxy);
567  }
568  delete envelope;
569  return;
570  }
571 
572  TGo4AnalysisObjectNames* objnames = dynamic_cast<TGo4AnalysisObjectNames*> (obj);
573  if (objnames!=0) {
574  AssignNewNamesList(objnames);
575  return;
576  }
577 
578  TGo4AnalysisObjectAccess* proxy = FindSubmittedProxy(0, obj->GetName());
579  if (proxy!=0) {
580  proxy->ReceiveObject(obj, 0, obj->GetName(), kTRUE);
581  DeleteSubmittedProxy(proxy);
582  return;
583  }
584 
585  delete obj;
586 }
587 
589 {
590  delete fAnalysisNames;
591  fAnalysisNames = objnames;
592  fbNamesListReceived = kTRUE;
593 
594  SetAnalysisReady(kTRUE);
595 
596  if (fxParentSlot!=0)
598 }
599 
601 {
602 // std::cout << " TGo4AnalysisProxy::RefreshNamesList() " << std::endl;
603  //fxDisplay->SubmitCommand(new TGo4ComGetNamesList());
604  fxDisplay->SubmitCommand("ANNames");
605  fbNamesListReceived = kFALSE;
606  return kTRUE;
607 }
608 
610 {
611  if (fxRefreshTimer==0) fxRefreshTimer = new TTimer(this, 10, kTRUE);
612 
613  fxRefreshTimer->Start(delay_sec*1000, kTRUE);
614 
615  return kTRUE;
616 }
617 
619 {
620  return fbNamesListReceived;
621 }
622 
624 {
625  if ((name==0) || (*name==0) || (fAnalysisNames==0)) return 0;
626 
627  TObject* entry = fAnalysisNames->GetNamesFolder()->FindObjectAny(name);
628 
629  const char* classname = TGo4AnalysisLevelIter::EntryClassName(entry);
630 
631  if (classname==0) return 0;
632 
633  TString objfolder, objname;
634  TGo4Slot::ProduceFolderAndName(name, objfolder, objname);
635 
636 // std::cout << "Make TGo4AnalysisObjectAccess name = " << objname
637 // << " class = " << classname << " folder = " << objfolder << std::endl;
638 
639  return new TGo4AnalysisObjectAccess(this, cmdEnvelope, objname.Data(), classname, objfolder.Data());
640 }
641 
642 void TGo4AnalysisProxy::Update(TGo4Slot* slot, Bool_t strong)
643 {
644  if (strong)
646 }
647 
648 
650 {
651  if (proxy==0) return kFALSE;
652 
653  fxSubmittedProxy.Add(proxy);
654 
656 
657  proxy->SetSubmitTime();
658 
659  if (proxy->ProxyKind()==cmdEnvelope) {
660  //TGo4ComGetEnvelope* com = new TGo4ComGetEnvelope(proxy->GetObjectName(), proxy->GetPathName());
661  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANGetEnvelope");
662 
663  com->SetString(proxy->GetObjectName(), 0);
664  com->SetString(proxy->GetPathName(), 1);
665  fxDisplay->SubmitCommand(com);
666  } else
667  if (proxy->ProxyKind()==cmdStatus) {
668 // TGo4ComGetObjectStatus *com = new TGo4ComGetObjectStatus(proxy->GetObjectName());
669 // com->SetFolderName(proxy->GetPathName());
670  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANObjectStatus");
671  com->SetString(proxy->GetObjectName(),0);
672  com->SetString(proxy->GetPathName(),1);
673  TString rcvname = proxy->GetObjectName();
674  rcvname.Append("_status");
675  proxy->ChangeObjectName(rcvname.Data());
676  fxDisplay->SubmitCommand(com);
677  } else
678  if (proxy->ProxyKind()==cmdEvStatus) {
679 // TGo4ComGetCurrentEvent *com = new TGo4ComGetCurrentEvent(proxy->GetObjectName());
680 // com->SetPrintoutOnly(kFALSE);
681 // com->SetOutputEvent(kFALSE);
682  Bool_t astree = strcmp(proxy->GetPathName(),"Tree")==0;
683 // com->SetTreeMode(astree);
684  TGo4RemoteCommand* com= new TGo4RemoteCommand("ANGetEvent");
685  com->SetString(proxy->GetObjectName(),0);
686  com->SetValue(kFALSE,0); // use output event
687  com->SetValue(kFALSE,1); // printout only
688  com->SetValue(astree,2); // treemode on or off
689  fxDisplay->SubmitCommand(com);
690  }
691 
692  return kTRUE;
693 }
694 
695 Bool_t TGo4AnalysisProxy::RequestObjectStatus(const char* fullname, TGo4Slot* tgtslot)
696 {
697  if ((fullname==0) || (tgtslot==0)) return kFALSE;
698 
699  TString objfolder, objname;
700  TGo4Slot::ProduceFolderAndName(fullname, objfolder, objname);
701 
702  TGo4AnalysisObjectAccess* access =
703  new TGo4AnalysisObjectAccess(this, cmdStatus, objname, "", objfolder);
704 
705  access->AssignObjectToSlot(tgtslot);
706 
707  return kTRUE;
708 }
709 
710 void TGo4AnalysisProxy::RequestEventStatus(const char* evname, Bool_t astree, TGo4Slot* tgtslot)
711 {
712  if (evname==0) return;
713 
714  TString folder, name;
715  TGo4Slot::ProduceFolderAndName(evname, folder, name);
716 
717  if (tgtslot==0) {
718 // TGo4ComGetCurrentEvent *com = new TGo4ComGetCurrentEvent(name);
719 // com->SetPrintoutOnly(kTRUE);
720 // com->SetOutputEvent(kFALSE);
721 // com->SetTreeMode(astree);
722  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANGetEvent");
723  com->SetString(name,0);
724  com->SetValue(kFALSE,0); // use output event
725  com->SetValue(kTRUE,1); // printout only
726  com->SetValue(astree,2); // treemode on or off
727  fxDisplay->SubmitCommand(com);
728  } else {
729  if (astree) folder = "Tree";
730  else folder = "Event";
731 
732  TGo4AnalysisObjectAccess* access =
733  new TGo4AnalysisObjectAccess(this, cmdEvStatus, name, "", folder);
734 
735  access->AssignObjectToSlot(tgtslot);
736  }
737 }
738 
739 
740 void TGo4AnalysisProxy::RemoteTreeDraw(const char* treename,
741  const char* varexp,
742  const char* cutcond,
743  const char* hname)
744 {
745  TString tfoldername, tobjectname;
746  TGo4Slot::ProduceFolderAndName(treename, tfoldername, tobjectname);
747 
748  TString hfoldername, hobjectname;
749  TGo4Slot::ProduceFolderAndName(hname, hfoldername, hobjectname);
750 
751  //fxDisplay->SubmitCommand(new TGo4ComAddTreeHistogram(hobjectname.Data(), tobjectname.Data(), varexp, cutcond));
752  TGo4RemoteCommand* remcom = new TGo4RemoteCommand("ANAddTreeHis");
753  remcom->SetString(hobjectname.Data(),0);
754  remcom->SetString(tobjectname.Data(),1);
755  remcom->SetString(varexp,2);
756  remcom->SetString(cutcond,3);
757  fxDisplay->SubmitCommand(remcom);
758 }
759 
760 void TGo4AnalysisProxy::RemotePrintEvent(const char* evname,
761  Int_t evnumber,
762  Int_t subid,
763  Bool_t ishex,
764  Bool_t islong)
765 {
766  TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSetPrintEvent");
767  com->SetString(evname,0);
768  com->SetValue(evnumber, 0);
769  com->SetValue(subid, 1);
770  com->SetValue(islong, 2);
771  com->SetValue(ishex, 3);
772  com->SetValue(!ishex, 4);
773  fxDisplay->SubmitCommand(com);
774 }
775 
776 Bool_t TGo4AnalysisProxy::UpdateAnalysisObject(const char* fullpath, TObject* obj)
777 {
778  if (obj==0) return kFALSE;
779 
780  const char* objname = obj->GetName();
781  if ((objname==0) || (*objname==0)) return kFALSE;
782 
784  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANSetObject");
785  com->SetString(objname,0); // object name
786  com->SetAggregate(obj); // parameter
787  fxDisplay->SubmitCommand(com);
788 
789  return kTRUE;
790 }
791 
792 void TGo4AnalysisProxy::LoadConfigFile(const char* fname)
793 {
794  if((fname==0) || (strlen(fname)==0)) {
795  fxDisplay->SubmitCommand("ANLoad");
796  } else {
797  //TGo4ComLoadAnalysisStatus *com = new TGo4ComLoadAnalysisStatus(fname);
798  TGo4RemoteCommand* com= new TGo4RemoteCommand("ANLoad");
799  com->SetString(fname,0); // name of status file
800  fxDisplay->SubmitCommand(com);
801  }
802 }
803 
804 void TGo4AnalysisProxy::SaveConfigFile(const char* fname)
805 {
806  if((fname==0) || (strlen(fname)==0)) {
807  fxDisplay->SubmitCommand("ANSave");
808  } else {
809  //TGo4ComSaveAnalysisStatus *com = new TGo4ComSaveAnalysisStatus(fname);
810  TGo4RemoteCommand* com= new TGo4RemoteCommand("ANSave");
811  com->SetString(fname,0); // name of status file
812  fxDisplay->SubmitCommand(com);
813  }
814 }
815 
816 void TGo4AnalysisProxy::WriteAutoSave(const char* fname,
817  Int_t complevel,
818  Bool_t overwrite)
819 {
820 // TGo4ComAutosave *com = new TGo4ComAutosave();
821 // com->SetAutoFileName(fname);
822 // com->SetAutoSaveCompression(complevel);
823 // com->SetAutoSaveOverwrite(overwrite);
824  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANAutosave");
825  com->SetString(fname,0); // name of asf file
826  com->SetValue(complevel,0); // file compression level
827  com->SetValue(overwrite,1); // overwrite on or off
828  fxDisplay->SubmitCommand(com);
829 }
830 
832 {
833  fxDisplay->SubmitCommand("THStart");
834  fbAnalysisRunning = kTRUE;
835 }
836 
838 {
839  fxDisplay->SubmitCommand("THStop");
840  fbAnalysisRunning = kFALSE;
841 }
842 
843 void TGo4AnalysisProxy::ExecuteLine(const char* line)
844 {
845  TGo4ComExecLine *com = new TGo4ComExecLine();
846  com->SetLine(line);
847  fxDisplay->SubmitCommand(com);
848 }
849 
851 {
852  ClearAnalysisObject("Histograms");
853  ClearAnalysisObject("Conditions");
854 }
855 
856 
857 void TGo4AnalysisProxy::ClearAnalysisObject(const char* fullpath)
858 {
859  TString foldername, objectname;
860  TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
861  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANClearObject");
862  com->SetString(objectname.Data(),0);
863  fxDisplay->SubmitCommand(com);
864 }
865 
866 void TGo4AnalysisProxy::ChageObjectProtection(const char* fullpath, const char* flags)
867 {
868  TString foldername, objectname;
869  TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
870  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANSetProtect");
871  com->SetString(objectname.Data(),0);
872  com->SetString(flags,2);
873  fxDisplay->SubmitCommand(com);
874 }
875 
877 {
878  TString foldername, objectname;
879  TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
880  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANDelete");
881  com->SetString(objectname.Data(),0);
882  fxDisplay->SubmitCommand(com);
883 }
884 
886 {
887  fxDisplay->SubmitCommand("ANGetStatus");
888 }
889 
891 {
892  TGo4AnalysisStatus* status = 0;
893  if (SettingsSlot()!=0)
894  status = dynamic_cast<TGo4AnalysisStatus*>(SettingsSlot()->GetAssignedObject());
895  if (status!=0) {
896  SetAnalysisSettingsReady(kFALSE);
897  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANSetStatus");
898  com->SetAggregate(status);
899  fxDisplay->SubmitCommand(com);
900  fxDisplay->SubmitCommand("ANInit");
901  }
902 }
903 
905 {
906  SetAnalysisSettingsReady(kFALSE);
907 
908  fxDisplay->SubmitCommand("ANClose");
909 }
910 
911 void TGo4AnalysisProxy::PrintDynListEntry(const char* fullpath)
912 {
913  TString foldername, objectname;
914  TGo4Slot::ProduceFolderAndName(fullpath, foldername, objectname);
915  TGo4RemoteCommand* com = new TGo4RemoteCommand("ANPrdyn");
916  com->SetString(objectname.Data(),0);
917  fxDisplay->SubmitCommand(com);
918 }
919 
921 {
922  if (fxDisplay==0) return 0;
923 
924  TGo4ServerTask* tsk = dynamic_cast<TGo4ServerTask*>
925  (fxDisplay->GetTask());
926  if (tsk==0) return 0;
927 
928  return tsk->GetTaskManager()->GetNegotiationPort();
929 }
930 
931 
932 Bool_t TGo4AnalysisProxy::LaunchAsClient(TString& launchcmd,
933  TString& killcmd,
934  Int_t usessh,
935  Int_t konsole,
936  const char* name,
937  const char* remotehost,
938  const char* remotedir,
939  const char* remoteexe,
940  Int_t exe_kind,
941  const char* exeargs)
942 {
943  if (fxDisplay==0) return kFALSE;
944 
945  TGo4ServerTask* tsk = dynamic_cast<TGo4ServerTask*> (fxDisplay->GetTask());
946  if (tsk==0) return kFALSE;
947 
948  Int_t guiport = tsk->GetTaskManager()->GetNegotiationPort();
949 
950  if (!GetLaunchString(launchcmd, killcmd,
951  0, usessh, konsole,
952  name, remotehost, remotedir, remoteexe,
953  guiport, exe_kind, exeargs)) return kFALSE;
954 
955  tsk->StartConnectorThread();
956 
957  if ((konsole==2) || (konsole==3))
958  gSystem->Exec(launchcmd.Data());
959 
960  fNodeName.Form("%s:%d",remotehost,guiport);
961  return kTRUE;
962 }
963 
964 Bool_t TGo4AnalysisProxy::LaunchAsServer(TString& launchcmd,
965  TString& killcmd,
966  Int_t usessh,
967  Int_t konsole,
968  const char* name,
969  const char* remotehost,
970  Int_t remoteport,
971  const char* remotedir,
972  const char* remoteexe,
973  Int_t exe_kind,
974  const char* exeargs)
975 {
976  if (!GetLaunchString(launchcmd, killcmd,
977  1, usessh, konsole,
978  name, remotehost, remotedir, remoteexe,
979  remoteport, exe_kind, exeargs)) return kFALSE;
980 
981  if ((konsole==2) || (konsole==3))
982  gSystem->Exec(launchcmd.Data());
983 
984  return kTRUE;
985 }
986 
987 Bool_t TGo4AnalysisProxy::ConnectToServer(const char* remotehost,
988  Int_t remoteport,
989  Int_t ascontroller,
990  const char* accesspass)
991 {
992 
993  TGo4ClientTask* client =
994  dynamic_cast<TGo4ClientTask*> (fxDisplay->GetTask());
995  if(client!=0) {
997  switch (ascontroller) {
998  case 0: mode = kGo4ComModeObserver; break;
999  case 1: mode = kGo4ComModeController; break;
1000  case 2: mode = kGo4ComModeAdministrator; break;
1001  }
1002  if (accesspass==0)
1003  switch (mode) {
1004  case kGo4ComModeObserver: accesspass = "go4view"; break;
1005  case kGo4ComModeController: accesspass = "go4ctrl"; break;
1006  case kGo4ComModeAdministrator: accesspass = "go4super"; break;
1007  case kGo4ComModeRefused:
1008  default: accesspass = ""; break;
1009  }
1010 
1011 // std::cout << "mode = " << mode << " pass = " << accesspass << std::endl;
1012 
1013  client->ConnectServer(remotehost, remoteport, mode, accesspass);
1014  fNodeName.Form("%s:%d",remotehost,remoteport);
1015  RefreshNamesList();
1016  }
1017 
1018  return (client!=0);
1019 }
1020 
1022 {
1023  Int_t period = seconds*1000;
1024  while (period>0) {
1025  if (IsConnected()) return kTRUE;
1026  gSystem->Sleep(100);
1027  gSystem->ProcessEvents();
1028  period-=100;
1029  }
1030  return IsConnected();
1031 }
1032 
1033 
1034 void TGo4AnalysisProxy::DisconnectAnalysis(Int_t waittime, Bool_t servershutdown)
1035 {
1036  if (fDisconectCounter>0) return;
1037 
1038  if (fxDisplay!=0) {
1039  if (servershutdown)
1040  fxDisplay->SubmitCommand("SVQuit");
1041  else
1042  fxDisplay->SubmitCommand("MRQuit");
1043  }
1044 
1045  fDisconectCounter = waittime*10;
1046 
1047  fActualRole = -1;
1048 
1049  CallSlotUpdate();
1050 
1051  if (fxConnectionTimer==0)
1052  fxConnectionTimer = new TTimer(this, 10, kTRUE);
1053 
1054  fxConnectionTimer->Start(100, kTRUE);
1055 }
1056 
1058 {
1059  if (fxDisplay==0) return kFALSE;
1060 
1061  if (!fxDisplay->IsConnected()) return kFALSE;
1062 
1063  return !IsAnalysisServer() || (fActualRole>=0);
1064 }
1065 
1067 {
1068  if (fxDisplay==displ) fxDisplay=0;
1069 }
1070 
1072 {
1073  if ((fxDisplay==displ) && (displ!=0))
1074  DisconnectAnalysis(5, false);
1075 // fxDisplay->SubmitCommand("MRQuit");
1076 }
1077 
1078 
1080 {
1081 // Info("CallSlotUpdate","ParentSlot = %x", fxParentSlot);
1082 
1083  if (fxParentSlot!=0)
1085 }
1086 
1087 Bool_t TGo4AnalysisProxy::HandleTimer(TTimer* timer)
1088 {
1089  if (timer == fxRefreshTimer) {
1090  RefreshNamesList();
1091  } else
1092  if (timer == fxConnectionTimer) {
1093  //std::cout << " TGo4AnalysisProxy::HandleTimer for connection timer" << std::endl;
1094  if (fxDisplay != 0) {
1095  // this is emergency handling only if display did not shutdown and deleted our proxy before.
1096  if (fDisconectCounter > 0) {
1098  fxConnectionTimer->Start(100, kTRUE);
1099  //std::cout<< " TGo4AnalysisProxy::HandleTimer has restarted connection timer, discon counter="<< fDisconectCounter << std::endl;
1100  } else {
1101  // this is an emergency disconnect! regularly, the TGo4Display will destroy us now
1102 
1103  std::cout<< " TGo4AnalysisProxy::HandleTimer still sees not that display is gone. Cleanup myself!"<< std::endl;
1104  fxConnectionTimer->TurnOff();
1105  fxConnectionTimer = 0; // avoid that timer is deleted in dtor, since this function runs within timer notify!
1106  if (fxParentSlot != 0) {
1107  // this will also delete Analysis proxy itself
1108  // practically the same as delete fxParentSlot;
1109  fxParentSlot->Delete();
1110  //fxParentSlot = 0;
1111  //fxParentSlot->GetOM()->DeleteObject(fxParentSlot);
1112  } else {
1113  delete this;
1114  }
1115  } // if(fDisconectCounter>0)
1116  } //if fxDisplay!=0
1117  }
1118  return kFALSE;
1119 }
1120 
1122 {
1123  if (rcv==0) {
1124  delete fxDefaultProxy; fxDefaultProxy = 0;
1125  } else {
1127  fxDefaultProxy->SetDefaultReceiver(rcv, path);
1128  }
1129 }
void SetLine(const char *name)
void DisplayDeleted(TGo4Display *displ)
virtual Bool_t RefreshNamesList()
virtual Int_t getflag(const char *flagname)
virtual Bool_t DelayedRefreshNamesList(Int_t delay_sec)
Bool_t IsDeleteProtect() const
TGo4AnalysisLevelIter(TFolder *folder, Bool_t istree=kFALSE)
virtual Bool_t HandleTimer(TTimer *timer)
TObject * TakeObject()
TGo4AnalysisProxy(Bool_t isserver=kFALSE)
const char * GetObjectFullName() const
void SetDefaultReceiver(TGo4ObjectManager *rcv, const char *path)
Bool_t IsConnected()
void SetProxy(TGo4Proxy *cont)
Definition: TGo4Slot.cxx:310
virtual Int_t Initialization()
Definition: TGo4Task.cxx:376
TGo4Slot * LoginfoSlot()
TGo4Slot * UpdateObjectSlot()
Go4CommandMode_t
Definition: TGo4Command.h:27
UInt_t GetNegotiationPort()
virtual void LoadConfigFile(const char *fname)
virtual const char * info()
virtual TGo4LevelIter * subiterator()
TGo4ObjectManager * fxReceiver
Bool_t LaunchAsClient(TString &launchcmd, TString &killcmd, Int_t shellkind, Int_t konsole, const char *name, const char *remotehost, const char *remotedir, const char *remoteexe, Int_t exe_kind=0, const char *exeargs=0)
void SetAggregate(TObject *ob)
void ReceiveStatus(TGo4Status *status)
virtual Bool_t IsRemote() const
void ChangeObjectName(const char *newname)
virtual void RemoteTreeDraw(const char *treename, const char *varexp, const char *cutcond, const char *hname)
void DoObjectAssignement(TGo4ObjectManager *rcv, const char *path, TObject *obj, Bool_t owner)
Definition: TGo4Proxy.cxx:63
virtual void ClearAllAnalysisObjects()
virtual void ClearAnalysisObject(const char *fullpath)
virtual TGo4TaskHandler * GetTaskHandler()
Definition: TGo4Task.h:99
Bool_t SubmitProxy(TGo4AnalysisObjectAccess *proxy)
virtual void RequestEventStatus(const char *evname, Bool_t astree, TGo4Slot *tgtslot)
void DeleteChilds(const char *startedwith=0)
Definition: TGo4Slot.cxx:218
virtual TGo4BufferQueue * GetCommandQueue(const char *task=0)
Definition: TGo4Task.h:101
TFolder * GetNamesFolder(Bool_t chown=kFALSE)
virtual Bool_t IsViewer()
virtual Bool_t IsAdministrator()
void AssignNewNamesList(TGo4AnalysisObjectNames *objnames)
virtual Bool_t IsController()
virtual Bool_t HasSublevels() const
void ReceiveObject(TObject *obj, const char *objfolder, const char *objname, Bool_t owner)
TGo4AnalysisObjectNames * fAnalysisNames
virtual Bool_t IsAnalysisServer() const
Bool_t IsResetProtect() const
virtual void Clear(Option_t *opt="")
virtual void Update(TGo4Slot *slot, Bool_t strong)
virtual void RemotePrintEvent(const char *evname, Int_t evnumber, Int_t subid, Bool_t ishex, Bool_t islong)
virtual const char * name()
Bool_t ConnectToServer(const char *remotehost, Int_t remoteport, Int_t ascontroller, const char *accesspass)
virtual void Initialize(TGo4Slot *slot)
TGo4Slot * RatemeterSlot()
TObject * GetAssignedObject()
Definition: TGo4Slot.cxx:370
void SetDefaultReceiver(TGo4ObjectManager *rcv, const char *path)
virtual void RequestAnalysisSettings()
void SetAnalysisReady(Bool_t on=kTRUE)
virtual void WriteAutoSave(const char *fname, Int_t complevel, Bool_t overwrite)
void SetAnalysis(TGo4AnalysisProxy *an)
Definition: TGo4Display.h:33
virtual Bool_t IsConnected()
TGo4Slot * FindChild(const char *name)
Definition: TGo4Slot.cxx:259
virtual const char * GetContainedObjectInfo()
virtual void Finalize(TGo4Slot *slot)
TGo4Slot * SettingsSlot()
void ReceiveObject(TNamed *obj)
void SetAnalysisSettingsReady(Bool_t on=kTRUE)
TGo4Task * GetTask()
Definition: TGo4TaskOwner.h:41
TGo4AnalysisObjectNames * GetNamesList(Bool_t chown=kTRUE)
virtual Bool_t NamesListReceived()
TGo4Slot * fxParentSlot
virtual Bool_t CanGetObject() const
void DisplayDisconnected(TGo4Display *displ)
virtual void RemoveObjectFromAnalysis(const char *fullpath)
virtual const char * GetObjectClassName() const
virtual void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
virtual const char * GetObjectName() const
static const char * EntryClassName(TObject *entry)
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)
TFolder * GetNamesFolder(Bool_t chown=kFALSE)
TGo4AnalysisObjectAccess * fxDefaultProxy
virtual TGo4LevelIter * MakeIter()
TGo4AnalysisProxy * fxAnalProxy
void SetObjectFullName(const char *nam)
TGo4AnalysisObjectAccess * FindSubmittedProxy(const char *pathname, const char *objname)
Bool_t ConnectServer(const char *node, UInt_t negport, Go4CommandMode_t role=kGo4ComModeRefused, const char *passwd=0)
virtual const char * GetClassName()
virtual const char * GetContainedObjectInfo()
const char * GetObjectClass() const
virtual void SaveConfigFile(const char *fname)
const char * GetObjFolder() const
virtual void StartAnalysis()
static void ProduceFolderAndName(const char *fullname, TString &foldername, TString &objectname)
Definition: TGo4Slot.cxx:664
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=0)
Definition: TGo4Slot.cxx:581
virtual Int_t AssignObjectTo(TGo4ObjectManager *rcv, const char *path)
virtual void CloseAnalysisSettings()
virtual Bool_t RequestObjectStatus(const char *objectname, TGo4Slot *tgtslot)
Int_t AssignObjectToSlot(TGo4Slot *slot)
Definition: TGo4Proxy.cxx:54
TString fNodeName
0 - not launched, 1 - external shell, 2 - in qt shell
void SetValue(Int_t num, Int_t i)
virtual void Delete(Option_t *opt="")
Definition: TGo4Slot.cxx:187
void SetString(const char *txt, Int_t i)
Go4CommandMode_t GetRole()
virtual void Initialize(TGo4Slot *slot)
TGo4AnalysisObjectAccess(TGo4AnalysisProxy *cont, Int_t proxykind, const char *name, const char *classname, const char *fullpath)
Bool_t AssignObject(TObject *obj, Bool_t owner)
Definition: TGo4Slot.cxx:358
const char * GetObjName() const
const char * GetPathName() const
virtual Bool_t UpdateAnalysisObject(const char *objectname, TObject *obj)
virtual const char * GetServerName() const
TObjArray fxSubmittedProxy
virtual void ChageObjectProtection(const char *fullpath, const char *flags)
virtual void ExecuteLine(const char *line)
Bool_t CheckLifeTime(long int millisec)
virtual TGo4Access * ProvideAccess(const char *name)
Int_t GetObjectSize() const
static const char * GetModeDescription(Go4CommandMode_t mode)
virtual void SubmitAnalysisSettings()
Bool_t WaitForConnection(Int_t seconds)
virtual void PrintDynListEntry(const char *fullpath)
TGo4Display * fxDisplay
TGo4TaskManager * GetTaskManager()
virtual void ReadData(TGo4Slot *slot, TDirectory *dir)
void DeleteSubmittedProxy(TGo4AnalysisObjectAccess *proxy)
Bool_t SubmitCommand(const char *name)
Definition: TGo4Master.cxx:60
virtual void DisconnectAnalysis(Int_t waittime=30, Bool_t servershutdown=kFALSE)
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284
virtual void StopAnalysis()
virtual Bool_t StartConnectorThread()
static Bool_t LaunchAsServer(TString &launchcmd, TString &killcmd, Int_t shellkind, Int_t konsole, const char *name, const char *remotehost, Int_t remoteport, const char *remotedir, const char *remoteexe, Int_t exe_kind=0, const char *exeargs=0)