00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4BrowserStatus.h"
00017
00018 #include <iostream.h>
00019 #include <string.h>
00020
00021 #include "TH1.h"
00022 #include "THStack.h"
00023 #include "TGraph.h"
00024 #include "TObjArray.h"
00025 #include "TIterator.h"
00026
00027 #include "Go4StatusBase/TGo4Picture.h"
00028 #include "Go4StatusBase/TGo4CanvasWrapper.h"
00029 #include "Go4LockGuard/TGo4LockGuard.h"
00030
00031 TGo4BrowserStatus::TGo4BrowserStatus(const char* name, const char* title) : TGo4Status(name, title)
00032 {
00033 TGo4LockGuard Global;
00034 LocalListContent = new TObjArray();
00035 LocalListIter = LocalListContent->MakeIterator();
00036 }
00037
00038 TGo4BrowserStatus::~TGo4BrowserStatus()
00039 {
00040 TGo4LockGuard Global;
00041 LocalListContent->Delete();
00042 delete LocalListIter;
00043 delete LocalListContent;
00044 }
00045
00046 const char *TGo4BrowserStatus::AddObjectToLocalListStatus(TNamed *fxData_Local, Bool_t clone, int i)
00047 {
00048 TGo4LockGuard Global;
00049 char buffer[256];
00050 char cycle[10];
00051 TObject* LocalObject=0;
00052 int Pos;
00053 TObject* addedobject=0;
00054
00055
00056 TGo4CanvasWrapper* cwrap=dynamic_cast<TGo4CanvasWrapper*>(fxData_Local);
00057 if(cwrap)
00058 {
00059
00060 addedobject=cwrap->GetCanvas(kFALSE);
00061 }
00062 else
00063 {
00064 addedobject=fxData_Local;
00065 }
00066 if(addedobject==0)
00067 {
00068
00069 return 0;
00070 }
00071 LocalObject=LocalListContent->FindObject(addedobject->GetName());
00072 if(LocalObject==0) {
00073 TObject* cloned= clone ? addedobject->Clone() : addedobject;
00074 TH1* clonedhis=dynamic_cast<TH1*>(cloned);
00075 if(clonedhis) clonedhis->SetDirectory(0);
00076 LocalListContent->AddLast(cloned);
00077 } else {
00078 snprintf(buffer,255,"%s",addedobject->GetName());
00079 Pos = strcspn(addedobject->GetName(),",");
00080 snprintf(cycle,255,",%d",i);
00081 strncpy(buffer+Pos,cycle,sizeof(cycle));
00082 if(LocalListContent->FindObject(buffer)==0) {
00083 TObject* cloned = 0;
00084 if (clone) {
00085 cloned = addedobject->Clone(buffer);
00086 } else {
00087 cloned = addedobject;
00088 TNamed* named = dynamic_cast<TNamed*> (cloned);
00089 if (named) named->SetName(buffer);
00090 }
00091 TH1* clonedhis = dynamic_cast<TH1*>(cloned);
00092 if(clonedhis) clonedhis->SetDirectory(0);
00093 LocalListContent->AddLast(cloned);
00094 } else
00095 AddObjectToLocalListStatus(fxData_Local, clone, i+1);
00096 }
00097 return LocalListContent->Last()->GetName();
00098 }
00099
00100 const char * TGo4BrowserStatus::AddLocalObject(TNamed * fxData_Local, int i)
00101 {
00102
00103 char buffer[256];
00104 char cycle[10];
00105 TObject* LocalObject;
00106 int Pos;
00107
00108 LocalObject=LocalListContent->FindObject(fxData_Local->GetName());
00109
00110 if(LocalObject==0){
00111
00112 LocalListContent->AddLast(fxData_Local);
00113 }else{
00114 snprintf(buffer,255,"%s",fxData_Local->GetName());
00115 Pos= strcspn(fxData_Local->GetName(),",");
00116 snprintf(cycle,9,",%d",i);
00117 strncpy(buffer+Pos,cycle,sizeof(cycle));
00118
00119 if(LocalListContent->FindObject(buffer)==0){
00120 fxData_Local->SetName(buffer);
00121 LocalListContent->AddLast(fxData_Local);
00122 }else{
00123 AddLocalObject(fxData_Local,i+1);
00124 }
00125
00126 }
00127 return LocalListContent->Last()->GetName();
00128
00129 }
00130
00131 const char * TGo4BrowserStatus::OverWriteLocalObject(TNamed * fxData_Local)
00132 {
00133
00134 TGo4LockGuard Global;
00135 TObject* LocalObject=0;
00136 LocalObject=LocalListContent->FindObject(fxData_Local->GetName());
00137 LocalListContent->Remove(LocalObject);
00138 LocalListContent->Compress();
00139 LocalListContent->Expand(LocalListContent->GetLast()+1);
00140 delete LocalObject;
00141 TObject* addedobject=0;
00142 TGo4CanvasWrapper* cwrap=dynamic_cast<TGo4CanvasWrapper*>(fxData_Local);
00143 if(cwrap)
00144 {
00145 addedobject=cwrap->GetCanvas(kFALSE);
00146 }
00147 else
00148 {
00149 addedobject=fxData_Local;
00150 }
00151 LocalListContent->AddLast(addedobject->Clone());
00152 return LocalListContent->Last()->GetName();
00153 }
00154
00155 TObjArray *TGo4BrowserStatus::GetLocalListStatus()
00156 {
00157
00158 return(LocalListContent);
00159 }
00160 TObject* TGo4BrowserStatus::GetObjectfromLocalList(const char *Object)
00161 {
00162
00163 return(LocalListContent->FindObject(Object));
00164 }
00165
00166
00167 void TGo4BrowserStatus::RemoveObjectfromLocalList(TObject *Object)
00168 {
00169
00170
00171
00172 if (Object==0) return;
00173
00174 if (Object->InheritsFrom(THStack::Class())) {
00175 THStack* stack = (THStack*) Object;
00176 if (stack->GetHists())
00177 stack->GetHists()->Clear("nodelete");
00178 }
00179
00180 LocalListContent->RecursiveRemove(Object);
00181 LocalListContent->Compress();
00182 LocalListContent->Expand(LocalListContent->GetLast()+1);
00183 TList stackstoremove;
00184 TIter iter(LocalListContent);
00185 TObject* obj;
00186 while ((obj=iter()) != 0)
00187 {
00188 if (obj->InheritsFrom(THStack::Class())) {
00189 THStack* stack = (THStack*) obj;
00190 TList* hlist=stack->GetHists();
00191 if (hlist)
00192 {
00193 if (hlist->FindObject(Object)) {
00194 hlist->Remove(Object);
00195 stack->Modified();
00196 }
00197
00198
00199
00200
00201
00202 }
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 delete Object;
00214
00215 }
00216
00217 void TGo4BrowserStatus::SetLocalSort(bool SORTING)
00218 {
00219 LocalListContent->Sort(SORTING);
00220 }
00221
00222