Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4ComSetObject.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4ComSetObject.h"
00017 
00018 #include "TFolder.h"
00019 #include "TH1.h"
00020 #include "snprintf.h"
00021 
00022 #include "TGo4Log.h"
00023 #include "TGo4AnalysisClientImp.h"
00024 #include "TGo4AnalysisImp.h"
00025 #include "TGo4AnalysisObjectManager.h"
00026 #include "TGo4RemoteCommand.h"
00027 #include "TGo4AnalysisObjectResult.h"
00028 #include "TGo4Parameter.h"
00029 #include "TGo4ParameterStatus.h"
00030 #include "TGo4Condition.h"
00031 #include "TGo4DynamicEntry.h"
00032 #include "TGo4TreeHistogramEntry.h"
00033 #include "TGo4Picture.h"
00034 
00035 
00036 TGo4ComSetObject::TGo4ComSetObject(const char* obname)
00037 :TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object",obname),
00038 fxObject(0),fxClient(0), fxAna(0),fxResult(0)
00039 {
00040    SetReceiverName("AnalysisClient");  // this command needs client as receiver
00041                                                  // override default receiver
00042    SetProtection(kGo4ComModeController);
00043 }
00044 
00045 TGo4ComSetObject::TGo4ComSetObject()
00046 :TGo4AnalysisObjectCommand("ANSetObject","Set existing object to new values or create new object","mypara"),
00047 fxObject(0),fxClient(0), fxAna(0),fxResult(0)
00048  {
00049    SetReceiverName("AnalysisClient");  // this command needs client as receiver
00050                                                  // override default receiver
00051    SetProtection(kGo4ComModeController);
00052 }
00053 
00054 TGo4ComSetObject::~TGo4ComSetObject()
00055 {
00056    //delete fxObject; // cleanup is done depending on ExeCom
00057    delete fxResult; //
00058 }
00059 
00060 void TGo4ComSetObject::Set(TGo4RemoteCommand* remcom)
00061 {
00062 if(remcom==0) return;
00063 TGo4AnalysisObjectCommand::Set(remcom);
00064 TObject* ob=remcom->GetAggregate(); // we take over ownership
00065 if(ob && ob!=fxObject)
00066    {
00067       delete fxObject;
00068       fxObject=ob;
00069    }
00070 }
00071 
00072 Int_t TGo4ComSetObject::ExeCom()
00073 {
00074    fxClient=dynamic_cast<TGo4AnalysisClient*> (fxReceiverBase);
00075    if (fxClient!=0)
00076       {
00077          if(fxObject==0)
00078             {
00079                fxClient->SendStatusMessage(3, kTRUE,"SetObject - ERROR:  no source object specified for  %s",
00080                                                 GetObjectName());
00081                return 0;
00082             } else {}
00083          SetObjectName(fxObject->GetName()); // override target name...
00084          TGo4Log::Debug(" %s : Setting object %s  ",
00085             GetName(), GetObjectName());
00086          fxAna = TGo4Analysis::Instance();
00087          fxResult = new TGo4AnalysisObjectResult(GetObjectName());
00088          Bool_t isdynentry = kFALSE;
00089          // evaluate object type here:
00090          if(ExeSetParStatus(dynamic_cast<TGo4ParameterStatus*>(fxObject))==0)
00091             ;
00092          else if(ExeSetPar(dynamic_cast<TGo4Parameter*>(fxObject))==0)
00093             ;
00094          else if(ExeSetCon(dynamic_cast<TGo4Condition*>(fxObject))==0)
00095             ;
00096          else if(ExeSetDyn(dynamic_cast<TGo4DynamicEntry*>(fxObject))==0)
00097             isdynentry = kTRUE;
00098          else if(ExeSetHis(dynamic_cast<TH1*>(fxObject))==0)
00099             ;
00100          else if(ExeSetPic(dynamic_cast<TGo4Picture*>(fxObject))==0)
00101             ;
00102          else
00103             ExeSetObj(fxObject);
00104 
00105          fxAna->UpdateNamesList();
00106          TGo4AnalysisObjectNames* state = fxAna->GetNamesList();
00107          fxResult->SetNamesList(state); // note: nameslist is not owned by result object!
00108          if(fxResult->Action()!=kGo4ActionError) {
00109              TString fullname;
00110 //             if (isdynentry) {
00111 //                fullname = "DynamicLists/Go4DynamicList/";
00112 //                fullname += GetObjectName();
00113 //             } else {
00114                 TFolder* top = fxAna->GetObjectFolder();
00115                 fullname = top->FindFullPathName(GetObjectName());
00116                 fullname.Remove(0, 6); // remove //Go4/ top folder name
00117 //             }
00118 
00119              fxResult->SetObjectFullName(fullname);
00120          }
00121          fxClient->SendStatus(fxResult);
00122       }
00123    else
00124       {
00125          TRACE((11,"TGo4ComSetObject::ExeCom() - no receiver specified ERROR!",__LINE__, __FILE__));
00126          TGo4Log::Debug(" !!! %s : NO RECEIVER ERROR!!!",GetName());
00127          return 1;
00128       }
00129    return -1;
00130 }
00131 
00132 Int_t TGo4ComSetObject::ExeSetParStatus(TGo4ParameterStatus* par)
00133 {
00134    if (par==0) return -1;
00135    char buf[256];
00136    if(fxAna->SetParameterStatus(GetObjectName(),par)) {
00137       snprintf(buf,255,"Parameter %s was set to new values.", GetObjectName());
00138       fxClient->SendStatusMessage(1, kTRUE,buf);
00139       fxResult->SetAction(kGo4ActionEdit);
00140    } else {
00141       snprintf(buf,255,"SetObject - ERROR: failed to set parameter %s",GetObjectName());
00142       fxClient->SendStatusMessage(3, kTRUE, buf);
00143       fxResult->SetAction(kGo4ActionError);
00144    }
00145    fxResult->SetMessage(buf);
00146    delete fxObject;
00147    return 0;
00148 }
00149 
00150 Int_t TGo4ComSetObject::ExeSetPar(TGo4Parameter* par)
00151 {
00152 if(par==0) return -1;
00153 char buf[256];
00154 if(fxAna->SetParameter(GetObjectName(),par))
00155    {
00156      snprintf(buf,255,"Parameter %s was set to new values.", GetObjectName());
00157      fxClient->SendStatusMessage(1, kTRUE,buf);
00158      fxResult->SetAction(kGo4ActionEdit);
00159    }
00160 else
00161    {
00162       snprintf(buf,255,"SetObject - ERROR: failed to set parameter %s",GetObjectName());
00163       fxClient->SendStatusMessage(3, kTRUE,buf);
00164       fxResult->SetAction(kGo4ActionError);
00165    }
00166 fxResult->SetMessage(buf);
00167 delete fxObject;
00168 return 0;
00169 }
00170 
00171 Int_t TGo4ComSetObject::ExeSetCon(TGo4Condition* conny)
00172 {
00173 if(conny==0) return -1;
00174 char buf[256];
00175 if(fxAna->SetAnalysisCondition(GetObjectName(),conny, kFALSE))
00176    {
00177      snprintf(buf,255,"Condition %s was set to new values.", GetObjectName());
00178      fxClient->SendStatusMessage(1, kTRUE,buf);
00179      fxResult->SetAction(kGo4ActionEdit);
00180    }
00181 else
00182    {
00183       snprintf(buf,255,"SetCondition - ERROR: failed to set %s", GetObjectName());
00184       fxClient->SendStatusMessage(3, kTRUE,buf);
00185       fxResult->SetAction(kGo4ActionError);
00186    }
00187 fxResult->SetMessage(buf);
00188 delete fxObject;
00189 return 0;
00190 }
00191 
00192 Int_t TGo4ComSetObject::ExeSetHis(TH1* his)
00193 {
00194 if(his==0) return -1;
00195 char buf[256];
00196 if(fxAna->AddHistogram(his))
00197    {
00198      his->SetBit(TGo4Status::kGo4CanDelete); // dynamic objects may be deleted from gui
00199      snprintf(buf,255,"Added new histogram %s to Go4 folders.", GetObjectName());
00200      fxResult->SetAction(kGo4ActionPlot);
00201      fxClient->SendStatusMessage(1, kFALSE,buf);
00202    }
00203 else
00204    {
00205       snprintf(buf,255,"ERROR on adding new histogram %s ", GetObjectName());
00206       fxClient->SendStatusMessage(3, kFALSE,buf);
00207       fxResult->SetAction(kGo4ActionError);
00208       delete his;
00209    }
00210 fxResult->SetMessage(buf);
00211 return 0;
00212 }
00213 
00214 Int_t TGo4ComSetObject::ExeSetDyn(TGo4DynamicEntry* dyn)
00215 {
00216    if(dyn==0) return -1;
00217    char buf[256];
00218    if(fxAna->AddDynamicEntry((TGo4DynamicEntry*)dyn->Clone())) {
00219       TGo4TreeHistogramEntry* tentry = dynamic_cast<TGo4TreeHistogramEntry*> (dyn);
00220       if ((tentry!=0) && tentry->IsEnabledProcessing())
00221         fxAna->SetDynListInterval(tentry->GetDynListInterval());
00222 
00223       snprintf(buf,255,"Set new status for entry  %s of dynamic list %s.",
00224                 GetObjectName(), GetFolderName());
00225       fxResult->SetAction(kGo4ActionEdit);
00226       fxClient->SendStatusMessage(1,kTRUE,buf);
00227    } else {
00228       snprintf(buf,255,"Could not set status for entry %s of dynamic list %s !!!",
00229                       GetObjectName(), GetFolderName());
00230       fxResult->SetAction(kGo4ActionError);
00231       fxClient->SendStatusMessage(2,kTRUE,buf);
00232    }
00233    fxResult->SetMessage(buf);
00234    delete fxObject;
00235    return 0;
00236 }
00237 
00238 Int_t TGo4ComSetObject::ExeSetPic(TGo4Picture* pic)
00239 {
00240 if(pic==0) return -1;
00241 char buf[256];
00242 if(fxAna->SetPicture(GetObjectName(),pic))
00243 {
00244    snprintf(buf,255,"Picture %s was set to new values.", GetObjectName());
00245    fxResult->SetAction(kGo4ActionPlot);
00246    fxClient->SendStatusMessage(1, kFALSE,buf);
00247 }
00248 else
00249 {
00250    snprintf(buf,255,"SetPicture - ERROR: failed to set %s",GetObjectName());
00251    fxClient->SendStatusMessage(3, kFALSE,buf);
00252    fxResult->SetAction(kGo4ActionError);
00253 }
00254 fxResult->SetMessage(buf);
00255 delete fxObject;
00256 return 0;
00257 
00258 
00259 }
00260 
00261 
00262 Int_t TGo4ComSetObject::ExeSetObj(TObject* ob)
00263 {
00264 char buf[256];
00265 if(fxAna->AddObject(dynamic_cast<TNamed*>(ob)))
00266    {
00267       snprintf(buf,255,"Added new object %s to Go4 folders.",
00268                                     GetObjectName());
00269       fxResult->SetAction(kGo4ActionRefresh);
00270       fxClient->SendStatusMessage(1, kFALSE,buf);
00271    }
00272 else
00273    {
00274       snprintf(buf,255,"ERROR on adding new object %s ",
00275                                      GetObjectName());
00276       fxResult->SetAction(kGo4ActionError);
00277       fxClient->SendStatusMessage(3, kFALSE,buf);
00278       delete ob;
00279    }
00280 fxResult->SetMessage(buf);
00281 return 0;
00282 }
00283 
00284 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:05 2008 for Go4-v3.04-1 by  doxygen 1.4.2