#include "TProofChain.h"
#include "TDSet.h"
#include "TList.h"
#include "TProof.h"
#include "TROOT.h"
#include "TEventList.h"
#include "TEntryList.h"
ClassImp(TProofChain)
TProofChain::TProofChain() : TChain()
{
fChain = 0;
fTree = 0;
fSet = 0;
fDirectory = gDirectory;
ResetBit(kOwnsChain);
}
TProofChain::TProofChain(TChain *chain, Bool_t gettreeheader) : TChain()
{
fChain = chain;
fTree = 0;
fSet = chain ? new TDSet((const TChain &)(*chain)) : 0;
fDirectory = gDirectory;
if (gProof) {
gProof->AddChain(chain);
ConnectProof();
if (gProof->IsLite()) {
SetBit(kProofLite);
fTree = fChain;
} else {
if (gettreeheader && fSet)
fTree = gProof->GetTreeHeader(fSet);
}
}
ResetBit(kOwnsChain);
}
TProofChain::TProofChain(TDSet *dset, Bool_t gettreeheader) : TChain()
{
fChain = 0;
fTree = 0;
fSet = dset;
fDirectory = gDirectory;
if (gProof) {
ConnectProof();
if (gettreeheader && dset)
fTree = gProof->GetTreeHeader(dset);
if (gProof->IsLite())
SetBit(kProofLite);
}
if (fTree && fSet) {
fChain = new TChain(fTree->GetName());
TIter nxe(fSet->GetListOfElements());
TDSetElement *e = 0;
while ((e = (TDSetElement *) nxe())) {
fChain->AddFile(e->GetName());
}
SetBit(kOwnsChain);
if (TestBit(kProofLite))
fTree = fChain;
}
}
TProofChain::~TProofChain()
{
if (fChain) {
SafeDelete(fSet);
TIter nxp(gROOT->GetListOfSockets());
TObject *o = 0;
TProof *p = 0;
while ((o = nxp()))
if ((p = dynamic_cast<TProof *>(o)))
p->RemoveChain(fChain);
if (fTree == fChain) fTree = 0;
if (TestBit(kOwnsChain)) {
SafeDelete(fChain);
} else {
fChain = 0;
}
} else {
fSet = 0;
}
SafeDelete(fTree);
fDirectory = 0;
}
void TProofChain::Browse(TBrowser *b)
{
fSet->Browse(b);
}
Long64_t TProofChain::Draw(const char *varexp, const TCut &selection,
Option_t *option, Long64_t nentries, Long64_t firstentry)
{
if (!gProof) {
Error("Draw", "no active PROOF session");
return -1;
}
ConnectProof();
fReadEntry = firstentry;
if (fEntryList) {
fSet->SetEntryList(fEntryList);
} else if (fEventList) {
fSet->SetEntryList(fEventList);
}
FillDrawAttributes(gProof);
Long64_t rv = fSet->Draw(varexp, selection, option, nentries, firstentry);
return rv;
}
Long64_t TProofChain::Draw(const char *varexp, const char *selection,
Option_t *option,Long64_t nentries, Long64_t firstentry)
{
if (!gProof) {
Error("Draw", "no active PROOF session");
return -1;
}
ConnectProof();
fReadEntry = firstentry;
if (fEntryList) {
fSet->SetEntryList(fEntryList);
} else if (fEventList) {
fSet->SetEntryList(fEventList);
}
FillDrawAttributes(gProof);
Long64_t rv = fSet->Draw(varexp, selection, option, nentries, firstentry);
return rv;
}
void TProofChain::FillDrawAttributes(TProof *p)
{
if (!p || !fChain) {
Error("FillDrawAttributes", "invalid PROOF or mother chain pointers!");
return;
}
p->SetParameter("PROOF_ChainWeight", fChain->GetWeight());
p->SetParameter("PROOF_LineColor", (Int_t) fChain->GetLineColor());
p->SetParameter("PROOF_LineStyle", (Int_t) fChain->GetLineStyle());
p->SetParameter("PROOF_LineWidth", (Int_t) fChain->GetLineWidth());
p->SetParameter("PROOF_MarkerColor", (Int_t) fChain->GetMarkerColor());
p->SetParameter("PROOF_MarkerSize", (Int_t) fChain->GetMarkerSize()*1000);
p->SetParameter("PROOF_MarkerStyle", (Int_t) fChain->GetMarkerStyle());
p->SetParameter("PROOF_FillColor", (Int_t) fChain->GetFillColor());
p->SetParameter("PROOF_FillStyle", (Int_t) fChain->GetFillStyle());
if (gDebug > 0) {
Info("FillDrawAttributes","line: color:%d, style:%d, width:%d",
fChain->GetLineColor(), fChain->GetLineStyle(), fChain->GetLineWidth());
Info("FillDrawAttributes","marker: color:%d, style:%d, size:%f",
fChain->GetMarkerColor(), fChain->GetMarkerStyle(), fChain->GetMarkerSize());
Info("FillDrawAttributes","area: color:%d, style:%d",
fChain->GetFillColor(), fChain->GetFillStyle());
}
}
TBranch *TProofChain::FindBranch(const char* branchname)
{
return (fTree ? fTree->FindBranch(branchname) : (TBranch *)0);
}
TLeaf *TProofChain::FindLeaf(const char* searchname)
{
return (fTree ? fTree->FindLeaf(searchname) : (TLeaf *)0);
}
TBranch *TProofChain::GetBranch(const char *name)
{
return (fTree ? fTree->GetBranch(name) : (TBranch *)0);
}
Bool_t TProofChain::GetBranchStatus(const char *branchname) const
{
return (fTree ? fTree->GetBranchStatus(branchname) : kFALSE);
}
TVirtualTreePlayer *TProofChain::GetPlayer()
{
return (fTree ? fTree->GetPlayer() : (TVirtualTreePlayer *)0);
}
Long64_t TProofChain::Process(const char *filename, Option_t *option,
Long64_t nentries, Long64_t firstentry)
{
if (fEntryList) {
fSet->SetEntryList(fEntryList);
} else if (fEventList) {
fSet->SetEntryList(fEventList);
}
return fSet->Process(filename, option, nentries, firstentry);
}
Long64_t TProofChain::Process(TSelector *selector, Option_t *option,
Long64_t nentries, Long64_t firstentry)
{
if (fEntryList) {
fSet->SetEntryList(fEntryList);
} else if (fEventList) {
fSet->SetEntryList(fEventList);
}
return fSet->Process(selector, option, nentries, firstentry);
}
void TProofChain::SetDebug(Int_t level, Long64_t min, Long64_t max)
{
TTree::SetDebug(level, min, max);
}
void TProofChain::SetName(const char *name)
{
TTree::SetName(name);
}
Long64_t TProofChain::GetEntries() const
{
if (TestBit(kProofLite)) {
return (fTree ? fTree->GetEntries() : (Long64_t)(-1));
} else {
return (fTree ? fTree->GetMaxEntryLoop() : (Long64_t)(-1));
}
}
Long64_t TProofChain::GetEntries(const char *selection)
{
if (TestBit(kProofLite)) {
return (fTree ? fTree->GetEntries(selection) : (Long64_t)(-1));
} else {
Warning("GetEntries", "GetEntries(selection) not yet implemented");
return ((Long64_t)(-1));
}
}
void TProofChain::Progress(Long64_t total, Long64_t processed)
{
if (gROOT->IsInterrupted() && gProof)
gProof->StopProcess(kTRUE);
if (total) { }
fReadEntry = processed;
}
Long64_t TProofChain::GetReadEntry() const
{
return fReadEntry;
}
void TProofChain::ReleaseProof()
{
if (!gProof)
return;
gProof->Disconnect("Progress(Long64_t,Long64_t)",
this, "Progress(Long64_t,Long64_t)");
}
void TProofChain::ConnectProof()
{
if (gProof)
gProof->Connect("Progress(Long64_t,Long64_t)", "TProofChain",
this, "Progress(Long64_t,Long64_t)");
}