// $Id$ //----------------------------------------------------------------------- // The GSI Online Offline Object Oriented (Go4) Project // Experiment Data Processing at EE department, GSI //----------------------------------------------------------------------- // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH // Planckstr. 1, 64291 Darmstadt, Germany // Contact: http://go4.gsi.de //----------------------------------------------------------------------- // This software can be used under the license agreements as stated // in Go4License.txt file which is part of the distribution. //----------------------------------------------------------------------- #include "TGo4ComSetObject.h" #include "TFolder.h" #include "TH1.h" #include "TGo4Log.h" #include "TGo4AnalysisClientImp.h" #include "TGo4AnalysisImp.h" #include "TGo4RemoteCommand.h" #include "TGo4AnalysisObjectResult.h" #include "TGo4Parameter.h" #include "TGo4ParameterStatus.h" #include "TGo4Condition.h" #include "TGo4DynamicEntry.h" #include "TGo4TreeHistogramEntry.h" #include "TGo4Picture.h" TGo4ComSetObject::TGo4ComSetObject() : TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object","mypara") { SetReceiverName("AnalysisClient"); // this command needs client as receiver // override default receiver SetProtection(kGo4ComModeController); } TGo4ComSetObject::TGo4ComSetObject(const char *obname) : TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object",obname) { SetReceiverName("AnalysisClient"); // this command needs client as receiver // override default receiver SetProtection(kGo4ComModeController); } TGo4ComSetObject::~TGo4ComSetObject() { //delete fxObject; // cleanup is done depending on ExeCom delete fxResult; // } void TGo4ComSetObject::Set(TGo4RemoteCommand *remcom) { if(!remcom) return; TGo4AnalysisObjectCommand::Set(remcom); TObject *ob = remcom->GetAggregate(); // we take over ownership if(ob && ob!=fxObject) { delete fxObject; fxObject = ob; } } Int_t TGo4ComSetObject::ExeCom() { fxClient = dynamic_cast (fxReceiverBase); if (!fxClient) { GO4TRACE((11,"TGo4ComSetObject::ExeCom() - no receiver specified ERROR!",__LINE__, __FILE__)); TGo4Log::Debug(" !!! %s : NO RECEIVER ERROR!!!",GetName()); return 1; } if(!fxObject) { fxClient->SendStatusMessage(3, kTRUE, TString::Format("SetObject - ERROR: no source object specified for %s", GetObjectName())); return 0; } SetObjectName(fxObject->GetName()); // override target name... TGo4Log::Debug(" %s : Setting object %s ", GetName(), GetObjectName()); fxAna = TGo4Analysis::Instance(); fxResult = new TGo4AnalysisObjectResult(GetObjectName()); // evaluate object type here: if(ExeSetParStatus(dynamic_cast(fxObject)) == 0) { ; } else if(ExeSetPar(dynamic_cast(fxObject)) == 0) { ; } else if(ExeSetCon(dynamic_cast(fxObject)) == 0) { ; } else if(ExeSetDyn(dynamic_cast(fxObject)) == 0) { ; } else if(ExeSetHis(dynamic_cast(fxObject)) == 0) { ; } else if(ExeSetPic(dynamic_cast(fxObject)) == 0) { ; } else { ExeSetObj(fxObject); } fxAna->UpdateNamesList(); TGo4AnalysisObjectNames *state = fxAna->GetNamesList(); fxResult->SetNamesList(state); // note: nameslist is not owned by result object! if(fxResult->Action() != kGo4ActionError) { TFolder *top = fxAna->GetObjectFolder(); TString fullname = top->FindFullPathName(GetObjectName()); fullname.Remove(0, 6); // remove //Go4/ top folder name fxResult->SetObjectFullName(fullname); } fxClient->SendStatus(fxResult); return -1; } Int_t TGo4ComSetObject::ExeSetParStatus(TGo4ParameterStatus *par) { if (!par) return -1; TString buf; if(fxAna->SetParameterStatus(GetObjectName(),par)) { buf = TString::Format("Parameter %s was set to new values.", GetObjectName()); fxClient->SendStatusMessage(1, kTRUE, buf); fxResult->SetAction(kGo4ActionEdit); } else { buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName()); fxClient->SendStatusMessage(3, kTRUE, buf); fxResult->SetAction(kGo4ActionError); } fxResult->SetMessage(buf.Data()); delete fxObject; fxObject = nullptr; return 0; } Int_t TGo4ComSetObject::ExeSetPar(TGo4Parameter *par) { if(!par) return -1; TString buf; if(fxAna->SetParameter(GetObjectName(),par)) { buf = TString::Format("Parameter %s was set to new values.", GetObjectName()); fxClient->SendStatusMessage(1, kTRUE, buf); fxResult->SetAction(kGo4ActionEdit); } else { buf = TString::Format("SetObject - ERROR: failed to set parameter %s",GetObjectName()); fxClient->SendStatusMessage(3, kTRUE, buf); fxResult->SetAction(kGo4ActionError); } fxResult->SetMessage(buf.Data()); delete fxObject; fxObject = nullptr; return 0; } Int_t TGo4ComSetObject::ExeSetCon(TGo4Condition *conny) { if(!conny) return -1; TString buf; if(fxAna->SetAnalysisCondition(GetObjectName(),conny, kFALSE)) { buf = TString::Format("Condition %s was set to new values.", GetObjectName()); fxClient->SendStatusMessage(1, kTRUE, buf); fxResult->SetAction(kGo4ActionEdit); } else { buf = TString::Format("SetCondition - ERROR: failed to set %s", GetObjectName()); fxClient->SendStatusMessage(3, kTRUE, buf); fxResult->SetAction(kGo4ActionError); } fxResult->SetMessage(buf.Data()); delete fxObject; fxObject = nullptr; return 0; } Int_t TGo4ComSetObject::ExeSetHis(TH1 *his) { if(!his) return -1; TString buf; if(fxAna->AddHistogram(his)) { his->SetBit(TGo4Status::kGo4CanDelete); // dynamic objects may be deleted from gui fxResult->SetAction(kGo4ActionPlot); buf = TString::Format("Added new histogram %s to Go4 folders.", GetObjectName()); fxClient->SendStatusMessage(1, kFALSE, buf); } else { buf = TString::Format("ERROR on adding new histogram %s ", GetObjectName()); fxClient->SendStatusMessage(3, kFALSE, buf); fxResult->SetAction(kGo4ActionError); delete his; } fxResult->SetMessage(buf.Data()); return 0; } Int_t TGo4ComSetObject::ExeSetDyn(TGo4DynamicEntry *dyn) { if(!dyn) return -1; TString buf; if(fxAna->AddDynamicEntry((TGo4DynamicEntry *)dyn->Clone())) { TGo4TreeHistogramEntry* tentry = dynamic_cast (dyn); if (tentry && tentry->IsEnabledProcessing()) fxAna->SetDynListInterval(tentry->GetDynListInterval()); fxResult->SetAction(kGo4ActionEdit); buf = TString::Format("Set new status for entry %s of dynamic list %s.", GetObjectName(), GetFolderName()); fxClient->SendStatusMessage(1, kTRUE, buf); } else { buf = TString::Format("Could not set status for entry %s of dynamic list %s !!!", GetObjectName(), GetFolderName()); fxResult->SetAction(kGo4ActionError); fxClient->SendStatusMessage(2, kTRUE, buf); } fxResult->SetMessage(buf.Data()); delete fxObject; fxObject = nullptr; return 0; } Int_t TGo4ComSetObject::ExeSetPic(TGo4Picture *pic) { if(!pic) return -1; TString buf; if(fxAna->SetPicture(GetObjectName(),pic)) { fxResult->SetAction(kGo4ActionPlot); buf = TString::Format("Picture %s was set to new values.", GetObjectName()); fxClient->SendStatusMessage(1, kFALSE, buf); } else { buf = TString::Format("SetPicture - ERROR: failed to set %s",GetObjectName()); fxClient->SendStatusMessage(3, kFALSE, buf); fxResult->SetAction(kGo4ActionError); } fxResult->SetMessage(buf.Data()); delete fxObject; fxObject = nullptr; return 0; } Int_t TGo4ComSetObject::ExeSetObj(TObject *ob) { TString buf; if(fxAna->AddObject(dynamic_cast(ob))) { fxResult->SetAction(kGo4ActionRefresh); buf = TString::Format("Added new object %s to Go4 folders.", GetObjectName()); fxClient->SendStatusMessage(1, kFALSE, buf); } else { fxResult->SetAction(kGo4ActionError); buf = TString::Format("ERROR on adding new object %s ", GetObjectName()); fxClient->SendStatusMessage(3, kFALSE, buf); delete ob; } fxResult->SetMessage(buf.Data()); return 0; }