#include "AEVProofFeedback.h"
#include <Glasses/AEVDistAnRep.h>
#include <Glasses/AEVDemoDriver.h>
#include <Glasses/ZImage.h>
#include <Glasses/Board.h>
#include <TList.h>
#include <TROOT.h>
#include <TProof.h>
#include <TError.h>
#include <TPad.h>
#include <TCanvas.h>
#include <TH1.h>
ClassImp(AEVProofFeedback);
void AEVProofFeedback::_init()
{
mProof = 0;
mDAR = 0;
mDD = 0;
mHImg = 0;
mBoard = 0;
}
void AEVProofFeedback::Connect(TProof* p, AEVDistAnRep* dar)
{
mProof = p;
mDAR = dar;
mProof->Connect("SiteProgress(TList *siteinfos)", "AEVProofFeedback",
this, "SiteProgress(TList *siteinfos)");
mProof->Connect("Feedback(TList *objs)", "AEVProofFeedback",
this, "Feedback(TList *objs)");
mFeedbackCount = 0;
}
void AEVProofFeedback::Disconnect()
{
if(mProof) {
mProof->Disconnect("SiteProgress(TList *siteinfos)");
mProof->Disconnect("Feedback(TList *objs)");
}
mProof = 0;
mDAR = 0;
}
void AEVProofFeedback::SiteProgress(TList *siteinfos)
{
static const Exc_t _eh("AEVProofFeedback::SiteProgress ");
map<string,int> siteevmap;
if(mDAR) {
mDAR->UpdateProcStatus(siteinfos, &siteevmap);
}
if(mDD) {
mDD->VisProofProgress(siteevmap);
}
}
void AEVProofFeedback::Feedback(TList *objs)
{
static const Exc_t _eh("AEVProofFeedback::Feedback ");
++mFeedbackCount;
TSeqCollection *canvases = gROOT->GetListOfCanvases();
TVirtualPad *save = gPad;
TIter next(objs);
TObject *o;
while( (o = next()) )
{
if (o->InheritsFrom("TH1")) {
TString name = o->GetName();
name += "_canvas";
TCanvas *c = (TCanvas*) canvases->FindObject( name.Data() );
if ( c == 0 ) {
if(mHImg) {
c = new TCanvas(name.Data(),name.Data(), 1028, 540);
} else {
c = new TCanvas(name.Data(),name.Data(), 640, 480);
}
c->SetGrid(1, 1);
c->SetLogy(1);
((TH1*)o)->DrawCopy();
} else {
c->cd();
((TH1*)o)->DrawCopy();
}
c->Update();
if(mHImg) {
GLensWriteHolder wlck(mHImg);
c->SaveAs(mHImg->GetFile());
mHImg->Load();
}
if(mBoard && mFeedbackCount <= 100) {
GLensWriteHolder wlck(mBoard);
mBoard->SetColor(1,1,1, 0.01*mFeedbackCount);
}
}
}
if (save != 0) {
save->cd();
} else {
gPad = 0;
}
}