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 
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
counter
Definition: counter.py:1
mps_fire.i
i
Definition: mps_fire.py:428
ESHandle.h
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
CSCDBCrosstalk.h
CSCCrosstalkDBConditions::CSCCrosstalkDBConditions
CSCCrosstalkDBConditions(const edm::ParameterSet &)
Definition: CSCCrosstalkDBConditions.cc:8
CSCDBCrosstalk::CrosstalkContainer
std::vector< Item > CrosstalkContainer
Definition: CSCDBCrosstalk.h:27
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
CSCDBCrosstalkRcd
Definition: CSCDBCrosstalkRcd.h:5
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
CSCDetId.h
CSCDBCrosstalk
Definition: CSCDBCrosstalk.h:9
CSCCrosstalkDBConditions::prefillDBCrosstalk
static CSCDBCrosstalk * prefillDBCrosstalk()
Definition: CSCCrosstalkDBConditions.h:43
MakerMacros.h
pixelgpudetails::MAX_SIZE
constexpr unsigned int MAX_SIZE
Definition: SiPixelROCsStatusAndMapping.h:10
CSCDBCrosstalk::factor_slope
int factor_slope
Definition: CSCDBCrosstalk.h:22
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
EventSetupRecordIntervalFinder.h
SourceFactory.h
CSCCrosstalkDBConditions::ReturnType
std::unique_ptr< CSCDBCrosstalk > ReturnType
Definition: CSCCrosstalkDBConditions.h:27
edm::ParameterSet
Definition: ParameterSet.h:47
CSCCrosstalkDBConditions
Definition: CSCCrosstalkDBConditions.h:20
Event.h
recoMuon::in
Definition: RecoMuonEnumerators.h:6
createfilelist.int
int
Definition: createfilelist.py:10
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
CSCDBCrosstalkRcd.h
CSCDBCrosstalk::crosstalk
CrosstalkContainer crosstalk
Definition: CSCDBCrosstalk.h:28
Frameworkfwd.h
EventSetup.h
edm::ESProducer
Definition: ESProducer.h:104
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
ParameterSet.h
CSCCrosstalkDBConditions::produceDBCrosstalk
ReturnType produceDBCrosstalk(const CSCDBCrosstalkRcd &)
Definition: CSCCrosstalkDBConditions.cc:27
CSCCrosstalkDBConditions::~CSCCrosstalkDBConditions
~CSCCrosstalkDBConditions() override
Definition: CSCCrosstalkDBConditions.cc:17
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
CSCCrosstalkDBConditions::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CSCCrosstalkDBConditions.cc:32
CSCDBCrosstalk::factor_intercept
int factor_intercept
Definition: CSCDBCrosstalk.h:23