test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCNoiseMatrixDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCNOISEMATRIXDBCONDITIONS_H
2 #define _CSCNOISEMATRIXDBCONDITIONS_H
3 
4 #include <memory>
5 #include <cmath>
15 
19 
21  public:
24 
25  inline static CSCDBNoiseMatrix * prefillDBNoiseMatrix();
26 
27  typedef const CSCDBNoiseMatrix * ReturnType;
28 
30 
31  private:
32  // ----------member data ---------------------------
35 
36 };
37 
38 
39 #include<fstream>
40 #include<vector>
41 #include<iostream>
42 
43 // to workaround plugin library
45 {
46  //const int MAX_SIZE = 273024; //for ME1a unganged
47  const int MAX_SIZE = 252288;
48  const int FACTOR=1000;
49  const int MAX_SHORT= 32767;
50 
51  int new_index, db_index;
52  float db_elm33,db_elm34, db_elm44, db_elm35, db_elm45, db_elm55;
53  float db_elm46, db_elm56, db_elm66, db_elm57, db_elm67, db_elm77;
54  std::vector<int> db_index_id;
55  std::vector<float> db_elem33;
56  std::vector<float> db_elem34;
57  std::vector<float> db_elem44;
58  std::vector<float> db_elem45;
59  std::vector<float> db_elem35;
60  std::vector<float> db_elem55;
61  std::vector<float> db_elem46;
62  std::vector<float> db_elem56;
63  std::vector<float> db_elem66;
64  std::vector<float> db_elem57;
65  std::vector<float> db_elem67;
66  std::vector<float> db_elem77;
67 
68 
69  float new_elm33,new_elm34, new_elm44, new_elm35, new_elm45, new_elm55;
70  float new_elm46, new_elm56, new_elm66, new_elm57, new_elm67, new_elm77;
71  std::vector<int> new_cham_id;
72  std::vector<int> new_index_id;
73  std::vector<float> new_elem33;
74  std::vector<float> new_elem34;
75  std::vector<float> new_elem44;
76  std::vector<float> new_elem45;
77  std::vector<float> new_elem35;
78  std::vector<float> new_elem55;
79  std::vector<float> new_elem46;
80  std::vector<float> new_elem56;
81  std::vector<float> new_elem66;
82  std::vector<float> new_elem57;
83  std::vector<float> new_elem67;
84  std::vector<float> new_elem77;
85 
86  CSCDBNoiseMatrix * cndbmatrix = new CSCDBNoiseMatrix();
87 
88  int counter;
89  int db_nrlines=0;
90  int new_nrlines=0;
91 
92  std::ifstream dbdata;
93  dbdata.open("old_dbmatrix.dat",std::ios::in);
94  if(!dbdata) {
95  std::cerr <<"Error: old_dbmatrix.dat -> no such file!"<< std::endl;
96  exit(1);
97  }
98 
99  while (!dbdata.eof() ) {
100  dbdata >> db_index >> db_elm33 >> db_elm34 >> db_elm44 >> db_elm35 >> db_elm45 >> db_elm55 >> db_elm46 >> db_elm56 >> db_elm66 >> db_elm57 >> db_elm67 >> db_elm77 ;
101  db_index_id.push_back(db_index);
102  db_elem33.push_back(db_elm33);
103  db_elem34.push_back(db_elm34);
104  db_elem35.push_back(db_elm35);
105  db_elem44.push_back(db_elm44);
106  db_elem45.push_back(db_elm45);
107  db_elem46.push_back(db_elm46);
108  db_elem55.push_back(db_elm55);
109  db_elem56.push_back(db_elm56);
110  db_elem57.push_back(db_elm57);
111  db_elem66.push_back(db_elm66);
112  db_elem67.push_back(db_elm67);
113  db_elem77.push_back(db_elm77);
114  db_nrlines++;
115  }
116  dbdata.close();
117 
118  std::ifstream newdata;
119  newdata.open("matrix.dat",std::ios::in);
120  if(!newdata) {
121  std::cerr <<"Error: matrix.dat -> no such file!"<< std::endl;
122  exit(1);
123  }
124 
125  while (!newdata.eof() ) {
126  newdata >> new_index>> new_elm33 >> new_elm34 >> new_elm44 >> new_elm35 >> new_elm45 >> new_elm55 >> new_elm46 >> 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 
165  for(int i=0; i<MAX_SIZE;++i){
166  counter=db_index_id[i];
167  itemvector[i] = itemvector[counter];
168  itemvector[i].elem33 = int (db_elem33[i]);
169  itemvector[i].elem34 = int (db_elem34[i]);
170  itemvector[i].elem35 = int (db_elem35[i]);
171  itemvector[i].elem44 = int (db_elem44[i]);
172  itemvector[i].elem45 = int (db_elem45[i]);
173  itemvector[i].elem46 = int (db_elem46[i]);
174  itemvector[i].elem55 = int (db_elem55[i]);
175  itemvector[i].elem56 = int (db_elem56[i]);
176  itemvector[i].elem57 = int (db_elem57[i]);
177  itemvector[i].elem66 = int (db_elem66[i]);
178  itemvector[i].elem67 = int (db_elem67[i]);
179  itemvector[i].elem77 = int (db_elem77[i]);
180 
181  for (unsigned int k=0;k<new_index_id.size()-1;k++){
182  if(counter==new_index_id[k]){
183  if((short int) (fabs(new_elem33[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem33 = int (new_elem33[k]*FACTOR+0.5);
184  if((short int) (fabs(new_elem34[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem34 = int (new_elem34[k]*FACTOR+0.5);
185  if((short int) (fabs(new_elem35[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem35 = int (new_elem35[k]*FACTOR+0.5);
186  if((short int) (fabs(new_elem44[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem44 = int (new_elem44[k]*FACTOR+0.5);
187  if((short int) (fabs(new_elem45[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem45 = int (new_elem45[k]*FACTOR+0.5);
188  if((short int) (fabs(new_elem46[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem46 = int (new_elem46[k]*FACTOR+0.5);
189  if((short int) (fabs(new_elem55[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem55 = int (new_elem55[k]*FACTOR+0.5);
190  if((short int) (fabs(new_elem56[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem56 = int (new_elem56[k]*FACTOR+0.5);
191  if((short int) (fabs(new_elem57[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem57 = int (new_elem57[k]*FACTOR+0.5);
192  if((short int) (fabs(new_elem66[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem66 = int (new_elem66[k]*FACTOR+0.5);
193  if((short int) (fabs(new_elem67[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem67 = int (new_elem67[k]*FACTOR+0.5);
194  if((short int) (fabs(new_elem77[k]*FACTOR+0.5))<MAX_SHORT) itemvector[counter].elem77 = int (new_elem77[k]*FACTOR+0.5);
195  itemvector[i] = itemvector[counter];
196  }
197  }
198 
199  if (counter>223968){
200  itemvector[counter].elem33 = int (db_elem33[i]);
201  itemvector[counter].elem34 = int (db_elem34[i]);
202  itemvector[counter].elem35 = int (db_elem35[i]);
203  itemvector[counter].elem44 = int (db_elem44[i]);
204  itemvector[counter].elem45 = int (db_elem45[i]);
205  itemvector[counter].elem46 = int (db_elem46[i]);
206  itemvector[counter].elem55 = int (db_elem55[i]);
207  itemvector[counter].elem56 = int (db_elem56[i]);
208  itemvector[counter].elem57 = int (db_elem57[i]);
209  itemvector[counter].elem66 = int (db_elem66[i]);
210  itemvector[counter].elem67 = int (db_elem67[i]);
211  itemvector[counter].elem77 = int (db_elem77[i]);
212  itemvector[i] = itemvector[counter];
213  }
214  }
215 
216  return cndbmatrix;
217 }
218 
219 #endif
220 
int i
Definition: DBlmapReader.cc:9
static CSCDBNoiseMatrix * prefillDBNoiseMatrix()
std::vector< Item > NoiseMatrixContainer
ReturnType produceDBNoiseMatrix(const CSCDBNoiseMatrixRcd &)
static std::atomic< unsigned int > counter
CSCNoiseMatrixDBConditions(const edm::ParameterSet &)
NoiseMatrixContainer matrix
const CSCDBNoiseMatrix * ReturnType
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)