CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BaseFunction.h
Go to the documentation of this file.
1 
6 #ifndef BaseFunction_h
7 #define BaseFunction_h
8 
9 #include <iostream>
10 #include <vector>
11 #include <cstdlib>
13 
14 class BaseFunction {
15 public:
17 
19  BaseFunction(const MuScleFitDBobject* dbObject) {
20  functionId_ = dbObject->identifiers;
21  parVecVec_ = dbObject->parameters;
22  // Needed for the tests in convertToArrays
23  iterationNum_ = functionId_.size() - 1;
24  }
25 
27  std::vector<int> identifiers() const { return functionId_; }
29  std::vector<double> parameters() const { return parVecVec_; }
31  std::vector<double> fitQuality() const { return parVecVec_; }
32 
33 protected:
35  template <class T>
36  void convertToArrays(T**& function_, const std::vector<T*>& functionVec_);
37 
38  std::vector<int> functionId_;
39  std::vector<double> parVecVec_;
40  std::vector<double> fitQuality_;
41  // We will use the array for the function calls because it is faster than the vector for random access.
42  double** parArray_;
43  double** fitQualityArray_;
45 };
46 
47 template <class T>
48 void BaseFunction::convertToArrays(T**& function_, const std::vector<T*>& functionVec_) {
49  // Check for consistency of number of passed parameters and number of required parameters.
50  int totParNums = 0;
51  typename std::vector<T*>::const_iterator funcIt = functionVec_.begin();
52  for (; funcIt != functionVec_.end(); ++funcIt) {
53  totParNums += (*funcIt)->parNum();
54  }
55  int parVecVecSize = parVecVec_.size();
56  int functionVecSize = functionVec_.size();
57  if (functionVecSize != iterationNum_ + 1) {
58  std::cout << "Error: inconsistent number of functions(" << functionVecSize << ") and iterations("
59  << iterationNum_ + 1 << ")" << std::endl;
60  exit(1);
61  } else if (totParNums != parVecVecSize) {
62  std::cout << "Error: inconsistent total number of requested parameters(" << totParNums << ") and parameters read("
63  << parVecVecSize << ")" << std::endl;
64  exit(1);
65  }
66  // else if( parVecVecSize != functionVecSize ) {
67  // std::cout << "Error: inconsistent number of functions("<<functionVecSize<<") and parameter sets("<<parVecVecSize<<")" << std::endl;
68  // exit(1);
69  // }
70  // else if( parVecVecSize != iterationNum_+1 ) {
71  // std::cout << "Error: inconsistent number of parameter sets("<<parVecVecSize<<") and iterations("<<iterationNum_+1<<")" << std::endl;
72  // exit(1);
73  // }
74  // parArray_ = new double*[parVecVecSize];
75 
76  parArray_ = new double*[functionVecSize];
77 
78  // std::vector<double>::const_iterator parVec = parVecVec_.begin();
79  // iterationNum_ starts from 0.
80  function_ = new T*[functionVecSize];
81  typename std::vector<T*>::const_iterator func = functionVec_.begin();
82  std::vector<double>::const_iterator parVec = parVecVec_.begin();
83 
84  int iterationCounter = 0;
85  for (; func != functionVec_.end(); ++func, ++iterationCounter) {
86  // Loop on the parameters size for each function and create corresponding parameter arrays
87  int parNum = (*func)->parNum();
88  parArray_[iterationCounter] = new double[parNum];
89  for (int par = 0; par < parNum; ++par) {
90  parArray_[iterationCounter][par] = *parVec;
91  ++parVec;
92  }
93 
94  // parArray_[iterationCounter] = new double[parVec->size()];
95  // std::vector<double>::const_iterator par = parVec->begin();
96  // int parNum = 0;
97  // for ( ; par != parVec->end(); ++par, ++parNum ) {
98  // parArray_[iterationCounter][parNum] = *par;
99  // // std::cout << "parameter["<<parNum<<"] = " << parArray_[iterationCounter][parNum] << std::endl;
100  // }
101  // // return make_pair(parameters, parameterErrors);
102 
103  function_[iterationCounter] = *func;
104  }
105 }
106 
107 #endif // BaseFunction_h
BaseFunction(const MuScleFitDBobject *dbObject)
Constructor when receiving database parameters.
Definition: BaseFunction.h:19
std::vector< int > identifiers() const
Return the vector of function identifiers.
Definition: BaseFunction.h:27
std::vector< double > parVecVec_
Definition: BaseFunction.h:39
void convertToArrays(T **&function_, const std::vector< T * > &functionVec_)
Convert vectors to arrays for faster random access. The first pointer is replaced, thus it is taken by reference.
Definition: BaseFunction.h:48
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
std::vector< double > fitQuality() const
Return the vector of fit quality values.
Definition: BaseFunction.h:31
std::vector< double > fitQuality_
Definition: BaseFunction.h:40
double ** fitQualityArray_
Definition: BaseFunction.h:43
std::vector< int > identifiers
std::vector< int > functionId_
Definition: BaseFunction.h:38
std::vector< double > parameters() const
Return the vector of parameters.
Definition: BaseFunction.h:29
tuple cout
Definition: gather_cfg.py:144
long double T
double ** parArray_
Definition: BaseFunction.h:42
std::vector< double > parameters