GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ComSetObject.cxx
Go to the documentation of this file.
1 // $Id: TGo4ComSetObject.cxx 3048 2021-03-12 10:02:24Z 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 "TGo4ComSetObject.h"
15 
16 #include "TFolder.h"
17 #include "TH1.h"
18 
19 #include "TGo4Log.h"
20 #include "TGo4AnalysisClientImp.h"
21 #include "TGo4AnalysisImp.h"
22 #include "TGo4RemoteCommand.h"
24 #include "TGo4Parameter.h"
25 #include "TGo4ParameterStatus.h"
26 #include "TGo4Condition.h"
27 #include "TGo4DynamicEntry.h"
28 #include "TGo4TreeHistogramEntry.h"
29 #include "TGo4Picture.h"
30 
31 
33  TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object","mypara"),
34  fxObject(0),
35  fxClient(0),
36  fxAna(0),
37  fxResult(0)
38 {
39  SetReceiverName("AnalysisClient"); // this command needs client as receiver
40  // override default receiver
42 }
43 
44 
46  TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object",obname),
47  fxObject(0),
48  fxClient(0),
49  fxAna(0),
50  fxResult(0)
51 {
52  SetReceiverName("AnalysisClient"); // this command needs client as receiver
53  // override default receiver
55 }
56 
57 
59 {
60  //delete fxObject; // cleanup is done depending on ExeCom
61  delete fxResult; //
62 }
63 
65 {
66  if(remcom==0) return;
68  TObject* ob=remcom->GetAggregate(); // we take over ownership
69  if(ob && ob!=fxObject) {
70  delete fxObject;
71  fxObject = ob;
72  }
73 }
74 
76 {
77  fxClient = dynamic_cast<TGo4AnalysisClient*> (fxReceiverBase);
78  if (fxClient==0) {
79  GO4TRACE((11,"TGo4ComSetObject::ExeCom() - no receiver specified ERROR!",__LINE__, __FILE__));
80  TGo4Log::Debug(" !!! %s : NO RECEIVER ERROR!!!",GetName());
81  return 1;
82  }
83 
84  if(fxObject==0) {
85  fxClient->SendStatusMessage(3, kTRUE, TString::Format("SetObject - ERROR: no source object specified for %s", GetObjectName()));
86  return 0;
87  }
88 
89  SetObjectName(fxObject->GetName()); // override target name...
90  TGo4Log::Debug(" %s : Setting object %s ", GetName(), GetObjectName());
93  // evaluate object type here:
94  if(ExeSetParStatus(dynamic_cast<TGo4ParameterStatus*>(fxObject))==0)
95  ;
96  else if(ExeSetPar(dynamic_cast<TGo4Parameter*>(fxObject))==0)
97  ;
98  else if(ExeSetCon(dynamic_cast<TGo4Condition*>(fxObject))==0)
99  ;
100  else if(ExeSetDyn(dynamic_cast<TGo4DynamicEntry*>(fxObject))==0)
101  ;
102  else if(ExeSetHis(dynamic_cast<TH1*>(fxObject))==0)
103  ;
104  else if(ExeSetPic(dynamic_cast<TGo4Picture*>(fxObject))==0)
105  ;
106  else
108 
111  fxResult->SetNamesList(state); // note: nameslist is not owned by result object!
113  TFolder* top = fxAna->GetObjectFolder();
114  TString fullname = top->FindFullPathName(GetObjectName());
115  fullname.Remove(0, 6); // remove //Go4/ top folder name
116  fxResult->SetObjectFullName(fullname);
117  }
119  return -1;
120 }
121 
123 {
124  if (par==0) return -1;
125  TString buf;
127  buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
128  fxClient->SendStatusMessage(1, kTRUE, buf);
130  } else {
131  buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
132  fxClient->SendStatusMessage(3, kTRUE, buf);
134  }
135  fxResult->SetMessage(buf.Data());
136  delete fxObject;
137  fxObject = 0;
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  fxObject = 0;
157  return 0;
158 }
159 
161 {
162  if(conny==0) return -1;
163  TString buf;
164  if(fxAna->SetAnalysisCondition(GetObjectName(),conny, kFALSE)) {
165  buf = TString::Format("Condition %s was set to new values.", GetObjectName());
166  fxClient->SendStatusMessage(1, kTRUE, buf);
168  } else {
169  buf = TString::Format("SetCondition - ERROR: failed to set %s", GetObjectName());
170  fxClient->SendStatusMessage(3, kTRUE, buf);
172  }
173  fxResult->SetMessage(buf.Data());
174  delete fxObject;
175  fxObject = 0;
176  return 0;
177 }
178 
180 {
181  if(his==0) return -1;
182  TString buf;
183  if(fxAna->AddHistogram(his)) {
184  his->SetBit(TGo4Status::kGo4CanDelete); // dynamic objects may be deleted from gui
186  buf = TString::Format("Added new histogram %s to Go4 folders.", GetObjectName());
187  fxClient->SendStatusMessage(1, kFALSE, buf);
188  } else {
189  buf = TString::Format("ERROR on adding new histogram %s ", GetObjectName());
190  fxClient->SendStatusMessage(3, kFALSE, buf);
192  delete his;
193  }
194  fxResult->SetMessage(buf.Data());
195  return 0;
196 }
197 
199 {
200  if(dyn==0) return -1;
201  TString buf;
202  if(fxAna->AddDynamicEntry((TGo4DynamicEntry*)dyn->Clone())) {
203  TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (dyn);
204  if ((tentry!=0) && tentry->IsEnabledProcessing())
207  buf = TString::Format("Set new status for entry %s of dynamic list %s.", GetObjectName(), GetFolderName());
208  fxClient->SendStatusMessage(1, kTRUE, buf);
209  } else {
210  buf = TString::Format("Could not set status for entry %s of dynamic list %s !!!", GetObjectName(), GetFolderName());
212  fxClient->SendStatusMessage(2, kTRUE, buf);
213  }
214  fxResult->SetMessage(buf.Data());
215  delete fxObject;
216  fxObject = 0;
217  return 0;
218 }
219 
221 {
222  if(pic==0) return -1;
223  TString buf;
224  if(fxAna->SetPicture(GetObjectName(),pic)) {
226  buf = TString::Format("Picture %s was set to new values.", GetObjectName());
227  fxClient->SendStatusMessage(1, kFALSE, buf);
228  } else {
229  buf = TString::Format("SetPicture - ERROR: failed to set %s",GetObjectName());
230  fxClient->SendStatusMessage(3, kFALSE, buf);
232  }
233  fxResult->SetMessage(buf.Data());
234  delete fxObject;
235  fxObject = 0;
236  return 0;
237 }
238 
239 
240 Int_t TGo4ComSetObject::ExeSetObj(TObject* ob)
241 {
242  TString buf;
243  if(fxAna->AddObject(dynamic_cast<TNamed*>(ob))) {
245  buf = TString::Format("Added new object %s to Go4 folders.", GetObjectName());
246  fxClient->SendStatusMessage(1, kFALSE, buf);
247  } else {
249  buf = TString::Format("ERROR on adding new object %s ", GetObjectName());
250  fxClient->SendStatusMessage(3, kFALSE, buf);
251  delete ob;
252  }
253  fxResult->SetMessage(buf.Data());
254  return 0;
255 }
Int_t ExeSetPar(TGo4Parameter *par)
void SetReceiverName(const char *)
Definition: TGo4Command.cxx:93
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
TGo4CommandReceiver * fxReceiverBase
Definition: TGo4Command.h:116
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:104
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:125
Bool_t AddDynamicEntry(TGo4DynamicEntry *entry)
Int_t ExeSetObj(TObject *ob)
static TGo4Analysis * Instance()
TFolder * GetObjectFolder()
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284