Skip to content

Commit

Permalink
Merge pull request #12675 from Dr15Jones/fixTMVAEvaluatorMemoryProblem
Browse files Browse the repository at this point in the history
Fix ownership problem in TMVAEvaluator
  • Loading branch information
davidlange6 committed Dec 8, 2015
2 parents ebeb0b1 + 8298bb8 commit 239b1de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
4 changes: 1 addition & 3 deletions CommonTools/Utils/interface/TMVAEvaluator.h
Expand Up @@ -17,7 +17,6 @@ class TMVAEvaluator {

public:
TMVAEvaluator();
~TMVAEvaluator();

void initialize(const std::string & options, const std::string & method, const std::string & weightFile,
const std::vector<std::string> & variables, const std::vector<std::string> & spectators, bool useGBRForest=false, bool useAdaBoost=false);
Expand All @@ -33,13 +32,12 @@ class TMVAEvaluator {
bool mIsInitialized;
bool mUsingGBRForest;
bool mUseAdaBoost;
bool mReleaseAtEnd;

std::string mMethod;
mutable std::mutex m_mutex;
[[cms::thread_guard("m_mutex")]] std::unique_ptr<TMVA::Reader> mReader;
std::unique_ptr<TMVA::IMethod> mIMethod;
std::unique_ptr<const GBRForest> mGBRForest;
std::shared_ptr<const GBRForest> mGBRForest;

[[cms::thread_guard("m_mutex")]] mutable std::map<std::string,std::pair<size_t,float>> mVariables;
[[cms::thread_guard("m_mutex")]] mutable std::map<std::string,std::pair<size_t,float>> mSpectators;
Expand Down
13 changes: 3 additions & 10 deletions CommonTools/Utils/src/TMVAEvaluator.cc
Expand Up @@ -8,18 +8,11 @@


TMVAEvaluator::TMVAEvaluator() :
mIsInitialized(false), mUsingGBRForest(false), mUseAdaBoost(false), mReleaseAtEnd(false)
mIsInitialized(false), mUsingGBRForest(false), mUseAdaBoost(false)
{
}


TMVAEvaluator::~TMVAEvaluator()
{
if (mReleaseAtEnd)
mGBRForest.release();
}


void TMVAEvaluator::initialize(const std::string & options, const std::string & method, const std::string & weightFile,
const std::vector<std::string> & variables, const std::vector<std::string> & spectators, bool useGBRForest, bool useAdaBoost)
{
Expand Down Expand Up @@ -72,12 +65,12 @@ void TMVAEvaluator::initializeGBRForest(const GBRForest* gbrForest, const std::v
for(std::vector<std::string>::const_iterator it = spectators.begin(); it!=spectators.end(); ++it)
mSpectators.insert( std::make_pair( *it, std::make_pair( it - spectators.begin(), 0. ) ) );

mGBRForest.reset( gbrForest );
// do not take ownership if getting GBRForest from an external source
mGBRForest = std::shared_ptr<const GBRForest>(gbrForest, [](const GBRForest*) {} );

mIsInitialized = true;
mUsingGBRForest = true;
mUseAdaBoost = useAdaBoost;
mReleaseAtEnd = true; // need to release ownership at the end if getting GBRForest from an external source
}


Expand Down

0 comments on commit 239b1de

Please sign in to comment.