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 
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DTRecoConditions::DTRecoConditions
DTRecoConditions()
Constructor.
Definition: DTRecoConditions.cc:21
DTRecoConditions::end
const_iterator end() const
Definition: DTRecoConditions.cc:84
DDAxes::x
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
DTRecoConditions::theVersion
int theVersion
Definition: DTRecoConditions.h:83
DTRecoConditions::get
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...
Definition: DTRecoConditions.cc:42
DTRecoConditions::formula
std::atomic< TFormula * > formula
Definition: DTRecoConditions.h:64
DTRecoConditions.h
DTWireId
Definition: DTWireId.h:12
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
jets_cff.payload
payload
Definition: jets_cff.py:32
DTRecoConditions::const_iterator
std::map< uint32_t, std::vector< double > >::const_iterator const_iterator
Definition: DTRecoConditions.h:30
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
DTRecoConditions::expression
std::string expression
Definition: DTRecoConditions.h:77
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DTRecoConditions::payload
std::map< uint32_t, std::vector< double > > payload
Definition: DTRecoConditions.h:80
DTRecoConditions::formulaType
std::atomic< int > formulaType
Definition: DTRecoConditions.h:71
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
DTWireId.h
DTRecoConditions::set
void set(const DTWireId &wireid, const std::vector< double > &values)
Fill the payload.
Definition: DTRecoConditions.cc:78
Exception
Definition: hltDiff.cc:245
DTRecoConditions::~DTRecoConditions
virtual ~DTRecoConditions()
Destructor.
Definition: DTRecoConditions.cc:40
DTLayerId::superlayerId
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
genVertex_cff.x
x
Definition: genVertex_cff.py:13
Exception.h
DTRecoConditions::begin
const_iterator begin() const
Access the data.
Definition: DTRecoConditions.cc:82
DTRecoConditions
Definition: DTRecoConditions.h:28
genParticles_cff.map
map
Definition: genParticles_cff.py:11
DTRecoConditions::operator=
const DTRecoConditions & operator=(const DTRecoConditions &)
Definition: DTRecoConditions.cc:30