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 
29  ReturnType produceDBCrosstalk(const CSCDBCrosstalkRcd &);
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  int db_nrlines = 0;
69  int new_nrlines = 0;
70 
71  std::ifstream dbdata;
72  dbdata.open("old_dbxtalk.dat", std::ios::in);
73  if (!dbdata) {
74  std::cerr << "Error: old_dbxtalk.dat -> no such file!" << std::endl;
75  exit(1);
76  }
77 
78  while (!dbdata.eof()) {
79  dbdata >> db_index >> db_slope_right >> db_intercept_right >> db_slope_left >> db_intercept_left;
80  db_index_id.push_back(db_index);
81  db_slope_r.push_back(db_slope_right);
82  db_slope_l.push_back(db_slope_left);
83  db_intercept_r.push_back(db_intercept_right);
84  db_intercept_l.push_back(db_intercept_left);
85  db_nrlines++;
86  }
87  dbdata.close();
88 
89  std::ifstream newdata;
90  newdata.open("xtalk.dat", std::ios::in);
91  if (!newdata) {
92  std::cerr << "Error: xtalk.dat -> no such file!" << std::endl;
93  exit(1);
94  }
95 
96  while (!newdata.eof()) {
97  newdata >> new_index >> new_slope_right >> new_intercept_right >> new_slope_left >> new_intercept_left;
98  new_index_id.push_back(new_index);
99  new_slope_r.push_back(new_slope_right);
100  new_slope_l.push_back(new_slope_left);
101  new_intercept_r.push_back(new_intercept_right);
102  new_intercept_l.push_back(new_intercept_left);
103  new_nrlines++;
104  }
105  newdata.close();
106 
107  CSCDBCrosstalk::CrosstalkContainer &itemvector = cndbcrosstalk->crosstalk;
108  itemvector.resize(MAX_SIZE);
109  cndbcrosstalk->factor_slope = int(SLOPE_FACTOR);
110  cndbcrosstalk->factor_intercept = int(INTERCEPT_FACTOR);
111 
112  for (int i = 0; i < MAX_SIZE; ++i) {
113  itemvector[i].xtalk_slope_right = (short int)(db_slope_r[i] * SLOPE_FACTOR + 0.5);
114  itemvector[i].xtalk_intercept_right = (short int)(db_intercept_r[i] * INTERCEPT_FACTOR + 0.5);
115  itemvector[i].xtalk_slope_left = (short int)(db_slope_l[i] * SLOPE_FACTOR + 0.5);
116  itemvector[i].xtalk_intercept_left = (short int)(db_intercept_l[i] * INTERCEPT_FACTOR + 0.5);
117  }
118 
119  for (int i = 0; i < MAX_SIZE; ++i) {
120  counter = db_index_id[i];
121  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
122  if (counter == new_index_id[k]) {
123  if ((short int)(fabs(new_slope_r[k] * SLOPE_FACTOR + 0.5)) < MAX_SHORT)
124  itemvector[counter].xtalk_slope_right = int(new_slope_r[k] * SLOPE_FACTOR + 0.5);
125  if ((short int)(fabs(new_intercept_r[k] * INTERCEPT_FACTOR + 0.5)) < MAX_SHORT)
126  itemvector[counter].xtalk_intercept_right = int(new_intercept_r[k] * INTERCEPT_FACTOR + 0.5);
127  if ((short int)(fabs(new_slope_l[k] * SLOPE_FACTOR + 0.5)) < MAX_SHORT)
128  itemvector[counter].xtalk_slope_left = int(new_slope_l[k] * SLOPE_FACTOR + 0.5);
129  if ((short int)(fabs(new_intercept_l[k] * INTERCEPT_FACTOR + 0.5)) < MAX_SHORT)
130  itemvector[counter].xtalk_intercept_left = int(new_intercept_l[k] * INTERCEPT_FACTOR + 0.5);
131  itemvector[i] = itemvector[counter];
132  // std::cout<<" counter "<<counter <<" dbindex "<<new_index_id[k]<<"
133  // dbslope " <<db_slope_r[k]<<" new slope "<<new_slope_r[k]<<std::endl;
134  }
135  }
136 
137  if (counter > 223968) {
138  itemvector[counter].xtalk_slope_right = int(db_slope_r[i]);
139  itemvector[counter].xtalk_slope_left = int(db_slope_l[i]);
140  itemvector[counter].xtalk_intercept_right = int(db_intercept_r[i]);
141  itemvector[counter].xtalk_intercept_left = int(db_intercept_l[i]);
142  }
143  }
144 
145  return cndbcrosstalk;
146 }
147 
148 #endif
CSCCrosstalkDBConditions(const edm::ParameterSet &)
ReturnType produceDBCrosstalk(const CSCDBCrosstalkRcd &)
static CSCDBCrosstalk * prefillDBCrosstalk()
std::vector< Item > CrosstalkContainer
std::unique_ptr< CSCDBCrosstalk > ReturnType
int k[5][pyjets_maxn]
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
static std::atomic< unsigned int > counter
CrosstalkContainer crosstalk