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::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  theVersion(0)
27 {}
28 
31  formulaType(0),
32  expression(iOther.expression),
33  payload(iOther.payload),
34  theVersion(iOther.theVersion)
35 {}
36 
37 const DTRecoConditions&
39 {
40  delete formula.load();
41  formula=nullptr;
42  formulaType =0;
43  expression = iOther.expression;
44  payload = iOther.payload;
45  theVersion=iOther.theVersion;
46  return *this;
47 }
48 
49 
51  delete formula.load();
52 }
53 
54 
55 float DTRecoConditions::get(const DTWireId& wireid, double* x) const {
56 
57  map<uint32_t, vector<double> >::const_iterator slIt = payload.find(wireid.superlayerId().rawId());
58  if(slIt == payload.end()) {
59  throw cms::Exception("InvalidInput") << "The SLId: " << wireid.superlayerId() << " is not in the paylaod map";
60  }
61  const vector<double>& par = slIt->second;
62 
63  // Initialize if this is the first call
64  if (formulaType==0) {
65  if (expression=="[0]") {
66  formulaType = 1;
67  } else if (expression=="par[step]") {
68  formulaType = 2;
69  } else {
70  std::unique_ptr<TFormula> temp{new TFormula("DTExpr",expression.c_str())};
71  TFormula* expected = nullptr;
72  if(formula.compare_exchange_strong(expected,temp.get())) {
73  //This thread set the value
74  temp.release();
75  }
76  formulaType = 99;
77  }
78  }
79 
80  if (formulaType==1 || par.size()==1) {
81  // Return value is simply a constant. Assume this is the case also if only one parameter exists.
82  return par[0];
83  } else if (formulaType==2) {
84  // Special case: par[i] represents the value for step i
85  return par[unsigned (x[0])];
86  } else {
87  // Use the formula corresponding to expression.
88  return (*formula).EvalPar(x,par.data());
89  }
90 }
91 
92 
93 void DTRecoConditions::set(const DTWireId& wireid, const std::vector<double>& values) {
94  payload[wireid.superlayerId()] = values;
95 }
96 
97 
99  return payload.begin();
100 }
101 
103  return payload.end();
104 }
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
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.
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...
virtual ~DTRecoConditions()
Destructor.
std::atomic< TFormula * > formula
std::string expression
std::atomic< int > formulaType