Skip to content
Snippets Groups Projects
Commit b8668ff6 authored by rgugel's avatar rgugel
Browse files

added option to TQMultiChannelAnalysisSampleVisitor for progress indication

git-svn-id: https://svn.cern.ch/reps/atlasoff/PhysicsAnalysis/AnalysisCommon/CAF/QFramework/trunk@801655 4525493e-7705-40b1-a816-d608a930855b
parent ad1580ad
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
#define __TQSampleVisitor__
#include "TNamed.h"
#include "TQStringUtils.h"
class TQSample;
class TQSampleFolder;
......@@ -16,12 +17,15 @@ protected:
bool fVerbose;
TString fVisitTraceID;
TString fStatusLine; //store the last printed status line to allow updates from child classes (e.g. indicating event loop progress)
static const TString statusSKIPPED;
static const TString statusOK;
static const TString statusFAILED;
static const TString statusWARN;
static const TString statusRUNNING;
inline static TString statusPROGRESS(double fraction) {return TQStringUtils::makeBoldWhite("[ ")+TQStringUtils::makeBoldWhite (TQStringUtils::fixedWidth(TString::Format("%.0f%%",fraction*100.),4,'c') )+TQStringUtils::makeBoldWhite(" ]");}; // %% is escaped '%' character
virtual int visitFolder(TQSampleFolder * sampleFolder, TString& message);
virtual int visitSample(TQSample * sample, TString& message);
......@@ -29,7 +33,7 @@ protected:
virtual int revisitFolder(TQSampleFolder * sampleFolder, TString& message);
inline TString printLine(TQSampleFolder* f, int level, bool isSample, const TString& bullet);
inline void updateLine(const TString& line, const TString& message, int result, bool ignore=false);
void updateLine(const TString& line, const TString& message, int result, bool ignore=false, double progress = 0.);
inline void leaveTrace(TQSampleFolder* sf, TString prefix, int result, const TString& message);
bool callInitialize(TQSampleFolder * sampleFolder);
......@@ -42,14 +46,15 @@ public:
enum visitSTATUS {
visitIGNORE = 9,
visitLISTONLY = 8,
visitPROGRESS = 7,
visitSKIPPED = 0,
visitOK = 1,
visitWARN = 2,
visitFAILED = 3
};
static TString getStatusString(int status);
static TString getStatusString(int status, double progress=0.);
TQSampleVisitor(const TString& name = "vis");
......
......@@ -32,7 +32,7 @@
#include "QFramework/TQUtils.h"
#include "QFramework/TQIterator.h"
#define _DEBUG_
// #define _DEBUG_
#include "QFramework/TQLibrary.h"
#include <iostream>
......
......@@ -58,7 +58,7 @@ bool TQCutflowAnalysisJob::initializeSelf() {
TQCut* c = this->getCut();
fCounter = new TQCounter(c->GetName(),c->GetTitle());
}
DEBUGclass("finished initializing cutflow analysis job");
return true;
}
......
......@@ -361,7 +361,7 @@ int TQMultiChannelAnalysisSampleVisitor::analyseTree(TQSample * sample, TString&
TQSampleIterator itr(sample->getFriends());
DEBUGclass("retrieving number of entries");
const int nEntries = std::min(tree->GetEntries(),this->fMaxEvents);
const Long64_t nEntries = std::min(tree->GetEntries(),this->fMaxEvents);
std::vector<bool> useMCweights;
std::vector<TQCut*> cuts;
......@@ -434,7 +434,9 @@ int TQMultiChannelAnalysisSampleVisitor::analyseTree(TQSample * sample, TString&
std::cout<<"Tree adress: "<<tree<<std::endl;
#endif
const size_t n = cuts.size();
for (int i = 0; i < nEntries; ++i) {
const Long64_t nEventsPerPercent = ceil(nEntries/100.); //+1 is a simple cosmetic patch to actually show the expected percent values later
const Long64_t progressInterval = nEventsPerPercent*this->getTagDoubleDefault("progressInterval",0.);
for (Long64_t i = 0; i < nEntries; ++i) {
//DEBUGclass(" visiting entry %d/%d",i,nEntries);
tree->GetEntry(i);
for(size_t j=0; j<n; ++j){
......@@ -444,6 +446,10 @@ int TQMultiChannelAnalysisSampleVisitor::analyseTree(TQSample * sample, TString&
,TString::Format("An error occured while evaluating entry %d of sample '%s'.",i,(cuts[j]->getSample()!=0?cuts[j]->getSample()->getPath().Data():"<undefined>"))
)
}
if ( i%progressInterval == 0 ) {
//TODO: update status buttom to reflect current status/progress
this->updateLine(fStatusLine,message,visitPROGRESS,progressInterval<=0,((double)i)/nEntries );
}
}
// finalize the cuts
......
......@@ -268,7 +268,6 @@ bool TQSample::getTree(){
/* the tree location */
TString location = treeLocations->At(i)->GetName();
/* extract file- and treename */
TString filename = extractFilename(location);
TString treename = extractTreename(location);
......
......@@ -82,11 +82,12 @@ const char* TQSampleVisitor::getVisitTraceIDConst() const {
//__________________________________________________________________________________|___________
TString TQSampleVisitor::getStatusString(int status) {
TString TQSampleVisitor::getStatusString(int status, double progress) {
if (status == visitSKIPPED) return TQSampleVisitor::statusSKIPPED;
if (status == visitOK) return TQSampleVisitor::statusOK;
if (status == visitFAILED) return TQSampleVisitor::statusFAILED;
if (status == visitWARN) return TQSampleVisitor::statusWARN;
if (status == visitPROGRESS) return TQSampleVisitor::statusPROGRESS(progress);
return "";
}
......@@ -161,10 +162,10 @@ TString TQSampleVisitor::printLine(TQSampleFolder* f, int level, bool isSample,
//__________________________________________________________________________________|___________
void TQSampleVisitor::updateLine(const TString& line, const TString& message, int result, bool ignore){
void TQSampleVisitor::updateLine(const TString& line, const TString& message, int result, bool ignore, double progress){
/* update status button */
if(ignore){
std::cout << std::endl;
if (result != visitPROGRESS) std::cout << std::endl; //don't end this line for ignored progress indications
return;
} else {
if (result == visitSKIPPED || result == visitOK || result == visitWARN || result == visitFAILED) {
......@@ -173,10 +174,15 @@ void TQSampleVisitor::updateLine(const TString& line, const TString& message, in
std::cout << TQStringUtils::fixedWidth(line, fSampleColWidth, "l") << TQStringUtils::repeat(" ", 10) << std::endl;
} else if (result == visitIGNORE) {
std::cout << TQStringUtils::fixedWidth(line, fSampleColWidth, "l") << TQStringUtils::repeat(" ", 10) << std::endl;
} else if (result == visitPROGRESS) {
std::cout << TQStringUtils::fixedWidth(line, fSampleColWidth, "l") << this->getStatusString(result,progress) << " " << message << "\r";
std::cout.flush();
}
}
}
//__________________________________________________________________________________|___________
int TQSampleVisitor::visit(TQSampleFolder * sampleFolder) {
......@@ -218,7 +224,7 @@ int TQSampleVisitor::callVisit(TQSampleFolder * sampleFolder, int level) {
TQLibrary::recordMemory();
/* print details */
TString line;
//TString line;
int result;
int nVisits = 0;
TString message;
......@@ -226,21 +232,21 @@ int TQSampleVisitor::callVisit(TQSampleFolder * sampleFolder, int level) {
if (isSample) {
/* visit as sample */
DEBUGclass("visiting as sample");
if (fVerbose) line = this->printLine(sampleFolder,level,true,"+");
if (fVerbose) fStatusLine = this->printLine(sampleFolder,level,true,"+");
result = visitSample(sample, message);
nVisits += (result == visitOK);
this->leaveTrace(sampleFolder,".sv.visit.",result,message);
if (fVerbose) this->updateLine(line,message,result);
if (fVerbose) this->updateLine(fStatusLine,message,result);
DEBUGclass("revisiting as sample");
result = revisitSample(sample, message);
this->leaveTrace(sampleFolder,".sv.revisit.",result,message);
} else {
/* visit as folder */
DEBUGclass("visiting as folder");
if (fVerbose) line = this->printLine(sampleFolder,level,false,"+");
if (fVerbose) fStatusLine = this->printLine(sampleFolder,level,false,"+");
result = visitFolder(sampleFolder, message);
this->leaveTrace(sampleFolder,".sv.visit.",result,message);
if (fVerbose) this->updateLine(line,message,result);
if (fVerbose) this->updateLine(fStatusLine,message,result);
/* next: visit all sub sample folders (if not disabled) */
if(result != visitFAILED && result != visitSKIPPED){
TQSampleFolderIterator itr(sampleFolder->getListOfSampleFolders("?"),true);
......@@ -255,10 +261,10 @@ int TQSampleVisitor::callVisit(TQSampleFolder * sampleFolder, int level) {
}
}
DEBUGclass("revisiting as folder");
if (fVerbose) line = this->printLine(sampleFolder,level,false,"-");
if (fVerbose) fStatusLine = this->printLine(sampleFolder,level,false,"-");
result = revisitFolder(sampleFolder, message);
this->leaveTrace(sampleFolder,".sv.revisit.",result,message);
if (fVerbose) this->updateLine(line,message,result);
if (fVerbose) this->updateLine(fStatusLine,message,result);
}
if (sampleFolder->hasTagString("asv.finalize.dumpTopTo")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment