CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::string;
16 using std::map;
17 using std::vector;
18 using std::cout;
19 using std::endl;
20 
21 
24  formulaType(0),
25  expression("[0]")
26 {}
27 
30  formulaType(0),
31  expression(iOther.expression)
32 {}
33 
34 const DTRecoConditions&
36 {
37  delete formula.load();
38  formula=nullptr;
39  formulaType =0;
40  expression = iOther.expression;
41  return *this;
42 }
43 
44 
46  delete formula.load();
47 }
48 
49 
50 float DTRecoConditions::get(const DTWireId& wireid, double* x) const {
51 
52  map<uint32_t, vector<double> >::const_iterator slIt = payload.find(wireid.superlayerId().rawId());
53  if(slIt == payload.end()) {
54  throw cms::Exception("InvalidInput") << "The SLId: " << wireid.superlayerId() << " is not in the paylaod map";
55  }
56  const vector<double>& par = slIt->second;
57 
58  // Initialize if this is the first call
59  if (formulaType==0) {
60  if (expression=="[0]") {
61  formulaType = 1;
62  } else if (expression=="par[step]") {
63  formulaType = 2;
64  } else {
65  std::unique_ptr<TFormula> temp{new TFormula("DTExpr",expression.c_str())};
66  TFormula* expected = nullptr;
67  if(formula.compare_exchange_strong(expected,temp.get())) {
68  //This thread set the value
69  temp.release();
70  }
71  formulaType = 99;
72  }
73  }
74 
75  if (formulaType==1 || par.size()==1) {
76  // Return value is simply a constant. Assume this is the case also if only one parameter exists.
77  return par[0];
78  } else if (formulaType==2) {
79  // Special case: par[i] represents the value for step i
80  return par[unsigned (x[0])];
81  } else {
82  // Use the formula corresponding to expression.
83  return (*formula).EvalPar(x,par.data());
84  }
85 }
86 
87 
88 void DTRecoConditions::set(const DTWireId& wireid, const std::vector<double>& values) {
89  payload[wireid.superlayerId()] = values;
90 }
91 
92 
94  return payload.begin();
95 }
96 
98  return payload.end();
99 }
const_iterator end() const
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
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:59
#define nullptr
float get(const DTWireId &wireid, double *x=0) const
Get the value correspoding to the given WireId, / using x[] as parameters of the parametrization wh...
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const DTRecoConditions & operator=(const DTRecoConditions &)
DTRecoConditions()
Constructor.
const_iterator begin() const
Access the data.
virtual ~DTRecoConditions()
Destructor.
std::atomic< TFormula * > formula
std::string expression
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
std::atomic< int > formulaType