CMS 3D CMS Logo

DTRecoConditions.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author N. Amapane, G. Cerminara
5  */
6 
10 #include <iostream>
11 #include <algorithm>
12 
13 #include <TFormula.h>
14 
15 using std::cout;
16 using std::endl;
17 using std::map;
18 using std::string;
19 using std::vector;
20 
21 DTRecoConditions::DTRecoConditions() : formula(nullptr), formulaType(0), expression("[0]"), theVersion(0) {}
22 
24  : formula(nullptr),
25  formulaType(0),
26  expression(iOther.expression),
27  payload(iOther.payload),
28  theVersion(iOther.theVersion) {}
29 
31  delete formula.load();
32  formula = nullptr;
33  formulaType = 0;
34  expression = iOther.expression;
35  payload = iOther.payload;
36  theVersion = iOther.theVersion;
37  return *this;
38 }
39 
41 
42 float DTRecoConditions::get(const DTWireId& wireid, double* x) const {
43  map<uint32_t, vector<double> >::const_iterator slIt = payload.find(wireid.superlayerId().rawId());
44  if (slIt == payload.end()) {
45  throw cms::Exception("InvalidInput") << "The SLId: " << wireid.superlayerId() << " is not in the paylaod map";
46  }
47  const vector<double>& par = slIt->second;
48 
49  // Initialize if this is the first call
50  if (formulaType == 0) {
51  if (expression == "[0]") {
52  formulaType = 1;
53  } else if (expression == "par[step]") {
54  formulaType = 2;
55  } else {
56  std::unique_ptr<TFormula> temp{new TFormula("DTExpr", expression.c_str())};
57  TFormula* expected = nullptr;
58  if (formula.compare_exchange_strong(expected, temp.get())) {
59  //This thread set the value
60  temp.release();
61  }
62  formulaType = 99;
63  }
64  }
65 
66  if (formulaType == 1 || par.size() == 1) {
67  // Return value is simply a constant. Assume this is the case also if only one parameter exists.
68  return par[0];
69  } else if (formulaType == 2) {
70  // Special case: par[i] represents the value for step i
71  return par[unsigned(x[0])];
72  } else {
73  // Use the formula corresponding to expression.
74  return (*formula).EvalPar(x, par.data());
75  }
76 }
77 
78 void DTRecoConditions::set(const DTWireId& wireid, const std::vector<double>& values) {
79  payload[wireid.superlayerId()] = values;
80 }
81 
83 
const_iterator begin() const
Access the data.
float get(const DTWireId &wireid, double *x=nullptr) const
Get the value correspoding to the given WireId, / using x[] as parameters of the parametrization when...
void set(const DTWireId &wireid, const std::vector< double > &values)
Fill the payload.
std::map< uint32_t, std::vector< double > > payload
std::map< uint32_t, std::vector< double > >::const_iterator const_iterator
const_iterator end() const
const DTRecoConditions & operator=(const DTRecoConditions &)
DTRecoConditions()
Constructor.
virtual ~DTRecoConditions()
Destructor.
std::atomic< TFormula * > formula
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::string expression
float x
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:48
std::atomic< int > formulaType