CMS 3D CMS Logo

CSCCrosstalkDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCCROSSTALKDBCONDITIONS_H
2 #define _CSCCROSSTALKDBCONDITIONS_H
3 
13 #include <cmath>
14 #include <memory>
15 
19 
21 public:
23  ~CSCCrosstalkDBConditions() override;
24 
25  inline static CSCDBCrosstalk *prefillDBCrosstalk();
26 
27  typedef std::unique_ptr<CSCDBCrosstalk> ReturnType;
28 
30 
31 private:
32  // ----------member data ---------------------------
34  const edm::IOVSyncValue &,
35  edm::ValidityInterval &) override;
36 };
37 
38 #include <fstream>
39 #include <iostream>
40 #include <vector>
41 
42 // to workaround plugin library
44  // const int MAX_SIZE = 273024; //for ME1a unganged
45  const int MAX_SIZE = 252288;
46  const int SLOPE_FACTOR = 10000000;
47  const int INTERCEPT_FACTOR = 100000;
48  const int MAX_SHORT = 32767;
49  CSCDBCrosstalk *cndbcrosstalk = new CSCDBCrosstalk();
50 
51  int db_index, new_index;
52  float db_slope_right, db_slope_left, db_intercept_right;
53  float db_intercept_left;
54  std::vector<int> db_index_id;
55  std::vector<float> db_slope_r;
56  std::vector<float> db_intercept_r;
57  std::vector<float> db_slope_l;
58  std::vector<float> db_intercept_l;
59  float new_slope_right, new_slope_left, new_intercept_right;
60  float new_intercept_left;
61  std::vector<int> new_index_id;
62  std::vector<float> new_slope_r;
63  std::vector<float> new_intercept_r;
64  std::vector<float> new_slope_l;
65  std::vector<float> new_intercept_l;
66 
67  int counter;
68 
69  std::ifstream dbdata;
70  dbdata.open("old_dbxtalk.dat", std::ios::in);
71  if (!dbdata) {
72  std::cerr << "Error: old_dbxtalk.dat -> no such file!" << std::endl;
73  exit(1);
74  }
75 
76  while (!dbdata.eof()) {
77  dbdata >> db_index >> db_slope_right >> db_intercept_right >> db_slope_left >> db_intercept_left;
78  db_index_id.push_back(db_index);
79  db_slope_r.push_back(db_slope_right);
80  db_slope_l.push_back(db_slope_left);
81  db_intercept_r.push_back(db_intercept_right);
82  db_intercept_l.push_back(db_intercept_left);
83  }
84  dbdata.close();
85 
86  std::ifstream newdata;
87  newdata.open("xtalk.dat", std::ios::in);
88  if (!newdata) {
89  std::cerr << "Error: xtalk.dat -> no such file!" << std::endl;
90  exit(1);
91  }
92 
93  while (!newdata.eof()) {
94  newdata >> new_index >> new_slope_right >> new_intercept_right >> new_slope_left >> new_intercept_left;
95  new_index_id.push_back(new_index);
96  new_slope_r.push_back(new_slope_right);
97  new_slope_l.push_back(new_slope_left);
98  new_intercept_r.push_back(new_intercept_right);
99  new_intercept_l.push_back(new_intercept_left);
100  }
101  newdata.close();
102 
103  CSCDBCrosstalk::CrosstalkContainer &itemvector = cndbcrosstalk->crosstalk;
104  itemvector.resize(MAX_SIZE);
105  cndbcrosstalk->factor_slope = int(SLOPE_FACTOR);
106  cndbcrosstalk->factor_intercept = int(INTERCEPT_FACTOR);
107 
108  for (int i = 0; i < MAX_SIZE; ++i) {
109  itemvector[i].xtalk_slope_right = (short int)(db_slope_r[i] * SLOPE_FACTOR + 0.5);
110  itemvector[i].xtalk_intercept_right = (short int)(db_intercept_r[i] * INTERCEPT_FACTOR + 0.5);
111  itemvector[i].xtalk_slope_left = (short int)(db_slope_l[i] * SLOPE_FACTOR + 0.5);
112  itemvector[i].xtalk_intercept_left = (short int)(db_intercept_l[i] * INTERCEPT_FACTOR + 0.5);
113  }
114 
115  for (int i = 0; i < MAX_SIZE; ++i) {
116  counter = db_index_id[i];
117  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
118  if (counter == new_index_id[k]) {
119  if ((short int)(fabs(new_slope_r[k] * SLOPE_FACTOR + 0.5)) < MAX_SHORT)
120  itemvector[counter].xtalk_slope_right = int(new_slope_r[k] * SLOPE_FACTOR + 0.5);
121  if ((short int)(fabs(new_intercept_r[k] * INTERCEPT_FACTOR + 0.5)) < MAX_SHORT)
122  itemvector[counter].xtalk_intercept_right = int(new_intercept_r[k] * INTERCEPT_FACTOR + 0.5);
123  if ((short int)(fabs(new_slope_l[k] * SLOPE_FACTOR + 0.5)) < MAX_SHORT)
124  itemvector[counter].xtalk_slope_left = int(new_slope_l[k] * SLOPE_FACTOR + 0.5);
125  if ((short int)(fabs(new_intercept_l[k] * INTERCEPT_FACTOR + 0.5)) < MAX_SHORT)
126  itemvector[counter].xtalk_intercept_left = int(new_intercept_l[k] * INTERCEPT_FACTOR + 0.5);
127  itemvector[i] = itemvector[counter];
128  // std::cout<<" counter "<<counter <<" dbindex "<<new_index_id[k]<<"
129  // dbslope " <<db_slope_r[k]<<" new slope "<<new_slope_r[k]<<std::endl;
130  }
131  }
132 
133  if (counter > 223968) {
134  itemvector[counter].xtalk_slope_right = int(db_slope_r[i]);
135  itemvector[counter].xtalk_slope_left = int(db_slope_l[i]);
136  itemvector[counter].xtalk_intercept_right = int(db_intercept_r[i]);
137  itemvector[counter].xtalk_intercept_left = int(db_intercept_l[i]);
138  }
139  }
140 
141  return cndbcrosstalk;
142 }
143 
144 #endif
CSCCrosstalkDBConditions(const edm::ParameterSet &)
ReturnType produceDBCrosstalk(const CSCDBCrosstalkRcd &)
static CSCDBCrosstalk * prefillDBCrosstalk()
std::vector< Item > CrosstalkContainer
std::unique_ptr< CSCDBCrosstalk > ReturnType
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
static std::atomic< unsigned int > counter
constexpr unsigned int MAX_SIZE
CrosstalkContainer crosstalk
def exit(msg="")