Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/TGo4BrowserStatus.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE 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 "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    // resolve canvas. Since TCanvas is not TNamed, we wrap it int
00055    // a TNamed container, the canvas wrapper:
00056    TGo4CanvasWrapper* cwrap=dynamic_cast<TGo4CanvasWrapper*>(fxData_Local);
00057    if(cwrap)
00058       {
00059          //cout <<"AddObjectToLocalListStatus has canvas wrapper." << endl;
00060          addedobject=cwrap->GetCanvas(kFALSE);
00061       }
00062    else
00063       {
00064          addedobject=fxData_Local;
00065       }
00066    if(addedobject==0)
00067       {
00068          //cout <<"addedobject is zero!" << endl;
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); // avoid histograms to appear in root memory
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); // avoid histograms to appear in root memory
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    // TGo4LockGuard Global;
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 //      fxData_Local->Print();
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    // TGo4LockGuard Global;
00163    return(LocalListContent->FindObject(Object));
00164 }
00165 
00166 
00167 void TGo4BrowserStatus::RemoveObjectfromLocalList(TObject *Object)
00168 {
00169    // TGo4LockGuard Global;
00170 //   LocalListContent->Remove(Object);
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 //             if(hlist->IsEmpty())
00198 //                {
00199 //                   stackstoremove.Add(stack); // do not change object list inside iteration!
00200 //                   cout <<"Stack is empty "<<stack << endl;
00201 //                }
00202           }
00203          }
00204       }
00205 //   TIter riter(&stackstoremove);
00206 //   while ((obj=riter()) != 0)
00207 //       {
00208 //         RemoveObjectfromLocalList(obj); // remove empty stacks afterwards
00209 //         cout <<"Removed from list "<<obj << endl;
00210 //         // here we would have to delete the item from browser ????
00211 //
00212 //       }
00213    delete   Object;
00214 //   cout <<"deleted"<<Object << endl;
00215 }
00216 
00217 void TGo4BrowserStatus::SetLocalSort(bool SORTING)
00218 {
00219    LocalListContent->Sort(SORTING);
00220 }
00221 
00222 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:59 2005 for Go4-v2.10-5 by doxygen1.2.15