GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4ComSetObject.cxx
Go to the documentation of this file.
1 // $Id$
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 {
35  SetReceiverName("AnalysisClient"); // this command needs client as receiver
36  // override default receiver
38 }
39 
40 
42  TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object",obname)
43 {
44  SetReceiverName("AnalysisClient"); // this command needs client as receiver
45  // override default receiver
47 }
48 
49 
51 {
52  //delete fxObject; // cleanup is done depending on ExeCom
53  delete fxResult; //
54 }
55 
57 {
58  if(!remcom) return;
60  TObject *ob = remcom->GetAggregate(); // we take over ownership
61  if(ob && ob!=fxObject) {
62  delete fxObject;
63  fxObject = ob;
64  }
65 }
66 
68 {
69  fxClient = dynamic_cast<TGo4AnalysisClient*> (fxReceiverBase);
70  if (!fxClient) {
71  GO4TRACE((11,"TGo4ComSetObject::ExeCom() - no receiver specified ERROR!",__LINE__, __FILE__));
72  TGo4Log::Debug(" !!! %s : NO RECEIVER ERROR!!!",GetName());
73  return 1;
74  }
75 
76  if(!fxObject) {
77  fxClient->SendStatusMessage(3, kTRUE, TString::Format("SetObject - ERROR: no source object specified for %s", GetObjectName()));
78  return 0;
79  }
80 
81  SetObjectName(fxObject->GetName()); // override target name...
82  TGo4Log::Debug(" %s : Setting object %s ", GetName(), GetObjectName());
85  // evaluate object type here:
86  if(ExeSetParStatus(dynamic_cast<TGo4ParameterStatus *>(fxObject)) == 0) {
87  ;
88  } else if(ExeSetPar(dynamic_cast<TGo4Parameter *>(fxObject)) == 0) {
89  ;
90  } else if(ExeSetCon(dynamic_cast<TGo4Condition *>(fxObject)) == 0) {
91  ;
92  } else if(ExeSetDyn(dynamic_cast<TGo4DynamicEntry *>(fxObject)) == 0) {
93  ;
94  } else if(ExeSetHis(dynamic_cast<TH1 *>(fxObject)) == 0) {
95  ;
96  } else if(ExeSetPic(dynamic_cast<TGo4Picture *>(fxObject)) == 0) {
97  ;
98  } else {
100  }
101 
104  fxResult->SetNamesList(state); // note: nameslist is not owned by result object!
105  if(fxResult->Action() != kGo4ActionError) {
106  TFolder *top = fxAna->GetObjectFolder();
107  TString fullname = top->FindFullPathName(GetObjectName());
108  fullname.Remove(0, 6); // remove //Go4/ top folder name
109  fxResult->SetObjectFullName(fullname);
110  }
112  return -1;
113 }
114 
116 {
117  if (!par) return -1;
118  TString buf;
120  buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
121  fxClient->SendStatusMessage(1, kTRUE, buf);
123  } else {
124  buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
125  fxClient->SendStatusMessage(3, kTRUE, buf);
127  }
128  fxResult->SetMessage(buf.Data());
129  delete fxObject;
130  fxObject = nullptr;
131  return 0;
132 }
133 
135 {
136  if(!par) return -1;
137  TString buf;
138  if(fxAna->SetParameter(GetObjectName(),par)) {
139  buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
140  fxClient->SendStatusMessage(1, kTRUE, buf);
142  } else {
143  buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
144  fxClient->SendStatusMessage(3, kTRUE, buf);
146  }
147  fxResult->SetMessage(buf.Data());
148  delete fxObject;
149  fxObject = nullptr;
150  return 0;
151 }
152 
154 {
155  if(!conny) return -1;
156  TString buf;
157  if(fxAna->SetAnalysisCondition(GetObjectName(),conny, kFALSE)) {
158  buf = TString::Format("Condition %s was set to new values.", GetObjectName());
159  fxClient->SendStatusMessage(1, kTRUE, buf);
161  } else {
162  buf = TString::Format("SetCondition - ERROR: failed to set %s", GetObjectName());
163  fxClient->SendStatusMessage(3, kTRUE, buf);
165  }
166  fxResult->SetMessage(buf.Data());
167  delete fxObject;
168  fxObject = nullptr;
169  return 0;
170 }
171 
173 {
174  if(!his) return -1;
175  TString buf;
176  if(fxAna->AddHistogram(his)) {
177  his->SetBit(TGo4Status::kGo4CanDelete); // dynamic objects may be deleted from gui
179  buf = TString::Format("Added new histogram %s to Go4 folders.", GetObjectName());
180  fxClient->SendStatusMessage(1, kFALSE, buf);
181  } else {
182  buf = TString::Format("ERROR on adding new histogram %s ", GetObjectName());
183  fxClient->SendStatusMessage(3, kFALSE, buf);
185  delete his;
186  }
187  fxResult->SetMessage(buf.Data());
188  return 0;
189 }
190 
192 {
193  if(!dyn) return -1;
194  TString buf;
195  if(fxAna->AddDynamicEntry((TGo4DynamicEntry *)dyn->Clone())) {
196  TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (dyn);
197  if (tentry && tentry->IsEnabledProcessing())
200  buf = TString::Format("Set new status for entry %s of dynamic list %s.", GetObjectName(), GetFolderName());
201  fxClient->SendStatusMessage(1, kTRUE, buf);
202  } else {
203  buf = TString::Format("Could not set status for entry %s of dynamic list %s !!!", GetObjectName(), GetFolderName());
205  fxClient->SendStatusMessage(2, kTRUE, buf);
206  }
207  fxResult->SetMessage(buf.Data());
208  delete fxObject;
209  fxObject = nullptr;
210  return 0;
211 }
212 
214 {
215  if(!pic) return -1;
216  TString buf;
217  if(fxAna->SetPicture(GetObjectName(),pic)) {
219  buf = TString::Format("Picture %s was set to new values.", GetObjectName());
220  fxClient->SendStatusMessage(1, kFALSE, buf);
221  } else {
222  buf = TString::Format("SetPicture - ERROR: failed to set %s",GetObjectName());
223  fxClient->SendStatusMessage(3, kFALSE, buf);
225  }
226  fxResult->SetMessage(buf.Data());
227  delete fxObject;
228  fxObject = nullptr;
229  return 0;
230 }
231 
232 Int_t TGo4ComSetObject::ExeSetObj(TObject *ob)
233 {
234  TString buf;
235  if(fxAna->AddObject(dynamic_cast<TNamed*>(ob))) {
237  buf = TString::Format("Added new object %s to Go4 folders.", GetObjectName());
238  fxClient->SendStatusMessage(1, kFALSE, buf);
239  } else {
241  buf = TString::Format("ERROR on adding new object %s ", GetObjectName());
242  fxClient->SendStatusMessage(3, kFALSE, buf);
243  delete ob;
244  }
245  fxResult->SetMessage(buf.Data());
246  return 0;
247 }
Int_t ExeSetPar(TGo4Parameter *par)
void SetReceiverName(const char *)
Definition: TGo4Command.cxx:93
Int_t ExeCom() override
Go4ResultAction_t Action() const
TGo4CommandReceiver * fxReceiverBase
Definition: TGo4Command.h:116
Bool_t SetParameter(const char *name, TGo4Parameter *par)
Int_t ExeSetHis(TH1 *his)
TGo4AnalysisObjectNames * GetNamesList() const
Int_t ExeSetParStatus(TGo4ParameterStatus *par)
TObject * GetAggregate(Bool_t chown=kTRUE)
void SetMessage(const char *nam)
Int_t ExeSetDyn(TGo4DynamicEntry *dyn)
Bool_t SetParameterStatus(const char *name, TGo4ParameterStatus *par)
void SendStatusMessage(Int_t level, Bool_t printout, const TString &text) override
void SetDynListInterval(Int_t val)
Bool_t IsEnabledProcessing() const
TGo4Analysis * fxAna
Bool_t SetAnalysisCondition(const char *name, TGo4Condition *con, Bool_t counter=kTRUE)
static void Debug(const char *text,...) GO4_PRINTF_ARGS
Definition: TGo4Log.cxx:281
void Set(TGo4RemoteCommand *remcon) override
TGo4AnalysisClient * fxClient
void SetNamesList(TGo4AnalysisObjectNames *n)
TGo4AnalysisObjectResult * fxResult
virtual ~TGo4ComSetObject()
void SetObjectName(const char *name)
Bool_t AddHistogram(TH1 *his, const char *subfolder=nullptr, Bool_t replace=kTRUE)
void SendStatus(TGo4Status *stat, const char *receiver=nullptr)
Definition: TGo4Slave.cxx:121
void SetProtection(Go4CommandMode_t m)
Definition: TGo4Command.h:104
void SetObjectFullName(const char *nam)
void SetAction(Go4ResultAction_t com)
Bool_t AddObject(TNamed *anything, const char *subfolder=nullptr, Bool_t replace=kTRUE)
Int_t ExeSetPic(TGo4Picture *pic)
#define GO4TRACE(X)
Definition: TGo4Log.h:25
Bool_t SetPicture(const char *name, TGo4Picture *pic)
void Set(TGo4RemoteCommand *remcon) override
Int_t ExeSetCon(TGo4Condition *con)
Bool_t AddDynamicEntry(TGo4DynamicEntry *entry)
Int_t ExeSetObj(TObject *ob)
static TGo4Analysis * Instance()
TFolder * GetObjectFolder()