00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4ComSetObject.h"
00015
00016 #include "TFolder.h"
00017 #include "TH1.h"
00018
00019 #include "TGo4Log.h"
00020 #include "TGo4AnalysisClientImp.h"
00021 #include "TGo4AnalysisImp.h"
00022 #include "TGo4AnalysisObjectManager.h"
00023 #include "TGo4RemoteCommand.h"
00024 #include "TGo4AnalysisObjectResult.h"
00025 #include "TGo4Parameter.h"
00026 #include "TGo4ParameterStatus.h"
00027 #include "TGo4Condition.h"
00028 #include "TGo4DynamicEntry.h"
00029 #include "TGo4TreeHistogramEntry.h"
00030 #include "TGo4Picture.h"
00031
00032
00033 TGo4ComSetObject::TGo4ComSetObject() :
00034 TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object","mypara"),
00035 fxObject(0),
00036 fxClient(0),
00037 fxAna(0),
00038 fxResult(0)
00039 {
00040 SetReceiverName("AnalysisClient");
00041
00042 SetProtection(kGo4ComModeController);
00043 }
00044
00045
00046 TGo4ComSetObject::TGo4ComSetObject(const char* obname) :
00047 TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object",obname),
00048 fxObject(0),
00049 fxClient(0),
00050 fxAna(0),
00051 fxResult(0)
00052 {
00053 SetReceiverName("AnalysisClient");
00054
00055 SetProtection(kGo4ComModeController);
00056 }
00057
00058
00059 TGo4ComSetObject::~TGo4ComSetObject()
00060 {
00061
00062 delete fxResult;
00063 }
00064
00065 void TGo4ComSetObject::Set(TGo4RemoteCommand* remcom)
00066 {
00067 if(remcom==0) return;
00068 TGo4AnalysisObjectCommand::Set(remcom);
00069 TObject* ob=remcom->GetAggregate();
00070 if(ob && ob!=fxObject) {
00071 delete fxObject;
00072 fxObject=ob;
00073 }
00074 }
00075
00076 Int_t TGo4ComSetObject::ExeCom()
00077 {
00078 fxClient = dynamic_cast<TGo4AnalysisClient*> (fxReceiverBase);
00079 if (fxClient==0) {
00080 GO4TRACE((11,"TGo4ComSetObject::ExeCom() - no receiver specified ERROR!",__LINE__, __FILE__));
00081 TGo4Log::Debug(" !!! %s : NO RECEIVER ERROR!!!",GetName());
00082 return 1;
00083 }
00084
00085 if(fxObject==0) {
00086 fxClient->SendStatusMessage(3, kTRUE, TString::Format("SetObject - ERROR: no source object specified for %s", GetObjectName()));
00087 return 0;
00088 }
00089
00090 SetObjectName(fxObject->GetName());
00091 TGo4Log::Debug(" %s : Setting object %s ", GetName(), GetObjectName());
00092 fxAna = TGo4Analysis::Instance();
00093 fxResult = new TGo4AnalysisObjectResult(GetObjectName());
00094
00095 if(ExeSetParStatus(dynamic_cast<TGo4ParameterStatus*>(fxObject))==0)
00096 ;
00097 else if(ExeSetPar(dynamic_cast<TGo4Parameter*>(fxObject))==0)
00098 ;
00099 else if(ExeSetCon(dynamic_cast<TGo4Condition*>(fxObject))==0)
00100 ;
00101 else if(ExeSetDyn(dynamic_cast<TGo4DynamicEntry*>(fxObject))==0)
00102 ;
00103 else if(ExeSetHis(dynamic_cast<TH1*>(fxObject))==0)
00104 ;
00105 else if(ExeSetPic(dynamic_cast<TGo4Picture*>(fxObject))==0)
00106 ;
00107 else
00108 ExeSetObj(fxObject);
00109
00110 fxAna->UpdateNamesList();
00111 TGo4AnalysisObjectNames* state = fxAna->GetNamesList();
00112 fxResult->SetNamesList(state);
00113 if(fxResult->Action()!=kGo4ActionError) {
00114 TFolder* top = fxAna->GetObjectFolder();
00115 TString fullname = top->FindFullPathName(GetObjectName());
00116 fullname.Remove(0, 6);
00117 fxResult->SetObjectFullName(fullname);
00118 }
00119 fxClient->SendStatus(fxResult);
00120 return -1;
00121 }
00122
00123 Int_t TGo4ComSetObject::ExeSetParStatus(TGo4ParameterStatus* par)
00124 {
00125 if (par==0) return -1;
00126 TString buf;
00127 if(fxAna->SetParameterStatus(GetObjectName(),par)) {
00128 buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
00129 fxClient->SendStatusMessage(1, kTRUE, buf);
00130 fxResult->SetAction(kGo4ActionEdit);
00131 } else {
00132 buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
00133 fxClient->SendStatusMessage(3, kTRUE, buf);
00134 fxResult->SetAction(kGo4ActionError);
00135 }
00136 fxResult->SetMessage(buf.Data());
00137 delete fxObject;
00138 return 0;
00139 }
00140
00141 Int_t TGo4ComSetObject::ExeSetPar(TGo4Parameter* par)
00142 {
00143 if(par==0) return -1;
00144 TString buf;
00145 if(fxAna->SetParameter(GetObjectName(),par)) {
00146 buf = TString::Format("Parameter %s was set to new values.", GetObjectName());
00147 fxClient->SendStatusMessage(1, kTRUE, buf);
00148 fxResult->SetAction(kGo4ActionEdit);
00149 } else {
00150 buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName());
00151 fxClient->SendStatusMessage(3, kTRUE, buf);
00152 fxResult->SetAction(kGo4ActionError);
00153 }
00154 fxResult->SetMessage(buf.Data());
00155 delete fxObject;
00156 return 0;
00157 }
00158
00159 Int_t TGo4ComSetObject::ExeSetCon(TGo4Condition* conny)
00160 {
00161 if(conny==0) return -1;
00162 TString buf;
00163 if(fxAna->SetAnalysisCondition(GetObjectName(),conny, kFALSE)) {
00164 buf = TString::Format("Condition %s was set to new values.", GetObjectName());
00165 fxClient->SendStatusMessage(1, kTRUE, buf);
00166 fxResult->SetAction(kGo4ActionEdit);
00167 } else {
00168 buf = TString::Format("SetCondition - ERROR: failed to set %s", GetObjectName());
00169 fxClient->SendStatusMessage(3, kTRUE, buf);
00170 fxResult->SetAction(kGo4ActionError);
00171 }
00172 fxResult->SetMessage(buf.Data());
00173 delete fxObject;
00174 return 0;
00175 }
00176
00177 Int_t TGo4ComSetObject::ExeSetHis(TH1* his)
00178 {
00179 if(his==0) return -1;
00180 TString buf;
00181 if(fxAna->AddHistogram(his)) {
00182 his->SetBit(TGo4Status::kGo4CanDelete);
00183 fxResult->SetAction(kGo4ActionPlot);
00184 buf = TString::Format("Added new histogram %s to Go4 folders.", GetObjectName());
00185 fxClient->SendStatusMessage(1, kFALSE, buf);
00186 } else {
00187 buf = TString::Format("ERROR on adding new histogram %s ", GetObjectName());
00188 fxClient->SendStatusMessage(3, kFALSE, buf);
00189 fxResult->SetAction(kGo4ActionError);
00190 delete his;
00191 }
00192 fxResult->SetMessage(buf.Data());
00193 return 0;
00194 }
00195
00196 Int_t TGo4ComSetObject::ExeSetDyn(TGo4DynamicEntry* dyn)
00197 {
00198 if(dyn==0) return -1;
00199 TString buf;
00200 if(fxAna->AddDynamicEntry((TGo4DynamicEntry*)dyn->Clone())) {
00201 TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (dyn);
00202 if ((tentry!=0) && tentry->IsEnabledProcessing())
00203 fxAna->SetDynListInterval(tentry->GetDynListInterval());
00204 fxResult->SetAction(kGo4ActionEdit);
00205 buf = TString::Format("Set new status for entry %s of dynamic list %s.", GetObjectName(), GetFolderName());
00206 fxClient->SendStatusMessage(1, kTRUE, buf);
00207 } else {
00208 buf = TString::Format("Could not set status for entry %s of dynamic list %s !!!", GetObjectName(), GetFolderName());
00209 fxResult->SetAction(kGo4ActionError);
00210 fxClient->SendStatusMessage(2, kTRUE, buf);
00211 }
00212 fxResult->SetMessage(buf.Data());
00213 delete fxObject;
00214 return 0;
00215 }
00216
00217 Int_t TGo4ComSetObject::ExeSetPic(TGo4Picture* pic)
00218 {
00219 if(pic==0) return -1;
00220 TString buf;
00221 if(fxAna->SetPicture(GetObjectName(),pic)) {
00222 fxResult->SetAction(kGo4ActionPlot);
00223 buf = TString::Format("Picture %s was set to new values.", GetObjectName());
00224 fxClient->SendStatusMessage(1, kFALSE, buf);
00225 } else {
00226 buf = TString::Format("SetPicture - ERROR: failed to set %s",GetObjectName());
00227 fxClient->SendStatusMessage(3, kFALSE, buf);
00228 fxResult->SetAction(kGo4ActionError);
00229 }
00230 fxResult->SetMessage(buf.Data());
00231 delete fxObject;
00232 return 0;
00233 }
00234
00235
00236 Int_t TGo4ComSetObject::ExeSetObj(TObject* ob)
00237 {
00238 TString buf;
00239 if(fxAna->AddObject(dynamic_cast<TNamed*>(ob))) {
00240 fxResult->SetAction(kGo4ActionRefresh);
00241 buf = TString::Format("Added new object %s to Go4 folders.", GetObjectName());
00242 fxClient->SendStatusMessage(1, kFALSE, buf);
00243 } else {
00244 fxResult->SetAction(kGo4ActionError);
00245 buf = TString::Format("ERROR on adding new object %s ", GetObjectName());
00246 fxClient->SendStatusMessage(3, kFALSE, buf);
00247 delete ob;
00248 }
00249 fxResult->SetMessage(buf.Data());
00250 return 0;
00251 }