CMS 3D CMS Logo

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