GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ComSetObject.cxx
Go to the documentation of this file.
1 // $Id: TGo4ComSetObject.cxx 1001 2013-07-25 15:10:31Z 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 "TGo4ComSetObject.h"
15 
16 #include "TFolder.h"
17 #include "TH1.h"
18 
19 #include "TGo4Log.h"
20 #include "TGo4AnalysisClientImp.h"
21 #include "TGo4AnalysisImp.h"
23 #include "TGo4RemoteCommand.h"
25 #include "TGo4Parameter.h"
26 #include "TGo4ParameterStatus.h"
27 #include "TGo4Condition.h"
28 #include "TGo4DynamicEntry.h"
29 #include "TGo4TreeHistogramEntry.h"
30 #include "TGo4Picture.h"
31 
32 
34  TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object","mypara"),
35  fxObject(0),
36  fxClient(0),
37  fxAna(0),
38  fxResult(0)
39  {
40  SetReceiverName("AnalysisClient"); // this command needs client as receiver
41  // override default receiver
43 }
44 
45 
47  TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object",obname),
48  fxObject(0),
49  fxClient(0),
50  fxAna(0),
51  fxResult(0)
52 {
53  SetReceiverName("AnalysisClient"); // this command needs client as receiver
54  // override default receiver
56 }
57 
58 
60 {
61  //delete fxObject; // cleanup is done depending on ExeCom
62  delete fxResult; //
63 }
64 
66 {
67  if(remcom==0) return;
69  TObject* ob=remcom->GetAggregate(); // we take over ownership
70  if(ob && ob!=fxObject) {
71  delete fxObject;
72  fxObject=ob;
73  }
74 }
75 
77 {
78  fxClient = dynamic_cast<TGo4AnalysisClient*> (fxReceiverBase);
79  if (fxClient==0) {
80  GO4TRACE((11,"TGo4ComSetObject::ExeCom() - no receiver specified ERROR!",__LINE__, __FILE__));
81  TGo4Log::Debug(" !!! %s : NO RECEIVER ERROR!!!",GetName());
82  return 1;
83  }
84 
85  if(fxObject==0) {
86  fxClient->SendStatusMessage(3, kTRUE, TString::Format("SetObject - ERROR: no source object specified for %s", GetObjectName()));
87  return 0;
88  }
89 
90  SetObjectName(fxObject->GetName()); // override target name...
91  TGo4Log::Debug(" %s : Setting object %s ", GetName(), GetObjectName());
94  // evaluate object type here:
95  if(ExeSetParStatus(dynamic_cast<TGo4ParameterStatus*>(fxObject))==0)
96  ;
97  else if(ExeSetPar(dynamic_cast<TGo4Parameter*>(fxObject))==0)
98  ;
99  else if(ExeSetCon(dynamic_cast<TGo4Condition*>(fxObject))==0)
100  ;
101  else if(ExeSetDyn(dynamic_cast<TGo4DynamicEntry*>(fxObject))==0)
102  ;
103  else if(ExeSetHis(dynamic_cast<TH1*>(fxObject))==0)
104  ;
105  else if(ExeSetPic(dynamic_cast<TGo4Picture*>(fxObject))==0)
106  ;
107  else
109 
112  fxResult->SetNamesList(state); // note: nameslist is not owned by result object!
114  TFolder* top = fxAna->GetObjectFolder();
115  TString fullname = top->FindFullPathName(GetObjectName());
116  fullname.Remove(0, 6); // remove //Go4/ top folder name
117  fxResult->SetObjectFullName(fullname);
118  }
120  return -1;
121 }
122 
124 {
125  if (par==0) return -1;
126  TString buf;
128  buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
129  fxClient->SendStatusMessage(1, kTRUE, buf);
131  } else {
132  buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
133  fxClient->SendStatusMessage(3, kTRUE, buf);
135  }
136  fxResult->SetMessage(buf.Data());
137  delete fxObject;
138  return 0;
139 }
140 
142 {
143  if(par==0) return -1;
144  TString buf;
145  if(fxAna->SetParameter(GetObjectName(),par)) {
146  buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
147  fxClient->SendStatusMessage(1, kTRUE, buf);
149  } else {
150  buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
151  fxClient->SendStatusMessage(3, kTRUE, buf);
153  }
154  fxResult->SetMessage(buf.Data());
155  delete fxObject;
156  return 0;
157 }
158 
160 {
161  if(conny==0) return -1;
162  TString buf;
163  if(fxAna->SetAnalysisCondition(GetObjectName(),conny, kFALSE)) {
164  buf = TString::Format("Condition %s was set to new values.", GetObjectName());
165  fxClient->SendStatusMessage(1, kTRUE, buf);
167  } else {
168  buf = TString::Format("SetCondition - ERROR: failed to set %s", GetObjectName());
169  fxClient->SendStatusMessage(3, kTRUE, buf);
171  }
172  fxResult->SetMessage(buf.Data());
173  delete fxObject;
174  return 0;
175 }
176 
178 {
179  if(his==0) return -1;
180  TString buf;
181  if(fxAna->AddHistogram(his)) {
182  his->SetBit(TGo4Status::kGo4CanDelete); // dynamic objects may be deleted from gui
184  buf = TString::Format("Added new histogram %s to Go4 folders.", GetObjectName());
185  fxClient->SendStatusMessage(1, kFALSE, buf);
186  } else {
187  buf = TString::Format("ERROR on adding new histogram %s ", GetObjectName());
188  fxClient->SendStatusMessage(3, kFALSE, buf);
190  delete his;
191  }
192  fxResult->SetMessage(buf.Data());
193  return 0;
194 }
195 
197 {
198  if(dyn==0) return -1;
199  TString buf;
200  if(fxAna->AddDynamicEntry((TGo4DynamicEntry*)dyn->Clone())) {
201  TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (dyn);
202  if ((tentry!=0) && tentry->IsEnabledProcessing())
205  buf = TString::Format("Set new status for entry %s of dynamic list %s.", GetObjectName(), GetFolderName());
206  fxClient->SendStatusMessage(1, kTRUE, buf);
207  } else {
208  buf = TString::Format("Could not set status for entry %s of dynamic list %s !!!", GetObjectName(), GetFolderName());
210  fxClient->SendStatusMessage(2, kTRUE, buf);
211  }
212  fxResult->SetMessage(buf.Data());
213  delete fxObject;
214  return 0;
215 }
216 
218 {
219  if(pic==0) return -1;
220  TString buf;
221  if(fxAna->SetPicture(GetObjectName(),pic)) {
223  buf = TString::Format("Picture %s was set to new values.", GetObjectName());
224  fxClient->SendStatusMessage(1, kFALSE, buf);
225  } else {
226  buf = TString::Format("SetPicture - ERROR: failed to set %s",GetObjectName());
227  fxClient->SendStatusMessage(3, kFALSE, buf);
229  }
230  fxResult->SetMessage(buf.Data());
231  delete fxObject;
232  return 0;
233 }
234 
235 
236 Int_t TGo4ComSetObject::ExeSetObj(TObject* ob)
237 {
238  TString buf;
239  if(fxAna->AddObject(dynamic_cast<TNamed*>(ob))) {
241  buf = TString::Format("Added new object %s to Go4 folders.", GetObjectName());
242  fxClient->SendStatusMessage(1, kFALSE, buf);
243  } else {
245  buf = TString::Format("ERROR on adding new object %s ", GetObjectName());
246  fxClient->SendStatusMessage(3, kFALSE, buf);
247  delete ob;
248  }
249  fxResult->SetMessage(buf.Data());
250  return 0;
251 }
Int_t ExeSetPar(TGo4Parameter *par)
void SetReceiverName(const char *)
Definition: TGo4Command.cxx:92
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
TGo4CommandReceiver * fxReceiverBase
Definition: TGo4Command.h:117
Bool_t SetParameter(const char *name, TGo4Parameter *par)
Int_t ExeSetHis(TH1 *his)
Int_t ExeSetParStatus(TGo4ParameterStatus *par)
TObject * GetAggregate(Bool_t chown=kTRUE)
void SetMessage(const char *nam)
Int_t ExeSetDyn(TGo4DynamicEntry *dyn)
virtual void Set(TGo4RemoteCommand *remcon)
Bool_t SetParameterStatus(const char *name, TGo4ParameterStatus *par)
void SetDynListInterval(Int_t val)
TGo4Analysis * fxAna
Bool_t AddHistogram(TH1 *his, const char *subfolder=0, Bool_t replace=kTRUE)
Bool_t SetAnalysisCondition(const char *name, TGo4Condition *con, Bool_t counter=kTRUE)
Go4ResultAction_t Action() const
virtual void Set(TGo4RemoteCommand *remcon)
const char * GetObjectName() const
TGo4AnalysisClient * fxClient
void SetNamesList(TGo4AnalysisObjectNames *n)
Bool_t AddObject(TNamed *anything, const char *subfolder=0, Bool_t replace=kTRUE)
TGo4AnalysisObjectResult * fxResult
virtual ~TGo4ComSetObject()
void SetObjectName(const char *name)
Bool_t IsEnabledProcessing() const
const char * GetFolderName() const
void SetProtection(Go4CommandMode_t m)
Definition: TGo4Command.h:105
void SetObjectFullName(const char *nam)
void SetAction(Go4ResultAction_t com)
Int_t ExeSetPic(TGo4Picture *pic)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
Bool_t SetPicture(const char *name, TGo4Picture *pic)
TGo4AnalysisObjectNames * GetNamesList() const
Int_t ExeSetCon(TGo4Condition *con)
void SendStatus(TGo4Status *stat, const char *receiver=0)
Definition: TGo4Slave.cxx:126
Bool_t AddDynamicEntry(TGo4DynamicEntry *entry)
Int_t ExeSetObj(TObject *ob)
static TGo4Analysis * Instance()
TFolder * GetObjectFolder()
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:270