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

TGo4BrowserProxy.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 "TGo4BrowserProxy.h"
00017 
00018 #include "RVersion.h"
00019 #include "math.h"
00020 
00021 #include "TH1.h"
00022 #include "TH2.h"
00023 #include "TH3.h"
00024 #include "THStack.h"
00025 #include "TProfile.h"
00026 #include "TGraph.h"
00027 #include "TGraphErrors.h"
00028 #include "TGraphAsymmErrors.h"
00029 #include "TMultiGraph.h"
00030 #include "TList.h"
00031 #include "TFolder.h"
00032 #include "TDirectory.h"
00033 #include "TFile.h"
00034 #include "TTree.h"
00035 // #include "TPad.h"
00036 #include "TCanvas.h"
00037 #include "TTimer.h"
00038 #include "TROOT.h"
00039 #include "TObjString.h"
00040 #include "TDatime.h"
00041 #include "TObjectTable.h"
00042 
00043 #include "TGo4Log.h"
00044 #include "TGo4LockGuard.h"
00045 #include "TGo4Slot.h"
00046 #include "TGo4ObjectProxy.h"
00047 #include "TGo4DirProxy.h"
00048 #include "TGo4LinkProxy.h"
00049 #include "TGo4Iter.h"
00050 #include "TGo4ObjectManager.h"
00051 
00052 #include "TGo4Condition.h"
00053 #include "TGo4Fitter.h"
00054 #include "TGo4Parameter.h"
00055 #include "TGo4Picture.h"
00056 #include "TGo4Condition.h"
00057 #include "TGo4PolyCond.h"
00058 #include "TGo4WinCond.h"
00059 #include "TGo4CondArray.h"
00060 #include "TGo4HistogramEntry.h"
00061 #include "TGo4TreeHistogramEntry.h"
00062 #include "TGo4ExportManager.h"
00063 
00064 #include "TGo4AnalysisProxy.h"
00065 #include "TGo4HServProxy.h"
00066 #include "TVirtualTreePlayer.h"
00067 
00068 // required for ROOT browser
00069 // #include "TGo4BrowserItem.h"
00070 // #include "TGClient.h"
00071 // #include "TGMimeTypes.h"
00072 
00073 
00074 class TGo4BrowserObjProxy : public TGo4ObjectProxy {
00075    public:
00076       TGo4BrowserObjProxy() : TGo4ObjectProxy() {}
00077       TGo4BrowserObjProxy(TGo4Slot* slot, TObject* obj, Bool_t owner) : TGo4ObjectProxy(obj, owner)
00078       {
00079         if ((slot!=0) && (obj!=0))
00080           TGo4BrowserProxy::SetItemTimeDate(slot);
00081       }
00082 
00083       virtual ~TGo4BrowserObjProxy() {}
00084 
00085       virtual Bool_t Use() const { return kFALSE; }
00086 
00087       virtual Bool_t AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
00088       {
00089         if (fObject==obj) return kTRUE;
00090 
00091         Bool_t updatedone = false;
00092 
00093         if ((fObject!=0) && (obj!=0))
00094            if ((fObject->IsA()==obj->IsA()) &&
00095               (strcmp(fObject->GetName(), obj->GetName())==0))
00096                 updatedone = TGo4BrowserProxy::UpdateObjectContent(fObject, obj);
00097 
00098         if (obj!=0)
00099           TGo4BrowserProxy::SetItemTimeDate(slot);
00100 
00101         if (updatedone) {
00102            slot->ForwardEvent(slot, TGo4Slot::evObjUpdated);
00103            if (owner) delete obj;
00104            return kTRUE;
00105         }
00106 
00107         return TGo4ObjectProxy::AssignObject(slot, obj, owner);
00108       }
00109 
00110       virtual void Update(TGo4Slot* slot, Bool_t strong)
00111       {
00112          // can not update object which is not there
00113          if ((fObject==0) && !strong) return;
00114 
00115          TGo4Slot* parent = slot->GetParent();
00116          TGo4BrowserProxy* browser = 0;
00117 
00118          while(parent!=0)  {
00119             browser = dynamic_cast<TGo4BrowserProxy*> (parent->GetProxy());
00120             if (browser!=0) break;
00121             parent = parent->GetParent();
00122          }
00123          if (browser!=0)
00124            browser->RequestBrowserObject(slot);
00125       }
00126 };
00127 
00128 // ******************************************************************
00129 
00130 TGo4BrowserProxy::TGo4BrowserProxy() :
00131    TGo4Proxy(),
00132    fxDataPath(),
00133    fxBrowserPath(),
00134    fxViewPath(),
00135    fbWithRootBrowser(kFALSE),
00136    fxMemoryPath(),
00137    fxOM(0),
00138    fxBrowserSlot(0),
00139    fiMonitoringPeriod(0),
00140    fxMonitorTimer(0),
00141    fbBlockMonitoring(kFALSE),
00142    fiFilterIndex(0),
00143    fxWaitingList(0),
00144    fxClipboard(0),
00145    fxSyncTimer(0),
00146    fbBlockSync(kFALSE),
00147    fDummyTreePlayer(0)
00148 {
00149 }
00150 
00151 TGo4BrowserProxy::TGo4BrowserProxy(const char* datapath,
00152                                    const char* viewpath,
00153                                    Bool_t withRootBrowser) :
00154    TGo4Proxy(),
00155    fxDataPath(datapath),
00156    fxBrowserPath(),
00157    fxViewPath(viewpath),
00158    fbWithRootBrowser(withRootBrowser),
00159    fxMemoryPath("Workspace"),
00160    fxOM(0),
00161    fxBrowserSlot(0),
00162    fiMonitoringPeriod(0),
00163    fxMonitorTimer(0),
00164    fbBlockMonitoring(kFALSE),
00165    fiFilterIndex(0),
00166    fxWaitingList(0),
00167    fxClipboard(0),
00168    fxSyncTimer(0),
00169    fbBlockSync(kFALSE),
00170    fDummyTreePlayer(0)
00171 {
00172 }
00173 
00174 TGo4BrowserProxy::~TGo4BrowserProxy()
00175 {
00176    if (gDebug>1) Info("~TGo4BrowserProxy","Called");
00177 
00178    if (fDummyTreePlayer!=0) {
00179       delete fDummyTreePlayer;
00180       fDummyTreePlayer = 0;
00181    }
00182 
00183    if (fxWaitingList!=0) {
00184       fxWaitingList->Delete();
00185       delete fxWaitingList;
00186       fxWaitingList = 0;
00187    }
00188 
00189    ClearClipboard();
00190 
00191    if (fxSyncTimer!=0) {
00192       delete fxSyncTimer;
00193       fxSyncTimer = 0;
00194    }
00195 
00196    if (fxMonitorTimer!=0) {
00197       delete fxMonitorTimer;
00198       fxMonitorTimer = 0;
00199    }
00200 
00201    if (gDebug>1) Info("~TGo4BrowserProxy","Finished");
00202 }
00203 
00204 void TGo4BrowserProxy::Initialize(TGo4Slot* slot)
00205 {
00206    fxOM = slot->GetOM();
00207    fxBrowserSlot = slot;
00208    fxBrowserPath = "";
00209    fxBrowserSlot->ProduceFullName(fxBrowserPath);
00210 
00211    gROOT->GetClass("TH1");
00212    gROOT->GetClass("TH1C");
00213    gROOT->GetClass("TH1D");
00214    gROOT->GetClass("TH1F");
00215    gROOT->GetClass("TH1I");
00216    gROOT->GetClass("TH1S");
00217    gROOT->GetClass("TH2");
00218    gROOT->GetClass("TH2C");
00219    gROOT->GetClass("TH2D");
00220    gROOT->GetClass("TH2F");
00221    gROOT->GetClass("TH2I");
00222    gROOT->GetClass("TH2S");
00223    gROOT->GetClass("TH3");
00224    gROOT->GetClass("TH3C");
00225    gROOT->GetClass("TH3D");
00226    gROOT->GetClass("TH3F");
00227    gROOT->GetClass("TH3I");
00228    gROOT->GetClass("TH3S");
00229 
00230    if (fxOM!=0)
00231       fxOM->RegisterLink(fxOM->GetSlot(fxDataPath.Data()), slot, kTRUE);
00232 
00233    fiMonitoringPeriod = 0;
00234 }
00235 
00236 void TGo4BrowserProxy::Finalize(TGo4Slot* slot)
00237 {
00238    if (fxOM!=0) fxOM->UnregisterLink(slot);
00239    fxOM = 0;
00240    fxBrowserSlot = 0;
00241    fxBrowserPath = "";
00242 }
00243 
00244 Bool_t TGo4BrowserProxy::ProcessEvent(TGo4Slot* slot, TGo4Slot* source, Int_t id, void* param)
00245 {
00246    bool ischildevent = source->IsParent(slot);
00247 
00248 //   Info("ProcessEvent","Source %x %s event %d", source, source->GetName(), id);
00249 
00250    if ((source!=slot) && !ischildevent) {
00251       if (source->GetParent()!=0)
00252         if (dynamic_cast<TGo4AnalysisProxy*>(source->GetParent()->GetProxy())!=0)
00253           return kFALSE; // suppress message from analysis subitems
00254 
00255       if (!fbBlockSync) {
00256          if (fxSyncTimer==0) fxSyncTimer = new TTimer(this, 10, kTRUE);
00257          fbBlockSync = kTRUE;
00258          fxSyncTimer->Start(10, kTRUE);
00259       }
00260 
00261       return kFALSE; // do not process further
00262    } else
00263    if ((source!=slot) && ischildevent) {
00264       if ((id==TGo4Slot::evObjUpdated) || (id==TGo4Slot::evObjAssigned)) {
00265          CheckWaitingList(source);
00266          slot->ForwardEvent(slot, TGo4Slot::evSubslotUpdated, (void*) source);
00267          CheckPictureMonitor(source);
00268       }
00269    }
00270 
00271    return kTRUE;
00272 }
00273 
00274 void TGo4BrowserProxy::DataSlotName(const char* item, TString& res)
00275 {
00276    res = fxDataPath;
00277    res += "/";
00278    res += item;
00279 }
00280 
00281 void TGo4BrowserProxy::BrowserSlotName(const char* item, TString& res)
00282 {
00283    res = fxBrowserPath;
00284    res += "/";
00285    res += item;
00286 }
00287 
00288 TGo4Slot* TGo4BrowserProxy::BrowserSlot(const char* item)
00289 {
00290    TString slotname;
00291    BrowserSlotName(item, slotname);
00292    return fxOM->GetSlot(slotname.Data());
00293 }
00294 
00295 TGo4Slot* TGo4BrowserProxy::DataSlot(const char* item)
00296 {
00297    TString slotname;
00298    DataSlotName(item, slotname);
00299    return fxOM->GetSlot(slotname.Data());
00300 }
00301 
00302 TGo4Slot* TGo4BrowserProxy::BrowserMemorySlot()
00303 {
00304    return BrowserSlot(fxMemoryPath.Data());
00305 }
00306 
00307 Bool_t TGo4BrowserProxy::BrowserItemName(TGo4Slot* itemslot, TString& res)
00308 {
00309    if ((itemslot==0) || (fxBrowserSlot==0) || !itemslot->IsParent(fxBrowserSlot)) return kFALSE;
00310    itemslot->ProduceFullName(res, fxBrowserSlot);
00311    return kTRUE;
00312 }
00313 
00314 void TGo4BrowserProxy::UpdateBrowserContent()
00315 {
00316    fxBrowserSlot->Update(kFALSE);
00317 
00318    TGo4Iter iter(fxOM->GetSlot(fxDataPath), kTRUE);
00319    while(iter.next()) {
00320       TGo4Slot* subslot = iter.getslot();
00321       TGo4AnalysisProxy* ancont =
00322          dynamic_cast<TGo4AnalysisProxy*>(subslot->GetProxy());
00323       if (ancont!=0) subslot->Update(kTRUE);
00324    }
00325 }
00326 
00327 Int_t TGo4BrowserProxy::RequestBrowserObject(const char* name, Int_t wait_time)
00328 {
00329    if ((name==0) || (fxBrowserSlot==0) || (fxOM==0)) return 0;
00330 
00331    Int_t kind = ItemKind(name);
00332    if (kind==TGo4Access::kndObject) {
00333       TClass* cl = ItemClass(name);
00334       if ((cl==0) || !cl->IsLoaded()) return 0;
00335    }
00336 
00337    TString src, tgt;
00338 
00339    DataSlotName(name, src);
00340    BrowserSlotName(name, tgt);
00341 
00342    return fxOM->RequestObject(src.Data(), tgt.Data(), wait_time);
00343 }
00344 
00345 Int_t TGo4BrowserProxy::RequestBrowserObject(TGo4Slot* slot, Int_t wait_time)
00346 {
00347    if ((slot==0) || !slot->IsParent(fxBrowserSlot)) return 0;
00348    TString name;
00349    slot->ProduceFullName(name, fxBrowserSlot);
00350    return RequestBrowserObject(name.Data(), wait_time);
00351 }
00352 
00353 Bool_t TGo4BrowserProxy::ProduceExplicitCopy(const char* itemname, const char* tgtpath, Bool_t forcerequest)
00354 {
00355    return ProduceExplicitCopy(BrowserSlot(itemname), tgtpath, forcerequest);
00356 }
00357 
00358 Bool_t TGo4BrowserProxy::ProduceExplicitCopy(TGo4Slot* itemslot, const char* tgtpath, Bool_t forcerequest)
00359 {
00360    TGo4LockGuard lock;
00361 
00362    if (itemslot==0) return kFALSE;
00363 
00364    // cout << "ProduceExplicitCopy " << itemslot->GetFullName() << "  " << (tgtpath ? tgtpath : "null") << endl;
00365 
00366    TGo4Slot* memslot = BrowserMemorySlot();
00367    if (itemslot->IsParent(memslot) && (tgtpath==0)) return kFALSE;
00368    if (tgtpath!=0) {
00369        TGo4Slot* tgtslot = BrowserSlot(tgtpath);
00370        if (tgtslot==0) return kFALSE;
00371        if ((tgtslot==itemslot) || tgtslot->IsParent(itemslot)) return kFALSE;
00372    }
00373 
00374    if (itemslot->NumChilds()>0) {
00375      Bool_t res = kTRUE;
00376      TObjArray childs;
00377      for (Int_t n=0;n<itemslot->NumChilds();n++)
00378        childs.Add(itemslot->GetChild(n));
00379 
00380      TString subpath;
00381      // create subpath for paste from clipboard folder
00382      if (tgtpath!=0) {
00383         TGo4Slot* tgtslot = DataSlot(tgtpath);
00384         if (tgtslot==0) return kFALSE;
00385         if (tgtslot->GetSlot(itemslot->GetName(), kTRUE)==0) return kFALSE;
00386 
00387         // synchronize folder structures in browser branch
00388         SyncBrowserSlots();
00389 
00390         subpath = tgtpath;
00391         subpath += "/";
00392         subpath += itemslot->GetName();
00393 
00394         tgtpath = subpath.Data();
00395      }
00396 
00397      for (Int_t n=0;n<=childs.GetLast();n++) {
00398         Bool_t res1 = ProduceExplicitCopy((TGo4Slot*)childs.At(n), tgtpath, forcerequest);
00399         res = res || res1;
00400      }
00401 
00402      return res;
00403    }
00404 
00405    if (ItemKind(itemslot)!=TGo4Access::kndObject) return kFALSE;
00406 
00407    TString pathname;
00408    if (tgtpath!=0) {
00409       TGo4Slot* tgtslot = ItemSlot(tgtpath);
00410       if (tgtslot==0) return kFALSE;
00411       if (!tgtslot->IsParent(memslot) && (tgtslot!=memslot)) return kFALSE;
00412       if (itemslot->GetParent()==tgtslot) return kFALSE;
00413       if (memslot!=tgtslot)
00414          tgtslot->ProduceFullName(pathname, memslot);
00415    } else {
00416      if (!BrowserItemName(itemslot->GetParent(), pathname)) return kFALSE;
00417    }
00418 
00419    TObject* obj = itemslot->GetAssignedObject();
00420 
00421    if ((obj==0) || forcerequest) {
00422       Int_t res = RequestBrowserObject(itemslot);
00423       if (res==0) return kFALSE;
00424       obj = 0;
00425       if ((res==1) || !forcerequest)
00426         obj = itemslot->GetAssignedObject();
00427    }
00428 
00429    if (obj!=0) {
00430       TString res = SaveToMemory(pathname, obj->Clone(), kTRUE);
00431       return res.Length()>0;
00432    }
00433 
00434    AddWaitingList(itemslot, tgtpath);
00435 
00436    return kTRUE;
00437 }
00438 
00439 void TGo4BrowserProxy::ClearClipboard()
00440 {
00441    if (fxClipboard!=0) {
00442       fxClipboard->Delete();
00443       delete fxClipboard;
00444       fxClipboard = 0;
00445    }
00446 }
00447 
00448 void TGo4BrowserProxy::AddToClipboard(const char* itemname)
00449 {
00450    if (fxClipboard==0) fxClipboard = new TObjArray;
00451 
00452    if (fxClipboard->FindObject(itemname)) return;
00453 
00454    TGo4Slot* itemslot = BrowserSlot(itemname);
00455    if (itemslot==0) return;
00456 
00457    // check if parent of that item already in clipboard
00458    for (Int_t n=0;n<=fxClipboard->GetLast();n++) {
00459       TNamed* nm = (TNamed*) fxClipboard->At(n);
00460       TGo4Slot* slot = ItemSlot(nm->GetName());
00461       if (slot==0) continue;
00462       if (itemslot->IsParent(slot)) return;
00463    }
00464 
00465    fxClipboard->Add(new TNamed(itemname, "clipbboard item"));
00466 }
00467 
00468 Bool_t TGo4BrowserProxy::IsClipboard()
00469 {
00470    return fxClipboard!=0;
00471 }
00472 
00473 void TGo4BrowserProxy::CopyClipboard(const char* tgtpath, Bool_t forcerequest)
00474 {
00475    if (fxClipboard==0) return;
00476 
00477    for(Int_t n=0;n<=fxClipboard->GetLast();n++) {
00478       TNamed* nm = (TNamed*) fxClipboard->At(n);
00479 
00480 //      cout << "CopyClipboard( " << nm->GetName() << "  to " << tgtpath << endl;
00481       ProduceExplicitCopy(nm->GetName(), tgtpath, forcerequest);
00482    }
00483 }
00484 
00485 void TGo4BrowserProxy::OpenFile(const char* fname)
00486 {
00487    if ((fname==0) || (*fname==0)) return;
00488 
00489    fxOM->AddFile(fxDataPath.Data(), fname);
00490 }
00491 
00492 Bool_t TGo4BrowserProxy::ConnectHServer(const char* servername,
00493                                         Int_t portnumber,
00494                                         const char* basename,
00495                                         const char* userpass,
00496                                         const char* filter)
00497 {
00498    Bool_t res = kFALSE;
00499 
00500    TGo4HServProxy* hserv = new TGo4HServProxy;
00501 
00502    hserv->SetHServConfig(servername,
00503                          portnumber,
00504                          basename,
00505                          userpass,
00506                          filter);
00507 
00508 
00509    if (hserv->RequestHistosList()) {
00510       TString capt = "HServ_";
00511       capt += basename;
00512 
00513       fxOM->AddProxy(fxDataPath.Data(), hserv, capt.Data(), "Connection to histogram server");
00514       res = kTRUE;
00515    } else {
00516       delete hserv;
00517    }
00518    return res;
00519 }
00520 
00521 void TGo4BrowserProxy::MakeFilesList(TObjArray* arr)
00522 {
00523    if (arr==0) return;
00524    arr->Clear();
00525    TGo4Slot* slot = fxOM->GetSlot(fxDataPath.Data());
00526    if (slot==0) return;
00527 
00528    for(Int_t n=0;n<slot->NumChilds();n++) {
00529       TGo4Slot* subslot = slot->GetChild(n);
00530       TGo4DirProxy* pr = dynamic_cast<TGo4DirProxy*> (subslot->GetProxy());
00531       if ((pr!=0) && pr->IsFile())
00532         arr->Add(pr);
00533    }
00534 }
00535 
00536 void TGo4BrowserProxy::MakeHServerList(TObjArray* arr)
00537 {
00538    if (arr==0) return;
00539    arr->Clear();
00540    TGo4Slot* slot = fxOM->GetSlot(fxDataPath.Data());
00541    if (slot==0) return;
00542 
00543    for(Int_t n=0;n<slot->NumChilds();n++) {
00544       TGo4Slot* subslot = slot->GetChild(n);
00545       TGo4HServProxy* pr = dynamic_cast<TGo4HServProxy*> (subslot->GetProxy());
00546       if (pr!=0) arr->Add(pr);
00547    }
00548 }
00549 
00550 void TGo4BrowserProxy::RequestObjectStatus(const char* name, TGo4Slot* tgtslot)
00551 {
00552    TString objname;
00553    TGo4AnalysisProxy* an = DefineAnalysisObject(name, objname);
00554    if (an!=0)
00555      an->RequestObjectStatus(objname.Data(), tgtslot);
00556 }
00557 
00558 void TGo4BrowserProxy::RequestEventStatus(const char* evname,
00559                                           Bool_t astree,
00560                                           TGo4Slot* tgtslot)
00561 {
00562    TString objname;
00563    TGo4AnalysisProxy* an = DefineAnalysisObject(evname, objname);
00564    if (an!=0)
00565      an->RequestEventStatus(objname.Data(), astree, tgtslot);
00566 }
00567 
00568 void TGo4BrowserProxy::PerformTreeDraw(const char* treename,
00569                                        const char* Xexp,
00570                                        const char* Yexp,
00571                                        const char* Zexp,
00572                                        const char* cutcond,
00573                                        const char* hname,
00574                                        TString& createdhistoname)
00575 {
00576    if (strlen(Xexp)==0) return;
00577 
00578    TString varexp(Xexp);
00579 
00580    int drawdim = 1;
00581 
00582    if(strlen(Yexp)==0)
00583       drawdim=1;
00584    else {
00585       varexp=TString(Yexp)+TString(":")+varexp;
00586       if(strlen(Zexp)==0)
00587          drawdim=2;
00588       else {
00589          varexp=TString(Zexp)+TString(":")+varexp;
00590          drawdim=3;
00591       }
00592    }
00593 
00594    if (IsItemRemote(treename)) {
00595       TString objname;
00596       TGo4AnalysisProxy* an = DefineAnalysisObject(treename, objname);
00597       if (an!=0) {
00598          TString analhname(hname);
00599 
00600          Int_t cnt = 0;
00601          TString anitem = "abcdef";
00602          if (analhname.Length()==0)
00603            while (anitem.Length()>0) {
00604               analhname = "hTreeDraw";
00605               if (cnt>0) { analhname+="_"; analhname+=cnt; }
00606               cnt++;
00607               anitem = FindItemInAnalysis(analhname.Data());
00608            }
00609 
00610          an->RemoteTreeDraw(objname.Data(), varexp.Data(), cutcond, analhname.Data());
00611          an->DelayedRefreshNamesList(3);
00612       }
00613 
00614       createdhistoname = "";
00615 
00616       return;
00617    }
00618 
00619    // take tree directly from data browser while
00620    // tree pointer is not stored in browser slots
00621    TString treeslotname;
00622    DataSlotName(treename, treeslotname);
00623    TTree* SelectedTree = dynamic_cast<TTree*> (fxOM->GetObject(treeslotname.Data()));
00624    if (SelectedTree==0) return;
00625 
00626    TString histoname(hname), hslotname;
00627    BrowserSlotName(hname, hslotname);
00628    TGo4Slot* hslot = fxOM->GetSlot(hslotname.Data());
00629 
00630    TH1* histo = 0;
00631 
00632    if ((hslot!=0) && !IsItemRemote(hslot)) {
00633        histo = dynamic_cast<TH1*> (GetBrowserObject(hname, 1));
00634        if ((histo!=0) && (drawdim!=histo->GetDimension())) histo = 0;
00635    }
00636 
00637    // find non used entry in memoty subfolder
00638    int cnt = 0;
00639    if ((histo==0) && (histoname.Length()==0))
00640      do {
00641        histoname = fxMemoryPath;
00642        histoname += "/hTreeDraw_";
00643        histoname += cnt++;
00644        BrowserSlotName( + histoname, hslotname);
00645        hslot = fxOM->GetSlot(hslotname.Data());
00646      } while (hslot!=0);
00647 
00648    TString hfoldername, hobjectname;
00649    TGo4Slot::ProduceFolderAndName(histoname.Data(), hfoldername, hobjectname);
00650 
00651    if (histo!=0)
00652      hobjectname  = histo->GetName();
00653 
00654    varexp += ">>+";
00655    varexp += hobjectname;
00656 
00657    TDirectory* oldhisdir = histo ? histo->GetDirectory() : 0;
00658    TDirectory* savdir = gDirectory;
00659    gDirectory = 0;
00660    TDirectory dummydir("DummyTreeDraw","Dummy directory to call tree draw");
00661    dummydir.cd();
00662    if (histo!=0)
00663       histo->SetDirectory(&dummydir);
00664 
00665    SelectedTree->Draw(varexp, cutcond, "goff", 10000000, 0);
00666 
00667    if (histo==0) { // when new histogram created by Tree::Draw
00668       histo = dynamic_cast<TH1*> (dummydir.FindObject(hobjectname));
00669       if(histo!=0) {
00670          histo->SetDirectory(0);
00671          createdhistoname = SaveToMemory(0, histo, kTRUE);
00672          // do sync immediately to be able draw this item in viewpanel
00673          SyncBrowserSlots();
00674       }
00675    } else {
00676        histo->SetDirectory(oldhisdir);
00677        TGo4Slot* brslot = BrowserSlot(hname);
00678        if (brslot!=0) brslot->ForwardEvent(brslot, TGo4Slot::evObjUpdated);
00679    }
00680    dummydir.Clear();
00681    savdir->cd();
00682 
00683    #if ROOT_VERSION_CODE < ROOT_VERSION(5,13,1)
00684 
00685    // this replace fgCurrent member in TVirtualTreePlayer,
00686    // problem was fixed starting from ROOT version 5.13/01
00687    if (fDummyTreePlayer!=0) delete fDummyTreePlayer;
00688    fDummyTreePlayer =  TVirtualTreePlayer::TreePlayer(0);
00689 
00690    #endif
00691 }
00692 
00693 TGo4Slot* TGo4BrowserProxy::FindAnalysisSlot(Bool_t databranch)
00694 {
00695     TGo4Slot* dataslot = fxOM->GetSlot(fxDataPath.Data());
00696 
00697     TGo4Iter iter(dataslot, kTRUE);
00698     TGo4Slot* res = 0;
00699 
00700     while (iter.next()) {
00701        TGo4AnalysisProxy* cont = dynamic_cast<TGo4AnalysisProxy*>
00702          (iter.getslot()->GetProxy());
00703        if (cont!=0) {
00704           res = iter.getslot();
00705           break;
00706        }
00707     }
00708 
00709     if ((res!=0) && !databranch) {
00710        TString itemname;
00711        res->ProduceFullName(itemname, dataslot);
00712        res = BrowserSlot(itemname.Data());
00713     }
00714 
00715     return res;
00716 }
00717 
00718 TGo4AnalysisProxy* TGo4BrowserProxy::FindAnalysis(const char* itemname)
00719 {
00720    TString slotname;
00721    DataSlotName(itemname, slotname);
00722 
00723    TGo4Slot* slot = fxOM->FindSlot(slotname.Data());
00724    if ((slot==0) || (itemname==0))
00725      slot = FindAnalysisSlot(kTRUE);
00726 
00727    return slot==0 ? 0 : dynamic_cast<TGo4AnalysisProxy*>(slot->GetProxy());
00728 }
00729 
00730 TString TGo4BrowserProxy::FindItemInAnalysis(const char* objname)
00731 {
00732    TGo4Slot* analslot = FindAnalysisSlot(kTRUE);
00733    if ((analslot==0) || (objname==0)) return TString("");
00734 
00735    TGo4Iter iter(analslot);
00736    while (iter.next()) {
00737       if (strcmp(iter.getname(), objname)!=0) continue;
00738       TString res;
00739       analslot->ProduceFullName(res, DataSlot(""));
00740       res+="/";
00741       res+=iter.getfullname();
00742       return res;
00743    }
00744 
00745    return TString("");
00746 }
00747 
00748 TString TGo4BrowserProxy::FindItem(const char* objname)
00749 {
00750    TGo4Slot* topslot = BrowserTopSlot();
00751    if ((topslot==0) || (objname==0)) return TString("");
00752 
00753    TGo4Iter iter(topslot);
00754    while (iter.next())
00755       if (strcmp(iter.getname(), objname)==0)
00756          return iter.getfullname();
00757 
00758    return TString("");
00759 }
00760 
00761 TGo4AnalysisProxy* TGo4BrowserProxy::DefineAnalysisObject(const char* itemname, TString& analysisname)
00762 {
00763    TString slotname;
00764    DataSlotName(itemname, slotname);
00765    const char* objectname = 0;
00766 
00767    TGo4Slot* anslot = fxOM->FindSlot(slotname.Data(), &objectname);
00768 
00769    TGo4AnalysisProxy* an = anslot==0 ? 0 :
00770      dynamic_cast<TGo4AnalysisProxy*>(anslot->GetProxy());
00771    if (an!=0)
00772      analysisname = objectname;
00773    return an;
00774 }
00775 
00776 TGo4HServProxy* TGo4BrowserProxy::DefineHServerProxy(const char* itemname)
00777 {
00778    TGo4Slot* slot = DataSlot(itemname);
00779    if (slot==0) return 0;
00780 
00781    while (slot!=0) {
00782       TGo4HServProxy* pr = dynamic_cast<TGo4HServProxy*> (slot->GetProxy());
00783       if (pr!=0) return pr;
00784       slot = slot->GetParent();
00785    }
00786 
00787    return 0;
00788 }
00789 
00790 Bool_t TGo4BrowserProxy::UpdateAnalysisItem(const char* itemname, TObject* obj)
00791 {
00792    TGo4Slot* slot = BrowserSlot(itemname);
00793    if (slot==0) return kFALSE;
00794 
00795    if (obj==0) obj = GetBrowserObject(itemname, 0);
00796    if (obj==0) return kFALSE;
00797 
00798    const char* analysisname = 0;
00799    TGo4Slot* anslot = 0;
00800    TString slotname;
00801 
00802    if (IsItemRemote(itemname)) {
00803       DataSlotName(itemname, slotname);
00804       anslot = fxOM->FindSlot(slotname.Data(), &analysisname);
00805    }
00806 
00807    if (anslot==0) {
00808       analysisname = 0;
00809       anslot = FindAnalysisSlot(kTRUE);
00810    }
00811 
00812    if (anslot==0) return kFALSE;
00813 
00814    TGo4AnalysisProxy* an =
00815      dynamic_cast<TGo4AnalysisProxy*>(anslot->GetProxy());
00816 
00817    return an==0 ? kFALSE : an->UpdateAnalysisObject(analysisname, obj);
00818 }
00819 
00820 
00821 void TGo4BrowserProxy::FetchItem(const char* itemname, Int_t wait_time)
00822 {
00823    TGo4Slot* itemslot = ItemSlot(itemname);
00824    if (itemslot==0) return;
00825 
00826    if (ItemKind(itemslot)==TGo4Access::kndObject)
00827       RequestBrowserObject(itemslot, wait_time);
00828 
00829    TGo4Iter iter(itemslot, kTRUE);
00830    while (iter.next()) {
00831       TGo4Slot* subslot = iter.getslot();
00832       if (ItemKind(subslot)==TGo4Access::kndObject)
00833          RequestBrowserObject(subslot, wait_time);
00834    }
00835 
00836    if (wait_time==0) return;
00837 }
00838 
00839 void TGo4BrowserProxy::RedrawItem(const char* itemname)
00840 {
00841    TGo4Slot* slot = BrowserSlot(itemname);
00842    if (slot!=0) {
00843       slot->ForwardEvent(slot, TGo4Slot::evObjUpdated);
00844       SetItemTimeDate(slot);
00845    }
00846 }
00847 
00848 TObject* TGo4BrowserProxy::GetBrowserObject(const char* name, int update)
00849 // update=0 - without update,
00850 //        1 - request only if obj==0,
00851 //        2 - update of object in any case
00852 //    >=100 - update object in any case and wait for specified time in millisec
00853 {
00854    if ((name==0) || (fxBrowserSlot==0) || (fxOM==0)) return 0;
00855 
00856    TString src, tgt;
00857    BrowserSlotName(name, tgt);
00858    TGo4Slot* guislot = fxOM->GetSlot(tgt.Data());
00859 
00860    if (guislot==0) return 0;
00861 
00862    TObject* obj = guislot->GetAssignedObject();
00863 
00864    if ((update==0) || ((update==1) && (obj!=0))) return obj;
00865 
00866    if (guislot->IsParent(BrowserMemorySlot())) return obj;
00867 
00868    DataSlotName(name, src);
00869 
00870    fxOM->RequestObject(src.Data(), tgt.Data(), (update<10) ? 0 : update);
00871 
00872    return guislot->GetAssignedObject();
00873 }
00874 
00875 void TGo4BrowserProxy::SetItemsFilter(Int_t filter)
00876 {
00877    fiFilterIndex = filter;
00878    InformBrowserUpdate();
00879 }
00880 
00881 void TGo4BrowserProxy::InformBrowserUpdate()
00882 {
00883    if (fxBrowserSlot!=0)
00884      fxBrowserSlot->ForwardEvent(fxBrowserSlot, TGo4Slot::evObjUpdated);
00885 }
00886 
00887 Bool_t TGo4BrowserProxy::DeleteDataSource(TGo4Slot* itemslot)
00888 {
00889    if ((itemslot==0) || (fxBrowserSlot==0) || (fxOM==0)) return kFALSE;
00890 
00891    Int_t cando = ItemCanDo(itemslot);
00892 
00893    Bool_t ismemoryitem = itemslot->IsParent(BrowserMemorySlot());
00894 
00895    if (!ismemoryitem && !CanCloseItem(cando) && !IsCanDelete(itemslot)) return kFALSE;
00896 
00897    if (itemslot->GetPar("::CopyObject")!=0) {
00898       delete itemslot;
00899       InformBrowserUpdate();
00900    } else {
00901       TString name = itemslot->GetFullName(fxBrowserSlot);
00902       TString src;
00903       DataSlotName(name.Data(), src);
00904       fxOM->DeleteSlot(src.Data());
00905    }
00906    return kTRUE;
00907 }
00908 
00909 void TGo4BrowserProxy::DoItemMonitor(TGo4Slot* slot)
00910 {
00911    if ((slot==0) || (!slot->IsParent(fxBrowserSlot))) return;
00912 
00913    slot->Update(kFALSE);
00914 }
00915 
00916 
00917 TGo4Slot* TGo4BrowserProxy::BrowserTopSlot()
00918 {
00919    return fxBrowserSlot;
00920 }
00921 
00922 TGo4Slot* TGo4BrowserProxy::ItemSlot(const char* itemname)
00923 {
00924    TString slotname;
00925    BrowserSlotName(itemname, slotname);
00926    return fxOM->GetSlot(slotname.Data());
00927 }
00928 
00929 
00930 Bool_t TGo4BrowserProxy::DefineTreeName(const char* itemname, TString& treename)
00931 {
00932    TString slotname;
00933    BrowserSlotName(itemname, slotname);
00934    TGo4Slot* slot = fxOM->GetSlot(slotname.Data());
00935    if (slot==0) return kFALSE;
00936 
00937    TGo4Slot* treeslot = slot;
00938    while (treeslot!=0) {
00939       TClass* cl = ItemClass(treeslot);
00940       if ((cl!=0) && (cl->InheritsFrom(TTree::Class()))) break;
00941       treeslot = treeslot->GetParent();
00942    }
00943    if (treeslot==0) return kFALSE;
00944 
00945    treeslot->ProduceFullName(treename, fxBrowserSlot);
00946 
00947    return kTRUE;
00948 }
00949 
00950 Bool_t TGo4BrowserProxy::DefineLeafName(const char* itemname, const char* treename, TString& leafname)
00951 {
00952    if ((itemname==0) || (treename==0)) return kFALSE;
00953 
00954    TString slotname;
00955    BrowserSlotName(itemname, slotname);
00956    TGo4Slot* slot = fxOM->GetSlot(slotname.Data());
00957    if (slot==0) return kFALSE;
00958 
00959    if (ItemKind(slot)!=TGo4Access::kndTreeLeaf) return kFALSE;
00960 
00961    int ilen = strlen(itemname);
00962    int tlen = strlen(treename);
00963    if ((ilen<tlen) || (strncmp(itemname, treename, tlen)!=0)) return kFALSE;
00964 
00965    leafname = slot->GetName();
00966    return kTRUE;
00967 }
00968 
00969 Bool_t TGo4BrowserProxy::DefineRelatedObject(const char* itemname, const char* objname, TString& objectitem)
00970 {
00971    if ((objname==0) || (*objname==0)) return kFALSE;
00972 
00973    if (BrowserSlot(objname)!=0) {
00974       objectitem = objname;
00975       return kTRUE;
00976    }
00977 
00978    TGo4Slot* picslot = BrowserSlot(itemname);
00979 
00980    if (picslot!=0) {
00981       TGo4Slot* searchslot = picslot->GetParent();
00982 
00983       while ((searchslot!=0) && (searchslot!=fxBrowserSlot)) {
00984          TString searchname;
00985          searchslot->ProduceFullName(searchname, fxBrowserSlot);
00986          if (*objname!='/') searchname+="/";
00987          searchname+=objname;
00988 
00989          TString fullname;
00990          BrowserSlotName(searchname.Data(), fullname);
00991 
00992          TGo4Slot* slot = fxOM->GetSlot(searchname.Data());
00993 
00994          if (slot!=0)
00995 //            if (CanDrawItem(ItemCanDo(slot)))
00996             {
00997                objectitem = searchname;
00998                return kTRUE;
00999             }
01000 
01001          searchslot = searchslot->GetParent();
01002       }
01003    }
01004 
01005    if (strchr(objname,'/')!=0) return kFALSE;
01006 
01007    TGo4Slot* searchslot = (picslot == 0) ? fxBrowserSlot : picslot->GetParent();
01008 
01009    do {
01010       TGo4Iter iter(searchslot, kTRUE);
01011       while (iter.next()) {
01012 //         if (iter.isfolder()) continue;
01013          if (strcmp(objname, iter.getname())!=0) continue;
01014          TGo4Slot* subslot = iter.getslot();
01015 //         if (!CanDrawItem(ItemCanDo(subslot))) continue;
01016 
01017          subslot->ProduceFullName(objectitem, fxBrowserSlot);
01018          return kTRUE;
01019       }
01020       if (searchslot==fxBrowserSlot) break;
01021       searchslot = searchslot->GetParent();
01022    } while (searchslot!=0);
01023 
01024    return kFALSE;
01025 }
01026 
01027 Bool_t TGo4BrowserProxy::DefineFileObject(const char* itemname, TString& fitemname, const char* &filepath)
01028 {
01029    TGo4Slot* slot = BrowserSlot(itemname);
01030    if (slot==0) return kFALSE;
01031 
01032    if (slot->GetAssignedObject()==0) return kFALSE;
01033 
01034    while (slot!=fxBrowserSlot) {
01035       TClass* cl = ItemClass(slot);
01036       if ((cl!=0) && (cl->InheritsFrom(TFile::Class()))) break;
01037       slot = slot->GetParent();
01038    }
01039    if (slot==fxBrowserSlot) return kFALSE;
01040 
01041    fitemname = "";
01042    slot->ProduceFullName(fitemname, fxBrowserSlot);
01043 
01044    filepath = itemname + fitemname.Length();
01045    if (*filepath=='/') filepath++;
01046 
01047    //filedataslot = fitemname;
01048    //DataSlotName(fitemname, filedataslot);
01049 
01050    return kTRUE;
01051 }
01052 
01053 Bool_t TGo4BrowserProxy::UpdateObjectInFile(const char* itemname, const char* fileitemname, const char* filepath)
01054 {
01055    TGo4Slot* slot = BrowserSlot(itemname);
01056    if (slot==0) return kFALSE;
01057 
01058    TObject* obj = slot->GetAssignedObject();
01059    if (obj==0) return kFALSE;
01060 
01061    TGo4Slot* fileslot = DataSlot(fileitemname);
01062    if (fileslot==0) return kFALSE;
01063 
01064    TGo4DirProxy* dircont = dynamic_cast<TGo4DirProxy*> (fileslot->GetProxy());
01065    if (dircont==0) return kFALSE;
01066 
01067    Bool_t res = dircont->UpdateObjectInFile(filepath, obj);
01068 
01069    if(res)
01070      fileslot->ForwardEvent(fileslot, TGo4Slot::evObjUpdated);
01071 
01072    return res;
01073 }
01074 
01075 Bool_t TGo4BrowserProxy::SaveItemToFile(const char* itemname, const char* filename, const char* subfolder)
01076 {
01077    TGo4Slot* slot = BrowserSlot(itemname);
01078    if (slot==0) return kFALSE;
01079 
01080    TObject* obj = slot->GetAssignedObject();
01081    if (obj==0) return kFALSE;
01082 
01083    TFile* f = TFile::Open(filename,"UPDATE");
01084    if (f==0) return kFALSE;
01085 
01086    TDirectory* dir = f;
01087 
01088    if ((subfolder!=0) && (*subfolder!=0)) {
01089       dir = dynamic_cast<TDirectory*> (f->Get(subfolder));
01090       if (dir==0) dir = f;
01091    }
01092 
01093    dir->cd();
01094    bool res = dir->WriteTObject(obj, obj->GetName(), "Overwrite") > 0;
01095 
01096    if (obj->InheritsFrom(TH1::Class()))
01097      ((TH1*) obj)->SetDirectory(0);
01098 
01099    delete f;
01100 
01101    return res;
01102 }
01103 
01104 void TGo4BrowserProxy::ExportItemsTo(TObjArray* items,  // array of TObjString
01105                                      Bool_t fetchitems,
01106                                      const char* filename,
01107                                      const char* filedir,
01108                                      const char* format,
01109                                      const char* description)
01110 {
01111    if ((items==0) || (items->GetSize()==0)) return;
01112 
01113    TString convert;
01114    if(format==0)
01115       convert="ROOT";
01116    else
01117       convert=format;
01118 
01119    Go4Export_t filter;
01120    if(convert.Contains("ASCII")) {
01121       TGo4Log::Message(0,"Export filter is ASCII");
01122       filter=GO4EX_ASCII;
01123    } else
01124    if (convert.Contains("Radware")) {
01125       TGo4Log::Message(0,"Export filter is Radware");
01126       filter=GO4EX_RADWARE;
01127    } else
01128    if (convert.Contains("ROOT XML")) {
01129       TGo4Log::Message(0,"Export filter is ROOT XML");
01130       filter=GO4EX_XML;
01131    } else
01132    if (convert.Contains("ROOT")) {
01133       TGo4Log::Message(0,"Export filter is ROOT");
01134       filter=GO4EX_ROOT;
01135    } else {
01136       TGo4Log::Message(0,"Export filter is unknown, using ROOT");
01137       filter=GO4EX_ROOT;
01138    }
01139 
01140    // if root export filter and 1 subfolder, export with complete file structures
01141    if (((filter==GO4EX_ROOT) || (filter==GO4EX_XML)) && (items->GetLast()==0)) {
01142       TObjString* str = dynamic_cast<TObjString*> (items->At(0));
01143 
01144       TGo4Slot* itemslot = (str==0) ? 0 : ItemSlot(str->GetName());
01145 
01146       TString fname = filename;
01147 
01148       if (filter==GO4EX_XML) {
01149          if(!fname.Contains(".xml")) fname.Append(".xml");
01150       } else {
01151          if(!fname.Contains(".root")) fname.Append(".root");
01152       }
01153 
01154       if ((itemslot!=0) && (itemslot->NumChilds()>0)) {
01155          SaveBrowserToFile(fname.Data(), fetchitems, str->GetName(), description);
01156          return;
01157       }
01158    }
01159 
01160    TGo4ExportManager exman("BrowserExport");
01161    exman.SetOutFile(filename);
01162    exman.SetOutFileComment(description);
01163    exman.SetStartDir();
01164    exman.SetCurrentDir(filedir);
01165 
01166    TGo4Log::Message(1,"Exporting selected browser objects to %s",convert.Data());
01167 
01168    TObjArray objs;
01169    for (int n=0;n<=items->GetLast();n++) {
01170       TObjString* str = dynamic_cast<TObjString*> (items->At(n));
01171       if (str==0) continue;
01172       TObject* obj = GetBrowserObject(str->GetName(), 0);
01173       if (obj==0)
01174         obj = GetBrowserObject(str->GetName(), 2000);
01175 
01176       if (obj!=0) objs.Add(obj);
01177    }
01178 
01179    exman.Export(&objs, filter);
01180 }
01181 
01182 Bool_t TGo4BrowserProxy::SaveBrowserToFile(const char* filename,
01183                                            Bool_t prefetch,
01184                                            const char* selectedpath,
01185                                            const char* description)
01186 {
01187    TGo4Slot* toppath = BrowserSlot(selectedpath);
01188 
01189    if (toppath==0) return kFALSE;
01190 
01191    if (prefetch)
01192       FetchItem(selectedpath, 2000);
01193 
01194    TFile* f = TFile::Open(filename, "recreate", description);
01195    if (f==0) return kFALSE;
01196 
01197    fxOM->SaveDataToFile(f, kTRUE, toppath);
01198 
01199    delete f;
01200 
01201    return kTRUE;
01202 }
01203 
01204 Bool_t TGo4BrowserProxy::IsItemRemote(const char* name)
01205 {
01206    return IsItemRemote(ItemSlot(name));
01207 }
01208 
01209 Bool_t TGo4BrowserProxy::IsItemRemote(TGo4Slot* slot)
01210 {
01211    if (slot==0) return kFALSE;
01212    Int_t remote;
01213    if (!slot->GetIntPar("GUI::Remote", remote)) return kFALSE;
01214    return remote!=0;
01215 }
01216 
01217 Bool_t TGo4BrowserProxy::IsAnalysisItem(const char* name)
01218 {
01219    TString analysisname;
01220    return DefineAnalysisObject(name, analysisname)!=0;
01221 }
01222 
01223 
01224 void TGo4BrowserProxy::SetItemTimeDate(TGo4Slot* slot, const char* stime, const char* sdate)
01225 {
01226    if ((stime!=0) && (sdate!=0)) {
01227      slot->SetPar("GUI::Time", stime);
01228      slot->SetPar("GUI::Date", sdate);
01229      return;
01230    }
01231 
01232    TDatime t;
01233    const char* datetime = t.AsSQLString();
01234    char* time = (char*) strchr(datetime, ' ');
01235    if (time==0) {
01236      slot->SetPar("GUI::Time",datetime);
01237      slot->SetPar("GUI::Date",datetime);
01238    } else {
01239      slot->SetPar("GUI::Time", time+1);
01240      *time = 0;
01241      slot->SetPar("GUI::Date", datetime);
01242    }
01243 }
01244 
01245 const char* TGo4BrowserProxy::ItemTime(TGo4Slot* slot)
01246 {
01247    return slot==0 ? 0 : slot->GetPar("GUI::Time");
01248 }
01249 
01250 const char* TGo4BrowserProxy::ItemDate(TGo4Slot* slot)
01251 {
01252    return slot==0 ? 0 : slot->GetPar("GUI::Date");
01253 }
01254 
01255 void TGo4BrowserProxy::SetLinkedName(TGo4Slot* slot, const char* itemname)
01256 {
01257    if (slot!=0)
01258      slot->SetPar("::LinkedItem", itemname);
01259 }
01260 
01261 const char* TGo4BrowserProxy::GetLinkedName(TGo4Slot* slot)
01262 {
01263    return (slot==0) ? 0 : slot->GetPar("::LinkedItem");
01264 }
01265 
01266 Int_t TGo4BrowserProxy::ItemKind(const char* name)
01267 {
01268    return ItemKind(ItemSlot(name));
01269 }
01270 
01271 Int_t TGo4BrowserProxy::ItemKind(TGo4Slot* slot)
01272 {
01273    if (slot==0) return TGo4Access::kndNone;
01274    Int_t kind;
01275    if (!slot->GetIntPar("GUI::Kind", kind)) return TGo4Access::kndNone;
01276    return kind;
01277 }
01278 
01279 void TGo4BrowserProxy::SetItemKind(TGo4Slot* slot, Int_t kind, const char* classname, const char* info, Int_t sizeinfo)
01280 {
01281    if (slot==0) return;
01282    if (kind>=0) slot->SetIntPar("GUI::Kind", kind);
01283            else slot->RemovePar("GUI::Kind");
01284    slot->SetPar("GUI::Class", classname);
01285    slot->SetPar("GUI::Info", info);
01286    slot->SetIntPar("GUI::SizeInfo", sizeinfo);
01287 }
01288 
01289 const char* TGo4BrowserProxy::ItemInfo(TGo4Slot* slot)
01290 {
01291    return slot==0 ? 0 : slot->GetPar("GUI::Info");
01292 }
01293 
01294 Int_t TGo4BrowserProxy::ItemSizeInfo(TGo4Slot* slot)
01295 {
01296    if (slot==0) return -1;
01297    Int_t sizeinfo;
01298    if (!slot->GetIntPar("GUI::SizeInfo", sizeinfo)) return -1;
01299    return sizeinfo;
01300 }
01301 
01302 void TGo4BrowserProxy::SetCalcSize(TGo4Slot* slot, Int_t size)
01303 {
01304    if (slot!=0)
01305      slot->SetIntPar("GUI::CalcSize", size);
01306 }
01307 
01308 Int_t TGo4BrowserProxy::GetCalcSize(TGo4Slot* slot)
01309 {
01310    if (slot==0) return 0;
01311    Int_t size;
01312    if (!slot->GetIntPar("GUI::CalcSize", size)) return 0;
01313    return size;
01314 }
01315 
01316 TClass* TGo4BrowserProxy::ItemClass(TGo4Slot* slot)
01317 {
01318    const char* classname = ItemClassName(slot);
01319 
01320    return classname==0 ? 0 : gROOT->GetClass(classname); //(TClass*) gROOT->GetListOfClasses()->FindObject(classname);
01321 }
01322 
01323 
01324 TClass* TGo4BrowserProxy::ItemClass(const char* name)
01325 {
01326    return ItemClass(ItemSlot(name));
01327 }
01328 
01329 const char* TGo4BrowserProxy::ItemClassName(TGo4Slot* slot)
01330 {
01331    return slot==0 ? 0 : slot->GetPar("GUI::Class");
01332 }
01333 
01334 const char* TGo4BrowserProxy::ItemClassName(const char* name)
01335 {
01336    return ItemClassName(ItemSlot(name));
01337 }
01338 
01339 Int_t TGo4BrowserProxy::ItemCanDo(const char* name)
01340 {
01341    return ItemCanDo(ItemSlot(name));
01342 }
01343 
01344 Int_t TGo4BrowserProxy::ItemCanDo(TGo4Slot* slot)
01345 {
01346    if (slot==0) return 0;
01347 
01348    Int_t cando;
01349    if (!slot->GetIntPar("GUI::CanDo", cando)) return 0;
01350    return cando;
01351 }
01352 
01353 void TGo4BrowserProxy::SetItemCanDo(TGo4Slot* slot, Int_t cando)
01354 {
01355    if (slot!=0) slot->SetIntPar("GUI::CanDo", cando);
01356 }
01357 
01358 Bool_t TGo4BrowserProxy::IsItemMonitored(TGo4Slot* slot)
01359 {
01360    return slot==0 ? kFALSE : slot->GetPar("GUI::Monitored")!=0;
01361 }
01362 
01363 void TGo4BrowserProxy::SetItemMonitored(TGo4Slot* slot, Bool_t on)
01364 {
01365    if (slot==0) return;
01366 
01367    if (ItemKind(slot)==TGo4Access::kndFolder) {
01368       TGo4Iter iter(slot, kTRUE);
01369       while (iter.next()) {
01370          TGo4Slot* subslot = iter.getslot();
01371          if (ItemKind(subslot)==TGo4Access::kndObject)
01372              SetItemMonitored(subslot, on);
01373       }
01374    } else {
01375       if (on) {
01376          slot->SetPar("GUI::Monitored","1");
01377          CheckPictureMonitor(slot);
01378       } else
01379          slot->RemovePar("GUI::Monitored");
01380    }
01381 }
01382 
01383 bool TGo4BrowserProxy::CanExportItem(int cando)
01384 {
01385    return (cando % 10000000) / 1000000 > 0;
01386 }
01387 
01388 bool TGo4BrowserProxy::CanInfoItem(int cando)
01389 {
01390    return (cando % 1000000) / 100000 > 0;
01391 }
01392 
01393 
01394 bool TGo4BrowserProxy::CanCloseItem(int cando)
01395 {
01396    return (cando % 100000) / 10000 > 0;
01397 }
01398 
01399 bool TGo4BrowserProxy::CanClearItem(int cando)
01400 {
01401    return (cando % 10000) / 1000 > 0;
01402 }
01403 
01404 bool TGo4BrowserProxy::CanDrawItem(int cando)
01405 {
01406    return (cando % 1000) / 100 > 0;
01407 }
01408 
01409 bool TGo4BrowserProxy::CanDragItem(int cando)
01410 {
01411    return (cando % 100) / 10 > 0;
01412 }
01413 
01414 bool TGo4BrowserProxy::CanEditItem(int cando)
01415 {
01416    return (cando % 10 > 0);
01417 }
01418 
01419 void TGo4BrowserProxy::CreateMemoryFolder(const char* foldername)
01420 {
01421    if ((foldername!=0) && (*foldername!=0))
01422      fxMemoryPath = foldername;
01423 
01424    TString fullpathname;
01425    DataSlotName(fxMemoryPath, fullpathname);
01426 
01427    fxOM->MakeFolder(fullpathname);
01428 }
01429 
01430 void TGo4BrowserProxy::CreateMemorySubfolder(const char* itemname, const char* newfoldername)
01431 {
01432     TGo4Slot* itemslot = BrowserSlot(itemname);
01433 
01434     if ((itemslot==0) || (newfoldername==0) || (strlen(newfoldername)==0)) return;
01435 
01436     TGo4Slot* memslot = BrowserMemorySlot();
01437     if (!itemslot->IsParent(memslot) && (memslot!=itemslot)) return;
01438 
01439     TGo4Slot* slot = DataSlot(itemname);
01440     if (slot==0) return;
01441 
01442     TGo4Slot* newslot = slot->GetSlot(newfoldername, kTRUE);
01443 
01444     if (newslot!=0)
01445        InformBrowserUpdate();
01446 }
01447 
01448 void TGo4BrowserProxy::RenameMemoryItem(const char* itemname, const char* newname)
01449 {
01450    TGo4Slot* itemslot = BrowserSlot(itemname);
01451    if ((itemslot==0) || (newname==0) || (strlen(newname)==0)) return;
01452 
01453    if ((strchr(newname,'/')!=0) || (strchr(newname,'\\')!=0)) return;
01454 
01455    TGo4Slot* memslot = BrowserMemorySlot();
01456    if (!itemslot->IsParent(memslot)) return;
01457 
01458    TGo4Slot* slot = DataSlot(itemname);
01459    if (slot==0) return;
01460 
01461    // check if item of that name is already existing
01462    if (slot->GetParent()->FindChild(newname)!=0) return;
01463 
01464    slot->SetName(newname);
01465    TNamed* n = dynamic_cast<TNamed*> (slot->GetAssignedObject());
01466    if (n!=0) n->SetName(newname);
01467 
01468    slot->ForwardEvent(slot, TGo4Slot::evObjAssigned);
01469 }
01470 
01471 TString TGo4BrowserProxy::SaveToMemory(const char* pathname, TObject* obj, Bool_t ownership, Bool_t overwrite)
01472 {
01473    if (obj==0) return TString("");
01474 
01475    TString path = fxMemoryPath;
01476    if ((pathname!=0) && (*pathname!=0)) {
01477       path += "/";
01478       path += pathname;
01479    }
01480 
01481    // if overwrite, check if slot of that name exists
01482    if (overwrite) {
01483        TString itemname = path;
01484        itemname+= "/";
01485        itemname+=obj->GetName();
01486        TGo4Slot* slot = DataSlot(itemname);
01487        if (slot!=0) {
01488           slot->AssignObject(obj, ownership);
01489           return itemname;
01490        }
01491    }
01492 
01493    TString fullpathname;
01494    DataSlotName(path.Data(), fullpathname);
01495 
01496    TGo4Slot* slot = fxOM->Add(fullpathname.Data(), obj, ownership, kTRUE);
01497 
01498    return slot==0 ? TString("") : slot->GetFullName(fxOM->GetSlot(fxDataPath));
01499 }
01500 
01501 void TGo4BrowserProxy::CheckPictureMonitor(TGo4Slot* slot)
01502 {
01503    if (slot==0) return;
01504 
01505    TObject* obj = slot->GetAssignedObject();
01506    if (obj==0) return;
01507 
01508    TGo4Picture* pic = dynamic_cast<TGo4Picture*> (obj);
01509    if (pic==0) return;
01510 
01511    if (!IsItemMonitored(slot)) return;
01512 
01513    TString picitemname;
01514    if (!BrowserItemName(slot, picitemname)) return;
01515 
01516    CheckPictureMonitor(pic, picitemname.Data());
01517 }
01518 
01519 void TGo4BrowserProxy::CheckPictureMonitor(TGo4Picture* pic, const char* picitemname)
01520 {
01521    if (pic==0) return;
01522    if (pic->IsDivided())
01523       for(Int_t posy=0; posy<pic->GetDivY(); posy++)
01524          for(Int_t posx=0; posx<pic->GetDivX(); posx++)
01525             CheckPictureMonitor(pic->FindPic(posy,posx), picitemname);
01526 
01527    for (Int_t n=0; n<pic->GetNumObjNames(); n++) {
01528 
01529       TString drawname;
01530 
01531       if (DefineRelatedObject(picitemname, pic->GetObjName(n), drawname))
01532          SetItemMonitored(BrowserSlot(drawname), kTRUE);
01533    }
01534 }
01535 
01536 void TGo4BrowserProxy::Scan_gROOT()
01537 {
01538    TIter iter(gROOT->GetList());
01539    TObject* obj = 0;
01540    while ((obj=iter())!=0) {
01541       SaveToMemory("gROOT", obj, kTRUE);
01542    }
01543 
01544    gROOT->GetList()->Clear();
01545 }
01546 
01547 void TGo4BrowserProxy::SetCanDelete(TGo4Slot* slot, Bool_t on)
01548 {
01549    if (slot!=0){
01550      if(on) slot->SetPar("GUI::CanDelete","1");
01551        else slot->RemovePar("GUI::CanDelete");
01552    }
01553 }
01554 
01555 Bool_t TGo4BrowserProxy::IsCanDelete(TGo4Slot* slot)
01556 {
01557    return slot==0 ? kFALSE : slot->GetPar("GUI::CanDelete")!=0;
01558 }
01559 
01560 void TGo4BrowserProxy::ToggleMonitoring(Int_t rate)
01561 {
01562    fiMonitoringPeriod = rate;
01563 
01564    fbBlockMonitoring = kFALSE;
01565 
01566    if (fiMonitoringPeriod>0) {
01567       if (fxMonitorTimer==0)
01568          fxMonitorTimer = new TTimer(this, 10, kTRUE);
01569       fxMonitorTimer->Start(10, kTRUE);
01570    } else {
01571       if (fxMonitorTimer!=0) fxMonitorTimer->Reset();
01572       delete fxMonitorTimer;
01573       fxMonitorTimer = 0;
01574    }
01575 
01576    InformBrowserUpdate();
01577 }
01578 
01579 Int_t TGo4BrowserProxy::UpdateVisibleAnalysisObjects(bool checkmonitor)
01580 {
01581    TGo4Slot* viewslot = fxOM->GetSlot(fxViewPath.Data());
01582    if (viewslot==0) return 0;
01583 
01584    TGo4Slot* brslot = BrowserSlot(0);
01585 
01586    TObjArray UniqueItems;
01587 
01588    // first produce list of slots without duplication
01589    TGo4Iter iter(viewslot, kTRUE);
01590    while (iter.next()) {
01591       TGo4Slot* subslot = iter.getslot();
01592 
01593       TGo4LinkProxy* link = dynamic_cast<TGo4LinkProxy*> (subslot->GetProxy());
01594       if (link!=0) {
01595          TGo4Slot* srcslot = link->GetLink();
01596          if ((srcslot!=0) && srcslot->IsParent(brslot) &&
01597              (UniqueItems.FindObject(srcslot)==0))
01598            UniqueItems.Add(srcslot);
01599       }
01600    }
01601 
01602    Int_t nrequests = 0;
01603    for (int n=0;n<=UniqueItems.GetLast();n++) {
01604       TGo4Slot* srcslot = (TGo4Slot*)UniqueItems.At(n);
01605       if (!checkmonitor || IsItemMonitored(srcslot)) {
01606          nrequests++;
01607          srcslot->Update(kFALSE);
01608       }
01609    }
01610    return nrequests;
01611 }
01612 
01613 Int_t TGo4BrowserProxy::UpdateAllMonitoredObjects()
01614 {
01615    Int_t nrequests = 0;
01616 
01617    TGo4Iter iter(BrowserSlot(0),kTRUE);
01618 
01619    while (iter.next()) {
01620       TGo4Slot* subslot = iter.getslot();
01621       if (IsItemMonitored(subslot)) {
01622          nrequests++;
01623          subslot->Update(kTRUE);
01624       }
01625    }
01626 
01627    return nrequests;
01628 }
01629 
01630 Bool_t TGo4BrowserProxy::HandleTimer(TTimer* timer)
01631 {
01632    if (timer==fxSyncTimer) {
01633       SyncBrowserSlots();
01634       return kTRUE;
01635 
01636    } else
01637 
01638    if (timer==fxMonitorTimer) {
01639 
01640       if (fiMonitoringPeriod<=0) return kTRUE;
01641 
01642       TGo4AnalysisProxy* an = FindAnalysis();
01643 
01644       Bool_t anready = kTRUE;
01645       if (an!=0) anready = an->IsConnected();
01646 
01647       // request new objects if total number of proxyes is not too big
01648       if (anready && (TGo4AnalysisProxy::NumberOfWaitingProxyes()<3) && !fbBlockMonitoring) {
01649          if (fbWithRootBrowser) {
01650             UpdateAllMonitoredObjects();
01651             UpdateAllCanvases();
01652          }
01653          else
01654             UpdateVisibleAnalysisObjects(true);
01655       }
01656 
01657       Int_t period = fiMonitoringPeriod;
01658 
01659       // if monitoring is blocked (no request for objects update are called), check again quickly
01660       if (fbBlockMonitoring) period = 1000;
01661 
01662       fxMonitorTimer->Start(period, kTRUE);
01663 
01664       return kTRUE;
01665    }
01666 
01667    return kFALSE;
01668 }
01669 
01670 void TGo4BrowserProxy::SetProtectionBits(TGo4Slot* slot, Int_t delprot, Int_t clearprot)
01671 {
01672    if (slot==0) return;
01673    if (delprot>=0)
01674       slot->SetIntPar("GUI::DeleteProtect", delprot);
01675    else
01676       slot->RemovePar("GUI::DeleteProtect");
01677    if (clearprot>=0)
01678       slot->SetIntPar("GUI::ResetProtect", clearprot);
01679    else
01680       slot->RemovePar("GUI::ResetProtect");
01681 }
01682 
01683 void TGo4BrowserProxy::GetProtectionBits(TGo4Slot* slot, Int_t& delprot, Int_t& clearprot)
01684 {
01685    delprot = -1; clearprot = -1;
01686    if (slot==0) return;
01687    if (!slot->GetIntPar("GUI::DeleteProtect", delprot)) delprot = -1;
01688    if (!slot->GetIntPar("GUI::ResetProtect", clearprot)) clearprot = -1;
01689 }
01690 
01691 void TGo4BrowserProxy::SyncBrowserSlots()
01692 {
01693    TGo4LockGuard lock;
01694 
01695    TGo4Slot* targetslot = BrowserTopSlot();
01696 
01697    TGo4Slot* source = fxOM->GetSlot(fxDataPath.Data());
01698    if (source==0) return;
01699 
01700    TGo4Slot* curfold = targetslot;
01701    if (curfold==0) return;
01702 
01703    TGo4Slot* curslot = curfold->GetChild(0);
01704 
01705    TGo4Iter iter(source);
01706 
01707    const char* EventsFolder = "EventObjects/Events/";
01708 
01709    while (curfold!=0) {
01710 
01711       // shift to next item in iterator
01712       Bool_t res = iter.next();
01713 
01714       // go to top folders and remove rest items
01715       Int_t levelchange = iter.levelchange();
01716 //      cout << "    " << iter.getname() << " levelchange = " << levelchange << endl;
01717 
01718       while (levelchange++<0) {
01719           while (curslot!=0) {
01720              TGo4Slot* next = curslot->GetNext();
01721              delete curslot;
01722              curslot = next;
01723           }
01724 
01725           curslot = curfold->GetNext();
01726           curfold = curfold->GetParent();
01727           if (curfold==0) break;
01728 //          cout << "cd .. ; folder = " << curfold->GetName() << endl;
01729       }
01730 
01731       if (!res) break;
01732 
01733 
01734       TGo4Slot* find = curslot;
01735       while ((find!=0) && (strcmp(iter.getname(), find->GetName())!=0))
01736         find = find->GetNext();
01737 
01738       if (find==0)
01739          find = new TGo4Slot(curfold, iter.getname(), iter.getinfo());
01740 
01741       if (find!=curslot) {
01742          curfold->ShiftSlotBefore(find, curslot);
01743          curslot = find;
01744       }
01745 
01746       Int_t kind = iter.getkindofitem();
01747       const char* classname = iter.getclassname();
01748       const char* fullname = iter.getfullname();
01749       const char* ppp = strstr(fullname, EventsFolder);
01750       if (ppp!=0) {
01751           ppp += strlen(EventsFolder);
01752           if ((strlen(ppp)!=0) && (strchr(ppp,'/')==0)) {
01753              kind = TGo4Access::kndEventElement;
01754              classname = 0;
01755           }
01756       }
01757 
01758 //      cout << curslot->GetFullName() << "   - " << iter.getinfo() << endl;
01759 
01760       SetItemKind(curslot, kind, classname, iter.getinfo(), iter.getsizeinfo());
01761       curslot->SetIntPar("GUI::Remote", iter.getflag("IsRemote")==1);
01762       SetProtectionBits(curslot, iter.getflag("IsDeleteProtect"), iter.getflag("IsResetProtect"));
01763 
01764       if (iter.getslot()!=0)
01765         SetCanDelete(curslot, IsCanDelete(iter.getslot()));
01766 
01767       TObject* assobj = 0;
01768       if ((kind==TGo4Access::kndObject) && (iter.getslot()!=0)) {
01769          TObject* obj = iter.getslot()->GetAssignedObject();
01770          if ((obj!=0) && (curslot->GetAssignedObject()==0))
01771            assobj = obj;
01772       }
01773 
01774       if (curslot->GetProxy()==0)
01775          curslot->SetProxy(new TGo4BrowserObjProxy(curslot, assobj, kFALSE));
01776       else
01777 
01778       if (assobj!=0)
01779          curslot->AssignObject(assobj, kFALSE);
01780 
01781       if (iter.isfolder()) {
01782          curfold = curslot;
01783 //         cout << "cd ++ ; folder = " << curfold->GetName() << endl;
01784          curslot = curfold->GetChild(0);
01785       } else {
01786          curslot->DeleteChilds();
01787          curslot = curslot->GetNext();
01788       }
01789    }
01790 
01791    if ((curslot!=0) && curslot->IsParent(targetslot))
01792       while (curslot!=0) {
01793          TGo4Slot* next = curslot->GetNext();
01794          delete curslot;
01795          curslot = next;
01796       }
01797 
01798     CalculateFolderSizes(targetslot);
01799 
01800     // inform other world that content was updated
01801     targetslot->ForwardEvent(targetslot, TGo4Slot::evObjUpdated);
01802 
01803     if (fxSyncTimer!=0) fxSyncTimer->Reset();
01804 
01805     fbBlockSync = kFALSE;
01806 }
01807 
01808 Int_t TGo4BrowserProxy::CalculateFolderSizes(TGo4Slot* topslot)
01809 {
01810    if (topslot==0) return 0;
01811    Int_t sizeinfo = ItemSizeInfo(topslot);
01812    bool verytop = fxBrowserSlot==topslot;
01813    if (!verytop && ItemKind(topslot)!=TGo4Access::kndFolder) return sizeinfo;
01814 
01815    Int_t sum = 0;
01816    for (Int_t n=0;n<topslot->NumChilds();n++)
01817        sum += CalculateFolderSizes(topslot->GetChild(n));
01818    if (!verytop) SetCalcSize(topslot, sum);
01819 
01820    return sum;
01821 }
01822 
01823 Int_t TGo4BrowserProxy::DefineItemProperties(Int_t kind, TClass* cl, TString& pixmap)
01824 {
01825    Int_t cando = 0; // 1000000 - export, 100000 - info, 10000 - close, 1000 - clear, 100 - draw, 10 - drag, 1 - edit
01826 
01827    // TClass * cl = (clname==0) ? 0 : (TClass*) gROOT->GetListOfClasses()->FindObject(clname);
01828 //   TClass * cl = (clname==0) ? 0 : gROOT->GetClass(clname);
01829 
01830    if (kind==TGo4Access::kndObject) {
01831       if (cl!=0) {
01832         if (cl->InheritsFrom(TProfile::Class())) { cando = 1110; pixmap = "profile_t.png"; } else
01833         if (cl->InheritsFrom(TGo4Picture::Class())) { cando = 110; pixmap = "picture.png"; } else
01834         if (cl->InheritsFrom(TGo4Parameter::Class())) { cando = 1011; pixmap = "parameter.png"; } else
01835         if (cl->InheritsFrom(TMultiGraph::Class())) { cando = 1110; pixmap = "superimpose.png"; } else
01836         if (cl->InheritsFrom(THStack::Class())) { cando = 1110; pixmap = "superimpose.png"; } else
01837         if (cl->InheritsFrom(TGraph::Class())) { cando = 1001110; pixmap = "tgraph.png"; } else
01838         if (cl->InheritsFrom(TGo4Fitter::Class())) { cando = 11; pixmap = "fitter.png"; } else
01839         if (cl->InheritsFrom(TCanvas::Class())) { cando = 110; pixmap = "canvas.png"; } else
01840         if (cl->InheritsFrom(TFile::Class())) { pixmap = "rootdb_t.png"; } else
01841         if (cl->InheritsFrom(TTree::Class())) { pixmap = "tree_t.png"; } else
01842         if (cl->InheritsFrom(TFolder::Class())) { pixmap = "folder_t.png"; } else
01843         if (cl->InheritsFrom(TDirectory::Class())) { pixmap = "folder_t.png"; } else
01844         if (cl->InheritsFrom(TH3::Class())) { cando = 1101110; pixmap = "h3_t.png"; } else
01845         if (cl->InheritsFrom(TH2::Class())) { cando = 1101110; pixmap = "h2_t.png"; } else
01846         if (cl->InheritsFrom(TH1::Class())) { cando = 1101110; pixmap = "h1_t.png"; } else
01847         if (cl->InheritsFrom(TGo4WinCond::Class())) { cando = 101011; pixmap = "windcond.png"; } else
01848         if (cl->InheritsFrom(TGo4PolyCond::Class())) { cando = 101011; pixmap = "polycond.png"; } else
01849         if (cl->InheritsFrom(TGo4CondArray::Class())) { cando = 101011; pixmap = "windcondarray.png"; } else
01850         if (cl->InheritsFrom(TGo4TreeHistogramEntry::Class())) { cando = 1011; pixmap = "dynentryx.png"; } else
01851         if (cl->InheritsFrom(TGo4HistogramEntry::Class())) { cando = 1011; pixmap = "dynentryx.png"; }
01852       }
01853    } else
01854    if (kind==TGo4Access::kndFolder) {
01855      pixmap = "folder_t.png";
01856      if ((cl!=0) && cl->InheritsFrom(TTree::Class())) { cando = 10; pixmap = "tree_t.png"; } else
01857      if ((cl!=0) && cl->InheritsFrom(TCanvas::Class())) { cando = 110; pixmap = "canvas.png"; } else
01858      if ((cl!=0) && cl->InheritsFrom(TFile::Class())) { cando = 10000; pixmap = "rootdb_t.png"; } else
01859      if ((cl!=0) && cl->InheritsFrom(TGo4HServProxy::Class())) { cando = 10000; pixmap = "histserv.png"; } else
01860      if ((cl!=0) && cl->InheritsFrom(TGo4AnalysisProxy::Class())) {pixmap = "analysiswin.png"; }
01861    } else
01862    if (kind==TGo4Access::kndTreeBranch)
01863      pixmap = "branch_t.png";
01864    else
01865    if (kind==TGo4Access::kndTreeLeaf) {
01866      cando = 11;  pixmap = "leaf_t.png";
01867    } else
01868    if (kind==TGo4Access::kndGo4Param) {
01869       cando = 1011; pixmap = "parameter.png";
01870    } else
01871    if (kind==TGo4Access::kndDataMember) {
01872       cando = 10; pixmap = "eventitem.png";
01873    } else
01874    if (kind==TGo4Access::kndEventElement) {
01875       cando = 100010; pixmap = "eventobj.png";
01876    }
01877 
01878    return cando;
01879 }
01880 
01881 Bool_t TGo4BrowserProxy::CompareAxisValues(Double_t v1, Double_t v2, Double_t scale)
01882 {
01883    if (v1==v2) return kTRUE;
01884 
01885    return (fabs(v1-v2) <= scale);
01886 }
01887 
01888 Int_t TGo4BrowserProxy::CompareAxis(TAxis* ax1, TAxis* ax2)
01889 {
01890    // return rebin factor
01891    // 0 - axis are differents
01892    // 1 - both axis the same
01893    // >1 - rebin factor than ax2->Rebin(n) will produce ax1
01894 
01895    if ((ax1==0) || (ax2==0)) return 0;
01896 
01897    Int_t num1 = ax1->GetNbins();
01898    Int_t num2 = ax2->GetNbins();
01899 
01900    Double_t scale = fabs(ax1->GetXmax() - ax1->GetXmin()) / (num1+1.) * 1e-3;
01901 
01902    if ((num1!=num2)) {
01903       // Minimum number for rebin is 2, therefore num2 should not more than num1/2
01904       if ((num1>num2/2) || (num1<2)) return 0;
01905 
01906       Int_t rebin = num2/num1;
01907       if (rebin==0) return 0;
01908 
01909       // support only uniform scale rebinning
01910       if ((ax1->GetXbins()->GetSize()!=0) || (ax1->GetXbins()->GetSize()!=0)) return 0;
01911 
01912       // minimum value on both axis should be the same
01913       if (!CompareAxisValues(ax1->GetXmin(), ax2->GetXmin(), scale)) return 0;
01914 
01915       Double_t xmax;
01916 
01917       if (num1*rebin!=num2) xmax = ax2->GetBinUpEdge(num1*rebin);
01918                        else xmax = ax2->GetXmax();
01919 
01920       // maximum value on both axis should be the same
01921        if (!CompareAxisValues(ax1->GetXmax(), xmax, scale)) return 0;
01922 
01923       return rebin;
01924    }
01925 
01926    if ((ax1->GetXbins()->GetSize()==0) && (ax1->GetXbins()->GetSize()==0)) {
01927        if (!CompareAxisValues(ax1->GetXmin(), ax2->GetXmin(), scale)) return 0;
01928        if (!CompareAxisValues(ax1->GetXmax(), ax2->GetXmax(), scale)) return 0;
01929    } else
01930       for (Int_t n=1;n<=num1;n++)
01931          if (!CompareAxisValues(ax1->GetBinCenter(n),
01932                                 ax2->GetBinCenter(n), scale)) return 0;
01933 
01934    return 1;
01935 }
01936 
01937 
01938 Bool_t TGo4BrowserProxy::UpdateObjectContent(TObject* obj, TObject* newobj, Int_t* hasrebinx, Int_t* hasrebiny)
01939 {
01940 //   return kFALSE;
01941 
01942    if (obj->InheritsFrom(TH1::Class())) {
01943       TH1* histo = dynamic_cast<TH1*> (obj);
01944       TH1* histo2 = dynamic_cast<TH1*> (newobj);
01945       if ((histo==0) || (histo2==0)) return kFALSE;
01946 
01947       if (dynamic_cast<TProfile*>(obj)!=0) return kFALSE;
01948 
01949       if (histo->GetDimension()!=histo2->GetDimension()) return kFALSE;
01950 
01951       Int_t rebinx = 1, rebiny = 1;
01952 
01953       rebinx = CompareAxis(histo->GetXaxis(), histo2->GetXaxis());
01954       if (histo->GetDimension()>1)
01955          rebiny = CompareAxis(histo->GetYaxis(), histo2->GetYaxis());
01956       if (histo->GetDimension()>2)
01957          if (CompareAxis(histo->GetZaxis(), histo2->GetZaxis())!=1) return kFALSE;
01958 
01959       if ((rebinx==0) || (rebiny==0)) return kFALSE;
01960 
01961       // in case when object was interactively rebin,
01962       // try to repeat same operation with new object to perform content update
01963       if ((rebinx>1) || (rebiny>1)) {
01964          if ((hasrebinx==0) || (hasrebiny==0)) return kFALSE;
01965 
01966          TH1* clon = (TH1*) histo2->Clone("____dummyhisto____");
01967          if (clon==0) return kFALSE;
01968          clon->SetDirectory(0);
01969          Bool_t rebinres = kFALSE;
01970 
01971          if (histo->GetDimension()==1) {
01972             clon->Rebin(rebinx);
01973             rebinres = UpdateObjectContent(histo, clon);
01974          }
01975 #if ROOT_VERSION_CODE > ROOT_VERSION(4,3,2)
01976          else
01977          if (histo->GetDimension()==2) {
01978             TH2* h2 = dynamic_cast<TH2*>(clon);
01979             if (h2!=0) h2->Rebin2D(rebinx, rebiny);
01980             rebinres = UpdateObjectContent(histo, h2);
01981          }
01982 #else
01983 
01984 
01985 #endif
01986 
01987          delete clon;
01988 
01989          if (rebinres) {
01990             *hasrebinx = rebinx;
01991             *hasrebiny = rebiny;
01992          }
01993 
01994          return rebinres;
01995       }
01996 
01997 
01998       Int_t sz = histo->GetNbinsX()+2;
01999       if (histo->GetDimension()>1)
02000         sz = sz*(histo->GetNbinsY()+2);
02001       if (histo->GetDimension()>2)
02002         sz = sz*(histo->GetNbinsZ()+2);
02003 
02004       Bool_t canrebin = histo->TestBit(TH1::kCanRebin);
02005       histo->SetBit(TH1::kCanRebin, kFALSE);
02006 
02007       Double_t sum = 0;
02008       for (int n=0;n<sz;n++) {
02009          Stat_t value = histo2->GetBinContent(n);
02010          sum += value;
02011          histo->SetBinContent(n, value);
02012       }
02013       if (canrebin) histo->SetBit(TH1::kCanRebin, kTRUE);
02014 
02015       histo->SetEntries(sum);
02016 
02017 #if ROOT_VERSION_CODE > ROOT_VERSION(4,3,2)
02018       TArrayD *sumw_tgt = 0, *sumw_src = 0;
02019 
02020       if (histo2->GetSumw2N()>0)
02021          sumw_src = histo2->GetSumw2();
02022 
02023       // if source has no sumw, target should also not has them
02024       if (sumw_src==0) histo->GetSumw2()->Set(0);
02025       else {
02026          histo->Sumw2();
02027          sumw_tgt = histo->GetSumw2();
02028       }
02029 
02030       if (sumw_src && sumw_tgt)
02031          sumw_tgt->Set(sz, sumw_src->GetArray());
02032 #endif
02033 
02034       return kTRUE;
02035    } else
02036    if (obj->InheritsFrom(TGo4Condition::Class())) {
02037       TGo4Condition* cond = dynamic_cast<TGo4Condition*> (obj);
02038       TGo4Condition* newcond = dynamic_cast<TGo4Condition*> (newobj);
02039       if ((cond==0) || (newcond==0)) return kFALSE;
02040 
02041       cond->UpdateFrom(newcond, kTRUE);
02042       cond->SetChanged(kFALSE);
02043 
02044       return kTRUE;
02045 
02046 //      newcond->SetLineColor(cond->GetLineColor());
02047 //      newcond->SetFillColor(cond->GetFillColor());
02048 //      newcond->SetFillStyle(cond->GetFillStyle());
02049 //      return kFALSE;
02050    } else
02051    if (obj->InheritsFrom(TGraphAsymmErrors::Class())) {
02052       TGraphAsymmErrors* gr = dynamic_cast<TGraphAsymmErrors*> (obj);
02053       TGraph* newgr = dynamic_cast<TGraph*> (newobj);
02054       if ((gr==0) || (newgr==0)) return kFALSE;
02055 
02056       Int_t npoints = newgr->GetN();
02057       gr->Set(npoints);
02058       Double_t xp, yp, exh, exl, eyh, eyl;
02059       for (Int_t n=0;n<npoints;n++) {
02060         newgr->GetPoint(n,xp,yp);
02061         gr->SetPoint(n,xp,yp);
02062 #if ROOT_VERSION_CODE > ROOT_VERSION(4,3,2)
02063         exh = newgr->GetErrorXhigh(n);
02064         exl = newgr->GetErrorXlow(n);
02065         eyh = newgr->GetErrorYhigh(n);
02066         eyl = newgr->GetErrorYlow(n);
02067         gr->SetPointError(n, exl, exh, eyl, eyh);
02068 #endif
02069       }
02070 
02071       return kTRUE;
02072    } else
02073    if (obj->InheritsFrom(TGraphErrors::Class())) {
02074       TGraphErrors* gr = dynamic_cast<TGraphErrors*> (obj);
02075       TGraph* newgr = dynamic_cast<TGraph*> (newobj);
02076       if ((gr==0) || (newgr==0)) return kFALSE;
02077 
02078       Int_t npoints = newgr->GetN();
02079       gr->Set(npoints);
02080       Double_t xp, yp, ex, ey;
02081       for (Int_t n=0;n<npoints;n++) {
02082         newgr->GetPoint(n,xp,yp);
02083         gr->SetPoint(n,xp,yp);
02084         ex = newgr->GetErrorX(n);
02085         ey = newgr->GetErrorY(n);
02086         gr->SetPointError(n, ex, ey);
02087       }
02088 
02089       return kTRUE;
02090    } else
02091    if (obj->InheritsFrom(TGraph::Class())) {
02092       TGraph* gr = dynamic_cast<TGraph*> (obj);
02093       TGraph* newgr = dynamic_cast<TGraph*> (newobj);
02094       if ((gr==0) || (newgr==0)) return kFALSE;
02095 
02096       Int_t npoints = newgr->GetN();
02097       gr->Set(npoints);
02098       Double_t xp, yp;
02099       for (Int_t n=0;n<npoints;n++) {
02100         newgr->GetPoint(n,xp,yp);
02101         gr->SetPoint(n,xp,yp);
02102       }
02103 
02104       return kTRUE;
02105    }
02106 
02107    return kFALSE;
02108 }
02109 
02110 void TGo4BrowserProxy::AddWaitingList(TGo4Slot* itemslot, const char* destination)
02111 {
02112    if (itemslot==0) return;
02113    if (fxWaitingList==0) fxWaitingList = new TList;
02114 
02115    TString itemname;
02116    if (!BrowserItemName(itemslot, itemname)) return;
02117 
02118    TNamed* n = (TNamed*) fxWaitingList->FindObject(itemname.Data());
02119    if (n!=0)
02120      n->SetTitle(destination);
02121    else
02122      fxWaitingList->Add(new TNamed(itemname.Data(), destination));
02123 }
02124 
02125 void TGo4BrowserProxy::CheckWaitingList(TGo4Slot* source)
02126 {
02127    if (fxWaitingList==0) return;
02128 
02129    TString itemname;
02130    if (!BrowserItemName(source, itemname)) return;
02131 
02132    TNamed* n = (TNamed*) fxWaitingList->FindObject(itemname.Data());
02133    if (n!=0) {
02134       const char* dest = n->GetTitle();
02135       if ((dest!=0) && (strlen(dest)==0)) dest = 0;
02136       ProduceExplicitCopy(source, dest, kFALSE);
02137       fxWaitingList->Remove(n);
02138       delete n;
02139    }
02140 }
02141 
02142 // used by ROOT browser
02143 
02144 void TGo4BrowserProxy::UpdateAllCanvases()
02145 {
02146    TIter next(gROOT->GetListOfCanvases());
02147    TPad* pad = 0;
02148    while ((pad = (TPad*) next()) != 0) {
02149       pad->Modified();
02150 
02151       TVirtualPad* subpad = 0;
02152       Int_t number = 0;
02153       while ((subpad = pad->GetPad(number++))!=0)
02154         subpad->Modified();
02155 
02156       pad->Update();
02157    }
02158 }
02159 
02160 //----------------------------END OF GO4 SOURCE FILE ---------------------

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