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 
88  std::ifstream dbdata;
89  dbdata.open("old_dbmatrix.dat", std::ios::in);
90  if (!dbdata) {
91  std::cerr << "Error: old_dbmatrix.dat -> no such file!" << std::endl;
92  exit(1);
93  }
94 
95  while (!dbdata.eof()) {
96  dbdata >> db_index >> db_elm33 >> db_elm34 >> db_elm44 >> db_elm35 >> db_elm45 >> db_elm55 >> db_elm46 >>
97  db_elm56 >> db_elm66 >> db_elm57 >> db_elm67 >> db_elm77;
98  db_index_id.push_back(db_index);
99  db_elem33.push_back(db_elm33);
100  db_elem34.push_back(db_elm34);
101  db_elem35.push_back(db_elm35);
102  db_elem44.push_back(db_elm44);
103  db_elem45.push_back(db_elm45);
104  db_elem46.push_back(db_elm46);
105  db_elem55.push_back(db_elm55);
106  db_elem56.push_back(db_elm56);
107  db_elem57.push_back(db_elm57);
108  db_elem66.push_back(db_elm66);
109  db_elem67.push_back(db_elm67);
110  db_elem77.push_back(db_elm77);
111  }
112  dbdata.close();
113 
114  std::ifstream newdata;
115  newdata.open("matrix.dat", std::ios::in);
116  if (!newdata) {
117  std::cerr << "Error: matrix.dat -> no such file!" << std::endl;
118  exit(1);
119  }
120 
121  while (!newdata.eof()) {
122  newdata >> new_index >> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >>
123  new_elm56 >> new_elm66 >> new_elm57 >> new_elm67 >> new_elm77;
124  // new_cham_id.push_back(new_chamber_id);
125  new_index_id.push_back(new_index);
126  new_elem33.push_back(new_elm33);
127  new_elem34.push_back(new_elm34);
128  new_elem35.push_back(new_elm35);
129  new_elem44.push_back(new_elm44);
130  new_elem45.push_back(new_elm45);
131  new_elem46.push_back(new_elm46);
132  new_elem55.push_back(new_elm55);
133  new_elem56.push_back(new_elm56);
134  new_elem57.push_back(new_elm57);
135  new_elem66.push_back(new_elm66);
136  new_elem67.push_back(new_elm67);
137  new_elem77.push_back(new_elm77);
138  }
139  newdata.close();
140 
141  CSCDBNoiseMatrix::NoiseMatrixContainer &itemvector = cndbmatrix->matrix;
142  itemvector.resize(MAX_SIZE);
143  cndbmatrix->factor_noise = int(FACTOR);
144 
145  for (int i = 0; i < MAX_SIZE; ++i) {
146  itemvector[i].elem33 = (short int)(db_elem33[i] * FACTOR + 0.5);
147  itemvector[i].elem34 = (short int)(db_elem34[i] * FACTOR + 0.5);
148  itemvector[i].elem35 = (short int)(db_elem35[i] * FACTOR + 0.5);
149  itemvector[i].elem44 = (short int)(db_elem44[i] * FACTOR + 0.5);
150  itemvector[i].elem45 = (short int)(db_elem45[i] * FACTOR + 0.5);
151  itemvector[i].elem46 = (short int)(db_elem46[i] * FACTOR + 0.5);
152  itemvector[i].elem55 = (short int)(db_elem55[i] * FACTOR + 0.5);
153  itemvector[i].elem56 = (short int)(db_elem56[i] * FACTOR + 0.5);
154  itemvector[i].elem57 = (short int)(db_elem57[i] * FACTOR + 0.5);
155  itemvector[i].elem66 = (short int)(db_elem66[i] * FACTOR + 0.5);
156  itemvector[i].elem67 = (short int)(db_elem67[i] * FACTOR + 0.5);
157  itemvector[i].elem77 = (short int)(db_elem77[i] * FACTOR + 0.5);
158  }
159 
160  for (int i = 0; i < MAX_SIZE; ++i) {
161  counter = db_index_id[i];
162  itemvector[i] = itemvector[counter];
163  itemvector[i].elem33 = int(db_elem33[i]);
164  itemvector[i].elem34 = int(db_elem34[i]);
165  itemvector[i].elem35 = int(db_elem35[i]);
166  itemvector[i].elem44 = int(db_elem44[i]);
167  itemvector[i].elem45 = int(db_elem45[i]);
168  itemvector[i].elem46 = int(db_elem46[i]);
169  itemvector[i].elem55 = int(db_elem55[i]);
170  itemvector[i].elem56 = int(db_elem56[i]);
171  itemvector[i].elem57 = int(db_elem57[i]);
172  itemvector[i].elem66 = int(db_elem66[i]);
173  itemvector[i].elem67 = int(db_elem67[i]);
174  itemvector[i].elem77 = int(db_elem77[i]);
175 
176  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
177  if (counter == new_index_id[k]) {
178  if ((short int)(fabs(new_elem33[k] * FACTOR + 0.5)) < MAX_SHORT)
179  itemvector[counter].elem33 = int(new_elem33[k] * FACTOR + 0.5);
180  if ((short int)(fabs(new_elem34[k] * FACTOR + 0.5)) < MAX_SHORT)
181  itemvector[counter].elem34 = int(new_elem34[k] * FACTOR + 0.5);
182  if ((short int)(fabs(new_elem35[k] * FACTOR + 0.5)) < MAX_SHORT)
183  itemvector[counter].elem35 = int(new_elem35[k] * FACTOR + 0.5);
184  if ((short int)(fabs(new_elem44[k] * FACTOR + 0.5)) < MAX_SHORT)
185  itemvector[counter].elem44 = int(new_elem44[k] * FACTOR + 0.5);
186  if ((short int)(fabs(new_elem45[k] * FACTOR + 0.5)) < MAX_SHORT)
187  itemvector[counter].elem45 = int(new_elem45[k] * FACTOR + 0.5);
188  if ((short int)(fabs(new_elem46[k] * FACTOR + 0.5)) < MAX_SHORT)
189  itemvector[counter].elem46 = int(new_elem46[k] * FACTOR + 0.5);
190  if ((short int)(fabs(new_elem55[k] * FACTOR + 0.5)) < MAX_SHORT)
191  itemvector[counter].elem55 = int(new_elem55[k] * FACTOR + 0.5);
192  if ((short int)(fabs(new_elem56[k] * FACTOR + 0.5)) < MAX_SHORT)
193  itemvector[counter].elem56 = int(new_elem56[k] * FACTOR + 0.5);
194  if ((short int)(fabs(new_elem57[k] * FACTOR + 0.5)) < MAX_SHORT)
195  itemvector[counter].elem57 = int(new_elem57[k] * FACTOR + 0.5);
196  if ((short int)(fabs(new_elem66[k] * FACTOR + 0.5)) < MAX_SHORT)
197  itemvector[counter].elem66 = int(new_elem66[k] * FACTOR + 0.5);
198  if ((short int)(fabs(new_elem67[k] * FACTOR + 0.5)) < MAX_SHORT)
199  itemvector[counter].elem67 = int(new_elem67[k] * FACTOR + 0.5);
200  if ((short int)(fabs(new_elem77[k] * FACTOR + 0.5)) < MAX_SHORT)
201  itemvector[counter].elem77 = int(new_elem77[k] * FACTOR + 0.5);
202  itemvector[i] = itemvector[counter];
203  }
204  }
205 
206  if (counter > 223968) {
207  itemvector[counter].elem33 = int(db_elem33[i]);
208  itemvector[counter].elem34 = int(db_elem34[i]);
209  itemvector[counter].elem35 = int(db_elem35[i]);
210  itemvector[counter].elem44 = int(db_elem44[i]);
211  itemvector[counter].elem45 = int(db_elem45[i]);
212  itemvector[counter].elem46 = int(db_elem46[i]);
213  itemvector[counter].elem55 = int(db_elem55[i]);
214  itemvector[counter].elem56 = int(db_elem56[i]);
215  itemvector[counter].elem57 = int(db_elem57[i]);
216  itemvector[counter].elem66 = int(db_elem66[i]);
217  itemvector[counter].elem67 = int(db_elem67[i]);
218  itemvector[counter].elem77 = int(db_elem77[i]);
219  itemvector[i] = itemvector[counter];
220  }
221  }
222 
223  return cndbmatrix;
224 }
225 
226 #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="")