Skip to content

Commit

Permalink
Merge pull request #7380 from Dr15Jones/makeDTRecoConditionsThreadSafe
Browse files Browse the repository at this point in the history
Make DTRecoConditions thread safe
  • Loading branch information
cmsbuild committed Feb 3, 2015
2 parents 3db8ee2 + 9e6c46e commit bb1adf2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
13 changes: 13 additions & 0 deletions CondFormats/DTObjects/interface/DTRecoConditions.h
Expand Up @@ -19,6 +19,9 @@
#include <vector>
#include <string>
#include <stdint.h>
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
#include <atomic>
#endif

class DTWireId;
class TFormula;
Expand All @@ -29,6 +32,8 @@ class DTRecoConditions {

/// Constructor
DTRecoConditions();
DTRecoConditions(const DTRecoConditions&);
const DTRecoConditions& operator=(const DTRecoConditions&);

/// Destructor
virtual ~DTRecoConditions();
Expand Down Expand Up @@ -65,10 +70,18 @@ class DTRecoConditions {
private:

// The formula used for parametrization (transient pointer)
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
mutable std::atomic<TFormula*> formula COND_TRANSIENT;
#else
mutable TFormula* formula COND_TRANSIENT;
#endif

// Formula evalaution strategy, derived from expression and cached for efficiency reasons
#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
mutable std::atomic<int> formulaType COND_TRANSIENT;
#else
mutable int formulaType COND_TRANSIENT;
#endif

// String with the expression representing the formula used for parametrization
std::string expression;
Expand Down
26 changes: 24 additions & 2 deletions CondFormats/DTObjects/src/DTRecoConditions.cc
Expand Up @@ -25,6 +25,23 @@ DTRecoConditions::DTRecoConditions() :
expression("[0]")
{}

DTRecoConditions::DTRecoConditions(const DTRecoConditions& iOther):
formula(nullptr),
formulaType(0),
expression(iOther.expression)
{}

const DTRecoConditions&
DTRecoConditions::operator=(const DTRecoConditions& iOther)
{
delete formula.load();
formula=nullptr;
formulaType =0;
expression = iOther.expression;
return *this;
}


DTRecoConditions::~DTRecoConditions(){
delete formula;
}
Expand All @@ -45,8 +62,13 @@ float DTRecoConditions::get(const DTWireId& wireid, double* x) const {
} else if (expression=="par[step]") {
formulaType = 2;
} else {
std::unique_ptr<TFormula> temp{new TFormula("DTExpr",expression.c_str())};
TFormula* expected = nullptr;
if(formula.compare_exchange_strong(expected,temp.get())) {
//This thread set the value
temp.release();
}
formulaType = 99;
formula = new TFormula("DTExpr",expression.c_str());
}
}

Expand All @@ -58,7 +80,7 @@ float DTRecoConditions::get(const DTWireId& wireid, double* x) const {
return par[unsigned (x[0])];
} else {
// Use the formula corresponding to expression.
return formula->EvalPar(x,par.data());
return (*formula).EvalPar(x,par.data());
}
}

Expand Down

0 comments on commit bb1adf2

Please sign in to comment.