CMS 3D CMS Logo

CSCGainsDBConditions.h
Go to the documentation of this file.
1 #ifndef _CSCGAINSDBCONDITIONS_H
2 #define _CSCGAINSDBCONDITIONS_H
3 
13 #include <cmath>
14 #include <memory>
15 
19 
21 public:
23  ~CSCGainsDBConditions() override;
24 
25  inline static CSCDBGains *prefillDBGains();
26 
27  typedef std::unique_ptr<CSCDBGains> 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  CSCDBGains *cndbgains = new CSCDBGains();
50 
51  int db_index;
52  float db_gainslope; // db_intercpt, db_chisq;
53  std::vector<int> db_index_id;
54  std::vector<float> db_slope;
55  std::vector<float> db_intercept;
56  std::vector<float> db_chi2;
57  int new_index;
58  float new_gainslope, new_intercpt, new_chisq;
59  std::vector<int> new_cham_id;
60  std::vector<int> new_index_id;
61  std::vector<int> new_strips;
62  std::vector<float> new_slope;
63  std::vector<float> new_intercept;
64  std::vector<float> new_chi2;
65 
66  int counter;
67  int db_nrlines = 0;
68  int new_nrlines = 0;
69 
70  std::ifstream dbdata;
71  dbdata.open("old_dbgains.dat", std::ios::in);
72  if (!dbdata) {
73  std::cerr << "Error: old_dbgains.dat -> no such file!" << std::endl;
74  exit(1);
75  }
76 
77  while (!dbdata.eof()) {
78  dbdata >> db_index >> db_gainslope;
79  db_index_id.push_back(db_index);
80  db_slope.push_back(db_gainslope);
81  // db_intercept.push_back(db_intercpt);
82  // db_chi2.push_back(db_chisq);
83  db_nrlines++;
84  }
85  dbdata.close();
86 
87  std::ifstream newdata;
88  newdata.open("gains.dat", std::ios::in);
89  if (!newdata) {
90  std::cerr << "Error: gains.dat -> no such file!" << std::endl;
91  exit(1);
92  }
93 
94  while (!newdata.eof()) {
95  newdata >> new_index >> new_gainslope >> new_intercpt >> new_chisq;
96  new_index_id.push_back(new_index);
97  new_slope.push_back(new_gainslope);
98  new_intercept.push_back(new_intercpt);
99  new_chi2.push_back(new_chisq);
100  new_nrlines++;
101  }
102  newdata.close();
103 
104  CSCDBGains::GainContainer &itemvector = cndbgains->gains;
105  itemvector.resize(MAX_SIZE);
106  cndbgains->factor_gain = (short int)(FACTOR);
107  std::cout << " myfactor " << cndbgains->factor_gain << std::endl;
108 
109  for (int i = 0; i < MAX_SIZE; ++i) {
110  itemvector[i].gain_slope = int(db_slope[i] * FACTOR + 0.5);
111  }
112 
113  for (int i = 0; i < MAX_SIZE; ++i) {
114  counter = db_index_id[i];
115  itemvector[i] = itemvector[counter];
116  itemvector[i].gain_slope = int(db_slope[i]);
117 
118  for (unsigned int k = 0; k < new_index_id.size() - 1; k++) {
119  if (counter == new_index_id[k]) {
120  if ((short int)(fabs(new_slope[k] * FACTOR + 0.5)) < MAX_SHORT)
121  itemvector[counter].gain_slope = int(new_slope[k] * FACTOR + 0.5);
122  itemvector[i] = itemvector[counter];
123  }
124  }
125  if (counter > 223968) {
126  itemvector[counter].gain_slope = int(db_slope[i]);
127  itemvector[i] = itemvector[counter];
128  }
129  }
130  return cndbgains;
131 }
132 
133 #endif
counter
Definition: counter.py:1
mps_fire.i
i
Definition: mps_fire.py:428
CSCGainsDBConditions::CSCGainsDBConditions
CSCGainsDBConditions(const edm::ParameterSet &)
Definition: CSCGainsDBConditions.cc:8
ESHandle.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
CSCGainsDBConditions::~CSCGainsDBConditions
~CSCGainsDBConditions() override
Definition: CSCGainsDBConditions.cc:17
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
CSCDetId.h
CSCDBGains
Definition: CSCDBGains.h:9
CSCDBGains::GainContainer
std::vector< Item > GainContainer
Definition: CSCDBGains.h:23
MakerMacros.h
pixelgpudetails::MAX_SIZE
constexpr unsigned int MAX_SIZE
Definition: SiPixelROCsStatusAndMapping.h:10
dqmdumpme.k
k
Definition: dqmdumpme.py:60
CSCGainsDBConditions::prefillDBGains
static CSCDBGains * prefillDBGains()
Definition: CSCGainsDBConditions.h:44
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
EventSetupRecordIntervalFinder.h
SourceFactory.h
CSCDBGains::gains
GainContainer gains
Definition: CSCDBGains.h:24
edm::ParameterSet
Definition: ParameterSet.h:47
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
CSCGainsDBConditions::produceDBGains
ReturnType produceDBGains(const CSCDBGainsRcd &)
Definition: CSCGainsDBConditions.cc:27
CSCGainsDBConditions::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: CSCGainsDBConditions.cc:32
Frameworkfwd.h
CSCGainsDBConditions
Definition: CSCGainsDBConditions.h:20
CSCDBGainsRcd.h
CSCDBGains::factor_gain
int factor_gain
Definition: CSCDBGains.h:19
EventSetup.h
CSCDBGainsRcd
Definition: CSCDBGainsRcd.h:5
CSCGainsDBConditions::ReturnType
std::unique_ptr< CSCDBGains > ReturnType
Definition: CSCGainsDBConditions.h:27
CSCDBGains.h
edm::ESProducer
Definition: ESProducer.h:104
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:52
ParameterSet.h
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
CSCGainsDBConditions::cndbGains
CSCDBGains * cndbGains
Definition: CSCGainsDBConditions.h:36