CMS 3D CMS Logo

CSCGainsDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCGAINSDBCONDITIONS_H
2 #define _CSCGAINSDBCONDITIONS_H
3 
13 #include <cmath>
14 #include <memory>
15 
19 
21 public:
23  ~CSCGainsDBConditions() override;
24 
25  inline static CSCDBGains *prefillDBGains();
26 
27  typedef std::unique_ptr<CSCDBGains> ReturnType;
28 
30 
31 private:
32  // ----------member data ---------------------------
34  const edm::IOVSyncValue &,
35  edm::ValidityInterval &) override;
37 };
38 
39 #include <fstream>
40 #include <iostream>
41 #include <vector>
42 
43 // to workaround plugin library
45  // const int MAX_SIZE = 273024;//for ME1a unganged
46  const int MAX_SIZE = 252288;
47  const int FACTOR = 1000;
48  const int MAX_SHORT = 32767;
49  CSCDBGains *cndbgains = new CSCDBGains();
50 
51  int db_index;
52  float db_gainslope; // db_intercpt, db_chisq;
53  std::vector<int> db_index_id;
54  std::vector<float> db_slope;
55  std::vector<float> db_intercept;
56  std::vector<float> db_chi2;
57  int new_index;
58  float new_gainslope, new_intercpt, new_chisq;
59  std::vector<int> new_cham_id;
60  std::vector<int> new_index_id;
61  std::vector<int> new_strips;
62  std::vector<float> new_slope;
63  std::vector<float> new_intercept;
64  std::vector<float> new_chi2;
65 
66  int counter;
67 
68  std::ifstream dbdata;
69  dbdata.open("old_dbgains.dat", std::ios::in);
70  if (!dbdata) {
71  std::cerr << "Error: old_dbgains.dat -> no such file!" << std::endl;
72  exit(1);
73  }
74 
75  while (!dbdata.eof()) {
76  dbdata >> db_index >> db_gainslope;
77  db_index_id.push_back(db_index);
78  db_slope.push_back(db_gainslope);
79  // db_intercept.push_back(db_intercpt);
80  // db_chi2.push_back(db_chisq);
81  }
82  dbdata.close();
83 
84  std::ifstream newdata;
85  newdata.open("gains.dat", std::ios::in);
86  if (!newdata) {
87  std::cerr << "Error: gains.dat -> no such file!" << std::endl;
88  exit(1);
89  }
90 
91  while (!newdata.eof()) {
92  newdata >> new_index >> new_gainslope >> new_intercpt >> new_chisq;
93  new_index_id.push_back(new_index);
94  new_slope.push_back(new_gainslope);
95  new_intercept.push_back(new_intercpt);
96  new_chi2.push_back(new_chisq);
97  }
98  newdata.close();
99 
100  CSCDBGains::GainContainer &itemvector = cndbgains->gains;
101  itemvector.resize(MAX_SIZE);
102  cndbgains->factor_gain = (short int)(FACTOR);
103  std::cout << " myfactor " << cndbgains->factor_gain << std::endl;
104 
105  for (int i = 0; i < MAX_SIZE; ++i) {
106  itemvector[i].gain_slope = int(db_slope[i] * FACTOR + 0.5);
107  }
108 
109  for (int i = 0; i < MAX_SIZE; ++i) {
110  counter = db_index_id[i];
111  itemvector[i] = itemvector[counter];
112  itemvector[i].gain_slope = int(db_slope[i]);
113 
114  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
115  if (counter == new_index_id[k]) {
116  if ((short int)(fabs(new_slope[k] * FACTOR + 0.5)) < MAX_SHORT)
117  itemvector[counter].gain_slope = int(new_slope[k] * FACTOR + 0.5);
118  itemvector[i] = itemvector[counter];
119  }
120  }
121  if (counter > 223968) {
122  itemvector[counter].gain_slope = int(db_slope[i]);
123  itemvector[i] = itemvector[counter];
124  }
125  }
126  return cndbgains;
127 }
128 
129 #endif
CSCGainsDBConditions(const edm::ParameterSet &)
GainContainer gains
Definition: CSCDBGains.h:24
int factor_gain
Definition: CSCDBGains.h:19
ReturnType produceDBGains(const CSCDBGainsRcd &)
static CSCDBGains * prefillDBGains()
std::vector< Item > GainContainer
Definition: CSCDBGains.h:23
static std::atomic< unsigned int > counter
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
constexpr unsigned int MAX_SIZE
std::unique_ptr< CSCDBGains > ReturnType
def exit(msg="")