TProofChain.cxx

Go to the documentation of this file.
00001 
00002 // @(#)root/proof:$Id: TProofChain.cxx 30069 2009-09-08 15:23:21Z ganis $
00003 // Author: G. Ganis  Nov 2006
00004 
00005 /*************************************************************************
00006  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 // TProofChain                                                          //
00016 //                                                                      //
00017 // A TChain proxy on PROOF.                                             //
00018 // Uses an internal TDSet to handle processing.                         //
00019 //                                                                      //
00020 //////////////////////////////////////////////////////////////////////////
00021 
00022 #include "TProofChain.h"
00023 #include "TDSet.h"
00024 #include "TList.h"
00025 #include "TProof.h"
00026 #include "TROOT.h"
00027 #include "TEventList.h"
00028 #include "TEntryList.h"
00029 
00030 ClassImp(TProofChain)
00031 
00032 //______________________________________________________________________________
00033 TProofChain::TProofChain() : TChain()
00034 {
00035    // Crates a new PROOF chain proxy.
00036 
00037    fChain        = 0;
00038    fTree         = 0;
00039    fSet          = 0;
00040    fDirectory    = gDirectory;
00041    fDrawFeedback = 0;
00042    ResetBit(kOwnsChain);
00043 }
00044 
00045 //______________________________________________________________________________
00046 TProofChain::TProofChain(TChain *chain, Bool_t gettreeheader) : TChain()
00047 {
00048    // Crates a new PROOF chain proxy containing the files from the chain.
00049 
00050    fChain        = chain;
00051    fTree         = 0;
00052    fSet          = chain ? new TDSet((const TChain &)(*chain)) : 0;
00053    fDirectory    = gDirectory;
00054    fDrawFeedback = 0;
00055    if (gProof) {
00056       gProof->AddChain(chain);
00057       ConnectProof();
00058       if (gProof->IsLite()) {
00059          SetBit(kProofLite);
00060          fTree = fChain;
00061       } else {
00062          if (gettreeheader && fSet)
00063             fTree = gProof->GetTreeHeader(fSet);
00064       }
00065    }
00066    ResetBit(kOwnsChain);
00067 }
00068 
00069 //______________________________________________________________________________
00070 TProofChain::TProofChain(TDSet *dset, Bool_t gettreeheader) : TChain()
00071 {
00072    // Creates a new PROOF chain proxy containing the files from the dset.
00073 
00074    fChain        = 0;
00075    fTree         = 0;
00076    fSet          = dset;
00077    fDirectory    = gDirectory;
00078    fDrawFeedback = 0;
00079    if (gProof) {
00080       ConnectProof();
00081       if (gettreeheader && dset)
00082          fTree = gProof->GetTreeHeader(dset);
00083       if (gProof->IsLite())
00084          SetBit(kProofLite);
00085    }
00086    if (fTree && fSet) {
00087       fChain = new TChain(fTree->GetName());
00088       TIter nxe(fSet->GetListOfElements());
00089       TDSetElement *e = 0;
00090       while ((e = (TDSetElement *) nxe())) {
00091          fChain->AddFile(e->GetName());
00092       }
00093       SetBit(kOwnsChain);
00094       if (TestBit(kProofLite))
00095          fTree = fChain;
00096    }
00097 }
00098 
00099 //______________________________________________________________________________
00100 TProofChain::~TProofChain()
00101 {
00102    // Destructor.
00103 
00104    if (fChain) {
00105       SafeDelete(fSet);
00106       // Remove the chain from the private lists in the TProof objects
00107       TIter nxp(gROOT->GetListOfSockets());
00108       TObject *o = 0;
00109       TProof *p = 0;
00110       while ((o = nxp()))
00111          if ((p = dynamic_cast<TProof *>(o)))
00112             p->RemoveChain(fChain);
00113       if (fTree == fChain) fTree = 0;
00114       if (TestBit(kOwnsChain)) {
00115          SafeDelete(fChain);
00116       } else {
00117          fChain = 0;
00118       }
00119    } else {
00120       // Not owner
00121       fSet = 0;
00122    }
00123    SafeDelete(fTree);
00124    fDirectory    = 0;
00125 
00126 }
00127 
00128 //______________________________________________________________________________
00129 void TProofChain::Browse(TBrowser *b)
00130 {
00131    // Forwards the execution to the dummy tree header.
00132    // See TTree::Browse().
00133 
00134    fSet->Browse(b);
00135 }
00136 
00137 //______________________________________________________________________________
00138 Long64_t TProofChain::Draw(const char *varexp, const TCut &selection,
00139                            Option_t *option, Long64_t nentries, Long64_t firstentry)
00140 {
00141    // Forwards the execution to the TDSet.
00142    // Returns -1 in case of error or number of selected events in case of success.
00143    // See TDSet::Browse().
00144 
00145    if (!gProof) {
00146       Error("Draw", "no active PROOF session");
00147       return -1;
00148    }
00149    ConnectProof();
00150 
00151    if (fDrawFeedback)
00152       gProof->SetDrawFeedbackOption(fDrawFeedback, option);
00153    fReadEntry = firstentry;
00154 
00155    // Set either the entry-list (priority) or the event-list
00156    if (fEntryList) {
00157       fSet->SetEntryList(fEntryList);
00158    } else if (fEventList) {
00159       fSet->SetEntryList(fEventList);
00160    }
00161 
00162    // Fill drawing attributes
00163    FillDrawAttributes(gProof);
00164 
00165    Long64_t rv = fSet->Draw(varexp, selection, option, nentries, firstentry);
00166    return rv;
00167 }
00168 
00169 //______________________________________________________________________________
00170 Long64_t TProofChain::Draw(const char *varexp, const char *selection,
00171                            Option_t *option,Long64_t nentries, Long64_t firstentry)
00172 {
00173    // Forwards the execution to the TDSet.
00174    // Returns -1 in case of error or number of selected events in case of success.
00175    // See TDSet::Browse().
00176 
00177    if (!gProof) {
00178       Error("Draw", "no active PROOF session");
00179       return -1;
00180    }
00181    ConnectProof();
00182 
00183    if (fDrawFeedback)
00184       gProof->SetDrawFeedbackOption(fDrawFeedback, option);
00185    fReadEntry = firstentry;
00186 
00187    // Set either the entry-list (priority) or the event-list
00188    if (fEntryList) {
00189       fSet->SetEntryList(fEntryList);
00190    } else if (fEventList) {
00191       fSet->SetEntryList(fEventList);
00192    }
00193 
00194    // Fill drawing attributes
00195    FillDrawAttributes(gProof);
00196 
00197    Long64_t rv = fSet->Draw(varexp, selection, option, nentries, firstentry);
00198    return rv;
00199 }
00200 
00201 //______________________________________________________________________________
00202 void TProofChain::FillDrawAttributes(TProof *p)
00203 {
00204    // Communicate the drawing attributes for this chain to the input list
00205    // so that the draw selectors can use them, in case of need.
00206    // The drawing attributes are:
00207    //
00208    //    LineColor          Line color
00209    //    LineStyle          Line style
00210    //    LineWidth          Line width
00211    //    MarkerColor        Marker color index
00212    //    MarkerSize         Marker size
00213    //    MarkerStyle        Marker style
00214    //    FillColor          Area fill color
00215    //    FillStyle          Area fill style
00216 
00217    if (!p || !fChain) {
00218       Error("FillDrawAttributes", "invalid PROOF or mother chain pointers!");
00219       return;
00220    }
00221 
00222    // Line Attributes
00223    p->SetParameter("PROOF_LineColor", (Int_t) fChain->GetLineColor());
00224    p->SetParameter("PROOF_LineStyle", (Int_t) fChain->GetLineStyle());
00225    p->SetParameter("PROOF_LineWidth", (Int_t) fChain->GetLineWidth());
00226 
00227    // Marker Attributes
00228    p->SetParameter("PROOF_MarkerColor", (Int_t) fChain->GetMarkerColor());
00229    p->SetParameter("PROOF_MarkerSize", (Int_t) fChain->GetMarkerSize()*1000);
00230    p->SetParameter("PROOF_MarkerStyle", (Int_t) fChain->GetMarkerStyle());
00231 
00232    // Area fill attributes
00233    p->SetParameter("PROOF_FillColor", (Int_t) fChain->GetFillColor());
00234    p->SetParameter("PROOF_FillStyle", (Int_t) fChain->GetFillStyle());
00235 
00236    if (gDebug > 0) {
00237       Info("FillDrawAttributes","line:   color:%d, style:%d, width:%d",
00238            fChain->GetLineColor(), fChain->GetLineStyle(), fChain->GetLineWidth());
00239       Info("FillDrawAttributes","marker: color:%d, style:%d, size:%f",
00240            fChain->GetMarkerColor(), fChain->GetMarkerStyle(), fChain->GetMarkerSize());
00241       Info("FillDrawAttributes","area:   color:%d, style:%d",
00242            fChain->GetFillColor(), fChain->GetFillStyle());
00243    }
00244 }
00245 
00246 //______________________________________________________________________________
00247 TBranch *TProofChain::FindBranch(const char* branchname)
00248 {
00249    // Forwards the execution to the dummy tree header.
00250    // See TTree::FindBranch().
00251 
00252    return (fTree ? fTree->FindBranch(branchname) : (TBranch *)0);
00253 }
00254 
00255 //______________________________________________________________________________
00256 TLeaf *TProofChain::FindLeaf(const char* searchname)
00257 {
00258    // Forwards the execution to the dummy tree header.
00259    // See TTree::FindLeaf().
00260 
00261    return (fTree ? fTree->FindLeaf(searchname) : (TLeaf *)0);
00262 }
00263 
00264 //______________________________________________________________________________
00265 TBranch *TProofChain::GetBranch(const char *name)
00266 {
00267    // Forwards the execution to the dummy tree header.
00268    // See TTree::GetBranch().
00269 
00270    return (fTree ? fTree->GetBranch(name) : (TBranch *)0);
00271 }
00272 
00273 //______________________________________________________________________________
00274 Bool_t TProofChain::GetBranchStatus(const char *branchname) const
00275 {
00276    // Forwards the execution to the dummy tree header.
00277    // See TTree::GetBranchStatus().
00278 
00279    return (fTree ? fTree->GetBranchStatus(branchname) : kFALSE);
00280 }
00281 
00282 //______________________________________________________________________________
00283 TVirtualTreePlayer *TProofChain::GetPlayer()
00284 {
00285    // Forwards the execution to the dummy tree header.
00286    // See TTree::GetPlayer().
00287 
00288    return (fTree ? fTree->GetPlayer() : (TVirtualTreePlayer *)0);
00289 }
00290 
00291 //______________________________________________________________________________
00292 Long64_t TProofChain::Process(const char *filename, Option_t *option,
00293                               Long64_t nentries, Long64_t firstentry)
00294 {
00295    // Forwards the execution to the TDSet.
00296    // The return value is -1 in case of error and TSelector::GetStatus() in
00297    // in case of success.
00298    // See TDSet::Process().
00299 
00300    // Set either the entry-list (priority) or the event-list
00301    if (fEntryList) {
00302       fSet->SetEntryList(fEntryList);
00303    } else if (fEventList) {
00304       fSet->SetEntryList(fEventList);
00305    }
00306 
00307    return fSet->Process(filename, option, nentries, firstentry);
00308 }
00309 
00310 //______________________________________________________________________________
00311 Long64_t TProofChain::Process(TSelector *selector, Option_t *option,
00312                               Long64_t nentries, Long64_t firstentry)
00313 {
00314    // Not implemented in TProofChain. Shouldn't be used.
00315    // The return value is -1 in case of error and TSelector::GetStatus() in
00316    // in case of success.
00317 
00318    if (selector || option || nentries || firstentry) { }
00319    //   return fSet->Process(selector, option, nentries, firstentry);
00320    Warning("Process", "not implemented"); // TODO
00321    return -1;
00322 }
00323 
00324 //______________________________________________________________________________
00325 void TProofChain::SetDebug(Int_t level, Long64_t min, Long64_t max)
00326 {
00327    // See TTree::SetDebug
00328 
00329    TTree::SetDebug(level, min, max);
00330 }
00331 
00332 //______________________________________________________________________________
00333 void TProofChain::SetName(const char *name)
00334 {
00335    // See TTree::GetName.
00336 
00337    TTree::SetName(name);
00338 }
00339 
00340 //______________________________________________________________________________
00341 Long64_t TProofChain::GetEntries() const
00342 {
00343    // Returns the total number of entries in the TProofChain, which is
00344    // the number of entries in the TDSet that it holds.
00345 
00346    // this was used for holding the total number of entries
00347    if (TestBit(kProofLite)) {
00348       return (fTree ? fTree->GetEntries() : (Long64_t)(-1));
00349    } else {
00350       return (fTree ? fTree->GetMaxEntryLoop() : (Long64_t)(-1));
00351    }
00352 }
00353 
00354 //______________________________________________________________________________
00355 Long64_t TProofChain::GetEntries(const char *selection)
00356 {
00357    // See TTree::GetEntries(const char *selection)
00358    // Not implemented in TProofChain. Shouldn't be used.
00359 
00360    if (TestBit(kProofLite)) {
00361       return (fTree ? fTree->GetEntries(selection) : (Long64_t)(-1));
00362    } else {
00363       Warning("GetEntries", "GetEntries(selection) not yet implemented");
00364       return ((Long64_t)(-1));
00365    }
00366 }
00367 
00368 //______________________________________________________________________________
00369 void TProofChain::Progress(Long64_t total, Long64_t processed)
00370 {
00371    // Changes the number of processed entries.
00372 
00373    if (gROOT->IsInterrupted() && gProof)
00374       gProof->StopProcess(kTRUE);
00375    if (total) { }
00376 
00377    fReadEntry = processed;
00378 }
00379 
00380 //______________________________________________________________________________
00381 Long64_t TProofChain::GetReadEntry() const
00382 {
00383    // Returns the number of processed entries.
00384 
00385    return fReadEntry;
00386 }
00387 
00388 //______________________________________________________________________________
00389 void TProofChain::ReleaseProof()
00390 {
00391    // Releases PROOF. Disconnect the "progress" signal.
00392 
00393    if (!gProof)
00394       return;
00395    gProof->Disconnect("Progress(Long64_t,Long64_t)",
00396                       this, "Progress(Long64_t,Long64_t)");
00397    if (fDrawFeedback)
00398       gProof->DeleteDrawFeedback(fDrawFeedback);
00399    fDrawFeedback = 0;
00400 }
00401 
00402 //______________________________________________________________________________
00403 void TProofChain::ConnectProof()
00404 {
00405    // Connects the proof - creates a "DrawFeedback" and connects the
00406    // "Progress" signal.
00407 
00408    if (gProof && !fDrawFeedback) {
00409       fDrawFeedback = gProof->CreateDrawFeedback();
00410 
00411       gProof->Connect("Progress(Long64_t,Long64_t)", "TProofChain",
00412                        this, "Progress(Long64_t,Long64_t)");
00413    }
00414 }

Generated on Tue Jul 5 14:51:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1