Skip to content

Commit

Permalink
Silencing ZZ warnings (#1007)
Browse files Browse the repository at this point in the history
* silencing ZZ complains

* silencing ZZ complains on Asimov

* trying to dup the file descriptors. this should work on condor and on local.

* fixing freopen
  • Loading branch information
amarini authored Sep 26, 2024
1 parent e62f3ee commit f2e9e6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/CachingNLL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ cacheutils::CachingAddNLL::setIncludeZeroWeights(bool includeZeroWeights)
}
}

int orig2_stdout_fd = fileno(stdout);

Double_t
cacheutils::CachingAddNLL::evaluate() const
{
Expand Down Expand Up @@ -638,12 +640,13 @@ cacheutils::CachingAddNLL::evaluate() const
}
// get vals
//std::cout<<"Silence is gold!"<<std::endl;
int stdout_fd = dup(STDOUT_FILENO);
int stdout_fd = dup(fileno(stdout));
freopen("/dev/null", "w", stdout); // (bad) Fix RooFit warnings: [#0] WARNING:Eval -- Evaluating RooAddPdf without a defined normalization set.
const std::vector<Double_t> &pdfvals = itp->eval(*data_);
//freopen("/dev/tty", "w", stdout);
dup2(stdout_fd, STDOUT_FILENO);
stdout = fdopen(stdout_fd, "w");

close(fileno(stdout));
dup2(stdout_fd, orig2_stdout_fd);
stdout = fdopen(orig2_stdout_fd, "w");
close(stdout_fd);
//std::cout<<"I am alive!"<<std::endl;
if (basicIntegrals_) {
Expand Down
13 changes: 8 additions & 5 deletions src/ToyMCSamplerOpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ toymcoptutils::SinglePdfGenInfo::generatePseudoAsimov(RooRealVar *&weightVar, in
}
}

//global
int orig_stdout_fd = fileno(stdout);

RooDataSet *
toymcoptutils::SinglePdfGenInfo::generateWithHisto(RooRealVar *&weightVar, bool asimov, double weightScale, int verbose)
Expand All @@ -204,7 +206,7 @@ toymcoptutils::SinglePdfGenInfo::generateWithHisto(RooRealVar *&weightVar, bool
RooCmdArg ay = (y ? RooFit::YVar(*y) : RooCmdArg::none());
RooCmdArg az = (z ? RooFit::ZVar(*z) : RooCmdArg::none());

int stdout_fd = dup(STDOUT_FILENO);
int stdout_fd = dup(fileno(stdout));
freopen("/dev/null", "w", stdout); // AMARINI
if (histoSpec_ == 0) {
histoSpec_ = pdf_->createHistogram("htemp", *x, ay, az);
Expand Down Expand Up @@ -267,10 +269,11 @@ toymcoptutils::SinglePdfGenInfo::generateWithHisto(RooRealVar *&weightVar, bool
if (!keepHistoSpec_) { delete histoSpec_; histoSpec_ = 0; }
//std::cout << "Asimov dataset generated from " << pdf_->GetName() << " (sumw? " << data->sumEntries() << ", expected events " << expectedEvents << ")" << std::endl;
//utils::printRDH(data);
//freopen("/dev/tty", "w", stdout);
dup2(stdout_fd, STDOUT_FILENO);
stdout = fdopen(stdout_fd, "w");
close(stdout_fd);
//assert(orig_stdout_fd == fileno(stdout));
close(fileno(stdout));//de-associate dev/null from 1
dup2(stdout_fd, orig_stdout_fd);//re-associate stdout to 1
stdout = fdopen(orig_stdout_fd, "w");
close(stdout_fd); //de-associate the stdout_fd from stream
return data;
}

Expand Down

0 comments on commit f2e9e6b

Please sign in to comment.