Skip to content

Commit

Permalink
Suppressing printf output from TMatrixBase (HEP-FCC#379)
Browse files Browse the repository at this point in the history
* Suppressing printf output from TMatrixBase

* One more return
  • Loading branch information
kjvbrt committed Jul 4, 2024
1 parent ff50f25 commit de84ccb
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion analyzers/dataframe/src/VertexFitterSimple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,33 @@
#include "TFile.h"
#include "TString.h"

#include <fcntl.h>

//#include "TrkUtil.h" // from delphes

namespace FCCAnalyses {

namespace VertexFitterSimple {

int supress_stdout() {
fflush(stdout);

int ret = dup(1);
int nullfd = open("/dev/null", O_WRONLY);
// check nullfd for error omitted
dup2(nullfd, 1);
close(nullfd);

return ret;
}

void resume_stdout(int fd) {
fflush(stdout);
dup2(fd, 1);
close(fd);
std::cout << std::flush;
}

// -----------------------------------------------------------------------------

VertexingUtils::FCCAnalysesVertex VertexFitter(
Expand Down Expand Up @@ -77,6 +98,11 @@ VertexFitter_Tk(int Primary, ROOT::VecOps::RVec<edm4hep::TrackState> tracks,
const ROOT::VecOps::RVec<edm4hep::TrackState> &alltracks,
bool BeamSpotConstraint, double bsc_sigmax, double bsc_sigmay,
double bsc_sigmaz, double bsc_x, double bsc_y, double bsc_z) {
// Suppressing printf() output from TMatrixBase:
// https://github.com/root-project/root/blob/722eb4652bfc79149df00c8b0e92d0837caf054c/math/matrix/src/TMatrixTBase.cxx#L662
// The solution found here:
// https://stackoverflow.com/questions/46728680/how-to-temporarily-suppress-output-from-printf
int fd = supress_stdout();

// Units for the beam-spot : mum
// See
Expand Down Expand Up @@ -117,8 +143,10 @@ VertexFitter_Tk(int Primary, ROOT::VecOps::RVec<edm4hep::TrackState> tracks,

int Ntr = tracks.size();
TheVertex.ntracks = Ntr;
if (Ntr <= 1)
if (Ntr <= 1) {
resume_stdout(fd);
return TheVertex; // can not reconstruct a vertex with only one track...
}

TVectorD **trkPar = new TVectorD *[Ntr];
TMatrixDSym **trkCov = new TMatrixDSym *[Ntr];
Expand Down Expand Up @@ -214,6 +242,8 @@ VertexFitter_Tk(int Primary, ROOT::VecOps::RVec<edm4hep::TrackState> tracks,
delete[] trkPar;
delete[] trkCov;

resume_stdout(fd);

return TheVertex;
}

Expand Down

0 comments on commit de84ccb

Please sign in to comment.