CMS 3D CMS Logo

CSCNoiseMatrixDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCNOISEMATRIXDBCONDITIONS_H
2 #define _CSCNOISEMATRIXDBCONDITIONS_H
3 
13 #include <cmath>
14 #include <memory>
15 
19 
21 public:
23  ~CSCNoiseMatrixDBConditions() override;
24 
25  inline static CSCDBNoiseMatrix *prefillDBNoiseMatrix();
26 
27  typedef std::unique_ptr<CSCDBNoiseMatrix> 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 
50  int new_index, db_index;
51  float db_elm33, db_elm34, db_elm44, db_elm35, db_elm45, db_elm55;
52  float db_elm46, db_elm56, db_elm66, db_elm57, db_elm67, db_elm77;
53  std::vector<int> db_index_id;
54  std::vector<float> db_elem33;
55  std::vector<float> db_elem34;
56  std::vector<float> db_elem44;
57  std::vector<float> db_elem45;
58  std::vector<float> db_elem35;
59  std::vector<float> db_elem55;
60  std::vector<float> db_elem46;
61  std::vector<float> db_elem56;
62  std::vector<float> db_elem66;
63  std::vector<float> db_elem57;
64  std::vector<float> db_elem67;
65  std::vector<float> db_elem77;
66 
67  float new_elm33, new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
68  float new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
69  std::vector<int> new_cham_id;
70  std::vector<int> new_index_id;
71  std::vector<float> new_elem33;
72  std::vector<float> new_elem34;
73  std::vector<float> new_elem44;
74  std::vector<float> new_elem45;
75  std::vector<float> new_elem35;
76  std::vector<float> new_elem55;
77  std::vector<float> new_elem46;
78  std::vector<float> new_elem56;
79  std::vector<float> new_elem66;
80  std::vector<float> new_elem57;
81  std::vector<float> new_elem67;
82  std::vector<float> new_elem77;
83 
84  CSCDBNoiseMatrix *cndbmatrix = new CSCDBNoiseMatrix();
85 
86  int counter;
87  int db_nrlines = 0;
88  int new_nrlines = 0;
89 
90  std::ifstream dbdata;
91  dbdata.open("old_dbmatrix.dat", std::ios::in);
92  if (!dbdata) {
93  std::cerr << "Error: old_dbmatrix.dat -> no such file!" << std::endl;
94  exit(1);
95  }
96 
97  while (!dbdata.eof()) {
98  dbdata >> db_index >> db_elm33 >> db_elm34 >> db_elm44 >> db_elm35 >> db_elm45 >> db_elm55 >> db_elm46 >>
99  db_elm56 >> db_elm66 >> db_elm57 >> db_elm67 >> db_elm77;
100  db_index_id.push_back(db_index);
101  db_elem33.push_back(db_elm33);
102  db_elem34.push_back(db_elm34);
103  db_elem35.push_back(db_elm35);
104  db_elem44.push_back(db_elm44);
105  db_elem45.push_back(db_elm45);
106  db_elem46.push_back(db_elm46);
107  db_elem55.push_back(db_elm55);
108  db_elem56.push_back(db_elm56);
109  db_elem57.push_back(db_elm57);
110  db_elem66.push_back(db_elm66);
111  db_elem67.push_back(db_elm67);
112  db_elem77.push_back(db_elm77);
113  db_nrlines++;
114  }
115  dbdata.close();
116 
117  std::ifstream newdata;
118  newdata.open("matrix.dat", std::ios::in);
119  if (!newdata) {
120  std::cerr << "Error: matrix.dat -> no such file!" << std::endl;
121  exit(1);
122  }
123 
124  while (!newdata.eof()) {
125  newdata >> new_index >> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >>
126  new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77;
127  // new_cham_id.push_back(new_chamber_id);
128  new_index_id.push_back(new_index);
129  new_elem33.push_back(new_elm33);
130  new_elem34.push_back(new_elm34);
131  new_elem35.push_back(new_elm35);
132  new_elem44.push_back(new_elm44);
133  new_elem45.push_back(new_elm45);
134  new_elem46.push_back(new_elm46);
135  new_elem55.push_back(new_elm55);
136  new_elem56.push_back(new_elm56);
137  new_elem57.push_back(new_elm57);
138  new_elem66.push_back(new_elm66);
139  new_elem67.push_back(new_elm67);
140  new_elem77.push_back(new_elm77);
141  new_nrlines++;
142  }
143  newdata.close();
144 
145  CSCDBNoiseMatrix::NoiseMatrixContainer &itemvector = cndbmatrix->matrix;
146  itemvector.resize(MAX_SIZE);
147  cndbmatrix->factor_noise = int(FACTOR);
148 
149  for (int i = 0; i < MAX_SIZE; ++i) {
150  itemvector[i].elem33 = (short int)(db_elem33[i] * FACTOR + 0.5);
151  itemvector[i].elem34 = (short int)(db_elem34[i] * FACTOR + 0.5);
152  itemvector[i].elem35 = (short int)(db_elem35[i] * FACTOR + 0.5);
153  itemvector[i].elem44 = (short int)(db_elem44[i] * FACTOR + 0.5);
154  itemvector[i].elem45 = (short int)(db_elem45[i] * FACTOR + 0.5);
155  itemvector[i].elem46 = (short int)(db_elem46[i] * FACTOR + 0.5);
156  itemvector[i].elem55 = (short int)(db_elem55[i] * FACTOR + 0.5);
157  itemvector[i].elem56 = (short int)(db_elem56[i] * FACTOR + 0.5);
158  itemvector[i].elem57 = (short int)(db_elem57[i] * FACTOR + 0.5);
159  itemvector[i].elem66 = (short int)(db_elem66[i] * FACTOR + 0.5);
160  itemvector[i].elem67 = (short int)(db_elem67[i] * FACTOR + 0.5);
161  itemvector[i].elem77 = (short int)(db_elem77[i] * FACTOR + 0.5);
162  }
163 
164  for (int i = 0; i < MAX_SIZE; ++i) {
165  counter = db_index_id[i];
166  itemvector[i] = itemvector[counter];
167  itemvector[i].elem33 = int(db_elem33[i]);
168  itemvector[i].elem34 = int(db_elem34[i]);
169  itemvector[i].elem35 = int(db_elem35[i]);
170  itemvector[i].elem44 = int(db_elem44[i]);
171  itemvector[i].elem45 = int(db_elem45[i]);
172  itemvector[i].elem46 = int(db_elem46[i]);
173  itemvector[i].elem55 = int(db_elem55[i]);
174  itemvector[i].elem56 = int(db_elem56[i]);
175  itemvector[i].elem57 = int(db_elem57[i]);
176  itemvector[i].elem66 = int(db_elem66[i]);
177  itemvector[i].elem67 = int(db_elem67[i]);
178  itemvector[i].elem77 = int(db_elem77[i]);
179 
180  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
181  if (counter == new_index_id[k]) {
182  if ((short int)(fabs(new_elem33[k] * FACTOR + 0.5)) < MAX_SHORT)
183  itemvector[counter].elem33 = int(new_elem33[k] * FACTOR + 0.5);
184  if ((short int)(fabs(new_elem34[k] * FACTOR + 0.5)) < MAX_SHORT)
185  itemvector[counter].elem34 = int(new_elem34[k] * FACTOR + 0.5);
186  if ((short int)(fabs(new_elem35[k] * FACTOR + 0.5)) < MAX_SHORT)
187  itemvector[counter].elem35 = int(new_elem35[k] * FACTOR + 0.5);
188  if ((short int)(fabs(new_elem44[k] * FACTOR + 0.5)) < MAX_SHORT)
189  itemvector[counter].elem44 = int(new_elem44[k] * FACTOR + 0.5);
190  if ((short int)(fabs(new_elem45[k] * FACTOR + 0.5)) < MAX_SHORT)
191  itemvector[counter].elem45 = int(new_elem45[k] * FACTOR + 0.5);
192  if ((short int)(fabs(new_elem46[k] * FACTOR + 0.5)) < MAX_SHORT)
193  itemvector[counter].elem46 = int(new_elem46[k] * FACTOR + 0.5);
194  if ((short int)(fabs(new_elem55[k] * FACTOR + 0.5)) < MAX_SHORT)
195  itemvector[counter].elem55 = int(new_elem55[k] * FACTOR + 0.5);
196  if ((short int)(fabs(new_elem56[k] * FACTOR + 0.5)) < MAX_SHORT)
197  itemvector[counter].elem56 = int(new_elem56[k] * FACTOR + 0.5);
198  if ((short int)(fabs(new_elem57[k] * FACTOR + 0.5)) < MAX_SHORT)
199  itemvector[counter].elem57 = int(new_elem57[k] * FACTOR + 0.5);
200  if ((short int)(fabs(new_elem66[k] * FACTOR + 0.5)) < MAX_SHORT)
201  itemvector[counter].elem66 = int(new_elem66[k] * FACTOR + 0.5);
202  if ((short int)(fabs(new_elem67[k] * FACTOR + 0.5)) < MAX_SHORT)
203  itemvector[counter].elem67 = int(new_elem67[k] * FACTOR + 0.5);
204  if ((short int)(fabs(new_elem77[k] * FACTOR + 0.5)) < MAX_SHORT)
205  itemvector[counter].elem77 = int(new_elem77[k] * FACTOR + 0.5);
206  itemvector[i] = itemvector[counter];
207  }
208  }
209 
210  if (counter > 223968) {
211  itemvector[counter].elem33 = int(db_elem33[i]);
212  itemvector[counter].elem34 = int(db_elem34[i]);
213  itemvector[counter].elem35 = int(db_elem35[i]);
214  itemvector[counter].elem44 = int(db_elem44[i]);
215  itemvector[counter].elem45 = int(db_elem45[i]);
216  itemvector[counter].elem46 = int(db_elem46[i]);
217  itemvector[counter].elem55 = int(db_elem55[i]);
218  itemvector[counter].elem56 = int(db_elem56[i]);
219  itemvector[counter].elem57 = int(db_elem57[i]);
220  itemvector[counter].elem66 = int(db_elem66[i]);
221  itemvector[counter].elem67 = int(db_elem67[i]);
222  itemvector[counter].elem77 = int(db_elem77[i]);
223  itemvector[i] = itemvector[counter];
224  }
225  }
226 
227  return cndbmatrix;
228 }
229 
230 #endif
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
static CSCDBNoiseMatrix * prefillDBNoiseMatrix()
std::vector< Item > NoiseMatrixContainer
std::unique_ptr< CSCDBNoiseMatrix > ReturnType
ReturnType produceDBNoiseMatrix(const CSCDBNoiseMatrixRcd &)
static std::atomic< unsigned int > counter
constexpr unsigned int MAX_SIZE
CSCNoiseMatrixDBConditions(const edm::ParameterSet &)
NoiseMatrixContainer matrix
def exit(msg="")