Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:07

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author N. Amapane, G. Cerminara
0005  */
0006 
0007 #include "CondFormats/DTObjects/interface/DTRecoConditions.h"
0008 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include <iostream>
0011 #include <algorithm>
0012 
0013 #include <TFormula.h>
0014 
0015 using std::cout;
0016 using std::endl;
0017 using std::map;
0018 using std::string;
0019 using std::vector;
0020 
0021 DTRecoConditions::DTRecoConditions() : formula(nullptr), formulaType(0), expression("[0]"), theVersion(0) {}
0022 
0023 DTRecoConditions::DTRecoConditions(const DTRecoConditions& iOther)
0024     : formula(nullptr),
0025       formulaType(0),
0026       expression(iOther.expression),
0027       payload(iOther.payload),
0028       theVersion(iOther.theVersion) {}
0029 
0030 const DTRecoConditions& DTRecoConditions::operator=(const DTRecoConditions& iOther) {
0031   delete formula.load();
0032   formula = nullptr;
0033   formulaType = 0;
0034   expression = iOther.expression;
0035   payload = iOther.payload;
0036   theVersion = iOther.theVersion;
0037   return *this;
0038 }
0039 
0040 DTRecoConditions::~DTRecoConditions() { delete formula.load(); }
0041 
0042 float DTRecoConditions::get(const DTWireId& wireid, double* x) const {
0043   map<uint32_t, vector<double> >::const_iterator slIt = payload.find(wireid.superlayerId().rawId());
0044   if (slIt == payload.end()) {
0045     throw cms::Exception("InvalidInput") << "The SLId: " << wireid.superlayerId() << " is not in the paylaod map";
0046   }
0047   const vector<double>& par = slIt->second;
0048 
0049   // Initialize if this is the first call
0050   if (formulaType == 0) {
0051     if (expression == "[0]") {
0052       formulaType = 1;
0053     } else if (expression == "par[step]") {
0054       formulaType = 2;
0055     } else {
0056       std::unique_ptr<TFormula> temp{new TFormula("DTExpr", expression.c_str())};
0057       TFormula* expected = nullptr;
0058       if (formula.compare_exchange_strong(expected, temp.get())) {
0059         //This thread set the value
0060         temp.release();
0061       }
0062       formulaType = 99;
0063     }
0064   }
0065 
0066   if (formulaType == 1 || par.size() == 1) {
0067     // Return value is simply a constant. Assume this is the case also if only one parameter exists.
0068     return par[0];
0069   } else if (formulaType == 2) {
0070     // Special case: par[i] represents the value for step i
0071     return par[unsigned(x[0])];
0072   } else {
0073     // Use the formula corresponding to expression.
0074     return (*formula).EvalPar(x, par.data());
0075   }
0076 }
0077 
0078 void DTRecoConditions::set(const DTWireId& wireid, const std::vector<double>& values) {
0079   payload[wireid.superlayerId()] = values;
0080 }
0081 
0082 DTRecoConditions::const_iterator DTRecoConditions::begin() const { return payload.begin(); }
0083 
0084 DTRecoConditions::const_iterator DTRecoConditions::end() const { return payload.end(); }