From b33300f8b1dba424481d19ca0679bce5dd491efd Mon Sep 17 00:00:00 2001 From: JohannesGaessler <johannesg@5d6.de> Date: Wed, 1 Nov 2023 20:17:38 +0100 Subject: [PATCH] Fixed table merge segfault depending on file order --- .../fastnlotoolkit/fastNLOCoeffAddFlex.cc | 28 ++++++++++++++++--- .../include/fastnlotk/fastNLOCoeffAddFlex.h | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/v2.5/toolkit/fastnlotoolkit/fastNLOCoeffAddFlex.cc b/v2.5/toolkit/fastnlotoolkit/fastNLOCoeffAddFlex.cc index fea21182..aba00db2 100644 --- a/v2.5/toolkit/fastnlotoolkit/fastNLOCoeffAddFlex.cc +++ b/v2.5/toolkit/fastnlotoolkit/fastNLOCoeffAddFlex.cc @@ -217,7 +217,7 @@ void fastNLOCoeffAddFlex::Add(const fastNLOCoeffAddBase& other, fastNLO::EMerge if ( !ok ) { error["Add"]<<"Incompatible table."<<endl; } - const fastNLOCoeffAddFlex& othflex = (const fastNLOCoeffAddFlex&) other; + fastNLOCoeffAddFlex& othflex = (fastNLOCoeffAddFlex&) other; if ( moption==fastNLO::kMerge ) { ExtendSigmaTilde(othflex, SigmaTildeMuIndep, othflex.SigmaTildeMuIndep); fastNLOTools::AddVectors(SigmaTildeMuIndep, othflex.SigmaTildeMuIndep); @@ -251,7 +251,7 @@ void fastNLOCoeffAddFlex::Add(const fastNLOCoeffAddBase& other, fastNLO::EMerge } else if ( moption==fastNLO::kAttach ) { vector<fastNLO::v5d*> st1 = this->AccessSigmaTildes(); - vector<const fastNLO::v5d*> st2 = othflex.GetSigmaTildes(); + vector<fastNLO::v5d*> st2 = othflex.AccessSigmaTildes(); int cMax = st1.size(); for ( int ii = cMax-1 ; ii>= 0 ; ii-- ) { if ( st1[ii]->size()==0 ) cMax--; @@ -287,7 +287,7 @@ void fastNLOCoeffAddFlex::Add(const fastNLOCoeffAddBase& other, fastNLO::EMerge } else { vector<fastNLO::v5d*> st1 = this->AccessSigmaTildes(); - vector<const fastNLO::v5d*> st2 = othflex.GetSigmaTildes(); + vector<fastNLO::v5d*> st2 = othflex.AccessSigmaTildes(); int cMax = st1.size(); for ( int ii = cMax-1 ; ii>= 0 ; ii-- ) { if ( st1[ii]->size()==0 && st2[ii]->size()==0) cMax--; @@ -305,6 +305,26 @@ void fastNLOCoeffAddFlex::Add(const fastNLOCoeffAddBase& other, fastNLO::EMerge } info["add"]<<"Copied coefficients from other table."<<endl; */ + + // May need to extend other sigma tilde prior to copying dimensions. + // Cannot call ExtendSigmaTilde because st1[ii]->size() == 0 . + for(int obsBin=0 ; obsBin<fNObsBins ; obsBin++){ + fastNLO::v3d insertValue = fastNLO::v3d( + GetNScaleNode1(obsBin), fastNLO::v2d(GetNScaleNode2(obsBin), fastNLO::v1d(GetNSubproc()))); + int thisNxtot1 = GetNxtot1(obsBin); + int thisNxtot2 = GetNxtot2(obsBin); + int otherNxtot1 = othflex.GetNxtot1(obsBin); + int otherNxtot2 = othflex.GetNxtot2(obsBin); + if (thisNxtot1 > otherNxtot1) { + fastNLOTools::ExtendSigmaTildeX((*st2[ii])[obsBin], otherNxtot1, thisNxtot1, + otherNxtot2, otherNxtot2, NPDFDim, insertValue); + } + int maxNxtot1 = max(thisNxtot1, otherNxtot1); + if (thisNxtot2 > otherNxtot2) { + fastNLOTools::ExtendSigmaTildeX((*st2[ii])[obsBin], maxNxtot1, maxNxtot1, + otherNxtot2, thisNxtot2, NPDFDim, insertValue); + } + } fastNLOTools::ResizeFlexibleVector(*st1[ii],*st2[ii]); } else if ( st2[ii]->size() == 0 ) { @@ -368,7 +388,7 @@ void fastNLOCoeffAddFlex::Add(const fastNLOCoeffAddBase& other, fastNLO::EMerge //________________________________________________________________________________________________________________ // void fastNLOCoeffAddFlex::ExtendSigmaTilde( - const fastNLOCoeffAddFlex& othflex, fastNLO::v5d& ThisSigmaTilde, fastNLO::v5d OtherSigmaTilde) { + const fastNLOCoeffAddFlex& othflex, fastNLO::v5d& ThisSigmaTilde, fastNLO::v5d& OtherSigmaTilde) { for(int obsBin=0 ; obsBin<fNObsBins ; obsBin++){ fastNLO::v3d insertValue = fastNLO::v3d( GetNScaleNode1(obsBin), fastNLO::v2d(GetNScaleNode2(obsBin), fastNLO::v1d(GetNSubproc()))); diff --git a/v2.5/toolkit/fastnlotoolkit/include/fastnlotk/fastNLOCoeffAddFlex.h b/v2.5/toolkit/fastnlotoolkit/include/fastnlotk/fastNLOCoeffAddFlex.h index be8e61da..84761a5f 100644 --- a/v2.5/toolkit/fastnlotoolkit/include/fastnlotk/fastNLOCoeffAddFlex.h +++ b/v2.5/toolkit/fastnlotoolkit/include/fastnlotk/fastNLOCoeffAddFlex.h @@ -58,7 +58,7 @@ public: protected: void ReadCoeffAddFlex(std::istream& table, int ITabVersionRead); - void ExtendSigmaTilde(const fastNLOCoeffAddFlex& othflex, fastNLO::v5d& ThisSigmaTilde, fastNLO::v5d OtherSigmaTilde); + void ExtendSigmaTilde(const fastNLOCoeffAddFlex& othflex, fastNLO::v5d& ThisSigmaTilde, fastNLO::v5d& OtherSigmaTilde); int fILOord; // obtained from Scenario int fSTildeDISFormat = 1; // format of sigma-tilde coefficients (0: log(mu2/q2), 1: log(mu2)) -- GitLab