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